Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 21 | import android.content.res.TypedArray; |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 22 | import android.graphics.Color; |
| 23 | import android.graphics.PorterDuff; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 24 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 25 | import android.graphics.drawable.Drawable; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 26 | import android.util.AttributeSet; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 27 | import android.view.ContextThemeWrapper; |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 28 | import android.view.accessibility.AccessibilityNodeInfo; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 29 | |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 30 | import com.android.internal.graphics.ColorUtils; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 31 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 32 | import com.android.systemui.R; |
| 33 | import com.android.systemui.statusbar.KeyguardAffordanceView; |
| 34 | import com.android.systemui.statusbar.policy.AccessibilityController; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 35 | import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Manages the different states and animations of the unlock icon. |
| 39 | */ |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 40 | public class LockIcon extends KeyguardAffordanceView implements OnUserInfoChangedListener { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 41 | |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 42 | private static final int FP_DRAW_OFF_TIMEOUT = 800; |
| 43 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 44 | private static final int STATE_LOCKED = 0; |
| 45 | private static final int STATE_LOCK_OPEN = 1; |
| 46 | private static final int STATE_FACE_UNLOCK = 2; |
| 47 | private static final int STATE_FINGERPRINT = 3; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 48 | private static final int STATE_BIOMETRICS_ERROR = 4; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 49 | |
| 50 | private int mLastState = 0; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 51 | private boolean mTransientBiometricsError; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 52 | private boolean mScreenOn; |
| 53 | private boolean mLastScreenOn; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 54 | private Drawable mUserAvatarIcon; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 55 | private final UnlockMethodCache mUnlockMethodCache; |
| 56 | private AccessibilityController mAccessibilityController; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 57 | private boolean mHasFingerPrintState; |
| 58 | private boolean mIsFaceUnlockState; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 59 | private int mDensity; |
Lucas Dupin | f22194f | 2018-12-26 11:43:57 -0800 | [diff] [blame] | 60 | private boolean mPulsing; |
| 61 | private boolean mDozing; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 62 | private boolean mLastDozing; |
| 63 | private boolean mLastPulsing; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 64 | |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 65 | private final Runnable mDrawOffTimeout = () -> update(true /* forceUpdate */); |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 66 | private float mDarkAmount; |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 67 | |
Jorim Jaggi | 582b57f | 2015-04-28 16:28:26 -0700 | [diff] [blame] | 68 | public LockIcon(Context context, AttributeSet attrs) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 69 | super(context, attrs); |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 70 | TypedArray typedArray = context.getTheme().obtainStyledAttributes( |
| 71 | attrs, new int[]{ R.attr.backgroundProtectedStyle }, 0, 0); |
| 72 | mContext = new ContextThemeWrapper(context, |
| 73 | typedArray.getResourceId(0, R.style.BackgroundProtectedStyle)); |
| 74 | typedArray.recycle(); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 75 | mUnlockMethodCache = UnlockMethodCache.getInstance(context); |
| 76 | } |
| 77 | |
| 78 | @Override |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 79 | public void onUserInfoChanged(String name, Drawable picture, String userAccount) { |
| 80 | mUserAvatarIcon = picture; |
| 81 | update(); |
| 82 | } |
| 83 | |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 84 | /** |
| 85 | * If we're currently presenting an authentication error message. |
| 86 | */ |
| 87 | public void setTransientBiometricsError(boolean transientBiometricsError) { |
| 88 | mTransientBiometricsError = transientBiometricsError; |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 89 | update(); |
| 90 | } |
| 91 | |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 92 | public void setScreenOn(boolean screenOn) { |
| 93 | mScreenOn = screenOn; |
| 94 | update(); |
| 95 | } |
| 96 | |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 97 | @Override |
| 98 | protected void onConfigurationChanged(Configuration newConfig) { |
| 99 | super.onConfigurationChanged(newConfig); |
| 100 | final int density = newConfig.densityDpi; |
| 101 | if (density != mDensity) { |
| 102 | mDensity = density; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 103 | update(); |
| 104 | } |
| 105 | } |
| 106 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 107 | public void update() { |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 108 | update(false /* force */); |
| 109 | } |
| 110 | |
| 111 | public void update(boolean force) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 112 | int state = getState(); |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 113 | boolean anyFingerprintState = state == STATE_FINGERPRINT |
| 114 | || state == STATE_BIOMETRICS_ERROR; |
| 115 | mIsFaceUnlockState = state == STATE_FACE_UNLOCK; |
| 116 | if (state != mLastState || mLastDozing == mDozing || mLastPulsing == mPulsing |
| 117 | || mLastScreenOn != mScreenOn || force) { |
| 118 | int iconAnimRes = getAnimationResForTransition(mLastState, state, mLastPulsing, |
| 119 | mPulsing, mLastDozing, mDozing); |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 120 | boolean isAnim = iconAnimRes != -1; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 121 | |
| 122 | Drawable icon; |
| 123 | if (isAnim) { |
| 124 | // Load the animation resource. |
| 125 | icon = mContext.getDrawable(iconAnimRes); |
| 126 | } else { |
| 127 | // Load the static icon resource based on the current state. |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 128 | icon = getIconForState(state); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 129 | } |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 130 | |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 131 | final AnimatedVectorDrawable animation = icon instanceof AnimatedVectorDrawable |
| 132 | ? (AnimatedVectorDrawable) icon |
| 133 | : null; |
Evan Laird | b0ddf87 | 2017-07-24 15:52:59 -0400 | [diff] [blame] | 134 | setImageDrawable(icon, false); |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 135 | updateDarkTint(); |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 136 | if (mIsFaceUnlockState) { |
Bingyu Zhang | bfe6dcf | 2018-04-25 10:20:36 -0700 | [diff] [blame] | 137 | announceForAccessibility(getContext().getString( |
| 138 | R.string.accessibility_scanning_face)); |
| 139 | } |
| 140 | |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 141 | mHasFingerPrintState = anyFingerprintState; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 142 | if (animation != null && isAnim) { |
Jorim Jaggi | 23bb84b | 2016-06-30 19:11:38 -0700 | [diff] [blame] | 143 | animation.forceAnimationOnUI(); |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 144 | animation.start(); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 145 | } |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 146 | |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 147 | if (isAnim && !mLastScreenOn) { |
Jorim Jaggi | 8dea48c | 2016-11-28 14:47:45 +0100 | [diff] [blame] | 148 | removeCallbacks(mDrawOffTimeout); |
| 149 | postDelayed(mDrawOffTimeout, FP_DRAW_OFF_TIMEOUT); |
| 150 | } else { |
| 151 | removeCallbacks(mDrawOffTimeout); |
| 152 | } |
| 153 | |
Jorim Jaggi | 864e64b | 2015-05-20 14:13:23 -0700 | [diff] [blame] | 154 | mLastState = state; |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 155 | mLastScreenOn = mScreenOn; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 156 | mLastDozing = mDozing; |
| 157 | mLastPulsing = mPulsing; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Lucas Dupin | f22194f | 2018-12-26 11:43:57 -0800 | [diff] [blame] | 160 | setVisibility(mDozing && !mPulsing ? GONE : VISIBLE); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 161 | updateClickability(); |
| 162 | } |
| 163 | |
| 164 | private void updateClickability() { |
| 165 | if (mAccessibilityController == null) { |
| 166 | return; |
| 167 | } |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 168 | boolean canLock = mUnlockMethodCache.isMethodSecure() |
| 169 | && mUnlockMethodCache.canSkipBouncer(); |
Adrian Roos | a94e964 | 2017-08-17 17:29:19 +0200 | [diff] [blame] | 170 | boolean clickToUnlock = mAccessibilityController.isAccessibilityEnabled(); |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 171 | boolean clickToForceLock = canLock && !clickToUnlock; |
| 172 | boolean longClickToForceLock = canLock && !clickToForceLock; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 173 | setClickable(clickToForceLock || clickToUnlock); |
| 174 | setLongClickable(longClickToForceLock); |
| 175 | setFocusable(mAccessibilityController.isAccessibilityEnabled()); |
| 176 | } |
| 177 | |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 178 | @Override |
| 179 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 180 | super.onInitializeAccessibilityNodeInfo(info); |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 181 | if (mHasFingerPrintState) { |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 182 | AccessibilityNodeInfo.AccessibilityAction unlock |
| 183 | = new AccessibilityNodeInfo.AccessibilityAction( |
| 184 | AccessibilityNodeInfo.ACTION_CLICK, |
| 185 | getContext().getString(R.string.accessibility_unlock_without_fingerprint)); |
| 186 | info.addAction(unlock); |
Selim Cinek | 947c77c | 2017-03-23 14:20:32 -0700 | [diff] [blame] | 187 | info.setHintText(getContext().getString( |
| 188 | R.string.accessibility_waiting_for_fingerprint)); |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 189 | } else if (mIsFaceUnlockState) { |
Bingyu Zhang | bfe6dcf | 2018-04-25 10:20:36 -0700 | [diff] [blame] | 190 | //Avoid 'button' to be spoken for scanning face |
| 191 | info.setClassName(LockIcon.class.getName()); |
| 192 | info.setContentDescription(getContext().getString( |
| 193 | R.string.accessibility_scanning_face)); |
Selim Cinek | c99d9a95 | 2015-06-19 18:44:50 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 197 | public void setAccessibilityController(AccessibilityController accessibilityController) { |
| 198 | mAccessibilityController = accessibilityController; |
| 199 | } |
| 200 | |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 201 | private Drawable getIconForState(int state) { |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 202 | int iconRes; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 203 | switch (state) { |
Lucas Dupin | 117365d | 2018-10-03 15:49:46 -0700 | [diff] [blame] | 204 | case STATE_FINGERPRINT: |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 205 | case STATE_LOCKED: |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 206 | case STATE_FACE_UNLOCK: |
| 207 | iconRes = com.android.internal.R.drawable.ic_lock_24dp; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 208 | break; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 209 | case STATE_LOCK_OPEN: |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 210 | if (mUnlockMethodCache.isTrustManaged() && mUnlockMethodCache.isTrusted() |
| 211 | && mUserAvatarIcon != null) { |
| 212 | return mUserAvatarIcon; |
| 213 | } else { |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 214 | iconRes = com.android.internal.R.drawable.ic_lock_open_24dp; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 215 | } |
| 216 | break; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 217 | case STATE_BIOMETRICS_ERROR: |
| 218 | iconRes = com.android.internal.R.drawable.ic_auth_error; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 219 | break; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 220 | default: |
| 221 | throw new IllegalArgumentException(); |
| 222 | } |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 223 | |
| 224 | return mContext.getDrawable(iconRes); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 227 | private int getAnimationResForTransition(int oldState, int newState, |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 228 | boolean wasPulsing, boolean pulsing, |
| 229 | boolean wasDozing, boolean dozing) { |
| 230 | |
| 231 | boolean isError = newState == STATE_BIOMETRICS_ERROR; |
| 232 | boolean isUnlocked = newState == STATE_LOCK_OPEN; |
| 233 | boolean isLocked = !isUnlocked; |
| 234 | boolean wasUnlocked = oldState == STATE_LOCK_OPEN; |
| 235 | |
| 236 | if (isError) { |
| 237 | return com.android.internal.R.anim.lock_to_error; |
| 238 | } else if (isUnlocked) { |
| 239 | return com.android.internal.R.anim.lock_unlock; |
| 240 | } else if (wasUnlocked && isLocked && mScreenOn) { |
| 241 | return com.android.internal.R.anim.lock_lock; |
| 242 | } else if (isLocked && (!wasPulsing && pulsing || wasDozing && !dozing)) { |
| 243 | return com.android.internal.R.anim.lock_in; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 244 | } |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 245 | return -1; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | private int getState() { |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 249 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 250 | boolean fingerprintRunning = updateMonitor.isFingerprintDetectionRunning(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 251 | boolean unlockingAllowed = updateMonitor.isUnlockingWithBiometricAllowed(); |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 252 | if (mTransientBiometricsError) { |
| 253 | return STATE_BIOMETRICS_ERROR; |
Selim Cinek | c384198 | 2015-08-25 18:34:29 -0700 | [diff] [blame] | 254 | } else if (mUnlockMethodCache.canSkipBouncer()) { |
| 255 | return STATE_LOCK_OPEN; |
Lucas Dupin | c9e5d76 | 2019-01-28 09:34:30 -0800 | [diff] [blame] | 256 | } else if (mUnlockMethodCache.isFaceUnlockRunning() |
| 257 | || updateMonitor.isFaceDetectionRunning()) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 258 | return STATE_FACE_UNLOCK; |
Adrian Roos | e07cbaf | 2015-09-02 13:29:42 -0700 | [diff] [blame] | 259 | } else if (fingerprintRunning && unlockingAllowed) { |
| 260 | return STATE_FINGERPRINT; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 261 | } else { |
| 262 | return STATE_LOCKED; |
| 263 | } |
| 264 | } |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 265 | |
| 266 | public void setDarkAmount(float darkAmount) { |
| 267 | mDarkAmount = darkAmount; |
| 268 | updateDarkTint(); |
| 269 | } |
| 270 | |
Lucas Dupin | f22194f | 2018-12-26 11:43:57 -0800 | [diff] [blame] | 271 | /** |
| 272 | * When keyguard is in pulsing (AOD2) state. |
| 273 | * @param pulsing {@code true} when pulsing. |
| 274 | * @param animated if transition should be animated. |
| 275 | */ |
| 276 | public void setPulsing(boolean pulsing, boolean animated) { |
| 277 | mPulsing = pulsing; |
| 278 | update(); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Sets the dozing state of the keyguard. |
| 283 | */ |
| 284 | public void setDozing(boolean dozing) { |
| 285 | mDozing = dozing; |
| 286 | update(); |
| 287 | } |
| 288 | |
Lucas Dupin | c90a6bf | 2018-10-10 13:53:20 -0700 | [diff] [blame] | 289 | private void updateDarkTint() { |
| 290 | Drawable drawable = getDrawable().mutate(); |
| 291 | int color = ColorUtils.blendARGB(Color.TRANSPARENT, Color.WHITE, mDarkAmount); |
| 292 | drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); |
| 293 | } |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 294 | } |