3030import android .os .Build .VERSION_CODES ;
3131import android .view .View ;
3232import android .view .accessibility .AccessibilityManager ;
33+ import androidx .core .view .accessibility .AccessibilityNodeInfoCompat ;
3334import com .google .android .material .timepicker .ClockHandView .OnActionUpListener ;
3435import com .google .android .material .timepicker .ClockHandView .OnRotateListener ;
3536import com .google .android .material .timepicker .TimePickerControls .ActiveSelection ;
@@ -56,8 +57,8 @@ class TimePickerClockPresenter
5657 private static final int DEGREES_PER_HOUR = 30 ;
5758 private static final int DEGREES_PER_MINUTE = 6 ;
5859
59- private TimePickerView timePickerView ;
60- private TimeModel time ;
60+ private final TimePickerView timePickerView ;
61+ private final TimeModel time ;
6162 private float minuteRotation ;
6263 private float hourRotation ;
6364
@@ -164,9 +165,28 @@ void setSelection(@ActiveSelection int selection, boolean animate) {
164165 timePickerView .setHandRotation (isMinute ? minuteRotation : hourRotation , animate );
165166 timePickerView .setActiveSelection (selection );
166167 timePickerView .setMinuteHourDelegate (
167- new ClickActionDelegate (timePickerView .getContext (), R .string .material_hour_selection ));
168+ new ClickActionDelegate (timePickerView .getContext (), R .string .material_hour_selection ) {
169+ @ Override
170+ public void onInitializeAccessibilityNodeInfo (
171+ View host , AccessibilityNodeInfoCompat info ) {
172+ super .onInitializeAccessibilityNodeInfo (host , info );
173+ info .setContentDescription (
174+ host .getResources ()
175+ .getString (
176+ R .string .material_hour_suffix , String .valueOf (time .getHourForDisplay ())));
177+ }
178+ });
168179 timePickerView .setHourClickDelegate (
169- new ClickActionDelegate (timePickerView .getContext (), R .string .material_minute_selection ));
180+ new ClickActionDelegate (timePickerView .getContext (), R .string .material_minute_selection ) {
181+ @ Override
182+ public void onInitializeAccessibilityNodeInfo (
183+ View host , AccessibilityNodeInfoCompat info ) {
184+ super .onInitializeAccessibilityNodeInfo (host , info );
185+ info .setContentDescription (
186+ host .getResources ()
187+ .getString (R .string .material_minute_suffix , String .valueOf (time .minute )));
188+ }
189+ });
170190 }
171191
172192 @ Override
@@ -182,7 +202,7 @@ public void onActionUp(float rotation, boolean moveInEventStream) {
182202
183203 AccessibilityManager am =
184204 getSystemService (timePickerView .getContext (), AccessibilityManager .class );
185- boolean isExploreByTouchEnabled = am .isTouchExplorationEnabled ();
205+ boolean isExploreByTouchEnabled = am != null && am .isTouchExplorationEnabled ();
186206 if (!isExploreByTouchEnabled ) {
187207 setSelection (MINUTE , /* animate= */ true );
188208 }
0 commit comments