4747import androidx .core .view .ViewCompat ;
4848import androidx .core .view .accessibility .AccessibilityNodeInfoCompat ;
4949import com .google .android .material .animation .AnimationUtils ;
50- import com .google .android .material .textfield .TextInputLayout .AccessibilityDelegate ;
5150import com .google .android .material .textfield .TextInputLayout .BoxBackgroundMode ;
5251
5352/** Default initialization of the exposed dropdown menu {@link TextInputLayout.EndIconMode}. */
@@ -62,37 +61,6 @@ class DropdownMenuEndIconDelegate extends EndIconDelegate {
6261 @ Nullable
6362 private AutoCompleteTextView autoCompleteTextView ;
6463
65- private final TextInputLayout .AccessibilityDelegate accessibilityDelegate =
66- new AccessibilityDelegate (textInputLayout ) {
67- @ Override
68- public void onInitializeAccessibilityNodeInfo (
69- View host , @ NonNull AccessibilityNodeInfoCompat info ) {
70- super .onInitializeAccessibilityNodeInfo (host , info );
71- // The non-editable exposed dropdown menu behaves like a Spinner.
72- if (!isEditable (autoCompleteTextView )) {
73- info .setClassName (Spinner .class .getName ());
74- }
75- if (info .isShowingHintText ()) {
76- // Set hint text to null so TalkBack doesn't announce the label twice when there is no
77- // item selected.
78- info .setHintText (null );
79- }
80- }
81-
82- @ Override
83- public void onPopulateAccessibilityEvent (View host , @ NonNull AccessibilityEvent event ) {
84- super .onPopulateAccessibilityEvent (host , event );
85- // If dropdown is non editable, layout click is what triggers showing/hiding the popup
86- // list. Otherwise, arrow icon alone is what triggers it.
87- if (event .getEventType () == TYPE_VIEW_CLICKED
88- && accessibilityManager .isEnabled ()
89- && !isEditable (autoCompleteTextView )) {
90- showHideDropdown ();
91- updateDropdownPopupDirty ();
92- }
93- }
94- };
95-
9664 private final OnClickListener onIconClickListener = view -> showHideDropdown ();
9765
9866 private final OnFocusChangeListener onEditTextFocusChangeListener = (view , hasFocus ) -> {
@@ -177,8 +145,6 @@ public void onEditTextAttached(@Nullable EditText editText) {
177145 if (!isEditable (editText ) && accessibilityManager .isTouchExplorationEnabled ()) {
178146 ViewCompat .setImportantForAccessibility (endIconView , IMPORTANT_FOR_ACCESSIBILITY_NO );
179147 }
180- textInputLayout .setTextInputAccessibilityDelegate (accessibilityDelegate );
181-
182148 textInputLayout .setEndIconVisible (true );
183149 }
184150
@@ -202,6 +168,32 @@ OnFocusChangeListener getOnEditTextFocusChangeListener() {
202168 return onEditTextFocusChangeListener ;
203169 }
204170
171+ @ Override
172+ public void onInitializeAccessibilityNodeInfo (
173+ View host , @ NonNull AccessibilityNodeInfoCompat info ) {
174+ // The non-editable exposed dropdown menu behaves like a Spinner.
175+ if (!isEditable (autoCompleteTextView )) {
176+ info .setClassName (Spinner .class .getName ());
177+ }
178+ if (info .isShowingHintText ()) {
179+ // Set hint text to null so TalkBack doesn't announce the label twice when there is no
180+ // item selected.
181+ info .setHintText (null );
182+ }
183+ }
184+
185+ @ Override
186+ public void onPopulateAccessibilityEvent (View host , @ NonNull AccessibilityEvent event ) {
187+ // If dropdown is non editable, layout click is what triggers showing/hiding the popup
188+ // list. Otherwise, arrow icon alone is what triggers it.
189+ if (event .getEventType () == TYPE_VIEW_CLICKED
190+ && accessibilityManager .isEnabled ()
191+ && !isEditable (autoCompleteTextView )) {
192+ showHideDropdown ();
193+ updateDropdownPopupDirty ();
194+ }
195+ }
196+
205197 private void showHideDropdown () {
206198 if (autoCompleteTextView == null ) {
207199 return ;
0 commit comments