diff options
author | Scott Lobdell <slobdell@google.com> | 2020-11-05 18:29:12 -0800 |
---|---|---|
committer | Scott Lobdell <slobdell@google.com> | 2020-11-13 11:48:49 -0800 |
commit | 3933f277a025be704e68ea593536e492831a7e05 (patch) | |
tree | 084aa5e0858c449a63dd18cc57fb21ab054d363a /packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java | |
parent | 248a6ce2e2ee65f367b01c43edeecef5a6d57581 (diff) | |
parent | 9c74513b2d828d5169e9942b58b2f93bb3e04aff (diff) |
Merge SP1A.201105.002
Change-Id: Iec83a0c1f6f286a1e51abfc4356633ca9d8aea5f
Diffstat (limited to 'packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java')
-rw-r--r-- | packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java | 256 |
1 files changed, 42 insertions, 214 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java index 9ef2def04ec1..2036b3321bda 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java @@ -19,16 +19,13 @@ package com.android.keyguard; import android.app.ActivityManager; import android.app.IActivityManager; import android.content.Context; -import android.content.res.Resources; import android.graphics.Color; import android.os.Handler; import android.os.RemoteException; import android.os.UserHandle; import android.text.TextUtils; -import android.text.format.DateFormat; import android.util.AttributeSet; import android.util.Log; -import android.util.Slog; import android.util.TypedValue; import android.view.View; import android.widget.GridLayout; @@ -39,15 +36,18 @@ import androidx.core.graphics.ColorUtils; import com.android.internal.widget.LockPatternUtils; import com.android.systemui.Dependency; import com.android.systemui.R; -import com.android.systemui.statusbar.policy.ConfigurationController; import java.io.FileDescriptor; import java.io.PrintWriter; -import java.util.Locale; -import java.util.TimeZone; -public class KeyguardStatusView extends GridLayout implements - ConfigurationController.ConfigurationListener { +/** + * View consisting of: + * - keyguard clock + * - logout button (on certain managed devices) + * - owner information (if set) + * - notification icons (shown on AOD) + */ +public class KeyguardStatusView extends GridLayout { private static final boolean DEBUG = KeyguardConstants.DEBUG; private static final String TAG = "KeyguardStatusView"; private static final int MARQUEE_DELAY_MS = 2000; @@ -62,9 +62,7 @@ public class KeyguardStatusView extends GridLayout implements private View mNotificationIcons; private Runnable mPendingMarqueeStart; private Handler mHandler; - private KeyguardSliceViewController mKeyguardSliceViewController; - private boolean mPulsing; private float mDarkAmount = 0; private int mTextColor; @@ -76,56 +74,6 @@ public class KeyguardStatusView extends GridLayout implements private int mIconTopMarginWithHeader; private boolean mShowingHeader; - private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() { - - @Override - public void onLockScreenModeChanged(int mode) { - updateLockScreenMode(mode); - } - - @Override - public void onTimeChanged() { - refreshTime(); - } - - @Override - public void onTimeZoneChanged(TimeZone timeZone) { - updateTimeZone(timeZone); - } - - @Override - public void onKeyguardVisibilityChanged(boolean showing) { - if (showing) { - if (DEBUG) Slog.v(TAG, "refresh statusview showing:" + showing); - refreshTime(); - updateOwnerInfo(); - updateLogoutView(); - } - } - - @Override - public void onStartedWakingUp() { - setEnableMarquee(true); - } - - @Override - public void onFinishedGoingToSleep(int why) { - setEnableMarquee(false); - } - - @Override - public void onUserSwitchComplete(int userId) { - refreshFormat(); - updateOwnerInfo(); - updateLogoutView(); - } - - @Override - public void onLogoutEnabledChanged() { - updateLogoutView(); - } - }; - public KeyguardStatusView(Context context) { this(context, null, 0); } @@ -142,21 +90,7 @@ public class KeyguardStatusView extends GridLayout implements onDensityOrFontScaleChanged(); } - /** - * If we're presenting a custom clock of just the default one. - */ - public boolean hasCustomClock() { - return mClockView.hasCustomClock(); - } - - /** - * Set whether or not the lock screen is showing notifications. - */ - public void setHasVisibleNotifications(boolean hasVisibleNotifications) { - mClockView.setHasVisibleNotifications(hasVisibleNotifications); - } - - private void setEnableMarquee(boolean enabled) { + void setEnableMarquee(boolean enabled) { if (DEBUG) Log.v(TAG, "Schedule setEnableMarquee: " + (enabled ? "Enable" : "Disable")); if (enabled) { if (mPendingMarqueeStart == null) { @@ -203,7 +137,6 @@ public class KeyguardStatusView extends GridLayout implements boolean shouldMarquee = Dependency.get(KeyguardUpdateMonitor.class).isDeviceInteractive(); setEnableMarquee(shouldMarquee); - refreshFormat(); updateOwnerInfo(); updateLogoutView(); updateDark(); @@ -238,64 +171,14 @@ public class KeyguardStatusView extends GridLayout implements layoutOwnerInfo(); } - @Override - public void onDensityOrFontScaleChanged() { - if (mClockView != null) { - mClockView.setTextSize(TypedValue.COMPLEX_UNIT_PX, - getResources().getDimensionPixelSize(R.dimen.widget_big_font_size)); - } - if (mOwnerInfo != null) { - mOwnerInfo.setTextSize(TypedValue.COMPLEX_UNIT_PX, - getResources().getDimensionPixelSize(R.dimen.widget_label_font_size)); - } - loadBottomMargin(); - } - - public void dozeTimeTick() { - refreshTime(); - mKeyguardSliceViewController.refresh(); - } - - private void refreshTime() { - mClockView.refresh(); - } - - private void updateLockScreenMode(int mode) { - mClockView.updateLockScreenMode(mode); - } - - private void updateTimeZone(TimeZone timeZone) { - mClockView.onTimeZoneChanged(timeZone); - } - - private void refreshFormat() { - Patterns.update(mContext); - mClockView.setFormat12Hour(Patterns.clockView12); - mClockView.setFormat24Hour(Patterns.clockView24); - } - - public int getLogoutButtonHeight() { + int getLogoutButtonHeight() { if (mLogoutView == null) { return 0; } return mLogoutView.getVisibility() == VISIBLE ? mLogoutView.getHeight() : 0; } - public float getClockTextSize() { - return mClockView.getTextSize(); - } - - /** - * Returns the preferred Y position of the clock. - * - * @param totalHeight The height available to position the clock. - * @return Y position of clock. - */ - public int getClockPreferredY(int totalHeight) { - return mClockView.getPreferredY(totalHeight); - } - - private void updateLogoutView() { + void updateLogoutView() { if (mLogoutView == null) { return; } @@ -305,7 +188,16 @@ public class KeyguardStatusView extends GridLayout implements com.android.internal.R.string.global_action_logout)); } - private void updateOwnerInfo() { + void onDensityOrFontScaleChanged() { + if (mOwnerInfo != null) { + mOwnerInfo.setTextSize(TypedValue.COMPLEX_UNIT_PX, + getResources().getDimensionPixelSize( + com.android.systemui.R.dimen.widget_label_font_size)); + loadBottomMargin(); + } + } + + void updateOwnerInfo() { if (mOwnerInfo == null) return; String info = mLockPatternUtils.getDeviceOwnerInfo(); if (info == null) { @@ -320,30 +212,36 @@ public class KeyguardStatusView extends GridLayout implements updateDark(); } - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - Dependency.get(KeyguardUpdateMonitor.class).registerCallback(mInfoCallback); - Dependency.get(ConfigurationController.class).addCallback(this); + void setDarkAmount(float darkAmount) { + if (mDarkAmount == darkAmount) { + return; + } + mDarkAmount = darkAmount; + mClockView.setDarkAmount(darkAmount); + updateDark(); } - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - Dependency.get(KeyguardUpdateMonitor.class).removeCallback(mInfoCallback); - Dependency.get(ConfigurationController.class).removeCallback(this); - } + void updateDark() { + boolean dark = mDarkAmount == 1; + if (mLogoutView != null) { + mLogoutView.setAlpha(dark ? 0 : 1); + } - @Override - public void onLocaleListChanged() { - refreshFormat(); + if (mOwnerInfo != null) { + boolean hasText = !TextUtils.isEmpty(mOwnerInfo.getText()); + mOwnerInfo.setVisibility(hasText ? VISIBLE : GONE); + layoutOwnerInfo(); + } + + final int blendedTextColor = ColorUtils.blendARGB(mTextColor, Color.WHITE, mDarkAmount); + mKeyguardSlice.setDarkAmount(mDarkAmount); + mClockView.setTextColor(blendedTextColor); } public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("KeyguardStatusView:"); pw.println(" mOwnerInfo: " + (mOwnerInfo == null ? "null" : mOwnerInfo.getVisibility() == VISIBLE)); - pw.println(" mPulsing: " + mPulsing); pw.println(" mDarkAmount: " + mDarkAmount); pw.println(" mTextColor: " + Integer.toHexString(mTextColor)); if (mLogoutView != null) { @@ -363,64 +261,6 @@ public class KeyguardStatusView extends GridLayout implements R.dimen.widget_vertical_padding_with_header); } - // DateFormat.getBestDateTimePattern is extremely expensive, and refresh is called often. - // This is an optimization to ensure we only recompute the patterns when the inputs change. - private static final class Patterns { - static String clockView12; - static String clockView24; - static String cacheKey; - - static void update(Context context) { - final Locale locale = Locale.getDefault(); - final Resources res = context.getResources(); - final String clockView12Skel = res.getString(R.string.clock_12hr_format); - final String clockView24Skel = res.getString(R.string.clock_24hr_format); - final String key = locale.toString() + clockView12Skel + clockView24Skel; - if (key.equals(cacheKey)) return; - - clockView12 = DateFormat.getBestDateTimePattern(locale, clockView12Skel); - // CLDR insists on adding an AM/PM indicator even though it wasn't in the skeleton - // format. The following code removes the AM/PM indicator if we didn't want it. - if (!clockView12Skel.contains("a")) { - clockView12 = clockView12.replaceAll("a", "").trim(); - } - - clockView24 = DateFormat.getBestDateTimePattern(locale, clockView24Skel); - - // Use fancy colon. - clockView24 = clockView24.replace(':', '\uee01'); - clockView12 = clockView12.replace(':', '\uee01'); - - cacheKey = key; - } - } - - public void setDarkAmount(float darkAmount) { - if (mDarkAmount == darkAmount) { - return; - } - mDarkAmount = darkAmount; - mClockView.setDarkAmount(darkAmount); - updateDark(); - } - - private void updateDark() { - boolean dark = mDarkAmount == 1; - if (mLogoutView != null) { - mLogoutView.setAlpha(dark ? 0 : 1); - } - - if (mOwnerInfo != null) { - boolean hasText = !TextUtils.isEmpty(mOwnerInfo.getText()); - mOwnerInfo.setVisibility(hasText ? VISIBLE : GONE); - layoutOwnerInfo(); - } - - final int blendedTextColor = ColorUtils.blendARGB(mTextColor, Color.WHITE, mDarkAmount); - mKeyguardSlice.setDarkAmount(mDarkAmount); - mClockView.setTextColor(blendedTextColor); - } - private void layoutOwnerInfo() { if (mOwnerInfo != null && mOwnerInfo.getVisibility() != GONE) { // Animate owner info during wake-up transition @@ -442,13 +282,6 @@ public class KeyguardStatusView extends GridLayout implements } } - public void setPulsing(boolean pulsing) { - if (mPulsing == pulsing) { - return; - } - mPulsing = pulsing; - } - private boolean shouldShowLogout() { return Dependency.get(KeyguardUpdateMonitor.class).isLogoutEnabled() && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM; @@ -463,9 +296,4 @@ public class KeyguardStatusView extends GridLayout implements Log.e(TAG, "Failed to logout user", re); } } - - // TODO: remove this method when a controller is available. - void setKeyguardSliceViewController(KeyguardSliceViewController keyguardSliceViewController) { - mKeyguardSliceViewController = keyguardSliceViewController; - } } |