Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java +20 −14 Original line number Original line Diff line number Diff line Loading @@ -88,10 +88,11 @@ public class Clock extends TextView implements private boolean mAttached; private boolean mAttached; private boolean mScreenReceiverRegistered; private boolean mScreenReceiverRegistered; private Calendar mCalendar; private Calendar mCalendar; private String mClockFormatString; private String mContentDescriptionFormatString; private SimpleDateFormat mClockFormat; private SimpleDateFormat mClockFormat; private SimpleDateFormat mContentDescriptionFormat; private SimpleDateFormat mContentDescriptionFormat; private Locale mLocale; private Locale mLocale; private DateTimePatternGenerator mDateTimePatternGenerator; private static final int AM_PM_STYLE_NORMAL = 0; private static final int AM_PM_STYLE_NORMAL = 0; private static final int AM_PM_STYLE_SMALL = 1; private static final int AM_PM_STYLE_SMALL = 1; Loading Loading @@ -196,7 +197,8 @@ public class Clock extends TextView implements // The time zone may have changed while the receiver wasn't registered, so update the Time // The time zone may have changed while the receiver wasn't registered, so update the Time mCalendar = Calendar.getInstance(TimeZone.getDefault()); mCalendar = Calendar.getInstance(TimeZone.getDefault()); mClockFormatString = ""; mContentDescriptionFormatString = ""; mDateTimePatternGenerator = null; // Make sure we update to the current time // Make sure we update to the current time updateClock(); updateClock(); Loading Loading @@ -247,7 +249,9 @@ public class Clock extends TextView implements handler.post(() -> { handler.post(() -> { if (!newLocale.equals(mLocale)) { if (!newLocale.equals(mLocale)) { mLocale = newLocale; mLocale = newLocale; mClockFormatString = ""; // force refresh // Force refresh of dependent variables. mContentDescriptionFormatString = ""; mDateTimePatternGenerator = null; } } }); }); } } Loading Loading @@ -367,17 +371,22 @@ public class Clock extends TextView implements private final CharSequence getSmallTime() { private final CharSequence getSmallTime() { Context context = getContext(); Context context = getContext(); boolean is24 = DateFormat.is24HourFormat(context, mCurrentUserId); boolean is24 = DateFormat.is24HourFormat(context, mCurrentUserId); DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance( if (mDateTimePatternGenerator == null) { // Despite its name, getInstance creates a cloned instance, so reuse the generator to // avoid unnecessary churn. mDateTimePatternGenerator = DateTimePatternGenerator.getInstance( context.getResources().getConfiguration().locale); context.getResources().getConfiguration().locale); } final char MAGIC1 = '\uEF00'; final char MAGIC1 = '\uEF00'; final char MAGIC2 = '\uEF01'; final char MAGIC2 = '\uEF01'; SimpleDateFormat sdf; final String formatSkeleton = mShowSeconds String format = mShowSeconds ? is24 ? "Hms" : "hms" ? is24 ? dtpg.getBestPattern("Hms") : dtpg.getBestPattern("hms") : is24 ? "Hm" : "hm"; : is24 ? dtpg.getBestPattern("Hm") : dtpg.getBestPattern("hm"); String format = mDateTimePatternGenerator.getBestPattern(formatSkeleton); if (!format.equals(mClockFormatString)) { if (!format.equals(mContentDescriptionFormatString)) { mContentDescriptionFormatString = format; mContentDescriptionFormat = new SimpleDateFormat(format); mContentDescriptionFormat = new SimpleDateFormat(format); /* /* * Search for an unquoted "a" in the format string, so we can * Search for an unquoted "a" in the format string, so we can Loading Loading @@ -409,12 +418,9 @@ public class Clock extends TextView implements + "a" + MAGIC2 + format.substring(b + 1); + "a" + MAGIC2 + format.substring(b + 1); } } } } mClockFormat = sdf = new SimpleDateFormat(format); mClockFormat = new SimpleDateFormat(format); mClockFormatString = format; } else { sdf = mClockFormat; } } String result = sdf.format(mCalendar.getTime()); String result = mClockFormat.format(mCalendar.getTime()); if (mAmPmStyle != AM_PM_STYLE_NORMAL) { if (mAmPmStyle != AM_PM_STYLE_NORMAL) { int magic1 = result.indexOf(MAGIC1); int magic1 = result.indexOf(MAGIC1); Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java +20 −14 Original line number Original line Diff line number Diff line Loading @@ -88,10 +88,11 @@ public class Clock extends TextView implements private boolean mAttached; private boolean mAttached; private boolean mScreenReceiverRegistered; private boolean mScreenReceiverRegistered; private Calendar mCalendar; private Calendar mCalendar; private String mClockFormatString; private String mContentDescriptionFormatString; private SimpleDateFormat mClockFormat; private SimpleDateFormat mClockFormat; private SimpleDateFormat mContentDescriptionFormat; private SimpleDateFormat mContentDescriptionFormat; private Locale mLocale; private Locale mLocale; private DateTimePatternGenerator mDateTimePatternGenerator; private static final int AM_PM_STYLE_NORMAL = 0; private static final int AM_PM_STYLE_NORMAL = 0; private static final int AM_PM_STYLE_SMALL = 1; private static final int AM_PM_STYLE_SMALL = 1; Loading Loading @@ -196,7 +197,8 @@ public class Clock extends TextView implements // The time zone may have changed while the receiver wasn't registered, so update the Time // The time zone may have changed while the receiver wasn't registered, so update the Time mCalendar = Calendar.getInstance(TimeZone.getDefault()); mCalendar = Calendar.getInstance(TimeZone.getDefault()); mClockFormatString = ""; mContentDescriptionFormatString = ""; mDateTimePatternGenerator = null; // Make sure we update to the current time // Make sure we update to the current time updateClock(); updateClock(); Loading Loading @@ -247,7 +249,9 @@ public class Clock extends TextView implements handler.post(() -> { handler.post(() -> { if (!newLocale.equals(mLocale)) { if (!newLocale.equals(mLocale)) { mLocale = newLocale; mLocale = newLocale; mClockFormatString = ""; // force refresh // Force refresh of dependent variables. mContentDescriptionFormatString = ""; mDateTimePatternGenerator = null; } } }); }); } } Loading Loading @@ -367,17 +371,22 @@ public class Clock extends TextView implements private final CharSequence getSmallTime() { private final CharSequence getSmallTime() { Context context = getContext(); Context context = getContext(); boolean is24 = DateFormat.is24HourFormat(context, mCurrentUserId); boolean is24 = DateFormat.is24HourFormat(context, mCurrentUserId); DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance( if (mDateTimePatternGenerator == null) { // Despite its name, getInstance creates a cloned instance, so reuse the generator to // avoid unnecessary churn. mDateTimePatternGenerator = DateTimePatternGenerator.getInstance( context.getResources().getConfiguration().locale); context.getResources().getConfiguration().locale); } final char MAGIC1 = '\uEF00'; final char MAGIC1 = '\uEF00'; final char MAGIC2 = '\uEF01'; final char MAGIC2 = '\uEF01'; SimpleDateFormat sdf; final String formatSkeleton = mShowSeconds String format = mShowSeconds ? is24 ? "Hms" : "hms" ? is24 ? dtpg.getBestPattern("Hms") : dtpg.getBestPattern("hms") : is24 ? "Hm" : "hm"; : is24 ? dtpg.getBestPattern("Hm") : dtpg.getBestPattern("hm"); String format = mDateTimePatternGenerator.getBestPattern(formatSkeleton); if (!format.equals(mClockFormatString)) { if (!format.equals(mContentDescriptionFormatString)) { mContentDescriptionFormatString = format; mContentDescriptionFormat = new SimpleDateFormat(format); mContentDescriptionFormat = new SimpleDateFormat(format); /* /* * Search for an unquoted "a" in the format string, so we can * Search for an unquoted "a" in the format string, so we can Loading Loading @@ -409,12 +418,9 @@ public class Clock extends TextView implements + "a" + MAGIC2 + format.substring(b + 1); + "a" + MAGIC2 + format.substring(b + 1); } } } } mClockFormat = sdf = new SimpleDateFormat(format); mClockFormat = new SimpleDateFormat(format); mClockFormatString = format; } else { sdf = mClockFormat; } } String result = sdf.format(mCalendar.getTime()); String result = mClockFormat.format(mCalendar.getTime()); if (mAmPmStyle != AM_PM_STYLE_NORMAL) { if (mAmPmStyle != AM_PM_STYLE_NORMAL) { int magic1 = result.indexOf(MAGIC1); int magic1 = result.indexOf(MAGIC1); Loading