Bug 1366668 - Part 5: Introduce ActionButton to support toolbar item with round rectangle background. r?nechen,walkingice draft
authorJing-wei Wu <topwu.tw@gmail.com>
Tue, 01 Aug 2017 17:34:30 +0800
changeset 619541 7a65a246e85b85d3afd7010b837cd27a45c2c98b
parent 619540 b9488ca26d1ba3a08dc88fb7c7ad5f620bc95731
child 640421 c530d685ff279c4b4bfd2458b0776084144e9b6a
push id71705
push userbmo:topwu.tw@gmail.com
push dateWed, 02 Aug 2017 06:32:50 +0000
reviewersnechen, walkingice
bugs1366668
milestone56.0a1
Bug 1366668 - Part 5: Introduce ActionButton to support toolbar item with round rectangle background. r?nechen,walkingice Implement a custom shaped button to describe the background of tool bar item. MozReview-Commit-ID: 1wmDCdzb2XZ
mobile/android/app/src/australis/java/org/mozilla/gecko/toolbar/ActionButton.java
mobile/android/app/src/photon/java/org/mozilla/gecko/toolbar/ActionButton.java
mobile/android/app/src/photon/res/drawable/url_bar_action_button.xml
mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java
mobile/android/base/java/org/mozilla/gecko/toolbar/ShapedButton.java
new file mode 100644
--- /dev/null
+++ b/mobile/android/app/src/australis/java/org/mozilla/gecko/toolbar/ActionButton.java
@@ -0,0 +1,25 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 android.content.Context;
+import android.util.AttributeSet;
+
+import org.mozilla.gecko.widget.themed.ThemedImageButton;
+
+class ActionButton extends ThemedImageButton {
+
+    public ActionButton(Context context) {
+        this(context, null);
+    }
+
+    public ActionButton(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public ActionButton(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/app/src/photon/java/org/mozilla/gecko/toolbar/ActionButton.java
@@ -0,0 +1,57 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Path;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.StateListDrawable;
+import android.util.AttributeSet;
+
+import org.mozilla.gecko.R;
+
+class ActionButton extends ShapedButton {
+
+    public ActionButton(Context context) {
+        this(context, null);
+    }
+
+    public ActionButton(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public ActionButton(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+
+        setPrivateMode(false);
+    }
+
+    @Override
+    protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
+        super.onSizeChanged(width, height, oldWidth, oldHeight);
+
+        mPath.reset();
+        mPath.setFillType(Path.FillType.INVERSE_EVEN_ODD);
+
+        final Resources res = getResources();
+        final int vSpace = res.getDimensionPixelSize(R.dimen.browser_toolbar_image_button_v_spacing);
+        final int hSpace = res.getDimensionPixelSize(R.dimen.browser_toolbar_image_button_h_spacing);
+        final RectF rect = new RectF(hSpace, vSpace, width - hSpace, height - vSpace);
+        final int radius = res.getDimensionPixelSize(R.dimen.browser_toolbar_menu_radius);
+        mPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
+    }
+
+    @Override
+    public void onLightweightThemeChanged() {
+        setBackgroundResource(R.drawable.url_bar_action_button);
+    }
+
+    @Override
+    public void onLightweightThemeReset() {
+        setBackgroundResource(R.drawable.url_bar_action_button);
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/app/src/photon/res/drawable/url_bar_action_button.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - 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/. -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android"
+          xmlns:gecko="http://schemas.android.com/apk/res-auto">
+
+    <!-- private browsing mode -->
+    <item android:drawable="@color/action_bar_item_bg_color_private_pressed"
+          android:state_enabled="true"
+          android:state_focused="true"
+          gecko:state_private="true"/>
+
+    <item android:drawable="@color/action_bar_item_bg_color_private_pressed"
+          android:state_enabled="true"
+          android:state_pressed="true"
+          gecko:state_private="true"/>
+
+    <!-- normal mode -->
+    <item android:drawable="@color/action_bar_item_bg_color_pressed"
+          android:state_enabled="true"
+          android:state_focused="true"/>
+
+    <item android:drawable="@color/action_bar_item_bg_color_pressed"
+          android:state_enabled="true"
+          android:state_pressed="true"/>
+
+    <item android:drawable="@android:color/transparent"/>
+
+</selector>
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java
@@ -1,32 +1,29 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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.EventDispatcher;
-import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.R;
-import org.mozilla.gecko.skin.SkinConfig;
 import org.mozilla.gecko.util.ResourceDrawableUtils;
 import org.mozilla.gecko.util.BundleEventListener;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.widget.GeckoPopupMenu;
 import org.mozilla.gecko.widget.themed.ThemedImageButton;
 import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
-import android.os.Bundle;
 import android.util.AttributeSet;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 
@@ -171,28 +168,20 @@ public class PageActionLayout extends Th
                 return;
             }
         }
     }
 
     private ThemedImageButton createImageButton() {
         ThreadUtils.assertOnUiThread();
 
-        ThemedImageButton imageButton = new ThemedImageButton(mContext, null, R.style.UrlBar_ImageButton);
-        // bug 1375351: different appearance in two skin
-        if (SkinConfig.isAustralis()) {
-            final int width = mContext.getResources().getDimensionPixelSize(R.dimen.page_action_button_width);
-            imageButton.setLayoutParams(new LayoutParams(width, LayoutParams.MATCH_PARENT));
-            imageButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
-        } else {
-            final int width = mContext.getResources().getDimensionPixelSize(R.dimen.browser_toolbar_image_button_width);
-            imageButton.setLayoutParams(new LayoutParams(width, LayoutParams.MATCH_PARENT));
-            imageButton.setBackgroundResource(R.drawable.action_bar_button);
-            imageButton.setScaleType(ImageView.ScaleType.CENTER);
-        }
+        final ActionButton imageButton = new ActionButton(mContext, null, R.style.UrlBar_ImageButton);
+        final int width = mContext.getResources().getDimensionPixelSize(R.dimen.page_action_button_width);
+        imageButton.setLayoutParams(new LayoutParams(width, LayoutParams.MATCH_PARENT));
+        imageButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
         imageButton.setOnClickListener(this);
         imageButton.setOnLongClickListener(this);
         return imageButton;
     }
 
     @Override
     public void onClick(View v) {
         String buttonClickedId = (String)v.getTag();
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ShapedButton.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ShapedButton.java
@@ -26,17 +26,21 @@ import android.util.AttributeSet;
  */
 public class ShapedButton extends ThemedImageButton
                           implements CanvasDelegate.DrawManager {
 
     protected final Path mPath;
     protected final CanvasDelegate mCanvasDelegate;
 
     public ShapedButton(Context context, AttributeSet attrs) {
-        super(context, attrs);
+        this(context, attrs, 0);
+    }
+
+    public ShapedButton(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
 
         // Path is clipped.
         mPath = new Path();
 
         final Paint paint = new Paint();
         paint.setAntiAlias(true);
         paint.setColor(ContextCompat.getColor(context, R.color.canvas_delegate_paint));
         paint.setStrokeWidth(0.0f);