PIN View - Control layout based on feature flag
Support both the old-style PIN views and the new ones behind the keyguard layout flag. Fixes: 179121004 Test: adb shell cmd overlay disable com.google.android.systemui.gxoverlay Change-Id: If588df2503d9337fe63b300fb24da09ef0a6d1e9
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2018 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License
|
||||
-->
|
||||
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight"
|
||||
android:radius="40dp"/>
|
||||
@@ -28,6 +28,7 @@ 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;
|
||||
|
||||
@@ -166,6 +167,7 @@ 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,
|
||||
@@ -176,7 +178,8 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
|
||||
@Main Resources resources, LiftToActivateListener liftToActivateListener,
|
||||
TelephonyManager telephonyManager,
|
||||
EmergencyButtonController.Factory emergencyButtonControllerFactory,
|
||||
FalsingCollector falsingCollector) {
|
||||
FalsingCollector falsingCollector,
|
||||
FeatureFlags featureFlags) {
|
||||
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
|
||||
mLockPatternUtils = lockPatternUtils;
|
||||
mLatencyTracker = latencyTracker;
|
||||
@@ -188,6 +191,7 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
|
||||
mTelephonyManager = telephonyManager;
|
||||
mEmergencyButtonControllerFactory = emergencyButtonControllerFactory;
|
||||
mFalsingCollector = falsingCollector;
|
||||
mIsNewLayoutEnabled = featureFlags.isKeyguardLayoutEnabled();
|
||||
}
|
||||
|
||||
/** Create a new {@link KeyguardInputViewController}. */
|
||||
@@ -212,21 +216,22 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
|
||||
return new KeyguardPinViewController((KeyguardPINView) keyguardInputView,
|
||||
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
|
||||
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
|
||||
mLiftToActivateListener, emergencyButtonController, mFalsingCollector);
|
||||
mLiftToActivateListener, emergencyButtonController, mFalsingCollector,
|
||||
mIsNewLayoutEnabled);
|
||||
} else if (keyguardInputView instanceof KeyguardSimPinView) {
|
||||
return new KeyguardSimPinViewController((KeyguardSimPinView) keyguardInputView,
|
||||
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
|
||||
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
|
||||
mLiftToActivateListener, mTelephonyManager,
|
||||
emergencyButtonController,
|
||||
mFalsingCollector);
|
||||
mFalsingCollector, mIsNewLayoutEnabled);
|
||||
} else if (keyguardInputView instanceof KeyguardSimPukView) {
|
||||
return new KeyguardSimPukViewController((KeyguardSimPukView) keyguardInputView,
|
||||
mKeyguardUpdateMonitor, securityMode, mLockPatternUtils,
|
||||
keyguardSecurityCallback, mMessageAreaControllerFactory, mLatencyTracker,
|
||||
mLiftToActivateListener, mTelephonyManager,
|
||||
emergencyButtonController,
|
||||
mFalsingCollector);
|
||||
mFalsingCollector, mIsNewLayoutEnabled);
|
||||
}
|
||||
|
||||
throw new RuntimeException("Unable to find controller for " + keyguardInputView);
|
||||
|
||||
@@ -166,6 +166,20 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
|
||||
reloadColors();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
@@ -35,11 +35,12 @@ public class KeyguardPinViewController
|
||||
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
|
||||
LatencyTracker latencyTracker, LiftToActivateListener liftToActivateListener,
|
||||
EmergencyButtonController emergencyButtonController,
|
||||
FalsingCollector falsingCollector) {
|
||||
FalsingCollector falsingCollector, boolean isNewLayoutEnabled) {
|
||||
super(view, keyguardUpdateMonitor, securityMode, lockPatternUtils, keyguardSecurityCallback,
|
||||
messageAreaControllerFactory, latencyTracker, liftToActivateListener,
|
||||
emergencyButtonController, falsingCollector);
|
||||
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
|
||||
view.setIsNewLayoutEnabled(isNewLayoutEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -79,13 +79,14 @@ public class KeyguardSimPinViewController
|
||||
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
|
||||
LatencyTracker latencyTracker, LiftToActivateListener liftToActivateListener,
|
||||
TelephonyManager telephonyManager, EmergencyButtonController emergencyButtonController,
|
||||
FalsingCollector falsingCollector) {
|
||||
FalsingCollector falsingCollector, boolean isNewLayoutEnabled) {
|
||||
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
|
||||
|
||||
@@ -85,13 +85,14 @@ public class KeyguardSimPukViewController
|
||||
KeyguardMessageAreaController.Factory messageAreaControllerFactory,
|
||||
LatencyTracker latencyTracker, LiftToActivateListener liftToActivateListener,
|
||||
TelephonyManager telephonyManager, EmergencyButtonController emergencyButtonController,
|
||||
FalsingCollector falsingCollector) {
|
||||
FalsingCollector falsingCollector, boolean isNewLayoutEnabled) {
|
||||
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
|
||||
|
||||
@@ -16,17 +16,23 @@
|
||||
package com.android.keyguard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.VectorDrawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.systemui.R;
|
||||
|
||||
/**
|
||||
* Similar to the {@link NumPadKey}, but displays an image.
|
||||
*/
|
||||
public class NumPadButton extends AlphaOptimizedImageButton {
|
||||
|
||||
private final NumPadAnimator mAnimator;
|
||||
private NumPadAnimator mAnimator;
|
||||
|
||||
public NumPadButton(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
@@ -36,25 +42,34 @@ public class NumPadButton extends AlphaOptimizedImageButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
mAnimator.updateMargin((ViewGroup.MarginLayoutParams) getLayoutParams());
|
||||
public void setLayoutParams(ViewGroup.LayoutParams params) {
|
||||
if (mAnimator != null) mAnimator.updateMargin((ViewGroup.MarginLayoutParams) params);
|
||||
|
||||
super.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
// Set width/height to the same value to ensure a smooth circle for the bg
|
||||
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
|
||||
// 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;
|
||||
|
||||
setMeasuredDimension(getMeasuredWidth(), height);
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
mAnimator.start();
|
||||
if (mAnimator != null) mAnimator.start();
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@@ -62,6 +77,23 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, the new layout will be enabled. Invoking will revert to the old style
|
||||
*/
|
||||
public void disableNewLayout() {
|
||||
mAnimator = null;
|
||||
ContextThemeWrapper ctw = new ContextThemeWrapper(getContext(), R.style.NumPadKey);
|
||||
setBackground(getContext().getResources().getDrawable(
|
||||
R.drawable.ripple_drawable_pin, ctw.getTheme()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.graphics.drawable.GradientDrawable;
|
||||
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;
|
||||
@@ -47,7 +48,7 @@ public class NumPadKey extends ViewGroup {
|
||||
private int mTextViewResId;
|
||||
private PasswordTextView mTextView;
|
||||
|
||||
private final NumPadAnimator mAnimator;
|
||||
private NumPadAnimator mAnimator;
|
||||
|
||||
private View.OnClickListener mListener = new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -130,6 +131,17 @@ public class NumPadKey extends ViewGroup {
|
||||
R.style.NumPadKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
mAnimator = null;
|
||||
ContextThemeWrapper ctw = new ContextThemeWrapper(getContext(), R.style.NumPadKey);
|
||||
setBackground(getContext().getResources().getDrawable(
|
||||
R.drawable.ripple_drawable_pin, ctw.getTheme()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload colors from resources.
|
||||
**/
|
||||
@@ -141,7 +153,7 @@ public class NumPadKey extends ViewGroup {
|
||||
mDigitText.setTextColor(textColor);
|
||||
mKlondikeText.setTextColor(klondikeColor);
|
||||
|
||||
mAnimator.reloadColors(getContext());
|
||||
if (mAnimator != null) mAnimator.reloadColors(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,14 +162,14 @@ public class NumPadKey extends ViewGroup {
|
||||
doHapticKeyClick();
|
||||
}
|
||||
|
||||
mAnimator.start();
|
||||
if (mAnimator != null) mAnimator.start();
|
||||
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLayoutParams(ViewGroup.LayoutParams params) {
|
||||
mAnimator.updateMargin((ViewGroup.MarginLayoutParams) params);
|
||||
if (mAnimator != null) mAnimator.updateMargin((ViewGroup.MarginLayoutParams) params);
|
||||
|
||||
super.setLayoutParams(params);
|
||||
}
|
||||
@@ -167,8 +179,12 @@ public class NumPadKey extends ViewGroup {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
measureChildren(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
// Set width/height to the same value to ensure a smooth circle for the bg
|
||||
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
|
||||
// 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;
|
||||
|
||||
setMeasuredDimension(getMeasuredWidth(), height);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,7 +203,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
|
||||
|
||||
Reference in New Issue
Block a user