ADD week 5
This commit is contained in:
		| @@ -0,0 +1,133 @@ | ||||
| package com.google.android.material.ripple; | ||||
|  | ||||
| import android.content.res.ColorStateList; | ||||
| import android.graphics.Canvas; | ||||
| import android.graphics.ColorFilter; | ||||
| import android.graphics.PorterDuff; | ||||
| import android.graphics.Rect; | ||||
| import android.graphics.drawable.Drawable; | ||||
| import androidx.core.graphics.drawable.TintAwareDrawable; | ||||
| import com.google.android.material.shape.MaterialShapeDrawable; | ||||
| import com.google.android.material.shape.ShapeAppearanceModel; | ||||
| import com.google.android.material.shape.Shapeable; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public class RippleDrawableCompat extends Drawable implements Shapeable, TintAwareDrawable { | ||||
|     private RippleDrawableCompatState drawableState; | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable | ||||
|     public Drawable.ConstantState getConstantState() { | ||||
|         return this.drawableState; | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable | ||||
|     public boolean isStateful() { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     public RippleDrawableCompat(ShapeAppearanceModel shapeAppearanceModel) { | ||||
|         this(new RippleDrawableCompatState(new MaterialShapeDrawable(shapeAppearanceModel))); | ||||
|     } | ||||
|  | ||||
|     private RippleDrawableCompat(RippleDrawableCompatState rippleDrawableCompatState) { | ||||
|         this.drawableState = rippleDrawableCompatState; | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable, androidx.core.graphics.drawable.TintAwareDrawable | ||||
|     public void setTint(int i) { | ||||
|         this.drawableState.delegate.setTint(i); | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable, androidx.core.graphics.drawable.TintAwareDrawable | ||||
|     public void setTintMode(PorterDuff.Mode mode) { | ||||
|         this.drawableState.delegate.setTintMode(mode); | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable, androidx.core.graphics.drawable.TintAwareDrawable | ||||
|     public void setTintList(ColorStateList colorStateList) { | ||||
|         this.drawableState.delegate.setTintList(colorStateList); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.shape.Shapeable | ||||
|     public void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel) { | ||||
|         this.drawableState.delegate.setShapeAppearanceModel(shapeAppearanceModel); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.shape.Shapeable | ||||
|     public ShapeAppearanceModel getShapeAppearanceModel() { | ||||
|         return this.drawableState.delegate.getShapeAppearanceModel(); | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable | ||||
|     protected boolean onStateChange(int[] iArr) { | ||||
|         boolean onStateChange = super.onStateChange(iArr); | ||||
|         if (this.drawableState.delegate.setState(iArr)) { | ||||
|             onStateChange = true; | ||||
|         } | ||||
|         boolean shouldDrawRippleCompat = RippleUtils.shouldDrawRippleCompat(iArr); | ||||
|         if (this.drawableState.shouldDrawDelegate == shouldDrawRippleCompat) { | ||||
|             return onStateChange; | ||||
|         } | ||||
|         this.drawableState.shouldDrawDelegate = shouldDrawRippleCompat; | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable | ||||
|     public void draw(Canvas canvas) { | ||||
|         if (this.drawableState.shouldDrawDelegate) { | ||||
|             this.drawableState.delegate.draw(canvas); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable | ||||
|     protected void onBoundsChange(Rect rect) { | ||||
|         super.onBoundsChange(rect); | ||||
|         this.drawableState.delegate.setBounds(rect); | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable | ||||
|     public RippleDrawableCompat mutate() { | ||||
|         this.drawableState = new RippleDrawableCompatState(this.drawableState); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable | ||||
|     public void setAlpha(int i) { | ||||
|         this.drawableState.delegate.setAlpha(i); | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable | ||||
|     public void setColorFilter(ColorFilter colorFilter) { | ||||
|         this.drawableState.delegate.setColorFilter(colorFilter); | ||||
|     } | ||||
|  | ||||
|     @Override // android.graphics.drawable.Drawable | ||||
|     public int getOpacity() { | ||||
|         return this.drawableState.delegate.getOpacity(); | ||||
|     } | ||||
|  | ||||
|     static final class RippleDrawableCompatState extends Drawable.ConstantState { | ||||
|         MaterialShapeDrawable delegate; | ||||
|         boolean shouldDrawDelegate; | ||||
|  | ||||
|         @Override // android.graphics.drawable.Drawable.ConstantState | ||||
|         public int getChangingConfigurations() { | ||||
|             return 0; | ||||
|         } | ||||
|  | ||||
|         public RippleDrawableCompatState(MaterialShapeDrawable materialShapeDrawable) { | ||||
|             this.delegate = materialShapeDrawable; | ||||
|             this.shouldDrawDelegate = false; | ||||
|         } | ||||
|  | ||||
|         public RippleDrawableCompatState(RippleDrawableCompatState rippleDrawableCompatState) { | ||||
|             this.delegate = (MaterialShapeDrawable) rippleDrawableCompatState.delegate.getConstantState().newDrawable(); | ||||
|             this.shouldDrawDelegate = rippleDrawableCompatState.shouldDrawDelegate; | ||||
|         } | ||||
|  | ||||
|         @Override // android.graphics.drawable.Drawable.ConstantState | ||||
|         public RippleDrawableCompat newDrawable() { | ||||
|             return new RippleDrawableCompat(new RippleDrawableCompatState(this)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,100 @@ | ||||
| package com.google.android.material.ripple; | ||||
|  | ||||
| import android.R; | ||||
| import android.content.Context; | ||||
| import android.content.res.ColorStateList; | ||||
| import android.graphics.Color; | ||||
| import android.graphics.drawable.Drawable; | ||||
| import android.graphics.drawable.GradientDrawable; | ||||
| import android.graphics.drawable.InsetDrawable; | ||||
| import android.graphics.drawable.RippleDrawable; | ||||
| import android.os.Build; | ||||
| import android.util.Log; | ||||
| import android.util.StateSet; | ||||
| import androidx.core.graphics.ColorUtils; | ||||
| import com.google.android.material.color.MaterialColors; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public class RippleUtils { | ||||
|     static final String TRANSPARENT_DEFAULT_COLOR_WARNING = "Use a non-transparent color for the default color as it will be used to finish ripple animations."; | ||||
|     public static final boolean USE_FRAMEWORK_RIPPLE = true; | ||||
|     private static final int[] PRESSED_STATE_SET = {R.attr.state_pressed}; | ||||
|     private static final int[] HOVERED_FOCUSED_STATE_SET = {R.attr.state_hovered, R.attr.state_focused}; | ||||
|     private static final int[] FOCUSED_STATE_SET = {R.attr.state_focused}; | ||||
|     private static final int[] HOVERED_STATE_SET = {R.attr.state_hovered}; | ||||
|     private static final int[] SELECTED_PRESSED_STATE_SET = {R.attr.state_selected, R.attr.state_pressed}; | ||||
|     private static final int[] SELECTED_HOVERED_FOCUSED_STATE_SET = {R.attr.state_selected, R.attr.state_hovered, R.attr.state_focused}; | ||||
|     private static final int[] SELECTED_FOCUSED_STATE_SET = {R.attr.state_selected, R.attr.state_focused}; | ||||
|     private static final int[] SELECTED_HOVERED_STATE_SET = {R.attr.state_selected, R.attr.state_hovered}; | ||||
|     private static final int[] SELECTED_STATE_SET = {R.attr.state_selected}; | ||||
|     private static final int[] ENABLED_PRESSED_STATE_SET = {R.attr.state_enabled, R.attr.state_pressed}; | ||||
|     static final String LOG_TAG = "RippleUtils"; | ||||
|  | ||||
|     private RippleUtils() { | ||||
|     } | ||||
|  | ||||
|     public static ColorStateList convertToRippleDrawableColor(ColorStateList colorStateList) { | ||||
|         if (USE_FRAMEWORK_RIPPLE) { | ||||
|             int[] iArr = FOCUSED_STATE_SET; | ||||
|             return new ColorStateList(new int[][]{SELECTED_STATE_SET, iArr, StateSet.NOTHING}, new int[]{getColorForState(colorStateList, SELECTED_PRESSED_STATE_SET), getColorForState(colorStateList, iArr), getColorForState(colorStateList, PRESSED_STATE_SET)}); | ||||
|         } | ||||
|         int[] iArr2 = SELECTED_PRESSED_STATE_SET; | ||||
|         int[] iArr3 = SELECTED_HOVERED_FOCUSED_STATE_SET; | ||||
|         int[] iArr4 = SELECTED_FOCUSED_STATE_SET; | ||||
|         int[] iArr5 = SELECTED_HOVERED_STATE_SET; | ||||
|         int[] iArr6 = PRESSED_STATE_SET; | ||||
|         int[] iArr7 = HOVERED_FOCUSED_STATE_SET; | ||||
|         int[] iArr8 = FOCUSED_STATE_SET; | ||||
|         int[] iArr9 = HOVERED_STATE_SET; | ||||
|         return new ColorStateList(new int[][]{iArr2, iArr3, iArr4, iArr5, SELECTED_STATE_SET, iArr6, iArr7, iArr8, iArr9, StateSet.NOTHING}, new int[]{getColorForState(colorStateList, iArr2), getColorForState(colorStateList, iArr3), getColorForState(colorStateList, iArr4), getColorForState(colorStateList, iArr5), 0, getColorForState(colorStateList, iArr6), getColorForState(colorStateList, iArr7), getColorForState(colorStateList, iArr8), getColorForState(colorStateList, iArr9), 0}); | ||||
|     } | ||||
|  | ||||
|     public static ColorStateList sanitizeRippleDrawableColor(ColorStateList colorStateList) { | ||||
|         if (colorStateList != null) { | ||||
|             if (Build.VERSION.SDK_INT >= 22 && Build.VERSION.SDK_INT <= 27 && Color.alpha(colorStateList.getDefaultColor()) == 0 && Color.alpha(colorStateList.getColorForState(ENABLED_PRESSED_STATE_SET, 0)) != 0) { | ||||
|                 Log.w(LOG_TAG, TRANSPARENT_DEFAULT_COLOR_WARNING); | ||||
|             } | ||||
|             return colorStateList; | ||||
|         } | ||||
|         return ColorStateList.valueOf(0); | ||||
|     } | ||||
|  | ||||
|     public static boolean shouldDrawRippleCompat(int[] iArr) { | ||||
|         boolean z = false; | ||||
|         boolean z2 = false; | ||||
|         for (int i : iArr) { | ||||
|             if (i == 16842910) { | ||||
|                 z = true; | ||||
|             } else if (i == 16842908 || i == 16842919 || i == 16843623) { | ||||
|                 z2 = true; | ||||
|             } | ||||
|         } | ||||
|         return z && z2; | ||||
|     } | ||||
|  | ||||
|     public static Drawable createOvalRippleLollipop(Context context, int i) { | ||||
|         return RippleUtilsLollipop.createOvalRipple(context, i); | ||||
|     } | ||||
|  | ||||
|     private static int getColorForState(ColorStateList colorStateList, int[] iArr) { | ||||
|         int colorForState = colorStateList != null ? colorStateList.getColorForState(iArr, colorStateList.getDefaultColor()) : 0; | ||||
|         return USE_FRAMEWORK_RIPPLE ? doubleAlpha(colorForState) : colorForState; | ||||
|     } | ||||
|  | ||||
|     private static int doubleAlpha(int i) { | ||||
|         return ColorUtils.setAlphaComponent(i, Math.min(Color.alpha(i) * 2, 255)); | ||||
|     } | ||||
|  | ||||
|     private static class RippleUtilsLollipop { | ||||
|         private RippleUtilsLollipop() { | ||||
|         } | ||||
|  | ||||
|         /* JADX INFO: Access modifiers changed from: private */ | ||||
|         public static Drawable createOvalRipple(Context context, int i) { | ||||
|             GradientDrawable gradientDrawable = new GradientDrawable(); | ||||
|             gradientDrawable.setColor(-1); | ||||
|             gradientDrawable.setShape(1); | ||||
|             return new RippleDrawable(MaterialColors.getColorStateList(context, com.google.android.material.R.attr.colorControlHighlight, ColorStateList.valueOf(0)), null, new InsetDrawable((Drawable) gradientDrawable, i, i, i, i)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user