3333import android .view .View ;
3434import android .view .View .OnClickListener ;
3535import android .view .ViewGroup ;
36+ import android .view .accessibility .AccessibilityEvent ;
37+ import android .view .accessibility .AccessibilityManager ;
3638import android .widget .GridView ;
3739import androidx .annotation .NonNull ;
3840import androidx .annotation .Nullable ;
@@ -92,6 +94,8 @@ enum CalendarSelector {
9294 private View monthNext ;
9395 private View yearFrame ;
9496 private View dayFrame ;
97+ private MaterialButton monthDropSelect ;
98+ private AccessibilityManager accessibilityManager ;
9599
96100 @ NonNull
97101 public static <T > MaterialCalendar <T > newInstance (
@@ -149,6 +153,9 @@ public View onCreateView(
149153 calendarStyle = new CalendarStyle (themedContext );
150154 LayoutInflater themedInflater = layoutInflater .cloneInContext (themedContext );
151155
156+ accessibilityManager =
157+ (AccessibilityManager ) requireContext ().getSystemService (Context .ACCESSIBILITY_SERVICE );
158+
152159 Month earliestMonth = calendarConstraints .getStart ();
153160
154161 int layout ;
@@ -335,18 +342,23 @@ CalendarConstraints getCalendarConstraints() {
335342 void setCurrentMonth (Month moveTo ) {
336343 MonthsPagerAdapter adapter = (MonthsPagerAdapter ) recyclerView .getAdapter ();
337344 int moveToPosition = adapter .getPosition (moveTo );
338- int distance = moveToPosition - adapter .getPosition (current );
339- boolean jump = Math .abs (distance ) > SMOOTH_SCROLL_MAX ;
340- boolean isForward = distance > 0 ;
341- current = moveTo ;
342- if (jump && isForward ) {
343- recyclerView .scrollToPosition (moveToPosition - SMOOTH_SCROLL_MAX );
344- postSmoothRecyclerViewScroll (moveToPosition );
345- } else if (jump ) {
346- recyclerView .scrollToPosition (moveToPosition + SMOOTH_SCROLL_MAX );
347- postSmoothRecyclerViewScroll (moveToPosition );
345+ if (accessibilityManager != null && accessibilityManager .isEnabled ()) {
346+ current = moveTo ;
347+ recyclerView .scrollToPosition (moveToPosition );
348348 } else {
349- postSmoothRecyclerViewScroll (moveToPosition );
349+ int distance = moveToPosition - adapter .getPosition (current );
350+ boolean jump = Math .abs (distance ) > SMOOTH_SCROLL_MAX ;
351+ boolean isForward = distance > 0 ;
352+ current = moveTo ;
353+ if (jump && isForward ) {
354+ recyclerView .scrollToPosition (moveToPosition - SMOOTH_SCROLL_MAX );
355+ postSmoothRecyclerViewScroll (moveToPosition );
356+ } else if (jump ) {
357+ recyclerView .scrollToPosition (moveToPosition + SMOOTH_SCROLL_MAX );
358+ postSmoothRecyclerViewScroll (moveToPosition );
359+ } else {
360+ postSmoothRecyclerViewScroll (moveToPosition );
361+ }
350362 }
351363 updateNavigationButtonsEnabled (moveToPosition );
352364 }
@@ -394,6 +406,12 @@ void setSelector(CalendarSelector selector) {
394406 }
395407 }
396408
409+ void sendAccessibilityFocusEventToMonthDropdown () {
410+ if (monthDropSelect != null ) {
411+ monthDropSelect .sendAccessibilityEvent (AccessibilityEvent .TYPE_VIEW_FOCUSED );
412+ }
413+ }
414+
397415 void toggleVisibleSelector () {
398416 if (calendarSelector == CalendarSelector .YEAR ) {
399417 setSelector (CalendarSelector .DAY );
@@ -408,7 +426,7 @@ void toggleVisibleSelector() {
408426
409427 private void addActionsToMonthNavigation (
410428 @ NonNull final View root , @ NonNull final MonthsPagerAdapter monthsPagerAdapter ) {
411- final MaterialButton monthDropSelect = root .findViewById (R .id .month_navigation_fragment_toggle );
429+ monthDropSelect = root .findViewById (R .id .month_navigation_fragment_toggle );
412430 monthDropSelect .setTag (SELECTOR_TOGGLE_TAG );
413431 ViewCompat .setAccessibilityDelegate (
414432 monthDropSelect ,
0 commit comments