Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8217581 authored by Mike Digman's avatar Mike Digman
Browse files

Apply prior tint to rotate icon on recreation

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
parent 94e5d34d
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -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);
    }

+16 −1
Original line number Diff line number Diff line
@@ -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;
    }
}