From 9fe1c121272a469f69fb36766dc762e85a2052e1 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Thu, 6 Apr 2017 14:48:28 -0700 Subject: [PATCH] Special-case English for DateTime and Time key listeners Because English time patterns use uppercase letters by default (and a comma to separate date and time when both are represented), we were concluding they need internationalized input. Although they literally do, let's keep the world simple and assume they don't need internationalized input. Compared to Nougat, we will now accept uppercase AM and PM and comma for English if the IME allows them, we just continue to not signal that an internationalized layout is needed. Test: CTS tests pass Bug: https://code.google.com/p/android/issues/detail?id=2626 Bug: https://code.google.com/p/android/issues/detail?id=82993 Bug: 8319249 Bug: 33276673 Bug: 34394455 Bug: 37079150 Change-Id: I82bfde323ba49ae1a27ff5c2e729063b7d81dcc8 --- .../java/android/text/method/DateTimeKeyListener.java | 11 +++++++++-- core/java/android/text/method/TimeKeyListener.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/java/android/text/method/DateTimeKeyListener.java b/core/java/android/text/method/DateTimeKeyListener.java index 551db55601280..1593db5de6419 100644 --- a/core/java/android/text/method/DateTimeKeyListener.java +++ b/core/java/android/text/method/DateTimeKeyListener.java @@ -68,7 +68,7 @@ public class DateTimeKeyListener extends NumberKeyListener final LinkedHashSet chars = new LinkedHashSet<>(); // First add the digits. Then, add all the character in AM and PM markers. Finally, add all // the non-pattern characters seen in the patterns for "yMdhms" and "yMdHms". - boolean success = NumberKeyListener.addDigits(chars, locale) + final boolean success = NumberKeyListener.addDigits(chars, locale) && NumberKeyListener.addAmPmChars(chars, locale) && NumberKeyListener.addFormatCharsFromSkeleton( chars, locale, SKELETON_12HOUR, SYMBOLS_TO_IGNORE) @@ -76,7 +76,14 @@ public class DateTimeKeyListener extends NumberKeyListener chars, locale, SKELETON_24HOUR, SYMBOLS_TO_IGNORE); if (success) { mCharacters = NumberKeyListener.collectionToArray(chars); - mNeedsAdvancedInput = !ArrayUtils.containsAll(CHARACTERS, mCharacters); + if (locale != null && "en".equals(locale.getLanguage())) { + // For backward compatibility reasons, assume we don't need advanced input for + // English locales, although English locales literally also need a comma and perhaps + // uppercase letters for AM and PM. + mNeedsAdvancedInput = false; + } else { + mNeedsAdvancedInput = !ArrayUtils.containsAll(CHARACTERS, mCharacters); + } } else { mCharacters = CHARACTERS; mNeedsAdvancedInput = false; diff --git a/core/java/android/text/method/TimeKeyListener.java b/core/java/android/text/method/TimeKeyListener.java index 5b1db11777dd6..f11f40099d9c2 100644 --- a/core/java/android/text/method/TimeKeyListener.java +++ b/core/java/android/text/method/TimeKeyListener.java @@ -68,7 +68,7 @@ public class TimeKeyListener extends NumberKeyListener final LinkedHashSet chars = new LinkedHashSet<>(); // First add the digits. Then, add all the character in AM and PM markers. Finally, add all // the non-pattern characters seen in the patterns for "hms" and "Hms". - boolean success = NumberKeyListener.addDigits(chars, locale) + final boolean success = NumberKeyListener.addDigits(chars, locale) && NumberKeyListener.addAmPmChars(chars, locale) && NumberKeyListener.addFormatCharsFromSkeleton( chars, locale, SKELETON_12HOUR, SYMBOLS_TO_IGNORE) @@ -76,7 +76,14 @@ public class TimeKeyListener extends NumberKeyListener chars, locale, SKELETON_24HOUR, SYMBOLS_TO_IGNORE); if (success) { mCharacters = NumberKeyListener.collectionToArray(chars); - mNeedsAdvancedInput = !ArrayUtils.containsAll(CHARACTERS, mCharacters); + if (locale != null && "en".equals(locale.getLanguage())) { + // For backward compatibility reasons, assume we don't need advanced input for + // English locales, although English locales may need uppercase letters for + // AM and PM. + mNeedsAdvancedInput = false; + } else { + mNeedsAdvancedInput = !ArrayUtils.containsAll(CHARACTERS, mCharacters); + } } else { mCharacters = CHARACTERS; mNeedsAdvancedInput = false;