Remove StateProvider from LockIcon

Whenever the state changes in the system, we now push that information
directly to the LockIcon, instead of pushing what we think the prior
state was and letting it query for the current state. This allows
the LockIcon to properly track what _it_ thinks the old state was
(when it last changed its icon) and then react accordingly.

This has the added benefit of being easier to understand with
less code.

Fixes: 153117689
Test: atest SystemUITests && Manual
Change-Id: I8f2e3e1d2287b26ca44b7eb6df8de392efd4bb2a
This commit is contained in:
Dave Mankoff
2020-04-07 14:58:51 -04:00
parent d5729ebc66
commit 9d892e4eba
2 changed files with 15 additions and 19 deletions

View File

@@ -50,19 +50,22 @@ public class LockIcon extends KeyguardAffordanceView {
static final int STATE_BIOMETRICS_ERROR = 3;
private float mDozeAmount;
private int mIconColor;
private StateProvider mStateProvider;
private int mOldState;
private int mState;
private boolean mPulsing;
private boolean mDozing;
private boolean mKeyguardJustShown;
private boolean mPredrawRegistered;
private final SparseArray<Drawable> mDrawableCache = new SparseArray<>();
private final OnPreDrawListener mOnPreDrawListener = new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
getViewTreeObserver().removeOnPreDrawListener(this);
mPredrawRegistered = false;
int newState = mStateProvider.getState();
int newState = mState;
mOldState = mState;
Drawable icon = getIcon(newState);
setImageDrawable(icon, false);
@@ -80,7 +83,7 @@ public class LockIcon extends KeyguardAffordanceView {
@Override
public void onAnimationEnd(Drawable drawable) {
if (getDrawable() == animation
&& newState == mStateProvider.getState()
&& newState == mState
&& newState == STATE_SCANNING_FACE) {
animation.start();
} else {
@@ -100,10 +103,6 @@ public class LockIcon extends KeyguardAffordanceView {
super(context, attrs);
}
void setStateProvider(StateProvider stateProvider) {
mStateProvider = stateProvider;
}
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
@@ -135,13 +134,16 @@ public class LockIcon extends KeyguardAffordanceView {
return false;
}
void update(int oldState, boolean pulsing, boolean dozing, boolean keyguardJustShown) {
mOldState = oldState;
void update(int newState, boolean pulsing, boolean dozing, boolean keyguardJustShown) {
mState = newState;
mPulsing = pulsing;
mDozing = dozing;
mKeyguardJustShown = keyguardJustShown;
getViewTreeObserver().addOnPreDrawListener(mOnPreDrawListener);
if (!mPredrawRegistered) {
mPredrawRegistered = true;
getViewTreeObserver().addOnPreDrawListener(mOnPreDrawListener);
}
}
void setDozeAmount(float dozeAmount) {
@@ -175,7 +177,7 @@ public class LockIcon extends KeyguardAffordanceView {
return mDrawableCache.get(iconRes);
}
static int getIconForState(int state) {
private static int getIconForState(int state) {
int iconRes;
switch (state) {
case STATE_LOCKED:
@@ -196,7 +198,7 @@ public class LockIcon extends KeyguardAffordanceView {
return iconRes;
}
static int getAnimationIndexForTransition(int oldState, int newState, boolean pulsing,
private static int getAnimationIndexForTransition(int oldState, int newState, boolean pulsing,
boolean dozing, boolean keyguardJustShown) {
// Never animate when screen is off
@@ -260,9 +262,4 @@ public class LockIcon extends KeyguardAffordanceView {
}
return LOCK_ANIM_RES_IDS[0][lockAnimIndex];
}
interface StateProvider {
int getState();
}
}

View File

@@ -352,7 +352,6 @@ public class LockscreenLockIconController {
mLockIcon.setOnClickListener(this::handleClick);
mLockIcon.setOnLongClickListener(this::handleLongClick);
mLockIcon.setAccessibilityDelegate(mAccessibilityDelegate);
mLockIcon.setStateProvider(this::getState);
if (mLockIcon.isAttachedToWindow()) {
mOnAttachStateChangeListener.onViewAttachedToWindow(mLockIcon);
@@ -462,7 +461,7 @@ public class LockscreenLockIconController {
shouldUpdate = false;
}
if (shouldUpdate && mLockIcon != null) {
mLockIcon.update(mLastState, mPulsing, mDozing, mKeyguardJustShown);
mLockIcon.update(state, mPulsing, mDozing, mKeyguardJustShown);
}
mLastState = state;
mKeyguardJustShown = false;