diff options
author | Sam Blitzstein <sblitz@google.com> | 2013-05-03 19:34:35 -0700 |
---|---|---|
committer | Sam Blitzstein <sblitz@google.com> | 2013-05-03 19:34:35 -0700 |
commit | c9d330f99ce1f2a58012fe1c4f12bdad544ede52 (patch) | |
tree | 9c4b1d35782f2a1160eaf17cc697b3d2486bd02a /src | |
parent | 59dc99f53e92d0a25b43c5eebf1a1e16c6985706 (diff) | |
download | datetimepicker-c9d330f99ce1f2a58012fe1c4f12bdad544ede52.tar.gz |
Improve accessibility for hardware keyboard mode.
Like a normal edittext, speak out each key as its typed.
Bug: 8590343
Change-Id: I52ff588aad5714d751a008e9d7c0574709a0c7e5
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/datetimepicker/time/TimePickerDialog.java | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/com/android/datetimepicker/time/TimePickerDialog.java b/src/com/android/datetimepicker/time/TimePickerDialog.java index 2a385f7..d5db83b 100644 --- a/src/com/android/datetimepicker/time/TimePickerDialog.java +++ b/src/com/android/datetimepicker/time/TimePickerDialog.java @@ -91,6 +91,7 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL // For hardware IME input. private char mPlaceholderText; private String mDoublePlaceholderText; + private String mDeletedKeyFormat; private boolean mInKbMode; private ArrayList<Integer> mTypedTimes; private Node mLegalTimesTree; @@ -275,6 +276,7 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); + mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); @@ -441,7 +443,17 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL } else if (keyCode == KeyEvent.KEYCODE_DEL) { if (mInKbMode) { if (!mTypedTimes.isEmpty()) { - deleteLastTypedKey(); + int deleted = deleteLastTypedKey(); + String deletedKeyStr; + if (deleted == getAmOrPmKeyCode(AM)) { + deletedKeyStr = mAmText; + } else if (deleted == getAmOrPmKeyCode(PM)) { + deletedKeyStr = mPmText; + } else { + deletedKeyStr = String.format("%d", getValFromKeyCode(deleted)); + } + Utils.tryAccessibilityAnnounce(mTimePicker, + String.format(mDeletedKeyFormat, deletedKeyStr)); updateDisplay(true); } } @@ -501,6 +513,8 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL return false; } + int val = getValFromKeyCode(keyCode); + Utils.tryAccessibilityAnnounce(mTimePicker, String.format("%d", val)); // Automatically fill in 0's if AM or PM was legally entered. if (isTypedTimeFullyLegal()) { if (!mIs24HourMode && mTypedTimes.size() <= 3) { @@ -545,11 +559,12 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL } } - private void deleteLastTypedKey() { - mTypedTimes.remove(mTypedTimes.size() - 1); + private int deleteLastTypedKey() { + int deleted = mTypedTimes.remove(mTypedTimes.size() - 1); if (!isTypedTimeFullyLegal()) { mDoneButton.setEnabled(false); } + return deleted; } /** @@ -600,8 +615,10 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL String minuteStr = (values[1] == -1)? mDoublePlaceholderText : String.format(minuteFormat, values[1]).replace(' ', mPlaceholderText); mHourView.setText(hourStr); + mHourSpaceView.setText(hourStr); mHourView.setTextColor(mBlack); mMinuteView.setText(minuteStr); + mMinuteSpaceView.setText(minuteStr); mMinuteView.setTextColor(mBlack); if (!mIs24HourMode) { updateAmPmDisplay(values[2]); |