336 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			336 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package com.google.android.material.textfield;
 | |
| 
 | |
| import android.animation.Animator;
 | |
| import android.animation.AnimatorListenerAdapter;
 | |
| import android.animation.TimeInterpolator;
 | |
| import android.animation.ValueAnimator;
 | |
| import android.graphics.drawable.Drawable;
 | |
| import android.text.Editable;
 | |
| import android.view.MotionEvent;
 | |
| import android.view.View;
 | |
| import android.view.accessibility.AccessibilityEvent;
 | |
| import android.view.accessibility.AccessibilityManager;
 | |
| import android.widget.AutoCompleteTextView;
 | |
| import android.widget.EditText;
 | |
| import android.widget.Spinner;
 | |
| import androidx.core.view.ViewCompat;
 | |
| import androidx.core.view.accessibility.AccessibilityManagerCompat;
 | |
| import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
 | |
| import com.google.android.material.R;
 | |
| import com.google.android.material.animation.AnimationUtils;
 | |
| import com.google.android.material.motion.MotionUtils;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| class DropdownMenuEndIconDelegate extends EndIconDelegate {
 | |
|     private static final int DEFAULT_ANIMATION_FADE_IN_DURATION = 67;
 | |
|     private static final int DEFAULT_ANIMATION_FADE_OUT_DURATION = 50;
 | |
|     private static final boolean IS_LOLLIPOP = true;
 | |
|     private AccessibilityManager accessibilityManager;
 | |
|     private final int animationFadeInDuration;
 | |
|     private final TimeInterpolator animationFadeInterpolator;
 | |
|     private final int animationFadeOutDuration;
 | |
|     private AutoCompleteTextView autoCompleteTextView;
 | |
|     private long dropdownPopupActivatedAt;
 | |
|     private boolean dropdownPopupDirty;
 | |
|     private boolean editTextHasFocus;
 | |
|     private ValueAnimator fadeInAnim;
 | |
|     private ValueAnimator fadeOutAnim;
 | |
|     private boolean isEndIconChecked;
 | |
|     private final View.OnFocusChangeListener onEditTextFocusChangeListener;
 | |
|     private final View.OnClickListener onIconClickListener;
 | |
|     private final AccessibilityManagerCompat.TouchExplorationStateChangeListener touchExplorationStateChangeListener;
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     View.OnFocusChangeListener getOnEditTextFocusChangeListener() {
 | |
|         return this.onEditTextFocusChangeListener;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     View.OnClickListener getOnIconClickListener() {
 | |
|         return this.onIconClickListener;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     public AccessibilityManagerCompat.TouchExplorationStateChangeListener getTouchExplorationStateChangeListener() {
 | |
|         return this.touchExplorationStateChangeListener;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     boolean isBoxBackgroundModeSupported(int i) {
 | |
|         return i != 0;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     boolean isIconActivable() {
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     boolean isIconActivated() {
 | |
|         return this.editTextHasFocus;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     boolean isIconCheckable() {
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     boolean isIconChecked() {
 | |
|         return this.isEndIconChecked;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     boolean shouldTintIconOnError() {
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     /* renamed from: lambda$new$0$com-google-android-material-textfield-DropdownMenuEndIconDelegate, reason: not valid java name */
 | |
|     /* synthetic */ void m273xd03fedd4(View view) {
 | |
|         showHideDropdown();
 | |
|     }
 | |
| 
 | |
|     /* renamed from: lambda$new$1$com-google-android-material-textfield-DropdownMenuEndIconDelegate, reason: not valid java name */
 | |
|     /* synthetic */ void m274xac016995(View view, boolean z) {
 | |
|         this.editTextHasFocus = z;
 | |
|         refreshIconState();
 | |
|         if (z) {
 | |
|             return;
 | |
|         }
 | |
|         setEndIconChecked(false);
 | |
|         this.dropdownPopupDirty = false;
 | |
|     }
 | |
| 
 | |
|     /* renamed from: lambda$new$2$com-google-android-material-textfield-DropdownMenuEndIconDelegate, reason: not valid java name */
 | |
|     /* synthetic */ void m275x87c2e556(boolean z) {
 | |
|         AutoCompleteTextView autoCompleteTextView = this.autoCompleteTextView;
 | |
|         if (autoCompleteTextView == null || EditTextUtils.isEditable(autoCompleteTextView)) {
 | |
|             return;
 | |
|         }
 | |
|         ViewCompat.setImportantForAccessibility(this.endIconView, z ? 2 : 1);
 | |
|     }
 | |
| 
 | |
|     DropdownMenuEndIconDelegate(EndCompoundLayout endCompoundLayout) {
 | |
|         super(endCompoundLayout);
 | |
|         this.onIconClickListener = new View.OnClickListener() { // from class: com.google.android.material.textfield.DropdownMenuEndIconDelegate$$ExternalSyntheticLambda0
 | |
|             @Override // android.view.View.OnClickListener
 | |
|             public final void onClick(View view) {
 | |
|                 DropdownMenuEndIconDelegate.this.m273xd03fedd4(view);
 | |
|             }
 | |
|         };
 | |
|         this.onEditTextFocusChangeListener = new View.OnFocusChangeListener() { // from class: com.google.android.material.textfield.DropdownMenuEndIconDelegate$$ExternalSyntheticLambda1
 | |
|             @Override // android.view.View.OnFocusChangeListener
 | |
|             public final void onFocusChange(View view, boolean z) {
 | |
|                 DropdownMenuEndIconDelegate.this.m274xac016995(view, z);
 | |
|             }
 | |
|         };
 | |
|         this.touchExplorationStateChangeListener = new AccessibilityManagerCompat.TouchExplorationStateChangeListener() { // from class: com.google.android.material.textfield.DropdownMenuEndIconDelegate$$ExternalSyntheticLambda2
 | |
|             @Override // androidx.core.view.accessibility.AccessibilityManagerCompat.TouchExplorationStateChangeListener
 | |
|             public final void onTouchExplorationStateChanged(boolean z) {
 | |
|                 DropdownMenuEndIconDelegate.this.m275x87c2e556(z);
 | |
|             }
 | |
|         };
 | |
|         this.dropdownPopupActivatedAt = Long.MAX_VALUE;
 | |
|         this.animationFadeInDuration = MotionUtils.resolveThemeDuration(endCompoundLayout.getContext(), R.attr.motionDurationShort3, 67);
 | |
|         this.animationFadeOutDuration = MotionUtils.resolveThemeDuration(endCompoundLayout.getContext(), R.attr.motionDurationShort3, 50);
 | |
|         this.animationFadeInterpolator = MotionUtils.resolveThemeInterpolator(endCompoundLayout.getContext(), R.attr.motionEasingLinearInterpolator, AnimationUtils.LINEAR_INTERPOLATOR);
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     void setUp() {
 | |
|         initAnimators();
 | |
|         this.accessibilityManager = (AccessibilityManager) this.context.getSystemService("accessibility");
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     void tearDown() {
 | |
|         AutoCompleteTextView autoCompleteTextView = this.autoCompleteTextView;
 | |
|         if (autoCompleteTextView != null) {
 | |
|             autoCompleteTextView.setOnTouchListener(null);
 | |
|             if (IS_LOLLIPOP) {
 | |
|                 this.autoCompleteTextView.setOnDismissListener(null);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     int getIconDrawableResId() {
 | |
|         return IS_LOLLIPOP ? R.drawable.mtrl_dropdown_arrow : R.drawable.mtrl_ic_arrow_drop_down;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     int getIconContentDescriptionResId() {
 | |
|         return R.string.exposed_dropdown_menu_content_description;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     public void onEditTextAttached(EditText editText) {
 | |
|         this.autoCompleteTextView = castAutoCompleteTextViewOrThrow(editText);
 | |
|         setUpDropdownShowHideBehavior();
 | |
|         this.textInputLayout.setErrorIconDrawable((Drawable) null);
 | |
|         if (!EditTextUtils.isEditable(editText) && this.accessibilityManager.isTouchExplorationEnabled()) {
 | |
|             ViewCompat.setImportantForAccessibility(this.endIconView, 2);
 | |
|         }
 | |
|         this.textInputLayout.setEndIconVisible(true);
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     public void afterEditTextChanged(Editable editable) {
 | |
|         if (this.accessibilityManager.isTouchExplorationEnabled() && EditTextUtils.isEditable(this.autoCompleteTextView) && !this.endIconView.hasFocus()) {
 | |
|             this.autoCompleteTextView.dismissDropDown();
 | |
|         }
 | |
|         this.autoCompleteTextView.post(new Runnable() { // from class: com.google.android.material.textfield.DropdownMenuEndIconDelegate$$ExternalSyntheticLambda4
 | |
|             @Override // java.lang.Runnable
 | |
|             public final void run() {
 | |
|                 DropdownMenuEndIconDelegate.this.m271xae660ff2();
 | |
|             }
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     /* renamed from: lambda$afterEditTextChanged$3$com-google-android-material-textfield-DropdownMenuEndIconDelegate, reason: not valid java name */
 | |
|     /* synthetic */ void m271xae660ff2() {
 | |
|         boolean isPopupShowing = this.autoCompleteTextView.isPopupShowing();
 | |
|         setEndIconChecked(isPopupShowing);
 | |
|         this.dropdownPopupDirty = isPopupShowing;
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     public void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
 | |
|         if (!EditTextUtils.isEditable(this.autoCompleteTextView)) {
 | |
|             accessibilityNodeInfoCompat.setClassName(Spinner.class.getName());
 | |
|         }
 | |
|         if (accessibilityNodeInfoCompat.isShowingHintText()) {
 | |
|             accessibilityNodeInfoCompat.setHintText(null);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // com.google.android.material.textfield.EndIconDelegate
 | |
|     public void onPopulateAccessibilityEvent(View view, AccessibilityEvent accessibilityEvent) {
 | |
|         if (!this.accessibilityManager.isEnabled() || EditTextUtils.isEditable(this.autoCompleteTextView)) {
 | |
|             return;
 | |
|         }
 | |
|         boolean z = accessibilityEvent.getEventType() == 32768 && this.isEndIconChecked && !this.autoCompleteTextView.isPopupShowing();
 | |
|         if (accessibilityEvent.getEventType() == 1 || z) {
 | |
|             showHideDropdown();
 | |
|             updateDropdownPopupDirty();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void showHideDropdown() {
 | |
|         if (this.autoCompleteTextView == null) {
 | |
|             return;
 | |
|         }
 | |
|         if (isDropdownPopupActive()) {
 | |
|             this.dropdownPopupDirty = false;
 | |
|         }
 | |
|         if (this.dropdownPopupDirty) {
 | |
|             this.dropdownPopupDirty = false;
 | |
|             return;
 | |
|         }
 | |
|         if (IS_LOLLIPOP) {
 | |
|             setEndIconChecked(!this.isEndIconChecked);
 | |
|         } else {
 | |
|             this.isEndIconChecked = !this.isEndIconChecked;
 | |
|             refreshIconState();
 | |
|         }
 | |
|         if (this.isEndIconChecked) {
 | |
|             this.autoCompleteTextView.requestFocus();
 | |
|             this.autoCompleteTextView.showDropDown();
 | |
|         } else {
 | |
|             this.autoCompleteTextView.dismissDropDown();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void setUpDropdownShowHideBehavior() {
 | |
|         this.autoCompleteTextView.setOnTouchListener(new View.OnTouchListener() { // from class: com.google.android.material.textfield.DropdownMenuEndIconDelegate$$ExternalSyntheticLambda5
 | |
|             @Override // android.view.View.OnTouchListener
 | |
|             public final boolean onTouch(View view, MotionEvent motionEvent) {
 | |
|                 return DropdownMenuEndIconDelegate.this.m276x5f2e2537(view, motionEvent);
 | |
|             }
 | |
|         });
 | |
|         if (IS_LOLLIPOP) {
 | |
|             this.autoCompleteTextView.setOnDismissListener(new AutoCompleteTextView.OnDismissListener() { // from class: com.google.android.material.textfield.DropdownMenuEndIconDelegate$$ExternalSyntheticLambda6
 | |
|                 @Override // android.widget.AutoCompleteTextView.OnDismissListener
 | |
|                 public final void onDismiss() {
 | |
|                     DropdownMenuEndIconDelegate.this.m277x3aefa0f8();
 | |
|                 }
 | |
|             });
 | |
|         }
 | |
|         this.autoCompleteTextView.setThreshold(0);
 | |
|     }
 | |
| 
 | |
|     /* renamed from: lambda$setUpDropdownShowHideBehavior$4$com-google-android-material-textfield-DropdownMenuEndIconDelegate, reason: not valid java name */
 | |
|     /* synthetic */ boolean m276x5f2e2537(View view, MotionEvent motionEvent) {
 | |
|         if (motionEvent.getAction() == 1) {
 | |
|             if (isDropdownPopupActive()) {
 | |
|                 this.dropdownPopupDirty = false;
 | |
|             }
 | |
|             showHideDropdown();
 | |
|             updateDropdownPopupDirty();
 | |
|         }
 | |
|         return false;
 | |
|     }
 | |
| 
 | |
|     /* renamed from: lambda$setUpDropdownShowHideBehavior$5$com-google-android-material-textfield-DropdownMenuEndIconDelegate, reason: not valid java name */
 | |
|     /* synthetic */ void m277x3aefa0f8() {
 | |
|         updateDropdownPopupDirty();
 | |
|         setEndIconChecked(false);
 | |
|     }
 | |
| 
 | |
|     private boolean isDropdownPopupActive() {
 | |
|         long currentTimeMillis = System.currentTimeMillis() - this.dropdownPopupActivatedAt;
 | |
|         return currentTimeMillis < 0 || currentTimeMillis > 300;
 | |
|     }
 | |
| 
 | |
|     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() {
 | |
|         this.dropdownPopupDirty = true;
 | |
|         this.dropdownPopupActivatedAt = System.currentTimeMillis();
 | |
|     }
 | |
| 
 | |
|     private void setEndIconChecked(boolean z) {
 | |
|         if (this.isEndIconChecked != z) {
 | |
|             this.isEndIconChecked = z;
 | |
|             this.fadeInAnim.cancel();
 | |
|             this.fadeOutAnim.start();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void initAnimators() {
 | |
|         this.fadeInAnim = getAlphaAnimator(this.animationFadeInDuration, 0.0f, 1.0f);
 | |
|         ValueAnimator alphaAnimator = getAlphaAnimator(this.animationFadeOutDuration, 1.0f, 0.0f);
 | |
|         this.fadeOutAnim = alphaAnimator;
 | |
|         alphaAnimator.addListener(new AnimatorListenerAdapter() { // from class: com.google.android.material.textfield.DropdownMenuEndIconDelegate.1
 | |
|             @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
 | |
|             public void onAnimationEnd(Animator animator) {
 | |
|                 DropdownMenuEndIconDelegate.this.refreshIconState();
 | |
|                 DropdownMenuEndIconDelegate.this.fadeInAnim.start();
 | |
|             }
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     private ValueAnimator getAlphaAnimator(int i, float... fArr) {
 | |
|         ValueAnimator ofFloat = ValueAnimator.ofFloat(fArr);
 | |
|         ofFloat.setInterpolator(this.animationFadeInterpolator);
 | |
|         ofFloat.setDuration(i);
 | |
|         ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.google.android.material.textfield.DropdownMenuEndIconDelegate$$ExternalSyntheticLambda3
 | |
|             @Override // android.animation.ValueAnimator.AnimatorUpdateListener
 | |
|             public final void onAnimationUpdate(ValueAnimator valueAnimator) {
 | |
|                 DropdownMenuEndIconDelegate.this.m272x6b943a83(valueAnimator);
 | |
|             }
 | |
|         });
 | |
|         return ofFloat;
 | |
|     }
 | |
| 
 | |
|     /* renamed from: lambda$getAlphaAnimator$6$com-google-android-material-textfield-DropdownMenuEndIconDelegate, reason: not valid java name */
 | |
|     /* synthetic */ void m272x6b943a83(ValueAnimator valueAnimator) {
 | |
|         this.endIconView.setAlpha(((Float) valueAnimator.getAnimatedValue()).floatValue());
 | |
|     }
 | |
| }
 |