Loading api/current.txt +23 −13 Original line number Diff line number Diff line Loading @@ -41017,19 +41017,23 @@ package android.text.method { } public class DateKeyListener extends android.text.method.NumberKeyListener { ctor public DateKeyListener(); ctor public deprecated DateKeyListener(); ctor public DateKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateKeyListener getInstance(); method public static android.text.method.DateKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DateTimeKeyListener extends android.text.method.NumberKeyListener { ctor public DateTimeKeyListener(); ctor public deprecated DateTimeKeyListener(); ctor public DateTimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateTimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateTimeKeyListener getInstance(); method public static android.text.method.DateTimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DialerKeyListener extends android.text.method.NumberKeyListener { Loading @@ -41041,12 +41045,16 @@ package android.text.method { } public class DigitsKeyListener extends android.text.method.NumberKeyListener { ctor public DigitsKeyListener(); ctor public DigitsKeyListener(boolean, boolean); ctor public deprecated DigitsKeyListener(); ctor public deprecated DigitsKeyListener(boolean, boolean); ctor public DigitsKeyListener(java.util.Locale); ctor public DigitsKeyListener(java.util.Locale, boolean, boolean); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DigitsKeyListener getInstance(); method public static android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static deprecated android.text.method.DigitsKeyListener getInstance(); method public static deprecated android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale, boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.lang.String); } Loading Loading @@ -41190,11 +41198,13 @@ package android.text.method { } public class TimeKeyListener extends android.text.method.NumberKeyListener { ctor public TimeKeyListener(); ctor public deprecated TimeKeyListener(); ctor public TimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.TimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.TimeKeyListener getInstance(); method public static android.text.method.TimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class Touch { api/system-current.txt +23 −13 Original line number Diff line number Diff line Loading @@ -44452,19 +44452,23 @@ package android.text.method { } public class DateKeyListener extends android.text.method.NumberKeyListener { ctor public DateKeyListener(); ctor public deprecated DateKeyListener(); ctor public DateKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateKeyListener getInstance(); method public static android.text.method.DateKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DateTimeKeyListener extends android.text.method.NumberKeyListener { ctor public DateTimeKeyListener(); ctor public deprecated DateTimeKeyListener(); ctor public DateTimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateTimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateTimeKeyListener getInstance(); method public static android.text.method.DateTimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DialerKeyListener extends android.text.method.NumberKeyListener { Loading @@ -44476,12 +44480,16 @@ package android.text.method { } public class DigitsKeyListener extends android.text.method.NumberKeyListener { ctor public DigitsKeyListener(); ctor public DigitsKeyListener(boolean, boolean); ctor public deprecated DigitsKeyListener(); ctor public deprecated DigitsKeyListener(boolean, boolean); ctor public DigitsKeyListener(java.util.Locale); ctor public DigitsKeyListener(java.util.Locale, boolean, boolean); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DigitsKeyListener getInstance(); method public static android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static deprecated android.text.method.DigitsKeyListener getInstance(); method public static deprecated android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale, boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.lang.String); } Loading Loading @@ -44625,11 +44633,13 @@ package android.text.method { } public class TimeKeyListener extends android.text.method.NumberKeyListener { ctor public TimeKeyListener(); ctor public deprecated TimeKeyListener(); ctor public TimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.TimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.TimeKeyListener getInstance(); method public static android.text.method.TimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class Touch { api/test-current.txt +23 −13 Original line number Diff line number Diff line Loading @@ -41156,19 +41156,23 @@ package android.text.method { } public class DateKeyListener extends android.text.method.NumberKeyListener { ctor public DateKeyListener(); ctor public deprecated DateKeyListener(); ctor public DateKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateKeyListener getInstance(); method public static android.text.method.DateKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DateTimeKeyListener extends android.text.method.NumberKeyListener { ctor public DateTimeKeyListener(); ctor public deprecated DateTimeKeyListener(); ctor public DateTimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateTimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateTimeKeyListener getInstance(); method public static android.text.method.DateTimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DialerKeyListener extends android.text.method.NumberKeyListener { Loading @@ -41180,12 +41184,16 @@ package android.text.method { } public class DigitsKeyListener extends android.text.method.NumberKeyListener { ctor public DigitsKeyListener(); ctor public DigitsKeyListener(boolean, boolean); ctor public deprecated DigitsKeyListener(); ctor public deprecated DigitsKeyListener(boolean, boolean); ctor public DigitsKeyListener(java.util.Locale); ctor public DigitsKeyListener(java.util.Locale, boolean, boolean); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DigitsKeyListener getInstance(); method public static android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static deprecated android.text.method.DigitsKeyListener getInstance(); method public static deprecated android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale, boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.lang.String); } Loading Loading @@ -41329,11 +41337,13 @@ package android.text.method { } public class TimeKeyListener extends android.text.method.NumberKeyListener { ctor public TimeKeyListener(); ctor public deprecated TimeKeyListener(); ctor public TimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.TimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.TimeKeyListener getInstance(); method public static android.text.method.TimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class Touch { core/java/android/text/method/DateKeyListener.java +64 −9 Original line number Diff line number Diff line Loading @@ -16,9 +16,17 @@ package android.text.method; import android.annotation.NonNull; import android.annotation.Nullable; import android.text.InputType; import android.view.KeyEvent; import com.android.internal.annotations.GuardedBy; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Locale; /** * For entering dates in a text field. * <p></p> Loading @@ -34,29 +42,76 @@ public class DateKeyListener extends NumberKeyListener } @Override protected char[] getAcceptedChars() { return CHARACTERS; @NonNull protected char[] getAcceptedChars() { return mCharacters; } /** * @deprecated Use {@link #DateKeyListener(Locale)} instead. */ @Deprecated public DateKeyListener() { this(null); } private static final String SYMBOLS_TO_IGNORE = "yMLd"; private static final String[] SKELETONS = {"yMd", "yM", "Md"}; public DateKeyListener(@Nullable Locale locale) { final LinkedHashSet<Character> chars = new LinkedHashSet<>(); // First add the digits, then add all the non-pattern characters seen in the pattern for // "yMd", which is supposed to only have numerical fields. final boolean success = NumberKeyListener.addDigits(chars, locale) && NumberKeyListener.addFormatCharsFromSkeletons( chars, locale, SKELETONS, SYMBOLS_TO_IGNORE); mCharacters = success ? NumberKeyListener.collectionToArray(chars) : CHARACTERS; } /** * @deprecated Use {@link #getInstance(Locale)} instead. */ @Deprecated @NonNull public static DateKeyListener getInstance() { if (sInstance != null) return sInstance; return getInstance(null); } sInstance = new DateKeyListener(); return sInstance; /** * Returns an instance of DateKeyListener appropriate for the given locale. */ @NonNull public static DateKeyListener getInstance(@Nullable Locale locale) { DateKeyListener instance; synchronized (sLock) { instance = sInstanceCache.get(locale); if (instance == null) { instance = new DateKeyListener(locale); sInstanceCache.put(locale, instance); } } return instance; } /** * The characters that are used. * This field used to list the characters that were used. But is now a fixed data * field that is the list of code units used for the deprecated case where the class * is instantiated with null or no input parameter. * * @see KeyEvent#getMatch * @see #getAcceptedChars * * @deprecated Use {@link #getAcceptedChars()} instead. */ @Deprecated public static final char[] CHARACTERS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '/', '-', '.' }; private static DateKeyListener sInstance; private final char[] mCharacters; private static final Object sLock = new Object(); @GuardedBy("sLock") private static final HashMap<Locale, DateKeyListener> sInstanceCache = new HashMap<>(); } core/java/android/text/method/DateTimeKeyListener.java +66 −7 Original line number Diff line number Diff line Loading @@ -16,9 +16,17 @@ package android.text.method; import android.annotation.NonNull; import android.annotation.Nullable; import android.text.InputType; import android.view.KeyEvent; import com.android.internal.annotations.GuardedBy; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Locale; /** * For entering dates and times in the same text field. * <p></p> Loading @@ -34,29 +42,80 @@ public class DateTimeKeyListener extends NumberKeyListener } @Override @NonNull protected char[] getAcceptedChars() { return CHARACTERS; return mCharacters; } /** * @deprecated Use {@link #DateTimeKeyListener(Locale)} instead. */ @Deprecated public DateTimeKeyListener() { this(null); } private static final String SYMBOLS_TO_IGNORE = "yMLdahHKkms"; private static final String SKELETON_12HOUR = "yMdhms"; private static final String SKELETON_24HOUR = "yMdHms"; public DateTimeKeyListener(@Nullable Locale locale) { final LinkedHashSet<Character> 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) && NumberKeyListener.addAmPmChars(chars, locale) && NumberKeyListener.addFormatCharsFromSkeleton( chars, locale, SKELETON_12HOUR, SYMBOLS_TO_IGNORE) && NumberKeyListener.addFormatCharsFromSkeleton( chars, locale, SKELETON_24HOUR, SYMBOLS_TO_IGNORE); mCharacters = success ? NumberKeyListener.collectionToArray(chars) : CHARACTERS; } /** * @deprecated Use {@link #getInstance(Locale)} instead. */ @Deprecated @NonNull public static DateTimeKeyListener getInstance() { if (sInstance != null) return sInstance; return getInstance(null); } sInstance = new DateTimeKeyListener(); return sInstance; /** * Returns an instance of DateTimeKeyListener appropriate for the given locale. */ @NonNull public static DateTimeKeyListener getInstance(@Nullable Locale locale) { DateTimeKeyListener instance; synchronized (sLock) { instance = sInstanceCache.get(locale); if (instance == null) { instance = new DateTimeKeyListener(locale); sInstanceCache.put(locale, instance); } } return instance; } /** * The characters that are used. * This field used to list the characters that were used. But is now a fixed data * field that is the list of code units used for the deprecated case where the class * is instantiated with null or no input parameter. * * @see KeyEvent#getMatch * @see #getAcceptedChars * * @deprecated Use {@link #getAcceptedChars()} instead. */ public static final char[] CHARACTERS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'm', 'p', ':', '/', '-', ' ' }; private static DateTimeKeyListener sInstance; private final char[] mCharacters; private static final Object sLock = new Object(); @GuardedBy("sLock") private static final HashMap<Locale, DateTimeKeyListener> sInstanceCache = new HashMap<>(); } Loading
api/current.txt +23 −13 Original line number Diff line number Diff line Loading @@ -41017,19 +41017,23 @@ package android.text.method { } public class DateKeyListener extends android.text.method.NumberKeyListener { ctor public DateKeyListener(); ctor public deprecated DateKeyListener(); ctor public DateKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateKeyListener getInstance(); method public static android.text.method.DateKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DateTimeKeyListener extends android.text.method.NumberKeyListener { ctor public DateTimeKeyListener(); ctor public deprecated DateTimeKeyListener(); ctor public DateTimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateTimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateTimeKeyListener getInstance(); method public static android.text.method.DateTimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DialerKeyListener extends android.text.method.NumberKeyListener { Loading @@ -41041,12 +41045,16 @@ package android.text.method { } public class DigitsKeyListener extends android.text.method.NumberKeyListener { ctor public DigitsKeyListener(); ctor public DigitsKeyListener(boolean, boolean); ctor public deprecated DigitsKeyListener(); ctor public deprecated DigitsKeyListener(boolean, boolean); ctor public DigitsKeyListener(java.util.Locale); ctor public DigitsKeyListener(java.util.Locale, boolean, boolean); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DigitsKeyListener getInstance(); method public static android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static deprecated android.text.method.DigitsKeyListener getInstance(); method public static deprecated android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale, boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.lang.String); } Loading Loading @@ -41190,11 +41198,13 @@ package android.text.method { } public class TimeKeyListener extends android.text.method.NumberKeyListener { ctor public TimeKeyListener(); ctor public deprecated TimeKeyListener(); ctor public TimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.TimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.TimeKeyListener getInstance(); method public static android.text.method.TimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class Touch {
api/system-current.txt +23 −13 Original line number Diff line number Diff line Loading @@ -44452,19 +44452,23 @@ package android.text.method { } public class DateKeyListener extends android.text.method.NumberKeyListener { ctor public DateKeyListener(); ctor public deprecated DateKeyListener(); ctor public DateKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateKeyListener getInstance(); method public static android.text.method.DateKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DateTimeKeyListener extends android.text.method.NumberKeyListener { ctor public DateTimeKeyListener(); ctor public deprecated DateTimeKeyListener(); ctor public DateTimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateTimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateTimeKeyListener getInstance(); method public static android.text.method.DateTimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DialerKeyListener extends android.text.method.NumberKeyListener { Loading @@ -44476,12 +44480,16 @@ package android.text.method { } public class DigitsKeyListener extends android.text.method.NumberKeyListener { ctor public DigitsKeyListener(); ctor public DigitsKeyListener(boolean, boolean); ctor public deprecated DigitsKeyListener(); ctor public deprecated DigitsKeyListener(boolean, boolean); ctor public DigitsKeyListener(java.util.Locale); ctor public DigitsKeyListener(java.util.Locale, boolean, boolean); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DigitsKeyListener getInstance(); method public static android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static deprecated android.text.method.DigitsKeyListener getInstance(); method public static deprecated android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale, boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.lang.String); } Loading Loading @@ -44625,11 +44633,13 @@ package android.text.method { } public class TimeKeyListener extends android.text.method.NumberKeyListener { ctor public TimeKeyListener(); ctor public deprecated TimeKeyListener(); ctor public TimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.TimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.TimeKeyListener getInstance(); method public static android.text.method.TimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class Touch {
api/test-current.txt +23 −13 Original line number Diff line number Diff line Loading @@ -41156,19 +41156,23 @@ package android.text.method { } public class DateKeyListener extends android.text.method.NumberKeyListener { ctor public DateKeyListener(); ctor public deprecated DateKeyListener(); ctor public DateKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateKeyListener getInstance(); method public static android.text.method.DateKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DateTimeKeyListener extends android.text.method.NumberKeyListener { ctor public DateTimeKeyListener(); ctor public deprecated DateTimeKeyListener(); ctor public DateTimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DateTimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.DateTimeKeyListener getInstance(); method public static android.text.method.DateTimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class DialerKeyListener extends android.text.method.NumberKeyListener { Loading @@ -41180,12 +41184,16 @@ package android.text.method { } public class DigitsKeyListener extends android.text.method.NumberKeyListener { ctor public DigitsKeyListener(); ctor public DigitsKeyListener(boolean, boolean); ctor public deprecated DigitsKeyListener(); ctor public deprecated DigitsKeyListener(boolean, boolean); ctor public DigitsKeyListener(java.util.Locale); ctor public DigitsKeyListener(java.util.Locale, boolean, boolean); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.DigitsKeyListener getInstance(); method public static android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static deprecated android.text.method.DigitsKeyListener getInstance(); method public static deprecated android.text.method.DigitsKeyListener getInstance(boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale); method public static android.text.method.DigitsKeyListener getInstance(java.util.Locale, boolean, boolean); method public static android.text.method.DigitsKeyListener getInstance(java.lang.String); } Loading Loading @@ -41329,11 +41337,13 @@ package android.text.method { } public class TimeKeyListener extends android.text.method.NumberKeyListener { ctor public TimeKeyListener(); ctor public deprecated TimeKeyListener(); ctor public TimeKeyListener(java.util.Locale); method protected char[] getAcceptedChars(); method public int getInputType(); method public static android.text.method.TimeKeyListener getInstance(); field public static final char[] CHARACTERS; method public static deprecated android.text.method.TimeKeyListener getInstance(); method public static android.text.method.TimeKeyListener getInstance(java.util.Locale); field public static final deprecated char[] CHARACTERS; } public class Touch {
core/java/android/text/method/DateKeyListener.java +64 −9 Original line number Diff line number Diff line Loading @@ -16,9 +16,17 @@ package android.text.method; import android.annotation.NonNull; import android.annotation.Nullable; import android.text.InputType; import android.view.KeyEvent; import com.android.internal.annotations.GuardedBy; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Locale; /** * For entering dates in a text field. * <p></p> Loading @@ -34,29 +42,76 @@ public class DateKeyListener extends NumberKeyListener } @Override protected char[] getAcceptedChars() { return CHARACTERS; @NonNull protected char[] getAcceptedChars() { return mCharacters; } /** * @deprecated Use {@link #DateKeyListener(Locale)} instead. */ @Deprecated public DateKeyListener() { this(null); } private static final String SYMBOLS_TO_IGNORE = "yMLd"; private static final String[] SKELETONS = {"yMd", "yM", "Md"}; public DateKeyListener(@Nullable Locale locale) { final LinkedHashSet<Character> chars = new LinkedHashSet<>(); // First add the digits, then add all the non-pattern characters seen in the pattern for // "yMd", which is supposed to only have numerical fields. final boolean success = NumberKeyListener.addDigits(chars, locale) && NumberKeyListener.addFormatCharsFromSkeletons( chars, locale, SKELETONS, SYMBOLS_TO_IGNORE); mCharacters = success ? NumberKeyListener.collectionToArray(chars) : CHARACTERS; } /** * @deprecated Use {@link #getInstance(Locale)} instead. */ @Deprecated @NonNull public static DateKeyListener getInstance() { if (sInstance != null) return sInstance; return getInstance(null); } sInstance = new DateKeyListener(); return sInstance; /** * Returns an instance of DateKeyListener appropriate for the given locale. */ @NonNull public static DateKeyListener getInstance(@Nullable Locale locale) { DateKeyListener instance; synchronized (sLock) { instance = sInstanceCache.get(locale); if (instance == null) { instance = new DateKeyListener(locale); sInstanceCache.put(locale, instance); } } return instance; } /** * The characters that are used. * This field used to list the characters that were used. But is now a fixed data * field that is the list of code units used for the deprecated case where the class * is instantiated with null or no input parameter. * * @see KeyEvent#getMatch * @see #getAcceptedChars * * @deprecated Use {@link #getAcceptedChars()} instead. */ @Deprecated public static final char[] CHARACTERS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '/', '-', '.' }; private static DateKeyListener sInstance; private final char[] mCharacters; private static final Object sLock = new Object(); @GuardedBy("sLock") private static final HashMap<Locale, DateKeyListener> sInstanceCache = new HashMap<>(); }
core/java/android/text/method/DateTimeKeyListener.java +66 −7 Original line number Diff line number Diff line Loading @@ -16,9 +16,17 @@ package android.text.method; import android.annotation.NonNull; import android.annotation.Nullable; import android.text.InputType; import android.view.KeyEvent; import com.android.internal.annotations.GuardedBy; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Locale; /** * For entering dates and times in the same text field. * <p></p> Loading @@ -34,29 +42,80 @@ public class DateTimeKeyListener extends NumberKeyListener } @Override @NonNull protected char[] getAcceptedChars() { return CHARACTERS; return mCharacters; } /** * @deprecated Use {@link #DateTimeKeyListener(Locale)} instead. */ @Deprecated public DateTimeKeyListener() { this(null); } private static final String SYMBOLS_TO_IGNORE = "yMLdahHKkms"; private static final String SKELETON_12HOUR = "yMdhms"; private static final String SKELETON_24HOUR = "yMdHms"; public DateTimeKeyListener(@Nullable Locale locale) { final LinkedHashSet<Character> 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) && NumberKeyListener.addAmPmChars(chars, locale) && NumberKeyListener.addFormatCharsFromSkeleton( chars, locale, SKELETON_12HOUR, SYMBOLS_TO_IGNORE) && NumberKeyListener.addFormatCharsFromSkeleton( chars, locale, SKELETON_24HOUR, SYMBOLS_TO_IGNORE); mCharacters = success ? NumberKeyListener.collectionToArray(chars) : CHARACTERS; } /** * @deprecated Use {@link #getInstance(Locale)} instead. */ @Deprecated @NonNull public static DateTimeKeyListener getInstance() { if (sInstance != null) return sInstance; return getInstance(null); } sInstance = new DateTimeKeyListener(); return sInstance; /** * Returns an instance of DateTimeKeyListener appropriate for the given locale. */ @NonNull public static DateTimeKeyListener getInstance(@Nullable Locale locale) { DateTimeKeyListener instance; synchronized (sLock) { instance = sInstanceCache.get(locale); if (instance == null) { instance = new DateTimeKeyListener(locale); sInstanceCache.put(locale, instance); } } return instance; } /** * The characters that are used. * This field used to list the characters that were used. But is now a fixed data * field that is the list of code units used for the deprecated case where the class * is instantiated with null or no input parameter. * * @see KeyEvent#getMatch * @see #getAcceptedChars * * @deprecated Use {@link #getAcceptedChars()} instead. */ public static final char[] CHARACTERS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'm', 'p', ':', '/', '-', ' ' }; private static DateTimeKeyListener sInstance; private final char[] mCharacters; private static final Object sLock = new Object(); @GuardedBy("sLock") private static final HashMap<Locale, DateTimeKeyListener> sInstanceCache = new HashMap<>(); }