From 47cba6dd846af9f46df75dcc2ba80ad7b2921fdb Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Thu, 28 Apr 2022 18:09:10 +0000 Subject: [PATCH] [Bouncer] Update colors for pin pad Use accent color for better contrast. Add tint animation for button image. This will add support for text color animation for num pad button like the enter and the back button. Bug: 229667014 Test: Manual on device Change-Id: I27fc22fa03b93713a09546096059cb7d0152c349 --- .../com/android/keyguard/NumPadAnimator.java | 60 +++++++++++-------- .../com/android/keyguard/NumPadButton.java | 2 +- .../src/com/android/keyguard/NumPadKey.java | 2 +- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadAnimator.java b/packages/SystemUI/src/com/android/keyguard/NumPadAnimator.java index caf7ee4db2c32..c91c8992780c5 100644 --- a/packages/SystemUI/src/com/android/keyguard/NumPadAnimator.java +++ b/packages/SystemUI/src/com/android/keyguard/NumPadAnimator.java @@ -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(); diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java index 7b98f2759d806..8099f75ed7d41 100644 --- a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java +++ b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java @@ -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; } diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java index f771c974fe603..4aed2513d4f25 100644 --- a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java +++ b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java @@ -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; }