From 8fc8607cb77cda092a4eca63560e4d7bc5e2d469 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Wed, 8 Jun 2022 14:28:55 +0100 Subject: [PATCH] Use CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE... Use CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE in place of CAPITALIZATION_FOR_STANDALONE for date formats, since ICU does not capitalize (at least) month names correctly today according to https://unicode-org.atlassian.net/browse/ICU-21631. The motivating example is the DatePicker/SimpleMonthView for Vietnam with "{month} {year}" (as used in the manual date selection in the Date & Time screen of the System settings): it does not capitalize the month without this change. It's difficult to know which formats will be affected, so this change modifies all the formats found in frameworks/base/ that currently express a preference for STANDALONE. The fix may be available by ICU 72, at which point this change can presumably be reverted as signified in the TODOs. Bug: 229287642 Test: Inspection of Date & Time settings + compilation only Change-Id: Iea753d0318aef55c6dd4f7e09068a0362ac970d8 --- core/java/android/widget/DatePickerCalendarDelegate.java | 6 +++++- core/java/android/widget/SimpleMonthView.java | 6 +++++- .../android/systemui/keyguard/KeyguardSliceProvider.java | 6 +++++- .../com/android/systemui/statusbar/policy/DateView.java | 6 +++++- .../statusbar/policy/VariableDateViewController.kt | 8 ++++++-- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/core/java/android/widget/DatePickerCalendarDelegate.java b/core/java/android/widget/DatePickerCalendarDelegate.java index 1bde2351b2da0..536b81f771740 100755 --- a/core/java/android/widget/DatePickerCalendarDelegate.java +++ b/core/java/android/widget/DatePickerCalendarDelegate.java @@ -302,7 +302,11 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate { // Update the date formatter. mMonthDayFormat = DateFormat.getInstanceForSkeleton("EMMMd", locale); - mMonthDayFormat.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE); + // The use of CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE instead of + // CAPITALIZATION_FOR_STANDALONE is to address + // https://unicode-org.atlassian.net/browse/ICU-21631 + // TODO(b/229287642): Switch back to CAPITALIZATION_FOR_STANDALONE + mMonthDayFormat.setContext(DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE); mYearFormat = DateFormat.getInstanceForSkeleton("y", locale); // Update the header text. diff --git a/core/java/android/widget/SimpleMonthView.java b/core/java/android/widget/SimpleMonthView.java index 695a253a04e09..6c53a44c79faa 100644 --- a/core/java/android/widget/SimpleMonthView.java +++ b/core/java/android/widget/SimpleMonthView.java @@ -186,7 +186,11 @@ class SimpleMonthView extends View { private void updateMonthYearLabel() { final String format = DateFormat.getBestDateTimePattern(mLocale, MONTH_YEAR_FORMAT); final SimpleDateFormat formatter = new SimpleDateFormat(format, mLocale); - formatter.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE); + // The use of CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE instead of + // CAPITALIZATION_FOR_STANDALONE is to address + // https://unicode-org.atlassian.net/browse/ICU-21631 + // TODO(b/229287642): Switch back to CAPITALIZATION_FOR_STANDALONE + formatter.setContext(DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE); mMonthYearLabel = formatter.format(mCalendar.getTime()); } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java index 2a737970907a3..5d564f74772bb 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java @@ -414,7 +414,11 @@ public class KeyguardSliceProvider extends SliceProvider implements if (mDateFormat == null) { final Locale l = Locale.getDefault(); DateFormat format = DateFormat.getInstanceForSkeleton(mDatePattern, l); - format.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE); + // The use of CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE instead of + // CAPITALIZATION_FOR_STANDALONE is to address + // https://unicode-org.atlassian.net/browse/ICU-21631 + // TODO(b/229287642): Switch back to CAPITALIZATION_FOR_STANDALONE + format.setContext(DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE); mDateFormat = format; } mCurrentTime.setTime(System.currentTimeMillis()); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java index b4c154aa28cbe..b5bd1d8f01023 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DateView.java @@ -114,7 +114,11 @@ public class DateView extends TextView { if (mDateFormat == null) { final Locale l = Locale.getDefault(); DateFormat format = DateFormat.getInstanceForSkeleton(mDatePattern, l); - format.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE); + // The use of CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE instead of + // CAPITALIZATION_FOR_STANDALONE is to address + // https://unicode-org.atlassian.net/browse/ICU-21631 + // TODO(b/229287642): Switch back to CAPITALIZATION_FOR_STANDALONE + format.setContext(DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE); mDateFormat = format; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/VariableDateViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/VariableDateViewController.kt index 99d84c4d0cedf..f040d0a0efcf0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/VariableDateViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/VariableDateViewController.kt @@ -54,7 +54,11 @@ internal fun getFormatFromPattern(pattern: String?): DateFormat { } val l = Locale.getDefault() val format = DateFormat.getInstanceForSkeleton(pattern, l) - format.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE) + // The use of CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE instead of + // CAPITALIZATION_FOR_STANDALONE is to address + // https://unicode-org.atlassian.net/browse/ICU-21631 + // TODO(b/229287642): Switch back to CAPITALIZATION_FOR_STANDALONE + format.setContext(DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE) return format } @@ -218,4 +222,4 @@ class VariableDateViewController( ) } } -} \ No newline at end of file +}