35
35
import android .view .ViewGroup .LayoutParams ;
36
36
import android .view .ViewParent ;
37
37
import android .view .accessibility .AccessibilityEvent ;
38
+ import android .view .accessibility .AccessibilityManager ;
39
+ import android .view .accessibility .AccessibilityManager .AccessibilityStateChangeListener ;
38
40
import androidx .annotation .NonNull ;
39
41
import androidx .annotation .Nullable ;
40
42
import androidx .coordinatorlayout .widget .CoordinatorLayout ;
51
53
* clickable. Clicking the drag handle will toggle the bottom sheet between its collapsed and
52
54
* expanded states.
53
55
*/
54
- public class BottomSheetDragHandleView extends AppCompatImageView {
56
+ public class BottomSheetDragHandleView extends AppCompatImageView implements
57
+ AccessibilityStateChangeListener {
55
58
private static final int DEF_STYLE_RES = R .style .Widget_Material3_BottomSheet_DragHandle ;
56
59
60
+ @ Nullable private final AccessibilityManager accessibilityManager ;
61
+
57
62
@ Nullable private BottomSheetBehavior <?> bottomSheetBehavior ;
58
63
59
64
private final GestureDetector gestureDetector ;
@@ -134,6 +139,9 @@ public BottomSheetDragHandleView(
134
139
gestureDetector =
135
140
new GestureDetector (context , gestureListener , new Handler (Looper .getMainLooper ()));
136
141
142
+ accessibilityManager =
143
+ (AccessibilityManager ) context .getSystemService (Context .ACCESSIBILITY_SERVICE );
144
+
137
145
ViewCompat .setAccessibilityDelegate (
138
146
this ,
139
147
new AccessibilityDelegateCompat () {
@@ -151,10 +159,17 @@ public void onPopulateAccessibilityEvent(View host, @NonNull AccessibilityEvent
151
159
protected void onAttachedToWindow () {
152
160
super .onAttachedToWindow ();
153
161
setBottomSheetBehavior (findParentBottomSheetBehavior ());
162
+ if (accessibilityManager != null ) {
163
+ accessibilityManager .addAccessibilityStateChangeListener (this );
164
+ onAccessibilityStateChanged (accessibilityManager .isEnabled ());
165
+ }
154
166
}
155
167
156
168
@ Override
157
169
protected void onDetachedFromWindow () {
170
+ if (accessibilityManager != null ) {
171
+ accessibilityManager .removeAccessibilityStateChangeListener (this );
172
+ }
158
173
setBottomSheetBehavior (null );
159
174
super .onDetachedFromWindow ();
160
175
}
@@ -183,6 +198,11 @@ public void setOnClickListener(@Nullable OnClickListener l) {
183
198
super .setOnClickListener (l );
184
199
}
185
200
201
+ @ Override
202
+ public void onAccessibilityStateChanged (boolean enabled ) {
203
+ // Do nothing.
204
+ }
205
+
186
206
private void setBottomSheetBehavior (@ Nullable BottomSheetBehavior <?> behavior ) {
187
207
if (bottomSheetBehavior != null ) {
188
208
bottomSheetBehavior .removeBottomSheetCallback (bottomSheetCallback );
0 commit comments