Merge "Bring back time formatting for single line clock" into sc-dev am: 67e353d818
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15192039 Change-Id: If27b4660b54a715b156c5a63d7c478202a1a3466
This commit is contained in:
@@ -35,13 +35,13 @@
|
||||
android:id="@+id/animatable_clock_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_gravity="start"
|
||||
android:gravity="start"
|
||||
android:textSize="@dimen/clock_text_size"
|
||||
android:fontFamily="@font/clock"
|
||||
android:typeface="monospace"
|
||||
android:elegantTextHeight="false"
|
||||
android:singleLine="true"
|
||||
android:fontFeatureSettings="pnum"
|
||||
chargeAnimationDelay="350"
|
||||
dozeWeight="200"
|
||||
lockScreenWeight="400"
|
||||
|
||||
@@ -212,6 +212,7 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
|
||||
} else {
|
||||
mView.setLineSpacingScale(mDefaultLineSpacing);
|
||||
}
|
||||
mView.refreshFormat();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ package com.android.keyguard;
|
||||
import android.annotation.FloatRange;
|
||||
import android.annotation.IntRange;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
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;
|
||||
@@ -30,6 +30,7 @@ import com.android.systemui.R;
|
||||
import com.android.systemui.statusbar.phone.KeyguardBypassController;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import kotlin.Unit;
|
||||
@@ -41,8 +42,6 @@ import kotlin.Unit;
|
||||
public class AnimatableClockView extends TextView {
|
||||
private static final CharSequence DOUBLE_LINE_FORMAT_12_HOUR = "hh\nmm";
|
||||
private static final CharSequence DOUBLE_LINE_FORMAT_24_HOUR = "HH\nmm";
|
||||
private static final CharSequence SINGLE_LINE_FORMAT_12_HOUR = "h:mm";
|
||||
private static final CharSequence SINGLE_LINE_FORMAT_24_HOUR = "HH:mm";
|
||||
private static final long DOZE_ANIM_DURATION = 300;
|
||||
private static final long APPEAR_ANIM_DURATION = 350;
|
||||
private static final long CHARGE_ANIM_DURATION_PHASE_0 = 500;
|
||||
@@ -259,25 +258,47 @@ public class AnimatableClockView extends TextView {
|
||||
}
|
||||
|
||||
void refreshFormat() {
|
||||
Patterns.update(mContext);
|
||||
|
||||
final boolean use24HourFormat = DateFormat.is24HourFormat(getContext());
|
||||
if (mIsSingleLine && use24HourFormat) {
|
||||
mFormat = SINGLE_LINE_FORMAT_24_HOUR;
|
||||
mFormat = Patterns.sClockView24;
|
||||
} else if (!mIsSingleLine && use24HourFormat) {
|
||||
mFormat = DOUBLE_LINE_FORMAT_24_HOUR;
|
||||
} else if (mIsSingleLine && !use24HourFormat) {
|
||||
mFormat = SINGLE_LINE_FORMAT_12_HOUR;
|
||||
mFormat = Patterns.sClockView12;
|
||||
} else {
|
||||
mFormat = DOUBLE_LINE_FORMAT_12_HOUR;
|
||||
}
|
||||
|
||||
mDescFormat = getBestDateTimePattern(getContext(), use24HourFormat ? "Hm" : "hm");
|
||||
mDescFormat = use24HourFormat ? Patterns.sClockView24 : Patterns.sClockView12;
|
||||
refreshTime();
|
||||
}
|
||||
|
||||
private static String getBestDateTimePattern(Context context, String skeleton) {
|
||||
DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance(
|
||||
context.getResources().getConfiguration().locale);
|
||||
return dtpg.getBestPattern(skeleton);
|
||||
// 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 sClockView12;
|
||||
static String sClockView24;
|
||||
static String sCacheKey;
|
||||
|
||||
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(sCacheKey)) return;
|
||||
sClockView12 = 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")) {
|
||||
sClockView12 = sClockView12.replaceAll("a", "").trim();
|
||||
}
|
||||
sClockView24 = DateFormat.getBestDateTimePattern(locale, clockView24Skel);
|
||||
sCacheKey = key;
|
||||
}
|
||||
}
|
||||
|
||||
interface DozeStateGetter {
|
||||
|
||||
@@ -20,9 +20,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.res.Resources;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateFormat;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
@@ -367,37 +365,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
|
||||
return mColorExtractor.getColors(WallpaperManager.FLAG_LOCK);
|
||||
}
|
||||
|
||||
// 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 sClockView12;
|
||||
static String sClockView24;
|
||||
static String sCacheKey;
|
||||
|
||||
static void update(Resources res) {
|
||||
final Locale locale = Locale.getDefault();
|
||||
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(sCacheKey)) return;
|
||||
|
||||
sClockView12 = 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")) {
|
||||
sClockView12 = sClockView12.replaceAll("a", "").trim();
|
||||
}
|
||||
|
||||
sClockView24 = DateFormat.getBestDateTimePattern(locale, clockView24Skel);
|
||||
|
||||
// Use fancy colon.
|
||||
sClockView24 = sClockView24.replace(':', '\uee01');
|
||||
sClockView12 = sClockView12.replace(':', '\uee01');
|
||||
|
||||
sCacheKey = key;
|
||||
}
|
||||
}
|
||||
|
||||
private int getCurrentLayoutDirection() {
|
||||
return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user