diff --git a/lib/java/com/google/android/material/timepicker/TimePickerClockPresenter.java b/lib/java/com/google/android/material/timepicker/TimePickerClockPresenter.java index f524fa184be..3a61aabd836 100644 --- a/lib/java/com/google/android/material/timepicker/TimePickerClockPresenter.java +++ b/lib/java/com/google/android/material/timepicker/TimePickerClockPresenter.java @@ -30,6 +30,7 @@ import android.os.Build.VERSION_CODES; import android.view.View; import android.view.accessibility.AccessibilityManager; +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import com.google.android.material.timepicker.ClockHandView.OnActionUpListener; import com.google.android.material.timepicker.ClockHandView.OnRotateListener; import com.google.android.material.timepicker.TimePickerControls.ActiveSelection; @@ -56,8 +57,8 @@ class TimePickerClockPresenter private static final int DEGREES_PER_HOUR = 30; private static final int DEGREES_PER_MINUTE = 6; - private TimePickerView timePickerView; - private TimeModel time; + private final TimePickerView timePickerView; + private final TimeModel time; private float minuteRotation; private float hourRotation; @@ -164,9 +165,28 @@ void setSelection(@ActiveSelection int selection, boolean animate) { timePickerView.setHandRotation(isMinute ? minuteRotation : hourRotation, animate); timePickerView.setActiveSelection(selection); timePickerView.setMinuteHourDelegate( - new ClickActionDelegate(timePickerView.getContext(), R.string.material_hour_selection)); + new ClickActionDelegate(timePickerView.getContext(), R.string.material_hour_selection) { + @Override + public void onInitializeAccessibilityNodeInfo( + View host, AccessibilityNodeInfoCompat info) { + super.onInitializeAccessibilityNodeInfo(host, info); + info.setContentDescription( + host.getResources() + .getString( + R.string.material_hour_suffix, String.valueOf(time.getHourForDisplay()))); + } + }); timePickerView.setHourClickDelegate( - new ClickActionDelegate(timePickerView.getContext(), R.string.material_minute_selection)); + new ClickActionDelegate(timePickerView.getContext(), R.string.material_minute_selection) { + @Override + public void onInitializeAccessibilityNodeInfo( + View host, AccessibilityNodeInfoCompat info) { + super.onInitializeAccessibilityNodeInfo(host, info); + info.setContentDescription( + host.getResources() + .getString(R.string.material_minute_suffix, String.valueOf(time.minute))); + } + }); } @Override @@ -182,7 +202,7 @@ public void onActionUp(float rotation, boolean moveInEventStream) { AccessibilityManager am = getSystemService(timePickerView.getContext(), AccessibilityManager.class); - boolean isExploreByTouchEnabled = am.isTouchExplorationEnabled(); + boolean isExploreByTouchEnabled = am != null && am.isTouchExplorationEnabled(); if (!isExploreByTouchEnabled) { setSelection(MINUTE, /* animate= */ true); } diff --git a/lib/java/com/google/android/material/timepicker/TimePickerTextInputPresenter.java b/lib/java/com/google/android/material/timepicker/TimePickerTextInputPresenter.java index fd7b2af3d1e..588701d858e 100644 --- a/lib/java/com/google/android/material/timepicker/TimePickerTextInputPresenter.java +++ b/lib/java/com/google/android/material/timepicker/TimePickerTextInputPresenter.java @@ -43,6 +43,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.ColorInt; +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import com.google.android.material.button.MaterialButtonToggleGroup; import com.google.android.material.button.MaterialButtonToggleGroup.OnButtonCheckedListener; import com.google.android.material.color.MaterialColors; @@ -95,7 +96,7 @@ public void afterTextChanged(Editable s) { private final EditText minuteEditText; private MaterialButtonToggleGroup toggle; - public TimePickerTextInputPresenter(LinearLayout timePickerView, TimeModel time) { + public TimePickerTextInputPresenter(final LinearLayout timePickerView, final TimeModel time) { this.timePickerView = timePickerView; this.time = time; Resources res = timePickerView.getResources(); @@ -137,9 +138,28 @@ public void onClick(View v) { controller = new TimePickerTextInputKeyController(hourTextInput, minuteTextInput, time); hourTextInput.setChipDelegate( - new ClickActionDelegate(timePickerView.getContext(), R.string.material_hour_selection)); + new ClickActionDelegate(timePickerView.getContext(), R.string.material_hour_selection) { + @Override + public void onInitializeAccessibilityNodeInfo( + View host, AccessibilityNodeInfoCompat info) { + super.onInitializeAccessibilityNodeInfo(host, info); + info.setContentDescription( + host.getResources() + .getString( + R.string.material_hour_suffix, String.valueOf(time.getHourForDisplay()))); + } + }); minuteTextInput.setChipDelegate( - new ClickActionDelegate(timePickerView.getContext(), R.string.material_minute_selection)); + new ClickActionDelegate(timePickerView.getContext(), R.string.material_minute_selection) { + @Override + public void onInitializeAccessibilityNodeInfo( + View host, AccessibilityNodeInfoCompat info) { + super.onInitializeAccessibilityNodeInfo(host, info); + info.setContentDescription( + host.getResources() + .getString(R.string.material_minute_suffix, String.valueOf(time.minute))); + } + }); initialize(); }