Bug 825176 - Use margin to hide forward button. r=sriram
authorWes Johnston <wjohnston@mozilla.com>
Wed, 02 Jan 2013 17:11:15 -0800
changeset 126504 83b7d05f5928247b3aa32700a96ab5dfe90e13a6
parent 126503 25c0a091b6613aac10965c35eea0758e96170673
child 126505 10834aa54577ed087990ffde67b0d3eced7a1d2e
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs825176
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 825176 - Use margin to hide forward button. r=sriram
mobile/android/base/BrowserToolbar.java
mobile/android/base/resources/values-large-v11/styles.xml
mobile/android/base/resources/values/dimens.xml
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -95,16 +95,17 @@ public class BrowserToolbar implements V
     private TranslateAnimation mSlideDownOut;
 
     private AlphaAnimation mLockFadeIn;
     private TranslateAnimation mTitleSlideLeft;
     private TranslateAnimation mTitleSlideRight;
 
     private int mAddressBarViewOffset;
     private int mAddressBarViewOffsetNoForward;
+    private int mDefaultForwardMargin;
     private PropertyAnimator mForwardAnim = null;
 
     private int mCount;
     private int mFaviconSize;
 
     private static final int TABS_CONTRACTED = 1;
     private static final int TABS_EXPANDED = 2;
 
@@ -129,16 +130,17 @@ public class BrowserToolbar implements V
 
         mShowSiteSecurity = false;
         mShowReader = false;
 
         mAddressBarBg = (BrowserToolbarBackground) mLayout.findViewById(R.id.address_bar_bg);
         mAddressBarView = mLayout.findViewById(R.id.addressbar);
         mAddressBarViewOffset = mActivity.getResources().getDimensionPixelSize(R.dimen.addressbar_offset_left);
         mAddressBarViewOffsetNoForward = mActivity.getResources().getDimensionPixelSize(R.dimen.addressbar_offset_left_noforward);
+        mDefaultForwardMargin = mActivity.getResources().getDimensionPixelSize(R.dimen.forward_default_offset);
         mAwesomeBarRightEdge = (GeckoFrameLayout) mLayout.findViewById(R.id.awesome_bar_right_edge);
         mAwesomeBarEntry = mLayout.findViewById(R.id.awesome_bar_entry);
 
         // This will hold the translation width inside the toolbar when the tabs
         // pane is visible. It will affect the padding applied to the title TextView.
         mTabsPaneWidth = 0;
 
         mTitle = (GeckoTextView) mLayout.findViewById(R.id.awesome_bar_title);
@@ -999,17 +1001,17 @@ public class BrowserToolbar implements V
         // Save the state on the forward button so that we can skip animations
         // when there's nothing to change
         mForward.setEnabled(enabled);
 
         if (mForward.getVisibility() != View.VISIBLE)
             return;
 
         mForwardAnim = new PropertyAnimator(FORWARD_ANIMATION_DURATION);
-        final int width = enabled ? mForward.getWidth()/2 : 0;
+        final int width = mForward.getWidth()/2;
 
         mForwardAnim.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
             @Override
             public void onPropertyAnimationStart() {
                 if (!enabled) {
                     // Set the margin before the transition when hiding the forward button. We
                     // have to do this so that the favicon isn't clipped during the transition
                     ViewGroup.MarginLayoutParams layoutParams =
@@ -1031,30 +1033,37 @@ public class BrowserToolbar implements V
 
                     AnimatorProxy proxy = AnimatorProxy.create(mTitle);
                     proxy.setTranslationX(0);
                     proxy = AnimatorProxy.create(mFavicon);
                     proxy.setTranslationX(0);
                     proxy = AnimatorProxy.create(mSiteSecurity);
                     proxy.setTranslationX(0);
 
-                    mAddressBarView.requestLayout();
                 }
+
+                ViewGroup.MarginLayoutParams layoutParams =
+                    (ViewGroup.MarginLayoutParams)mForward.getLayoutParams();
+                layoutParams.leftMargin = mDefaultForwardMargin + (mForward.isEnabled() ? mForward.getWidth()/2 : 0);
+                AnimatorProxy proxy = AnimatorProxy.create(mForward);
+                proxy.setTranslationX(0);
+
+                mAddressBarView.requestLayout();
                 mForwardAnim = null;
             }
         });
-        prepareForwardAnimation(mForwardAnim, width);
+        prepareForwardAnimation(mForwardAnim, enabled, width);
         mForwardAnim.start();
     }
 
-    private void prepareForwardAnimation(PropertyAnimator anim, int width) {
-        if (width == 0) {
+    private void prepareForwardAnimation(PropertyAnimator anim, boolean enabled, int width) {
+        if (!enabled) {
             anim.attach(mForward,
                       PropertyAnimator.Property.TRANSLATION_X,
-                      0);
+                      -1*width);
             anim.attach(mForward,
                       PropertyAnimator.Property.ALPHA,
                       0);
             anim.attach(mTitle,
                       PropertyAnimator.Property.TRANSLATION_X,
                       0);
             anim.attach(mFavicon,
                       PropertyAnimator.Property.TRANSLATION_X,
--- a/mobile/android/base/resources/values-large-v11/styles.xml
+++ b/mobile/android/base/resources/values-large-v11/styles.xml
@@ -37,17 +37,17 @@
         <item name="android:layout_height">38dip</item>
         <item name="android:paddingLeft">22dp</item>
         <item name="android:layout_gravity">center_vertical</item>
         <item name="android:layout_centerVertical">true</item>
         <item name="android:src">@drawable/ic_menu_forward</item>
         <item name="android:background">@drawable/address_bar_nav_button</item>
         <!-- Start with the button hidden -->
         <item name="android:alpha">0</item>
-        <item name="android:layout_marginLeft">-11dp</item>
+        <item name="android:layout_marginLeft">@dimen/forward_default_offset</item>
     </style>
 
    <style name="AddressBar.Button.Container">
         <item name="android:layout_marginTop">6dp</item>
         <item name="android:layout_marginBottom">6dp</item>
         <item name="android:layout_marginRight">0dp</item>
         <!-- Start with forward hidden -->
         <item name="android:layout_marginLeft">@dimen/addressbar_offset_left_noforward</item>
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -49,16 +49,17 @@
     <dimen name="tabs_counter_size">22sp</dimen>
     <dimen name="tabs_list_divider_height">2dp</dimen>
     <dimen name="text_selection_handle_width">30dp</dimen>
     <dimen name="text_selection_handle_height">44dp</dimen>
     <dimen name="text_selection_handle_shadow">2dp</dimen>
     <dimen name="validation_message_height">50dp</dimen>
     <dimen name="validation_message_margin_top">6dp</dimen>
     <dimen name="widget_padding">8dp</dimen>
+    <dimen name="forward_default_offset">-11dip</dimen>
 
     <dimen name="addressbar_offset_left">90dp</dimen>
     <dimen name="addressbar_offset_left_noforward">50dip</dimen>
     <dimen name="app_defaultsize_w">632.0dip</dimen>
     <dimen name="app_defaultsize_h">598.0dip</dimen>
     <dimen name="app_minimumsize_w">632.0dip</dimen>
     <dimen name="app_minimumsize_h">598.0dip</dimen>