Merge "Fix issue with icon being loaded by the wrong context"

This commit is contained in:
TreeHugger Robot
2020-08-06 21:56:09 +00:00
committed by Android (Google) Code Review
5 changed files with 20 additions and 21 deletions

View File

@@ -34,6 +34,7 @@ public class ContextualButton extends ButtonDispatcher {
private ContextButtonListener mListener;
private ContextualButtonGroup mGroup;
protected final Context mLightContext;
protected final @DrawableRes int mIconResId;
/**
@@ -42,8 +43,10 @@ public class ContextualButton extends ButtonDispatcher {
* @param buttonResId the button view from xml layout
* @param iconResId icon resource to be used
*/
public ContextualButton(@IdRes int buttonResId, @DrawableRes int iconResId) {
public ContextualButton(@IdRes int buttonResId, Context lightContext,
@DrawableRes int iconResId) {
super(buttonResId);
mLightContext = lightContext;
mIconResId = iconResId;
}
@@ -117,17 +120,8 @@ public class ContextualButton extends ButtonDispatcher {
}
protected KeyButtonDrawable getNewDrawable(int lightIconColor, int darkIconColor) {
return KeyButtonDrawable.create(getContext().getApplicationContext(), lightIconColor,
darkIconColor, mIconResId, false /* shadow */, null /* ovalBackground */);
}
/**
* This context is from the view that could be stale after rotation or config change. To get
* correct resources use getApplicationContext() as well.
* @return current view context
*/
protected Context getContext() {
return getCurrentView().getContext();
return KeyButtonDrawable.create(mLightContext, lightIconColor, darkIconColor, mIconResId,
false /* shadow */, null /* ovalBackground */);
}
public interface ContextButtonListener {

View File

@@ -295,11 +295,12 @@ public class NavigationBarView extends FrameLayout implements
// Set up the context group of buttons
mContextualButtonGroup = new ContextualButtonGroup(R.id.menu_container);
final ContextualButton imeSwitcherButton = new ContextualButton(R.id.ime_switcher,
R.drawable.ic_ime_switcher_default);
mLightContext, R.drawable.ic_ime_switcher_default);
final RotationContextButton rotateSuggestionButton = new RotationContextButton(
R.id.rotate_suggestion, R.drawable.ic_sysbar_rotate_button_ccw_start_0);
R.id.rotate_suggestion, mLightContext,
R.drawable.ic_sysbar_rotate_button_ccw_start_0);
final ContextualButton accessibilityButton =
new ContextualButton(R.id.accessibility_button,
new ContextualButton(R.id.accessibility_button, mLightContext,
R.drawable.ic_sysbar_accessibility_button);
mContextualButtonGroup.addButton(imeSwitcherButton);
if (!isGesturalMode) {

View File

@@ -283,7 +283,6 @@ public class RotationButtonController {
return;
}
// TODO: Remove styles?
// Prepare to show the navbar icon by updating the icon style to change anim params
mLastRotationSuggestion = rotation; // Remember rotation for click
final boolean rotationCCW = isRotationAnimationCCW(windowRotation, rotation);

View File

@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.phone;
import android.annotation.DrawableRes;
import android.annotation.IdRes;
import android.content.Context;
import android.view.View;
import com.android.systemui.statusbar.policy.KeyButtonDrawable;
@@ -28,8 +29,12 @@ public class RotationContextButton extends ContextualButton implements RotationB
private RotationButtonController mRotationButtonController;
public RotationContextButton(@IdRes int buttonResId, @DrawableRes int iconResId) {
super(buttonResId, iconResId);
/**
* @param lightContext the context to use to load the icon resource
*/
public RotationContextButton(@IdRes int buttonResId, Context lightContext,
@DrawableRes int iconResId) {
super(buttonResId, lightContext, iconResId);
}
@Override

View File

@@ -65,9 +65,9 @@ public class NavigationBarContextTest extends SysuiTestCase {
mDependency.injectMockDependency(AssistManager.class);
mGroup = new ContextualButtonGroup(GROUP_ID);
mBtn0 = new ContextualButton(BUTTON_0_ID, ICON_RES_ID);
mBtn1 = new ContextualButton(BUTTON_1_ID, ICON_RES_ID);
mBtn2 = new ContextualButton(BUTTON_2_ID, ICON_RES_ID);
mBtn0 = new ContextualButton(BUTTON_0_ID, mContext, ICON_RES_ID);
mBtn1 = new ContextualButton(BUTTON_1_ID, mContext, ICON_RES_ID);
mBtn2 = new ContextualButton(BUTTON_2_ID, mContext, ICON_RES_ID);
// Order of adding buttons to group determines the priority, ascending priority order
mGroup.addButton(mBtn0);