310 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			310 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package com.google.android.material.materialswitch;
 | |
| 
 | |
| import android.content.Context;
 | |
| import android.content.res.ColorStateList;
 | |
| import android.graphics.PorterDuff;
 | |
| import android.graphics.drawable.Drawable;
 | |
| import android.graphics.drawable.LayerDrawable;
 | |
| import android.util.AttributeSet;
 | |
| import androidx.appcompat.content.res.AppCompatResources;
 | |
| import androidx.appcompat.widget.SwitchCompat;
 | |
| import androidx.core.graphics.ColorUtils;
 | |
| import androidx.core.graphics.drawable.DrawableCompat;
 | |
| import com.google.android.material.R;
 | |
| import com.google.android.material.drawable.DrawableUtils;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| public class MaterialSwitch extends SwitchCompat {
 | |
|     private static final int DEF_STYLE_RES = R.style.Widget_Material3_CompoundButton_MaterialSwitch;
 | |
|     private static final int[] STATE_SET_WITH_ICON = {R.attr.state_with_icon};
 | |
|     private int[] currentStateChecked;
 | |
|     private int[] currentStateUnchecked;
 | |
|     private Drawable thumbDrawable;
 | |
|     private Drawable thumbIconDrawable;
 | |
|     private int thumbIconSize;
 | |
|     private ColorStateList thumbIconTintList;
 | |
|     private PorterDuff.Mode thumbIconTintMode;
 | |
|     private ColorStateList thumbTintList;
 | |
|     private Drawable trackDecorationDrawable;
 | |
|     private ColorStateList trackDecorationTintList;
 | |
|     private PorterDuff.Mode trackDecorationTintMode;
 | |
|     private Drawable trackDrawable;
 | |
|     private ColorStateList trackTintList;
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public Drawable getThumbDrawable() {
 | |
|         return this.thumbDrawable;
 | |
|     }
 | |
| 
 | |
|     public Drawable getThumbIconDrawable() {
 | |
|         return this.thumbIconDrawable;
 | |
|     }
 | |
| 
 | |
|     public int getThumbIconSize() {
 | |
|         return this.thumbIconSize;
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getThumbIconTintList() {
 | |
|         return this.thumbIconTintList;
 | |
|     }
 | |
| 
 | |
|     public PorterDuff.Mode getThumbIconTintMode() {
 | |
|         return this.thumbIconTintMode;
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public ColorStateList getThumbTintList() {
 | |
|         return this.thumbTintList;
 | |
|     }
 | |
| 
 | |
|     public Drawable getTrackDecorationDrawable() {
 | |
|         return this.trackDecorationDrawable;
 | |
|     }
 | |
| 
 | |
|     public ColorStateList getTrackDecorationTintList() {
 | |
|         return this.trackDecorationTintList;
 | |
|     }
 | |
| 
 | |
|     public PorterDuff.Mode getTrackDecorationTintMode() {
 | |
|         return this.trackDecorationTintMode;
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public Drawable getTrackDrawable() {
 | |
|         return this.trackDrawable;
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public ColorStateList getTrackTintList() {
 | |
|         return this.trackTintList;
 | |
|     }
 | |
| 
 | |
|     public MaterialSwitch(Context context) {
 | |
|         this(context, null);
 | |
|     }
 | |
| 
 | |
|     public MaterialSwitch(Context context, AttributeSet attributeSet) {
 | |
|         this(context, attributeSet, R.attr.materialSwitchStyle);
 | |
|     }
 | |
| 
 | |
|     /* JADX WARN: Illegal instructions before constructor call */
 | |
|     /*
 | |
|         Code decompiled incorrectly, please refer to instructions dump.
 | |
|         To view partially-correct add '--show-bad-code' argument
 | |
|     */
 | |
|     public MaterialSwitch(android.content.Context r8, android.util.AttributeSet r9, int r10) {
 | |
|         /*
 | |
|             r7 = this;
 | |
|             int r4 = com.google.android.material.materialswitch.MaterialSwitch.DEF_STYLE_RES
 | |
|             android.content.Context r8 = com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap(r8, r9, r10, r4)
 | |
|             r7.<init>(r8, r9, r10)
 | |
|             r8 = -1
 | |
|             r7.thumbIconSize = r8
 | |
|             android.content.Context r0 = r7.getContext()
 | |
|             android.graphics.drawable.Drawable r1 = super.getThumbDrawable()
 | |
|             r7.thumbDrawable = r1
 | |
|             android.content.res.ColorStateList r1 = super.getThumbTintList()
 | |
|             r7.thumbTintList = r1
 | |
|             r1 = 0
 | |
|             super.setThumbTintList(r1)
 | |
|             android.graphics.drawable.Drawable r2 = super.getTrackDrawable()
 | |
|             r7.trackDrawable = r2
 | |
|             android.content.res.ColorStateList r2 = super.getTrackTintList()
 | |
|             r7.trackTintList = r2
 | |
|             super.setTrackTintList(r1)
 | |
|             int[] r2 = com.google.android.material.R.styleable.MaterialSwitch
 | |
|             r6 = 0
 | |
|             int[] r5 = new int[r6]
 | |
|             r1 = r9
 | |
|             r3 = r10
 | |
|             androidx.appcompat.widget.TintTypedArray r9 = com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(r0, r1, r2, r3, r4, r5)
 | |
|             int r10 = com.google.android.material.R.styleable.MaterialSwitch_thumbIcon
 | |
|             android.graphics.drawable.Drawable r10 = r9.getDrawable(r10)
 | |
|             r7.thumbIconDrawable = r10
 | |
|             int r10 = com.google.android.material.R.styleable.MaterialSwitch_thumbIconSize
 | |
|             int r10 = r9.getDimensionPixelSize(r10, r8)
 | |
|             r7.thumbIconSize = r10
 | |
|             int r10 = com.google.android.material.R.styleable.MaterialSwitch_thumbIconTint
 | |
|             android.content.res.ColorStateList r10 = r9.getColorStateList(r10)
 | |
|             r7.thumbIconTintList = r10
 | |
|             int r10 = com.google.android.material.R.styleable.MaterialSwitch_thumbIconTintMode
 | |
|             int r10 = r9.getInt(r10, r8)
 | |
|             android.graphics.PorterDuff$Mode r0 = android.graphics.PorterDuff.Mode.SRC_IN
 | |
|             android.graphics.PorterDuff$Mode r10 = com.google.android.material.internal.ViewUtils.parseTintMode(r10, r0)
 | |
|             r7.thumbIconTintMode = r10
 | |
|             int r10 = com.google.android.material.R.styleable.MaterialSwitch_trackDecoration
 | |
|             android.graphics.drawable.Drawable r10 = r9.getDrawable(r10)
 | |
|             r7.trackDecorationDrawable = r10
 | |
|             int r10 = com.google.android.material.R.styleable.MaterialSwitch_trackDecorationTint
 | |
|             android.content.res.ColorStateList r10 = r9.getColorStateList(r10)
 | |
|             r7.trackDecorationTintList = r10
 | |
|             int r10 = com.google.android.material.R.styleable.MaterialSwitch_trackDecorationTintMode
 | |
|             int r8 = r9.getInt(r10, r8)
 | |
|             android.graphics.PorterDuff$Mode r10 = android.graphics.PorterDuff.Mode.SRC_IN
 | |
|             android.graphics.PorterDuff$Mode r8 = com.google.android.material.internal.ViewUtils.parseTintMode(r8, r10)
 | |
|             r7.trackDecorationTintMode = r8
 | |
|             r9.recycle()
 | |
|             r7.setEnforceSwitchWidth(r6)
 | |
|             r7.refreshThumbDrawable()
 | |
|             r7.refreshTrackDrawable()
 | |
|             return
 | |
|         */
 | |
|         throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.materialswitch.MaterialSwitch.<init>(android.content.Context, android.util.AttributeSet, int):void");
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public void invalidate() {
 | |
|         updateDrawableTints();
 | |
|         super.invalidate();
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat, android.widget.CompoundButton, android.widget.TextView, android.view.View
 | |
|     protected int[] onCreateDrawableState(int i) {
 | |
|         int[] onCreateDrawableState = super.onCreateDrawableState(i + 1);
 | |
|         if (this.thumbIconDrawable != null) {
 | |
|             mergeDrawableStates(onCreateDrawableState, STATE_SET_WITH_ICON);
 | |
|         }
 | |
|         this.currentStateUnchecked = DrawableUtils.getUncheckedState(onCreateDrawableState);
 | |
|         this.currentStateChecked = DrawableUtils.getCheckedState(onCreateDrawableState);
 | |
|         return onCreateDrawableState;
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public void setThumbDrawable(Drawable drawable) {
 | |
|         this.thumbDrawable = drawable;
 | |
|         refreshThumbDrawable();
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public void setThumbTintList(ColorStateList colorStateList) {
 | |
|         this.thumbTintList = colorStateList;
 | |
|         refreshThumbDrawable();
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public void setThumbTintMode(PorterDuff.Mode mode) {
 | |
|         super.setThumbTintMode(mode);
 | |
|         refreshThumbDrawable();
 | |
|     }
 | |
| 
 | |
|     public void setThumbIconResource(int i) {
 | |
|         setThumbIconDrawable(AppCompatResources.getDrawable(getContext(), i));
 | |
|     }
 | |
| 
 | |
|     public void setThumbIconDrawable(Drawable drawable) {
 | |
|         this.thumbIconDrawable = drawable;
 | |
|         refreshThumbDrawable();
 | |
|     }
 | |
| 
 | |
|     public void setThumbIconSize(int i) {
 | |
|         if (this.thumbIconSize != i) {
 | |
|             this.thumbIconSize = i;
 | |
|             refreshThumbDrawable();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setThumbIconTintList(ColorStateList colorStateList) {
 | |
|         this.thumbIconTintList = colorStateList;
 | |
|         refreshThumbDrawable();
 | |
|     }
 | |
| 
 | |
|     public void setThumbIconTintMode(PorterDuff.Mode mode) {
 | |
|         this.thumbIconTintMode = mode;
 | |
|         refreshThumbDrawable();
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public void setTrackDrawable(Drawable drawable) {
 | |
|         this.trackDrawable = drawable;
 | |
|         refreshTrackDrawable();
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public void setTrackTintList(ColorStateList colorStateList) {
 | |
|         this.trackTintList = colorStateList;
 | |
|         refreshTrackDrawable();
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.appcompat.widget.SwitchCompat
 | |
|     public void setTrackTintMode(PorterDuff.Mode mode) {
 | |
|         super.setTrackTintMode(mode);
 | |
|         refreshTrackDrawable();
 | |
|     }
 | |
| 
 | |
|     public void setTrackDecorationResource(int i) {
 | |
|         setTrackDecorationDrawable(AppCompatResources.getDrawable(getContext(), i));
 | |
|     }
 | |
| 
 | |
|     public void setTrackDecorationDrawable(Drawable drawable) {
 | |
|         this.trackDecorationDrawable = drawable;
 | |
|         refreshTrackDrawable();
 | |
|     }
 | |
| 
 | |
|     public void setTrackDecorationTintList(ColorStateList colorStateList) {
 | |
|         this.trackDecorationTintList = colorStateList;
 | |
|         refreshTrackDrawable();
 | |
|     }
 | |
| 
 | |
|     public void setTrackDecorationTintMode(PorterDuff.Mode mode) {
 | |
|         this.trackDecorationTintMode = mode;
 | |
|         refreshTrackDrawable();
 | |
|     }
 | |
| 
 | |
|     private void refreshThumbDrawable() {
 | |
|         this.thumbDrawable = DrawableUtils.createTintableDrawableIfNeeded(this.thumbDrawable, this.thumbTintList, getThumbTintMode());
 | |
|         this.thumbIconDrawable = DrawableUtils.createTintableDrawableIfNeeded(this.thumbIconDrawable, this.thumbIconTintList, this.thumbIconTintMode);
 | |
|         updateDrawableTints();
 | |
|         Drawable drawable = this.thumbDrawable;
 | |
|         Drawable drawable2 = this.thumbIconDrawable;
 | |
|         int i = this.thumbIconSize;
 | |
|         super.setThumbDrawable(DrawableUtils.compositeTwoLayeredDrawable(drawable, drawable2, i, i));
 | |
|         refreshDrawableState();
 | |
|     }
 | |
| 
 | |
|     private void refreshTrackDrawable() {
 | |
|         this.trackDrawable = DrawableUtils.createTintableDrawableIfNeeded(this.trackDrawable, this.trackTintList, getTrackTintMode());
 | |
|         this.trackDecorationDrawable = DrawableUtils.createTintableDrawableIfNeeded(this.trackDecorationDrawable, this.trackDecorationTintList, this.trackDecorationTintMode);
 | |
|         updateDrawableTints();
 | |
|         Drawable drawable = this.trackDrawable;
 | |
|         if (drawable != null && this.trackDecorationDrawable != null) {
 | |
|             drawable = new LayerDrawable(new Drawable[]{this.trackDrawable, this.trackDecorationDrawable});
 | |
|         } else if (drawable == null) {
 | |
|             drawable = this.trackDecorationDrawable;
 | |
|         }
 | |
|         if (drawable != null) {
 | |
|             setSwitchMinWidth(drawable.getIntrinsicWidth());
 | |
|         }
 | |
|         super.setTrackDrawable(drawable);
 | |
|     }
 | |
| 
 | |
|     private void updateDrawableTints() {
 | |
|         if (this.thumbTintList == null && this.thumbIconTintList == null && this.trackTintList == null && this.trackDecorationTintList == null) {
 | |
|             return;
 | |
|         }
 | |
|         float thumbPosition = getThumbPosition();
 | |
|         ColorStateList colorStateList = this.thumbTintList;
 | |
|         if (colorStateList != null) {
 | |
|             setInterpolatedDrawableTintIfPossible(this.thumbDrawable, colorStateList, this.currentStateUnchecked, this.currentStateChecked, thumbPosition);
 | |
|         }
 | |
|         ColorStateList colorStateList2 = this.thumbIconTintList;
 | |
|         if (colorStateList2 != null) {
 | |
|             setInterpolatedDrawableTintIfPossible(this.thumbIconDrawable, colorStateList2, this.currentStateUnchecked, this.currentStateChecked, thumbPosition);
 | |
|         }
 | |
|         ColorStateList colorStateList3 = this.trackTintList;
 | |
|         if (colorStateList3 != null) {
 | |
|             setInterpolatedDrawableTintIfPossible(this.trackDrawable, colorStateList3, this.currentStateUnchecked, this.currentStateChecked, thumbPosition);
 | |
|         }
 | |
|         ColorStateList colorStateList4 = this.trackDecorationTintList;
 | |
|         if (colorStateList4 != null) {
 | |
|             setInterpolatedDrawableTintIfPossible(this.trackDecorationDrawable, colorStateList4, this.currentStateUnchecked, this.currentStateChecked, thumbPosition);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private static void setInterpolatedDrawableTintIfPossible(Drawable drawable, ColorStateList colorStateList, int[] iArr, int[] iArr2, float f) {
 | |
|         if (drawable == null || colorStateList == null) {
 | |
|             return;
 | |
|         }
 | |
|         DrawableCompat.setTint(drawable, ColorUtils.blendARGB(colorStateList.getColorForState(iArr, 0), colorStateList.getColorForState(iArr2, 0), f));
 | |
|     }
 | |
| }
 |