ADD week 5
This commit is contained in:
		| @@ -0,0 +1,293 @@ | ||||
| package com.google.android.material.shadow; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.graphics.Canvas; | ||||
| import android.graphics.LinearGradient; | ||||
| import android.graphics.Paint; | ||||
| import android.graphics.Path; | ||||
| import android.graphics.RadialGradient; | ||||
| import android.graphics.Rect; | ||||
| import android.graphics.RectF; | ||||
| import android.graphics.Shader; | ||||
| import android.graphics.drawable.Drawable; | ||||
| import androidx.appcompat.graphics.drawable.DrawableWrapperCompat; | ||||
| import androidx.core.content.ContextCompat; | ||||
| import com.google.android.material.R; | ||||
|  | ||||
| @Deprecated | ||||
| /* loaded from: classes.dex */ | ||||
| public class ShadowDrawableWrapper extends DrawableWrapperCompat { | ||||
|     static final double COS_45 = Math.cos(Math.toRadians(45.0d)); | ||||
|     static final float SHADOW_BOTTOM_SCALE = 1.0f; | ||||
|     static final float SHADOW_HORIZ_SCALE = 0.5f; | ||||
|     static final float SHADOW_MULTIPLIER = 1.5f; | ||||
|     static final float SHADOW_TOP_SCALE = 0.25f; | ||||
|     private boolean addPaddingForCorners; | ||||
|     final RectF contentBounds; | ||||
|     float cornerRadius; | ||||
|     final Paint cornerShadowPaint; | ||||
|     Path cornerShadowPath; | ||||
|     private boolean dirty; | ||||
|     final Paint edgeShadowPaint; | ||||
|     float maxShadowSize; | ||||
|     private boolean printedShadowClipWarning; | ||||
|     float rawMaxShadowSize; | ||||
|     float rawShadowSize; | ||||
|     private float rotation; | ||||
|     private final int shadowEndColor; | ||||
|     private final int shadowMiddleColor; | ||||
|     float shadowSize; | ||||
|     private final int shadowStartColor; | ||||
|  | ||||
|     public static float calculateHorizontalPadding(float f, float f2, boolean z) { | ||||
|         return z ? (float) (f + ((1.0d - COS_45) * f2)) : f; | ||||
|     } | ||||
|  | ||||
|     public static float calculateVerticalPadding(float f, float f2, boolean z) { | ||||
|         return z ? (float) ((f * SHADOW_MULTIPLIER) + ((1.0d - COS_45) * f2)) : f * SHADOW_MULTIPLIER; | ||||
|     } | ||||
|  | ||||
|     public float getCornerRadius() { | ||||
|         return this.cornerRadius; | ||||
|     } | ||||
|  | ||||
|     public float getMaxShadowSize() { | ||||
|         return this.rawMaxShadowSize; | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable | ||||
|     public int getOpacity() { | ||||
|         return -3; | ||||
|     } | ||||
|  | ||||
|     public float getShadowSize() { | ||||
|         return this.rawShadowSize; | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable | ||||
|     protected void onBoundsChange(Rect rect) { | ||||
|         this.dirty = true; | ||||
|     } | ||||
|  | ||||
|     public ShadowDrawableWrapper(Context context, Drawable drawable, float f, float f2, float f3) { | ||||
|         super(drawable); | ||||
|         this.dirty = true; | ||||
|         this.addPaddingForCorners = true; | ||||
|         this.printedShadowClipWarning = false; | ||||
|         this.shadowStartColor = ContextCompat.getColor(context, R.color.design_fab_shadow_start_color); | ||||
|         this.shadowMiddleColor = ContextCompat.getColor(context, R.color.design_fab_shadow_mid_color); | ||||
|         this.shadowEndColor = ContextCompat.getColor(context, R.color.design_fab_shadow_end_color); | ||||
|         Paint paint = new Paint(5); | ||||
|         this.cornerShadowPaint = paint; | ||||
|         paint.setStyle(Paint.Style.FILL); | ||||
|         this.cornerRadius = Math.round(f); | ||||
|         this.contentBounds = new RectF(); | ||||
|         Paint paint2 = new Paint(paint); | ||||
|         this.edgeShadowPaint = paint2; | ||||
|         paint2.setAntiAlias(false); | ||||
|         setShadowSize(f2, f3); | ||||
|     } | ||||
|  | ||||
|     private static int toEven(float f) { | ||||
|         int round = Math.round(f); | ||||
|         return round % 2 == 1 ? round - 1 : round; | ||||
|     } | ||||
|  | ||||
|     public void setAddPaddingForCorners(boolean z) { | ||||
|         this.addPaddingForCorners = z; | ||||
|         invalidateSelf(); | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable | ||||
|     public void setAlpha(int i) { | ||||
|         super.setAlpha(i); | ||||
|         this.cornerShadowPaint.setAlpha(i); | ||||
|         this.edgeShadowPaint.setAlpha(i); | ||||
|     } | ||||
|  | ||||
|     public void setShadowSize(float f, float f2) { | ||||
|         if (f < 0.0f || f2 < 0.0f) { | ||||
|             throw new IllegalArgumentException("invalid shadow size"); | ||||
|         } | ||||
|         float even = toEven(f); | ||||
|         float even2 = toEven(f2); | ||||
|         if (even > even2) { | ||||
|             if (!this.printedShadowClipWarning) { | ||||
|                 this.printedShadowClipWarning = true; | ||||
|             } | ||||
|             even = even2; | ||||
|         } | ||||
|         if (this.rawShadowSize == even && this.rawMaxShadowSize == even2) { | ||||
|             return; | ||||
|         } | ||||
|         this.rawShadowSize = even; | ||||
|         this.rawMaxShadowSize = even2; | ||||
|         this.shadowSize = Math.round(even * SHADOW_MULTIPLIER); | ||||
|         this.maxShadowSize = even2; | ||||
|         this.dirty = true; | ||||
|         invalidateSelf(); | ||||
|     } | ||||
|  | ||||
|     public void setShadowSize(float f) { | ||||
|         setShadowSize(f, this.rawMaxShadowSize); | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable | ||||
|     public boolean getPadding(Rect rect) { | ||||
|         int ceil = (int) Math.ceil(calculateVerticalPadding(this.rawMaxShadowSize, this.cornerRadius, this.addPaddingForCorners)); | ||||
|         int ceil2 = (int) Math.ceil(calculateHorizontalPadding(this.rawMaxShadowSize, this.cornerRadius, this.addPaddingForCorners)); | ||||
|         rect.set(ceil2, ceil, ceil2, ceil); | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     public void setCornerRadius(float f) { | ||||
|         float round = Math.round(f); | ||||
|         if (this.cornerRadius == round) { | ||||
|             return; | ||||
|         } | ||||
|         this.cornerRadius = round; | ||||
|         this.dirty = true; | ||||
|         invalidateSelf(); | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable | ||||
|     public void draw(Canvas canvas) { | ||||
|         if (this.dirty) { | ||||
|             buildComponents(getBounds()); | ||||
|             this.dirty = false; | ||||
|         } | ||||
|         drawShadow(canvas); | ||||
|         super.draw(canvas); | ||||
|     } | ||||
|  | ||||
|     public final void setRotation(float f) { | ||||
|         if (this.rotation != f) { | ||||
|             this.rotation = f; | ||||
|             invalidateSelf(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void drawShadow(Canvas canvas) { | ||||
|         int i; | ||||
|         float f; | ||||
|         int i2; | ||||
|         float f2; | ||||
|         float f3; | ||||
|         float f4; | ||||
|         int save = canvas.save(); | ||||
|         canvas.rotate(this.rotation, this.contentBounds.centerX(), this.contentBounds.centerY()); | ||||
|         float f5 = this.cornerRadius; | ||||
|         float f6 = (-f5) - this.shadowSize; | ||||
|         float f7 = f5 * 2.0f; | ||||
|         boolean z = this.contentBounds.width() - f7 > 0.0f; | ||||
|         boolean z2 = this.contentBounds.height() - f7 > 0.0f; | ||||
|         float f8 = this.rawShadowSize; | ||||
|         float f9 = f5 / ((f8 - (0.5f * f8)) + f5); | ||||
|         float f10 = f5 / ((f8 - (SHADOW_TOP_SCALE * f8)) + f5); | ||||
|         float f11 = f5 / ((f8 - (f8 * 1.0f)) + f5); | ||||
|         int save2 = canvas.save(); | ||||
|         canvas.translate(this.contentBounds.left + f5, this.contentBounds.top + f5); | ||||
|         canvas.scale(f9, f10); | ||||
|         canvas.drawPath(this.cornerShadowPath, this.cornerShadowPaint); | ||||
|         if (z) { | ||||
|             canvas.scale(1.0f / f9, 1.0f); | ||||
|             i = save2; | ||||
|             f = f11; | ||||
|             i2 = save; | ||||
|             f2 = f10; | ||||
|             canvas.drawRect(0.0f, f6, this.contentBounds.width() - f7, -this.cornerRadius, this.edgeShadowPaint); | ||||
|         } else { | ||||
|             i = save2; | ||||
|             f = f11; | ||||
|             i2 = save; | ||||
|             f2 = f10; | ||||
|         } | ||||
|         canvas.restoreToCount(i); | ||||
|         int save3 = canvas.save(); | ||||
|         canvas.translate(this.contentBounds.right - f5, this.contentBounds.bottom - f5); | ||||
|         float f12 = f; | ||||
|         canvas.scale(f9, f12); | ||||
|         canvas.rotate(180.0f); | ||||
|         canvas.drawPath(this.cornerShadowPath, this.cornerShadowPaint); | ||||
|         if (z) { | ||||
|             canvas.scale(1.0f / f9, 1.0f); | ||||
|             f3 = f2; | ||||
|             f4 = f12; | ||||
|             canvas.drawRect(0.0f, f6, this.contentBounds.width() - f7, (-this.cornerRadius) + this.shadowSize, this.edgeShadowPaint); | ||||
|         } else { | ||||
|             f3 = f2; | ||||
|             f4 = f12; | ||||
|         } | ||||
|         canvas.restoreToCount(save3); | ||||
|         int save4 = canvas.save(); | ||||
|         canvas.translate(this.contentBounds.left + f5, this.contentBounds.bottom - f5); | ||||
|         canvas.scale(f9, f4); | ||||
|         canvas.rotate(270.0f); | ||||
|         canvas.drawPath(this.cornerShadowPath, this.cornerShadowPaint); | ||||
|         if (z2) { | ||||
|             canvas.scale(1.0f / f4, 1.0f); | ||||
|             canvas.drawRect(0.0f, f6, this.contentBounds.height() - f7, -this.cornerRadius, this.edgeShadowPaint); | ||||
|         } | ||||
|         canvas.restoreToCount(save4); | ||||
|         int save5 = canvas.save(); | ||||
|         canvas.translate(this.contentBounds.right - f5, this.contentBounds.top + f5); | ||||
|         float f13 = f3; | ||||
|         canvas.scale(f9, f13); | ||||
|         canvas.rotate(90.0f); | ||||
|         canvas.drawPath(this.cornerShadowPath, this.cornerShadowPaint); | ||||
|         if (z2) { | ||||
|             canvas.scale(1.0f / f13, 1.0f); | ||||
|             canvas.drawRect(0.0f, f6, this.contentBounds.height() - f7, -this.cornerRadius, this.edgeShadowPaint); | ||||
|         } | ||||
|         canvas.restoreToCount(save5); | ||||
|         canvas.restoreToCount(i2); | ||||
|     } | ||||
|  | ||||
|     private void buildShadowCorners() { | ||||
|         float f = this.cornerRadius; | ||||
|         RectF rectF = new RectF(-f, -f, f, f); | ||||
|         RectF rectF2 = new RectF(rectF); | ||||
|         float f2 = this.shadowSize; | ||||
|         rectF2.inset(-f2, -f2); | ||||
|         Path path = this.cornerShadowPath; | ||||
|         if (path == null) { | ||||
|             this.cornerShadowPath = new Path(); | ||||
|         } else { | ||||
|             path.reset(); | ||||
|         } | ||||
|         this.cornerShadowPath.setFillType(Path.FillType.EVEN_ODD); | ||||
|         this.cornerShadowPath.moveTo(-this.cornerRadius, 0.0f); | ||||
|         this.cornerShadowPath.rLineTo(-this.shadowSize, 0.0f); | ||||
|         this.cornerShadowPath.arcTo(rectF2, 180.0f, 90.0f, false); | ||||
|         this.cornerShadowPath.arcTo(rectF, 270.0f, -90.0f, false); | ||||
|         this.cornerShadowPath.close(); | ||||
|         float f3 = -rectF2.top; | ||||
|         if (f3 > 0.0f) { | ||||
|             float f4 = this.cornerRadius / f3; | ||||
|             this.cornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, f3, new int[]{0, this.shadowStartColor, this.shadowMiddleColor, this.shadowEndColor}, new float[]{0.0f, f4, ((1.0f - f4) / 2.0f) + f4, 1.0f}, Shader.TileMode.CLAMP)); | ||||
|         } | ||||
|         this.edgeShadowPaint.setShader(new LinearGradient(0.0f, rectF.top, 0.0f, rectF2.top, new int[]{this.shadowStartColor, this.shadowMiddleColor, this.shadowEndColor}, new float[]{0.0f, 0.5f, 1.0f}, Shader.TileMode.CLAMP)); | ||||
|         this.edgeShadowPaint.setAntiAlias(false); | ||||
|     } | ||||
|  | ||||
|     private void buildComponents(Rect rect) { | ||||
|         float f = this.rawMaxShadowSize * SHADOW_MULTIPLIER; | ||||
|         this.contentBounds.set(rect.left + this.rawMaxShadowSize, rect.top + f, rect.right - this.rawMaxShadowSize, rect.bottom - f); | ||||
|         getDrawable().setBounds((int) this.contentBounds.left, (int) this.contentBounds.top, (int) this.contentBounds.right, (int) this.contentBounds.bottom); | ||||
|         buildShadowCorners(); | ||||
|     } | ||||
|  | ||||
|     public void setMaxShadowSize(float f) { | ||||
|         setShadowSize(this.rawShadowSize, f); | ||||
|     } | ||||
|  | ||||
|     public float getMinWidth() { | ||||
|         float f = this.rawMaxShadowSize; | ||||
|         return (Math.max(f, this.cornerRadius + (f / 2.0f)) * 2.0f) + (this.rawMaxShadowSize * 2.0f); | ||||
|     } | ||||
|  | ||||
|     public float getMinHeight() { | ||||
|         float f = this.rawMaxShadowSize; | ||||
|         return (Math.max(f, this.cornerRadius + ((f * SHADOW_MULTIPLIER) / 2.0f)) * 2.0f) + (this.rawMaxShadowSize * SHADOW_MULTIPLIER * 2.0f); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,135 @@ | ||||
| package com.google.android.material.shadow; | ||||
|  | ||||
| import android.graphics.Canvas; | ||||
| import android.graphics.LinearGradient; | ||||
| import android.graphics.Matrix; | ||||
| import android.graphics.Paint; | ||||
| import android.graphics.Path; | ||||
| import android.graphics.RadialGradient; | ||||
| import android.graphics.RectF; | ||||
| import android.graphics.Region; | ||||
| import android.graphics.Shader; | ||||
| import androidx.core.graphics.ColorUtils; | ||||
| import androidx.core.view.ViewCompat; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public class ShadowRenderer { | ||||
|     private static final int COLOR_ALPHA_END = 0; | ||||
|     private static final int COLOR_ALPHA_MIDDLE = 20; | ||||
|     private static final int COLOR_ALPHA_START = 68; | ||||
|     private final Paint cornerShadowPaint; | ||||
|     private final Paint edgeShadowPaint; | ||||
|     private final Path scratch; | ||||
|     private int shadowEndColor; | ||||
|     private int shadowMiddleColor; | ||||
|     private final Paint shadowPaint; | ||||
|     private int shadowStartColor; | ||||
|     private final Paint transparentPaint; | ||||
|     private static final int[] edgeColors = new int[3]; | ||||
|     private static final float[] edgePositions = {0.0f, 0.5f, 1.0f}; | ||||
|     private static final int[] cornerColors = new int[4]; | ||||
|     private static final float[] cornerPositions = {0.0f, 0.0f, 0.5f, 1.0f}; | ||||
|  | ||||
|     public Paint getShadowPaint() { | ||||
|         return this.shadowPaint; | ||||
|     } | ||||
|  | ||||
|     public ShadowRenderer() { | ||||
|         this(ViewCompat.MEASURED_STATE_MASK); | ||||
|     } | ||||
|  | ||||
|     public ShadowRenderer(int i) { | ||||
|         this.scratch = new Path(); | ||||
|         Paint paint = new Paint(); | ||||
|         this.transparentPaint = paint; | ||||
|         this.shadowPaint = new Paint(); | ||||
|         setShadowColor(i); | ||||
|         paint.setColor(0); | ||||
|         Paint paint2 = new Paint(4); | ||||
|         this.cornerShadowPaint = paint2; | ||||
|         paint2.setStyle(Paint.Style.FILL); | ||||
|         this.edgeShadowPaint = new Paint(paint2); | ||||
|     } | ||||
|  | ||||
|     public void setShadowColor(int i) { | ||||
|         this.shadowStartColor = ColorUtils.setAlphaComponent(i, 68); | ||||
|         this.shadowMiddleColor = ColorUtils.setAlphaComponent(i, 20); | ||||
|         this.shadowEndColor = ColorUtils.setAlphaComponent(i, 0); | ||||
|         this.shadowPaint.setColor(this.shadowStartColor); | ||||
|     } | ||||
|  | ||||
|     public void drawEdgeShadow(Canvas canvas, Matrix matrix, RectF rectF, int i) { | ||||
|         rectF.bottom += i; | ||||
|         rectF.offset(0.0f, -i); | ||||
|         int[] iArr = edgeColors; | ||||
|         iArr[0] = this.shadowEndColor; | ||||
|         iArr[1] = this.shadowMiddleColor; | ||||
|         iArr[2] = this.shadowStartColor; | ||||
|         this.edgeShadowPaint.setShader(new LinearGradient(rectF.left, rectF.top, rectF.left, rectF.bottom, iArr, edgePositions, Shader.TileMode.CLAMP)); | ||||
|         canvas.save(); | ||||
|         canvas.concat(matrix); | ||||
|         canvas.drawRect(rectF, this.edgeShadowPaint); | ||||
|         canvas.restore(); | ||||
|     } | ||||
|  | ||||
|     public void drawCornerShadow(Canvas canvas, Matrix matrix, RectF rectF, int i, float f, float f2) { | ||||
|         boolean z = f2 < 0.0f; | ||||
|         Path path = this.scratch; | ||||
|         if (z) { | ||||
|             int[] iArr = cornerColors; | ||||
|             iArr[0] = 0; | ||||
|             iArr[1] = this.shadowEndColor; | ||||
|             iArr[2] = this.shadowMiddleColor; | ||||
|             iArr[3] = this.shadowStartColor; | ||||
|         } else { | ||||
|             path.rewind(); | ||||
|             path.moveTo(rectF.centerX(), rectF.centerY()); | ||||
|             path.arcTo(rectF, f, f2); | ||||
|             path.close(); | ||||
|             float f3 = -i; | ||||
|             rectF.inset(f3, f3); | ||||
|             int[] iArr2 = cornerColors; | ||||
|             iArr2[0] = 0; | ||||
|             iArr2[1] = this.shadowStartColor; | ||||
|             iArr2[2] = this.shadowMiddleColor; | ||||
|             iArr2[3] = this.shadowEndColor; | ||||
|         } | ||||
|         float width = rectF.width() / 2.0f; | ||||
|         if (width <= 0.0f) { | ||||
|             return; | ||||
|         } | ||||
|         float f4 = 1.0f - (i / width); | ||||
|         float[] fArr = cornerPositions; | ||||
|         fArr[1] = f4; | ||||
|         fArr[2] = ((1.0f - f4) / 2.0f) + f4; | ||||
|         this.cornerShadowPaint.setShader(new RadialGradient(rectF.centerX(), rectF.centerY(), width, cornerColors, fArr, Shader.TileMode.CLAMP)); | ||||
|         canvas.save(); | ||||
|         canvas.concat(matrix); | ||||
|         canvas.scale(1.0f, rectF.height() / rectF.width()); | ||||
|         if (!z) { | ||||
|             canvas.clipPath(path, Region.Op.DIFFERENCE); | ||||
|             canvas.drawPath(path, this.transparentPaint); | ||||
|         } | ||||
|         canvas.drawArc(rectF, f, f2, true, this.cornerShadowPaint); | ||||
|         canvas.restore(); | ||||
|     } | ||||
|  | ||||
|     public void drawInnerCornerShadow(Canvas canvas, Matrix matrix, RectF rectF, int i, float f, float f2, float[] fArr) { | ||||
|         if (f2 > 0.0f) { | ||||
|             f += f2; | ||||
|             f2 = -f2; | ||||
|         } | ||||
|         drawCornerShadow(canvas, matrix, rectF, i, f, f2); | ||||
|         Path path = this.scratch; | ||||
|         path.rewind(); | ||||
|         path.moveTo(fArr[0], fArr[1]); | ||||
|         path.arcTo(rectF, f, f2); | ||||
|         path.close(); | ||||
|         canvas.save(); | ||||
|         canvas.concat(matrix); | ||||
|         canvas.scale(1.0f, rectF.height() / rectF.width()); | ||||
|         canvas.drawPath(path, this.transparentPaint); | ||||
|         canvas.drawPath(path, this.shadowPaint); | ||||
|         canvas.restore(); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| package com.google.android.material.shadow; | ||||
|  | ||||
| import android.graphics.drawable.Drawable; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public interface ShadowViewDelegate { | ||||
|     float getRadius(); | ||||
|  | ||||
|     boolean isCompatPaddingEnabled(); | ||||
|  | ||||
|     void setBackgroundDrawable(Drawable drawable); | ||||
|  | ||||
|     void setShadowPadding(int i, int i2, int i3, int i4); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user