alexandroid/decompiled/jadx/sources/com/google/android/material/shape/ShapeAppearancePathProvider.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

253 lines
11 KiB
Java

package com.google.android.material.shape;
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RectF;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.annotation.UiThread;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes7.dex */
public class ShapeAppearancePathProvider {
protected static final int BOTTOM_LEFT_CORNER_INDEX = 2;
protected static final int BOTTOM_RIGHT_CORNER_INDEX = 1;
protected static final int TOP_LEFT_CORNER_INDEX = 3;
protected static final int TOP_RIGHT_CORNER_INDEX = 0;
private final ShapePath[] cornerPaths = new ShapePath[4];
private final Matrix[] cornerTransforms = new Matrix[4];
private final Matrix[] edgeTransforms = new Matrix[4];
private final PointF pointF = new PointF();
private final Path overlappedEdgePath = new Path();
private final Path boundsPath = new Path();
private final ShapePath shapePath = new ShapePath();
private final float[] scratch = new float[2];
private final float[] scratch2 = new float[2];
private final Path edgePath = new Path();
private final Path cornerPath = new Path();
private boolean edgeIntersectionCheckEnabled = true;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static class Lazy {
static final ShapeAppearancePathProvider INSTANCE = new ShapeAppearancePathProvider();
private Lazy() {
}
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public interface PathListener {
void onCornerPathCreated(ShapePath shapePath, Matrix matrix, int i);
void onEdgePathCreated(ShapePath shapePath, Matrix matrix, int i);
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static final class ShapeAppearancePathSpec {
@NonNull
public final RectF bounds;
public final float interpolation;
@NonNull
public final Path path;
@Nullable
public final PathListener pathListener;
@NonNull
public final ShapeAppearanceModel shapeAppearanceModel;
public ShapeAppearancePathSpec(@NonNull ShapeAppearanceModel shapeAppearanceModel, float f, RectF rectF, @Nullable PathListener pathListener, Path path) {
this.pathListener = pathListener;
this.shapeAppearanceModel = shapeAppearanceModel;
this.interpolation = f;
this.bounds = rectF;
this.path = path;
}
}
public ShapeAppearancePathProvider() {
for (int i = 0; i < 4; i++) {
this.cornerPaths[i] = new ShapePath();
this.cornerTransforms[i] = new Matrix();
this.edgeTransforms[i] = new Matrix();
}
}
private float angleOfEdge(int i) {
return ((i + 1) % 4) * 90;
}
private void appendCornerPath(@NonNull ShapeAppearancePathSpec shapeAppearancePathSpec, int i) {
this.scratch[0] = this.cornerPaths[i].getStartX();
this.scratch[1] = this.cornerPaths[i].getStartY();
this.cornerTransforms[i].mapPoints(this.scratch);
if (i == 0) {
Path path = shapeAppearancePathSpec.path;
float[] fArr = this.scratch;
path.moveTo(fArr[0], fArr[1]);
} else {
Path path2 = shapeAppearancePathSpec.path;
float[] fArr2 = this.scratch;
path2.lineTo(fArr2[0], fArr2[1]);
}
this.cornerPaths[i].applyToPath(this.cornerTransforms[i], shapeAppearancePathSpec.path);
PathListener pathListener = shapeAppearancePathSpec.pathListener;
if (pathListener != null) {
pathListener.onCornerPathCreated(this.cornerPaths[i], this.cornerTransforms[i], i);
}
}
private void appendEdgePath(@NonNull ShapeAppearancePathSpec shapeAppearancePathSpec, int i) {
int i2 = (i + 1) % 4;
this.scratch[0] = this.cornerPaths[i].getEndX();
this.scratch[1] = this.cornerPaths[i].getEndY();
this.cornerTransforms[i].mapPoints(this.scratch);
this.scratch2[0] = this.cornerPaths[i2].getStartX();
this.scratch2[1] = this.cornerPaths[i2].getStartY();
this.cornerTransforms[i2].mapPoints(this.scratch2);
float f = this.scratch[0];
float[] fArr = this.scratch2;
float max = Math.max(((float) Math.hypot(f - fArr[0], r1[1] - fArr[1])) - 0.001f, 0.0f);
float edgeCenterForIndex = getEdgeCenterForIndex(shapeAppearancePathSpec.bounds, i);
this.shapePath.reset(0.0f, 0.0f);
EdgeTreatment edgeTreatmentForIndex = getEdgeTreatmentForIndex(i, shapeAppearancePathSpec.shapeAppearanceModel);
edgeTreatmentForIndex.getEdgePath(max, edgeCenterForIndex, shapeAppearancePathSpec.interpolation, this.shapePath);
this.edgePath.reset();
this.shapePath.applyToPath(this.edgeTransforms[i], this.edgePath);
if (this.edgeIntersectionCheckEnabled && (edgeTreatmentForIndex.forceIntersection() || pathOverlapsCorner(this.edgePath, i) || pathOverlapsCorner(this.edgePath, i2))) {
Path path = this.edgePath;
path.op(path, this.boundsPath, Path.Op.DIFFERENCE);
this.scratch[0] = this.shapePath.getStartX();
this.scratch[1] = this.shapePath.getStartY();
this.edgeTransforms[i].mapPoints(this.scratch);
Path path2 = this.overlappedEdgePath;
float[] fArr2 = this.scratch;
path2.moveTo(fArr2[0], fArr2[1]);
this.shapePath.applyToPath(this.edgeTransforms[i], this.overlappedEdgePath);
} else {
this.shapePath.applyToPath(this.edgeTransforms[i], shapeAppearancePathSpec.path);
}
PathListener pathListener = shapeAppearancePathSpec.pathListener;
if (pathListener != null) {
pathListener.onEdgePathCreated(this.shapePath, this.edgeTransforms[i], i);
}
}
private void getCoordinatesOfCorner(int i, @NonNull RectF rectF, @NonNull PointF pointF) {
if (i == 1) {
pointF.set(rectF.right, rectF.bottom);
return;
}
if (i == 2) {
pointF.set(rectF.left, rectF.bottom);
} else if (i != 3) {
pointF.set(rectF.right, rectF.top);
} else {
pointF.set(rectF.left, rectF.top);
}
}
private CornerTreatment getCornerTreatmentForIndex(int i, @NonNull ShapeAppearanceModel shapeAppearanceModel) {
return i != 1 ? i != 2 ? i != 3 ? shapeAppearanceModel.getTopRightCorner() : shapeAppearanceModel.getTopLeftCorner() : shapeAppearanceModel.getBottomLeftCorner() : shapeAppearanceModel.getBottomRightCorner();
}
private float getEdgeCenterForIndex(@NonNull RectF rectF, int i) {
float[] fArr = this.scratch;
ShapePath shapePath = this.cornerPaths[i];
fArr[0] = shapePath.endX;
fArr[1] = shapePath.endY;
this.cornerTransforms[i].mapPoints(fArr);
return (i == 1 || i == 3) ? Math.abs(rectF.centerX() - this.scratch[0]) : Math.abs(rectF.centerY() - this.scratch[1]);
}
private EdgeTreatment getEdgeTreatmentForIndex(int i, @NonNull ShapeAppearanceModel shapeAppearanceModel) {
return i != 1 ? i != 2 ? i != 3 ? shapeAppearanceModel.getRightEdge() : shapeAppearanceModel.getTopEdge() : shapeAppearanceModel.getLeftEdge() : shapeAppearanceModel.getBottomEdge();
}
@NonNull
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
@UiThread
public static ShapeAppearancePathProvider getInstance() {
return Lazy.INSTANCE;
}
private boolean pathOverlapsCorner(Path path, int i) {
this.cornerPath.reset();
this.cornerPaths[i].applyToPath(this.cornerTransforms[i], this.cornerPath);
RectF rectF = new RectF();
path.computeBounds(rectF, true);
this.cornerPath.computeBounds(rectF, true);
path.op(this.cornerPath, Path.Op.INTERSECT);
path.computeBounds(rectF, true);
return !rectF.isEmpty() || (rectF.width() > 1.0f && rectF.height() > 1.0f);
}
private void setCornerPathAndTransform(@NonNull ShapeAppearancePathSpec shapeAppearancePathSpec, int i, @Nullable float[] fArr) {
getCornerTreatmentForIndex(i, shapeAppearancePathSpec.shapeAppearanceModel).getCornerPath(this.cornerPaths[i], 90.0f, shapeAppearancePathSpec.interpolation, shapeAppearancePathSpec.bounds, fArr == null ? getCornerSizeForIndex(i, shapeAppearancePathSpec.shapeAppearanceModel) : new ClampedCornerSize(fArr[i]));
float angleOfEdge = angleOfEdge(i);
this.cornerTransforms[i].reset();
getCoordinatesOfCorner(i, shapeAppearancePathSpec.bounds, this.pointF);
Matrix matrix = this.cornerTransforms[i];
PointF pointF = this.pointF;
matrix.setTranslate(pointF.x, pointF.y);
this.cornerTransforms[i].preRotate(angleOfEdge);
}
private void setEdgePathAndTransform(int i) {
this.scratch[0] = this.cornerPaths[i].getEndX();
this.scratch[1] = this.cornerPaths[i].getEndY();
this.cornerTransforms[i].mapPoints(this.scratch);
float angleOfEdge = angleOfEdge(i);
this.edgeTransforms[i].reset();
Matrix matrix = this.edgeTransforms[i];
float[] fArr = this.scratch;
matrix.setTranslate(fArr[0], fArr[1]);
this.edgeTransforms[i].preRotate(angleOfEdge);
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public void calculatePath(@NonNull ShapeAppearanceModel shapeAppearanceModel, @Nullable float[] fArr, float f, RectF rectF, PathListener pathListener, @NonNull Path path) {
path.rewind();
this.overlappedEdgePath.rewind();
this.boundsPath.rewind();
this.boundsPath.addRect(rectF, Path.Direction.CW);
ShapeAppearancePathSpec shapeAppearancePathSpec = new ShapeAppearancePathSpec(shapeAppearanceModel, f, rectF, pathListener, path);
for (int i = 0; i < 4; i++) {
setCornerPathAndTransform(shapeAppearancePathSpec, i, fArr);
setEdgePathAndTransform(i);
}
for (int i2 = 0; i2 < 4; i2++) {
appendCornerPath(shapeAppearancePathSpec, i2);
appendEdgePath(shapeAppearancePathSpec, i2);
}
path.close();
this.overlappedEdgePath.close();
if (this.overlappedEdgePath.isEmpty()) {
return;
}
path.op(this.overlappedEdgePath, Path.Op.UNION);
}
@NonNull
public CornerSize getCornerSizeForIndex(int i, @NonNull ShapeAppearanceModel shapeAppearanceModel) {
return i != 1 ? i != 2 ? i != 3 ? shapeAppearanceModel.getTopRightCornerSize() : shapeAppearanceModel.getTopLeftCornerSize() : shapeAppearanceModel.getBottomLeftCornerSize() : shapeAppearanceModel.getBottomRightCornerSize();
}
public void setEdgeIntersectionCheckEnable(boolean z) {
this.edgeIntersectionCheckEnabled = z;
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public void calculatePath(ShapeAppearanceModel shapeAppearanceModel, float f, RectF rectF, PathListener pathListener, @NonNull Path path) {
calculatePath(shapeAppearanceModel, null, f, rectF, pathListener, path);
}
public void calculatePath(ShapeAppearanceModel shapeAppearanceModel, float f, RectF rectF, @NonNull Path path) {
calculatePath(shapeAppearanceModel, f, rectF, null, path);
}
}