Merge "[Bouncer] Update colors for pin pad" into tm-dev
This commit is contained in:
@@ -30,7 +30,6 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.StyleRes;
|
||||
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.systemui.animation.Interpolators;
|
||||
|
||||
/**
|
||||
@@ -42,24 +41,29 @@ class NumPadAnimator {
|
||||
private ValueAnimator mContractAnimator;
|
||||
private AnimatorSet mContractAnimatorSet;
|
||||
private GradientDrawable mBackground;
|
||||
private int mNormalColor;
|
||||
private int mHighlightColor;
|
||||
private int mStyle;
|
||||
private Drawable mImageButton;
|
||||
private TextView mDigitTextView;
|
||||
private int mNormalBackgroundColor;
|
||||
private int mPressedBackgroundColor;
|
||||
private int mTextColorPrimary;
|
||||
private int mTextColorPressed;
|
||||
private int mStyle;
|
||||
private static final int EXPAND_ANIMATION_MS = 100;
|
||||
private static final int EXPAND_COLOR_ANIMATION_MS = 50;
|
||||
private static final int CONTRACT_ANIMATION_DELAY_MS = 33;
|
||||
private static final int CONTRACT_ANIMATION_MS = 417;
|
||||
|
||||
NumPadAnimator(Context context, final Drawable drawable, @StyleRes int style) {
|
||||
this(context, drawable, style, null);
|
||||
NumPadAnimator(Context context, final Drawable drawable,
|
||||
@StyleRes int style, Drawable buttonImage) {
|
||||
this(context, drawable, style, null, buttonImage);
|
||||
}
|
||||
|
||||
NumPadAnimator(Context context, final Drawable drawable, @StyleRes int style,
|
||||
@Nullable TextView digitTextView) {
|
||||
@Nullable TextView digitTextView, @Nullable Drawable buttonImage) {
|
||||
mStyle = style;
|
||||
mBackground = (GradientDrawable) drawable;
|
||||
mDigitTextView = digitTextView;
|
||||
mImageButton = buttonImage;
|
||||
|
||||
reloadColors(context);
|
||||
}
|
||||
@@ -88,26 +92,28 @@ class NumPadAnimator {
|
||||
* Reload colors from resources.
|
||||
**/
|
||||
void reloadColors(Context context) {
|
||||
int[] customAttrs = {android.R.attr.colorControlNormal,
|
||||
android.R.attr.colorControlHighlight};
|
||||
boolean isNumPadKey = mImageButton == null;
|
||||
|
||||
int[] customAttrs = {android.R.attr.colorControlNormal};
|
||||
ContextThemeWrapper ctw = new ContextThemeWrapper(context, mStyle);
|
||||
TypedArray a = ctw.obtainStyledAttributes(customAttrs);
|
||||
mNormalColor = getPrivateAttrColorIfUnset(ctw, a, 0, 0,
|
||||
mNormalBackgroundColor = getPrivateAttrColorIfUnset(ctw, a, 0, 0,
|
||||
com.android.internal.R.attr.colorSurface);
|
||||
mHighlightColor = a.getColor(1, 0);
|
||||
a.recycle();
|
||||
mBackground.setColor(mNormalBackgroundColor);
|
||||
|
||||
mBackground.setColor(mNormalColor);
|
||||
createAnimators(context);
|
||||
mPressedBackgroundColor = context.getColor(android.R.color.system_accent1_200);
|
||||
mTextColorPrimary = isNumPadKey
|
||||
? com.android.settingslib.Utils
|
||||
.getColorAttrDefaultColor(context, android.R.attr.textColorPrimary)
|
||||
: com.android.settingslib.Utils
|
||||
.getColorAttrDefaultColor(context, android.R.attr.textColorPrimaryInverse);
|
||||
mTextColorPressed = com.android.settingslib.Utils
|
||||
.getColorAttrDefaultColor(context, com.android.internal.R.attr.textColorOnAccent);
|
||||
createAnimators();
|
||||
}
|
||||
|
||||
private void createAnimators(Context context) {
|
||||
int textColorPrimary = Utils.getColorAttrDefaultColor(context,
|
||||
android.R.attr.textColorPrimary);
|
||||
int textColorPrimaryInverse = Utils.getColorAttrDefaultColor(context,
|
||||
android.R.attr.textColorPrimaryInverse);
|
||||
|
||||
private void createAnimators() {
|
||||
// Actual values will be updated later, usually during an onLayout() call
|
||||
mExpandAnimator = ValueAnimator.ofFloat(0f, 1f);
|
||||
mExpandAnimator.setDuration(EXPAND_ANIMATION_MS);
|
||||
@@ -116,7 +122,7 @@ class NumPadAnimator {
|
||||
anim -> mBackground.setCornerRadius((float) anim.getAnimatedValue()));
|
||||
|
||||
ValueAnimator expandBackgroundColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(),
|
||||
mNormalColor, mHighlightColor);
|
||||
mNormalBackgroundColor, mPressedBackgroundColor);
|
||||
expandBackgroundColorAnimator.setDuration(EXPAND_COLOR_ANIMATION_MS);
|
||||
expandBackgroundColorAnimator.setInterpolator(Interpolators.LINEAR);
|
||||
expandBackgroundColorAnimator.addUpdateListener(
|
||||
@@ -124,13 +130,16 @@ class NumPadAnimator {
|
||||
|
||||
ValueAnimator expandTextColorAnimator =
|
||||
ValueAnimator.ofObject(new ArgbEvaluator(),
|
||||
textColorPrimary, textColorPrimaryInverse);
|
||||
mTextColorPrimary, mTextColorPressed);
|
||||
expandTextColorAnimator.setInterpolator(Interpolators.LINEAR);
|
||||
expandTextColorAnimator.setDuration(EXPAND_COLOR_ANIMATION_MS);
|
||||
expandTextColorAnimator.addUpdateListener(valueAnimator -> {
|
||||
if (mDigitTextView != null) {
|
||||
mDigitTextView.setTextColor((int) valueAnimator.getAnimatedValue());
|
||||
}
|
||||
if (mImageButton != null) {
|
||||
mImageButton.setTint((int) valueAnimator.getAnimatedValue());
|
||||
}
|
||||
});
|
||||
|
||||
mExpandAnimatorSet = new AnimatorSet();
|
||||
@@ -144,7 +153,7 @@ class NumPadAnimator {
|
||||
mContractAnimator.addUpdateListener(
|
||||
anim -> mBackground.setCornerRadius((float) anim.getAnimatedValue()));
|
||||
ValueAnimator contractBackgroundColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(),
|
||||
mHighlightColor, mNormalColor);
|
||||
mPressedBackgroundColor, mNormalBackgroundColor);
|
||||
contractBackgroundColorAnimator.setInterpolator(Interpolators.LINEAR);
|
||||
contractBackgroundColorAnimator.setStartDelay(CONTRACT_ANIMATION_DELAY_MS);
|
||||
contractBackgroundColorAnimator.setDuration(CONTRACT_ANIMATION_MS);
|
||||
@@ -152,8 +161,8 @@ class NumPadAnimator {
|
||||
animator -> mBackground.setColor((int) animator.getAnimatedValue()));
|
||||
|
||||
ValueAnimator contractTextColorAnimator =
|
||||
ValueAnimator.ofObject(new ArgbEvaluator(), textColorPrimaryInverse,
|
||||
textColorPrimary);
|
||||
ValueAnimator.ofObject(new ArgbEvaluator(), mTextColorPressed,
|
||||
mTextColorPrimary);
|
||||
contractTextColorAnimator.setInterpolator(Interpolators.LINEAR);
|
||||
contractTextColorAnimator.setStartDelay(CONTRACT_ANIMATION_DELAY_MS);
|
||||
contractTextColorAnimator.setDuration(CONTRACT_ANIMATION_MS);
|
||||
@@ -161,6 +170,9 @@ class NumPadAnimator {
|
||||
if (mDigitTextView != null) {
|
||||
mDigitTextView.setTextColor((int) valueAnimator.getAnimatedValue());
|
||||
}
|
||||
if (mImageButton != null) {
|
||||
mImageButton.setTint((int) valueAnimator.getAnimatedValue());
|
||||
}
|
||||
});
|
||||
|
||||
mContractAnimatorSet = new AnimatorSet();
|
||||
|
||||
@@ -42,7 +42,7 @@ public class NumPadButton extends AlphaOptimizedImageButton {
|
||||
Drawable background = getBackground();
|
||||
if (background instanceof GradientDrawable) {
|
||||
mAnimator = new NumPadAnimator(context, background.mutate(),
|
||||
attrs.getStyleAttribute());
|
||||
attrs.getStyleAttribute(), getDrawable());
|
||||
} else {
|
||||
mAnimator = null;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class NumPadKey extends ViewGroup {
|
||||
Drawable background = getBackground();
|
||||
if (background instanceof GradientDrawable) {
|
||||
mAnimator = new NumPadAnimator(context, background.mutate(),
|
||||
R.style.NumPadKey, mDigitText);
|
||||
R.style.NumPadKey, mDigitText, null);
|
||||
} else {
|
||||
mAnimator = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user