Merge "Setting NumPadAnimator only if background is RippleDrawable" into sc-dev am: 05ebc56867
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14709458 Change-Id: I6bbd72c0e290a0922a22baacdcc9437588d743e2
This commit is contained in:
@@ -16,22 +16,36 @@
|
|||||||
package com.android.keyguard;
|
package com.android.keyguard;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.RippleDrawable;
|
import android.graphics.drawable.RippleDrawable;
|
||||||
|
import android.graphics.drawable.VectorDrawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
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.
|
* Similar to the {@link NumPadKey}, but displays an image.
|
||||||
*/
|
*/
|
||||||
public class NumPadButton extends AlphaOptimizedImageButton {
|
public class NumPadButton extends AlphaOptimizedImageButton {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private NumPadAnimator mAnimator;
|
private NumPadAnimator mAnimator;
|
||||||
|
|
||||||
public NumPadButton(Context context, AttributeSet attrs) {
|
public NumPadButton(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
|
||||||
mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(),
|
Drawable background = getBackground();
|
||||||
attrs.getStyleAttribute());
|
if (background instanceof RippleDrawable) {
|
||||||
|
mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(),
|
||||||
|
attrs.getStyleAttribute());
|
||||||
|
} else {
|
||||||
|
mAnimator = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
// 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
|
// the height to match the old pin bouncer
|
||||||
int width = getMeasuredWidth();
|
int width = getMeasuredWidth();
|
||||||
int height = width;
|
int height = mAnimator == null ? (int) (width * .75f) : width;
|
||||||
|
|
||||||
setMeasuredDimension(getMeasuredWidth(), height);
|
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) {
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
super.onLayout(changed, l, t, r, b);
|
super.onLayout(changed, l, t, r, b);
|
||||||
|
|
||||||
mAnimator.onLayout(b - t);
|
if (mAnimator != null) mAnimator.onLayout(b - t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && mAnimator != null) {
|
||||||
mAnimator.start();
|
mAnimator.start();
|
||||||
}
|
}
|
||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
@@ -65,6 +79,13 @@ public class NumPadButton extends AlphaOptimizedImageButton {
|
|||||||
* Reload colors from resources.
|
* Reload colors from resources.
|
||||||
**/
|
**/
|
||||||
public void reloadColors() {
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.keyguard;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.RippleDrawable;
|
import android.graphics.drawable.RippleDrawable;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
@@ -30,6 +31,8 @@ import android.view.ViewGroup;
|
|||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settingslib.Utils;
|
import com.android.settingslib.Utils;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
@@ -47,6 +50,7 @@ public class NumPadKey extends ViewGroup {
|
|||||||
private int mTextViewResId;
|
private int mTextViewResId;
|
||||||
private PasswordTextView mTextView;
|
private PasswordTextView mTextView;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private NumPadAnimator mAnimator;
|
private NumPadAnimator mAnimator;
|
||||||
|
|
||||||
private View.OnClickListener mListener = new View.OnClickListener() {
|
private View.OnClickListener mListener = new View.OnClickListener() {
|
||||||
@@ -126,8 +130,13 @@ public class NumPadKey extends ViewGroup {
|
|||||||
|
|
||||||
setContentDescription(mDigitText.getText().toString());
|
setContentDescription(mDigitText.getText().toString());
|
||||||
|
|
||||||
mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(),
|
Drawable background = getBackground();
|
||||||
R.style.NumPadKey);
|
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);
|
mDigitText.setTextColor(textColor);
|
||||||
mKlondikeText.setTextColor(klondikeColor);
|
mKlondikeText.setTextColor(klondikeColor);
|
||||||
|
|
||||||
mAnimator.reloadColors(getContext());
|
if (mAnimator != null) mAnimator.reloadColors(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||||
doHapticKeyClick();
|
doHapticKeyClick();
|
||||||
mAnimator.start();
|
if (mAnimator != null) mAnimator.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onTouchEvent(event);
|
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
|
// 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
|
// the height to match the old pin bouncer
|
||||||
int width = getMeasuredWidth();
|
int width = getMeasuredWidth();
|
||||||
int height = width;
|
int height = mAnimator == null ? (int) (width * .75f) : width;
|
||||||
|
|
||||||
setMeasuredDimension(getMeasuredWidth(), height);
|
setMeasuredDimension(getMeasuredWidth(), height);
|
||||||
}
|
}
|
||||||
@@ -183,7 +192,7 @@ public class NumPadKey extends ViewGroup {
|
|||||||
left = centerX - mKlondikeText.getMeasuredWidth() / 2;
|
left = centerX - mKlondikeText.getMeasuredWidth() / 2;
|
||||||
mKlondikeText.layout(left, top, left + mKlondikeText.getMeasuredWidth(), bottom);
|
mKlondikeText.layout(left, top, left + mKlondikeText.getMeasuredWidth(), bottom);
|
||||||
|
|
||||||
mAnimator.onLayout(b - t);
|
if (mAnimator != null) mAnimator.onLayout(b - t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user