From 192615787d95de16e093a6984c1d3610811ade7d Mon Sep 17 00:00:00 2001 From: Julian_Chu Date: Thu, 6 Jul 2017 13:26:16 +0800 Subject: [PATCH] Bug 1379066 - 6. PageAction supports Private Mode r=jwu 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 --HG-- extra : rebase_source : 8428d005875c1c1b24e72fb9ef431060b8b02b5a --- .../app/src/australis/res/values/dimens.xml | 1 + .../gecko/toolbar/PageActionLayout.java | 44 +++++++++++++++---- .../gecko/toolbar/ToolbarDisplayLayout.java | 1 + 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/mobile/android/app/src/australis/res/values/dimens.xml b/mobile/android/app/src/australis/res/values/dimens.xml index d4c63c8bc811..68d722387f3e 100644 --- a/mobile/android/app/src/australis/res/values/dimens.xml +++ b/mobile/android/app/src/australis/res/values/dimens.xml @@ -11,6 +11,7 @@ 32dp 48dp + @dimen/page_action_button_width diff --git a/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java b/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java index cac1aa6fe975..7ade347f943e 100644 --- a/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java +++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/PageActionLayout.java @@ -8,12 +8,15 @@ 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; @@ -32,7 +35,7 @@ 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"; @@ -57,8 +60,9 @@ public class PageActionLayout extends LinearLayout implements BundleEventListene refreshPageActionIcons(); } + // Bug 1375351 - should change to protected after bug 1366704 land @Override - protected void onAttachedToWindow() { + public void onAttachedToWindow() { super.onAttachedToWindow(); EventDispatcher.getInstance().registerUiThreadListener(this, @@ -66,8 +70,9 @@ public class PageActionLayout extends LinearLayout implements BundleEventListene "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"); @@ -75,6 +80,17 @@ public class PageActionLayout extends LinearLayout implements BundleEventListene 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(); @@ -157,13 +173,21 @@ public class PageActionLayout extends LinearLayout implements BundleEventListene } } - 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; @@ -227,6 +251,10 @@ public class PageActionLayout extends LinearLayout implements BundleEventListene } else { setActionForView(v, pageAction); } + + if (v instanceof ThemedImageButton) { + ((ThemedImageButton) v).setPrivateMode(isPrivateMode()); + } } } diff --git a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java index 57b18777c270..ea37b5f3faad 100644 --- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java +++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java @@ -170,6 +170,7 @@ public class ToolbarDisplayLayout extends ThemedLinearLayout { public void setPrivateMode(boolean isPrivate) { super.setPrivateMode(isPrivate); mSiteSecurity.setPrivateMode(isPrivate); + mPageActionLayout.setPrivateMode(isPrivate); }