117 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package com.google.android.material.textfield;
 | |
| 
 | |
| import android.content.res.ColorStateList;
 | |
| import android.graphics.PorterDuff;
 | |
| import android.graphics.drawable.Drawable;
 | |
| import android.os.Build;
 | |
| import android.view.View;
 | |
| import android.widget.ImageView;
 | |
| import androidx.core.graphics.drawable.DrawableCompat;
 | |
| import androidx.core.view.ViewCompat;
 | |
| import com.google.android.material.internal.CheckableImageButton;
 | |
| import com.google.android.material.internal.ViewUtils;
 | |
| import com.google.android.material.ripple.RippleUtils;
 | |
| import java.util.Arrays;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| class IconHelper {
 | |
|     private IconHelper() {
 | |
|     }
 | |
| 
 | |
|     static void setIconOnClickListener(CheckableImageButton checkableImageButton, View.OnClickListener onClickListener, View.OnLongClickListener onLongClickListener) {
 | |
|         checkableImageButton.setOnClickListener(onClickListener);
 | |
|         setIconClickable(checkableImageButton, onLongClickListener);
 | |
|     }
 | |
| 
 | |
|     static void setIconOnLongClickListener(CheckableImageButton checkableImageButton, View.OnLongClickListener onLongClickListener) {
 | |
|         checkableImageButton.setOnLongClickListener(onLongClickListener);
 | |
|         setIconClickable(checkableImageButton, onLongClickListener);
 | |
|     }
 | |
| 
 | |
|     private static void setIconClickable(CheckableImageButton checkableImageButton, View.OnLongClickListener onLongClickListener) {
 | |
|         boolean hasOnClickListeners = ViewCompat.hasOnClickListeners(checkableImageButton);
 | |
|         boolean z = onLongClickListener != null;
 | |
|         boolean z2 = hasOnClickListeners || z;
 | |
|         checkableImageButton.setFocusable(z2);
 | |
|         checkableImageButton.setClickable(hasOnClickListeners);
 | |
|         checkableImageButton.setPressable(hasOnClickListeners);
 | |
|         checkableImageButton.setLongClickable(z);
 | |
|         ViewCompat.setImportantForAccessibility(checkableImageButton, z2 ? 1 : 2);
 | |
|     }
 | |
| 
 | |
|     static void applyIconTint(TextInputLayout textInputLayout, CheckableImageButton checkableImageButton, ColorStateList colorStateList, PorterDuff.Mode mode) {
 | |
|         Drawable drawable = checkableImageButton.getDrawable();
 | |
|         if (drawable != null) {
 | |
|             drawable = DrawableCompat.wrap(drawable).mutate();
 | |
|             if (colorStateList != null && colorStateList.isStateful()) {
 | |
|                 DrawableCompat.setTintList(drawable, ColorStateList.valueOf(colorStateList.getColorForState(mergeIconState(textInputLayout, checkableImageButton), colorStateList.getDefaultColor())));
 | |
|             } else {
 | |
|                 DrawableCompat.setTintList(drawable, colorStateList);
 | |
|             }
 | |
|             if (mode != null) {
 | |
|                 DrawableCompat.setTintMode(drawable, mode);
 | |
|             }
 | |
|         }
 | |
|         if (checkableImageButton.getDrawable() != drawable) {
 | |
|             checkableImageButton.setImageDrawable(drawable);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static void refreshIconDrawableState(TextInputLayout textInputLayout, CheckableImageButton checkableImageButton, ColorStateList colorStateList) {
 | |
|         Drawable drawable = checkableImageButton.getDrawable();
 | |
|         if (checkableImageButton.getDrawable() == null || colorStateList == null || !colorStateList.isStateful()) {
 | |
|             return;
 | |
|         }
 | |
|         int colorForState = colorStateList.getColorForState(mergeIconState(textInputLayout, checkableImageButton), colorStateList.getDefaultColor());
 | |
|         Drawable mutate = DrawableCompat.wrap(drawable).mutate();
 | |
|         DrawableCompat.setTintList(mutate, ColorStateList.valueOf(colorForState));
 | |
|         checkableImageButton.setImageDrawable(mutate);
 | |
|     }
 | |
| 
 | |
|     private static int[] mergeIconState(TextInputLayout textInputLayout, CheckableImageButton checkableImageButton) {
 | |
|         int[] drawableState = textInputLayout.getDrawableState();
 | |
|         int[] drawableState2 = checkableImageButton.getDrawableState();
 | |
|         int length = drawableState.length;
 | |
|         int[] copyOf = Arrays.copyOf(drawableState, drawableState.length + drawableState2.length);
 | |
|         System.arraycopy(drawableState2, 0, copyOf, length, drawableState2.length);
 | |
|         return copyOf;
 | |
|     }
 | |
| 
 | |
|     static void setCompatRippleBackgroundIfNeeded(CheckableImageButton checkableImageButton) {
 | |
|         if (Build.VERSION.SDK_INT <= 22) {
 | |
|             checkableImageButton.setBackground(RippleUtils.createOvalRippleLollipop(checkableImageButton.getContext(), (int) ViewUtils.dpToPx(checkableImageButton.getContext(), 4)));
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static void setIconMinSize(CheckableImageButton checkableImageButton, int i) {
 | |
|         checkableImageButton.setMinimumWidth(i);
 | |
|         checkableImageButton.setMinimumHeight(i);
 | |
|     }
 | |
| 
 | |
|     static void setIconScaleType(CheckableImageButton checkableImageButton, ImageView.ScaleType scaleType) {
 | |
|         checkableImageButton.setScaleType(scaleType);
 | |
|     }
 | |
| 
 | |
|     static ImageView.ScaleType convertScaleType(int i) {
 | |
|         if (i == 0) {
 | |
|             return ImageView.ScaleType.FIT_XY;
 | |
|         }
 | |
|         if (i == 1) {
 | |
|             return ImageView.ScaleType.FIT_START;
 | |
|         }
 | |
|         if (i == 2) {
 | |
|             return ImageView.ScaleType.FIT_CENTER;
 | |
|         }
 | |
|         if (i == 3) {
 | |
|             return ImageView.ScaleType.FIT_END;
 | |
|         }
 | |
|         if (i == 5) {
 | |
|             return ImageView.ScaleType.CENTER_CROP;
 | |
|         }
 | |
|         if (i == 6) {
 | |
|             return ImageView.ScaleType.CENTER_INSIDE;
 | |
|         }
 | |
|         return ImageView.ScaleType.CENTER;
 | |
|     }
 | |
| }
 |