adjust url bar for portrait large screen

      Bug: 4515354
      Original bug: 4335356
      hand picked the changes into the new code

Change-Id: I54b69a35660a5a38f41486c974c1cea171ee5d5e
diff --git a/res/layout-sw600dp/title_bar_nav.xml b/res/layout-sw600dp/title_bar_nav.xml
index 4ef94e8..ccb9188 100644
--- a/res/layout-sw600dp/title_bar_nav.xml
+++ b/res/layout-sw600dp/title_bar_nav.xml
@@ -18,26 +18,32 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     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:layout_height="wrap_content"
+        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/NavigationBarTablet.java b/src/com/android/browser/NavigationBarTablet.java
index 45c1e75..1aeb35b 100644
--- a/src/com/android/browser/NavigationBarTablet.java
+++ b/src/com/android/browser/NavigationBarTablet.java
@@ -15,13 +15,17 @@
  */
 package com.android.browser;
 
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
 import android.content.Context;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.View;
-import android.webkit.WebView;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 
@@ -43,8 +47,10 @@
     private View mAllButton;
     private View mClearButton;
     private ImageView mVoiceSearch;
+    private View mNavButtons;
     private Drawable mFocusDrawable;
     private Drawable mUnfocusDrawable;
+    private boolean mHideNavButtons;
 
     public NavigationBarTablet(Context context) {
         super(context);
@@ -69,6 +75,7 @@
                 R.drawable.textfield_active_holo_dark);
         mUnfocusDrawable = resources.getDrawable(
                 R.drawable.textfield_default_holo_dark);
+        mHideNavButtons = resources.getBoolean(R.bool.hide_nav_buttons);
     }
 
     @Override
@@ -77,6 +84,7 @@
         mAllButton = findViewById(R.id.all_btn);
         // TODO: Change enabled states based on whether you can go
         // back/forward.  Probably should be done inside onPageStarted.
+        mNavButtons = findViewById(R.id.navbuttons);
         mBackButton = (ImageButton) findViewById(R.id.back);
         mForwardButton = (ImageButton) findViewById(R.id.forward);
         mUrlIcon = (ImageView) findViewById(R.id.url_icon);
@@ -100,6 +108,24 @@
         mUrlInput.setContainer(mUrlContainer);
     }
 
+    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);
+            }
+        }
+    }
+
     @Override
     public void setTitleBar(TitleBar titleBar) {
         super.setTitleBar(titleBar);
@@ -171,12 +197,18 @@
     protected void setFocusState(boolean focus) {
         super.setFocusState(focus);
         if (focus) {
+            if (mHideNavButtons) {
+                hideNavButtons();
+            }
             mSearchButton.setVisibility(View.GONE);
             mStar.setVisibility(View.GONE);
             mClearButton.setVisibility(View.VISIBLE);
             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);
@@ -232,4 +264,34 @@
         }
     }
 
+    private void hideNavButtons() {
+        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() {
+            @Override
+            public void onAnimationEnd(Animator animation) {
+                mNavButtons.setVisibility(View.GONE);
+            }
+        });
+        combo.setDuration(150);
+        combo.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);
+        mNavButtons.setVisibility(View.VISIBLE);
+        combo.setDuration(150);
+        combo.start();
+    }
+
 }