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

230 lines
11 KiB
Java

package com.google.android.material.transition;
import android.animation.TimeInterpolator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.TypedValue;
import android.view.View;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.FloatRange;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.biometric.ErrorUtils$$ExternalSyntheticOutline0;
import androidx.compose.runtime.BitVector$$ExternalSyntheticOutline0;
import androidx.core.graphics.PathParser;
import androidx.transition.PathMotion;
import androidx.transition.PatternPathMotion;
import androidx.transition.Transition;
import androidx.transition.TransitionSet;
import com.google.android.material.canvas.CanvasCompat;
import com.google.android.material.motion.MotionUtils;
import com.google.android.material.shape.AbsoluteCornerSize;
import com.google.android.material.shape.CornerSize;
import com.google.android.material.shape.RelativeCornerSize;
import com.google.android.material.shape.ShapeAppearanceModel;
import defpackage.a$$ExternalSyntheticOutline0;
import rx.Single$$ExternalSyntheticBUOutline0;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes7.dex */
class TransitionUtils {
@AttrRes
static final int NO_ATTR_RES_ID = 0;
static final int NO_DURATION = -1;
private static final int PATH_TYPE_ARC = 1;
private static final int PATH_TYPE_LINEAR = 0;
private static final RectF transformAlphaRectF = new RectF();
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public interface CornerSizeBinaryOperator {
@NonNull
CornerSize apply(@NonNull CornerSize cornerSize, @NonNull CornerSize cornerSize2);
}
private TransitionUtils() {
}
public static float calculateArea(@NonNull RectF rectF) {
return rectF.height() * rectF.width();
}
public static ShapeAppearanceModel convertToRelativeCornerSizes(ShapeAppearanceModel shapeAppearanceModel, final RectF rectF) {
return shapeAppearanceModel.withTransformedCornerSizes(new ShapeAppearanceModel.CornerSizeUnaryOperator() { // from class: com.google.android.material.transition.TransitionUtils$$ExternalSyntheticLambda0
@Override // com.google.android.material.shape.ShapeAppearanceModel.CornerSizeUnaryOperator
public final CornerSize apply(CornerSize cornerSize) {
CornerSize createFromCornerSize;
createFromCornerSize = RelativeCornerSize.createFromCornerSize(rectF, cornerSize);
return createFromCornerSize;
}
});
}
public static Shader createColorShader(@ColorInt int i) {
return new LinearGradient(0.0f, 0.0f, 0.0f, 0.0f, i, i, Shader.TileMode.CLAMP);
}
@NonNull
public static <T> T defaultIfNull(@Nullable T t, @NonNull T t2) {
return t != null ? t : t2;
}
public static View findAncestorById(View view, @IdRes int i) {
String resourceName = view.getResources().getResourceName(i);
while (view != null) {
if (view.getId() != i) {
Object parent = view.getParent();
if (!(parent instanceof View)) {
break;
}
view = (View) parent;
} else {
return view;
}
}
Single$$ExternalSyntheticBUOutline0.m$3(BitVector$$ExternalSyntheticOutline0.m(resourceName, " is not a valid ancestor"));
return null;
}
public static View findDescendantOrAncestorById(View view, @IdRes int i) {
View findViewById = view.findViewById(i);
return findViewById != null ? findViewById : findAncestorById(view, i);
}
public static RectF getLocationInWindow(View view) {
int[] iArr = new int[2];
view.getLocationInWindow(iArr);
return new RectF(iArr[0], iArr[1], view.getWidth() + r1, view.getHeight() + r0);
}
public static RectF getRelativeBounds(View view) {
return new RectF(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
}
public static Rect getRelativeBoundsRect(View view) {
return new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
}
private static boolean isShapeAppearanceSignificant(ShapeAppearanceModel shapeAppearanceModel, RectF rectF) {
return (shapeAppearanceModel.getTopLeftCornerSize().getCornerSize(rectF) == 0.0f && shapeAppearanceModel.getTopRightCornerSize().getCornerSize(rectF) == 0.0f && shapeAppearanceModel.getBottomRightCornerSize().getCornerSize(rectF) == 0.0f && shapeAppearanceModel.getBottomLeftCornerSize().getCornerSize(rectF) == 0.0f) ? false : true;
}
public static float lerp(float f, float f2, @FloatRange(from = 0.0d, to = 1.0d) float f3, @FloatRange(from = 0.0d, to = 1.0d) float f4, @FloatRange(from = 0.0d) float f5, boolean z) {
return (!z || (f5 >= 0.0f && f5 <= 1.0f)) ? f5 < f3 ? f : f5 > f4 ? f2 : lerp(f, f2, (f5 - f3) / (f4 - f3)) : lerp(f, f2, f5);
}
public static void maybeAddTransition(TransitionSet transitionSet, @Nullable Transition transition) {
if (transition != null) {
transitionSet.addTransition(transition);
}
}
public static boolean maybeApplyThemeDuration(Transition transition, Context context, @AttrRes int i) {
int resolveThemeDuration;
if (i == 0 || transition.getDuration() != -1 || (resolveThemeDuration = MotionUtils.resolveThemeDuration(context, i, -1)) == -1) {
return false;
}
transition.setDuration(resolveThemeDuration);
return true;
}
public static boolean maybeApplyThemeInterpolator(Transition transition, Context context, @AttrRes int i, TimeInterpolator timeInterpolator) {
if (i == 0 || transition.getInterpolator() != null) {
return false;
}
transition.setInterpolator(MotionUtils.resolveThemeInterpolator(context, i, timeInterpolator));
return true;
}
public static boolean maybeApplyThemePath(Transition transition, Context context, @AttrRes int i) {
PathMotion resolveThemePath;
if (i == 0 || (resolveThemePath = resolveThemePath(context, i)) == null) {
return false;
}
transition.setPathMotion(resolveThemePath);
return true;
}
public static void maybeRemoveTransition(TransitionSet transitionSet, @Nullable Transition transition) {
if (transition != null) {
transitionSet.removeTransition(transition);
}
}
@Nullable
public static PathMotion resolveThemePath(Context context, @AttrRes int i) {
TypedValue typedValue = new TypedValue();
if (!context.getTheme().resolveAttribute(i, typedValue, true)) {
return null;
}
int i2 = typedValue.type;
if (i2 != 16) {
if (i2 == 3) {
return new PatternPathMotion(PathParser.createPathFromPathData(String.valueOf(typedValue.string)));
}
Single$$ExternalSyntheticBUOutline0.m$3("Motion path theme attribute must either be an enum value or path data string");
return null;
}
int i3 = typedValue.data;
if (i3 == 0) {
return null;
}
if (i3 == 1) {
return new MaterialArcMotion();
}
Single$$ExternalSyntheticBUOutline0.m$3(a$$ExternalSyntheticOutline0.m(i3, "Invalid motion path type: "));
return null;
}
private static int saveLayerAlphaCompat(Canvas canvas, Rect rect, int i) {
RectF rectF = transformAlphaRectF;
rectF.set(rect);
return canvas.saveLayerAlpha(rectF, i);
}
public static void transform(Canvas canvas, Rect rect, float f, float f2, float f3, int i, CanvasCompat.CanvasOperation canvasOperation) {
if (i <= 0) {
return;
}
int save = canvas.save();
canvas.translate(f, f2);
canvas.scale(f3, f3);
if (i < 255) {
saveLayerAlphaCompat(canvas, rect, i);
}
canvasOperation.run(canvas);
canvas.restoreToCount(save);
}
public static ShapeAppearanceModel transformCornerSizes(ShapeAppearanceModel shapeAppearanceModel, ShapeAppearanceModel shapeAppearanceModel2, RectF rectF, CornerSizeBinaryOperator cornerSizeBinaryOperator) {
return (isShapeAppearanceSignificant(shapeAppearanceModel, rectF) ? shapeAppearanceModel : shapeAppearanceModel2).toBuilder().setTopLeftCornerSize(cornerSizeBinaryOperator.apply(shapeAppearanceModel.getTopLeftCornerSize(), shapeAppearanceModel2.getTopLeftCornerSize())).setTopRightCornerSize(cornerSizeBinaryOperator.apply(shapeAppearanceModel.getTopRightCornerSize(), shapeAppearanceModel2.getTopRightCornerSize())).setBottomLeftCornerSize(cornerSizeBinaryOperator.apply(shapeAppearanceModel.getBottomLeftCornerSize(), shapeAppearanceModel2.getBottomLeftCornerSize())).setBottomRightCornerSize(cornerSizeBinaryOperator.apply(shapeAppearanceModel.getBottomRightCornerSize(), shapeAppearanceModel2.getBottomRightCornerSize())).build();
}
public static float lerp(float f, float f2, @FloatRange(from = 0.0d, to = 1.0d) float f3, @FloatRange(from = 0.0d, to = 1.0d) float f4, @FloatRange(from = 0.0d, to = 1.0d) float f5) {
return lerp(f, f2, f3, f4, f5, false);
}
public static float lerp(float f, float f2, float f3) {
return ErrorUtils$$ExternalSyntheticOutline0.m(f2, f, f3, f);
}
public static int lerp(int i, int i2, @FloatRange(from = 0.0d, to = 1.0d) float f, @FloatRange(from = 0.0d, to = 1.0d) float f2, @FloatRange(from = 0.0d, to = 1.0d) float f3) {
return f3 < f ? i : f3 > f2 ? i2 : (int) lerp(i, i2, (f3 - f) / (f2 - f));
}
public static ShapeAppearanceModel lerp(ShapeAppearanceModel shapeAppearanceModel, ShapeAppearanceModel shapeAppearanceModel2, final RectF rectF, final RectF rectF2, @FloatRange(from = 0.0d, to = 1.0d) final float f, @FloatRange(from = 0.0d, to = 1.0d) final float f2, @FloatRange(from = 0.0d, to = 1.0d) final float f3) {
return f3 < f ? shapeAppearanceModel : f3 > f2 ? shapeAppearanceModel2 : transformCornerSizes(shapeAppearanceModel, shapeAppearanceModel2, rectF, new CornerSizeBinaryOperator() { // from class: com.google.android.material.transition.TransitionUtils.1
@Override // com.google.android.material.transition.TransitionUtils.CornerSizeBinaryOperator
@NonNull
public CornerSize apply(@NonNull CornerSize cornerSize, @NonNull CornerSize cornerSize2) {
return new AbsoluteCornerSize(TransitionUtils.lerp(cornerSize.getCornerSize(rectF), cornerSize2.getCornerSize(rectF2), f, f2, f3));
}
});
}
}