adjust url bar for portrait large screen

       Bug: 4431091
       remove navigation buttons in portrait large screen
       when url field has focus

Change-Id: I7f800263a3652987a53937ea833eab3c45088ac0
diff --git a/res/layout/url_bar.xml b/res/layout/url_bar.xml
index 8743906..43bbdcd 100644
--- a/res/layout/url_bar.xml
+++ b/res/layout/url_bar.xml
@@ -76,26 +76,32 @@
         android:layout_height="48dip"
         android:orientation="horizontal"
         android:background="@drawable/bg_urlbar">
-        <ImageButton
-            android:id="@+id/back"
-            android:src="@drawable/ic_back_holo_dark"
+        <LinearLayout
+            android:id="@+id/navbuttons"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:paddingLeft="16dip"
-            style="@style/HoloButton" />
-        <ImageButton
-            android:id="@+id/forward"
-            android:src="@drawable/ic_forward_holo_dark"
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            style="@style/HoloButton" />
-        <ImageButton
-            android:id="@+id/stop"
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            style="@style/HoloButton"
-            android:gravity="center_vertical"
-            android:src="@drawable/ic_stop_holo_dark" />
+            android:orientation="horizontal">
+            <ImageButton
+                android:id="@+id/back"
+                android:src="@drawable/ic_back_holo_dark"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                android:paddingLeft="16dip"
+                style="@style/HoloButton" />
+            <ImageButton
+                android:id="@+id/forward"
+                android:src="@drawable/ic_forward_holo_dark"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                style="@style/HoloButton" />
+            <ImageButton
+                android:id="@+id/stop"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                style="@style/HoloButton"
+                android:gravity="center_vertical"
+                android:src="@drawable/ic_stop_holo_dark" />
+        </LinearLayout>
         <LinearLayout
             android:id="@+id/urlbar_focused"
             android:layout_width="0dip"
diff --git a/res/values-w720dp/bools.xml b/res/values-w720dp/bools.xml
new file mode 100644
index 0000000..0d05b7f
--- /dev/null
+++ b/res/values-w720dp/bools.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2011 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 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.
+-->
+<resources
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <bool name="hide_nav_buttons">false</bool>
+</resources>
diff --git a/res/values/bools.xml b/res/values/bools.xml
index 6217de1..55f8242 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -13,4 +13,5 @@
 <resources
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <bool name="isTablet">false</bool>
+    <bool name="hide_nav_buttons">true</bool>
 </resources>
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 9fcc7b7..e91597f 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -20,8 +20,13 @@
 import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher;
 import com.android.browser.search.SearchEngine;
 
+import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
 import android.app.Activity;
 import android.content.Context;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.drawable.Drawable;
@@ -68,6 +73,7 @@
     private ImageView mUrlIcon;
     private ImageView mSearchButton;
     private View mUrlContainer;
+    private View mNavButtons;
     private View mGoButton;
     private ImageView mStopButton;
     private View mAllButton;
@@ -88,6 +94,7 @@
 
     private boolean mInLoad;
     private boolean mUseQuickControls;
+    private boolean mHideNavButtons;
 
     public TitleBarXLarge(Activity activity, UiController controller,
             XLargeUi ui) {
@@ -105,6 +112,8 @@
     }
 
     private void initLayout(Context context) {
+        Resources res = mContext.getResources();
+        mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons);
         LayoutInflater factory = LayoutInflater.from(context);
         factory.inflate(R.layout.url_bar, this);
 
@@ -124,6 +133,7 @@
         mClearButton = findViewById(R.id.clear);
         mVoiceSearch = (ImageView) findViewById(R.id.voicesearch);
         mProgressView = (PageProgressView) findViewById(R.id.progress);
+        mNavButtons = findViewById(R.id.navbuttons);
         mUrlContainer = findViewById(R.id.urlbar_focused);
         mBackButton.setOnClickListener(this);
         mForwardButton.setOnClickListener(this);
@@ -154,6 +164,25 @@
         setFocusState(false);
     }
 
+    @Override
+    public void onConfigurationChanged(Configuration config) {
+        super.onConfigurationChanged(config);
+        Resources res = mContext.getResources();
+        mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons);
+        if (mUrlInput.hasFocus()) {
+            if (mHideNavButtons && (mNavButtons.getVisibility() == View.VISIBLE)) {
+                int aw = mNavButtons.getMeasuredWidth();
+                mNavButtons.setVisibility(View.GONE);
+                mNavButtons.setAlpha(0f);
+                mNavButtons.setTranslationX(-aw);
+            } else if (!mHideNavButtons && (mNavButtons.getVisibility() == View.GONE)) {
+                mNavButtons.setVisibility(View.VISIBLE);
+                mNavButtons.setAlpha(1f);
+                mNavButtons.setTranslationX(0);
+            }
+        }
+    }
+
     void updateNavigationState(Tab tab) {
         WebView web = tab.getWebView();
         if (web != null) {
@@ -402,6 +431,9 @@
 
     private void setFocusState(boolean focus) {
         if (focus) {
+            if (mHideNavButtons) {
+                hideNavButtons();
+            }
             mUrlInput.setDropDownWidth(mUrlContainer.getWidth());
             mUrlInput.setDropDownHorizontalOffset(-mUrlInput.getLeft());
             mSearchButton.setVisibility(View.GONE);
@@ -410,6 +442,9 @@
             mUrlIcon.setImageResource(R.drawable.ic_search_holo_dark);
             updateSearchMode(false);
         } else {
+            if (mHideNavButtons) {
+                showNavButtons();
+            }
             mGoButton.setVisibility(View.GONE);
             mVoiceSearch.setVisibility(View.GONE);
             mStar.setVisibility(View.VISIBLE);
@@ -547,4 +582,48 @@
     void registerDropdownChangeListener(DropdownChangeListener d) {
         mUrlInput.registerDropdownChangeListener(d);
     }
+
+    private void hideNavButtons() {
+        int awidth = mNavButtons.getMeasuredWidth();
+        Animator anim1 = ObjectAnimator.ofFloat(mNavButtons, "translationX", 0, - awidth);
+        Animator anim2 = ObjectAnimator.ofInt(mUrlContainer, "left", mUrlContainer.getLeft(),
+                mUrlContainer.getPaddingLeft());
+        Animator anim3 = ObjectAnimator.ofFloat(mNavButtons, "alpha", 1f, 0f);
+        AnimatorSet combo = new AnimatorSet();
+        combo.playTogether(anim1, anim2, anim3);
+        combo.addListener(new AnimatorListener() {
+
+            @Override
+            public void onAnimationCancel(Animator animation) {
+            }
+
+            @Override
+            public void onAnimationEnd(Animator animation) {
+                mNavButtons.setVisibility(View.GONE);
+            }
+
+            @Override
+            public void onAnimationRepeat(Animator animation) {
+            }
+
+            @Override
+            public void onAnimationStart(Animator animation) {
+            }
+        });
+        combo.setDuration(150);
+        combo.start();
+    }
+
+    private void showNavButtons() {
+        int awidth = mNavButtons.getMeasuredWidth();
+        Animator anim1 = ObjectAnimator.ofFloat(mNavButtons, "translationX", -awidth, 0);
+        Animator anim2 = ObjectAnimator.ofInt(mUrlContainer, "left", 0, awidth);
+        Animator anim3 = ObjectAnimator.ofFloat(mNavButtons, "alpha", 0f, 1f);
+        AnimatorSet combo = new AnimatorSet();
+        combo.playTogether(anim1, anim2, anim3);
+        mNavButtons.setVisibility(View.VISIBLE);
+        combo.setDuration(150);
+        combo.start();
+    }
+
 }