diff options
author | Beverly <beverlyt@google.com> | 2020-12-01 09:00:57 -0500 |
---|---|---|
committer | Beverly Tai <beverlyt@google.com> | 2020-12-03 14:09:35 +0000 |
commit | e1b6d7f819a892b650f61db5ad5c0621e2b80f06 (patch) | |
tree | c8a843352588d4c92255f3a802b0642af7b254b4 /packages/SystemUI/src | |
parent | 648d4e5e005f2a1422d5e8f8cf7bd4d9c93639e0 (diff) |
Update AOD/LS clock
- Update clock sizes (large clock = 200dp, small clock = 100dp)
- Update clock weights (large = 100-400, small = 200-300)
- Update clocks on time zone and time format changes
(Settings > System > Date & Time)
Test: manual, atest SystemUITests
Bug: 170228350
Change-Id: I446a2625fdd776c15e744f1601b3ea0e2a873cf1
Diffstat (limited to 'packages/SystemUI/src')
7 files changed, 124 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java index 3157a5a8fc5b..7c6a27446c78 100644 --- a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java +++ b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java @@ -24,6 +24,8 @@ import com.android.settingslib.Utils; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.util.ViewController; +import java.util.TimeZone; + /** * Controls the color of a GradientTextClock. */ @@ -62,12 +64,26 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie } /** - * Updates the time for this view. + * Updates the time for the view. */ public void refreshTime() { mView.refreshTime(); } + /** + * Updates the timezone for the view. + */ + public void onTimeZoneChanged(TimeZone timeZone) { + mView.onTimeZoneChanged(timeZone); + } + + /** + * Trigger a time format update + */ + public void refreshFormat() { + mView.refreshFormat(); + } + private void initColors() { mLockScreenColors[0] = Utils.getColorAttrDefaultColor(getContext(), com.android.systemui.R.attr.wallpaperTextColor); diff --git a/packages/SystemUI/src/com/android/keyguard/AnimatableClockView.java b/packages/SystemUI/src/com/android/keyguard/AnimatableClockView.java index 6d1d42e2988b..ca99563986b4 100644 --- a/packages/SystemUI/src/com/android/keyguard/AnimatableClockView.java +++ b/packages/SystemUI/src/com/android/keyguard/AnimatableClockView.java @@ -19,13 +19,17 @@ package com.android.keyguard; import android.annotation.FloatRange; import android.annotation.IntRange; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Canvas; import android.icu.text.DateTimePatternGenerator; import android.text.format.DateFormat; import android.util.AttributeSet; import android.widget.TextView; +import com.android.systemui.R; + import java.util.Calendar; +import java.util.TimeZone; import kotlin.Unit; @@ -38,11 +42,14 @@ public class AnimatableClockView extends TextView { private static final CharSequence FORMAT_24_HOUR = "HH\nmm"; private static final long ANIM_DURATION = 300; + private final Calendar mTime = Calendar.getInstance(); + private CharSequence mFormat; private CharSequence mDescFormat; - private Calendar mTime = Calendar.getInstance(); private int[] mDozingColors; private int[] mLockScreenColors; + private final int mDozingWeight; + private final int mLockScreenWeight; private TextAnimator mTextAnimator = null; private Runnable mOnTextAnimatorInitialized; @@ -62,13 +69,21 @@ public class AnimatableClockView extends TextView { public AnimatableClockView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - updateTimeFormat(); + TypedArray ta = context.obtainStyledAttributes( + attrs, R.styleable.AnimatableClockView, defStyleAttr, defStyleRes); + try { + mDozingWeight = ta.getInt(R.styleable.AnimatableClockView_dozeWeight, 100); + mLockScreenWeight = ta.getInt(R.styleable.AnimatableClockView_lockScreenWeight, 300); + } finally { + ta.recycle(); + } + refreshFormat(); } @Override public void onAttachedToWindow() { super.onAttachedToWindow(); - updateTimeFormat(); + refreshFormat(); } @Override @@ -82,6 +97,11 @@ public class AnimatableClockView extends TextView { setContentDescription(DateFormat.format(mDescFormat, mTime)); } + void onTimeZoneChanged(TimeZone timeZone) { + mTime.setTimeZone(timeZone); + refreshFormat(); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); @@ -113,7 +133,7 @@ public class AnimatableClockView extends TextView { } void animateDoze(boolean isDozing, boolean animate) { - setTextStyle(isDozing ? 100 : 300 /* weight */, + setTextStyle(isDozing ? mDozingWeight : mLockScreenWeight /* weight */, -1, isDozing ? mDozingColors : mLockScreenColors, animate); @@ -144,10 +164,11 @@ public class AnimatableClockView extends TextView { } } - private void updateTimeFormat() { + void refreshFormat() { final boolean use24HourFormat = DateFormat.is24HourFormat(getContext()); mFormat = use24HourFormat ? FORMAT_24_HOUR : FORMAT_12_HOUR; mDescFormat = getBestDateTimePattern(getContext(), use24HourFormat ? "Hm" : "hm"); + refreshTime(); } private static String getBestDateTimePattern(Context context, String skeleton) { diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java index 68405a1fca68..0a78efa8ea03 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java @@ -401,6 +401,17 @@ public class KeyguardClockSwitch extends RelativeLayout { } } + /** + * Notifies that the time format has changed. + * + * @param timeFormat "12" for 12-hour format, "24" for 24-hour format + */ + public void onTimeFormatChanged(String timeFormat) { + if (mClockPlugin != null) { + mClockPlugin.onTimeFormatChanged(timeFormat); + } + } + void updateColors(ColorExtractor.GradientColors colors) { mSupportsDarkText = colors.supportsDarkText(); mColorPalette = colors.getColorPalette(); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java index 829ff9771fb4..4d6e8a90e57b 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java @@ -17,7 +17,9 @@ package com.android.keyguard; import android.app.WallpaperManager; +import android.content.ContentResolver; import android.content.res.Resources; +import android.provider.Settings; import android.text.format.DateFormat; import android.util.TypedValue; import android.view.View; @@ -90,6 +92,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS }; private ClockManager.ClockChangedListener mClockChangedListener = this::setClockPlugin; + private String mTimeFormat; @Inject public KeyguardClockSwitchController( @@ -98,7 +101,8 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS StatusBarStateController statusBarStateController, SysuiColorExtractor colorExtractor, ClockManager clockManager, KeyguardSliceViewController keyguardSliceViewController, - NotificationIconAreaController notificationIconAreaController) { + NotificationIconAreaController notificationIconAreaController, + ContentResolver contentResolver) { super(keyguardClockSwitch); mResources = resources; mStatusBarStateController = statusBarStateController; @@ -106,6 +110,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS mClockManager = clockManager; mKeyguardSliceViewController = keyguardSliceViewController; mNotificationIconAreaController = notificationIconAreaController; + mTimeFormat = Settings.System.getString(contentResolver, Settings.System.TIME_12_24); } /** @@ -246,12 +251,26 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS void updateTimeZone(TimeZone timeZone) { mView.onTimeZoneChanged(timeZone); + if (mNewLockScreenClockViewController != null) { + mNewLockScreenClockViewController.onTimeZoneChanged(timeZone); + mNewLockScreenLargeClockViewController.onTimeZoneChanged(timeZone); + } } - void refreshFormat() { + void refreshFormat(String timeFormat) { + mTimeFormat = timeFormat; Patterns.update(mResources); mView.setFormat12Hour(Patterns.sClockView12); mView.setFormat24Hour(Patterns.sClockView24); + mView.onTimeFormatChanged(mTimeFormat); + if (mNewLockScreenClockViewController != null) { + mNewLockScreenClockViewController.refreshFormat(); + mNewLockScreenLargeClockViewController.refreshFormat(); + } + } + + void refreshFormat() { + refreshFormat(mTimeFormat); } float getClockTextTopPadding() { diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java index bc81a198c7e6..826020c71159 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java @@ -329,6 +329,11 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV } @Override + public void onTimeFormatChanged(String timeFormat) { + mKeyguardClockSwitchController.refreshFormat(timeFormat); + } + + @Override public void onKeyguardVisibilityChanged(boolean showing) { if (showing) { if (DEBUG) Slog.v(TAG, "refresh statusview showing:" + showing); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index a7e51951e9cd..2fa45e6d1b95 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -182,6 +182,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab private static final int MSG_USER_REMOVED = 341; private static final int MSG_KEYGUARD_GOING_AWAY = 342; private static final int MSG_LOCK_SCREEN_MODE = 343; + private static final int MSG_TIME_FORMAT_UPDATE = 344; public static final int LOCK_SCREEN_MODE_NORMAL = 0; public static final int LOCK_SCREEN_MODE_LAYOUT_1 = 1; @@ -280,6 +281,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab mCallbacks = Lists.newArrayList(); private ContentObserver mDeviceProvisionedObserver; private ContentObserver mLockScreenModeObserver; + private ContentObserver mTimeFormatChangeObserver; private boolean mSwitchingUser; @@ -1721,6 +1723,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab case MSG_LOCK_SCREEN_MODE: handleLockScreenMode(); break; + case MSG_TIME_FORMAT_UPDATE: + handleTimeFormatUpdate((String) msg.obj); + break; default: super.handleMessage(msg); break; @@ -1866,6 +1871,20 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab mContext.getContentResolver().registerContentObserver( Settings.Global.getUriFor(Settings.Global.SHOW_NEW_LOCKSCREEN), false, mLockScreenModeObserver); + + mTimeFormatChangeObserver = new ContentObserver(mHandler) { + @Override + public void onChange(boolean selfChange) { + mHandler.sendMessage(mHandler.obtainMessage( + MSG_TIME_FORMAT_UPDATE, + Settings.System.getString( + mContext.getContentResolver(), + Settings.System.TIME_12_24))); + } + }; + mContext.getContentResolver().registerContentObserver( + Settings.System.getUriFor(Settings.System.TIME_12_24), + false, mTimeFormatChangeObserver, UserHandle.USER_ALL); } private void updateLockScreenMode() { @@ -2451,6 +2470,22 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } /** + * Handle (@line #MSG_TIME_FORMAT_UPDATE} + * + * @param timeFormat "12" for 12-hour format, "24" for 24-hour format + */ + private void handleTimeFormatUpdate(String timeFormat) { + Assert.isMainThread(); + if (DEBUG) Log.d(TAG, "handleTimeFormatUpdate timeFormat=" + timeFormat); + for (int i = 0; i < mCallbacks.size(); i++) { + KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); + if (cb != null) { + cb.onTimeFormatChanged(timeFormat); + } + } + } + + /** * Handle {@link #MSG_BATTERY_UPDATE} */ private void handleBatteryUpdate(BatteryStatus status) { @@ -3055,6 +3090,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab mContext.getContentResolver().unregisterContentObserver(mLockScreenModeObserver); } + if (mTimeFormatChangeObserver != null) { + mContext.getContentResolver().unregisterContentObserver(mTimeFormatChangeObserver); + } + try { ActivityManager.getService().unregisterUserSwitchObserver(mUserSwitchObserver); } catch (RemoteException e) { diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java index b722deab528a..36617c239352 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java @@ -58,6 +58,11 @@ public class KeyguardUpdateMonitorCallback { public void onTimeZoneChanged(TimeZone timeZone) { } /** + * Called when time format changes. + */ + public void onTimeFormatChanged(String timeFormat) { } + + /** * Called when the carrier PLMN or SPN changes. */ public void onRefreshCarrierInfo() { } |