Merge "Only import bookmarks not associated with an account"
diff --git a/res/layout/url_bar.xml b/res/layout/url_bar.xml
index 4d8efdd..f2b32c4 100644
--- a/res/layout/url_bar.xml
+++ b/res/layout/url_bar.xml
@@ -51,19 +51,12 @@
             android:orientation="horizontal"
             android:background="@drawable/url_background">
             <ImageView
-                android:id="@+id/web_icon"
+                android:id="@+id/url_icon"
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
                 android:src="@drawable/ic_web_holo_dark"
                 style="@style/HoloIcon" />
             <ImageView
-                android:id="@+id/voice_icon"
-                android:layout_width="wrap_content"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_voice_search_holo_dark"
-                style="@style/HoloIcon"
-                android:visibility="gone" />
-            <ImageView
                 android:id="@+id/lock"
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
diff --git a/res/values/integers.xml b/res/values/integers.xml
index a899a14..ad0ed90 100644
--- a/res/values/integers.xml
+++ b/res/values/integers.xml
@@ -25,4 +25,6 @@
     <integer name="most_visits_limit">10</integer>
     <!-- Animation durations -->
     <integer name="comboViewFadeInDuration">400</integer>
+    <!--  fade between tabs duration -->
+    <integer name="tabFadeDuration">300</integer>
 </resources>
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index bca999d..93b0ec8 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -18,6 +18,8 @@
 
 import com.android.browser.Tab.LockIcon;
 
+import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
 import android.animation.ObjectAnimator;
 import android.app.Activity;
 import android.content.res.Configuration;
@@ -67,7 +69,7 @@
     Activity mActivity;
     UiController mUiController;
     TabControl mTabControl;
-    private Tab mActiveTab;
+    protected Tab mActiveTab;
     private InputMethodManager mInputManager;
 
     private Drawable mSecLockIcon;
@@ -220,12 +222,18 @@
     }
 
     @Override
-    public void setActiveTab(Tab tab) {
+    public void setActiveTab(final Tab tab) {
+        setActiveTab(tab, true);
+    }
+
+    void setActiveTab(Tab tab, boolean needsAttaching) {
         if ((tab != mActiveTab) && (mActiveTab != null)) {
             removeTabFromContentView(mActiveTab);
         }
         mActiveTab = tab;
-        attachTabToContentView(tab);
+        if (needsAttaching) {
+            attachTabToContentView(tab);
+        }
         setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
         onTabDataChanged(tab);
         onProgressChanged(tab);
@@ -259,7 +267,7 @@
         attachTabToContentView(tab);
     }
 
-    private void attachTabToContentView(Tab tab) {
+    protected void attachTabToContentView(Tab tab) {
         if ((tab == null) || (tab.getWebView() == null)) {
             return;
         }
diff --git a/src/com/android/browser/ScrollWebView.java b/src/com/android/browser/ScrollWebView.java
index 2bf07e1..d1dc25b 100644
--- a/src/com/android/browser/ScrollWebView.java
+++ b/src/com/android/browser/ScrollWebView.java
@@ -1,22 +1,24 @@
 /*
  * Copyright (C) 2010 The Android Open Source Project
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
  */
 
 package com.android.browser;
 
 import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Paint;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
@@ -25,7 +27,7 @@
 import java.util.Map;
 
 /**
- *  Manage WebView scroll events
+ * Manage WebView scroll events
  */
 public class ScrollWebView extends WebView implements Runnable {
 
@@ -34,6 +36,9 @@
     private boolean mBackgroundRemoved = false;
     private boolean mUserInitiated = false;
     private TitleBarBase mTitleBar;
+    private boolean mDrawCached = false;
+    private Bitmap mBitmap;
+    private Paint mCachePaint = new Paint();
 
     /**
      * @param context
@@ -51,8 +56,8 @@
      * @param attrs
      * @param defStyle
      */
-    public ScrollWebView(Context context, AttributeSet attrs, int defStyle,
-            boolean privateBrowsing) {
+    public ScrollWebView(
+            Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
         super(context, attrs, defStyle, privateBrowsing);
     }
 
@@ -97,6 +102,10 @@
         }
     }
 
+    public boolean hasTitleBar() {
+        return (mTitleBar != null);
+    }
+
     @Override
     public boolean onTouchEvent(MotionEvent evt) {
         if (MotionEvent.ACTION_DOWN == evt.getActionMasked()) {
@@ -128,22 +137,46 @@
         mScrollListener = l;
     }
 
+    @Override
+    public void invalidate() {
+        if (!mDrawCached) {
+            super.invalidate();
+        }
+    }
+
     // callback for scroll events
 
     interface ScrollListener {
         public void onScroll(int visibleTitleHeight, boolean userInitiated);
     }
 
-    @Override
-    protected void onDraw(android.graphics.Canvas c) {
-        super.onDraw(c);
-        if (!mBackgroundRemoved && getRootView().getBackground() != null) {
-            mBackgroundRemoved = true;
-            post(new Runnable() {
-                public void run() {
-                    getRootView().setBackgroundDrawable(null);
-                }
-            });
+    void setDrawCached(boolean cached) {
+        if (cached) {
+            buildDrawingCache();
+            mBitmap = getDrawingCache(false);
+            mDrawCached = (mBitmap != null);
+        } else {
+            mBitmap = null;
+            destroyDrawingCache();
+            mDrawCached = false;
         }
     }
+
+    @Override
+    protected void onDraw(android.graphics.Canvas c) {
+        if (mDrawCached) {
+            c.drawBitmap(mBitmap, getScrollX(), getScrollY(), mCachePaint);
+        } else {
+            super.onDraw(c);
+            if (!mBackgroundRemoved && getRootView().getBackground() != null) {
+                mBackgroundRemoved = true;
+                post(new Runnable() {
+                    public void run() {
+                        getRootView().setBackgroundDrawable(null);
+                    }
+                });
+            }
+        }
+    }
+
 }
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 85935a0..14e7c72 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -57,15 +57,14 @@
     private ImageButton mBackButton;
     private ImageButton mForwardButton;
     private ImageView mStar;
-    private ImageView mWebIcon;
-    private View mSearchButton;
+    private ImageView mUrlIcon;
+    private ImageView mSearchButton;
     private View mUrlContainer;
     private View mGoButton;
     private ImageView mStopButton;
     private View mAllButton;
     private View mClearButton;
-    private View mVoiceSearch;
-    private View mVoiceSearchIndicator;
+    private ImageView mVoiceSearch;
     private PageProgressView mProgressView;
     private Drawable mFocusDrawable;
     private Drawable mUnfocusDrawable;
@@ -111,17 +110,16 @@
         // back/forward.  Probably should be done inside onPageStarted.
         mBackButton = (ImageButton) findViewById(R.id.back);
         mForwardButton = (ImageButton) findViewById(R.id.forward);
-        mWebIcon = (ImageView) findViewById(R.id.web_icon);
+        mUrlIcon = (ImageView) findViewById(R.id.url_icon);
         mStar = (ImageView) findViewById(R.id.star);
         mStopButton = (ImageView) findViewById(R.id.stop);
-        mSearchButton = findViewById(R.id.search);
+        mSearchButton = (ImageView) findViewById(R.id.search);
         mLockIcon = (ImageView) findViewById(R.id.lock);
         mGoButton = findViewById(R.id.go);
         mClearButton = findViewById(R.id.clear);
-        mVoiceSearch = findViewById(R.id.voicesearch);
+        mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
         mProgressView = (PageProgressView) findViewById(R.id.progress);
         mUrlContainer = findViewById(R.id.urlbar_focused);
-        mVoiceSearchIndicator = findViewById(R.id.voice_icon);
         mBackButton.setOnClickListener(this);
         mForwardButton.setOnClickListener(this);
         mStar.setOnClickListener(this);
@@ -293,23 +291,21 @@
             mSearchButton.setVisibility(View.GONE);
             mStar.setVisibility(View.GONE);
             mClearButton.setVisibility(View.VISIBLE);
-            if (mInVoiceMode) {
-                mVoiceSearchIndicator.setVisibility(View.VISIBLE);
-            }
-            mWebIcon.setImageResource(R.drawable.ic_search_holo_dark);
+            mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
             updateSearchMode(false);
         } else {
             mGoButton.setVisibility(View.GONE);
             mVoiceSearch.setVisibility(View.GONE);
             mStar.setVisibility(View.VISIBLE);
             mClearButton.setVisibility(View.GONE);
-            mVoiceSearchIndicator.setVisibility(View.GONE);
             if (mUseQuickControls) {
                 mSearchButton.setVisibility(View.GONE);
             } else {
                 mSearchButton.setVisibility(View.VISIBLE);
             }
-            mWebIcon.setImageResource(R.drawable.ic_web_holo_dark);
+            mUrlIcon.setImageResource(mInVoiceMode ?
+                    R.drawable.ic_search_holo_dark
+                    : R.drawable.ic_web_holo_dark);
         }
     }
 
@@ -399,9 +395,7 @@
     public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
         mInVoiceMode = voicemode;
         mUrlInput.setVoiceResults(voiceResults);
-        mVoiceSearchIndicator.setVisibility(mInVoiceMode
-                ? View.VISIBLE : View.GONE);
-        mWebIcon.setVisibility(mInVoiceMode ? View.GONE : View.VISIBLE);
+        mUrlIcon.setImageDrawable(mSearchButton.getDrawable());
     }
 
     @Override
diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java
index f914183..8c7756b 100644
--- a/src/com/android/browser/XLargeUi.java
+++ b/src/com/android/browser/XLargeUi.java
@@ -18,6 +18,9 @@
 
 import com.android.browser.ScrollWebView.ScrollListener;
 
+import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
+import android.animation.ObjectAnimator;
 import android.app.ActionBar;
 import android.app.Activity;
 import android.content.pm.PackageManager;
@@ -204,11 +207,57 @@
     }
 
     @Override
-    public void setActiveTab(Tab tab) {
-        if (mTitleBar.isEditingUrl()) {
-            mTitleBar.stopEditingUrl();
+    public void setActiveTab(final Tab tab) {
+        if ((tab != mActiveTab) && (mActiveTab != null)) {
+            // animate between the two
+            final ScrollWebView fromWV = (ScrollWebView) mActiveTab.getWebView();
+            fromWV.setDrawCached(true);
+            fromWV.setEmbeddedTitleBar(null);
+            final ScrollWebView toWV = (ScrollWebView) tab.getWebView();
+            if (!mUseQuickControls) {
+                if (mTitleBar.getParent() == null) {
+                    toWV.setEmbeddedTitleBar(mTitleBar);
+                }
+            }
+            toWV.setDrawCached(true);
+            attachTabToContentView(tab);
+            super.setActiveTab(tab, false);
+            ObjectAnimator transition = ObjectAnimator.ofFloat(
+                    toWV, "alpha", 0f, 1f);
+            transition.setDuration(mActivity.getResources()
+                    .getInteger(R.integer.tabFadeDuration));
+            transition.addListener(new AnimatorListener() {
+                @Override
+                public void onAnimationCancel(Animator animation) {
+                    fromWV.setDrawCached(false);
+                    toWV.setDrawCached(false);
+                    setActiveTab(tab, false);
+                }
+
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    fromWV.setDrawCached(false);
+                    toWV.setDrawCached(false);
+                    setActiveTab(tab, false);
+                }
+
+                @Override
+                public void onAnimationRepeat(Animator animation) {
+                }
+
+                @Override
+                public void onAnimationStart(Animator animation) {
+                }
+            });
+            transition.start();
+        } else {
+            super.setActiveTab(tab, true);
+            setActiveTab(tab, true);
         }
-        super.setActiveTab(tab);
+    }
+
+    @Override
+    void setActiveTab(Tab tab, boolean needsAttaching) {
         ScrollWebView view = (ScrollWebView) tab.getWebView();
         // TabControl.setCurrentTab has been called before this,
         // so the tab is guaranteed to have a webview
@@ -222,7 +271,10 @@
             view.setScrollListener(null);
             mTabBar.showTitleBarIndicator(false);
         } else {
-            view.setEmbeddedTitleBar(mTitleBar);
+            // check if title bar is already attached by animation
+            if (mTitleBar.getParent() == null) {
+                view.setEmbeddedTitleBar(mTitleBar);
+            }
             view.setScrollListener(this);
         }
         mTabBar.onSetActiveTab(tab);