Reconcile with jb-release

Change-Id: I8d1db6d558f2de1084a006bd2d63d2afe3b08318
diff --git a/res/layout-sw600dp/title_bar_nav.xml b/res/layout-sw600dp/title_bar_nav.xml
index 300b740..651474a 100644
--- a/res/layout-sw600dp/title_bar_nav.xml
+++ b/res/layout-sw600dp/title_bar_nav.xml
@@ -28,7 +28,6 @@
             android:src="@drawable/ic_back_holo_dark"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:paddingLeft="16dip"
             android:contentDescription="@string/accessibility_button_back"
             style="@style/HoloButton" />
         <ImageButton
@@ -52,22 +51,20 @@
         android:layout_width="0dip"
         android:layout_height="match_parent"
         android:layout_weight="1.0"
-        android:layout_marginLeft="8dip"
-        android:layout_marginRight="8dip"
         android:orientation="horizontal"
         android:background="@drawable/url_background">
         <ImageView
             android:id="@+id/url_icon"
-            android:layout_width="48dip"
+            android:layout_width="32dip"
             android:layout_height="20dip"
-            android:paddingLeft="14dip"
-            android:paddingRight="14dip"
             android:src="@drawable/ic_web_holo_dark"
             android:layout_gravity="center" />
         <ImageView
             android:id="@+id/lock"
             android:layout_width="wrap_content"
-            android:layout_height="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical"
+            android:layout_marginLeft="0dip"
             style="@style/HoloIcon"
             android:visibility="gone" />
         <com.android.browser.UrlInputView
@@ -75,7 +72,7 @@
             android:layout_width="0dip"
             android:layout_weight="1.0"
             android:layout_height="match_parent"
-            android:paddingLeft="0dip"
+            android:paddingLeft="4dip"
             android:paddingRight="0dip"
             android:background="@null"
             android:textAppearance="?android:attr/textAppearanceMedium"
@@ -115,7 +112,6 @@
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:scaleType="center"
-        android:paddingRight="16dip"
         style="@style/HoloButton"
         android:contentDescription="@string/accessibility_button_bookmarks"
         android:src="@drawable/ic_bookmarks_history_holo_dark" />
diff --git a/res/menu/browser.xml b/res/menu/browser.xml
index b0c25ea..9d95e88 100644
--- a/res/menu/browser.xml
+++ b/res/menu/browser.xml
@@ -76,6 +76,9 @@
         <group
             android:id="@+id/COMBO_MENU">
             <item
+                android:id="@+id/close_other_tabs_id"
+                android:title="@string/close_other_tabs" />
+            <item
                 android:id="@+id/history_menu_id"
                 android:title="@string/tab_history"
                 android:alphabeticShortcut="h" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 214c28d..ff396ce 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -197,6 +197,8 @@
     <string name="goto_dot">Go</string>
     <!-- Menu item to switch to text selection mode for copy and paste. -->
     <string name="select_dot">Select text</string>
+    <!-- Menu item to close all other tabs [CHAR LIMIT=40] -->
+    <string name="close_other_tabs">Close other tabs</string>
     <!-- Menu item to open the bookmarks page. This is a shorter version that
             is displayed with an icon -->
     <string name="bookmarks">Bookmarks</string>
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index e3f5986..cfe9a53 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -113,6 +113,7 @@
     protected TitleBar mTitleBar;
     private NavigationBarBase mNavigationBar;
     protected PieControl mPieControl;
+    private boolean mBlockFocusAnimations;
 
     public BaseUi(Activity browser, UiController controller) {
         mActivity = browser;
@@ -264,6 +265,8 @@
     @Override
     public void setActiveTab(final Tab tab) {
         if (tab == null) return;
+        // block unnecessary focus change animations during tab switch
+        mBlockFocusAnimations = true;
         mHandler.removeMessages(MSG_HIDE_TITLEBAR);
         if ((tab != mActiveTab) && (mActiveTab != null)) {
             removeTabFromContentView(mActiveTab);
@@ -294,6 +297,7 @@
         onProgressChanged(tab);
         mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
         updateAutoLogin(tab, false);
+        mBlockFocusAnimations = false;
     }
 
     protected void updateUrlBarAutoShowManagerTarget() {
@@ -860,4 +864,10 @@
             mContentView.setLayoutParams(params);
         }
     }
+
+    @Override
+    public boolean blockFocusAnimations() {
+        return mBlockFocusAnimations;
+    }
+
 }
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index fb535ba..8c9b11e 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -1554,6 +1554,10 @@
                 openIncognitoTab();
                 break;
 
+            case R.id.close_other_tabs_id:
+                closeOtherTabs();
+                break;
+
             case R.id.goto_menu_id:
                 editUrl();
                 break;
@@ -2475,6 +2479,20 @@
         }
     }
 
+    /**
+     * Close all tabs except the current one
+     */
+    @Override
+    public void closeOtherTabs() {
+        int inactiveTabs = mTabControl.getTabCount() - 1;
+        for (int i = inactiveTabs; i >= 0; i--) {
+            Tab tab = mTabControl.getTab(i);
+            if (tab != mTabControl.getCurrentTab()) {
+                removeTab(tab);
+            }
+        }
+    }
+
     // Called when loading from context menu or LOAD_URL message
     protected void loadUrlFromContext(String url) {
         Tab tab = getCurrentTab();
diff --git a/src/com/android/browser/DownloadHandler.java b/src/com/android/browser/DownloadHandler.java
index 6e2c786..31212b4 100644
--- a/src/com/android/browser/DownloadHandler.java
+++ b/src/com/android/browser/DownloadHandler.java
@@ -204,6 +204,7 @@
         // old percent-encoded url.
         String cookies = CookieManager.getInstance().getCookie(url, privateBrowsing);
         request.addRequestHeader("cookie", cookies);
+        request.addRequestHeader("User-Agent", userAgent);
         request.setNotificationVisibility(
                 DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
         if (mimetype == null) {
diff --git a/src/com/android/browser/NavigationBarBase.java b/src/com/android/browser/NavigationBarBase.java
index cf61c45..37b11c8 100644
--- a/src/com/android/browser/NavigationBarBase.java
+++ b/src/com/android/browser/NavigationBarBase.java
@@ -134,7 +134,9 @@
 
     void setDisplayTitle(String title) {
         if (!isEditingUrl()) {
-            mUrlInput.setText(title, false);
+            if (!title.equals(mUrlInput.getText().toString())) {
+                mUrlInput.setText(title, false);
+            }
         }
     }
 
diff --git a/src/com/android/browser/NavigationBarTablet.java b/src/com/android/browser/NavigationBarTablet.java
index b9c86e3..426174b 100644
--- a/src/com/android/browser/NavigationBarTablet.java
+++ b/src/com/android/browser/NavigationBarTablet.java
@@ -259,34 +259,49 @@
         mStopButton.setContentDescription(mRefreshDescription);
     }
 
+    private AnimatorSet mAnimation;
+
     private void hideNavButtons() {
+        if (mBaseUi.blockFocusAnimations()) {
+            mNavButtons.setVisibility(View.GONE);
+            return;
+        }
         int awidth = mNavButtons.getMeasuredWidth();
         Animator anim1 = ObjectAnimator.ofFloat(mNavButtons, View.TRANSLATION_X, 0, - awidth);
         Animator anim2 = ObjectAnimator.ofInt(mUrlContainer, "left", mUrlContainer.getLeft(),
                 mUrlContainer.getPaddingLeft());
         Animator anim3 = ObjectAnimator.ofFloat(mNavButtons, View.ALPHA, 1f, 0f);
-        AnimatorSet combo = new AnimatorSet();
-        combo.playTogether(anim1, anim2, anim3);
-        combo.addListener(new AnimatorListenerAdapter() {
+        mAnimation = new AnimatorSet();
+        mAnimation.playTogether(anim1, anim2, anim3);
+        mAnimation.addListener(new AnimatorListenerAdapter() {
             @Override
             public void onAnimationEnd(Animator animation) {
                 mNavButtons.setVisibility(View.GONE);
+                mAnimation = null;
             }
         });
-        combo.setDuration(150);
-        combo.start();
+        mAnimation.setDuration(150);
+        mAnimation.start();
     }
 
     private void showNavButtons() {
-        int awidth = mNavButtons.getMeasuredWidth();
-        Animator anim1 = ObjectAnimator.ofFloat(mNavButtons, View.TRANSLATION_X, -awidth, 0);
-        Animator anim2 = ObjectAnimator.ofInt(mUrlContainer, "left", 0, awidth);
-        Animator anim3 = ObjectAnimator.ofFloat(mNavButtons, View.ALPHA, 0f, 1f);
-        AnimatorSet combo = new AnimatorSet();
-        combo.playTogether(anim1, anim2, anim3);
+        if (mAnimation != null) {
+            mAnimation.cancel();
+        }
         mNavButtons.setVisibility(View.VISIBLE);
-        combo.setDuration(150);
-        combo.start();
+        if (!mBaseUi.blockFocusAnimations()) {
+            int awidth = mNavButtons.getMeasuredWidth();
+            Animator anim1 = ObjectAnimator.ofFloat(mNavButtons,
+                    View.TRANSLATION_X, -awidth, 0);
+            Animator anim2 = ObjectAnimator.ofInt(mUrlContainer, "left", 0,
+                    awidth);
+            Animator anim3 = ObjectAnimator.ofFloat(mNavButtons, View.ALPHA,
+                    0f, 1f);
+            AnimatorSet combo = new AnimatorSet();
+            combo.playTogether(anim1, anim2, anim3);
+            combo.setDuration(150);
+            combo.start();
+        }
     }
 
     private void showHideStar(Tab tab) {
diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java
index eb6032d..e3c22bd 100644
--- a/src/com/android/browser/PhoneUi.java
+++ b/src/com/android/browser/PhoneUi.java
@@ -182,6 +182,14 @@
         if (incognito != null) {
             incognito.setVisible(showingNavScreen() || mUseQuickControls);
         }
+        MenuItem closeOthers = menu.findItem(R.id.close_other_tabs_id);
+        if (closeOthers != null) {
+            boolean isLastTab = true;
+            if (tab != null) {
+                isLastTab = (mTabControl.getTabCount() <= 1);
+            }
+            closeOthers.setEnabled(!isLastTab);
+        }
         if (showingNavScreen()) {
             menu.setGroupVisible(R.id.LIVE_MENU, false);
             menu.setGroupVisible(R.id.SNAPSHOT_MENU, false);
diff --git a/src/com/android/browser/UI.java b/src/com/android/browser/UI.java
index aeab746..96f6640 100644
--- a/src/com/android/browser/UI.java
+++ b/src/com/android/browser/UI.java
@@ -146,4 +146,6 @@
 
     public boolean shouldCaptureThumbnails();
 
+    boolean blockFocusAnimations();
+
 }
diff --git a/src/com/android/browser/UiController.java b/src/com/android/browser/UiController.java
index b3d4631..a2946a7 100644
--- a/src/com/android/browser/UiController.java
+++ b/src/com/android/browser/UiController.java
@@ -59,6 +59,8 @@
 
     void closeTab(Tab tab);
 
+    void closeOtherTabs();
+
     void stopLoading();
 
     Intent createBookmarkCurrentPageIntent(boolean canBeAnEdit);