Merge "Improve time picker accessibility" into lmp-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ff44188309
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user