From aff42367bf96b4fac3e851f224bb8391d5566f2a Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Fri, 27 Mar 2020 16:28:20 -0700 Subject: [PATCH] Also update color when changing the visibility We were updating the text field color only during some code paths, which is error prone and doesn't handle visibility events well. Also, the color of the field on AOD should never be red, according to UX guidance. Fixes: 149891226 Test: manual Test: atest KeyguardIndicationControllerTest Change-Id: I6e244786e72d90f00b0b733bdcb00c3e8e03582f --- .../KeyguardIndicationController.java | 32 ++++++++----------- .../KeyguardIndicationControllerTest.java | 6 ++-- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index bb0fa2d2c7cb7..5475812b55630 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -93,7 +93,7 @@ public class KeyguardIndicationController implements StateListener, private String mRestingIndication; private String mAlignmentIndication; private CharSequence mTransientIndication; - private ColorStateList mTransientTextColorState; + private boolean mTransientTextIsError; private ColorStateList mInitialTextColorState; private boolean mVisible; private boolean mHideTransientMessageOnScreenOff; @@ -260,7 +260,7 @@ public class KeyguardIndicationController implements StateListener, * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. */ public void showTransientIndication(CharSequence transientIndication) { - showTransientIndication(transientIndication, mInitialTextColorState, + showTransientIndication(transientIndication, false /* isError */, false /* hideOnScreenOff */); } @@ -268,10 +268,10 @@ public class KeyguardIndicationController implements StateListener, * Shows {@param transientIndication} until it is hidden by {@link #hideTransientIndication}. */ private void showTransientIndication(CharSequence transientIndication, - ColorStateList textColorState, boolean hideOnScreenOff) { + boolean isError, boolean hideOnScreenOff) { mTransientIndication = transientIndication; mHideTransientMessageOnScreenOff = hideOnScreenOff && transientIndication != null; - mTransientTextColorState = textColorState; + mTransientTextIsError = isError; mHandler.removeMessages(MSG_HIDE_TRANSIENT); mHandler.removeMessages(MSG_SWIPE_UP_TO_UNLOCK); if (mDozing && !TextUtils.isEmpty(mTransientIndication)) { @@ -311,7 +311,6 @@ public class KeyguardIndicationController implements StateListener, mTextView.switchIndication(mTransientIndication); } else if (!TextUtils.isEmpty(mAlignmentIndication)) { mTextView.switchIndication(mAlignmentIndication); - mTextView.setTextColor(Utils.getColorError(mContext)); } else if (mPowerPluggedIn) { String indication = computePowerIndication(); if (animate) { @@ -336,9 +335,9 @@ public class KeyguardIndicationController implements StateListener, powerIndication = computePowerIndication(); } + boolean isError = false; if (!mKeyguardUpdateMonitor.isUserUnlocked(userId)) { mTextView.switchIndication(com.android.internal.R.string.lockscreen_storage_locked); - mTextView.setTextColor(mInitialTextColorState); } else if (!TextUtils.isEmpty(mTransientIndication)) { if (powerIndication != null && !mTransientIndication.equals(powerIndication)) { String indication = mContext.getResources().getString( @@ -348,7 +347,7 @@ public class KeyguardIndicationController implements StateListener, } else { mTextView.switchIndication(mTransientIndication); } - mTextView.setTextColor(mTransientTextColorState); + isError = mTransientTextIsError; } else if (!TextUtils.isEmpty(trustGrantedIndication) && mKeyguardUpdateMonitor.getUserHasTrust(userId)) { if (powerIndication != null) { @@ -359,15 +358,13 @@ public class KeyguardIndicationController implements StateListener, } else { mTextView.switchIndication(trustGrantedIndication); } - mTextView.setTextColor(mInitialTextColorState); } else if (!TextUtils.isEmpty(mAlignmentIndication)) { mTextView.switchIndication(mAlignmentIndication); - mTextView.setTextColor(Utils.getColorError(mContext)); + isError = true; } else if (mPowerPluggedIn) { if (DEBUG_CHARGING_SPEED) { powerIndication += ", " + (mChargingWattage / 1000) + " mW"; } - mTextView.setTextColor(mInitialTextColorState); if (animate) { animateText(mTextView, powerIndication); } else { @@ -377,11 +374,11 @@ public class KeyguardIndicationController implements StateListener, && mKeyguardUpdateMonitor.getUserTrustIsManaged(userId) && !mKeyguardUpdateMonitor.getUserHasTrust(userId)) { mTextView.switchIndication(trustManagedIndication); - mTextView.setTextColor(mInitialTextColorState); } else { mTextView.switchIndication(mRestingIndication); - mTextView.setTextColor(mInitialTextColorState); } + mTextView.setTextColor(isError ? Utils.getColorError(mContext) + : mInitialTextColorState); } } @@ -532,7 +529,7 @@ public class KeyguardIndicationController implements StateListener, mStatusBarKeyguardViewManager.showBouncerMessage(message, mInitialTextColorState); } else if (mKeyguardUpdateMonitor.isScreenOn()) { showTransientIndication(mContext.getString(R.string.keyguard_unlock), - mInitialTextColorState, true /* hideOnScreenOff */); + false /* isError */, true /* hideOnScreenOff */); hideTransientIndicationDelayed(BaseKeyguardCallback.HIDE_DELAY_MS); } } @@ -551,7 +548,7 @@ public class KeyguardIndicationController implements StateListener, public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("KeyguardIndicationController:"); - pw.println(" mTransientTextColorState: " + mTransientTextColorState); + pw.println(" mTransientTextIsError: " + mTransientTextIsError); pw.println(" mInitialTextColorState: " + mInitialTextColorState); pw.println(" mPowerPluggedInWired: " + mPowerPluggedInWired); pw.println(" mPowerPluggedIn: " + mPowerPluggedIn); @@ -630,7 +627,7 @@ public class KeyguardIndicationController implements StateListener, mStatusBarKeyguardViewManager.showBouncerMessage(helpString, mInitialTextColorState); } else if (mKeyguardUpdateMonitor.isScreenOn()) { - showTransientIndication(helpString, mInitialTextColorState, showSwipeToUnlock); + showTransientIndication(helpString, false /* isError */, showSwipeToUnlock); if (!showSwipeToUnlock) { hideTransientIndicationDelayed(TRANSIENT_BIOMETRIC_ERROR_TIMEOUT); } @@ -704,14 +701,13 @@ public class KeyguardIndicationController implements StateListener, @Override public void onTrustAgentErrorMessage(CharSequence message) { - showTransientIndication(message, Utils.getColorError(mContext), - false /* hideOnScreenOff */); + showTransientIndication(message, true /* isError */, false /* hideOnScreenOff */); } @Override public void onScreenTurnedOn() { if (mMessageToShowOnScreenOn != null) { - showTransientIndication(mMessageToShowOnScreenOn, Utils.getColorError(mContext), + showTransientIndication(mMessageToShowOnScreenOn, true /* isError */, false /* hideOnScreenOff */); // We want to keep this message around in case the screen was off hideTransientIndicationDelayed(HIDE_DELAY_MS); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java index fb401778d891c..be5b190b54a56 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java @@ -192,8 +192,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { assertThat(mTextView.getText()).isEqualTo( mContext.getResources().getString(R.string.dock_alignment_slow_charging)); - assertThat(mTextView.getCurrentTextColor()).isEqualTo( - Utils.getColorError(mContext).getDefaultColor()); + assertThat(mTextView.getCurrentTextColor()).isEqualTo(Color.WHITE); } @Test @@ -210,8 +209,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { assertThat(mTextView.getText()).isEqualTo( mContext.getResources().getString(R.string.dock_alignment_not_charging)); - assertThat(mTextView.getCurrentTextColor()).isEqualTo( - Utils.getColorError(mContext).getDefaultColor()); + assertThat(mTextView.getCurrentTextColor()).isEqualTo(Color.WHITE); } @Test