Fix issue with icon being loaded by the wrong context
- Fixing a regression from ag/12184846 (Reduce ContextThemeWrapper usage), the context used to load the icons (which references a color in the theme) was not the light context. This was only an issue with ContextualButtons which loaded their icons separate from nav bar view Bug: 162784729 Test: Verify ime switcher and accessibility buttons are visible Test: atest SystemUITests:NavigationBarContextTest Change-Id: I7e18cd68889b2b4215fc817becd6412a466c8da5
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user