diff options
author | Alan Viverette <alanv@google.com> | 2014-12-10 09:46:49 -0800 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-12-10 09:46:49 -0800 |
commit | 3fc00e3139706c2c90f8e7261eef48086887dc11 (patch) | |
tree | 3d03767f6fd8075be21adda84c6746e6933eeb64 /core | |
parent | 0aac16bbf1fd122302f8e58b7d4d5ee9d6afebc5 (diff) | |
download | frameworks_base-3fc00e3139706c2c90f8e7261eef48086887dc11.zip frameworks_base-3fc00e3139706c2c90f8e7261eef48086887dc11.tar.gz frameworks_base-3fc00e3139706c2c90f8e7261eef48086887dc11.tar.bz2 |
Improve time picker accessibility
Overrides click action description for TimePicker hour/minute selectors
and manually specifies traversal order for radial time picker nodes.
BUG: 17468036
Change-Id: I4472b42a95d762085d7a4d382feb2b9216c0d41c
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/RadialTimePickerView.java | 26 | ||||
-rw-r--r-- | core/java/android/widget/TimePickerClockDelegate.java | 22 |
2 files changed, 48 insertions, 0 deletions
diff --git a/core/java/android/widget/RadialTimePickerView.java b/core/java/android/widget/RadialTimePickerView.java index 75c6184..7b64cf5 100644 --- a/core/java/android/widget/RadialTimePickerView.java +++ b/core/java/android/widget/RadialTimePickerView.java @@ -1456,6 +1456,32 @@ public class RadialTimePickerView extends View implements View.OnTouchListener { final boolean selected = isVirtualViewSelected(type, value); node.setSelected(selected); + + final int nextId = getVirtualViewIdAfter(type, value); + if (nextId != INVALID_ID) { + node.setTraversalBefore(RadialTimePickerView.this, nextId); + } + } + + private int getVirtualViewIdAfter(int type, int value) { + if (type == TYPE_HOUR) { + final int nextValue = value + 1; + final int max = mIs24HourMode ? 23 : 12; + if (nextValue <= max) { + return makeId(type, nextValue); + } + } else if (type == TYPE_MINUTE) { + final int current = getCurrentMinute(); + final int snapValue = value - (value % MINUTE_INCREMENT); + final int nextValue = snapValue + MINUTE_INCREMENT; + if (value < current && nextValue > current) { + // The current value is between two snap values. + return makeId(type, current); + } else if (nextValue < 60) { + return makeId(type, nextValue); + } + } + return INVALID_ID; } @Override diff --git a/core/java/android/widget/TimePickerClockDelegate.java b/core/java/android/widget/TimePickerClockDelegate.java index d61b6fc..8d475a7 100644 --- a/core/java/android/widget/TimePickerClockDelegate.java +++ b/core/java/android/widget/TimePickerClockDelegate.java @@ -33,9 +33,11 @@ import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; +import android.view.View.AccessibilityDelegate; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; +import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; import com.android.internal.R; @@ -136,9 +138,13 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl // Set up hour/minute labels. mHourView = (TextView) mHeaderView.findViewById(R.id.hours); mHourView.setOnClickListener(mClickListener); + mHourView.setAccessibilityDelegate( + new ClickActionDelegate(context, R.string.select_hours)); mSeparatorView = (TextView) mHeaderView.findViewById(R.id.separator); mMinuteView = (TextView) mHeaderView.findViewById(R.id.minutes); mMinuteView.setOnClickListener(mClickListener); + mMinuteView.setAccessibilityDelegate( + new ClickActionDelegate(context, R.string.select_minutes)); final int headerTimeTextAppearance = a.getResourceId( R.styleable.TimePicker_headerTimeTextAppearance, 0); @@ -206,6 +212,22 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX); } + private static class ClickActionDelegate extends AccessibilityDelegate { + private final AccessibilityAction mClickAction; + + public ClickActionDelegate(Context context, int resId) { + mClickAction = new AccessibilityAction( + AccessibilityNodeInfo.ACTION_CLICK, context.getString(resId)); + } + + @Override + public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(host, info); + + info.addAction(mClickAction); + } + } + private int computeStableWidth(TextView v, int maxNumber) { int maxWidth = 0; |