Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1 | /* |
| 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 Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 17 | package com.android.keyguard; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 18 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 20 | import android.app.IActivityManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Jim Miller | 0c48689 | 2013-10-11 16:21:45 -0700 | [diff] [blame] | 22 | import android.content.res.Resources; |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 23 | import android.graphics.Color; |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 24 | import android.os.Handler; |
| 25 | import android.os.Looper; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 26 | import android.os.RemoteException; |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 27 | import android.os.UserHandle; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 28 | import android.text.TextUtils; |
Jim Miller | 38ab277 | 2013-10-08 15:32:09 -0700 | [diff] [blame] | 29 | import android.text.format.DateFormat; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 30 | import android.util.ArraySet; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 31 | import android.util.AttributeSet; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 32 | import android.util.Log; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 33 | import android.util.Slog; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 34 | import android.util.TypedValue; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 35 | import android.view.View; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 36 | import android.widget.GridLayout; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 37 | import android.widget.TextView; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 38 | |
Lucas Dupin | 43976f8 | 2018-10-22 19:52:59 -0700 | [diff] [blame] | 39 | import androidx.core.graphics.ColorUtils; |
| 40 | |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 41 | import com.android.internal.widget.LockPatternUtils; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 42 | import com.android.systemui.Dependency; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 43 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 44 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 45 | import com.google.android.collect.Sets; |
| 46 | |
Chris Wren | 56018e5 | 2013-01-15 10:59:43 -0500 | [diff] [blame] | 47 | import java.util.Locale; |
Robert Snoeberger | 9c1074f | 2018-12-07 17:35:21 -0500 | [diff] [blame] | 48 | import java.util.TimeZone; |
Chris Wren | 56018e5 | 2013-01-15 10:59:43 -0500 | [diff] [blame] | 49 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 50 | public class KeyguardStatusView extends GridLayout implements |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 51 | ConfigurationController.ConfigurationListener { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 52 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 53 | private static final String TAG = "KeyguardStatusView"; |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 54 | private static final int MARQUEE_DELAY_MS = 2000; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 55 | |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 56 | private final LockPatternUtils mLockPatternUtils; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 57 | private final IActivityManager mIActivityManager; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 58 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 59 | private TextView mLogoutView; |
Kunhung Li | 29007e6 | 2018-07-30 19:30:25 +0800 | [diff] [blame] | 60 | private KeyguardClockSwitch mClockView; |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 61 | private TextView mOwnerInfo; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 62 | private KeyguardSliceView mKeyguardSlice; |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 63 | private Runnable mPendingMarqueeStart; |
| 64 | private Handler mHandler; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 65 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 66 | private ArraySet<View> mVisibleInDoze; |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 67 | private boolean mPulsing; |
Adrian Roos | 7f91072 | 2017-07-12 19:15:59 +0200 | [diff] [blame] | 68 | private float mDarkAmount = 0; |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 69 | private int mTextColor; |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 70 | |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 71 | private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() { |
| 72 | |
| 73 | @Override |
| 74 | public void onTimeChanged() { |
Lucas Dupin | 08c013e | 2018-04-26 17:45:14 -0700 | [diff] [blame] | 75 | refreshTime(); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
Robert Snoeberger | 9c1074f | 2018-12-07 17:35:21 -0500 | [diff] [blame] | 79 | public void onTimeZoneChanged(TimeZone timeZone) { |
| 80 | updateTimeZone(timeZone); |
| 81 | } |
| 82 | |
| 83 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 84 | public void onKeyguardVisibilityChanged(boolean showing) { |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 85 | if (showing) { |
| 86 | if (DEBUG) Slog.v(TAG, "refresh statusview showing:" + showing); |
Lucas Dupin | 08c013e | 2018-04-26 17:45:14 -0700 | [diff] [blame] | 87 | refreshTime(); |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 88 | updateOwnerInfo(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 89 | updateLogoutView(); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 90 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 91 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 92 | |
Jim Miller | 38ab277 | 2013-10-08 15:32:09 -0700 | [diff] [blame] | 93 | @Override |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 94 | public void onStartedWakingUp() { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 95 | setEnableMarquee(true); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 96 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 97 | |
Jim Miller | 38ab277 | 2013-10-08 15:32:09 -0700 | [diff] [blame] | 98 | @Override |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 99 | public void onFinishedGoingToSleep(int why) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 100 | setEnableMarquee(false); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 101 | } |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 102 | |
| 103 | @Override |
| 104 | public void onUserSwitchComplete(int userId) { |
Lucas Dupin | 08c013e | 2018-04-26 17:45:14 -0700 | [diff] [blame] | 105 | refreshFormat(); |
Adrian Roos | e32dac8 | 2014-07-28 15:58:50 +0200 | [diff] [blame] | 106 | updateOwnerInfo(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 107 | updateLogoutView(); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public void onLogoutEnabledChanged() { |
| 112 | updateLogoutView(); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 113 | } |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 114 | }; |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 115 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 116 | public KeyguardStatusView(Context context) { |
| 117 | this(context, null, 0); |
| 118 | } |
| 119 | |
| 120 | public KeyguardStatusView(Context context, AttributeSet attrs) { |
| 121 | this(context, attrs, 0); |
| 122 | } |
| 123 | |
| 124 | public KeyguardStatusView(Context context, AttributeSet attrs, int defStyle) { |
| 125 | super(context, attrs, defStyle); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 126 | mIActivityManager = ActivityManager.getService(); |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 127 | mLockPatternUtils = new LockPatternUtils(getContext()); |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 128 | mHandler = new Handler(Looper.myLooper()); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 129 | onDensityOrFontScaleChanged(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 132 | /** |
| 133 | * If we're presenting a custom clock of just the default one. |
| 134 | */ |
| 135 | public boolean hasCustomClock() { |
| 136 | return mClockView.hasCustomClock(); |
| 137 | } |
| 138 | |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 139 | private void setEnableMarquee(boolean enabled) { |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 140 | 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 Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 159 | if (DEBUG) Log.v(TAG, (enabled ? "Enable" : "Disable") + " transport text marquee"); |
John Spurlock | 1e6eb17 | 2014-07-13 11:59:50 -0400 | [diff] [blame] | 160 | if (mOwnerInfo != null) mOwnerInfo.setSelected(enabled); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 163 | @Override |
| 164 | protected void onFinishInflate() { |
| 165 | super.onFinishInflate(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 166 | mLogoutView = findViewById(R.id.logout); |
Lucas Dupin | 0cf5e4a | 2018-05-02 00:33:17 -0700 | [diff] [blame] | 167 | if (mLogoutView != null) { |
| 168 | mLogoutView.setOnClickListener(this::onLogoutClicked); |
| 169 | } |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 170 | |
Robert Snoeberger | e3b3e78 | 2018-12-17 13:32:15 -0500 | [diff] [blame] | 171 | mClockView = findViewById(R.id.keyguard_clock_container); |
Selim Cinek | 9c4a707 | 2014-11-21 17:44:34 +0100 | [diff] [blame] | 172 | mClockView.setShowCurrentUserTime(true); |
Adrian Roos | b670f4b | 2017-07-20 20:06:54 +0200 | [diff] [blame] | 173 | if (KeyguardClockAccessibilityDelegate.isNeeded(mContext)) { |
| 174 | mClockView.setAccessibilityDelegate(new KeyguardClockAccessibilityDelegate(mContext)); |
| 175 | } |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 176 | mOwnerInfo = findViewById(R.id.owner_info); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 177 | mKeyguardSlice = findViewById(R.id.keyguard_status_area); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 178 | mVisibleInDoze = Sets.newArraySet(mClockView, mKeyguardSlice); |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 179 | mTextColor = mClockView.getCurrentTextColor(); |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 180 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 181 | mKeyguardSlice.setContentChangeListener(this::onSliceContentChanged); |
Lucas Dupin | 3978e6e | 2018-05-22 18:08:35 -0700 | [diff] [blame] | 182 | onSliceContentChanged(); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 183 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 184 | boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive(); |
| 185 | setEnableMarquee(shouldMarquee); |
Lucas Dupin | 08c013e | 2018-04-26 17:45:14 -0700 | [diff] [blame] | 186 | refreshFormat(); |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 187 | updateOwnerInfo(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 188 | updateLogoutView(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 189 | updateDark(); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Lucas Dupin | 1a38851 | 2018-06-28 11:09:09 -0700 | [diff] [blame] | 192 | /** |
Lucas Dupin | c9d28b7 | 2018-10-22 17:59:18 -0700 | [diff] [blame] | 193 | * Moves clock, adjusting margins when slice content changes. |
Lucas Dupin | 1a38851 | 2018-06-28 11:09:09 -0700 | [diff] [blame] | 194 | */ |
Lucas Dupin | 3978e6e | 2018-05-22 18:08:35 -0700 | [diff] [blame] | 195 | private void onSliceContentChanged() { |
Lucas Dupin | e570af6 | 2019-02-10 14:52:30 -0800 | [diff] [blame] | 196 | mClockView.setKeyguardShowingHeader(mKeyguardSlice.hasHeader()); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 199 | @Override |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 200 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 201 | super.onLayout(changed, left, top, right, bottom); |
Lucas Dupin | 09952ee | 2018-06-06 18:19:18 -0700 | [diff] [blame] | 202 | layoutOwnerInfo(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void onDensityOrFontScaleChanged() { |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 207 | if (mClockView != null) { |
| 208 | mClockView.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 209 | getResources().getDimensionPixelSize(R.dimen.widget_big_font_size)); |
| 210 | } |
Jorim Jaggi | ad15b49 | 2017-05-30 18:01:49 -0700 | [diff] [blame] | 211 | if (mOwnerInfo != null) { |
| 212 | mOwnerInfo.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 213 | getResources().getDimensionPixelSize(R.dimen.widget_label_font_size)); |
| 214 | } |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 215 | } |
| 216 | |
Lucas Dupin | 9fedb89 | 2018-05-04 17:42:33 -0700 | [diff] [blame] | 217 | public void dozeTimeTick() { |
| 218 | refreshTime(); |
| 219 | mKeyguardSlice.refresh(); |
Robert Snoeberger | ffbe315 | 2018-11-08 15:53:27 -0500 | [diff] [blame] | 220 | mClockView.dozeTimeTick(); |
Lucas Dupin | 9fedb89 | 2018-05-04 17:42:33 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | private void refreshTime() { |
Lucas Dupin | f9583c4 | 2018-04-05 22:20:44 -0700 | [diff] [blame] | 224 | mClockView.refresh(); |
Jorim Jaggi | d09def751 | 2014-09-02 18:36:45 +0200 | [diff] [blame] | 225 | } |
Jim Miller | 0c48689 | 2013-10-11 16:21:45 -0700 | [diff] [blame] | 226 | |
Robert Snoeberger | 9c1074f | 2018-12-07 17:35:21 -0500 | [diff] [blame] | 227 | private void updateTimeZone(TimeZone timeZone) { |
| 228 | mClockView.onTimeZoneChanged(timeZone); |
| 229 | } |
| 230 | |
Lucas Dupin | 08c013e | 2018-04-26 17:45:14 -0700 | [diff] [blame] | 231 | private void refreshFormat() { |
Lucas Dupin | ca46ae9 | 2018-04-02 11:05:09 -0700 | [diff] [blame] | 232 | Patterns.update(mContext); |
Lucas Dupin | 08c013e | 2018-04-26 17:45:14 -0700 | [diff] [blame] | 233 | mClockView.setFormat12Hour(Patterns.clockView12); |
| 234 | mClockView.setFormat24Hour(Patterns.clockView24); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 237 | public int getLogoutButtonHeight() { |
Lucas Dupin | 0cf5e4a | 2018-05-02 00:33:17 -0700 | [diff] [blame] | 238 | if (mLogoutView == null) { |
| 239 | return 0; |
| 240 | } |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 241 | return mLogoutView.getVisibility() == VISIBLE ? mLogoutView.getHeight() : 0; |
Adrian Roos | c934c43 | 2017-01-13 11:44:56 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 244 | public float getClockTextSize() { |
| 245 | return mClockView.getTextSize(); |
| 246 | } |
| 247 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 248 | private void updateLogoutView() { |
Lucas Dupin | 0cf5e4a | 2018-05-02 00:33:17 -0700 | [diff] [blame] | 249 | if (mLogoutView == null) { |
| 250 | return; |
| 251 | } |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 252 | mLogoutView.setVisibility(shouldShowLogout() ? VISIBLE : GONE); |
| 253 | // Logout button will stay in language of user 0 if we don't set that manually. |
| 254 | mLogoutView.setText(mContext.getResources().getString( |
| 255 | com.android.internal.R.string.global_action_logout)); |
| 256 | } |
| 257 | |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 258 | private void updateOwnerInfo() { |
John Spurlock | 1e6eb17 | 2014-07-13 11:59:50 -0400 | [diff] [blame] | 259 | if (mOwnerInfo == null) return; |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 260 | String info = mLockPatternUtils.getDeviceOwnerInfo(); |
| 261 | if (info == null) { |
Andrei Stingaceanu | 04e245b | 2015-11-12 12:15:56 +0000 | [diff] [blame] | 262 | // Use the current user owner information if enabled. |
| 263 | final boolean ownerInfoEnabled = mLockPatternUtils.isOwnerInfoEnabled( |
| 264 | KeyguardUpdateMonitor.getCurrentUser()); |
| 265 | if (ownerInfoEnabled) { |
| 266 | info = mLockPatternUtils.getOwnerInfo(KeyguardUpdateMonitor.getCurrentUser()); |
| 267 | } |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 268 | } |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 269 | mOwnerInfo.setText(info); |
Lucas Dupin | 43976f8 | 2018-10-22 19:52:59 -0700 | [diff] [blame] | 270 | updateDark(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | @Override |
| 274 | protected void onAttachedToWindow() { |
| 275 | super.onAttachedToWindow(); |
| 276 | KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mInfoCallback); |
| 277 | Dependency.get(ConfigurationController.class).addCallback(this); |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | protected void onDetachedFromWindow() { |
| 282 | super.onDetachedFromWindow(); |
| 283 | KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mInfoCallback); |
| 284 | Dependency.get(ConfigurationController.class).removeCallback(this); |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 285 | } |
| 286 | |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 287 | @Override |
Lucas Dupin | 08c013e | 2018-04-26 17:45:14 -0700 | [diff] [blame] | 288 | public void onLocaleListChanged() { |
| 289 | refreshFormat(); |
| 290 | } |
| 291 | |
| 292 | @Override |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 293 | public boolean hasOverlappingRendering() { |
| 294 | return false; |
| 295 | } |
| 296 | |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 297 | // DateFormat.getBestDateTimePattern is extremely expensive, and refresh is called often. |
| 298 | // This is an optimization to ensure we only recompute the patterns when the inputs change. |
| 299 | private static final class Patterns { |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 300 | static String clockView12; |
| 301 | static String clockView24; |
| 302 | static String cacheKey; |
| 303 | |
Lucas Dupin | ca46ae9 | 2018-04-02 11:05:09 -0700 | [diff] [blame] | 304 | static void update(Context context) { |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 305 | final Locale locale = Locale.getDefault(); |
| 306 | final Resources res = context.getResources(); |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 307 | final String clockView12Skel = res.getString(R.string.clock_12hr_format); |
| 308 | final String clockView24Skel = res.getString(R.string.clock_24hr_format); |
Lucas Dupin | ca46ae9 | 2018-04-02 11:05:09 -0700 | [diff] [blame] | 309 | final String key = locale.toString() + clockView12Skel + clockView24Skel; |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 310 | if (key.equals(cacheKey)) return; |
| 311 | |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 312 | clockView12 = DateFormat.getBestDateTimePattern(locale, clockView12Skel); |
| 313 | // CLDR insists on adding an AM/PM indicator even though it wasn't in the skeleton |
| 314 | // format. The following code removes the AM/PM indicator if we didn't want it. |
| 315 | if (!clockView12Skel.contains("a")) { |
| 316 | clockView12 = clockView12.replaceAll("a", "").trim(); |
| 317 | } |
| 318 | |
| 319 | clockView24 = DateFormat.getBestDateTimePattern(locale, clockView24Skel); |
| 320 | |
Jorim Jaggi | cc12a9d | 2014-05-26 01:55:29 +0200 | [diff] [blame] | 321 | // Use fancy colon. |
| 322 | clockView24 = clockView24.replace(':', '\uee01'); |
| 323 | clockView12 = clockView12.replace(':', '\uee01'); |
| 324 | |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 325 | cacheKey = key; |
| 326 | } |
| 327 | } |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 328 | |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 329 | public void setDarkAmount(float darkAmount) { |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 330 | if (mDarkAmount == darkAmount) { |
Adrian Roos | 52414e3 | 2017-04-28 09:23:19 -0700 | [diff] [blame] | 331 | return; |
| 332 | } |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 333 | mDarkAmount = darkAmount; |
Robert Snoeberger | e32efd7 | 2018-11-12 08:38:34 -0500 | [diff] [blame] | 334 | mClockView.setDarkAmount(darkAmount); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 335 | updateDark(); |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 336 | } |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 337 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 338 | private void updateDark() { |
| 339 | boolean dark = mDarkAmount == 1; |
Lucas Dupin | 0cf5e4a | 2018-05-02 00:33:17 -0700 | [diff] [blame] | 340 | if (mLogoutView != null) { |
| 341 | mLogoutView.setAlpha(dark ? 0 : 1); |
| 342 | } |
Lucas Dupin | 09952ee | 2018-06-06 18:19:18 -0700 | [diff] [blame] | 343 | |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 344 | if (mOwnerInfo != null) { |
| 345 | boolean hasText = !TextUtils.isEmpty(mOwnerInfo.getText()); |
Lucas Dupin | 09952ee | 2018-06-06 18:19:18 -0700 | [diff] [blame] | 346 | mOwnerInfo.setVisibility(hasText ? VISIBLE : GONE); |
| 347 | layoutOwnerInfo(); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | final int blendedTextColor = ColorUtils.blendARGB(mTextColor, Color.WHITE, mDarkAmount); |
| 351 | updateDozeVisibleViews(); |
| 352 | mKeyguardSlice.setDarkAmount(mDarkAmount); |
| 353 | mClockView.setTextColor(blendedTextColor); |
Lucas Dupin | 4e02381 | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Lucas Dupin | 09952ee | 2018-06-06 18:19:18 -0700 | [diff] [blame] | 356 | private void layoutOwnerInfo() { |
| 357 | if (mOwnerInfo != null && mOwnerInfo.getVisibility() != GONE) { |
| 358 | // Animate owner info during wake-up transition |
| 359 | mOwnerInfo.setAlpha(1f - mDarkAmount); |
| 360 | |
| 361 | float ratio = mDarkAmount; |
| 362 | // Calculate how much of it we should crop in order to have a smooth transition |
| 363 | int collapsed = mOwnerInfo.getTop() - mOwnerInfo.getPaddingTop(); |
| 364 | int expanded = mOwnerInfo.getBottom() + mOwnerInfo.getPaddingBottom(); |
| 365 | int toRemove = (int) ((expanded - collapsed) * ratio); |
| 366 | setBottom(getMeasuredHeight() - toRemove); |
| 367 | } |
| 368 | } |
| 369 | |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 370 | public void setPulsing(boolean pulsing) { |
Lucas Dupin | 2a6bdfd | 2018-06-12 17:45:21 -0700 | [diff] [blame] | 371 | if (mPulsing == pulsing) { |
| 372 | return; |
| 373 | } |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 374 | mPulsing = pulsing; |
| 375 | updateDozeVisibleViews(); |
| 376 | } |
| 377 | |
| 378 | private void updateDozeVisibleViews() { |
| 379 | for (View child : mVisibleInDoze) { |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 380 | child.setAlpha(mDarkAmount == 1 && mPulsing ? 0.8f : 1); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 383 | |
| 384 | private boolean shouldShowLogout() { |
| 385 | return KeyguardUpdateMonitor.getInstance(mContext).isLogoutEnabled() |
| 386 | && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM; |
| 387 | } |
| 388 | |
| 389 | private void onLogoutClicked(View view) { |
| 390 | int currentUserId = KeyguardUpdateMonitor.getCurrentUser(); |
| 391 | try { |
| 392 | mIActivityManager.switchUser(UserHandle.USER_SYSTEM); |
| 393 | mIActivityManager.stopUser(currentUserId, true /*force*/, null); |
| 394 | } catch (RemoteException re) { |
| 395 | Log.e(TAG, "Failed to logout user", re); |
| 396 | } |
| 397 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 398 | } |