Bug 965548 - Part 5: Shrink the url bar on appropriate phones. r=lucasr
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 17 Apr 2014 13:34:12 -0700
changeset 179600 440224cc83d9162ce2b0f963315902d9bc95f2ae
parent 179599 be018ccdcb8220a0fbc8be391cb67a20f0b6bc11
child 179601 9a5586190013a870fcf0b2b2eb64039fdcd24db4
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewerslucasr
bugs965548
milestone31.0a1
Bug 965548 - Part 5: Shrink the url bar on appropriate phones. r=lucasr
mobile/android/base/resources/layout/browser_toolbar.xml
mobile/android/base/toolbar/BrowserToolbar.java
--- a/mobile/android/base/resources/layout/browser_toolbar.xml
+++ b/mobile/android/base/resources/layout/browser_toolbar.xml
@@ -7,37 +7,48 @@
        xmlns:gecko="http://schemas.android.com/apk/res-auto">
 
     <ImageButton android:id="@+id/back"
                  style="@style/UrlBar.ImageButton.Unused"/>
 
     <ImageButton android:id="@+id/forward"
                  style="@style/UrlBar.ImageButton.Unused"/>
 
+    <!-- Note: any layout parameters setting the right edge of
+         this View should be matched in the url_bar_translating_edge.
+
+         Note 2: On devices where the editing mode cancel items are
+         wider than the tabs and similar buttons (e.g. hardware menu
+         button), the url bar will shrink, in which case the LayoutParams
+         of this View are changed dynamically. -->
     <ImageView android:id="@+id/url_bar_entry"
                style="@style/UrlBar.Button"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="-19dp"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/tabs"
                android:paddingRight="4dp"
                android:duplicateParentState="true"
                android:clickable="false"
                android:focusable="false"
                android:src="@drawable/url_bar_entry"
                android:scaleType="fitXY"/>
 
+    <!-- A View that clips with url_bar_entry and translates
+         around it to animate shrinking or growing the url bar,
+         which occurs in the display/editing mode transitions. -->
     <ImageView android:id="@+id/url_bar_translating_edge"
                style="@style/UrlBar.Button"
                android:layout_alignLeft="@id/url_bar_entry"
-               android:layout_alignRight="@id/url_bar_entry"
+               android:layout_toLeftOf="@+id/tabs"
                android:layout_alignTop="@id/url_bar_entry"
                android:layout_alignBottom="@id/url_bar_entry"
+               android:layout_marginRight="-19dp"
                android:paddingRight="4dp"
                android:duplicateParentState="true"
                android:clickable="false"
                android:focusable="false"
                android:visibility="invisible"
                android:src="@drawable/url_bar_translating_edge"
                android:scaleType="fitXY"/>
 
--- a/mobile/android/base/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/toolbar/BrowserToolbar.java
@@ -54,16 +54,17 @@ import android.view.View;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.Interpolator;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.PopupWindow;
+import android.widget.RelativeLayout;
 
 /**
 * {@code BrowserToolbar} is single entry point for users of the toolbar
 * subsystem i.e. this should be the only import outside the 'toolbar'
 * package.
 *
 * {@code BrowserToolbar} serves at the single event bus for all
 * sub-components in the toolbar. It tracks tab events and gecko messages
@@ -115,16 +116,18 @@ public class BrowserToolbar extends Them
     enum ForwardButtonAnimation {
         SHOW,
         HIDE
     }
 
     private ToolbarDisplayLayout mUrlDisplayLayout;
     private ToolbarEditLayout mUrlEditLayout;
     private View mUrlBarEntry;
+    private RelativeLayout.LayoutParams urlBarEntryDefaultLayoutParams;
+    private RelativeLayout.LayoutParams urlBarEntryShrunkenLayoutParams;
     private ImageView urlBarTranslatingEdge;
     private boolean mSwitchingTabs;
     private ShapedButton mTabs;
     private ImageButton mBack;
     private ImageButton mForward;
 
     private ToolbarProgressView mProgressBar;
     private TabCounter mTabsCounter;
@@ -132,16 +135,18 @@ public class BrowserToolbar extends Them
     private ThemedImageView mMenuIcon;
     private LinearLayout mActionItemBar;
     private MenuPopup mMenuPopup;
     private List<View> mFocusOrder;
 
     private final ThemedView editSeparator;
     private final View editCancel;
 
+    private boolean shouldShrinkURLBar = false;
+
     private OnActivateListener mActivateListener;
     private OnCommitListener mCommitListener;
     private OnDismissListener mDismissListener;
     private OnFilterListener mFilterListener;
     private OnFocusChangeListener mFocusChangeListener;
     private OnStartEditingListener mStartEditingListener;
     private OnStopEditingListener mStopEditingListener;
 
@@ -185,16 +190,21 @@ public class BrowserToolbar extends Them
 
         final Resources res = getResources();
         mUrlBarViewOffset = res.getDimensionPixelSize(R.dimen.url_bar_offset_left);
         mDefaultForwardMargin = res.getDimensionPixelSize(R.dimen.forward_default_offset);
         mUrlDisplayLayout = (ToolbarDisplayLayout) findViewById(R.id.display_layout);
         mUrlBarEntry = findViewById(R.id.url_bar_entry);
         mUrlEditLayout = (ToolbarEditLayout) findViewById(R.id.edit_layout);
 
+        urlBarEntryDefaultLayoutParams = (RelativeLayout.LayoutParams) mUrlBarEntry.getLayoutParams();
+        urlBarEntryShrunkenLayoutParams = new RelativeLayout.LayoutParams(urlBarEntryDefaultLayoutParams);
+        urlBarEntryShrunkenLayoutParams.addRule(RelativeLayout.ALIGN_RIGHT, R.id.edit_layout);
+        urlBarEntryShrunkenLayoutParams.rightMargin = 0;
+
         // This will clip the translating edge's image at 60% of its width
         urlBarTranslatingEdge = (ImageView) findViewById(R.id.url_bar_translating_edge);
         if (urlBarTranslatingEdge != null) {
             urlBarTranslatingEdge.getDrawable().setLevel(6000);
         }
 
         mTabs = (ShapedButton) findViewById(R.id.tabs);
         mTabsCounter = (TabCounter) findViewById(R.id.tabs_counter);
@@ -958,23 +968,27 @@ public class BrowserToolbar extends Them
         updateChildrenForEditing();
 
         updateProgressVisibility();
 
         if (mStartEditingListener != null) {
             mStartEditingListener.onStartEditing();
         }
 
+        final int curveTranslation = getUrlBarCurveTranslation();
+        final int entryTranslation = getUrlBarEntryTranslation();
+        shouldShrinkURLBar = (entryTranslation < 0);
+
         if (urlBarTranslatingEdge != null) {
             urlBarTranslatingEdge.setVisibility(View.VISIBLE);
+            if (shouldShrinkURLBar) {
+                mUrlBarEntry.setLayoutParams(urlBarEntryShrunkenLayoutParams);
+            }
         }
 
-        final int entryTranslation = getUrlBarEntryTranslation();
-        final int curveTranslation = getUrlBarCurveTranslation();
-
         // This animation doesn't make much sense in a sidebar UI
         if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
             showUrlEditLayout();
 
             if (!HardwareUtils.isTablet()) {
                 if (urlBarTranslatingEdge != null) {
                     ViewHelper.setTranslationX(urlBarTranslatingEdge, entryTranslation);
                 }
@@ -1083,17 +1097,21 @@ public class BrowserToolbar extends Them
 
         if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
             hideUrlEditLayout();
 
             if (!HardwareUtils.isTablet()) {
                 updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
 
                 if (urlBarTranslatingEdge != null) {
+                    urlBarTranslatingEdge.setVisibility(View.INVISIBLE);
                     ViewHelper.setTranslationX(urlBarTranslatingEdge, 0);
+                    if (shouldShrinkURLBar) {
+                        mUrlBarEntry.setLayoutParams(urlBarEntryDefaultLayoutParams);
+                    }
                 }
 
                 ViewHelper.setTranslationX(mTabs, 0);
                 ViewHelper.setTranslationX(mTabsCounter, 0);
                 ViewHelper.setTranslationX(mActionItemBar, 0);
 
                 if (mHasSoftMenuButton) {
                     ViewHelper.setTranslationX(mMenu, 0);
@@ -1141,16 +1159,19 @@ public class BrowserToolbar extends Them
             @Override
             public void onPropertyAnimationStart() {
             }
 
             @Override
             public void onPropertyAnimationEnd() {
                 if (urlBarTranslatingEdge != null) {
                     urlBarTranslatingEdge.setVisibility(View.INVISIBLE);
+                    if (shouldShrinkURLBar) {
+                        mUrlBarEntry.setLayoutParams(urlBarEntryDefaultLayoutParams);
+                    }
                 }
 
                 PropertyAnimator buttonsAnimator = new PropertyAnimator(300);
                 mUrlDisplayLayout.prepareStopEditingAnimation(buttonsAnimator);
                 buttonsAnimator.start();
 
                 mAnimatingEntry = false;