am dd508581: Use min when comparing AM and PM text lengths
* commit 'dd508581216ef3ef47bd474316232f269db43f03': Use min when comparing AM and PM text lengths
This commit is contained in:
@@ -1051,15 +1051,16 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
|
|||||||
// Cache the codes.
|
// Cache the codes.
|
||||||
if (mAmKeyCode == -1 || mPmKeyCode == -1) {
|
if (mAmKeyCode == -1 || mPmKeyCode == -1) {
|
||||||
// Find the first character in the AM/PM text that is unique.
|
// Find the first character in the AM/PM text that is unique.
|
||||||
KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
|
final KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
|
||||||
char amChar;
|
final CharSequence amText = mAmText.toLowerCase(mCurrentLocale);
|
||||||
char pmChar;
|
final CharSequence pmText = mPmText.toLowerCase(mCurrentLocale);
|
||||||
for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
|
final int N = Math.min(amText.length(), pmText.length());
|
||||||
amChar = mAmText.toLowerCase(mCurrentLocale).charAt(i);
|
for (int i = 0; i < N; i++) {
|
||||||
pmChar = mPmText.toLowerCase(mCurrentLocale).charAt(i);
|
final char amChar = amText.charAt(i);
|
||||||
|
final char pmChar = pmText.charAt(i);
|
||||||
if (amChar != pmChar) {
|
if (amChar != pmChar) {
|
||||||
KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
|
|
||||||
// There should be 4 events: a down and up for both AM and PM.
|
// There should be 4 events: a down and up for both AM and PM.
|
||||||
|
final KeyEvent[] events = kcm.getEvents(new char[] { amChar, pmChar });
|
||||||
if (events != null && events.length == 4) {
|
if (events != null && events.length == 4) {
|
||||||
mAmKeyCode = events[0].getKeyCode();
|
mAmKeyCode = events[0].getKeyCode();
|
||||||
mPmKeyCode = events[2].getKeyCode();
|
mPmKeyCode = events[2].getKeyCode();
|
||||||
@@ -1070,6 +1071,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amOrPm == AM) {
|
if (amOrPm == AM) {
|
||||||
return mAmKeyCode;
|
return mAmKeyCode;
|
||||||
} else if (amOrPm == PM) {
|
} else if (amOrPm == PM) {
|
||||||
|
|||||||
Reference in New Issue
Block a user