private KeyButtonDrawable mImeIcon;
private KeyButtonDrawable mMenuIcon;
private KeyButtonDrawable mAccessibilityIcon;
- private KeyButtonDrawable mRotateSuggestionIcon;
+ private TintedKeyButtonDrawable mRotateSuggestionIcon;
private GestureHelper mGestureHelper;
private DeadZone mDeadZone;
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);
}
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);
}
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);
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));
}
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;
}
}