Merge "Update AOD/LS clock"

This commit is contained in:
Beverly Tai
2020-12-03 19:53:25 +00:00
committed by Android (Google) Code Review
12 changed files with 147 additions and 12 deletions

View File

@@ -126,6 +126,13 @@ public interface ClockPlugin extends Plugin {
*/
default void onTimeZoneChanged(TimeZone timeZone) {}
/**
* Notifies that the time format has changed.
*
* @param timeFormat "12" for 12-hour format, "24" for 24-hour format
*/
default void onTimeFormatChanged(String timeFormat) {}
/**
* Indicates whether the keyguard status area (date) should be shown below
* the clock.

View File

@@ -73,13 +73,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="80dp"
android:textSize="100dp"
android:letterSpacing="0.02"
android:lineSpacingMultiplier=".8"
android:includeFontPadding="false"
android:fontFamily="@font/clock"
android:typeface="monospace"
android:elegantTextHeight="false"
dozeWeight="200"
lockScreenWeight="300"
/>
</FrameLayout>
<FrameLayout
@@ -95,13 +97,15 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textSize="180dp"
android:textSize="200dp"
android:letterSpacing="0.02"
android:lineSpacingMultiplier=".8"
android:includeFontPadding="false"
android:fontFamily="@font/clock"
android:typeface="monospace"
android:elegantTextHeight="false"
dozeWeight="100"
lockScreenWeight="400"
/>
</FrameLayout>
<include layout="@layout/keyguard_status_area"

View File

@@ -39,4 +39,9 @@
</declare-styleable>
<attr name="passwordStyle" format="reference" />
<declare-styleable name="AnimatableClockView">
<attr name="dozeWeight" format="integer" />
<attr name="lockScreenWeight" format="integer" />
</declare-styleable>
</resources>

View File

@@ -137,5 +137,4 @@
<item name="android:shadowColor">@color/keyguard_shadow_color</item>
<item name="android:shadowRadius">?attr/shadowRadius</item>
</style>
</resources>

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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() {

View File

@@ -328,6 +328,11 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
mKeyguardClockSwitchController.updateTimeZone(timeZone);
}
@Override
public void onTimeFormatChanged(String timeFormat) {
mKeyguardClockSwitchController.refreshFormat(timeFormat);
}
@Override
public void onKeyguardVisibilityChanged(boolean showing) {
if (showing) {

View File

@@ -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() {
@@ -2449,6 +2468,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}
*/
@@ -3059,6 +3094,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) {

View File

@@ -57,6 +57,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.
*/

View File

@@ -23,6 +23,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.res.Resources;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
@@ -72,6 +73,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
Resources mResources;
@Mock
NotificationIconAreaController mNotificationIconAreaController;
@Mock
ContentResolver mContentResolver;
private KeyguardClockSwitchController mController;
@@ -90,7 +93,8 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
mColorExtractor,
mClockManager,
mKeyguardSliceViewController,
mNotificationIconAreaController);
mNotificationIconAreaController,
mContentResolver);
when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE);
when(mColorExtractor.getColors(anyInt())).thenReturn(mGradientColors);