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 | |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 22 | import android.app.IActivityManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 23 | import android.content.Context; |
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; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 39 | import android.widget.GridLayout; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 40 | import android.widget.RelativeLayout; |
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; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 45 | import com.android.internal.widget.ViewClippingUtil; |
| 46 | import com.android.systemui.Dependency; |
| 47 | import com.android.systemui.Interpolators; |
| 48 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 49 | import com.android.systemui.util.wakelock.KeepAwakeAnimationListener; |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 50 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 51 | import com.google.android.collect.Sets; |
| 52 | |
Chris Wren | 56018e5 | 2013-01-15 10:59:43 -0500 | [diff] [blame] | 53 | import java.util.Locale; |
| 54 | |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 55 | public class KeyguardStatusView extends GridLayout implements |
| 56 | ConfigurationController.ConfigurationListener, View.OnLayoutChangeListener { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 57 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 58 | private static final String TAG = "KeyguardStatusView"; |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 59 | private static final int MARQUEE_DELAY_MS = 2000; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 60 | |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 61 | private final LockPatternUtils mLockPatternUtils; |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 62 | private final IActivityManager mIActivityManager; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 63 | private final float mSmallClockScale; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 64 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 65 | private TextView mLogoutView; |
Jim Miller | 0c48689 | 2013-10-11 16:21:45 -0700 | [diff] [blame] | 66 | private TextClock mClockView; |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 67 | private View mClockSeparator; |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 68 | private TextView mOwnerInfo; |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 69 | private KeyguardSliceView mKeyguardSlice; |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 70 | private Runnable mPendingMarqueeStart; |
| 71 | private Handler mHandler; |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 72 | |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 73 | private ArraySet<View> mVisibleInDoze; |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 74 | private boolean mPulsing; |
Adrian Roos | 7f91072 | 2017-07-12 19:15:59 +0200 | [diff] [blame] | 75 | private float mDarkAmount = 0; |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 76 | private int mTextColor; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 77 | private float mWidgetPadding; |
| 78 | private boolean mAnimateLayout; |
| 79 | private int mLastLayoutHeight; |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 80 | |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 81 | private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() { |
| 82 | |
| 83 | @Override |
| 84 | public void onTimeChanged() { |
| 85 | refresh(); |
| 86 | } |
| 87 | |
| 88 | @Override |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 89 | public void onKeyguardVisibilityChanged(boolean showing) { |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 90 | if (showing) { |
| 91 | if (DEBUG) Slog.v(TAG, "refresh statusview showing:" + showing); |
| 92 | refresh(); |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 93 | updateOwnerInfo(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 94 | updateLogoutView(); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 95 | } |
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 onStartedWakingUp() { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 100 | setEnableMarquee(true); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 101 | } |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 102 | |
Jim Miller | 38ab277 | 2013-10-08 15:32:09 -0700 | [diff] [blame] | 103 | @Override |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 104 | public void onFinishedGoingToSleep(int why) { |
Jim Miller | 20daffd | 2013-10-07 14:59:53 -0700 | [diff] [blame] | 105 | setEnableMarquee(false); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 106 | } |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 107 | |
| 108 | @Override |
| 109 | public void onUserSwitchComplete(int userId) { |
| 110 | refresh(); |
Adrian Roos | e32dac8 | 2014-07-28 15:58:50 +0200 | [diff] [blame] | 111 | updateOwnerInfo(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 112 | updateLogoutView(); |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public void onLogoutEnabledChanged() { |
| 117 | updateLogoutView(); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 118 | } |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 119 | }; |
Jim Miller | 6212cc0 | 2012-09-05 17:35:31 -0700 | [diff] [blame] | 120 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 121 | public KeyguardStatusView(Context context) { |
| 122 | this(context, null, 0); |
| 123 | } |
| 124 | |
| 125 | public KeyguardStatusView(Context context, AttributeSet attrs) { |
| 126 | this(context, attrs, 0); |
| 127 | } |
| 128 | |
| 129 | public KeyguardStatusView(Context context, AttributeSet attrs, int defStyle) { |
| 130 | super(context, attrs, defStyle); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 131 | mIActivityManager = ActivityManager.getService(); |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 132 | mLockPatternUtils = new LockPatternUtils(getContext()); |
Geoffrey Pitsch | c239fef | 2017-07-14 09:55:16 -0400 | [diff] [blame] | 133 | mHandler = new Handler(Looper.myLooper()); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 134 | mSmallClockScale = getResources().getDimension(R.dimen.widget_small_font_size) |
| 135 | / getResources().getDimension(R.dimen.widget_big_font_size); |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 136 | onDensityOrFontScaleChanged(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 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); |
| 167 | mLogoutView.setOnClickListener(this::onLogoutClicked); |
| 168 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 169 | mClockView = findViewById(R.id.clock_view); |
Selim Cinek | 9c4a707 | 2014-11-21 17:44:34 +0100 | [diff] [blame] | 170 | mClockView.setShowCurrentUserTime(true); |
Adrian Roos | b670f4b | 2017-07-20 20:06:54 +0200 | [diff] [blame] | 171 | if (KeyguardClockAccessibilityDelegate.isNeeded(mContext)) { |
| 172 | mClockView.setAccessibilityDelegate(new KeyguardClockAccessibilityDelegate(mContext)); |
| 173 | } |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 174 | mOwnerInfo = findViewById(R.id.owner_info); |
Lucas Dupin | 957e50c | 2017-10-10 11:23:27 -0700 | [diff] [blame] | 175 | mKeyguardSlice = findViewById(R.id.keyguard_status_area); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 176 | mClockSeparator = findViewById(R.id.clock_separator); |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 177 | mVisibleInDoze = Sets.newArraySet(mClockView, mKeyguardSlice); |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 178 | mTextColor = mClockView.getCurrentTextColor(); |
Adrian Roos | 9dd16eb | 2015-01-08 16:20:49 +0100 | [diff] [blame] | 179 | |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 180 | mClockView.addOnLayoutChangeListener(this); |
| 181 | mClockSeparator.addOnLayoutChangeListener(this); |
| 182 | mKeyguardSlice.setContentChangeListener(this::onSliceContentChanged); |
| 183 | onSliceContentChanged(false /* animated */); |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 184 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 185 | boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive(); |
| 186 | setEnableMarquee(shouldMarquee); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 187 | refresh(); |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 188 | updateOwnerInfo(); |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 189 | updateLogoutView(); |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 190 | updateDark(); |
Jorim Jaggi | cc12a9d | 2014-05-26 01:55:29 +0200 | [diff] [blame] | 191 | |
| 192 | // Disable elegant text height because our fancy colon makes the ymin value huge for no |
| 193 | // reason. |
| 194 | mClockView.setElegantTextHeight(false); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 197 | private void onSliceContentChanged(boolean animated) { |
| 198 | mAnimateLayout = animated; |
| 199 | boolean smallClock = mKeyguardSlice.hasHeader() || mPulsing; |
| 200 | float clockScale = smallClock ? mSmallClockScale : 1; |
| 201 | |
| 202 | RelativeLayout.LayoutParams layoutParams = |
| 203 | (RelativeLayout.LayoutParams) mClockView.getLayoutParams(); |
| 204 | int height = mClockView.getHeight(); |
| 205 | layoutParams.bottomMargin = (int) -(height - (clockScale * height)); |
| 206 | mClockView.setLayoutParams(layoutParams); |
| 207 | |
| 208 | layoutParams = (RelativeLayout.LayoutParams) mClockSeparator.getLayoutParams(); |
| 209 | layoutParams.topMargin = smallClock ? (int) mWidgetPadding : 0; |
| 210 | layoutParams.bottomMargin = layoutParams.topMargin; |
| 211 | mClockSeparator.setLayoutParams(layoutParams); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Animate clock and its separator when necessary. |
| 216 | */ |
| 217 | @Override |
| 218 | public void onLayoutChange(View view, int left, int top, int right, int bottom, |
| 219 | int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 220 | int heightOffset = mPulsing ? 0 : getHeight() - mLastLayoutHeight; |
| 221 | boolean hasHeader = mKeyguardSlice.hasHeader(); |
| 222 | boolean smallClock = hasHeader || mPulsing; |
| 223 | long duration = KeyguardSliceView.DEFAULT_ANIM_DURATION; |
| 224 | long delay = smallClock ? 0 : duration / 4; |
| 225 | |
| 226 | if (view == mClockView) { |
| 227 | float clockScale = smallClock ? mSmallClockScale : 1; |
| 228 | if (mAnimateLayout) { |
| 229 | mClockView.setY(oldTop + heightOffset); |
| 230 | mClockView.animate().cancel(); |
| 231 | mClockView.animate() |
| 232 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
| 233 | .setDuration(duration) |
| 234 | .setListener(new ClipChildrenAnimationListener()) |
| 235 | .setStartDelay(delay) |
| 236 | .y(top) |
| 237 | .scaleX(clockScale) |
| 238 | .scaleY(clockScale) |
| 239 | .start(); |
| 240 | } else { |
| 241 | mClockView.setY(top); |
| 242 | mClockView.setScaleX(clockScale); |
| 243 | mClockView.setScaleY(clockScale); |
| 244 | } |
| 245 | } else if (view == mClockSeparator) { |
| 246 | boolean hasSeparator = hasHeader && !mPulsing; |
| 247 | float alpha = hasSeparator ? 1 : 0; |
| 248 | if (mAnimateLayout) { |
| 249 | boolean isAwake = mDarkAmount != 0; |
| 250 | mClockSeparator.setY(oldTop + heightOffset); |
| 251 | mClockSeparator.animate().cancel(); |
| 252 | mClockSeparator.animate() |
| 253 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
| 254 | .setDuration(duration) |
| 255 | .setListener(isAwake ? null : new KeepAwakeAnimationListener(getContext())) |
| 256 | .setStartDelay(delay) |
| 257 | .y(top) |
| 258 | .alpha(alpha) |
| 259 | .start(); |
| 260 | } else { |
| 261 | mClockSeparator.setY(top); |
| 262 | mClockSeparator.setAlpha(alpha); |
| 263 | } |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 264 | } |
Lucas Dupin | 6bd8601 | 2017-12-05 17:58:57 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 267 | @Override |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 268 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 269 | super.onLayout(changed, left, top, right, bottom); |
| 270 | mClockView.setPivotX(mClockView.getWidth() / 2); |
| 271 | mClockView.setPivotY(0); |
| 272 | mLastLayoutHeight = getHeight(); |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public void onDensityOrFontScaleChanged() { |
| 277 | mWidgetPadding = getResources().getDimension(R.dimen.widget_vertical_padding); |
| 278 | if (mClockView != null) { |
| 279 | mClockView.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 280 | getResources().getDimensionPixelSize(R.dimen.widget_big_font_size)); |
| 281 | } |
Jorim Jaggi | ad15b49 | 2017-05-30 18:01:49 -0700 | [diff] [blame] | 282 | if (mOwnerInfo != null) { |
| 283 | mOwnerInfo.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 284 | getResources().getDimensionPixelSize(R.dimen.widget_label_font_size)); |
| 285 | } |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Jorim Jaggi | d09def751 | 2014-09-02 18:36:45 +0200 | [diff] [blame] | 288 | public void refreshTime() { |
Lucas Dupin | f9583c4 | 2018-04-05 22:20:44 -0700 | [diff] [blame] | 289 | mClockView.refresh(); |
Jorim Jaggi | d09def751 | 2014-09-02 18:36:45 +0200 | [diff] [blame] | 290 | } |
Jim Miller | 0c48689 | 2013-10-11 16:21:45 -0700 | [diff] [blame] | 291 | |
Jorim Jaggi | d09def751 | 2014-09-02 18:36:45 +0200 | [diff] [blame] | 292 | private void refresh() { |
Lucas Dupin | ca46ae9 | 2018-04-02 11:05:09 -0700 | [diff] [blame] | 293 | Patterns.update(mContext); |
Jorim Jaggi | d09def751 | 2014-09-02 18:36:45 +0200 | [diff] [blame] | 294 | refreshTime(); |
Jim Miller | edc74ab | 2012-11-06 21:46:11 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 297 | public int getLogoutButtonHeight() { |
| 298 | return mLogoutView.getVisibility() == VISIBLE ? mLogoutView.getHeight() : 0; |
Adrian Roos | c934c43 | 2017-01-13 11:44:56 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 301 | public float getClockTextSize() { |
| 302 | return mClockView.getTextSize(); |
| 303 | } |
| 304 | |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 305 | private void updateLogoutView() { |
| 306 | mLogoutView.setVisibility(shouldShowLogout() ? VISIBLE : GONE); |
| 307 | // Logout button will stay in language of user 0 if we don't set that manually. |
| 308 | mLogoutView.setText(mContext.getResources().getString( |
| 309 | com.android.internal.R.string.global_action_logout)); |
| 310 | } |
| 311 | |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 312 | private void updateOwnerInfo() { |
John Spurlock | 1e6eb17 | 2014-07-13 11:59:50 -0400 | [diff] [blame] | 313 | if (mOwnerInfo == null) return; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 314 | String info = mLockPatternUtils.getDeviceOwnerInfo(); |
| 315 | if (info == null) { |
Andrei Stingaceanu | 04e245b | 2015-11-12 12:15:56 +0000 | [diff] [blame] | 316 | // Use the current user owner information if enabled. |
| 317 | final boolean ownerInfoEnabled = mLockPatternUtils.isOwnerInfoEnabled( |
| 318 | KeyguardUpdateMonitor.getCurrentUser()); |
| 319 | if (ownerInfoEnabled) { |
| 320 | info = mLockPatternUtils.getOwnerInfo(KeyguardUpdateMonitor.getCurrentUser()); |
| 321 | } |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 322 | } |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 323 | mOwnerInfo.setText(info); |
| 324 | } |
| 325 | |
| 326 | @Override |
| 327 | protected void onAttachedToWindow() { |
| 328 | super.onAttachedToWindow(); |
| 329 | KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mInfoCallback); |
| 330 | Dependency.get(ConfigurationController.class).addCallback(this); |
| 331 | } |
| 332 | |
| 333 | @Override |
| 334 | protected void onDetachedFromWindow() { |
| 335 | super.onDetachedFromWindow(); |
| 336 | KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mInfoCallback); |
| 337 | Dependency.get(ConfigurationController.class).removeCallback(this); |
Jorim Jaggi | 93afa1d | 2014-06-03 20:56:32 +0200 | [diff] [blame] | 338 | } |
| 339 | |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 340 | @Override |
| 341 | public boolean hasOverlappingRendering() { |
| 342 | return false; |
| 343 | } |
| 344 | |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 345 | // DateFormat.getBestDateTimePattern is extremely expensive, and refresh is called often. |
| 346 | // This is an optimization to ensure we only recompute the patterns when the inputs change. |
| 347 | private static final class Patterns { |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 348 | static String clockView12; |
| 349 | static String clockView24; |
| 350 | static String cacheKey; |
| 351 | |
Lucas Dupin | ca46ae9 | 2018-04-02 11:05:09 -0700 | [diff] [blame] | 352 | static void update(Context context) { |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 353 | final Locale locale = Locale.getDefault(); |
| 354 | final Resources res = context.getResources(); |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 355 | final String clockView12Skel = res.getString(R.string.clock_12hr_format); |
| 356 | final String clockView24Skel = res.getString(R.string.clock_24hr_format); |
Lucas Dupin | ca46ae9 | 2018-04-02 11:05:09 -0700 | [diff] [blame] | 357 | final String key = locale.toString() + clockView12Skel + clockView24Skel; |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 358 | if (key.equals(cacheKey)) return; |
| 359 | |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 360 | clockView12 = DateFormat.getBestDateTimePattern(locale, clockView12Skel); |
| 361 | // CLDR insists on adding an AM/PM indicator even though it wasn't in the skeleton |
| 362 | // format. The following code removes the AM/PM indicator if we didn't want it. |
| 363 | if (!clockView12Skel.contains("a")) { |
| 364 | clockView12 = clockView12.replaceAll("a", "").trim(); |
| 365 | } |
| 366 | |
| 367 | clockView24 = DateFormat.getBestDateTimePattern(locale, clockView24Skel); |
| 368 | |
Jorim Jaggi | cc12a9d | 2014-05-26 01:55:29 +0200 | [diff] [blame] | 369 | // Use fancy colon. |
| 370 | clockView24 = clockView24.replace(':', '\uee01'); |
| 371 | clockView12 = clockView12.replace(':', '\uee01'); |
| 372 | |
John Spurlock | 385a63d | 2013-10-30 19:40:48 -0400 | [diff] [blame] | 373 | cacheKey = key; |
| 374 | } |
| 375 | } |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 376 | |
Lucas Dupin | 4272f44 | 2018-01-13 22:00:35 -0800 | [diff] [blame] | 377 | public void setDarkAmount(float darkAmount) { |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 378 | if (mDarkAmount == darkAmount) { |
Adrian Roos | 52414e3 | 2017-04-28 09:23:19 -0700 | [diff] [blame] | 379 | return; |
| 380 | } |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 381 | mDarkAmount = darkAmount; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 382 | updateDark(); |
Adrian Roos | 7907ff2 | 2017-01-17 15:44:11 -0800 | [diff] [blame] | 383 | } |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 384 | |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 385 | private void updateDark() { |
| 386 | boolean dark = mDarkAmount == 1; |
| 387 | mLogoutView.setAlpha(dark ? 0 : 1); |
| 388 | if (mOwnerInfo != null) { |
| 389 | boolean hasText = !TextUtils.isEmpty(mOwnerInfo.getText()); |
| 390 | mOwnerInfo.setVisibility(hasText && mDarkAmount != 1 ? VISIBLE : GONE); |
| 391 | } |
| 392 | |
| 393 | final int blendedTextColor = ColorUtils.blendARGB(mTextColor, Color.WHITE, mDarkAmount); |
| 394 | updateDozeVisibleViews(); |
| 395 | mKeyguardSlice.setDarkAmount(mDarkAmount); |
| 396 | mClockView.setTextColor(blendedTextColor); |
| 397 | mClockSeparator.setBackgroundColor(blendedTextColor); |
| 398 | } |
| 399 | |
| 400 | public void setPulsing(boolean pulsing, boolean animate) { |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 401 | mPulsing = pulsing; |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 402 | mKeyguardSlice.setPulsing(pulsing, animate); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 403 | updateDozeVisibleViews(); |
| 404 | } |
| 405 | |
| 406 | private void updateDozeVisibleViews() { |
| 407 | for (View child : mVisibleInDoze) { |
Lucas Dupin | 76d38e7 | 2017-05-13 22:04:22 -0700 | [diff] [blame] | 408 | child.setAlpha(mDarkAmount == 1 && mPulsing ? 0.8f : 1); |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
Alex Chau | ff7653d | 2018-02-01 17:18:08 +0000 | [diff] [blame] | 411 | |
| 412 | private boolean shouldShowLogout() { |
| 413 | return KeyguardUpdateMonitor.getInstance(mContext).isLogoutEnabled() |
| 414 | && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM; |
| 415 | } |
| 416 | |
| 417 | private void onLogoutClicked(View view) { |
| 418 | int currentUserId = KeyguardUpdateMonitor.getCurrentUser(); |
| 419 | try { |
| 420 | mIActivityManager.switchUser(UserHandle.USER_SYSTEM); |
| 421 | mIActivityManager.stopUser(currentUserId, true /*force*/, null); |
| 422 | } catch (RemoteException re) { |
| 423 | Log.e(TAG, "Failed to logout user", re); |
| 424 | } |
| 425 | } |
Lucas Dupin | 3d7ccaf | 2018-04-02 21:19:23 -0700 | [diff] [blame] | 426 | |
| 427 | private class ClipChildrenAnimationListener extends AnimatorListenerAdapter implements |
| 428 | ViewClippingUtil.ClippingParameters { |
| 429 | |
| 430 | ClipChildrenAnimationListener() { |
| 431 | ViewClippingUtil.setClippingDeactivated(mClockView, true /* deactivated */, |
| 432 | this /* clippingParams */); |
| 433 | } |
| 434 | |
| 435 | @Override |
| 436 | public void onAnimationEnd(Animator animation) { |
| 437 | ViewClippingUtil.setClippingDeactivated(mClockView, false /* deactivated */, |
| 438 | this /* clippingParams */); |
| 439 | } |
| 440 | |
| 441 | @Override |
| 442 | public boolean shouldFinish(View view) { |
| 443 | return view == getParent(); |
| 444 | } |
| 445 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 446 | } |