alexandroid/decompiled/jadx/sources/com/google/android/material/shape/ShapeAppearanceModel.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

546 lines
22 KiB
Java

package com.google.android.material.shape;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import androidx.annotation.AttrRes;
import androidx.annotation.Dimension;
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.annotation.StyleRes;
import com.amazon.alexa.ra.core.ui.markdown.parser.formatter.MarkdownConstants;
import com.google.android.material.R;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes7.dex */
public class ShapeAppearanceModel {
public static final int NUM_CORNERS = 4;
public static final CornerSize PILL = new RelativeCornerSize(0.5f);
EdgeTreatment bottomEdge;
CornerTreatment bottomLeftCorner;
CornerSize bottomLeftCornerSize;
CornerTreatment bottomRightCorner;
CornerSize bottomRightCornerSize;
EdgeTreatment leftEdge;
EdgeTreatment rightEdge;
EdgeTreatment topEdge;
CornerTreatment topLeftCorner;
CornerSize topLeftCornerSize;
CornerTreatment topRightCorner;
CornerSize topRightCornerSize;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public interface CornerSizeUnaryOperator {
@NonNull
CornerSize apply(@NonNull CornerSize cornerSize);
}
public ShapeAppearanceModel() {
this.topLeftCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.topRightCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.bottomRightCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.bottomLeftCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.topLeftCornerSize = new AbsoluteCornerSize(0.0f);
this.topRightCornerSize = new AbsoluteCornerSize(0.0f);
this.bottomRightCornerSize = new AbsoluteCornerSize(0.0f);
this.bottomLeftCornerSize = new AbsoluteCornerSize(0.0f);
this.topEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.rightEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.bottomEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.leftEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
}
@NonNull
private static Builder builder(Context context, @StyleRes int i, @StyleRes int i2, @NonNull CornerSize cornerSize) {
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(context, i);
if (i2 != 0) {
contextThemeWrapper.getTheme().applyStyle(i2, true);
}
TypedArray obtainStyledAttributes = contextThemeWrapper.obtainStyledAttributes(R.styleable.ShapeAppearance);
try {
int i3 = obtainStyledAttributes.getInt(R.styleable.ShapeAppearance_cornerFamily, 0);
int i4 = obtainStyledAttributes.getInt(R.styleable.ShapeAppearance_cornerFamilyTopLeft, i3);
int i5 = obtainStyledAttributes.getInt(R.styleable.ShapeAppearance_cornerFamilyTopRight, i3);
int i6 = obtainStyledAttributes.getInt(R.styleable.ShapeAppearance_cornerFamilyBottomRight, i3);
int i7 = obtainStyledAttributes.getInt(R.styleable.ShapeAppearance_cornerFamilyBottomLeft, i3);
CornerSize cornerSize2 = getCornerSize(obtainStyledAttributes, R.styleable.ShapeAppearance_cornerSize, cornerSize);
CornerSize cornerSize3 = getCornerSize(obtainStyledAttributes, R.styleable.ShapeAppearance_cornerSizeTopLeft, cornerSize2);
CornerSize cornerSize4 = getCornerSize(obtainStyledAttributes, R.styleable.ShapeAppearance_cornerSizeTopRight, cornerSize2);
CornerSize cornerSize5 = getCornerSize(obtainStyledAttributes, R.styleable.ShapeAppearance_cornerSizeBottomRight, cornerSize2);
return new Builder().setTopLeftCorner(i4, cornerSize3).setTopRightCorner(i5, cornerSize4).setBottomRightCorner(i6, cornerSize5).setBottomLeftCorner(i7, getCornerSize(obtainStyledAttributes, R.styleable.ShapeAppearance_cornerSizeBottomLeft, cornerSize2));
} finally {
obtainStyledAttributes.recycle();
}
}
@NonNull
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public static CornerSize getCornerSize(@NonNull TypedArray typedArray, int i, @NonNull CornerSize cornerSize) {
TypedValue peekValue = typedArray.peekValue(i);
if (peekValue != null) {
int i2 = peekValue.type;
if (i2 == 5) {
return new AbsoluteCornerSize(TypedValue.complexToDimensionPixelSize(peekValue.data, typedArray.getResources().getDisplayMetrics()));
}
if (i2 == 6) {
return new RelativeCornerSize(peekValue.getFraction(1.0f, 1.0f));
}
}
return cornerSize;
}
@NonNull
public EdgeTreatment getBottomEdge() {
return this.bottomEdge;
}
@NonNull
public CornerTreatment getBottomLeftCorner() {
return this.bottomLeftCorner;
}
@NonNull
public CornerSize getBottomLeftCornerSize() {
return this.bottomLeftCornerSize;
}
@NonNull
public CornerTreatment getBottomRightCorner() {
return this.bottomRightCorner;
}
@NonNull
public CornerSize getBottomRightCornerSize() {
return this.bottomRightCornerSize;
}
@NonNull
public EdgeTreatment getLeftEdge() {
return this.leftEdge;
}
@NonNull
public EdgeTreatment getRightEdge() {
return this.rightEdge;
}
@NonNull
public EdgeTreatment getTopEdge() {
return this.topEdge;
}
@NonNull
public CornerTreatment getTopLeftCorner() {
return this.topLeftCorner;
}
@NonNull
public CornerSize getTopLeftCornerSize() {
return this.topLeftCornerSize;
}
@NonNull
public CornerTreatment getTopRightCorner() {
return this.topRightCorner;
}
@NonNull
public CornerSize getTopRightCornerSize() {
return this.topRightCornerSize;
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public boolean hasRoundedCorners() {
return (this.topRightCorner instanceof RoundedCornerTreatment) && (this.topLeftCorner instanceof RoundedCornerTreatment) && (this.bottomRightCorner instanceof RoundedCornerTreatment) && (this.bottomLeftCorner instanceof RoundedCornerTreatment);
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public boolean isRoundRect(@NonNull RectF rectF) {
boolean z = this.leftEdge.getClass().equals(EdgeTreatment.class) && this.rightEdge.getClass().equals(EdgeTreatment.class) && this.topEdge.getClass().equals(EdgeTreatment.class) && this.bottomEdge.getClass().equals(EdgeTreatment.class);
float cornerSize = this.topLeftCornerSize.getCornerSize(rectF);
return z && ((this.topRightCornerSize.getCornerSize(rectF) > cornerSize ? 1 : (this.topRightCornerSize.getCornerSize(rectF) == cornerSize ? 0 : -1)) == 0 && (this.bottomLeftCornerSize.getCornerSize(rectF) > cornerSize ? 1 : (this.bottomLeftCornerSize.getCornerSize(rectF) == cornerSize ? 0 : -1)) == 0 && (this.bottomRightCornerSize.getCornerSize(rectF) > cornerSize ? 1 : (this.bottomRightCornerSize.getCornerSize(rectF) == cornerSize ? 0 : -1)) == 0) && hasRoundedCorners();
}
@NonNull
public Builder toBuilder() {
return new Builder(this);
}
@NonNull
public String toString() {
return MarkdownConstants.LEFT_BRACKET + getTopLeftCornerSize() + ", " + getTopRightCornerSize() + ", " + getBottomRightCornerSize() + ", " + getBottomLeftCornerSize() + MarkdownConstants.RIGHT_BRACKET;
}
@NonNull
public ShapeAppearanceModel withCornerSize(float f) {
return toBuilder().setAllCornerSizes(f).build();
}
@NonNull
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public ShapeAppearanceModel withTransformedCornerSizes(@NonNull CornerSizeUnaryOperator cornerSizeUnaryOperator) {
return toBuilder().setTopLeftCornerSize(cornerSizeUnaryOperator.apply(getTopLeftCornerSize())).setTopRightCornerSize(cornerSizeUnaryOperator.apply(getTopRightCornerSize())).setBottomLeftCornerSize(cornerSizeUnaryOperator.apply(getBottomLeftCornerSize())).setBottomRightCornerSize(cornerSizeUnaryOperator.apply(getBottomRightCornerSize())).build();
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static final class Builder {
@NonNull
private EdgeTreatment bottomEdge;
@NonNull
private CornerTreatment bottomLeftCorner;
@NonNull
private CornerSize bottomLeftCornerSize;
@NonNull
private CornerTreatment bottomRightCorner;
@NonNull
private CornerSize bottomRightCornerSize;
@NonNull
private EdgeTreatment leftEdge;
@NonNull
private EdgeTreatment rightEdge;
@NonNull
private EdgeTreatment topEdge;
@NonNull
private CornerTreatment topLeftCorner;
@NonNull
private CornerSize topLeftCornerSize;
@NonNull
private CornerTreatment topRightCorner;
@NonNull
private CornerSize topRightCornerSize;
public Builder(@NonNull ShapeAppearanceModel shapeAppearanceModel) {
this.topLeftCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.topRightCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.bottomRightCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.bottomLeftCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.topLeftCornerSize = new AbsoluteCornerSize(0.0f);
this.topRightCornerSize = new AbsoluteCornerSize(0.0f);
this.bottomRightCornerSize = new AbsoluteCornerSize(0.0f);
this.bottomLeftCornerSize = new AbsoluteCornerSize(0.0f);
this.topEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.rightEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.bottomEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.leftEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.topLeftCorner = shapeAppearanceModel.topLeftCorner;
this.topRightCorner = shapeAppearanceModel.topRightCorner;
this.bottomRightCorner = shapeAppearanceModel.bottomRightCorner;
this.bottomLeftCorner = shapeAppearanceModel.bottomLeftCorner;
this.topLeftCornerSize = shapeAppearanceModel.topLeftCornerSize;
this.topRightCornerSize = shapeAppearanceModel.topRightCornerSize;
this.bottomRightCornerSize = shapeAppearanceModel.bottomRightCornerSize;
this.bottomLeftCornerSize = shapeAppearanceModel.bottomLeftCornerSize;
this.topEdge = shapeAppearanceModel.topEdge;
this.rightEdge = shapeAppearanceModel.rightEdge;
this.bottomEdge = shapeAppearanceModel.bottomEdge;
this.leftEdge = shapeAppearanceModel.leftEdge;
}
private static float compatCornerTreatmentSize(CornerTreatment cornerTreatment) {
if (cornerTreatment instanceof RoundedCornerTreatment) {
return ((RoundedCornerTreatment) cornerTreatment).radius;
}
if (cornerTreatment instanceof CutCornerTreatment) {
return ((CutCornerTreatment) cornerTreatment).size;
}
return -1.0f;
}
@NonNull
public ShapeAppearanceModel build() {
return new ShapeAppearanceModel(this);
}
@NonNull
@CanIgnoreReturnValue
public Builder setAllCornerSizes(@NonNull CornerSize cornerSize) {
return setTopLeftCornerSize(cornerSize).setTopRightCornerSize(cornerSize).setBottomRightCornerSize(cornerSize).setBottomLeftCornerSize(cornerSize);
}
@NonNull
@CanIgnoreReturnValue
public Builder setAllCorners(@NonNull CornerTreatment cornerTreatment) {
return setTopLeftCorner(cornerTreatment).setTopRightCorner(cornerTreatment).setBottomRightCorner(cornerTreatment).setBottomLeftCorner(cornerTreatment);
}
@NonNull
@CanIgnoreReturnValue
public Builder setAllEdges(@NonNull EdgeTreatment edgeTreatment) {
return setLeftEdge(edgeTreatment).setTopEdge(edgeTreatment).setRightEdge(edgeTreatment).setBottomEdge(edgeTreatment);
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomEdge(@NonNull EdgeTreatment edgeTreatment) {
this.bottomEdge = edgeTreatment;
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomLeftCorner(@NonNull CornerTreatment cornerTreatment) {
this.bottomLeftCorner = cornerTreatment;
float compatCornerTreatmentSize = compatCornerTreatmentSize(cornerTreatment);
if (compatCornerTreatmentSize != -1.0f) {
setBottomLeftCornerSize(compatCornerTreatmentSize);
}
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomLeftCornerSize(@Dimension float f) {
this.bottomLeftCornerSize = new AbsoluteCornerSize(f);
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomRightCorner(@NonNull CornerTreatment cornerTreatment) {
this.bottomRightCorner = cornerTreatment;
float compatCornerTreatmentSize = compatCornerTreatmentSize(cornerTreatment);
if (compatCornerTreatmentSize != -1.0f) {
setBottomRightCornerSize(compatCornerTreatmentSize);
}
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomRightCornerSize(@Dimension float f) {
this.bottomRightCornerSize = new AbsoluteCornerSize(f);
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setLeftEdge(@NonNull EdgeTreatment edgeTreatment) {
this.leftEdge = edgeTreatment;
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setRightEdge(@NonNull EdgeTreatment edgeTreatment) {
this.rightEdge = edgeTreatment;
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopEdge(@NonNull EdgeTreatment edgeTreatment) {
this.topEdge = edgeTreatment;
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopLeftCorner(@NonNull CornerTreatment cornerTreatment) {
this.topLeftCorner = cornerTreatment;
float compatCornerTreatmentSize = compatCornerTreatmentSize(cornerTreatment);
if (compatCornerTreatmentSize != -1.0f) {
setTopLeftCornerSize(compatCornerTreatmentSize);
}
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopLeftCornerSize(@Dimension float f) {
this.topLeftCornerSize = new AbsoluteCornerSize(f);
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopRightCorner(@NonNull CornerTreatment cornerTreatment) {
this.topRightCorner = cornerTreatment;
float compatCornerTreatmentSize = compatCornerTreatmentSize(cornerTreatment);
if (compatCornerTreatmentSize != -1.0f) {
setTopRightCornerSize(compatCornerTreatmentSize);
}
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopRightCornerSize(@Dimension float f) {
this.topRightCornerSize = new AbsoluteCornerSize(f);
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomLeftCornerSize(@NonNull CornerSize cornerSize) {
this.bottomLeftCornerSize = cornerSize;
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomRightCornerSize(@NonNull CornerSize cornerSize) {
this.bottomRightCornerSize = cornerSize;
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopLeftCornerSize(@NonNull CornerSize cornerSize) {
this.topLeftCornerSize = cornerSize;
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopRightCornerSize(@NonNull CornerSize cornerSize) {
this.topRightCornerSize = cornerSize;
return this;
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomLeftCorner(int i, @NonNull CornerSize cornerSize) {
return setBottomLeftCorner(MaterialShapeUtils.createCornerTreatment(i)).setBottomLeftCornerSize(cornerSize);
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomRightCorner(int i, @NonNull CornerSize cornerSize) {
return setBottomRightCorner(MaterialShapeUtils.createCornerTreatment(i)).setBottomRightCornerSize(cornerSize);
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopLeftCorner(int i, @NonNull CornerSize cornerSize) {
return setTopLeftCorner(MaterialShapeUtils.createCornerTreatment(i)).setTopLeftCornerSize(cornerSize);
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopRightCorner(int i, @NonNull CornerSize cornerSize) {
return setTopRightCorner(MaterialShapeUtils.createCornerTreatment(i)).setTopRightCornerSize(cornerSize);
}
@NonNull
@CanIgnoreReturnValue
public Builder setAllCornerSizes(@Dimension float f) {
return setTopLeftCornerSize(f).setTopRightCornerSize(f).setBottomRightCornerSize(f).setBottomLeftCornerSize(f);
}
@NonNull
@CanIgnoreReturnValue
public Builder setAllCorners(int i, @Dimension float f) {
return setAllCorners(MaterialShapeUtils.createCornerTreatment(i)).setAllCornerSizes(f);
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomLeftCorner(int i, @Dimension float f) {
return setBottomLeftCorner(MaterialShapeUtils.createCornerTreatment(i)).setBottomLeftCornerSize(f);
}
@NonNull
@CanIgnoreReturnValue
public Builder setBottomRightCorner(int i, @Dimension float f) {
return setBottomRightCorner(MaterialShapeUtils.createCornerTreatment(i)).setBottomRightCornerSize(f);
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopLeftCorner(int i, @Dimension float f) {
return setTopLeftCorner(MaterialShapeUtils.createCornerTreatment(i)).setTopLeftCornerSize(f);
}
@NonNull
@CanIgnoreReturnValue
public Builder setTopRightCorner(int i, @Dimension float f) {
return setTopRightCorner(MaterialShapeUtils.createCornerTreatment(i)).setTopRightCornerSize(f);
}
public Builder() {
this.topLeftCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.topRightCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.bottomRightCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.bottomLeftCorner = MaterialShapeUtils.createDefaultCornerTreatment();
this.topLeftCornerSize = new AbsoluteCornerSize(0.0f);
this.topRightCornerSize = new AbsoluteCornerSize(0.0f);
this.bottomRightCornerSize = new AbsoluteCornerSize(0.0f);
this.bottomLeftCornerSize = new AbsoluteCornerSize(0.0f);
this.topEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.rightEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.bottomEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
this.leftEdge = MaterialShapeUtils.createDefaultEdgeTreatment();
}
}
@NonNull
public ShapeAppearanceModel withCornerSize(@NonNull CornerSize cornerSize) {
return toBuilder().setAllCornerSizes(cornerSize).build();
}
private ShapeAppearanceModel(@NonNull Builder builder) {
this.topLeftCorner = builder.topLeftCorner;
this.topRightCorner = builder.topRightCorner;
this.bottomRightCorner = builder.bottomRightCorner;
this.bottomLeftCorner = builder.bottomLeftCorner;
this.topLeftCornerSize = builder.topLeftCornerSize;
this.topRightCornerSize = builder.topRightCornerSize;
this.bottomRightCornerSize = builder.bottomRightCornerSize;
this.bottomLeftCornerSize = builder.bottomLeftCornerSize;
this.topEdge = builder.topEdge;
this.rightEdge = builder.rightEdge;
this.bottomEdge = builder.bottomEdge;
this.leftEdge = builder.leftEdge;
}
@NonNull
public static Builder builder(@NonNull Context context, AttributeSet attributeSet, @AttrRes int i, @StyleRes int i2) {
return builder(context, attributeSet, i, i2, 0);
}
@NonNull
public static Builder builder(@NonNull Context context, AttributeSet attributeSet, @AttrRes int i, @StyleRes int i2, int i3) {
return builder(context, attributeSet, i, i2, new AbsoluteCornerSize(i3));
}
@NonNull
public static Builder builder(@NonNull Context context, AttributeSet attributeSet, @AttrRes int i, @StyleRes int i2, @NonNull CornerSize cornerSize) {
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.MaterialShape, i, i2);
int resourceId = obtainStyledAttributes.getResourceId(R.styleable.MaterialShape_shapeAppearance, 0);
int resourceId2 = obtainStyledAttributes.getResourceId(R.styleable.MaterialShape_shapeAppearanceOverlay, 0);
obtainStyledAttributes.recycle();
return builder(context, resourceId, resourceId2, cornerSize);
}
@NonNull
public static Builder builder(Context context, @StyleRes int i, @StyleRes int i2) {
return builder(context, i, i2, 0);
}
@NonNull
private static Builder builder(Context context, @StyleRes int i, @StyleRes int i2, int i3) {
return builder(context, i, i2, new AbsoluteCornerSize(i3));
}
@NonNull
public static Builder builder() {
return new Builder();
}
}