|
27 | 27 | import android.os.Bundle; |
28 | 28 | import androidx.appcompat.app.AppCompatActivity; |
29 | 29 | import android.util.SparseIntArray; |
| 30 | +import android.view.KeyEvent; |
30 | 31 | import android.view.View; |
31 | 32 | import android.view.ViewGroup.LayoutParams; |
32 | 33 | import android.view.accessibility.AccessibilityManager; |
@@ -109,6 +110,25 @@ public void test_customClickListenerOverridesInternalClickBehavior() { |
109 | 110 | .isEqualTo(BottomSheetBehavior.STATE_EXPANDED); |
110 | 111 | } |
111 | 112 |
|
| 113 | + @Test |
| 114 | + public void test_customClickListenerOverridesInternalClickBehaviorWithKeyboardEnter() { |
| 115 | + activity.addViewToBottomSheet(dragHandleView); |
| 116 | + activity.bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); |
| 117 | + shadowOf(accessibilityManager).setEnabled(true); |
| 118 | + dragHandleView.setOnClickListener( |
| 119 | + v -> { |
| 120 | + // do nothing |
| 121 | + }); |
| 122 | + |
| 123 | + boolean unused = |
| 124 | + dragHandleView.onKeyDown( |
| 125 | + KeyEvent.KEYCODE_ENTER, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); |
| 126 | + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 127 | + |
| 128 | + assertThat(activity.bottomSheetBehavior.getState()) |
| 129 | + .isEqualTo(BottomSheetBehavior.STATE_EXPANDED); |
| 130 | + } |
| 131 | + |
112 | 132 | @Test |
113 | 133 | public void test_notInteractableWhenNotAttachedToBottomSheetAndAccessibilityEnabled() { |
114 | 134 | activity.addViewToContainer(dragHandleView); |
@@ -152,6 +172,39 @@ public void test_collapseExpandedBottomSheetWhenClicked() { |
152 | 172 | .isEqualTo(BottomSheetBehavior.STATE_COLLAPSED); |
153 | 173 | } |
154 | 174 |
|
| 175 | + @Test |
| 176 | + public void test_expandCollapsedBottomSheetWithKeyboardEnter() { |
| 177 | + activity.bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); |
| 178 | + activity.addViewToBottomSheet(dragHandleView); |
| 179 | + shadowOf(accessibilityManager).setEnabled(true); |
| 180 | + boolean unused = |
| 181 | + dragHandleView.onKeyDown( |
| 182 | + KeyEvent.KEYCODE_ENTER, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); |
| 183 | + |
| 184 | + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 185 | + |
| 186 | + assertThat(activity.bottomSheetBehavior.getState()) |
| 187 | + .isEqualTo(BottomSheetBehavior.STATE_EXPANDED); |
| 188 | + } |
| 189 | + |
| 190 | + @Test |
| 191 | + public void test_collapseExpandedBottomSheetWithKeyboardEnter() { |
| 192 | + activity.bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); |
| 193 | + activity.addViewToBottomSheet(dragHandleView); |
| 194 | + shadowOf(accessibilityManager).setEnabled(true); |
| 195 | + |
| 196 | + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 197 | + |
| 198 | + boolean unused = |
| 199 | + dragHandleView.onKeyDown( |
| 200 | + KeyEvent.KEYCODE_ENTER, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); |
| 201 | + |
| 202 | + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 203 | + |
| 204 | + assertThat(activity.bottomSheetBehavior.getState()) |
| 205 | + .isEqualTo(BottomSheetBehavior.STATE_COLLAPSED); |
| 206 | + } |
| 207 | + |
155 | 208 | @Test |
156 | 209 | public void test_collapsedBottomSheetMoveToHalfExpanded_whenClickedAndFitToContentsFalse() { |
157 | 210 | activity.bottomSheetBehavior.setFitToContents(false); |
|
0 commit comments