blob: ce34d0b3b7ccb706fcb4d2b51b18865e86aa8074 [file] [log] [blame]
Jim Millerdcb3d842012-08-23 19:18:12 -07001/*
2 * Copyright (C) 2012 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
Jim Miller5ecd8112013-01-09 18:50:26 -080017package com.android.keyguard;
Jim Millerdcb3d842012-08-23 19:18:12 -070018
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -070019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Alex Chauff7653d2018-02-01 17:18:08 +000021import android.app.ActivityManager;
Alex Chauff7653d2018-02-01 17:18:08 +000022import android.app.IActivityManager;
Jim Millerdcb3d842012-08-23 19:18:12 -070023import android.content.Context;
Jim Miller0c486892013-10-11 16:21:45 -070024import android.content.res.Resources;
Lucas Dupin76d38e72017-05-13 22:04:22 -070025import android.graphics.Color;
Geoffrey Pitschc239fef2017-07-14 09:55:16 -040026import android.os.Handler;
27import android.os.Looper;
Alex Chauff7653d2018-02-01 17:18:08 +000028import android.os.RemoteException;
Adrian Roos9dd16eb2015-01-08 16:20:49 +010029import android.os.UserHandle;
Lucas Dupin76d38e72017-05-13 22:04:22 -070030import android.support.v4.graphics.ColorUtils;
Jim Milleredc74ab2012-11-06 21:46:11 -080031import android.text.TextUtils;
Jim Miller38ab2772013-10-08 15:32:09 -070032import android.text.format.DateFormat;
Lucas Dupin6bd86012017-12-05 17:58:57 -080033import android.util.ArraySet;
Jim Millerdcb3d842012-08-23 19:18:12 -070034import android.util.AttributeSet;
Jim Miller20daffd2013-10-07 14:59:53 -070035import android.util.Log;
Jim Milleredc74ab2012-11-06 21:46:11 -080036import android.util.Slog;
Jorim Jaggie210cc82014-08-12 23:44:59 +020037import android.util.TypedValue;
Jim Milleredc74ab2012-11-06 21:46:11 -080038import android.view.View;
Jim Millerdcb3d842012-08-23 19:18:12 -070039import android.widget.GridLayout;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -070040import android.widget.RelativeLayout;
Jim Miller38ab2772013-10-08 15:32:09 -070041import android.widget.TextClock;
Jim Milleredc74ab2012-11-06 21:46:11 -080042import android.widget.TextView;
Jim Millerdcb3d842012-08-23 19:18:12 -070043
Michael Jurka1254f2f2012-10-25 11:44:31 -070044import com.android.internal.widget.LockPatternUtils;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -070045import com.android.internal.widget.ViewClippingUtil;
46import com.android.systemui.Dependency;
47import com.android.systemui.Interpolators;
48import com.android.systemui.statusbar.policy.ConfigurationController;
49import com.android.systemui.util.wakelock.KeepAwakeAnimationListener;
Michael Jurka1254f2f2012-10-25 11:44:31 -070050
Lucas Dupin6bd86012017-12-05 17:58:57 -080051import com.google.android.collect.Sets;
52
Chris Wren56018e52013-01-15 10:59:43 -050053import java.util.Locale;
54
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -070055public class KeyguardStatusView extends GridLayout implements
56 ConfigurationController.ConfigurationListener, View.OnLayoutChangeListener {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010057 private static final boolean DEBUG = KeyguardConstants.DEBUG;
Jim Milleredc74ab2012-11-06 21:46:11 -080058 private static final String TAG = "KeyguardStatusView";
Geoffrey Pitschc239fef2017-07-14 09:55:16 -040059 private static final int MARQUEE_DELAY_MS = 2000;
Jim Milleredc74ab2012-11-06 21:46:11 -080060
Adrian Roos9dd16eb2015-01-08 16:20:49 +010061 private final LockPatternUtils mLockPatternUtils;
Alex Chauff7653d2018-02-01 17:18:08 +000062 private final IActivityManager mIActivityManager;
Lucas Dupin6bd86012017-12-05 17:58:57 -080063 private final float mSmallClockScale;
Jim Milleredc74ab2012-11-06 21:46:11 -080064
Alex Chauff7653d2018-02-01 17:18:08 +000065 private TextView mLogoutView;
Jim Miller0c486892013-10-11 16:21:45 -070066 private TextClock mClockView;
Lucas Dupin6bd86012017-12-05 17:58:57 -080067 private View mClockSeparator;
Jorim Jaggi93afa1d2014-06-03 20:56:32 +020068 private TextView mOwnerInfo;
Lucas Dupin957e50c2017-10-10 11:23:27 -070069 private KeyguardSliceView mKeyguardSlice;
Geoffrey Pitschc239fef2017-07-14 09:55:16 -040070 private Runnable mPendingMarqueeStart;
71 private Handler mHandler;
Jim Milleredc74ab2012-11-06 21:46:11 -080072
Lucas Dupin6bd86012017-12-05 17:58:57 -080073 private ArraySet<View> mVisibleInDoze;
Adrian Roosd83e9992017-03-16 15:17:57 -070074 private boolean mPulsing;
Adrian Roos7f910722017-07-12 19:15:59 +020075 private float mDarkAmount = 0;
Lucas Dupin76d38e72017-05-13 22:04:22 -070076 private int mTextColor;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -070077 private float mWidgetPadding;
78 private boolean mAnimateLayout;
79 private int mLastLayoutHeight;
Adrian Roosd83e9992017-03-16 15:17:57 -070080
Jim Milleredc74ab2012-11-06 21:46:11 -080081 private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
82
83 @Override
84 public void onTimeChanged() {
85 refresh();
86 }
87
88 @Override
Jorim Jaggi5cf17872014-03-26 18:31:48 +010089 public void onKeyguardVisibilityChanged(boolean showing) {
Jim Milleredc74ab2012-11-06 21:46:11 -080090 if (showing) {
91 if (DEBUG) Slog.v(TAG, "refresh statusview showing:" + showing);
92 refresh();
Jorim Jaggi93afa1d2014-06-03 20:56:32 +020093 updateOwnerInfo();
Alex Chauff7653d2018-02-01 17:18:08 +000094 updateLogoutView();
Jim Milleredc74ab2012-11-06 21:46:11 -080095 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +010096 }
Jim Miller20daffd2013-10-07 14:59:53 -070097
Jim Miller38ab2772013-10-08 15:32:09 -070098 @Override
Jorim Jaggi0d210f62015-07-10 14:24:44 -070099 public void onStartedWakingUp() {
Jim Miller20daffd2013-10-07 14:59:53 -0700100 setEnableMarquee(true);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100101 }
Jim Miller20daffd2013-10-07 14:59:53 -0700102
Jim Miller38ab2772013-10-08 15:32:09 -0700103 @Override
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700104 public void onFinishedGoingToSleep(int why) {
Jim Miller20daffd2013-10-07 14:59:53 -0700105 setEnableMarquee(false);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100106 }
Jorim Jaggic7dea6e2014-07-26 14:36:57 +0200107
108 @Override
109 public void onUserSwitchComplete(int userId) {
110 refresh();
Adrian Roose32dac82014-07-28 15:58:50 +0200111 updateOwnerInfo();
Alex Chauff7653d2018-02-01 17:18:08 +0000112 updateLogoutView();
113 }
114
115 @Override
116 public void onLogoutEnabledChanged() {
117 updateLogoutView();
Jorim Jaggic7dea6e2014-07-26 14:36:57 +0200118 }
Jim Milleredc74ab2012-11-06 21:46:11 -0800119 };
Jim Miller6212cc02012-09-05 17:35:31 -0700120
Jim Millerdcb3d842012-08-23 19:18:12 -0700121 public KeyguardStatusView(Context context) {
122 this(context, null, 0);
123 }
124
125 public KeyguardStatusView(Context context, AttributeSet attrs) {
126 this(context, attrs, 0);
127 }
128
129 public KeyguardStatusView(Context context, AttributeSet attrs, int defStyle) {
130 super(context, attrs, defStyle);
Alex Chauff7653d2018-02-01 17:18:08 +0000131 mIActivityManager = ActivityManager.getService();
Adrian Roos9dd16eb2015-01-08 16:20:49 +0100132 mLockPatternUtils = new LockPatternUtils(getContext());
Geoffrey Pitschc239fef2017-07-14 09:55:16 -0400133 mHandler = new Handler(Looper.myLooper());
Lucas Dupin6bd86012017-12-05 17:58:57 -0800134 mSmallClockScale = getResources().getDimension(R.dimen.widget_small_font_size)
135 / getResources().getDimension(R.dimen.widget_big_font_size);
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700136 onDensityOrFontScaleChanged();
Jim Millerdcb3d842012-08-23 19:18:12 -0700137 }
138
Jim Miller20daffd2013-10-07 14:59:53 -0700139 private void setEnableMarquee(boolean enabled) {
Geoffrey Pitschc239fef2017-07-14 09:55:16 -0400140 if (DEBUG) Log.v(TAG, "Schedule setEnableMarquee: " + (enabled ? "Enable" : "Disable"));
141 if (enabled) {
142 if (mPendingMarqueeStart == null) {
143 mPendingMarqueeStart = () -> {
144 setEnableMarqueeImpl(true);
145 mPendingMarqueeStart = null;
146 };
147 mHandler.postDelayed(mPendingMarqueeStart, MARQUEE_DELAY_MS);
148 }
149 } else {
150 if (mPendingMarqueeStart != null) {
151 mHandler.removeCallbacks(mPendingMarqueeStart);
152 mPendingMarqueeStart = null;
153 }
154 setEnableMarqueeImpl(false);
155 }
156 }
157
158 private void setEnableMarqueeImpl(boolean enabled) {
Jim Miller20daffd2013-10-07 14:59:53 -0700159 if (DEBUG) Log.v(TAG, (enabled ? "Enable" : "Disable") + " transport text marquee");
John Spurlock1e6eb172014-07-13 11:59:50 -0400160 if (mOwnerInfo != null) mOwnerInfo.setSelected(enabled);
Jim Miller20daffd2013-10-07 14:59:53 -0700161 }
162
Jim Milleredc74ab2012-11-06 21:46:11 -0800163 @Override
164 protected void onFinishInflate() {
165 super.onFinishInflate();
Alex Chauff7653d2018-02-01 17:18:08 +0000166 mLogoutView = findViewById(R.id.logout);
167 mLogoutView.setOnClickListener(this::onLogoutClicked);
168
Alan Viverette51efddb2017-04-05 10:00:01 -0400169 mClockView = findViewById(R.id.clock_view);
Selim Cinek9c4a7072014-11-21 17:44:34 +0100170 mClockView.setShowCurrentUserTime(true);
Adrian Roosb670f4b2017-07-20 20:06:54 +0200171 if (KeyguardClockAccessibilityDelegate.isNeeded(mContext)) {
172 mClockView.setAccessibilityDelegate(new KeyguardClockAccessibilityDelegate(mContext));
173 }
Alan Viverette51efddb2017-04-05 10:00:01 -0400174 mOwnerInfo = findViewById(R.id.owner_info);
Lucas Dupin957e50c2017-10-10 11:23:27 -0700175 mKeyguardSlice = findViewById(R.id.keyguard_status_area);
Lucas Dupin6bd86012017-12-05 17:58:57 -0800176 mClockSeparator = findViewById(R.id.clock_separator);
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700177 mVisibleInDoze = Sets.newArraySet(mClockView, mKeyguardSlice);
Lucas Dupin76d38e72017-05-13 22:04:22 -0700178 mTextColor = mClockView.getCurrentTextColor();
Adrian Roos9dd16eb2015-01-08 16:20:49 +0100179
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700180 mClockView.addOnLayoutChangeListener(this);
181 mClockSeparator.addOnLayoutChangeListener(this);
182 mKeyguardSlice.setContentChangeListener(this::onSliceContentChanged);
183 onSliceContentChanged(false /* animated */);
Lucas Dupin6bd86012017-12-05 17:58:57 -0800184
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700185 boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
186 setEnableMarquee(shouldMarquee);
Jim Milleredc74ab2012-11-06 21:46:11 -0800187 refresh();
Jorim Jaggi93afa1d2014-06-03 20:56:32 +0200188 updateOwnerInfo();
Alex Chauff7653d2018-02-01 17:18:08 +0000189 updateLogoutView();
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700190 updateDark();
Jorim Jaggicc12a9d2014-05-26 01:55:29 +0200191
192 // Disable elegant text height because our fancy colon makes the ymin value huge for no
193 // reason.
194 mClockView.setElegantTextHeight(false);
Jim Milleredc74ab2012-11-06 21:46:11 -0800195 }
196
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700197 private void onSliceContentChanged(boolean animated) {
198 mAnimateLayout = animated;
199 boolean smallClock = mKeyguardSlice.hasHeader() || mPulsing;
200 float clockScale = smallClock ? mSmallClockScale : 1;
201
202 RelativeLayout.LayoutParams layoutParams =
203 (RelativeLayout.LayoutParams) mClockView.getLayoutParams();
204 int height = mClockView.getHeight();
205 layoutParams.bottomMargin = (int) -(height - (clockScale * height));
206 mClockView.setLayoutParams(layoutParams);
207
208 layoutParams = (RelativeLayout.LayoutParams) mClockSeparator.getLayoutParams();
209 layoutParams.topMargin = smallClock ? (int) mWidgetPadding : 0;
210 layoutParams.bottomMargin = layoutParams.topMargin;
211 mClockSeparator.setLayoutParams(layoutParams);
212 }
213
214 /**
215 * Animate clock and its separator when necessary.
216 */
217 @Override
218 public void onLayoutChange(View view, int left, int top, int right, int bottom,
219 int oldLeft, int oldTop, int oldRight, int oldBottom) {
220 int heightOffset = mPulsing ? 0 : getHeight() - mLastLayoutHeight;
221 boolean hasHeader = mKeyguardSlice.hasHeader();
222 boolean smallClock = hasHeader || mPulsing;
223 long duration = KeyguardSliceView.DEFAULT_ANIM_DURATION;
224 long delay = smallClock ? 0 : duration / 4;
225
226 if (view == mClockView) {
227 float clockScale = smallClock ? mSmallClockScale : 1;
228 if (mAnimateLayout) {
229 mClockView.setY(oldTop + heightOffset);
230 mClockView.animate().cancel();
231 mClockView.animate()
232 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
233 .setDuration(duration)
234 .setListener(new ClipChildrenAnimationListener())
235 .setStartDelay(delay)
236 .y(top)
237 .scaleX(clockScale)
238 .scaleY(clockScale)
239 .start();
240 } else {
241 mClockView.setY(top);
242 mClockView.setScaleX(clockScale);
243 mClockView.setScaleY(clockScale);
244 }
245 } else if (view == mClockSeparator) {
246 boolean hasSeparator = hasHeader && !mPulsing;
247 float alpha = hasSeparator ? 1 : 0;
248 if (mAnimateLayout) {
249 boolean isAwake = mDarkAmount != 0;
250 mClockSeparator.setY(oldTop + heightOffset);
251 mClockSeparator.animate().cancel();
252 mClockSeparator.animate()
253 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
254 .setDuration(duration)
255 .setListener(isAwake ? null : new KeepAwakeAnimationListener(getContext()))
256 .setStartDelay(delay)
257 .y(top)
258 .alpha(alpha)
259 .start();
260 } else {
261 mClockSeparator.setY(top);
262 mClockSeparator.setAlpha(alpha);
263 }
Lucas Dupin6bd86012017-12-05 17:58:57 -0800264 }
Lucas Dupin6bd86012017-12-05 17:58:57 -0800265 }
266
Jorim Jaggie210cc82014-08-12 23:44:59 +0200267 @Override
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700268 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
269 super.onLayout(changed, left, top, right, bottom);
270 mClockView.setPivotX(mClockView.getWidth() / 2);
271 mClockView.setPivotY(0);
272 mLastLayoutHeight = getHeight();
273 }
274
275 @Override
276 public void onDensityOrFontScaleChanged() {
277 mWidgetPadding = getResources().getDimension(R.dimen.widget_vertical_padding);
278 if (mClockView != null) {
279 mClockView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
280 getResources().getDimensionPixelSize(R.dimen.widget_big_font_size));
281 }
Jorim Jaggiad15b492017-05-30 18:01:49 -0700282 if (mOwnerInfo != null) {
283 mOwnerInfo.setTextSize(TypedValue.COMPLEX_UNIT_PX,
284 getResources().getDimensionPixelSize(R.dimen.widget_label_font_size));
285 }
Jorim Jaggie210cc82014-08-12 23:44:59 +0200286 }
287
Jorim Jaggid09def7512014-09-02 18:36:45 +0200288 public void refreshTime() {
Lucas Dupinf9583c42018-04-05 22:20:44 -0700289 mClockView.refresh();
Jorim Jaggid09def7512014-09-02 18:36:45 +0200290 }
Jim Miller0c486892013-10-11 16:21:45 -0700291
Jorim Jaggid09def7512014-09-02 18:36:45 +0200292 private void refresh() {
Lucas Dupinca46ae92018-04-02 11:05:09 -0700293 Patterns.update(mContext);
Jorim Jaggid09def7512014-09-02 18:36:45 +0200294 refreshTime();
Jim Milleredc74ab2012-11-06 21:46:11 -0800295 }
296
Alex Chauff7653d2018-02-01 17:18:08 +0000297 public int getLogoutButtonHeight() {
298 return mLogoutView.getVisibility() == VISIBLE ? mLogoutView.getHeight() : 0;
Adrian Roosc934c432017-01-13 11:44:56 -0800299 }
300
Lucas Dupin987f1932017-05-13 21:02:52 -0700301 public float getClockTextSize() {
302 return mClockView.getTextSize();
303 }
304
Alex Chauff7653d2018-02-01 17:18:08 +0000305 private void updateLogoutView() {
306 mLogoutView.setVisibility(shouldShowLogout() ? VISIBLE : GONE);
307 // Logout button will stay in language of user 0 if we don't set that manually.
308 mLogoutView.setText(mContext.getResources().getString(
309 com.android.internal.R.string.global_action_logout));
310 }
311
Jorim Jaggi93afa1d2014-06-03 20:56:32 +0200312 private void updateOwnerInfo() {
John Spurlock1e6eb172014-07-13 11:59:50 -0400313 if (mOwnerInfo == null) return;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700314 String info = mLockPatternUtils.getDeviceOwnerInfo();
315 if (info == null) {
Andrei Stingaceanu04e245b2015-11-12 12:15:56 +0000316 // Use the current user owner information if enabled.
317 final boolean ownerInfoEnabled = mLockPatternUtils.isOwnerInfoEnabled(
318 KeyguardUpdateMonitor.getCurrentUser());
319 if (ownerInfoEnabled) {
320 info = mLockPatternUtils.getOwnerInfo(KeyguardUpdateMonitor.getCurrentUser());
321 }
Jorim Jaggi93afa1d2014-06-03 20:56:32 +0200322 }
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700323 mOwnerInfo.setText(info);
324 }
325
326 @Override
327 protected void onAttachedToWindow() {
328 super.onAttachedToWindow();
329 KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mInfoCallback);
330 Dependency.get(ConfigurationController.class).addCallback(this);
331 }
332
333 @Override
334 protected void onDetachedFromWindow() {
335 super.onDetachedFromWindow();
336 KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mInfoCallback);
337 Dependency.get(ConfigurationController.class).removeCallback(this);
Jorim Jaggi93afa1d2014-06-03 20:56:32 +0200338 }
339
Selim Cinekf99d0002014-06-13 07:36:01 +0200340 @Override
341 public boolean hasOverlappingRendering() {
342 return false;
343 }
344
John Spurlock385a63d2013-10-30 19:40:48 -0400345 // DateFormat.getBestDateTimePattern is extremely expensive, and refresh is called often.
346 // This is an optimization to ensure we only recompute the patterns when the inputs change.
347 private static final class Patterns {
John Spurlock385a63d2013-10-30 19:40:48 -0400348 static String clockView12;
349 static String clockView24;
350 static String cacheKey;
351
Lucas Dupinca46ae92018-04-02 11:05:09 -0700352 static void update(Context context) {
John Spurlock385a63d2013-10-30 19:40:48 -0400353 final Locale locale = Locale.getDefault();
354 final Resources res = context.getResources();
John Spurlock385a63d2013-10-30 19:40:48 -0400355 final String clockView12Skel = res.getString(R.string.clock_12hr_format);
356 final String clockView24Skel = res.getString(R.string.clock_24hr_format);
Lucas Dupinca46ae92018-04-02 11:05:09 -0700357 final String key = locale.toString() + clockView12Skel + clockView24Skel;
John Spurlock385a63d2013-10-30 19:40:48 -0400358 if (key.equals(cacheKey)) return;
359
John Spurlock385a63d2013-10-30 19:40:48 -0400360 clockView12 = DateFormat.getBestDateTimePattern(locale, clockView12Skel);
361 // CLDR insists on adding an AM/PM indicator even though it wasn't in the skeleton
362 // format. The following code removes the AM/PM indicator if we didn't want it.
363 if (!clockView12Skel.contains("a")) {
364 clockView12 = clockView12.replaceAll("a", "").trim();
365 }
366
367 clockView24 = DateFormat.getBestDateTimePattern(locale, clockView24Skel);
368
Jorim Jaggicc12a9d2014-05-26 01:55:29 +0200369 // Use fancy colon.
370 clockView24 = clockView24.replace(':', '\uee01');
371 clockView12 = clockView12.replace(':', '\uee01');
372
John Spurlock385a63d2013-10-30 19:40:48 -0400373 cacheKey = key;
374 }
375 }
Adrian Roos7907ff22017-01-17 15:44:11 -0800376
Lucas Dupin4272f442018-01-13 22:00:35 -0800377 public void setDarkAmount(float darkAmount) {
Lucas Dupin76d38e72017-05-13 22:04:22 -0700378 if (mDarkAmount == darkAmount) {
Adrian Roos52414e32017-04-28 09:23:19 -0700379 return;
380 }
Lucas Dupin76d38e72017-05-13 22:04:22 -0700381 mDarkAmount = darkAmount;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700382 updateDark();
Adrian Roos7907ff22017-01-17 15:44:11 -0800383 }
Adrian Roosd83e9992017-03-16 15:17:57 -0700384
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700385 private void updateDark() {
386 boolean dark = mDarkAmount == 1;
387 mLogoutView.setAlpha(dark ? 0 : 1);
388 if (mOwnerInfo != null) {
389 boolean hasText = !TextUtils.isEmpty(mOwnerInfo.getText());
390 mOwnerInfo.setVisibility(hasText && mDarkAmount != 1 ? VISIBLE : GONE);
391 }
392
393 final int blendedTextColor = ColorUtils.blendARGB(mTextColor, Color.WHITE, mDarkAmount);
394 updateDozeVisibleViews();
395 mKeyguardSlice.setDarkAmount(mDarkAmount);
396 mClockView.setTextColor(blendedTextColor);
397 mClockSeparator.setBackgroundColor(blendedTextColor);
398 }
399
400 public void setPulsing(boolean pulsing, boolean animate) {
Adrian Roosd83e9992017-03-16 15:17:57 -0700401 mPulsing = pulsing;
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700402 mKeyguardSlice.setPulsing(pulsing, animate);
Adrian Roosd83e9992017-03-16 15:17:57 -0700403 updateDozeVisibleViews();
404 }
405
406 private void updateDozeVisibleViews() {
407 for (View child : mVisibleInDoze) {
Lucas Dupin76d38e72017-05-13 22:04:22 -0700408 child.setAlpha(mDarkAmount == 1 && mPulsing ? 0.8f : 1);
Adrian Roosd83e9992017-03-16 15:17:57 -0700409 }
410 }
Alex Chauff7653d2018-02-01 17:18:08 +0000411
412 private boolean shouldShowLogout() {
413 return KeyguardUpdateMonitor.getInstance(mContext).isLogoutEnabled()
414 && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM;
415 }
416
417 private void onLogoutClicked(View view) {
418 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
419 try {
420 mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
421 mIActivityManager.stopUser(currentUserId, true /*force*/, null);
422 } catch (RemoteException re) {
423 Log.e(TAG, "Failed to logout user", re);
424 }
425 }
Lucas Dupin3d7ccaf2018-04-02 21:19:23 -0700426
427 private class ClipChildrenAnimationListener extends AnimatorListenerAdapter implements
428 ViewClippingUtil.ClippingParameters {
429
430 ClipChildrenAnimationListener() {
431 ViewClippingUtil.setClippingDeactivated(mClockView, true /* deactivated */,
432 this /* clippingParams */);
433 }
434
435 @Override
436 public void onAnimationEnd(Animator animation) {
437 ViewClippingUtil.setClippingDeactivated(mClockView, false /* deactivated */,
438 this /* clippingParams */);
439 }
440
441 @Override
442 public boolean shouldFinish(View view) {
443 return view == getParent();
444 }
445 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700446}