Cleanup support for multiple PIN views

Had to support both old/new UX for PIN for a while. Cleanup the
unneeded code and simply the ripple.

Fixes: 187340770
Test: atest KeyguardPinBasedInputViewControllerTest and visual check
Change-Id: Ie12cd93c7aaba5a3ef172792a5dd2a41f2196447
This commit is contained in:
Matt Pietal
2021-05-06 09:02:17 -04:00
parent 006f1a69d0
commit e28295bb22
9 changed files with 30 additions and 122 deletions

View File

@@ -16,23 +16,14 @@
* limitations under the License.
*/
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item android:id="@+id/background">
<shape>
<solid android:color="?android:attr/colorControlNormal" />
<corners android:radius="10dp" />
</shape>
</item>
<item android:id="@+id/ripple">
<ripple
android:color="?android:attr/colorControlHighlight">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="?android:attr/colorControlNormal" />
<corners android:radius="10dp" />
</shape>
</item>
</ripple>
</item>
</layer-list>
</ripple>

View File

@@ -28,7 +28,6 @@ import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
import com.android.systemui.R;
import com.android.systemui.classifier.FalsingCollector;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.concurrency.DelayableExecutor;
@@ -167,7 +166,6 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
private final TelephonyManager mTelephonyManager;
private final EmergencyButtonController.Factory mEmergencyButtonControllerFactory;
private final FalsingCollector mFalsingCollector;
private final boolean mIsNewLayoutEnabled;
@Inject
public Factory(KeyguardUpdateMonitor keyguardUpdateMonitor,
@@ -177,8 +175,7 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
InputMethodManager inputMethodManager, @Main DelayableExecutor mainExecutor,
@Main Resources resources, LiftToActivateListener liftToActivateListener,
TelephonyManager telephonyManager, FalsingCollector falsingCollector,
EmergencyButtonController.Factory emergencyButtonControllerFactory,
FeatureFlags featureFlags) {
EmergencyButtonController.Factory emergencyButtonControllerFactory) {
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mLockPatternUtils = lockPatternUtils;
mLatencyTracker = latencyTracker;
@@ -190,7 +187,6 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
mTelephonyManager = telephonyManager;
mEmergencyButtonControllerFactory = emergencyButtonControllerFactory;
mFalsingCollector = falsingCollector;
mIsNewLayoutEnabled = featureFlags.isKeyguardLayoutEnabled();
}
/** Create a new {@link KeyguardInputViewController}. */
@@ -216,20 +212,19 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
return new KeyguardPinViewController((KeyguardPINView) keyguardInputView,
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
mLiftToActivateListener, emergencyButtonController, mFalsingCollector,
mIsNewLayoutEnabled);
mLiftToActivateListener, emergencyButtonController, mFalsingCollector);
} else if (keyguardInputView instanceof KeyguardSimPinView) {
return new KeyguardSimPinViewController((KeyguardSimPinView) keyguardInputView,
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
mLiftToActivateListener, mTelephonyManager, mFalsingCollector,
emergencyButtonController, mIsNewLayoutEnabled);
emergencyButtonController);
} else if (keyguardInputView instanceof KeyguardSimPukView) {
return new KeyguardSimPukViewController((KeyguardSimPukView) keyguardInputView,
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
mLiftToActivateListener, mTelephonyManager, mFalsingCollector,
emergencyButtonController, mIsNewLayoutEnabled);
emergencyButtonController);
}
throw new RuntimeException("Unable to find controller for " + keyguardInputView);

View File

@@ -168,20 +168,6 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
return mButtons;
}
/**
* By default, the new layout will be enabled. When false, revert to the old style.
*/
public void setIsNewLayoutEnabled(boolean isEnabled) {
if (!isEnabled) {
for (int i = 0; i < mButtons.length; i++) {
mButtons[i].disableNewLayout();
}
mDeleteButton.disableNewLayout();
mOkButton.disableNewLayout();
reloadColors();
}
}
/**
* Reload colors from resources.
**/

View File

@@ -35,12 +35,11 @@ public class KeyguardPinViewController
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
LatencyTracker latencyTracker, LiftToActivateListener liftToActivateListener,
EmergencyButtonController emergencyButtonController,
FalsingCollector falsingCollector, boolean isNewLayoutEnabled) {
FalsingCollector falsingCollector) {
super(view, keyguardUpdateMonitor, securityMode, lockPatternUtils, keyguardSecurityCallback,
messageAreaControllerFactory, latencyTracker, liftToActivateListener,
emergencyButtonController, falsingCollector);
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
view.setIsNewLayoutEnabled(isNewLayoutEnabled);
}
@Override

View File

@@ -79,14 +79,13 @@ public class KeyguardSimPinViewController
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
LatencyTracker latencyTracker, LiftToActivateListener liftToActivateListener,
TelephonyManager telephonyManager, FalsingCollector falsingCollector,
EmergencyButtonController emergencyButtonController, boolean isNewLayoutEnabled) {
EmergencyButtonController emergencyButtonController) {
super(view, keyguardUpdateMonitor, securityMode, lockPatternUtils, keyguardSecurityCallback,
messageAreaControllerFactory, latencyTracker, liftToActivateListener,
emergencyButtonController, falsingCollector);
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mTelephonyManager = telephonyManager;
mSimImageView = mView.findViewById(R.id.keyguard_sim);
view.setIsNewLayoutEnabled(isNewLayoutEnabled);
}
@Override

View File

@@ -85,14 +85,13 @@ public class KeyguardSimPukViewController
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
LatencyTracker latencyTracker, LiftToActivateListener liftToActivateListener,
TelephonyManager telephonyManager, FalsingCollector falsingCollector,
EmergencyButtonController emergencyButtonController, boolean isNewLayoutEnabled) {
EmergencyButtonController emergencyButtonController) {
super(view, keyguardUpdateMonitor, securityMode, lockPatternUtils, keyguardSecurityCallback,
messageAreaControllerFactory, latencyTracker, liftToActivateListener,
emergencyButtonController, falsingCollector);
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
mTelephonyManager = telephonyManager;
mSimImageView = mView.findViewById(R.id.keyguard_sim);
view.setIsNewLayoutEnabled(isNewLayoutEnabled);
}
@Override

View File

@@ -21,7 +21,6 @@ import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RippleDrawable;
import android.view.ContextThemeWrapper;
@@ -40,17 +39,14 @@ class NumPadAnimator {
private ValueAnimator mContractAnimator;
private GradientDrawable mBackground;
private RippleDrawable mRipple;
private GradientDrawable mRippleMask;
private int mNormalColor;
private int mHighlightColor;
private int mStyle;
NumPadAnimator(Context context, LayerDrawable drawable, @StyleRes int style) {
LayerDrawable ld = (LayerDrawable) drawable.mutate();
mBackground = (GradientDrawable) ld.findDrawableByLayerId(R.id.background);
mRipple = (RippleDrawable) ld.findDrawableByLayerId(R.id.ripple);
mRippleMask = (GradientDrawable) mRipple.findDrawableByLayerId(android.R.id.mask);
NumPadAnimator(Context context, final RippleDrawable drawable, @StyleRes int style) {
mStyle = style;
mRipple = (RippleDrawable) drawable.mutate();
mBackground = (GradientDrawable) mRipple.findDrawableByLayerId(R.id.background);
reloadColors(context);
@@ -62,7 +58,7 @@ class NumPadAnimator {
mExpandAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator anim) {
mBackground.setCornerRadius((float) anim.getAnimatedValue());
mRippleMask.setCornerRadius((float) anim.getAnimatedValue());
mRipple.invalidateSelf();
}
});
@@ -73,7 +69,7 @@ class NumPadAnimator {
mContractAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator anim) {
mBackground.setCornerRadius((float) anim.getAnimatedValue());
mRippleMask.setCornerRadius((float) anim.getAnimatedValue());
mRipple.invalidateSelf();
}
});
mAnimator.playSequentially(mExpandAnimator, mContractAnimator);

View File

@@ -16,37 +16,22 @@
package com.android.keyguard;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.VectorDrawable;
import android.graphics.drawable.RippleDrawable;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
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);
Drawable background = getBackground();
if (background instanceof LayerDrawable) {
mAnimator = new NumPadAnimator(context, (LayerDrawable) background,
attrs.getStyleAttribute());
} else {
mAnimator = null;
}
mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(),
attrs.getStyleAttribute());
}
@Override
@@ -56,7 +41,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 = mAnimator == null ? (int) (width * .75f) : width;
int height = width;
setMeasuredDimension(getMeasuredWidth(), height);
}
@@ -65,13 +50,13 @@ 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);
if (mAnimator != null) mAnimator.onLayout(b - t);
mAnimator.onLayout(b - t);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
if (mAnimator != null) mAnimator.start();
mAnimator.start();
}
return super.onTouchEvent(event);
}
@@ -80,25 +65,6 @@ public class NumPadButton extends AlphaOptimizedImageButton {
* Reload colors from resources.
**/
public void reloadColors() {
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));
}
}
/**
* By default, the new layout will be enabled. Invoking will revert to the old style
*/
public void disableNewLayout() {
if (mAnimator != null) {
mAnimator = null;
ContextThemeWrapper ctw = new ContextThemeWrapper(getContext(), R.style.NumPadKey);
setBackground(getContext().getResources().getDrawable(
R.drawable.ripple_drawable_pin, ctw.getTheme()));
}
mAnimator.reloadColors(getContext());
}
}

View File

@@ -18,12 +18,10 @@ package com.android.keyguard;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RippleDrawable;
import android.os.PowerManager;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -32,8 +30,6 @@ 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;
@@ -51,7 +47,6 @@ public class NumPadKey extends ViewGroup {
private int mTextViewResId;
private PasswordTextView mTextView;
@Nullable
private NumPadAnimator mAnimator;
private View.OnClickListener mListener = new View.OnClickListener() {
@@ -131,26 +126,8 @@ public class NumPadKey extends ViewGroup {
setContentDescription(mDigitText.getText().toString());
Drawable background = getBackground();
if (background instanceof LayerDrawable) {
mAnimator = new NumPadAnimator(context, (LayerDrawable) background,
R.style.NumPadKey);
} else {
mAnimator = null;
}
}
/**
* By default, the new layout will be enabled. Invoking will revert to the old style
*/
public void disableNewLayout() {
findViewById(R.id.klondike_text).setVisibility(View.VISIBLE);
if (mAnimator != null) {
mAnimator = null;
ContextThemeWrapper ctw = new ContextThemeWrapper(getContext(), R.style.NumPadKey);
setBackground(getContext().getResources().getDrawable(
R.drawable.ripple_drawable_pin, ctw.getTheme()));
}
mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(),
R.style.NumPadKey);
}
/**
@@ -164,14 +141,14 @@ public class NumPadKey extends ViewGroup {
mDigitText.setTextColor(textColor);
mKlondikeText.setTextColor(klondikeColor);
if (mAnimator != null) mAnimator.reloadColors(getContext());
mAnimator.reloadColors(getContext());
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
doHapticKeyClick();
if (mAnimator != null) mAnimator.start();
mAnimator.start();
}
return super.onTouchEvent(event);
@@ -185,7 +162,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 = mAnimator == null ? (int) (width * .75f) : width;
int height = width;
setMeasuredDimension(getMeasuredWidth(), height);
}
@@ -206,7 +183,7 @@ public class NumPadKey extends ViewGroup {
left = centerX - mKlondikeText.getMeasuredWidth() / 2;
mKlondikeText.layout(left, top, left + mKlondikeText.getMeasuredWidth(), bottom);
if (mAnimator != null) mAnimator.onLayout(b - t);
mAnimator.onLayout(b - t);
}
@Override