Skip to content

Commit 8ded9f5

Browse files
hunterstichdsn5ft
authored andcommitted
[BottomSheet] Added back the AccessibilityStateChangedListener implementation in drag handle component
PiperOrigin-RevId: 741553738
1 parent f062532 commit 8ded9f5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/java/com/google/android/material/bottomsheet/BottomSheetDragHandleView.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import android.view.ViewGroup.LayoutParams;
3636
import android.view.ViewParent;
3737
import android.view.accessibility.AccessibilityEvent;
38+
import android.view.accessibility.AccessibilityManager;
39+
import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
3840
import androidx.annotation.NonNull;
3941
import androidx.annotation.Nullable;
4042
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@@ -51,9 +53,12 @@
5153
* clickable. Clicking the drag handle will toggle the bottom sheet between its collapsed and
5254
* expanded states.
5355
*/
54-
public class BottomSheetDragHandleView extends AppCompatImageView {
56+
public class BottomSheetDragHandleView extends AppCompatImageView implements
57+
AccessibilityStateChangeListener {
5558
private static final int DEF_STYLE_RES = R.style.Widget_Material3_BottomSheet_DragHandle;
5659

60+
@Nullable private final AccessibilityManager accessibilityManager;
61+
5762
@Nullable private BottomSheetBehavior<?> bottomSheetBehavior;
5863

5964
private final GestureDetector gestureDetector;
@@ -134,6 +139,9 @@ public BottomSheetDragHandleView(
134139
gestureDetector =
135140
new GestureDetector(context, gestureListener, new Handler(Looper.getMainLooper()));
136141

142+
accessibilityManager =
143+
(AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
144+
137145
ViewCompat.setAccessibilityDelegate(
138146
this,
139147
new AccessibilityDelegateCompat() {
@@ -151,10 +159,17 @@ public void onPopulateAccessibilityEvent(View host, @NonNull AccessibilityEvent
151159
protected void onAttachedToWindow() {
152160
super.onAttachedToWindow();
153161
setBottomSheetBehavior(findParentBottomSheetBehavior());
162+
if (accessibilityManager != null) {
163+
accessibilityManager.addAccessibilityStateChangeListener(this);
164+
onAccessibilityStateChanged(accessibilityManager.isEnabled());
165+
}
154166
}
155167

156168
@Override
157169
protected void onDetachedFromWindow() {
170+
if (accessibilityManager != null) {
171+
accessibilityManager.removeAccessibilityStateChangeListener(this);
172+
}
158173
setBottomSheetBehavior(null);
159174
super.onDetachedFromWindow();
160175
}
@@ -183,6 +198,11 @@ public void setOnClickListener(@Nullable OnClickListener l) {
183198
super.setOnClickListener(l);
184199
}
185200

201+
@Override
202+
public void onAccessibilityStateChanged(boolean enabled) {
203+
// Do nothing.
204+
}
205+
186206
private void setBottomSheetBehavior(@Nullable BottomSheetBehavior<?> behavior) {
187207
if (bottomSheetBehavior != null) {
188208
bottomSheetBehavior.removeBottomSheetCallback(bottomSheetCallback);

0 commit comments

Comments
 (0)