OSDN Git Service

Apply prior tint to rotate icon on recreation
authorMike Digman <digman@google.com>
Tue, 6 Mar 2018 21:08:33 +0000 (13:08 -0800)
committerMike Digman <digman@google.com>
Wed, 7 Mar 2018 22:47:22 +0000 (22:47 +0000)
In very rare circumstances, it's possible for the rotate icon
to be recreated but not have the dark intensity set. Fix this
by applying prior icon's intensity.

Test: manual but heisenbug so very hard to validate
Fixes: 74354524
Change-Id: I042de35e725794b04f5250fa3a2fc5a54d65d143

packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
packages/SystemUI/src/com/android/systemui/statusbar/policy/TintedKeyButtonDrawable.java

index 74fbed1..6e60179 100644 (file)
@@ -117,7 +117,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
     private KeyButtonDrawable mImeIcon;
     private KeyButtonDrawable mMenuIcon;
     private KeyButtonDrawable mAccessibilityIcon;
-    private KeyButtonDrawable mRotateSuggestionIcon;
+    private TintedKeyButtonDrawable mRotateSuggestionIcon;
 
     private GestureHelper mGestureHelper;
     private DeadZone mDeadZone;
@@ -475,7 +475,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
                 darkContext.getDrawable(darkIcon));
     }
 
-    private KeyButtonDrawable getDrawable(Context ctx, @DrawableRes int icon,
+    private TintedKeyButtonDrawable getDrawable(Context ctx, @DrawableRes int icon,
             @ColorInt int lightColor, @ColorInt int darkColor) {
         return TintedKeyButtonDrawable.create(ctx.getDrawable(icon), lightColor, darkColor);
     }
@@ -746,8 +746,15 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
         Context rotateContext = new ContextThemeWrapper(ctx, style);
 
         // Recreate the icon and set it if needed
+        TintedKeyButtonDrawable priorIcon = mRotateSuggestionIcon;
         mRotateSuggestionIcon = getDrawable(rotateContext, R.drawable.ic_sysbar_rotate_button,
                 lightColor, darkColor);
+
+        // Apply any prior set dark intensity
+        if (priorIcon != null && priorIcon.isDarkIntensitySet()) {
+            mRotateSuggestionIcon.setDarkIntensity(priorIcon.getDarkIntensity());
+        }
+
         if (setIcon) getRotateSuggestionButton().setImageDrawable(mRotateSuggestionIcon);
     }
 
index acf9c00..56f6726 100644 (file)
@@ -30,6 +30,9 @@ public class TintedKeyButtonDrawable extends KeyButtonDrawable {
     private final int mLightColor;
     private final int mDarkColor;
 
+    public static final float DARK_INTENSITY_NOT_SET = -1f;
+    private float mDarkIntensity = DARK_INTENSITY_NOT_SET;
+
     public static TintedKeyButtonDrawable create(Drawable drawable, @ColorInt int lightColor,
             @ColorInt int darkColor) {
         return new TintedKeyButtonDrawable(new Drawable[] { drawable }, lightColor, darkColor);
@@ -39,11 +42,13 @@ public class TintedKeyButtonDrawable extends KeyButtonDrawable {
         super(drawables);
         mLightColor = lightColor;
         mDarkColor = darkColor;
+        setDarkIntensity(0f); // Set initial coloration
     }
 
     @Override
     public void setDarkIntensity(float intensity) {
         // Duplicate intensity scaling from KeyButtonDrawable
+        mDarkIntensity = intensity;
         int intermediateColor = ColorUtils.compositeColors(
                 setAlphaFloat(mDarkColor, intensity),
                 setAlphaFloat(mLightColor,1f - intensity));
@@ -52,6 +57,16 @@ public class TintedKeyButtonDrawable extends KeyButtonDrawable {
     }
 
     private int setAlphaFloat(int color, float alpha) {
-        return ColorUtils.setAlphaComponent(color, (int) (alpha * 255f));
+        // Ensure alpha is clamped [0-255] or ColorUtils will crash
+        final int alphaInt = alpha > 1f ? 255 : (alpha < 0f ? 0 : ((int) alpha*255));
+        return ColorUtils.setAlphaComponent(color, alphaInt);
+    }
+
+    public boolean isDarkIntensitySet() {
+        return mDarkIntensity == DARK_INTENSITY_NOT_SET;
+    }
+
+    public float getDarkIntensity() {
+        return mDarkIntensity;
     }
 }