diff options
| author | 2021-05-26 13:07:03 +0000 | |
|---|---|---|
| committer | 2021-05-26 13:07:03 +0000 | |
| commit | 05ebc56867b76bcf0f77b4845fd078334839b9d2 (patch) | |
| tree | 0855265ab10651481be29deb31ca88df209d0acb | |
| parent | 63a50896d83ba30bc637175e1c98b1dc997ed85d (diff) | |
| parent | 43b7eadab1113dbdc6d4c0114757ca682c8ace73 (diff) | |
Merge "Setting NumPadAnimator only if background is RippleDrawable" into sc-dev
| -rw-r--r-- | packages/SystemUI/src/com/android/keyguard/NumPadButton.java | 33 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/keyguard/NumPadKey.java | 21 |
2 files changed, 42 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java index 096597afa889..0d31906d2f80 100644 --- a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java +++ b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java @@ -16,22 +16,36 @@ package com.android.keyguard; import android.content.Context; +import android.content.res.ColorStateList; +import android.graphics.drawable.Drawable; import android.graphics.drawable.RippleDrawable; +import android.graphics.drawable.VectorDrawable; import android.util.AttributeSet; import android.view.MotionEvent; +import androidx.annotation.Nullable; + +import com.android.settingslib.Utils; +import com.android.systemui.R; + /** * Similar to the {@link NumPadKey}, but displays an image. */ public class NumPadButton extends AlphaOptimizedImageButton { + @Nullable private NumPadAnimator mAnimator; public NumPadButton(Context context, AttributeSet attrs) { super(context, attrs); - mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(), - attrs.getStyleAttribute()); + Drawable background = getBackground(); + if (background instanceof RippleDrawable) { + mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(), + attrs.getStyleAttribute()); + } else { + mAnimator = null; + } } @Override @@ -41,7 +55,7 @@ public class NumPadButton extends AlphaOptimizedImageButton { // Set width/height to the same value to ensure a smooth circle for the bg, but shrink // the height to match the old pin bouncer int width = getMeasuredWidth(); - int height = width; + int height = mAnimator == null ? (int) (width * .75f) : width; setMeasuredDimension(getMeasuredWidth(), height); } @@ -50,12 +64,12 @@ public class NumPadButton extends AlphaOptimizedImageButton { protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); - mAnimator.onLayout(b - t); + if (mAnimator != null) mAnimator.onLayout(b - t); } @Override public boolean onTouchEvent(MotionEvent event) { - if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { + if (event.getActionMasked() == MotionEvent.ACTION_DOWN && mAnimator != null) { mAnimator.start(); } return super.onTouchEvent(event); @@ -65,6 +79,13 @@ public class NumPadButton extends AlphaOptimizedImageButton { * Reload colors from resources. **/ public void reloadColors() { - mAnimator.reloadColors(getContext()); + if (mAnimator != null) { + mAnimator.reloadColors(getContext()); + } else { + // Needed for old style pin + int textColor = Utils.getColorAttr(getContext(), android.R.attr.textColorPrimary) + .getDefaultColor(); + ((VectorDrawable) getDrawable()).setTintList(ColorStateList.valueOf(textColor)); + } } } diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java index 35ace0d1a404..cffa630c6ec8 100644 --- a/packages/SystemUI/src/com/android/keyguard/NumPadKey.java +++ b/packages/SystemUI/src/com/android/keyguard/NumPadKey.java @@ -18,6 +18,7 @@ package com.android.keyguard; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; import android.graphics.drawable.RippleDrawable; import android.os.PowerManager; import android.os.SystemClock; @@ -30,6 +31,8 @@ import android.view.ViewGroup; import android.view.accessibility.AccessibilityManager; import android.widget.TextView; +import androidx.annotation.Nullable; + import com.android.internal.widget.LockPatternUtils; import com.android.settingslib.Utils; import com.android.systemui.R; @@ -47,6 +50,7 @@ public class NumPadKey extends ViewGroup { private int mTextViewResId; private PasswordTextView mTextView; + @Nullable private NumPadAnimator mAnimator; private View.OnClickListener mListener = new View.OnClickListener() { @@ -126,8 +130,13 @@ public class NumPadKey extends ViewGroup { setContentDescription(mDigitText.getText().toString()); - mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(), - R.style.NumPadKey); + Drawable background = getBackground(); + if (background instanceof RippleDrawable) { + mAnimator = new NumPadAnimator(context, (RippleDrawable) background, + R.style.NumPadKey); + } else { + mAnimator = null; + } } /** @@ -141,14 +150,14 @@ public class NumPadKey extends ViewGroup { mDigitText.setTextColor(textColor); mKlondikeText.setTextColor(klondikeColor); - mAnimator.reloadColors(getContext()); + if (mAnimator != null) mAnimator.reloadColors(getContext()); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { doHapticKeyClick(); - mAnimator.start(); + if (mAnimator != null) mAnimator.start(); } return super.onTouchEvent(event); @@ -162,7 +171,7 @@ public class NumPadKey extends ViewGroup { // Set width/height to the same value to ensure a smooth circle for the bg, but shrink // the height to match the old pin bouncer int width = getMeasuredWidth(); - int height = width; + int height = mAnimator == null ? (int) (width * .75f) : width; setMeasuredDimension(getMeasuredWidth(), height); } @@ -183,7 +192,7 @@ public class NumPadKey extends ViewGroup { left = centerX - mKlondikeText.getMeasuredWidth() / 2; mKlondikeText.layout(left, top, left + mKlondikeText.getMeasuredWidth(), bottom); - mAnimator.onLayout(b - t); + if (mAnimator != null) mAnimator.onLayout(b - t); } @Override |