Merge "Merge "Apply prior tint to rotate icon on recreation" into pi-dev am: a42585c349" into pi-dev-plus-aosp

This commit is contained in:
Android Build Merger (Role)
2018-03-07 23:10:50 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 3 deletions

View File

@@ -117,7 +117,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
private KeyButtonDrawable mImeIcon; private KeyButtonDrawable mImeIcon;
private KeyButtonDrawable mMenuIcon; private KeyButtonDrawable mMenuIcon;
private KeyButtonDrawable mAccessibilityIcon; private KeyButtonDrawable mAccessibilityIcon;
private KeyButtonDrawable mRotateSuggestionIcon; private TintedKeyButtonDrawable mRotateSuggestionIcon;
private GestureHelper mGestureHelper; private GestureHelper mGestureHelper;
private DeadZone mDeadZone; private DeadZone mDeadZone;
@@ -479,7 +479,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
darkContext.getDrawable(darkIcon)); 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) { @ColorInt int lightColor, @ColorInt int darkColor) {
return TintedKeyButtonDrawable.create(ctx.getDrawable(icon), lightColor, darkColor); return TintedKeyButtonDrawable.create(ctx.getDrawable(icon), lightColor, darkColor);
} }
@@ -745,8 +745,15 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
Context rotateContext = new ContextThemeWrapper(ctx, style); Context rotateContext = new ContextThemeWrapper(ctx, style);
// Recreate the icon and set it if needed // Recreate the icon and set it if needed
TintedKeyButtonDrawable priorIcon = mRotateSuggestionIcon;
mRotateSuggestionIcon = getDrawable(rotateContext, R.drawable.ic_sysbar_rotate_button, mRotateSuggestionIcon = getDrawable(rotateContext, R.drawable.ic_sysbar_rotate_button,
lightColor, darkColor); lightColor, darkColor);
// Apply any prior set dark intensity
if (priorIcon != null && priorIcon.isDarkIntensitySet()) {
mRotateSuggestionIcon.setDarkIntensity(priorIcon.getDarkIntensity());
}
if (setIcon) getRotateSuggestionButton().setImageDrawable(mRotateSuggestionIcon); if (setIcon) getRotateSuggestionButton().setImageDrawable(mRotateSuggestionIcon);
} }

View File

@@ -30,6 +30,9 @@ public class TintedKeyButtonDrawable extends KeyButtonDrawable {
private final int mLightColor; private final int mLightColor;
private final int mDarkColor; 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, public static TintedKeyButtonDrawable create(Drawable drawable, @ColorInt int lightColor,
@ColorInt int darkColor) { @ColorInt int darkColor) {
return new TintedKeyButtonDrawable(new Drawable[] { drawable }, lightColor, darkColor); return new TintedKeyButtonDrawable(new Drawable[] { drawable }, lightColor, darkColor);
@@ -39,11 +42,13 @@ public class TintedKeyButtonDrawable extends KeyButtonDrawable {
super(drawables); super(drawables);
mLightColor = lightColor; mLightColor = lightColor;
mDarkColor = darkColor; mDarkColor = darkColor;
setDarkIntensity(0f); // Set initial coloration
} }
@Override @Override
public void setDarkIntensity(float intensity) { public void setDarkIntensity(float intensity) {
// Duplicate intensity scaling from KeyButtonDrawable // Duplicate intensity scaling from KeyButtonDrawable
mDarkIntensity = intensity;
int intermediateColor = ColorUtils.compositeColors( int intermediateColor = ColorUtils.compositeColors(
setAlphaFloat(mDarkColor, intensity), setAlphaFloat(mDarkColor, intensity),
setAlphaFloat(mLightColor,1f - intensity)); setAlphaFloat(mLightColor,1f - intensity));
@@ -52,6 +57,16 @@ public class TintedKeyButtonDrawable extends KeyButtonDrawable {
} }
private int setAlphaFloat(int color, float alpha) { 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;
} }
} }