summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Winson Chung <winsonc@google.com> 2020-08-05 20:16:27 -0700
committer Winson Chung <winsonc@google.com> 2020-08-06 20:01:19 +0000
commit88332bba320b80c4e6b0ef5adef9692455af79e3 (patch)
treedb7f0afbe82bba30a68f8a3f5472428c348f70ef
parentf1a408f2080c78a9258f59faeedd18fcb483985f (diff)
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
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/ContextualButton.java18
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java1
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationContextButton.java9
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarContextTest.java6
5 files changed, 20 insertions, 21 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ContextualButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ContextualButton.java
index 53b369c3543e..eb476457dcec 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ContextualButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ContextualButton.java
@@ -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 {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
index 84512ac85fa9..0b4a2b69ffb3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -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) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java
index f83cdd488c04..b0630a649ffe 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java
@@ -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);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationContextButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationContextButton.java
index d7e95e43ea8f..08aeb0425f68 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationContextButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationContextButton.java
@@ -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
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarContextTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarContextTest.java
index b5060ee416f7..1fb28f0878bd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarContextTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarContextTest.java
@@ -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);