Skip to content

Commit

Permalink
[A11y][Time Picker] Adjust talkback to include "minute" and "hour" fo…
Browse files Browse the repository at this point in the history
…r text input fields.

PiperOrigin-RevId: 676884936
  • Loading branch information
kendrickumstattd authored and dsn5ft committed Sep 20, 2024
1 parent b77824f commit 20ee1ed
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -95,7 +96,11 @@ public TimePickerTextInputPresenter(final LinearLayout timePickerView, final Tim
TextView hourLabel = hourTextInput.findViewById(R.id.material_label);

minuteLabel.setText(res.getString(R.string.material_timepicker_minute));
minuteLabel.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);

hourLabel.setText(res.getString(R.string.material_timepicker_hour));
hourLabel.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);

minuteTextInput.setTag(R.id.selection_type, MINUTE);
hourTextInput.setTag(R.id.selection_type, HOUR);

Expand All @@ -117,7 +122,13 @@ public void onClick(View v) {
minuteTextInput.addInputFilter(time.getMinuteInputValidator());

hourEditText = hourTextInput.getTextInput().getEditText();
hourEditText.setAccessibilityDelegate(
setTimeUnitAccessiblityLabel(
timePickerView.getResources(), R.string.material_timepicker_hour));
minuteEditText = minuteTextInput.getTextInput().getEditText();
minuteEditText.setAccessibilityDelegate(
setTimeUnitAccessiblityLabel(
timePickerView.getResources(), R.string.material_timepicker_minute));

controller = new TimePickerTextInputKeyController(hourTextInput, minuteTextInput, time);
hourTextInput.setChipDelegate(
Expand Down Expand Up @@ -148,6 +159,17 @@ public void onInitializeAccessibilityNodeInfo(
initialize();
}

private View.AccessibilityDelegate setTimeUnitAccessiblityLabel(
Resources res, int contentDescriptionResId) {
return new View.AccessibilityDelegate() {
@Override
public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(v, info);
info.setText(res.getString(contentDescriptionResId));
}
};
}

@Override
public void initialize() {
addTextWatchers();
Expand Down

0 comments on commit 20ee1ed

Please sign in to comment.