package defpackage;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.RectF;
import android.os.Build;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.method.TransformationMethod;
import android.util.TypedValue;
import android.widget.TextView;
import j$.util.concurrent.ConcurrentHashMap;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

/* renamed from: ˎˏˊ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1719 {

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public static final RectF f6843 = new RectF();

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public static final ConcurrentHashMap f6844 = new ConcurrentHashMap();

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final TextView f6849;

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final Context f6852;

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final C3691 f6853;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public TextPaint f6854;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public int f6850 = 0;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public boolean f6851 = false;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public float f6848 = -1.0f;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public float f6855 = -1.0f;

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public float f6845 = -1.0f;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public int[] f6847 = new int[0];

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public boolean f6846 = false;

    public C1719(TextView textView) {
        this.f6849 = textView;
        this.f6852 = textView.getContext();
        if (Build.VERSION.SDK_INT >= 29) {
            this.f6853 = new C4200();
        } else {
            this.f6853 = new C3691();
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static int[] m4907(int[] iArr) {
        int length = iArr.length;
        if (length != 0) {
            Arrays.sort(iArr);
            ArrayList arrayList = new ArrayList();
            for (int i : iArr) {
                if (i > 0 && Collections.binarySearch(arrayList, Integer.valueOf(i)) < 0) {
                    arrayList.add(Integer.valueOf(i));
                }
            }
            if (length != arrayList.size()) {
                int size = arrayList.size();
                int[] iArr2 = new int[size];
                for (int i2 = 0; i2 < size; i2++) {
                    iArr2[i2] = ((Integer) arrayList.get(i2)).intValue();
                }
                return iArr2;
            }
        }
        return iArr;
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public static Method m4908(String str) throws SecurityException {
        try {
            ConcurrentHashMap concurrentHashMap = f6844;
            Method declaredMethod = (Method) concurrentHashMap.get(str);
            if (declaredMethod == null && (declaredMethod = TextView.class.getDeclaredMethod(str, null)) != null) {
                declaredMethod.setAccessible(true);
                concurrentHashMap.put(str, declaredMethod);
            }
            return declaredMethod;
        } catch (Exception unused) {
            return null;
        }
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final boolean m4909() {
        return m4913() && this.f6850 != 0;
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final boolean m4910() {
        if (m4913() && this.f6850 == 1) {
            if (!this.f6846 || this.f6847.length == 0) {
                int iFloor = ((int) Math.floor((this.f6845 - this.f6855) / this.f6848)) + 1;
                int[] iArr = new int[iFloor];
                for (int i = 0; i < iFloor; i++) {
                    iArr[i] = Math.round((i * this.f6848) + this.f6855);
                }
                this.f6847 = m4907(iArr);
            }
            this.f6851 = true;
        } else {
            this.f6851 = false;
        }
        return this.f6851;
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final void m4911(int i, float f) {
        Context context = this.f6852;
        float fApplyDimension = TypedValue.applyDimension(i, f, (context == null ? Resources.getSystem() : context.getResources()).getDisplayMetrics());
        TextView textView = this.f6849;
        if (fApplyDimension != textView.getPaint().getTextSize()) {
            textView.getPaint().setTextSize(fApplyDimension);
            boolean zIsInLayout = textView.isInLayout();
            if (textView.getLayout() != null) {
                this.f6851 = false;
                try {
                    Method methodM4908 = m4908("nullLayouts");
                    if (methodM4908 != null) {
                        methodM4908.invoke(textView, null);
                    }
                } catch (Exception unused) {
                }
                if (zIsInLayout) {
                    textView.forceLayout();
                } else {
                    textView.requestLayout();
                }
                textView.invalidate();
            }
        }
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final int m4912(RectF rectF) {
        CharSequence transformation;
        int length = this.f6847.length;
        if (length == 0) {
            ᵹˉᵞ.ᵳٴᵶ("No available text sizes to choose from.");
            return 0;
        }
        int i = length - 1;
        int i2 = 0;
        int i3 = 1;
        while (true) {
            int[] iArr = this.f6847;
            if (i3 > i) {
                return iArr[i2];
            }
            int i4 = (i3 + i) / 2;
            int i5 = iArr[i4];
            TextView textView = this.f6849;
            CharSequence text = textView.getText();
            TransformationMethod transformationMethod = textView.getTransformationMethod();
            if (transformationMethod != null && (transformation = transformationMethod.getTransformation(text, textView)) != null) {
                text = transformation;
            }
            int maxLines = textView.getMaxLines();
            TextPaint textPaint = this.f6854;
            if (textPaint == null) {
                this.f6854 = new TextPaint();
            } else {
                textPaint.reset();
            }
            this.f6854.set(textView.getPaint());
            this.f6854.setTextSize(i5);
            Object objInvoke = Layout.Alignment.ALIGN_NORMAL;
            try {
                objInvoke = m4908("getLayoutAlignment").invoke(textView, null);
            } catch (Exception unused) {
            }
            int iRound = Math.round(rectF.right);
            TextPaint textPaint2 = this.f6854;
            C3691 c3691 = this.f6853;
            StaticLayout.Builder builderObtain = StaticLayout.Builder.obtain(text, 0, text.length(), textPaint2, iRound);
            builderObtain.setAlignment((Layout.Alignment) objInvoke).setLineSpacing(textView.getLineSpacingExtra(), textView.getLineSpacingMultiplier()).setIncludePad(textView.getIncludeFontPadding()).setBreakStrategy(textView.getBreakStrategy()).setHyphenationFrequency(textView.getHyphenationFrequency()).setMaxLines(maxLines == -1 ? Integer.MAX_VALUE : maxLines);
            try {
                c3691.mo8283(builderObtain, textView);
            } catch (ClassCastException unused2) {
            }
            StaticLayout staticLayoutBuild = builderObtain.build();
            if ((maxLines == -1 || (staticLayoutBuild.getLineCount() <= maxLines && staticLayoutBuild.getLineEnd(staticLayoutBuild.getLineCount() - 1) == text.length())) && staticLayoutBuild.getHeight() <= rectF.bottom) {
                int i6 = i4 + 1;
                i2 = i3;
                i3 = i6;
            } else {
                i2 = i4 - 1;
                i = i2;
            }
        }
    }

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final boolean m4913() {
        return !(this.f6849 instanceof C3483);
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m4914() {
        if (m4909()) {
            if (this.f6851) {
                if (this.f6849.getMeasuredHeight() <= 0 || this.f6849.getMeasuredWidth() <= 0) {
                    return;
                }
                int measuredWidth = this.f6853.mo8284(this.f6849) ? 1048576 : (this.f6849.getMeasuredWidth() - this.f6849.getTotalPaddingLeft()) - this.f6849.getTotalPaddingRight();
                int height = (this.f6849.getHeight() - this.f6849.getCompoundPaddingBottom()) - this.f6849.getCompoundPaddingTop();
                if (measuredWidth <= 0 || height <= 0) {
                    return;
                }
                RectF rectF = f6843;
                synchronized (rectF) {
                    try {
                        rectF.setEmpty();
                        rectF.right = measuredWidth;
                        rectF.bottom = height;
                        float fM4912 = m4912(rectF);
                        if (fM4912 != this.f6849.getTextSize()) {
                            m4911(0, fM4912);
                        }
                    } finally {
                    }
                }
            }
            this.f6851 = true;
        }
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final void m4915(float f, float f2, float f3) {
        if (f <= 0.0f) {
            throw new IllegalArgumentException("Minimum auto-size text size (" + f + "px) is less or equal to (0px)");
        }
        if (f2 <= f) {
            throw new IllegalArgumentException("Maximum auto-size text size (" + f2 + "px) is less or equal to minimum auto-size text size (" + f + "px)");
        }
        if (f3 <= 0.0f) {
            throw new IllegalArgumentException("The auto-size step granularity (" + f3 + "px) is less or equal to (0px)");
        }
        this.f6850 = 1;
        this.f6855 = f;
        this.f6845 = f2;
        this.f6848 = f3;
        this.f6846 = false;
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final boolean m4916() {
        boolean z = this.f6847.length > 0;
        this.f6846 = z;
        if (z) {
            this.f6850 = 1;
            this.f6855 = r0[0];
            this.f6845 = r0[r1 - 1];
            this.f6848 = -1.0f;
        }
        return z;
    }
}
