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
This commit is contained in:
Julian_Chu 2017-07-06 13:26:16 +08:00
Родитель 3dd2a66301
Коммит 192615787d
3 изменённых файлов: 38 добавлений и 8 удалений

Просмотреть файл

@ -11,6 +11,7 @@
<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. -->

Просмотреть файл

@ -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();
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 imageButton = new ImageButton(mContext, null, R.style.UrlBar_ImageButton);
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());
}
}
}

Просмотреть файл

@ -170,6 +170,7 @@ public class ToolbarDisplayLayout extends ThemedLinearLayout {
public void setPrivateMode(boolean isPrivate) {
super.setPrivateMode(isPrivate);
mSiteSecurity.setPrivateMode(isPrivate);
mPageActionLayout.setPrivateMode(isPrivate);
}