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