Merge "Apply prior tint to rotate icon on recreation" into pi-dev
am: a42585c349
Change-Id: Ia1262a8596d7bae614d60a52904a6a5e97c93883
This commit is contained in:
@@ -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;
|
||||
@@ -479,7 +479,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);
|
||||
}
|
||||
@@ -745,8 +745,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user