Bug 1379066 - 3. Simplify Toolbar menu in Photon flavor
authorJulian_Chu <walkingice0204@gmail.com>
Thu, 22 Jun 2017 17:33:01 +0800
changeset 1180214 47acff87d47c15a8bf344e8cbe0163c9925eb80d
parent 1180213 b39ebc0732dd5714bfdd7746938f08575719a20e
child 1180215 2a92409b9b54e1f07ff6741ab41567775d74c8af
push id203611
push usertopwu.tw@gmail.com
push dateMon, 10 Jul 2017 10:11:07 +0000
treeherdertry@8d2f2bebdeb1 [default view] [failures only]
bugs1379066
milestone56.0a1
Bug 1379066 - 3. Simplify Toolbar menu in Photon flavor In Photon flavor, only one view for menu button is enough. This patch is to merge menu and menu-icon into one ThemedImageButton. MozReview-Commit-ID: KyjsriirmbA
mobile/android/app/src/main/res/values/ids.xml
mobile/android/app/src/photon/res/layout-large-v11/browser_toolbar.xml
mobile/android/app/src/photon/res/layout/browser_toolbar.xml
mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarPhone.java
mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarPhoneBase.java
mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarTabletBase.java
--- a/mobile/android/app/src/main/res/values/ids.xml
+++ b/mobile/android/app/src/main/res/values/ids.xml
@@ -19,9 +19,11 @@
     <item type="id" name="updateServicePermissionNotification" />
     <item type="id" name="websiteContentNotification" />
     <item type="id" name="foregroundNotification" />
     <item type="id" name="actionbar"/>
     <item type="id" name="action_button"/>
     <item type="id" name="page_progress"/>
     <item type="id" name="mediaControlNotification"/>
 
+    <!-- add this id to make java code pass build. should be removed in Bug 1375351 -->
+    <item type="id" name="menu_icon"/>
 </resources>
--- a/mobile/android/app/src/photon/res/layout-large-v11/browser_toolbar.xml
+++ b/mobile/android/app/src/photon/res/layout-large-v11/browser_toolbar.xml
@@ -101,33 +101,23 @@
     <View
         android:id="@id/menu_margin"
         style="@style/UrlBar.MenuMargin"
         android:layout_width="6dp"
         android:layout_height="match_parent"
         android:clickable="true"
         android:visibility="gone" />
 
-    <org.mozilla.gecko.widget.themed.ThemedFrameLayout
+    <org.mozilla.gecko.widget.themed.ThemedImageButton
         android:id="@+id/menu"
         style="@style/UrlBar.Menu"
         android:layout_alignWithParentIfMissing="true"
         android:background="@drawable/browser_toolbar_action_bar_button"
-        android:contentDescription="@string/menu">
-
-        <org.mozilla.gecko.widget.themed.ThemedImageView
-            android:id="@+id/menu_icon"
-            style="@style/UrlBar.ImageButton.BrowserToolbarColors"
-            android:layout_width="wrap_content"
-            android:layout_height="@dimen/browser_toolbar_menu_icon_height"
-            android:layout_gravity="center"
-            android:scaleType="centerInside"
-            android:src="@drawable/menu" />
-
-    </org.mozilla.gecko.widget.themed.ThemedFrameLayout>
+        android:contentDescription="@string/menu"
+        android:src="@drawable/menu" />
 
     <!-- We draw after the menu items so when they are hidden, the cancel button,
          which is thus drawn on top, may be pressed. -->
     <org.mozilla.gecko.widget.themed.ThemedImageView
         android:id="@+id/edit_cancel"
         style="@style/UrlBar.EditCancel"
         android:layout_width="@dimen/browser_toolbar_icon_width"
         android:layout_height="@dimen/browser_toolbar_height"
--- a/mobile/android/app/src/photon/res/layout/browser_toolbar.xml
+++ b/mobile/android/app/src/photon/res/layout/browser_toolbar.xml
@@ -29,35 +29,24 @@
         android:layout_alignTop="@id/url_bar_entry"
         android:clickable="false"
         android:duplicateParentState="true"
         android:focusable="false"
         android:scaleType="fitXY"
         android:src="@drawable/url_bar_translating_edge"
         android:visibility="invisible" />
 
-    <org.mozilla.gecko.toolbar.ShapedButtonFrameLayout
+    <org.mozilla.gecko.widget.themed.ThemedImageButton
         android:id="@+id/menu"
         style="@style/UrlBar.Menu"
-        android:background="@drawable/shaped_button"
-        android:contentDescription="@string/menu">
+        android:background="@drawable/action_bar_button"
+        android:contentDescription="@string/menu"
+        android:src="@drawable/menu" />
 
-        <org.mozilla.gecko.widget.themed.ThemedImageView
-            android:id="@+id/menu_icon"
-            style="@style/UrlBar.ImageButton"
-            android:layout_width="wrap_content"
-            android:layout_height="@dimen/browser_toolbar_menu_icon_height"
-            android:layout_gravity="center"
-            android:scaleType="centerInside"
-            android:src="@drawable/menu"
-            android:tint="@color/tabs_tray_icon_grey" />
-
-    </org.mozilla.gecko.toolbar.ShapedButtonFrameLayout>
-
-    <org.mozilla.gecko.toolbar.PhoneTabsButton
+    <org.mozilla.gecko.widget.themed.ThemedImageButton
         android:id="@+id/tabs"
         style="@style/UrlBar.Tabs"
         android:layout_width="64dip"
         android:layout_alignWithParentIfMissing="true"
         android:background="@drawable/shaped_button" />
 
     <!-- The TextSwitcher should be shifted 24dp on the left, to avoid
          the curve. On a 48dp space, centering 24dp image will leave
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
@@ -25,24 +25,24 @@ import org.mozilla.gecko.TouchEventInter
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.PropertyAnimator.PropertyAnimationListener;
 import org.mozilla.gecko.animation.ViewHelper;
 import org.mozilla.gecko.lwt.LightweightTheme;
 import org.mozilla.gecko.lwt.LightweightThemeDrawable;
 import org.mozilla.gecko.menu.GeckoMenu;
 import org.mozilla.gecko.menu.MenuPopup;
 import org.mozilla.gecko.preferences.GeckoPreferences;
+import org.mozilla.gecko.skin.SkinConfig;
 import org.mozilla.gecko.tabs.TabHistoryController;
 import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.OnStopListener;
 import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.OnTitleChangeListener;
 import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.UpdateFlags;
 import org.mozilla.gecko.util.Clipboard;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.MenuUtils;
-import org.mozilla.gecko.widget.themed.ThemedFrameLayout;
 import org.mozilla.gecko.widget.themed.ThemedImageButton;
 import org.mozilla.gecko.widget.themed.ThemedImageView;
 import org.mozilla.gecko.widget.themed.ThemedRelativeLayout;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Paint;
@@ -119,17 +119,18 @@ public abstract class BrowserToolbar ext
     protected final ToolbarDisplayLayout urlDisplayLayout;
     protected final ToolbarEditLayout urlEditLayout;
     protected final View urlBarEntry;
     protected boolean isSwitchingTabs;
     protected final ThemedImageButton tabsButton;
 
     private ToolbarProgressView progressBar;
     protected final TabCounter tabsCounter;
-    protected final ThemedFrameLayout menuButton;
+    protected final View menuButton;
+    // bug 1375351: There is no menuIcon in Photon flavor, menuIcon should be removed
     protected final ThemedImageView menuIcon;
     private MenuPopup menuPopup;
     protected final List<View> focusOrder;
 
     private OnActivateListener activateListener;
     private OnFocusChangeListener focusChangeListener;
     private OnStartEditingListener startEditingListener;
     private OnStopEditingListener stopEditingListener;
@@ -190,17 +191,17 @@ public abstract class BrowserToolbar ext
         urlDisplayLayout = (ToolbarDisplayLayout) findViewById(R.id.display_layout);
         urlBarEntry = findViewById(R.id.url_bar_entry);
         urlEditLayout = (ToolbarEditLayout) findViewById(R.id.edit_layout);
 
         tabsButton = (ThemedImageButton) findViewById(R.id.tabs);
         tabsCounter = (TabCounter) findViewById(R.id.tabs_counter);
         tabsCounter.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
 
-        menuButton = (ThemedFrameLayout) findViewById(R.id.menu);
+        menuButton = findViewById(R.id.menu);
         menuIcon = (ThemedImageView) findViewById(R.id.menu_icon);
 
         // The focusOrder List should be filled by sub-classes.
         focusOrder = new ArrayList<View>();
 
         final Resources res = getResources();
         shadowSize = res.getDimensionPixelSize(R.dimen.browser_toolbar_shadow_size);
 
@@ -834,19 +835,25 @@ public abstract class BrowserToolbar ext
         return url;
     }
 
     @Override
     public void setPrivateMode(boolean isPrivate) {
         super.setPrivateMode(isPrivate);
 
         tabsButton.setPrivateMode(isPrivate);
-        menuButton.setPrivateMode(isPrivate);
         urlEditLayout.setPrivateMode(isPrivate);
 
+        // bug 1375351: menuButton is a ThemedImageButton in Photon flavor
+        if (SkinConfig.isPhoton()) {
+            ((ThemedImageButton)menuButton).setPrivateMode(isPrivate);
+        } else {
+            ((ShapedButtonFrameLayout)menuButton).setPrivateMode(isPrivate);
+        }
+
         shadowPaint.setColor(isPrivate ? shadowPrivateColor : shadowColor);
     }
 
     public void show() {
         setVisibility(View.VISIBLE);
     }
 
     public void hide() {
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarPhone.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarPhone.java
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.toolbar;
 
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.PropertyAnimator.PropertyAnimationListener;
+import org.mozilla.gecko.skin.SkinConfig;
 import org.mozilla.gecko.util.HardwareUtils;
 
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.View;
 
 /**
  * A toolbar implementation for phones.
@@ -116,13 +117,17 @@ class BrowserToolbarPhone extends Browse
                         PropertyAnimator.Property.TRANSLATION_X,
                         curveTranslation);
         animator.attach(tabsCounter,
                         PropertyAnimator.Property.TRANSLATION_X,
                         curveTranslation);
         animator.attach(menuButton,
                         PropertyAnimator.Property.TRANSLATION_X,
                         curveTranslation);
-        animator.attach(menuIcon,
-                        PropertyAnimator.Property.TRANSLATION_X,
-                        curveTranslation);
+
+        // bug 1375351: menuIcon only exists in Australis flavor
+        if (SkinConfig.isAustralis()) {
+            animator.attach(menuIcon,
+                    PropertyAnimator.Property.TRANSLATION_X,
+                    curveTranslation);
+        }
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarPhoneBase.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarPhoneBase.java
@@ -9,16 +9,17 @@ import java.util.Arrays;
 
 import android.support.v4.content.ContextCompat;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.ViewHelper;
+import org.mozilla.gecko.skin.SkinConfig;
 import org.mozilla.gecko.widget.themed.ThemedImageView;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Path;
 import android.support.v4.view.ViewCompat;
@@ -142,28 +143,43 @@ abstract class BrowserToolbarPhoneBase e
             canvas.drawPath(roundCornerShape, roundCornerPaint);
         }
     }
 
     @Override
     public void triggerTabsPanelTransition(final PropertyAnimator animator, final boolean areTabsShown) {
         if (areTabsShown) {
             ViewHelper.setAlpha(tabsCounter, 0.0f);
-            ViewHelper.setAlpha(menuIcon, 0.0f);
+
+            // bug 1375351: menuIcon only exists in Australis flavor
+            if (SkinConfig.isAustralis()) {
+                ViewHelper.setAlpha(menuIcon, 0.0f);
+            } else {
+                ViewHelper.setAlpha(menuButton, 0.0f);
+            }
             return;
         }
 
         final PropertyAnimator buttonsAnimator =
                 new PropertyAnimator(animator.getDuration(), buttonsInterpolator);
         buttonsAnimator.attach(tabsCounter,
                                PropertyAnimator.Property.ALPHA,
                                1.0f);
-        buttonsAnimator.attach(menuIcon,
-                               PropertyAnimator.Property.ALPHA,
-                               1.0f);
+
+        // bug 1375351: menuIcon only exists in Australis flavor
+        if (SkinConfig.isAustralis()) {
+            buttonsAnimator.attach(menuIcon,
+                    PropertyAnimator.Property.ALPHA,
+                    1.0f);
+        } else {
+            buttonsAnimator.attach(menuButton,
+                    PropertyAnimator.Property.ALPHA,
+                    1.0f);
+        }
+
         buttonsAnimator.start();
     }
 
     /**
      * Returns the number of pixels the url bar translating edge
      * needs to translate to the right to enter its editing mode state.
      * A negative value means the edge must translate to the left.
      */
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarTabletBase.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarTabletBase.java
@@ -10,16 +10,17 @@ import java.util.Arrays;
 import android.support.v4.content.ContextCompat;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.skin.SkinConfig;
 import org.mozilla.gecko.tabs.TabHistoryController;
 import org.mozilla.gecko.menu.MenuItemActionBar;
 import org.mozilla.gecko.util.HardwareUtils;
+import org.mozilla.gecko.widget.themed.ThemedImageButton;
 import org.mozilla.gecko.widget.themed.ThemedTextView;
 
 import android.content.Context;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffColorFilter;
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.ViewGroup.LayoutParams;
@@ -151,17 +152,26 @@ abstract class BrowserToolbarTabletBase 
             // code in favor of setPrivateMode (bug 1197432).
             final PorterDuffColorFilter colorFilter =
                     isPrivate ? privateBrowsingTabletMenuItemColorFilter : null;
             setTabsCounterPrivateMode(isPrivate, colorFilter);
         }
 
         backButton.setPrivateMode(isPrivate);
         forwardButton.setPrivateMode(isPrivate);
-        menuIcon.setPrivateMode(isPrivate);
+
+        // bug 1375351: menuButton is a ThemedImageButton in Photon flavor
+        if (SkinConfig.isPhoton()) {
+            ((ThemedImageButton)menuButton).setPrivateMode(isPrivate);
+        } else {
+            ((ShapedButtonFrameLayout)menuButton).setPrivateMode(isPrivate);
+            // menuIcon only exists in Australis flavor
+            menuIcon.setPrivateMode(isPrivate);
+        }
+
         for (int i = 0; i < actionItemBar.getChildCount(); ++i) {
             final MenuItemActionBar child = (MenuItemActionBar) actionItemBar.getChildAt(i);
             child.setPrivateMode(isPrivate);
         }
     }
 
     private void setTabsCounterPrivateMode(final boolean isPrivate, final PorterDuffColorFilter colorFilter) {
         // The TabsCounter is a TextSwitcher which cycles two views