ADD week 5
This commit is contained in:
@@ -0,0 +1,926 @@
|
||||
package com.google.android.material.shape;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Outline;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Region;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import androidx.core.graphics.drawable.TintAwareDrawable;
|
||||
import androidx.core.util.ObjectsCompat;
|
||||
import com.google.android.material.R;
|
||||
import com.google.android.material.color.MaterialColors;
|
||||
import com.google.android.material.drawable.DrawableUtils;
|
||||
import com.google.android.material.elevation.ElevationOverlayProvider;
|
||||
import com.google.android.material.shadow.ShadowRenderer;
|
||||
import com.google.android.material.shape.ShapeAppearanceModel;
|
||||
import com.google.android.material.shape.ShapeAppearancePathProvider;
|
||||
import com.google.android.material.shape.ShapePath;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.BitSet;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class MaterialShapeDrawable extends Drawable implements TintAwareDrawable, Shapeable {
|
||||
public static final int SHADOW_COMPAT_MODE_ALWAYS = 2;
|
||||
public static final int SHADOW_COMPAT_MODE_DEFAULT = 0;
|
||||
public static final int SHADOW_COMPAT_MODE_NEVER = 1;
|
||||
private static final float SHADOW_OFFSET_MULTIPLIER = 0.25f;
|
||||
private static final float SHADOW_RADIUS_MULTIPLIER = 0.75f;
|
||||
private static final String TAG = "MaterialShapeDrawable";
|
||||
private static final Paint clearPaint;
|
||||
private final BitSet containsIncompatibleShadowOp;
|
||||
private final ShapePath.ShadowCompatOperation[] cornerShadowOperation;
|
||||
private MaterialShapeDrawableState drawableState;
|
||||
private final ShapePath.ShadowCompatOperation[] edgeShadowOperation;
|
||||
private final Paint fillPaint;
|
||||
private final RectF insetRectF;
|
||||
private final Matrix matrix;
|
||||
private final Path path;
|
||||
private final RectF pathBounds;
|
||||
private boolean pathDirty;
|
||||
private final Path pathInsetByStroke;
|
||||
private final ShapeAppearancePathProvider pathProvider;
|
||||
private final ShapeAppearancePathProvider.PathListener pathShadowListener;
|
||||
private final RectF rectF;
|
||||
private int resolvedTintColor;
|
||||
private final Region scratchRegion;
|
||||
private boolean shadowBitmapDrawingEnable;
|
||||
private final ShadowRenderer shadowRenderer;
|
||||
private final Paint strokePaint;
|
||||
private ShapeAppearanceModel strokeShapeAppearance;
|
||||
private PorterDuffColorFilter strokeTintFilter;
|
||||
private PorterDuffColorFilter tintFilter;
|
||||
private final Region transparentRegion;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface CompatibilityShadowMode {
|
||||
}
|
||||
|
||||
private static int modulateAlpha(int i, int i2) {
|
||||
return (i * (i2 + (i2 >>> 7))) >>> 8;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public Drawable.ConstantState getConstantState() {
|
||||
return this.drawableState;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public int getOpacity() {
|
||||
return -3;
|
||||
}
|
||||
|
||||
public int getResolvedTintColor() {
|
||||
return this.resolvedTintColor;
|
||||
}
|
||||
|
||||
public void setShadowBitmapDrawingEnable(boolean z) {
|
||||
this.shadowBitmapDrawingEnable = z;
|
||||
}
|
||||
|
||||
static {
|
||||
Paint paint = new Paint(1);
|
||||
clearPaint = paint;
|
||||
paint.setColor(-1);
|
||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
|
||||
}
|
||||
|
||||
public static MaterialShapeDrawable createWithElevationOverlay(Context context) {
|
||||
return createWithElevationOverlay(context, 0.0f);
|
||||
}
|
||||
|
||||
public static MaterialShapeDrawable createWithElevationOverlay(Context context, float f) {
|
||||
return createWithElevationOverlay(context, f, null);
|
||||
}
|
||||
|
||||
public static MaterialShapeDrawable createWithElevationOverlay(Context context, float f, ColorStateList colorStateList) {
|
||||
if (colorStateList == null) {
|
||||
colorStateList = ColorStateList.valueOf(MaterialColors.getColor(context, R.attr.colorSurface, TAG));
|
||||
}
|
||||
MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable();
|
||||
materialShapeDrawable.initializeElevationOverlay(context);
|
||||
materialShapeDrawable.setFillColor(colorStateList);
|
||||
materialShapeDrawable.setElevation(f);
|
||||
return materialShapeDrawable;
|
||||
}
|
||||
|
||||
public MaterialShapeDrawable() {
|
||||
this(new ShapeAppearanceModel());
|
||||
}
|
||||
|
||||
public MaterialShapeDrawable(Context context, AttributeSet attributeSet, int i, int i2) {
|
||||
this(ShapeAppearanceModel.builder(context, attributeSet, i, i2).build());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public MaterialShapeDrawable(ShapePathModel shapePathModel) {
|
||||
this((ShapeAppearanceModel) shapePathModel);
|
||||
}
|
||||
|
||||
public MaterialShapeDrawable(ShapeAppearanceModel shapeAppearanceModel) {
|
||||
this(new MaterialShapeDrawableState(shapeAppearanceModel, null));
|
||||
}
|
||||
|
||||
protected MaterialShapeDrawable(MaterialShapeDrawableState materialShapeDrawableState) {
|
||||
ShapeAppearancePathProvider shapeAppearancePathProvider;
|
||||
this.cornerShadowOperation = new ShapePath.ShadowCompatOperation[4];
|
||||
this.edgeShadowOperation = new ShapePath.ShadowCompatOperation[4];
|
||||
this.containsIncompatibleShadowOp = new BitSet(8);
|
||||
this.matrix = new Matrix();
|
||||
this.path = new Path();
|
||||
this.pathInsetByStroke = new Path();
|
||||
this.rectF = new RectF();
|
||||
this.insetRectF = new RectF();
|
||||
this.transparentRegion = new Region();
|
||||
this.scratchRegion = new Region();
|
||||
Paint paint = new Paint(1);
|
||||
this.fillPaint = paint;
|
||||
Paint paint2 = new Paint(1);
|
||||
this.strokePaint = paint2;
|
||||
this.shadowRenderer = new ShadowRenderer();
|
||||
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
|
||||
shapeAppearancePathProvider = ShapeAppearancePathProvider.getInstance();
|
||||
} else {
|
||||
shapeAppearancePathProvider = new ShapeAppearancePathProvider();
|
||||
}
|
||||
this.pathProvider = shapeAppearancePathProvider;
|
||||
this.pathBounds = new RectF();
|
||||
this.shadowBitmapDrawingEnable = true;
|
||||
this.drawableState = materialShapeDrawableState;
|
||||
paint2.setStyle(Paint.Style.STROKE);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
updateTintFilter();
|
||||
updateColorsForState(getState());
|
||||
this.pathShadowListener = new ShapeAppearancePathProvider.PathListener() { // from class: com.google.android.material.shape.MaterialShapeDrawable.1
|
||||
@Override // com.google.android.material.shape.ShapeAppearancePathProvider.PathListener
|
||||
public void onCornerPathCreated(ShapePath shapePath, Matrix matrix, int i) {
|
||||
MaterialShapeDrawable.this.containsIncompatibleShadowOp.set(i, shapePath.containsIncompatibleShadowOp());
|
||||
MaterialShapeDrawable.this.cornerShadowOperation[i] = shapePath.createShadowCompatOperation(matrix);
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.shape.ShapeAppearancePathProvider.PathListener
|
||||
public void onEdgePathCreated(ShapePath shapePath, Matrix matrix, int i) {
|
||||
MaterialShapeDrawable.this.containsIncompatibleShadowOp.set(i + 4, shapePath.containsIncompatibleShadowOp());
|
||||
MaterialShapeDrawable.this.edgeShadowOperation[i] = shapePath.createShadowCompatOperation(matrix);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public Drawable mutate() {
|
||||
this.drawableState = new MaterialShapeDrawableState(this.drawableState);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.shape.Shapeable
|
||||
public void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel) {
|
||||
this.drawableState.shapeAppearanceModel = shapeAppearanceModel;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override // com.google.android.material.shape.Shapeable
|
||||
public ShapeAppearanceModel getShapeAppearanceModel() {
|
||||
return this.drawableState.shapeAppearanceModel;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setShapedViewModel(ShapePathModel shapePathModel) {
|
||||
setShapeAppearanceModel(shapePathModel);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ShapePathModel getShapedViewModel() {
|
||||
ShapeAppearanceModel shapeAppearanceModel = getShapeAppearanceModel();
|
||||
if (shapeAppearanceModel instanceof ShapePathModel) {
|
||||
return (ShapePathModel) shapeAppearanceModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFillColor(ColorStateList colorStateList) {
|
||||
if (this.drawableState.fillColor != colorStateList) {
|
||||
this.drawableState.fillColor = colorStateList;
|
||||
onStateChange(getState());
|
||||
}
|
||||
}
|
||||
|
||||
public ColorStateList getFillColor() {
|
||||
return this.drawableState.fillColor;
|
||||
}
|
||||
|
||||
public void setStrokeColor(ColorStateList colorStateList) {
|
||||
if (this.drawableState.strokeColor != colorStateList) {
|
||||
this.drawableState.strokeColor = colorStateList;
|
||||
onStateChange(getState());
|
||||
}
|
||||
}
|
||||
|
||||
public ColorStateList getStrokeColor() {
|
||||
return this.drawableState.strokeColor;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable, androidx.core.graphics.drawable.TintAwareDrawable
|
||||
public void setTintMode(PorterDuff.Mode mode) {
|
||||
if (this.drawableState.tintMode != mode) {
|
||||
this.drawableState.tintMode = mode;
|
||||
updateTintFilter();
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable, androidx.core.graphics.drawable.TintAwareDrawable
|
||||
public void setTintList(ColorStateList colorStateList) {
|
||||
this.drawableState.tintList = colorStateList;
|
||||
updateTintFilter();
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
|
||||
public ColorStateList getTintList() {
|
||||
return this.drawableState.tintList;
|
||||
}
|
||||
|
||||
public ColorStateList getStrokeTintList() {
|
||||
return this.drawableState.strokeTintList;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable, androidx.core.graphics.drawable.TintAwareDrawable
|
||||
public void setTint(int i) {
|
||||
setTintList(ColorStateList.valueOf(i));
|
||||
}
|
||||
|
||||
public void setStrokeTint(ColorStateList colorStateList) {
|
||||
this.drawableState.strokeTintList = colorStateList;
|
||||
updateTintFilter();
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
|
||||
public void setStrokeTint(int i) {
|
||||
setStrokeTint(ColorStateList.valueOf(i));
|
||||
}
|
||||
|
||||
public void setStroke(float f, int i) {
|
||||
setStrokeWidth(f);
|
||||
setStrokeColor(ColorStateList.valueOf(i));
|
||||
}
|
||||
|
||||
public void setStroke(float f, ColorStateList colorStateList) {
|
||||
setStrokeWidth(f);
|
||||
setStrokeColor(colorStateList);
|
||||
}
|
||||
|
||||
public float getStrokeWidth() {
|
||||
return this.drawableState.strokeWidth;
|
||||
}
|
||||
|
||||
public void setStrokeWidth(float f) {
|
||||
this.drawableState.strokeWidth = f;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public int getAlpha() {
|
||||
return this.drawableState.alpha;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void setAlpha(int i) {
|
||||
if (this.drawableState.alpha != i) {
|
||||
this.drawableState.alpha = i;
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void setColorFilter(ColorFilter colorFilter) {
|
||||
this.drawableState.colorFilter = colorFilter;
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public Region getTransparentRegion() {
|
||||
this.transparentRegion.set(getBounds());
|
||||
calculatePath(getBoundsAsRectF(), this.path);
|
||||
this.scratchRegion.setPath(this.path, this.transparentRegion);
|
||||
this.transparentRegion.op(this.scratchRegion, Region.Op.DIFFERENCE);
|
||||
return this.transparentRegion;
|
||||
}
|
||||
|
||||
protected RectF getBoundsAsRectF() {
|
||||
this.rectF.set(getBounds());
|
||||
return this.rectF;
|
||||
}
|
||||
|
||||
public void setCornerSize(float f) {
|
||||
setShapeAppearanceModel(this.drawableState.shapeAppearanceModel.withCornerSize(f));
|
||||
}
|
||||
|
||||
public void setCornerSize(CornerSize cornerSize) {
|
||||
setShapeAppearanceModel(this.drawableState.shapeAppearanceModel.withCornerSize(cornerSize));
|
||||
}
|
||||
|
||||
public boolean isPointInTransparentRegion(int i, int i2) {
|
||||
return getTransparentRegion().contains(i, i2);
|
||||
}
|
||||
|
||||
public int getShadowCompatibilityMode() {
|
||||
return this.drawableState.shadowCompatMode;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public boolean getPadding(Rect rect) {
|
||||
if (this.drawableState.padding != null) {
|
||||
rect.set(this.drawableState.padding);
|
||||
return true;
|
||||
}
|
||||
return super.getPadding(rect);
|
||||
}
|
||||
|
||||
public void setPadding(int i, int i2, int i3, int i4) {
|
||||
if (this.drawableState.padding == null) {
|
||||
this.drawableState.padding = new Rect();
|
||||
}
|
||||
this.drawableState.padding.set(i, i2, i3, i4);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
public void setShadowCompatibilityMode(int i) {
|
||||
if (this.drawableState.shadowCompatMode != i) {
|
||||
this.drawableState.shadowCompatMode = i;
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isShadowEnabled() {
|
||||
return this.drawableState.shadowCompatMode == 0 || this.drawableState.shadowCompatMode == 2;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setShadowEnabled(boolean z) {
|
||||
setShadowCompatibilityMode(!z ? 1 : 0);
|
||||
}
|
||||
|
||||
public boolean isElevationOverlayEnabled() {
|
||||
return this.drawableState.elevationOverlayProvider != null && this.drawableState.elevationOverlayProvider.isThemeElevationOverlayEnabled();
|
||||
}
|
||||
|
||||
public boolean isElevationOverlayInitialized() {
|
||||
return this.drawableState.elevationOverlayProvider != null;
|
||||
}
|
||||
|
||||
public void initializeElevationOverlay(Context context) {
|
||||
this.drawableState.elevationOverlayProvider = new ElevationOverlayProvider(context);
|
||||
updateZ();
|
||||
}
|
||||
|
||||
protected int compositeElevationOverlayIfNeeded(int i) {
|
||||
return this.drawableState.elevationOverlayProvider != null ? this.drawableState.elevationOverlayProvider.compositeOverlayIfNeeded(i, getZ() + getParentAbsoluteElevation()) : i;
|
||||
}
|
||||
|
||||
public float getInterpolation() {
|
||||
return this.drawableState.interpolation;
|
||||
}
|
||||
|
||||
public void setInterpolation(float f) {
|
||||
if (this.drawableState.interpolation != f) {
|
||||
this.drawableState.interpolation = f;
|
||||
this.pathDirty = true;
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
public float getParentAbsoluteElevation() {
|
||||
return this.drawableState.parentAbsoluteElevation;
|
||||
}
|
||||
|
||||
public void setParentAbsoluteElevation(float f) {
|
||||
if (this.drawableState.parentAbsoluteElevation != f) {
|
||||
this.drawableState.parentAbsoluteElevation = f;
|
||||
updateZ();
|
||||
}
|
||||
}
|
||||
|
||||
public float getElevation() {
|
||||
return this.drawableState.elevation;
|
||||
}
|
||||
|
||||
public void setElevation(float f) {
|
||||
if (this.drawableState.elevation != f) {
|
||||
this.drawableState.elevation = f;
|
||||
updateZ();
|
||||
}
|
||||
}
|
||||
|
||||
public float getTranslationZ() {
|
||||
return this.drawableState.translationZ;
|
||||
}
|
||||
|
||||
public void setTranslationZ(float f) {
|
||||
if (this.drawableState.translationZ != f) {
|
||||
this.drawableState.translationZ = f;
|
||||
updateZ();
|
||||
}
|
||||
}
|
||||
|
||||
public float getZ() {
|
||||
return getElevation() + getTranslationZ();
|
||||
}
|
||||
|
||||
public void setZ(float f) {
|
||||
setTranslationZ(f - getElevation());
|
||||
}
|
||||
|
||||
private void updateZ() {
|
||||
float z = getZ();
|
||||
this.drawableState.shadowCompatRadius = (int) Math.ceil(0.75f * z);
|
||||
this.drawableState.shadowCompatOffset = (int) Math.ceil(z * SHADOW_OFFSET_MULTIPLIER);
|
||||
updateTintFilter();
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getShadowElevation() {
|
||||
return (int) getElevation();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setShadowElevation(int i) {
|
||||
setElevation(i);
|
||||
}
|
||||
|
||||
public int getShadowVerticalOffset() {
|
||||
return this.drawableState.shadowCompatOffset;
|
||||
}
|
||||
|
||||
public void setEdgeIntersectionCheckEnable(boolean z) {
|
||||
this.pathProvider.setEdgeIntersectionCheckEnable(z);
|
||||
}
|
||||
|
||||
public void setShadowVerticalOffset(int i) {
|
||||
if (this.drawableState.shadowCompatOffset != i) {
|
||||
this.drawableState.shadowCompatOffset = i;
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
}
|
||||
|
||||
public int getShadowCompatRotation() {
|
||||
return this.drawableState.shadowCompatRotation;
|
||||
}
|
||||
|
||||
public void setShadowCompatRotation(int i) {
|
||||
if (this.drawableState.shadowCompatRotation != i) {
|
||||
this.drawableState.shadowCompatRotation = i;
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
}
|
||||
|
||||
public int getShadowRadius() {
|
||||
return this.drawableState.shadowCompatRadius;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setShadowRadius(int i) {
|
||||
this.drawableState.shadowCompatRadius = i;
|
||||
}
|
||||
|
||||
public boolean requiresCompatShadow() {
|
||||
return (isRoundRect() || this.path.isConvex() || Build.VERSION.SDK_INT >= 29) ? false : true;
|
||||
}
|
||||
|
||||
public float getScale() {
|
||||
return this.drawableState.scale;
|
||||
}
|
||||
|
||||
public void setScale(float f) {
|
||||
if (this.drawableState.scale != f) {
|
||||
this.drawableState.scale = f;
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void invalidateSelf() {
|
||||
this.pathDirty = true;
|
||||
super.invalidateSelf();
|
||||
}
|
||||
|
||||
private void invalidateSelfIgnoreShape() {
|
||||
super.invalidateSelf();
|
||||
}
|
||||
|
||||
public void setUseTintColorForShadow(boolean z) {
|
||||
if (this.drawableState.useTintColorForShadow != z) {
|
||||
this.drawableState.useTintColorForShadow = z;
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
public void setShadowColor(int i) {
|
||||
this.shadowRenderer.setShadowColor(i);
|
||||
this.drawableState.useTintColorForShadow = false;
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
|
||||
public Paint.Style getPaintStyle() {
|
||||
return this.drawableState.paintStyle;
|
||||
}
|
||||
|
||||
public void setPaintStyle(Paint.Style style) {
|
||||
this.drawableState.paintStyle = style;
|
||||
invalidateSelfIgnoreShape();
|
||||
}
|
||||
|
||||
private boolean hasCompatShadow() {
|
||||
return this.drawableState.shadowCompatMode != 1 && this.drawableState.shadowCompatRadius > 0 && (this.drawableState.shadowCompatMode == 2 || requiresCompatShadow());
|
||||
}
|
||||
|
||||
private boolean hasFill() {
|
||||
return this.drawableState.paintStyle == Paint.Style.FILL_AND_STROKE || this.drawableState.paintStyle == Paint.Style.FILL;
|
||||
}
|
||||
|
||||
private boolean hasStroke() {
|
||||
return (this.drawableState.paintStyle == Paint.Style.FILL_AND_STROKE || this.drawableState.paintStyle == Paint.Style.STROKE) && this.strokePaint.getStrokeWidth() > 0.0f;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
protected void onBoundsChange(Rect rect) {
|
||||
this.pathDirty = true;
|
||||
super.onBoundsChange(rect);
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void draw(Canvas canvas) {
|
||||
this.fillPaint.setColorFilter(this.tintFilter);
|
||||
int alpha = this.fillPaint.getAlpha();
|
||||
this.fillPaint.setAlpha(modulateAlpha(alpha, this.drawableState.alpha));
|
||||
this.strokePaint.setColorFilter(this.strokeTintFilter);
|
||||
this.strokePaint.setStrokeWidth(this.drawableState.strokeWidth);
|
||||
int alpha2 = this.strokePaint.getAlpha();
|
||||
this.strokePaint.setAlpha(modulateAlpha(alpha2, this.drawableState.alpha));
|
||||
if (this.pathDirty) {
|
||||
calculateStrokePath();
|
||||
calculatePath(getBoundsAsRectF(), this.path);
|
||||
this.pathDirty = false;
|
||||
}
|
||||
maybeDrawCompatShadow(canvas);
|
||||
if (hasFill()) {
|
||||
drawFillShape(canvas);
|
||||
}
|
||||
if (hasStroke()) {
|
||||
drawStrokeShape(canvas);
|
||||
}
|
||||
this.fillPaint.setAlpha(alpha);
|
||||
this.strokePaint.setAlpha(alpha2);
|
||||
}
|
||||
|
||||
private void maybeDrawCompatShadow(Canvas canvas) {
|
||||
if (hasCompatShadow()) {
|
||||
canvas.save();
|
||||
prepareCanvasForShadow(canvas);
|
||||
if (!this.shadowBitmapDrawingEnable) {
|
||||
drawCompatShadow(canvas);
|
||||
canvas.restore();
|
||||
return;
|
||||
}
|
||||
int width = (int) (this.pathBounds.width() - getBounds().width());
|
||||
int height = (int) (this.pathBounds.height() - getBounds().height());
|
||||
if (width < 0 || height < 0) {
|
||||
throw new IllegalStateException("Invalid shadow bounds. Check that the treatments result in a valid path.");
|
||||
}
|
||||
Bitmap createBitmap = Bitmap.createBitmap(((int) this.pathBounds.width()) + (this.drawableState.shadowCompatRadius * 2) + width, ((int) this.pathBounds.height()) + (this.drawableState.shadowCompatRadius * 2) + height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas2 = new Canvas(createBitmap);
|
||||
float f = (getBounds().left - this.drawableState.shadowCompatRadius) - width;
|
||||
float f2 = (getBounds().top - this.drawableState.shadowCompatRadius) - height;
|
||||
canvas2.translate(-f, -f2);
|
||||
drawCompatShadow(canvas2);
|
||||
canvas.drawBitmap(createBitmap, f, f2, (Paint) null);
|
||||
createBitmap.recycle();
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawShape(Canvas canvas, Paint paint, Path path, RectF rectF) {
|
||||
drawShape(canvas, paint, path, this.drawableState.shapeAppearanceModel, rectF);
|
||||
}
|
||||
|
||||
private void drawShape(Canvas canvas, Paint paint, Path path, ShapeAppearanceModel shapeAppearanceModel, RectF rectF) {
|
||||
if (shapeAppearanceModel.isRoundRect(rectF)) {
|
||||
float cornerSize = shapeAppearanceModel.getTopRightCornerSize().getCornerSize(rectF) * this.drawableState.interpolation;
|
||||
canvas.drawRoundRect(rectF, cornerSize, cornerSize, paint);
|
||||
} else {
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawFillShape(Canvas canvas) {
|
||||
drawShape(canvas, this.fillPaint, this.path, this.drawableState.shapeAppearanceModel, getBoundsAsRectF());
|
||||
}
|
||||
|
||||
protected void drawStrokeShape(Canvas canvas) {
|
||||
drawShape(canvas, this.strokePaint, this.pathInsetByStroke, this.strokeShapeAppearance, getBoundsInsetByStroke());
|
||||
}
|
||||
|
||||
private void prepareCanvasForShadow(Canvas canvas) {
|
||||
canvas.translate(getShadowOffsetX(), getShadowOffsetY());
|
||||
}
|
||||
|
||||
private void drawCompatShadow(Canvas canvas) {
|
||||
if (this.containsIncompatibleShadowOp.cardinality() > 0) {
|
||||
Log.w(TAG, "Compatibility shadow requested but can't be drawn for all operations in this shape.");
|
||||
}
|
||||
if (this.drawableState.shadowCompatOffset != 0) {
|
||||
canvas.drawPath(this.path, this.shadowRenderer.getShadowPaint());
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
this.cornerShadowOperation[i].draw(this.shadowRenderer, this.drawableState.shadowCompatRadius, canvas);
|
||||
this.edgeShadowOperation[i].draw(this.shadowRenderer, this.drawableState.shadowCompatRadius, canvas);
|
||||
}
|
||||
if (this.shadowBitmapDrawingEnable) {
|
||||
int shadowOffsetX = getShadowOffsetX();
|
||||
int shadowOffsetY = getShadowOffsetY();
|
||||
canvas.translate(-shadowOffsetX, -shadowOffsetY);
|
||||
canvas.drawPath(this.path, clearPaint);
|
||||
canvas.translate(shadowOffsetX, shadowOffsetY);
|
||||
}
|
||||
}
|
||||
|
||||
public int getShadowOffsetX() {
|
||||
return (int) (this.drawableState.shadowCompatOffset * Math.sin(Math.toRadians(this.drawableState.shadowCompatRotation)));
|
||||
}
|
||||
|
||||
public int getShadowOffsetY() {
|
||||
return (int) (this.drawableState.shadowCompatOffset * Math.cos(Math.toRadians(this.drawableState.shadowCompatRotation)));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void getPathForSize(int i, int i2, Path path) {
|
||||
calculatePathForSize(new RectF(0.0f, 0.0f, i, i2), path);
|
||||
}
|
||||
|
||||
protected final void calculatePathForSize(RectF rectF, Path path) {
|
||||
this.pathProvider.calculatePath(this.drawableState.shapeAppearanceModel, this.drawableState.interpolation, rectF, this.pathShadowListener, path);
|
||||
}
|
||||
|
||||
private void calculateStrokePath() {
|
||||
final float f = -getStrokeInsetLength();
|
||||
ShapeAppearanceModel withTransformedCornerSizes = getShapeAppearanceModel().withTransformedCornerSizes(new ShapeAppearanceModel.CornerSizeUnaryOperator() { // from class: com.google.android.material.shape.MaterialShapeDrawable.2
|
||||
@Override // com.google.android.material.shape.ShapeAppearanceModel.CornerSizeUnaryOperator
|
||||
public CornerSize apply(CornerSize cornerSize) {
|
||||
return cornerSize instanceof RelativeCornerSize ? cornerSize : new AdjustedCornerSize(f, cornerSize);
|
||||
}
|
||||
});
|
||||
this.strokeShapeAppearance = withTransformedCornerSizes;
|
||||
this.pathProvider.calculatePath(withTransformedCornerSizes, this.drawableState.interpolation, getBoundsInsetByStroke(), this.pathInsetByStroke);
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void getOutline(Outline outline) {
|
||||
if (this.drawableState.shadowCompatMode == 2) {
|
||||
return;
|
||||
}
|
||||
if (isRoundRect()) {
|
||||
outline.setRoundRect(getBounds(), getTopLeftCornerResolvedSize() * this.drawableState.interpolation);
|
||||
} else {
|
||||
calculatePath(getBoundsAsRectF(), this.path);
|
||||
DrawableUtils.setOutlineToPath(outline, this.path);
|
||||
}
|
||||
}
|
||||
|
||||
private void calculatePath(RectF rectF, Path path) {
|
||||
calculatePathForSize(rectF, path);
|
||||
if (this.drawableState.scale != 1.0f) {
|
||||
this.matrix.reset();
|
||||
this.matrix.setScale(this.drawableState.scale, this.drawableState.scale, rectF.width() / 2.0f, rectF.height() / 2.0f);
|
||||
path.transform(this.matrix);
|
||||
}
|
||||
path.computeBounds(this.pathBounds, true);
|
||||
}
|
||||
|
||||
private boolean updateTintFilter() {
|
||||
PorterDuffColorFilter porterDuffColorFilter = this.tintFilter;
|
||||
PorterDuffColorFilter porterDuffColorFilter2 = this.strokeTintFilter;
|
||||
this.tintFilter = calculateTintFilter(this.drawableState.tintList, this.drawableState.tintMode, this.fillPaint, true);
|
||||
this.strokeTintFilter = calculateTintFilter(this.drawableState.strokeTintList, this.drawableState.tintMode, this.strokePaint, false);
|
||||
if (this.drawableState.useTintColorForShadow) {
|
||||
this.shadowRenderer.setShadowColor(this.drawableState.tintList.getColorForState(getState(), 0));
|
||||
}
|
||||
return (ObjectsCompat.equals(porterDuffColorFilter, this.tintFilter) && ObjectsCompat.equals(porterDuffColorFilter2, this.strokeTintFilter)) ? false : true;
|
||||
}
|
||||
|
||||
private PorterDuffColorFilter calculateTintFilter(ColorStateList colorStateList, PorterDuff.Mode mode, Paint paint, boolean z) {
|
||||
if (colorStateList == null || mode == null) {
|
||||
return calculatePaintColorTintFilter(paint, z);
|
||||
}
|
||||
return calculateTintColorTintFilter(colorStateList, mode, z);
|
||||
}
|
||||
|
||||
private PorterDuffColorFilter calculatePaintColorTintFilter(Paint paint, boolean z) {
|
||||
if (!z) {
|
||||
return null;
|
||||
}
|
||||
int color = paint.getColor();
|
||||
int compositeElevationOverlayIfNeeded = compositeElevationOverlayIfNeeded(color);
|
||||
this.resolvedTintColor = compositeElevationOverlayIfNeeded;
|
||||
if (compositeElevationOverlayIfNeeded != color) {
|
||||
return new PorterDuffColorFilter(compositeElevationOverlayIfNeeded, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private PorterDuffColorFilter calculateTintColorTintFilter(ColorStateList colorStateList, PorterDuff.Mode mode, boolean z) {
|
||||
int colorForState = colorStateList.getColorForState(getState(), 0);
|
||||
if (z) {
|
||||
colorForState = compositeElevationOverlayIfNeeded(colorForState);
|
||||
}
|
||||
this.resolvedTintColor = colorForState;
|
||||
return new PorterDuffColorFilter(colorForState, mode);
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public boolean isStateful() {
|
||||
return super.isStateful() || (this.drawableState.tintList != null && this.drawableState.tintList.isStateful()) || ((this.drawableState.strokeTintList != null && this.drawableState.strokeTintList.isStateful()) || ((this.drawableState.strokeColor != null && this.drawableState.strokeColor.isStateful()) || (this.drawableState.fillColor != null && this.drawableState.fillColor.isStateful())));
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable, com.google.android.material.internal.TextDrawableHelper.TextDrawableDelegate
|
||||
protected boolean onStateChange(int[] iArr) {
|
||||
boolean z = updateColorsForState(iArr) || updateTintFilter();
|
||||
if (z) {
|
||||
invalidateSelf();
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
private boolean updateColorsForState(int[] iArr) {
|
||||
boolean z;
|
||||
int color;
|
||||
int colorForState;
|
||||
int color2;
|
||||
int colorForState2;
|
||||
if (this.drawableState.fillColor == null || color2 == (colorForState2 = this.drawableState.fillColor.getColorForState(iArr, (color2 = this.fillPaint.getColor())))) {
|
||||
z = false;
|
||||
} else {
|
||||
this.fillPaint.setColor(colorForState2);
|
||||
z = true;
|
||||
}
|
||||
if (this.drawableState.strokeColor == null || color == (colorForState = this.drawableState.strokeColor.getColorForState(iArr, (color = this.strokePaint.getColor())))) {
|
||||
return z;
|
||||
}
|
||||
this.strokePaint.setColor(colorForState);
|
||||
return true;
|
||||
}
|
||||
|
||||
private float getStrokeInsetLength() {
|
||||
if (hasStroke()) {
|
||||
return this.strokePaint.getStrokeWidth() / 2.0f;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
private RectF getBoundsInsetByStroke() {
|
||||
this.insetRectF.set(getBoundsAsRectF());
|
||||
float strokeInsetLength = getStrokeInsetLength();
|
||||
this.insetRectF.inset(strokeInsetLength, strokeInsetLength);
|
||||
return this.insetRectF;
|
||||
}
|
||||
|
||||
public float getTopLeftCornerResolvedSize() {
|
||||
return this.drawableState.shapeAppearanceModel.getTopLeftCornerSize().getCornerSize(getBoundsAsRectF());
|
||||
}
|
||||
|
||||
public float getTopRightCornerResolvedSize() {
|
||||
return this.drawableState.shapeAppearanceModel.getTopRightCornerSize().getCornerSize(getBoundsAsRectF());
|
||||
}
|
||||
|
||||
public float getBottomLeftCornerResolvedSize() {
|
||||
return this.drawableState.shapeAppearanceModel.getBottomLeftCornerSize().getCornerSize(getBoundsAsRectF());
|
||||
}
|
||||
|
||||
public float getBottomRightCornerResolvedSize() {
|
||||
return this.drawableState.shapeAppearanceModel.getBottomRightCornerSize().getCornerSize(getBoundsAsRectF());
|
||||
}
|
||||
|
||||
public boolean isRoundRect() {
|
||||
return this.drawableState.shapeAppearanceModel.isRoundRect(getBoundsAsRectF());
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: protected */
|
||||
public static class MaterialShapeDrawableState extends Drawable.ConstantState {
|
||||
int alpha;
|
||||
ColorFilter colorFilter;
|
||||
float elevation;
|
||||
ElevationOverlayProvider elevationOverlayProvider;
|
||||
ColorStateList fillColor;
|
||||
float interpolation;
|
||||
Rect padding;
|
||||
Paint.Style paintStyle;
|
||||
float parentAbsoluteElevation;
|
||||
float scale;
|
||||
int shadowCompatMode;
|
||||
int shadowCompatOffset;
|
||||
int shadowCompatRadius;
|
||||
int shadowCompatRotation;
|
||||
ShapeAppearanceModel shapeAppearanceModel;
|
||||
ColorStateList strokeColor;
|
||||
ColorStateList strokeTintList;
|
||||
float strokeWidth;
|
||||
ColorStateList tintList;
|
||||
PorterDuff.Mode tintMode;
|
||||
float translationZ;
|
||||
boolean useTintColorForShadow;
|
||||
|
||||
@Override // android.graphics.drawable.Drawable.ConstantState
|
||||
public int getChangingConfigurations() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public MaterialShapeDrawableState(ShapeAppearanceModel shapeAppearanceModel, ElevationOverlayProvider elevationOverlayProvider) {
|
||||
this.fillColor = null;
|
||||
this.strokeColor = null;
|
||||
this.strokeTintList = null;
|
||||
this.tintList = null;
|
||||
this.tintMode = PorterDuff.Mode.SRC_IN;
|
||||
this.padding = null;
|
||||
this.scale = 1.0f;
|
||||
this.interpolation = 1.0f;
|
||||
this.alpha = 255;
|
||||
this.parentAbsoluteElevation = 0.0f;
|
||||
this.elevation = 0.0f;
|
||||
this.translationZ = 0.0f;
|
||||
this.shadowCompatMode = 0;
|
||||
this.shadowCompatRadius = 0;
|
||||
this.shadowCompatOffset = 0;
|
||||
this.shadowCompatRotation = 0;
|
||||
this.useTintColorForShadow = false;
|
||||
this.paintStyle = Paint.Style.FILL_AND_STROKE;
|
||||
this.shapeAppearanceModel = shapeAppearanceModel;
|
||||
this.elevationOverlayProvider = elevationOverlayProvider;
|
||||
}
|
||||
|
||||
public MaterialShapeDrawableState(MaterialShapeDrawableState materialShapeDrawableState) {
|
||||
this.fillColor = null;
|
||||
this.strokeColor = null;
|
||||
this.strokeTintList = null;
|
||||
this.tintList = null;
|
||||
this.tintMode = PorterDuff.Mode.SRC_IN;
|
||||
this.padding = null;
|
||||
this.scale = 1.0f;
|
||||
this.interpolation = 1.0f;
|
||||
this.alpha = 255;
|
||||
this.parentAbsoluteElevation = 0.0f;
|
||||
this.elevation = 0.0f;
|
||||
this.translationZ = 0.0f;
|
||||
this.shadowCompatMode = 0;
|
||||
this.shadowCompatRadius = 0;
|
||||
this.shadowCompatOffset = 0;
|
||||
this.shadowCompatRotation = 0;
|
||||
this.useTintColorForShadow = false;
|
||||
this.paintStyle = Paint.Style.FILL_AND_STROKE;
|
||||
this.shapeAppearanceModel = materialShapeDrawableState.shapeAppearanceModel;
|
||||
this.elevationOverlayProvider = materialShapeDrawableState.elevationOverlayProvider;
|
||||
this.strokeWidth = materialShapeDrawableState.strokeWidth;
|
||||
this.colorFilter = materialShapeDrawableState.colorFilter;
|
||||
this.fillColor = materialShapeDrawableState.fillColor;
|
||||
this.strokeColor = materialShapeDrawableState.strokeColor;
|
||||
this.tintMode = materialShapeDrawableState.tintMode;
|
||||
this.tintList = materialShapeDrawableState.tintList;
|
||||
this.alpha = materialShapeDrawableState.alpha;
|
||||
this.scale = materialShapeDrawableState.scale;
|
||||
this.shadowCompatOffset = materialShapeDrawableState.shadowCompatOffset;
|
||||
this.shadowCompatMode = materialShapeDrawableState.shadowCompatMode;
|
||||
this.useTintColorForShadow = materialShapeDrawableState.useTintColorForShadow;
|
||||
this.interpolation = materialShapeDrawableState.interpolation;
|
||||
this.parentAbsoluteElevation = materialShapeDrawableState.parentAbsoluteElevation;
|
||||
this.elevation = materialShapeDrawableState.elevation;
|
||||
this.translationZ = materialShapeDrawableState.translationZ;
|
||||
this.shadowCompatRadius = materialShapeDrawableState.shadowCompatRadius;
|
||||
this.shadowCompatRotation = materialShapeDrawableState.shadowCompatRotation;
|
||||
this.strokeTintList = materialShapeDrawableState.strokeTintList;
|
||||
this.paintStyle = materialShapeDrawableState.paintStyle;
|
||||
if (materialShapeDrawableState.padding != null) {
|
||||
this.padding = new Rect(materialShapeDrawableState.padding);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable.ConstantState
|
||||
public Drawable newDrawable() {
|
||||
MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable(this);
|
||||
materialShapeDrawable.pathDirty = true;
|
||||
return materialShapeDrawable;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user