diff options
author | Alan Viverette <alanv@google.com> | 2015-01-05 11:28:12 -0800 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2015-01-05 11:28:12 -0800 |
commit | dd508581216ef3ef47bd474316232f269db43f03 (patch) | |
tree | 9437cf8e67e20a85f29621e9062fb43a35eeb24f /core/java | |
parent | 4ae97d3632edf4fd00fe23b9a2304e4e0f2348b7 (diff) | |
download | frameworks_base-dd508581216ef3ef47bd474316232f269db43f03.zip frameworks_base-dd508581216ef3ef47bd474316232f269db43f03.tar.gz frameworks_base-dd508581216ef3ef47bd474316232f269db43f03.tar.bz2 |
Use min when comparing AM and PM text lengths
Also cleans up code a little to prevent unnecessary re-computation
of lower-cased strings and use final where possible.
BUG: 18874813
Change-Id: I852eb7a281aed64ac36e95f32f5fa410f50abfa4
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/widget/TimePickerClockDelegate.java | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/core/java/android/widget/TimePickerClockDelegate.java b/core/java/android/widget/TimePickerClockDelegate.java index 8d475a7..b70595a 100644 --- a/core/java/android/widget/TimePickerClockDelegate.java +++ b/core/java/android/widget/TimePickerClockDelegate.java @@ -1051,15 +1051,16 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl // Cache the codes. if (mAmKeyCode == -1 || mPmKeyCode == -1) { // Find the first character in the AM/PM text that is unique. - KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); - char amChar; - char pmChar; - for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) { - amChar = mAmText.toLowerCase(mCurrentLocale).charAt(i); - pmChar = mPmText.toLowerCase(mCurrentLocale).charAt(i); + final KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); + final CharSequence amText = mAmText.toLowerCase(mCurrentLocale); + final CharSequence pmText = mPmText.toLowerCase(mCurrentLocale); + final int N = Math.min(amText.length(), pmText.length()); + for (int i = 0; i < N; i++) { + final char amChar = amText.charAt(i); + final char pmChar = pmText.charAt(i); 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. + final KeyEvent[] events = kcm.getEvents(new char[] { amChar, pmChar }); if (events != null && events.length == 4) { mAmKeyCode = events[0].getKeyCode(); mPmKeyCode = events[2].getKeyCode(); @@ -1070,6 +1071,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl } } } + if (amOrPm == AM) { return mAmKeyCode; } else if (amOrPm == PM) { |