package vr;

import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.text.Layout;
import android.text.SpannableStringBuilder;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.view.Gravity;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.text.Bidi;

/* loaded from: classes5.dex */
public abstract class f {
    public static float a(Layout layout) {
        float f10 = BitmapDescriptorFactory.HUE_RED;
        if (layout != null) {
            int lineCount = layout.getLineCount();
            for (int i10 = 0; i10 < lineCount; i10++) {
                f10 = Math.max(f10, layout.getLineWidth(i10));
            }
        }
        return f10;
    }

    public static float b(float f10, Rect rect, int i10, float f11) {
        if (rect != null) {
            i10 = rect.right - rect.left;
        }
        return Math.max(80.0f, Math.min(f10, i10 - (f11 * 2.0f)));
    }

    public static boolean c(Rect rect, int i10, int i11, int i12) {
        return i11 > rect.left + i10 && i11 < rect.right - i10 && i12 > rect.top + i10 && i12 < rect.bottom - i10;
    }

    public static StaticLayout d(CharSequence charSequence, TextPaint textPaint, int i10, Layout.Alignment alignment, float f10) {
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(charSequence);
        spannableStringBuilder.setSpan(new a(f10), 0, spannableStringBuilder.length(), 18);
        StaticLayout.Builder obtain = StaticLayout.Builder.obtain(spannableStringBuilder, 0, charSequence.length(), textPaint, i10);
        obtain.setAlignment(alignment);
        return obtain.build();
    }

    public static Layout.Alignment e(Resources resources, int i10, CharSequence charSequence) {
        int layoutDirection = resources.getConfiguration().getLayoutDirection();
        if (charSequence != null && layoutDirection == 1 && new Bidi(charSequence.toString(), -2).isRightToLeft()) {
            if (i10 == 8388611) {
                i10 = 8388613;
            } else if (i10 == 8388613) {
                i10 = 8388611;
            }
        }
        int absoluteGravity = Gravity.getAbsoluteGravity(i10, layoutDirection);
        return absoluteGravity != 1 ? absoluteGravity != 5 ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER;
    }

    public static boolean f(float f10, float f11, PointF pointF, float f12) {
        return Math.pow((double) (f10 - pointF.x), 2.0d) + Math.pow((double) (f11 - pointF.y), 2.0d) < Math.pow((double) f12, 2.0d);
    }

    public static boolean g(Layout layout, Resources resources) {
        if (layout == null) {
            return false;
        }
        boolean z10 = layout.getAlignment() == Layout.Alignment.ALIGN_OPPOSITE;
        boolean isRtlCharAt = layout.isRtlCharAt(0);
        boolean z11 = (!(z10 && isRtlCharAt) && (z10 || isRtlCharAt)) || isRtlCharAt;
        if (!z11 && layout.getAlignment() == Layout.Alignment.ALIGN_NORMAL) {
            return resources.getConfiguration().getLayoutDirection() == 1;
        }
        if (layout.getAlignment() == Layout.Alignment.ALIGN_OPPOSITE && isRtlCharAt) {
            return false;
        }
        return z11;
    }

    public static PorterDuff.Mode h(int i10, PorterDuff.Mode mode) {
        if (i10 == 3) {
            return PorterDuff.Mode.SRC_OVER;
        }
        if (i10 == 5) {
            return PorterDuff.Mode.SRC_IN;
        }
        if (i10 == 9) {
            return PorterDuff.Mode.SRC_ATOP;
        }
        switch (i10) {
            case 14:
                return PorterDuff.Mode.MULTIPLY;
            case 15:
                return PorterDuff.Mode.SCREEN;
            case 16:
                return PorterDuff.Mode.valueOf("ADD");
            default:
                return mode;
        }
    }

    public static void i(PointF pointF, RectF rectF, RectF rectF2, float f10, boolean z10) {
        if (f10 == 1.0f) {
            rectF2.set(rectF);
            return;
        }
        float centerX = rectF.centerX() - rectF.left;
        float centerY = rectF.centerY();
        float f11 = rectF.top;
        float f12 = centerY - f11;
        if (z10 && f10 > 1.0f) {
            float min = Math.min((centerX * f10) - centerX, (f10 * f12) - f12);
            rectF2.left = rectF.left - min;
            rectF2.top = rectF.top - min;
            rectF2.right = rectF.right + min;
            rectF2.bottom = rectF.bottom + min;
            return;
        }
        float f13 = pointF.x;
        float f14 = centerX * f10;
        rectF2.left = f13 - (((f13 - rectF.left) / centerX) * f14);
        float f15 = pointF.y;
        float f16 = f10 * f12;
        rectF2.top = f15 - (((f15 - f11) / f12) * f16);
        rectF2.right = f13 + (f14 * ((rectF.right - f13) / centerX));
        rectF2.bottom = f15 + (f16 * ((rectF.bottom - f15) / f12));
    }

    public static void j(TextPaint textPaint, Typeface typeface, int i10) {
        if (i10 <= 0) {
            if (typeface != null) {
                textPaint.setTypeface(typeface);
                return;
            } else {
                textPaint.setTypeface(Typeface.defaultFromStyle(i10));
                return;
            }
        }
        Typeface defaultFromStyle = typeface == null ? Typeface.defaultFromStyle(i10) : Typeface.create(typeface, i10);
        textPaint.setTypeface(defaultFromStyle);
        int i11 = (~(defaultFromStyle != null ? defaultFromStyle.getStyle() : 0)) & i10;
        textPaint.setFakeBoldText((i11 & 1) != 0);
        textPaint.setTextSkewX((i11 & 2) != 0 ? -0.25f : BitmapDescriptorFactory.HUE_RED);
    }

    public static Typeface k(String str, int i10, int i11) {
        Typeface create;
        if (str == null || (create = Typeface.create(str, i11)) == null) {
            return Typeface.create(i10 != 1 ? i10 != 2 ? i10 != 3 ? Typeface.DEFAULT : Typeface.MONOSPACE : Typeface.SERIF : Typeface.SANS_SERIF, i11);
        }
        return create;
    }
}
