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