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