Merge "Polish of the accessibility feedback of Date and Time pickers"

This commit is contained in:
Svetoslav Ganov
2011-09-01 18:14:38 -07:00
committed by Android (Google) Code Review
4 changed files with 124 additions and 10 deletions

View File

@@ -30,6 +30,7 @@ import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.widget.NumberPicker.OnValueChangeListener; import android.widget.NumberPicker.OnValueChangeListener;
import com.android.internal.R; import com.android.internal.R;
@@ -264,6 +265,11 @@ public class DatePicker extends FrameLayout {
// re-order the number spinners to match the current date format // re-order the number spinners to match the current date format
reorderSpinners(); reorderSpinners();
// set content descriptions
if (AccessibilityManager.getInstance(mContext).isEnabled()) {
setContentDescriptions();
}
} }
/** /**
@@ -356,12 +362,17 @@ public class DatePicker extends FrameLayout {
return mIsEnabled; return mIsEnabled;
} }
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
onPopulateAccessibilityEvent(event);
return true;
}
@Override @Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) { public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(event); super.onPopulateAccessibilityEvent(event);
final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
| DateUtils.FORMAT_SHOW_YEAR;
String selectedDateUtterance = DateUtils.formatDateTime(mContext, String selectedDateUtterance = DateUtils.formatDateTime(mContext,
mCurrentDate.getTimeInMillis(), flags); mCurrentDate.getTimeInMillis(), flags);
event.getText().add(selectedDateUtterance); event.getText().add(selectedDateUtterance);
@@ -709,5 +720,22 @@ public class DatePicker extends FrameLayout {
} }
}; };
} }
}
private void setContentDescriptions() {
// Day
String text = mContext.getString(R.string.date_picker_increment_day_button);
mDaySpinner.findViewById(R.id.increment).setContentDescription(text);
text = mContext.getString(R.string.date_picker_decrement_day_button);
mDaySpinner.findViewById(R.id.decrement).setContentDescription(text);
// Month
text = mContext.getString(R.string.date_picker_increment_month_button);
mMonthSpinner.findViewById(R.id.increment).setContentDescription(text);
text = mContext.getString(R.string.date_picker_decrement_month_button);
mMonthSpinner.findViewById(R.id.decrement).setContentDescription(text);
// Year
text = mContext.getString(R.string.date_picker_increment_year_button);
mYearSpinner.findViewById(R.id.increment).setContentDescription(text);
text = mContext.getString(R.string.date_picker_decrement_year_button);
mYearSpinner.findViewById(R.id.decrement).setContentDescription(text);
}
}

View File

@@ -33,6 +33,7 @@ import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Paint.Align; import android.graphics.Paint.Align;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.SystemClock;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.InputType; import android.text.InputType;
import android.text.Spanned; import android.text.Spanned;
@@ -48,6 +49,8 @@ import android.view.VelocityTracker;
import android.view.View; import android.view.View;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;
import android.view.LayoutInflater.Filter; import android.view.LayoutInflater.Filter;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.DecelerateInterpolator; import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@@ -471,7 +474,7 @@ public class NumberPicker extends LinearLayout {
// the fading edge effect implemented by View and we need our // the fading edge effect implemented by View and we need our
// draw() method to be called. Therefore, we declare we will draw. // draw() method to be called. Therefore, we declare we will draw.
setWillNotDraw(false); setWillNotDraw(false);
setDrawSelectorWheel(false); setDrawScrollWheel(false);
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE); Context.LAYOUT_INFLATER_SERVICE);
@@ -561,7 +564,7 @@ public class NumberPicker extends LinearLayout {
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
if (!mCanceled) { if (!mCanceled) {
// if canceled => we still want the wheel drawn // if canceled => we still want the wheel drawn
setDrawSelectorWheel(false); setDrawScrollWheel(false);
} }
mCanceled = false; mCanceled = false;
mSelectorPaint.setAlpha(255); mSelectorPaint.setAlpha(255);
@@ -587,7 +590,7 @@ public class NumberPicker extends LinearLayout {
// Start with shown selector wheel and hidden controls. When made // Start with shown selector wheel and hidden controls. When made
// visible hide the selector and fade-in the controls to suggest // visible hide the selector and fade-in the controls to suggest
// fling interaction. // fling interaction.
setDrawSelectorWheel(true); setDrawScrollWheel(true);
hideInputControls(); hideInputControls();
} }
} }
@@ -630,7 +633,7 @@ public class NumberPicker extends LinearLayout {
|| (!mDecrementButton.isShown() || (!mDecrementButton.isShown()
&& isEventInViewHitRect(event, mDecrementButton))) { && isEventInViewHitRect(event, mDecrementButton))) {
mAdjustScrollerOnUpEvent = false; mAdjustScrollerOnUpEvent = false;
setDrawSelectorWheel(true); setDrawScrollWheel(true);
hideInputControls(); hideInputControls();
return true; return true;
} }
@@ -641,7 +644,7 @@ public class NumberPicker extends LinearLayout {
if (deltaDownY > mTouchSlop) { if (deltaDownY > mTouchSlop) {
mBeginEditOnUpEvent = false; mBeginEditOnUpEvent = false;
onScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); onScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
setDrawSelectorWheel(true); setDrawScrollWheel(true);
hideInputControls(); hideInputControls();
return true; return true;
} }
@@ -678,7 +681,7 @@ public class NumberPicker extends LinearLayout {
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
if (mBeginEditOnUpEvent) { if (mBeginEditOnUpEvent) {
setDrawSelectorWheel(false); setDrawScrollWheel(false);
showInputControls(mShowInputControlsAnimimationDuration); showInputControls(mShowInputControlsAnimimationDuration);
mInputText.requestFocus(); mInputText.requestFocus();
InputMethodManager imm = (InputMethodManager) getContext().getSystemService( InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
@@ -1135,6 +1138,12 @@ public class NumberPicker extends LinearLayout {
} }
} }
@Override
public void sendAccessibilityEvent(int eventType) {
// Do not send accessibility events - we want the user to
// perceive this widget as several controls rather as a whole.
}
/** /**
* Resets the selector indices and clear the cached * Resets the selector indices and clear the cached
* string representation of these indices. * string representation of these indices.
@@ -1192,10 +1201,19 @@ public class NumberPicker extends LinearLayout {
/** /**
* Sets if to <code>drawSelectionWheel</code>. * Sets if to <code>drawSelectionWheel</code>.
*/ */
private void setDrawSelectorWheel(boolean drawSelectorWheel) { private void setDrawScrollWheel(boolean drawSelectorWheel) {
mDrawSelectorWheel = drawSelectorWheel; mDrawSelectorWheel = drawSelectorWheel;
// do not fade if the selector wheel not shown // do not fade if the selector wheel not shown
setVerticalFadingEdgeEnabled(drawSelectorWheel); setVerticalFadingEdgeEnabled(drawSelectorWheel);
if (mFlingable && mDrawSelectorWheel
&& AccessibilityManager.getInstance(mContext).isEnabled()) {
AccessibilityManager.getInstance(mContext).interrupt();
String text = mContext.getString(R.string.number_picker_increment_scroll_action);
mInputText.setContentDescription(text);
mInputText.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
mInputText.setContentDescription(null);
}
} }
private void initializeScrollWheel() { private void initializeScrollWheel() {
@@ -1429,6 +1447,12 @@ public class NumberPicker extends LinearLayout {
mInputText.setText(mDisplayedValues[mValue - mMinValue]); mInputText.setText(mDisplayedValues[mValue - mMinValue]);
} }
mInputText.setSelection(mInputText.getText().length()); mInputText.setSelection(mInputText.getText().length());
if (mFlingable && AccessibilityManager.getInstance(mContext).isEnabled()) {
String text = mContext.getString(R.string.number_picker_increment_scroll_mode,
mInputText.getText());
mInputText.setContentDescription(text);
}
} }
/** /**

View File

@@ -29,6 +29,7 @@ import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.widget.NumberPicker.OnValueChangeListener; import android.widget.NumberPicker.OnValueChangeListener;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
@@ -227,6 +228,11 @@ public class TimePicker extends FrameLayout {
if (!isEnabled()) { if (!isEnabled()) {
setEnabled(false); setEnabled(false);
} }
// set the content descriptions
if (AccessibilityManager.getInstance(mContext).isEnabled()) {
setContentDescriptions();
}
} }
@Override @Override
@@ -432,6 +438,12 @@ public class TimePicker extends FrameLayout {
return mHourSpinner.getBaseline(); return mHourSpinner.getBaseline();
} }
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
onPopulateAccessibilityEvent(event);
return true;
}
@Override @Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) { public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(event); super.onPopulateAccessibilityEvent(event);
@@ -487,4 +499,22 @@ public class TimePicker extends FrameLayout {
mOnTimeChangedListener.onTimeChanged(this, getCurrentHour(), getCurrentMinute()); mOnTimeChangedListener.onTimeChanged(this, getCurrentHour(), getCurrentMinute());
} }
} }
private void setContentDescriptions() {
// Minute
String text = mContext.getString(R.string.time_picker_increment_minute_button);
mMinuteSpinner.findViewById(R.id.increment).setContentDescription(text);
text = mContext.getString(R.string.time_picker_decrement_minute_button);
mMinuteSpinner.findViewById(R.id.decrement).setContentDescription(text);
// Hour
text = mContext.getString(R.string.time_picker_increment_hour_button);
mHourSpinner.findViewById(R.id.increment).setContentDescription(text);
text = mContext.getString(R.string.time_picker_decrement_hour_button);
mHourSpinner.findViewById(R.id.decrement).setContentDescription(text);
// AM/PM
text = mContext.getString(R.string.time_picker_increment_set_pm_button);
mAmPmSpinner.findViewById(R.id.increment).setContentDescription(text);
text = mContext.getString(R.string.time_picker_decrement_set_am_button);
mAmPmSpinner.findViewById(R.id.decrement).setContentDescription(text);
}
} }

View File

@@ -3091,6 +3091,38 @@
<string name="number_picker_increment_button">Increment</string> <string name="number_picker_increment_button">Increment</string>
<!-- Description of the button to decrement the NumberPicker value. [CHAR LIMIT=NONE] --> <!-- Description of the button to decrement the NumberPicker value. [CHAR LIMIT=NONE] -->
<string name="number_picker_decrement_button">Decrement</string> <string name="number_picker_decrement_button">Decrement</string>
<!-- Description of the tap and hold action to get into scroll mode in NumberPicker. [CHAR LIMIT=NONE] -->
<string name="number_picker_increment_scroll_mode"><xliff:g id="value" example="3">%s</xliff:g> tap and hold.</string>
<!-- Description of the scrolling action in NumberPicker. [CHAR LIMIT=NONE] -->
<string name="number_picker_increment_scroll_action">Slide up to increment and down to decrement.</string>
<!-- TimePicker - accessibility support -->
<!-- Description of the button to increment the TimePicker's minute value. [CHAR LIMIT=NONE] -->
<string name="time_picker_increment_minute_button">Increment minute</string>
<!-- Description of the button to decrement the TimePicker's minute value. [CHAR LIMIT=NONE] -->
<string name="time_picker_decrement_minute_button">Decrement minute</string>
<!-- Description of the button to increment the TimePicker's hour value. [CHAR LIMIT=NONE] -->
<string name="time_picker_increment_hour_button">Increment hour</string>
<!-- Description of the button to decrement the TimePicker's hour value. [CHAR LIMIT=NONE] -->
<string name="time_picker_decrement_hour_button">Decrement hour</string>
<!-- Description of the button to increment the TimePicker's set PM value. [CHAR LIMIT=NONE] -->
<string name="time_picker_increment_set_pm_button">Set PM</string>
<!-- Description of the button to decrement the TimePicker's set AM value. [CHAR LIMIT=NONE] -->
<string name="time_picker_decrement_set_am_button">Set AM</string>
<!-- DatePicker - accessibility support -->
<!-- Description of the button to increment the DatePicker's month value. [CHAR LIMIT=NONE] -->
<string name="date_picker_increment_month_button">Increment month</string>
<!-- Description of the button to decrement the DatePicker's month value. [CHAR LIMIT=NONE] -->
<string name="date_picker_decrement_month_button">Decrement month</string>
<!-- Description of the button to increment the DatePicker's day value. [CHAR LIMIT=NONE] -->
<string name="date_picker_increment_day_button">Increment day</string>
<!-- Description of the button to decrement the DatePicker's day value. [CHAR LIMIT=NONE] -->
<string name="date_picker_decrement_day_button">Decrement day</string>
<!-- Description of the button to increment the DatePicker's year value. [CHAR LIMIT=NONE] -->
<string name="date_picker_increment_year_button">Increment year</string>
<!-- Description of the button to decrement the DatePicker's year value. [CHAR LIMIT=NONE] -->
<string name="date_picker_decrement_year_button">Decrement year</string>
<!-- CheckBox - accessibility support --> <!-- CheckBox - accessibility support -->
<!-- Description of the checked state of a CheckBox. [CHAR LIMIT=NONE] --> <!-- Description of the checked state of a CheckBox. [CHAR LIMIT=NONE] -->