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; |
Jose Lima | 235510e | 2014-08-13 12:50:01 -0700 | [diff] [blame] | 20 | import android.app.AlarmManager; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 21 | import android.app.IActivityManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 23 | import android.content.res.Configuration; |
Jim Miller | 0c48689 | 2013-10-11 16:21:45 -0700 | [diff] [blame] | 24 | import android.content.res.Resources; |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 25 | import android.graphics.Color; |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 26 | import android.os.Handler; |
| 27 | import android.os.Looper; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 28 | import android.os.RemoteException; |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 29 | import android.os.UserHandle; |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 30 | import android.support.v4.graphics.ColorUtils; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 31 | import android.text.TextUtils; |
Jim Miller | 38ab277 | 2013-10-08 15:32:09 -0700 | [diff] [blame] | 32 | import android.text.format.DateFormat; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 33 | import android.util.ArraySet; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 34 | import android.util.AttributeSet; |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 35 | import android.util.Log; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 36 | import android.util.Slog; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 37 | import android.util.TypedValue; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 38 | import android.view.View; |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 39 | import android.view.ViewGroup; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 40 | import android.widget.GridLayout; |
Jim Miller | 38ab277 | 2013-10-08 15:32:09 -0700 | [diff] [blame] | 41 | import android.widget.TextClock; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 42 | import android.widget.TextView; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 43 | |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 44 | import com.android.internal.widget.LockPatternUtils; |
| 45 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 46 | import com.google.android.collect.Sets; |
| 47 | |
Chris Wren | 56018e5 | 2013-01-15 10:59:43 -0500 | [diff] [blame] | 48 | import java.util.Locale; |
| 49 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 50 | public class KeyguardStatusView extends GridLayout { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 51 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 52 | private static final String TAG = "KeyguardStatusView"; |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 53 | private static final int MARQUEE_DELAY_MS = 2000; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 54 | |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 55 | private final LockPatternUtils mLockPatternUtils; |
| 56 | private final AlarmManager mAlarmManager; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 57 | private final IActivityManager mIActivityManager; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 58 | private final float mSmallClockScale; |
| 59 | private final float mWidgetPadding; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 60 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 61 | private TextView mLogoutView; |
Jim Miller | 0c48689 | 2013-10-11 16:21:45 -0700 | [diff] [blame] | 62 | private TextClock mClockView; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 63 | private View mClockSeparator; |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 64 | private TextView mOwnerInfo; |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 65 | private ViewGroup mClockContainer; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 66 | private KeyguardSliceView mKeyguardSlice; |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 67 | private Runnable mPendingMarqueeStart; |
| 68 | private Handler mHandler; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 69 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 70 | private ArraySet<View> mVisibleInDoze; |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 71 | private boolean mPulsing; |
Adrian Roos | 7f91072 | 2017-07-12 19:15:59 +0200 | [diff] [blame] | 72 | private float mDarkAmount = 0; |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 73 | private int mTextColor; |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 74 | |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 75 | private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() { |
| 76 | |
| 77 | @Override |
| 78 | public void onTimeChanged() { |
| 79 | refresh(); |
| 80 | } |
| 81 | |
| 82 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 83 | public void onKeyguardVisibilityChanged(boolean showing) { |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 84 | if (showing) { |
| 85 | if (DEBUG) Slog.v(TAG, "refresh statusview showing:" + showing); |
| 86 | refresh(); |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 87 | updateOwnerInfo(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 88 | updateLogoutView(); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 89 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 90 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 91 | |
Jim Miller | 38ab277 | 2013-10-08 15:32:09 -0700 | [diff] [blame] | 92 | @Override |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 93 | public void onStartedWakingUp() { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 94 | setEnableMarquee(true); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 95 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 96 | |
Jim Miller | 38ab277 | 2013-10-08 15:32:09 -0700 | [diff] [blame] | 97 | @Override |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 98 | public void onFinishedGoingToSleep(int why) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 99 | setEnableMarquee(false); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 100 | } |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 101 | |
| 102 | @Override |
| 103 | public void onUserSwitchComplete(int userId) { |
| 104 | refresh(); |
Adrian Roos | e32dac8 | 2014-07-28 15:58:50 +0200 | [diff] [blame] | 105 | updateOwnerInfo(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 106 | updateLogoutView(); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void onLogoutEnabledChanged() { |
| 111 | updateLogoutView(); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 112 | } |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 113 | }; |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 114 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 115 | public KeyguardStatusView(Context context) { |
| 116 | this(context, null, 0); |
| 117 | } |
| 118 | |
| 119 | public KeyguardStatusView(Context context, AttributeSet attrs) { |
| 120 | this(context, attrs, 0); |
| 121 | } |
| 122 | |
| 123 | public KeyguardStatusView(Context context, AttributeSet attrs, int defStyle) { |
| 124 | super(context, attrs, defStyle); |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 125 | mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
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 | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 129 | mSmallClockScale = getResources().getDimension(R.dimen.widget_small_font_size) |
| 130 | / getResources().getDimension(R.dimen.widget_big_font_size); |
| 131 | mWidgetPadding = getResources().getDimension(R.dimen.widget_vertical_padding); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 134 | private void setEnableMarquee(boolean enabled) { |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 135 | if (DEBUG) Log.v(TAG, "Schedule setEnableMarquee: " + (enabled ? "Enable" : "Disable")); |
| 136 | if (enabled) { |
| 137 | if (mPendingMarqueeStart == null) { |
| 138 | mPendingMarqueeStart = () -> { |
| 139 | setEnableMarqueeImpl(true); |
| 140 | mPendingMarqueeStart = null; |
| 141 | }; |
| 142 | mHandler.postDelayed(mPendingMarqueeStart, MARQUEE_DELAY_MS); |
| 143 | } |
| 144 | } else { |
| 145 | if (mPendingMarqueeStart != null) { |
| 146 | mHandler.removeCallbacks(mPendingMarqueeStart); |
| 147 | mPendingMarqueeStart = null; |
| 148 | } |
| 149 | setEnableMarqueeImpl(false); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | private void setEnableMarqueeImpl(boolean enabled) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 154 | if (DEBUG) Log.v(TAG, (enabled ? "Enable" : "Disable") + " transport text marquee"); |
John Spurlock | 1e6eb17 | 2014-07-13 11:59:50 -0400 | [diff] [blame] | 155 | if (mOwnerInfo != null) mOwnerInfo.setSelected(enabled); |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 158 | @Override |
| 159 | protected void onFinishInflate() { |
| 160 | super.onFinishInflate(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 161 | mLogoutView = findViewById(R.id.logout); |
| 162 | mLogoutView.setOnClickListener(this::onLogoutClicked); |
| 163 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 164 | mClockContainer = findViewById(R.id.keyguard_clock_container); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 165 | mClockView = findViewById(R.id.clock_view); |
Selim Cinek | 9c4a707 | 2014-11-21 17:44:34 +0100 | [diff] [blame] | 166 | mClockView.setShowCurrentUserTime(true); |
Adrian Roos | b670f4b | 2017-07-20 20:06:54 +0200 | [diff] [blame] | 167 | if (KeyguardClockAccessibilityDelegate.isNeeded(mContext)) { |
| 168 | mClockView.setAccessibilityDelegate(new KeyguardClockAccessibilityDelegate(mContext)); |
| 169 | } |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 170 | mOwnerInfo = findViewById(R.id.owner_info); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 171 | mKeyguardSlice = findViewById(R.id.keyguard_status_area); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 172 | mClockSeparator = findViewById(R.id.clock_separator); |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 173 | mVisibleInDoze = Sets.newArraySet(mClockView, mKeyguardSlice, mClockSeparator); |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 174 | mTextColor = mClockView.getCurrentTextColor(); |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 175 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 176 | mKeyguardSlice.setListener(this::onSliceContentChanged); |
| 177 | onSliceContentChanged(mKeyguardSlice.hasHeader()); |
| 178 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 179 | boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive(); |
| 180 | setEnableMarquee(shouldMarquee); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 181 | refresh(); |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 182 | updateOwnerInfo(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 183 | updateLogoutView(); |
Jorim Jaggi | cc12a9d | 2014-05-26 01:55:29 +0200 | [diff] [blame] | 184 | |
| 185 | // Disable elegant text height because our fancy colon makes the ymin value huge for no |
| 186 | // reason. |
| 187 | mClockView.setElegantTextHeight(false); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 190 | private void onSliceContentChanged(boolean hasHeader) { |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 191 | final boolean smallClock = hasHeader || mPulsing; |
| 192 | final float clockScale = smallClock ? mSmallClockScale : 1; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 193 | float translation = (mClockView.getHeight() - (mClockView.getHeight() * clockScale)) / 2f; |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 194 | if (smallClock) { |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 195 | translation -= mWidgetPadding; |
| 196 | } |
| 197 | mClockView.setTranslationY(translation); |
| 198 | mClockView.setScaleX(clockScale); |
| 199 | mClockView.setScaleY(clockScale); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 200 | mClockSeparator.setVisibility(hasHeader && !mPulsing ? VISIBLE : GONE); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 203 | @Override |
| 204 | protected void onConfigurationChanged(Configuration newConfig) { |
| 205 | super.onConfigurationChanged(newConfig); |
| 206 | mClockView.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 207 | getResources().getDimensionPixelSize(R.dimen.widget_big_font_size)); |
Selim Cinek | b6143c1 | 2016-07-14 16:32:23 -0700 | [diff] [blame] | 208 | // Some layouts like burmese have a different margin for the clock |
| 209 | MarginLayoutParams layoutParams = (MarginLayoutParams) mClockView.getLayoutParams(); |
| 210 | layoutParams.bottomMargin = getResources().getDimensionPixelSize( |
| 211 | R.dimen.bottom_text_spacing_digital); |
| 212 | mClockView.setLayoutParams(layoutParams); |
Jorim Jaggi | ad15b49 | 2017-05-30 18:01:49 -0700 | [diff] [blame] | 213 | if (mOwnerInfo != null) { |
| 214 | mOwnerInfo.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 215 | getResources().getDimensionPixelSize(R.dimen.widget_label_font_size)); |
| 216 | } |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Jorim Jaggi | d09def751 | 2014-09-02 18:36:45 +0200 | [diff] [blame] | 219 | public void refreshTime() { |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 220 | mClockView.setFormat12Hour(Patterns.clockView12); |
| 221 | mClockView.setFormat24Hour(Patterns.clockView24); |
Jorim Jaggi | d09def751 | 2014-09-02 18:36:45 +0200 | [diff] [blame] | 222 | } |
Jim Miller | 0c48689 | 2013-10-11 16:21:45 -0700 | [diff] [blame] | 223 | |
Jorim Jaggi | d09def751 | 2014-09-02 18:36:45 +0200 | [diff] [blame] | 224 | private void refresh() { |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 225 | AlarmManager.AlarmClockInfo nextAlarm = |
| 226 | mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT); |
Jorim Jaggi | d09def751 | 2014-09-02 18:36:45 +0200 | [diff] [blame] | 227 | Patterns.update(mContext, nextAlarm != null); |
| 228 | |
| 229 | refreshTime(); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Adrian Roos | c934c43 | 2017-01-13 11:44:56 -0800 | [diff] [blame] | 232 | public int getClockBottom() { |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 233 | if (mOwnerInfo != null && mOwnerInfo.getVisibility() == VISIBLE) { |
| 234 | return mOwnerInfo.getBottom(); |
| 235 | } else { |
| 236 | return mClockContainer.getBottom(); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | public int getLogoutButtonHeight() { |
| 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() { |
| 249 | mLogoutView.setVisibility(shouldShowLogout() ? VISIBLE : GONE); |
| 250 | // Logout button will stay in language of user 0 if we don't set that manually. |
| 251 | mLogoutView.setText(mContext.getResources().getString( |
| 252 | com.android.internal.R.string.global_action_logout)); |
| 253 | } |
| 254 | |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 255 | private void updateOwnerInfo() { |
John Spurlock | 1e6eb17 | 2014-07-13 11:59:50 -0400 | [diff] [blame] | 256 | if (mOwnerInfo == null) return; |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 257 | String ownerInfo = getOwnerInfo(); |
| 258 | if (!TextUtils.isEmpty(ownerInfo)) { |
| 259 | mOwnerInfo.setVisibility(View.VISIBLE); |
| 260 | mOwnerInfo.setText(ownerInfo); |
| 261 | } else { |
| 262 | mOwnerInfo.setVisibility(View.GONE); |
| 263 | } |
| 264 | } |
| 265 | |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 266 | @Override |
| 267 | protected void onAttachedToWindow() { |
| 268 | super.onAttachedToWindow(); |
| 269 | KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mInfoCallback); |
| 270 | } |
| 271 | |
| 272 | @Override |
| 273 | protected void onDetachedFromWindow() { |
| 274 | super.onDetachedFromWindow(); |
| 275 | KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mInfoCallback); |
| 276 | } |
| 277 | |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 278 | private String getOwnerInfo() { |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 279 | String info = null; |
Andrei Stingaceanu | 04e245b | 2015-11-12 12:15:56 +0000 | [diff] [blame] | 280 | if (mLockPatternUtils.isDeviceOwnerInfoEnabled()) { |
| 281 | // Use the device owner information set by device policy client via |
| 282 | // device policy manager. |
| 283 | info = mLockPatternUtils.getDeviceOwnerInfo(); |
| 284 | } else { |
| 285 | // Use the current user owner information if enabled. |
| 286 | final boolean ownerInfoEnabled = mLockPatternUtils.isOwnerInfoEnabled( |
| 287 | KeyguardUpdateMonitor.getCurrentUser()); |
| 288 | if (ownerInfoEnabled) { |
| 289 | info = mLockPatternUtils.getOwnerInfo(KeyguardUpdateMonitor.getCurrentUser()); |
| 290 | } |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 291 | } |
| 292 | return info; |
| 293 | } |
| 294 | |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 295 | @Override |
| 296 | public boolean hasOverlappingRendering() { |
| 297 | return false; |
| 298 | } |
| 299 | |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 300 | // DateFormat.getBestDateTimePattern is extremely expensive, and refresh is called often. |
| 301 | // This is an optimization to ensure we only recompute the patterns when the inputs change. |
| 302 | private static final class Patterns { |
Adrian Roos | 59de4f3 | 2017-05-31 15:22:38 -0700 | [diff] [blame] | 303 | static String dateViewSkel; |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 304 | static String clockView12; |
| 305 | static String clockView24; |
| 306 | static String cacheKey; |
| 307 | |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 308 | static void update(Context context, boolean hasAlarm) { |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 309 | final Locale locale = Locale.getDefault(); |
| 310 | final Resources res = context.getResources(); |
Adrian Roos | 59de4f3 | 2017-05-31 15:22:38 -0700 | [diff] [blame] | 311 | dateViewSkel = res.getString(hasAlarm |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 312 | ? R.string.abbrev_wday_month_day_no_year_alarm |
| 313 | : R.string.abbrev_wday_month_day_no_year); |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 314 | final String clockView12Skel = res.getString(R.string.clock_12hr_format); |
| 315 | final String clockView24Skel = res.getString(R.string.clock_24hr_format); |
| 316 | final String key = locale.toString() + dateViewSkel + clockView12Skel + clockView24Skel; |
| 317 | if (key.equals(cacheKey)) return; |
| 318 | |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 319 | clockView12 = DateFormat.getBestDateTimePattern(locale, clockView12Skel); |
| 320 | // CLDR insists on adding an AM/PM indicator even though it wasn't in the skeleton |
| 321 | // format. The following code removes the AM/PM indicator if we didn't want it. |
| 322 | if (!clockView12Skel.contains("a")) { |
| 323 | clockView12 = clockView12.replaceAll("a", "").trim(); |
| 324 | } |
| 325 | |
| 326 | clockView24 = DateFormat.getBestDateTimePattern(locale, clockView24Skel); |
| 327 | |
Jorim Jaggi | cc12a9d | 2014-05-26 01:55:29 +0200 | [diff] [blame] | 328 | // Use fancy colon. |
| 329 | clockView24 = clockView24.replace(':', '\uee01'); |
| 330 | clockView12 = clockView12.replace(':', '\uee01'); |
| 331 | |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 332 | cacheKey = key; |
| 333 | } |
| 334 | } |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 335 | |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 336 | public void setDarkAmount(float darkAmount) { |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 337 | if (mDarkAmount == darkAmount) { |
Adrian Roos | 52414e3 | 2017-04-28 09:23:19 -0700 | [diff] [blame] | 338 | return; |
| 339 | } |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 340 | mDarkAmount = darkAmount; |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 341 | |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 342 | boolean dark = darkAmount == 1; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 343 | mLogoutView.setAlpha(dark ? 0 : 1); |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 344 | final int N = mClockContainer.getChildCount(); |
| 345 | for (int i = 0; i < N; i++) { |
| 346 | View child = mClockContainer.getChildAt(i); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 347 | if (mVisibleInDoze.contains(child)) { |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 348 | continue; |
| 349 | } |
| 350 | child.setAlpha(dark ? 0 : 1); |
| 351 | } |
Adrian Roos | 8e130f0 | 2017-07-20 15:14:25 +0200 | [diff] [blame] | 352 | if (mOwnerInfo != null) { |
| 353 | mOwnerInfo.setAlpha(dark ? 0 : 1); |
| 354 | } |
| 355 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 356 | final int blendedTextColor = ColorUtils.blendARGB(mTextColor, Color.WHITE, darkAmount); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 357 | updateDozeVisibleViews(); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 358 | mKeyguardSlice.setDark(darkAmount); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 359 | mClockView.setTextColor(blendedTextColor); |
| 360 | mClockSeparator.setBackgroundColor(blendedTextColor); |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 361 | } |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 362 | |
| 363 | public void setPulsing(boolean pulsing) { |
| 364 | mPulsing = pulsing; |
Lucas Dupin | 2c5fce6 | 2018-03-05 19:06:00 -0800 | [diff] [blame^] | 365 | mKeyguardSlice.setHideContent(pulsing); |
Lucas Dupin | 6bf7b64 | 2018-01-22 18:56:24 -0800 | [diff] [blame] | 366 | onSliceContentChanged(mKeyguardSlice.hasHeader()); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 367 | updateDozeVisibleViews(); |
| 368 | } |
| 369 | |
| 370 | private void updateDozeVisibleViews() { |
| 371 | for (View child : mVisibleInDoze) { |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 372 | child.setAlpha(mDarkAmount == 1 && mPulsing ? 0.8f : 1); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 373 | } |
| 374 | } |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 375 | |
| 376 | private boolean shouldShowLogout() { |
| 377 | return KeyguardUpdateMonitor.getInstance(mContext).isLogoutEnabled() |
| 378 | && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM; |
| 379 | } |
| 380 | |
| 381 | private void onLogoutClicked(View view) { |
| 382 | int currentUserId = KeyguardUpdateMonitor.getCurrentUser(); |
| 383 | try { |
| 384 | mIActivityManager.switchUser(UserHandle.USER_SYSTEM); |
| 385 | mIActivityManager.stopUser(currentUserId, true /*force*/, null); |
| 386 | } catch (RemoteException re) { |
| 387 | Log.e(TAG, "Failed to logout user", re); |
| 388 | } |
| 389 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 390 | } |