Bug 1379066 - 6. PageAction supports Private Mode draft
authorJulian_Chu <walkingice0204@gmail.com>
Thu, 06 Jul 2017 13:26:16 +0800
changeset 607547 a3566456981d82d568a734b887acf47c6944b52b
parent 607546 8e4aa02b0998c74927537e385115108239d66a39
child 607548 7a82f9b46e7d7ad471300fc38b6c5869312ef750
push id68017
push userbmo:walkingice0204@gmail.com
push dateWed, 12 Jul 2017 10:37:39 +0000
bugs1379066
milestone56.0a1
Bug 1379066 - 6. PageAction supports Private Mode PageAction are views which be added to awesomebar dynamically, for example "Reader mode icon". Now let it becomes ThemedImageButton to support Private mode. MozReview-Commit-ID: HQXgJWL19Oz
mobile/android/app/src/australis/res/values/dimens.xml
mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
--- a/mobile/android/app/src/australis/res/values/dimens.xml
+++ b/mobile/android/app/src/australis/res/values/dimens.xml
@@ -6,16 +6,17 @@
 <resources>
 
     <dimen name="standard_corner_radius">4dp</dimen>
 
     <dimen name="autocomplete_min_width">200dp</dimen>
     <dimen name="autocomplete_row_height">32dp</dimen>
 
     <dimen name="browser_toolbar_height">48dp</dimen>
+    <dimen name="browser_toolbar_image_button_width">@dimen/page_action_button_width</dimen>
     <!-- This value is the height of the Tabs Panel header view
          (browser_toolbar_height) minus the height of the indicator
          (6dp). This value should change when the height of the view changes. -->
     <dimen name="tabs_panel_indicator_selected_padding_top">42dp</dimen>
 
     <!-- We use two different values for browser_toolbar_height on tablet
          which is inconsistent. Temporary value until bug 1150730 is fixed. -->
     <dimen name="browser_toolbar_height_flipper">48dp</dimen>
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java
@@ -3,22 +3,25 @@
  * 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;
@@ -27,17 +30,17 @@ import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 
 import java.util.Iterator;
 import java.util.List;
 import java.util.UUID;
 import java.util.ArrayList;
 
-public class PageActionLayout extends LinearLayout implements BundleEventListener,
+public class PageActionLayout extends ThemedLinearLayout implements BundleEventListener,
                                                               View.OnClickListener,
                                                               View.OnLongClickListener {
     private static final String MENU_BUTTON_KEY = "MENU_BUTTON_KEY";
     private static final int DEFAULT_PAGE_ACTIONS_SHOWN = 2;
 
     private final Context mContext;
     private final LinearLayout mLayout;
     private final List<PageAction> mPageActionList;
@@ -52,34 +55,47 @@ public class PageActionLayout extends Li
         mContext = context;
         mLayout = this;
 
         mPageActionList = new ArrayList<PageAction>();
         setNumberShown(DEFAULT_PAGE_ACTIONS_SHOWN);
         refreshPageActionIcons();
     }
 
+    // Bug 1375351 - should change to protected after bug 1366704 land
     @Override
-    protected void onAttachedToWindow() {
+    public void onAttachedToWindow() {
         super.onAttachedToWindow();
 
         EventDispatcher.getInstance().registerUiThreadListener(this,
             "PageActions:Add",
             "PageActions:Remove");
     }
 
+    // Bug 1375351 - should change to protected after bug 1366704 land
     @Override
-    protected void onDetachedFromWindow() {
+    public void onDetachedFromWindow() {
         EventDispatcher.getInstance().unregisterUiThreadListener(this,
             "PageActions:Add",
             "PageActions:Remove");
 
         super.onDetachedFromWindow();
     }
 
+    @Override
+    public void setPrivateMode(boolean isPrivate) {
+        super.setPrivateMode(isPrivate);
+        for (int i = 0; i < getChildCount(); i++) {
+            View child = getChildAt(i);
+            if (child instanceof ThemedImageButton) {
+                ((ThemedImageButton) child).setPrivateMode(true);
+            }
+        }
+    }
+
     private void setNumberShown(int count) {
         ThreadUtils.assertOnUiThread();
 
         mMaxVisiblePageActions = count;
 
         for (int index = 0; index < count; index++) {
             if ((getChildCount() - 1) < index) {
                 mLayout.addView(createImageButton());
@@ -152,23 +168,31 @@ public class PageActionLayout extends Li
             if (pageAction.getID().equals(id)) {
                 iter.remove();
                 refreshPageActionIcons();
                 return;
             }
         }
     }
 
-    private ImageButton createImageButton() {
+    private ThemedImageButton createImageButton() {
         ThreadUtils.assertOnUiThread();
 
-        final int width = mContext.getResources().getDimensionPixelSize(R.dimen.page_action_button_width);
-        ImageButton imageButton = new ImageButton(mContext, null, R.style.UrlBar_ImageButton);
-        imageButton.setLayoutParams(new LayoutParams(width, LayoutParams.MATCH_PARENT));
-        imageButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
+        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);
+        }
         imageButton.setOnClickListener(this);
         imageButton.setOnLongClickListener(this);
         return imageButton;
     }
 
     @Override
     public void onClick(View v) {
         String buttonClickedId = (String)v.getTag();
@@ -222,16 +246,20 @@ public class PageActionLayout extends Li
             if ((i == this.getChildCount() - 1) && (mPageActionList.size() > mMaxVisiblePageActions)) {
                 v.setTag(MENU_BUTTON_KEY);
                 v.setImageDrawable(resources.getDrawable(R.drawable.icon_pageaction));
                 v.setVisibility((pageAction != null) ? View.VISIBLE : View.GONE);
                 v.setContentDescription(resources.getString(R.string.page_action_dropmarker_description));
             } else {
                 setActionForView(v, pageAction);
             }
+
+            if (v instanceof ThemedImageButton) {
+                ((ThemedImageButton) v).setPrivateMode(isPrivateMode());
+            }
         }
     }
 
     private PageAction getPageActionForViewAt(int index) {
         ThreadUtils.assertOnUiThread();
 
         /**
          * We show the user the most recent pageaction added since this keeps the user aware of any new page actions being added
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -165,16 +165,17 @@ public class ToolbarDisplayLayout extend
         mStop = (ImageButton) findViewById(R.id.stop);
         mPageActionLayout = (PageActionLayout) findViewById(R.id.page_action_layout);
     }
 
     @Override
     public void setPrivateMode(boolean isPrivate) {
         super.setPrivateMode(isPrivate);
         mSiteSecurity.setPrivateMode(isPrivate);
+        mPageActionLayout.setPrivateMode(isPrivate);
     }
 
 
     @Override
     public void onAttachedToWindow() {
         super.onAttachedToWindow();
 
         mIsAttached = true;