/
DropdownMenuEndIconDelegate.java
571 lines (523 loc) · 23 KB
/
DropdownMenuEndIconDelegate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.material.textfield;
import com.google.android.material.R;
import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_CLICKED;
import static androidx.core.view.ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
import static androidx.core.view.ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.widget.AutoCompleteTextView;
import android.widget.AutoCompleteTextView.OnDismissListener;
import android.widget.EditText;
import android.widget.Spinner;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityManagerCompat;
import androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.google.android.material.animation.AnimationUtils;
import com.google.android.material.color.MaterialColors;
import com.google.android.material.internal.TextWatcherAdapter;
import com.google.android.material.shape.MaterialShapeDrawable;
import com.google.android.material.shape.ShapeAppearanceModel;
import com.google.android.material.textfield.TextInputLayout.AccessibilityDelegate;
import com.google.android.material.textfield.TextInputLayout.BoxBackgroundMode;
import com.google.android.material.textfield.TextInputLayout.OnEditTextAttachedListener;
import com.google.android.material.textfield.TextInputLayout.OnEndIconChangedListener;
/** Default initialization of the exposed dropdown menu {@link TextInputLayout.EndIconMode}. */
class DropdownMenuEndIconDelegate extends EndIconDelegate {
private static final boolean IS_LOLLIPOP = VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP;
private static final int ANIMATION_FADE_OUT_DURATION = 50;
private static final int ANIMATION_FADE_IN_DURATION = 67;
private final TextWatcher exposedDropdownEndIconTextWatcher =
new TextWatcherAdapter() {
@Override
public void afterTextChanged(Editable s) {
final AutoCompleteTextView editText =
castAutoCompleteTextViewOrThrow(textInputLayout.getEditText());
// Don't show dropdown list if we're in a11y mode and the menu is editable.
if (accessibilityManager.isTouchExplorationEnabled()
&& isEditable(editText)
&& !endIconView.hasFocus()) {
editText.dismissDropDown();
}
editText.post(
new Runnable() {
@Override
public void run() {
boolean isPopupShowing = editText.isPopupShowing();
setEndIconChecked(isPopupShowing);
dropdownPopupDirty = isPopupShowing;
}
});
}
};
private final OnFocusChangeListener onFocusChangeListener =
new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
textInputLayout.setEndIconActivated(hasFocus);
if (!hasFocus) {
setEndIconChecked(false);
dropdownPopupDirty = false;
}
}
};
private final TextInputLayout.AccessibilityDelegate accessibilityDelegate =
new AccessibilityDelegate(textInputLayout) {
@Override
public void onInitializeAccessibilityNodeInfo(
View host, @NonNull AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
// The non-editable exposed dropdown menu behaves like a Spinner.
if (!isEditable(textInputLayout.getEditText())) {
info.setClassName(Spinner.class.getName());
}
if (info.isShowingHintText()) {
// Set hint text to null so TalkBack doesn't announce the label twice when there is no
// item selected.
info.setHintText(null);
}
}
@Override
public void onPopulateAccessibilityEvent(View host, @NonNull AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
AutoCompleteTextView editText =
castAutoCompleteTextViewOrThrow(textInputLayout.getEditText());
// If dropdown is non editable, layout click is what triggers showing/hiding the popup
// list. Otherwise, arrow icon alone is what triggers it.
if (event.getEventType() == TYPE_VIEW_CLICKED
&& accessibilityManager.isEnabled()
&& !isEditable(textInputLayout.getEditText())) {
showHideDropdown(editText);
updateDropdownPopupDirty();
}
}
};
private final OnEditTextAttachedListener dropdownMenuOnEditTextAttachedListener =
new OnEditTextAttachedListener() {
@Override
public void onEditTextAttached(@NonNull TextInputLayout textInputLayout) {
AutoCompleteTextView autoCompleteTextView =
castAutoCompleteTextViewOrThrow(textInputLayout.getEditText());
setPopupBackground(autoCompleteTextView);
addRippleEffect(autoCompleteTextView);
setUpDropdownShowHideBehavior(autoCompleteTextView);
autoCompleteTextView.setThreshold(0);
autoCompleteTextView.removeTextChangedListener(exposedDropdownEndIconTextWatcher);
autoCompleteTextView.addTextChangedListener(exposedDropdownEndIconTextWatcher);
textInputLayout.setEndIconCheckable(true);
textInputLayout.setErrorIconDrawable(null);
if (!isEditable(autoCompleteTextView)
&& accessibilityManager.isTouchExplorationEnabled()) {
ViewCompat.setImportantForAccessibility(endIconView, IMPORTANT_FOR_ACCESSIBILITY_NO);
}
textInputLayout.setTextInputAccessibilityDelegate(accessibilityDelegate);
textInputLayout.setEndIconVisible(true);
}
};
@SuppressLint("ClickableViewAccessibility") // There's an accessibility delegate that handles
// interactions with the dropdown menu.
private final OnEndIconChangedListener endIconChangedListener =
new OnEndIconChangedListener() {
@Override
public void onEndIconChanged(@NonNull TextInputLayout textInputLayout, int previousIcon) {
final AutoCompleteTextView editText =
(AutoCompleteTextView) textInputLayout.getEditText();
if (editText != null && previousIcon == TextInputLayout.END_ICON_DROPDOWN_MENU) {
// Remove any listeners set on the edit text.
editText.post(
new Runnable() {
@Override
public void run() {
editText.removeTextChangedListener(exposedDropdownEndIconTextWatcher);
}
});
if (editText.getOnFocusChangeListener() == onFocusChangeListener) {
editText.setOnFocusChangeListener(null);
}
editText.setOnTouchListener(null);
if (IS_LOLLIPOP) {
editText.setOnDismissListener(null);
}
}
if (previousIcon == TextInputLayout.END_ICON_DROPDOWN_MENU) {
textInputLayout.removeOnAttachStateChangeListener(onAttachStateChangeListener);
removeTouchExplorationStateChangeListenerIfNeeded();
}
}
};
private final OnAttachStateChangeListener onAttachStateChangeListener = new OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View ignored) {
addTouchExplorationStateChangeListenerIfNeeded();
}
@Override
public void onViewDetachedFromWindow(View ignored) {
removeTouchExplorationStateChangeListenerIfNeeded();
}
};
private final TouchExplorationStateChangeListener touchExplorationStateChangeListener =
new TouchExplorationStateChangeListener() {
@Override
public void onTouchExplorationStateChanged(boolean enabled) {
if (textInputLayout != null) {
final AutoCompleteTextView autoCompleteTextView =
(AutoCompleteTextView) textInputLayout.getEditText();
if (autoCompleteTextView != null && !isEditable(autoCompleteTextView)) {
ViewCompat.setImportantForAccessibility(
endIconView,
enabled ? IMPORTANT_FOR_ACCESSIBILITY_NO : IMPORTANT_FOR_ACCESSIBILITY_YES);
}
}
}
};
private boolean dropdownPopupDirty = false;
private boolean isEndIconChecked = false;
private long dropdownPopupActivatedAt = Long.MAX_VALUE;
private StateListDrawable filledPopupBackground;
private MaterialShapeDrawable outlinedPopupBackground;
@Nullable private AccessibilityManager accessibilityManager;
private ValueAnimator fadeOutAnim;
private ValueAnimator fadeInAnim;
DropdownMenuEndIconDelegate(
@NonNull TextInputLayout textInputLayout, @DrawableRes int customEndIcon) {
super(textInputLayout, customEndIcon);
}
@Override
void initialize() {
float popupCornerRadius =
context
.getResources()
.getDimensionPixelOffset(R.dimen.mtrl_shape_corner_size_small_component);
float exposedDropdownPopupElevation =
context
.getResources()
.getDimensionPixelOffset(R.dimen.mtrl_exposed_dropdown_menu_popup_elevation);
int exposedDropdownPopupVerticalPadding =
context
.getResources()
.getDimensionPixelOffset(R.dimen.mtrl_exposed_dropdown_menu_popup_vertical_padding);
// Background for the popups of the outlined variation and for the filled variation when it is
// being displayed above the layout.
MaterialShapeDrawable roundedCornersPopupBackground =
getPopUpMaterialShapeDrawable(
popupCornerRadius,
popupCornerRadius,
exposedDropdownPopupElevation,
exposedDropdownPopupVerticalPadding);
// Background for the popup of the filled variation when it is being displayed below the layout.
MaterialShapeDrawable roundedBottomCornersPopupBackground =
getPopUpMaterialShapeDrawable(
0,
popupCornerRadius,
exposedDropdownPopupElevation,
exposedDropdownPopupVerticalPadding);
outlinedPopupBackground = roundedCornersPopupBackground;
filledPopupBackground = new StateListDrawable();
filledPopupBackground.addState(
new int[] {android.R.attr.state_above_anchor}, roundedCornersPopupBackground);
filledPopupBackground.addState(new int[] {}, roundedBottomCornersPopupBackground);
// For lollipop+, the arrow icon changes orientation based on dropdown popup, otherwise it
// always points down.
int drawableResId =
customEndIcon == 0
? (IS_LOLLIPOP ? R.drawable.mtrl_dropdown_arrow : R.drawable.mtrl_ic_arrow_drop_down)
: customEndIcon;
textInputLayout.setEndIconDrawable(drawableResId);
textInputLayout.setEndIconContentDescription(
textInputLayout.getResources().getText(R.string.exposed_dropdown_menu_content_description));
textInputLayout.setEndIconOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
AutoCompleteTextView editText = (AutoCompleteTextView) textInputLayout.getEditText();
showHideDropdown(editText);
}
});
textInputLayout.addOnEditTextAttachedListener(dropdownMenuOnEditTextAttachedListener);
textInputLayout.addOnEndIconChangedListener(endIconChangedListener);
initAnimators();
accessibilityManager =
(AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
textInputLayout.addOnAttachStateChangeListener(onAttachStateChangeListener);
addTouchExplorationStateChangeListenerIfNeeded();
}
@Override
boolean shouldTintIconOnError() {
return true;
}
@Override
boolean isBoxBackgroundModeSupported(@BoxBackgroundMode int boxBackgroundMode) {
return boxBackgroundMode != TextInputLayout.BOX_BACKGROUND_NONE;
}
private void showHideDropdown(@Nullable AutoCompleteTextView editText) {
if (editText == null) {
return;
}
if (isDropdownPopupActive()) {
dropdownPopupDirty = false;
}
if (!dropdownPopupDirty) {
if (IS_LOLLIPOP) {
setEndIconChecked(!isEndIconChecked);
} else {
isEndIconChecked = !isEndIconChecked;
endIconView.toggle();
}
if (isEndIconChecked) {
editText.requestFocus();
editText.showDropDown();
} else {
editText.dismissDropDown();
}
} else {
dropdownPopupDirty = false;
}
}
private void setPopupBackground(@NonNull AutoCompleteTextView editText) {
if (IS_LOLLIPOP) {
int boxBackgroundMode = textInputLayout.getBoxBackgroundMode();
if (boxBackgroundMode == TextInputLayout.BOX_BACKGROUND_OUTLINE) {
editText.setDropDownBackgroundDrawable(outlinedPopupBackground);
} else if (boxBackgroundMode == TextInputLayout.BOX_BACKGROUND_FILLED) {
editText.setDropDownBackgroundDrawable(filledPopupBackground);
}
}
}
/*
* This method should be called if the outlined ripple background should be updated. For example,
* if a new {@link ShapeAppearanceModel} is set on the text field.
*/
void updateOutlinedRippleEffect(@NonNull AutoCompleteTextView editText) {
if (isEditable(editText)
|| textInputLayout.getBoxBackgroundMode() != TextInputLayout.BOX_BACKGROUND_OUTLINE
|| !(editText.getBackground() instanceof LayerDrawable)) {
return;
}
addRippleEffect(editText);
}
/* Add ripple effect to non editable layouts. */
private void addRippleEffect(@NonNull AutoCompleteTextView editText) {
if (isEditable(editText)) {
return;
}
int boxBackgroundMode = textInputLayout.getBoxBackgroundMode();
MaterialShapeDrawable boxBackground = textInputLayout.getBoxBackground();
int rippleColor = MaterialColors.getColor(editText, R.attr.colorControlHighlight);
int[][] states =
new int[][] {
new int[] {android.R.attr.state_pressed}, new int[] {},
};
if (boxBackgroundMode == TextInputLayout.BOX_BACKGROUND_OUTLINE) {
addRippleEffectOnOutlinedLayout(editText, rippleColor, states, boxBackground);
} else if (boxBackgroundMode == TextInputLayout.BOX_BACKGROUND_FILLED) {
addRippleEffectOnFilledLayout(editText, rippleColor, states, boxBackground);
}
}
private void addRippleEffectOnOutlinedLayout(
@NonNull AutoCompleteTextView editText,
int rippleColor,
int[][] states,
@NonNull MaterialShapeDrawable boxBackground) {
LayerDrawable editTextBackground;
int surfaceColor = MaterialColors.getColor(editText, R.attr.colorSurface);
MaterialShapeDrawable rippleBackground =
new MaterialShapeDrawable(boxBackground.getShapeAppearanceModel());
int pressedBackgroundColor = MaterialColors.layer(rippleColor, surfaceColor, 0.1f);
int[] rippleBackgroundColors = new int[] {pressedBackgroundColor, Color.TRANSPARENT};
rippleBackground.setFillColor(new ColorStateList(states, rippleBackgroundColors));
if (IS_LOLLIPOP) {
rippleBackground.setTint(surfaceColor);
int[] colors = new int[] {pressedBackgroundColor, surfaceColor};
ColorStateList rippleColorStateList = new ColorStateList(states, colors);
MaterialShapeDrawable mask =
new MaterialShapeDrawable(boxBackground.getShapeAppearanceModel());
mask.setTint(Color.WHITE);
Drawable rippleDrawable = new RippleDrawable(rippleColorStateList, rippleBackground, mask);
Drawable[] layers = {rippleDrawable, boxBackground};
editTextBackground = new LayerDrawable(layers);
} else {
Drawable[] layers = {rippleBackground, boxBackground};
editTextBackground = new LayerDrawable(layers);
}
ViewCompat.setBackground(editText, editTextBackground);
}
private void addRippleEffectOnFilledLayout(
@NonNull AutoCompleteTextView editText,
int rippleColor,
int[][] states,
@NonNull MaterialShapeDrawable boxBackground) {
int boxBackgroundColor = textInputLayout.getBoxBackgroundColor();
int pressedBackgroundColor = MaterialColors.layer(rippleColor, boxBackgroundColor, 0.1f);
int[] colors = new int[] {pressedBackgroundColor, boxBackgroundColor};
if (IS_LOLLIPOP) {
ColorStateList rippleColorStateList = new ColorStateList(states, colors);
Drawable editTextBackground =
new RippleDrawable(rippleColorStateList, boxBackground, boxBackground);
ViewCompat.setBackground(editText, editTextBackground);
} else {
MaterialShapeDrawable rippleBackground =
new MaterialShapeDrawable(boxBackground.getShapeAppearanceModel());
rippleBackground.setFillColor(new ColorStateList(states, colors));
Drawable[] layers = {boxBackground, rippleBackground};
LayerDrawable editTextBackground = new LayerDrawable(layers);
int start = ViewCompat.getPaddingStart(editText);
int top = editText.getPaddingTop();
int end = ViewCompat.getPaddingEnd(editText);
int bottom = editText.getPaddingBottom();
ViewCompat.setBackground(editText, editTextBackground);
ViewCompat.setPaddingRelative(editText, start, top, end, bottom);
}
}
@SuppressLint("ClickableViewAccessibility") // There's an accessibility delegate that handles
// interactions with the dropdown menu.
private void setUpDropdownShowHideBehavior(@NonNull final AutoCompleteTextView editText) {
// Set whole layout clickable.
editText.setOnTouchListener(
new OnTouchListener() {
@Override
public boolean onTouch(@NonNull View v, @NonNull MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (isDropdownPopupActive()) {
dropdownPopupDirty = false;
}
showHideDropdown(editText);
updateDropdownPopupDirty();
}
return false;
}
});
editText.setOnFocusChangeListener(onFocusChangeListener);
if (IS_LOLLIPOP) {
editText.setOnDismissListener(
new OnDismissListener() {
@Override
public void onDismiss() {
updateDropdownPopupDirty();
setEndIconChecked(false);
}
});
}
}
private MaterialShapeDrawable getPopUpMaterialShapeDrawable(
float topCornerRadius, float bottomCornerRadius, float elevation, int verticalPadding) {
ShapeAppearanceModel shapeAppearanceModel =
ShapeAppearanceModel.builder()
.setTopLeftCornerSize(topCornerRadius)
.setTopRightCornerSize(topCornerRadius)
.setBottomLeftCornerSize(bottomCornerRadius)
.setBottomRightCornerSize(bottomCornerRadius)
.build();
MaterialShapeDrawable popupDrawable =
MaterialShapeDrawable.createWithElevationOverlay(context, elevation);
popupDrawable.setShapeAppearanceModel(shapeAppearanceModel);
popupDrawable.setPadding(0, verticalPadding, 0, verticalPadding);
return popupDrawable;
}
private boolean isDropdownPopupActive() {
long activeFor = System.currentTimeMillis() - dropdownPopupActivatedAt;
return activeFor < 0 || activeFor > 300;
}
@NonNull
private static AutoCompleteTextView castAutoCompleteTextViewOrThrow(EditText editText) {
if (!(editText instanceof AutoCompleteTextView)) {
throw new RuntimeException(
"EditText needs to be an AutoCompleteTextView if an Exposed Dropdown Menu is being"
+ " used.");
}
return (AutoCompleteTextView) editText;
}
private void updateDropdownPopupDirty() {
dropdownPopupDirty = true;
dropdownPopupActivatedAt = System.currentTimeMillis();
}
private static boolean isEditable(@NonNull EditText editText) {
return editText.getKeyListener() != null;
}
private void setEndIconChecked(boolean checked) {
if (isEndIconChecked != checked) {
isEndIconChecked = checked;
fadeInAnim.cancel();
fadeOutAnim.start();
}
}
private void initAnimators() {
fadeInAnim = getAlphaAnimator(ANIMATION_FADE_IN_DURATION, 0, 1);
fadeOutAnim = getAlphaAnimator(ANIMATION_FADE_OUT_DURATION, 1, 0);
fadeOutAnim.addListener(
new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
endIconView.setChecked(isEndIconChecked);
fadeInAnim.start();
}
});
}
private ValueAnimator getAlphaAnimator(int duration, float... values) {
ValueAnimator animator = ValueAnimator.ofFloat(values);
animator.setInterpolator(AnimationUtils.LINEAR_INTERPOLATOR);
animator.setDuration(duration);
animator.addUpdateListener(
new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(@NonNull ValueAnimator animation) {
float alpha = (float) animation.getAnimatedValue();
endIconView.setAlpha(alpha);
}
});
return animator;
}
private void addTouchExplorationStateChangeListenerIfNeeded() {
if (accessibilityManager != null
&& textInputLayout != null
&& ViewCompat.isAttachedToWindow(textInputLayout)) {
AccessibilityManagerCompat.addTouchExplorationStateChangeListener(
accessibilityManager, touchExplorationStateChangeListener);
}
}
private void removeTouchExplorationStateChangeListenerIfNeeded() {
if (accessibilityManager != null) {
AccessibilityManagerCompat.removeTouchExplorationStateChangeListener(
accessibilityManager, touchExplorationStateChangeListener);
}
}
}