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;

/* JADX INFO: renamed from: ᵪˑ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C3890 {

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public TextPaint f14840;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final Context f14843;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public final C5302 f14846;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final TextView f14848;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public static final RectF f14838 = new RectF();

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public static final ConcurrentHashMap f14837 = new ConcurrentHashMap();

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public int f14844 = 0;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public boolean f14839 = false;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public float f14841 = -1.0f;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public float f14847 = -1.0f;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public float f14842 = -1.0f;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public int[] f14849 = new int[0];

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public boolean f14845 = false;

    public C3890(TextView textView) {
        this.f14848 = textView;
        this.f14843 = textView.getContext();
        if (Build.VERSION.SDK_INT >= 29) {
            this.f14846 = new C2275();
        } else {
            this.f14846 = new C5302();
        }
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static int[] m8592(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;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static Method m8593(String str) {
        try {
            ConcurrentHashMap concurrentHashMap = f14837;
            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;
        }
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final boolean m8594() {
        boolean z = this.f14849.length > 0;
        this.f14845 = z;
        if (z) {
            this.f14844 = 1;
            this.f14847 = r0[0];
            this.f14842 = r0[r1 - 1];
            this.f14841 = -1.0f;
        }
        return z;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final int m8595(RectF rectF) {
        CharSequence transformation;
        int length = this.f14849.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.f14849;
            if (i3 > i) {
                return iArr[i2];
            }
            int i4 = (i3 + i) / 2;
            int i5 = iArr[i4];
            TextView textView = this.f14848;
            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.f14840;
            if (textPaint == null) {
                this.f14840 = new TextPaint();
            } else {
                textPaint.reset();
            }
            this.f14840.set(textView.getPaint());
            this.f14840.setTextSize(i5);
            Object objInvoke = Layout.Alignment.ALIGN_NORMAL;
            try {
                objInvoke = m8593("getLayoutAlignment").invoke(textView, null);
            } catch (Exception unused) {
            }
            int iRound = Math.round(rectF.right);
            TextPaint textPaint2 = this.f14840;
            C5302 c5302 = this.f14846;
            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 {
                c5302.mo5890(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;
            }
        }
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final boolean m8596() {
        return m8600() && this.f14844 != 0;
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final void m8597(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.f14844 = 1;
        this.f14847 = f;
        this.f14842 = f2;
        this.f14841 = f3;
        this.f14845 = false;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m8598() {
        if (m8596()) {
            if (this.f14839) {
                if (this.f14848.getMeasuredHeight() <= 0 || this.f14848.getMeasuredWidth() <= 0) {
                    return;
                }
                int measuredWidth = this.f14846.mo5889(this.f14848) ? 1048576 : (this.f14848.getMeasuredWidth() - this.f14848.getTotalPaddingLeft()) - this.f14848.getTotalPaddingRight();
                int height = (this.f14848.getHeight() - this.f14848.getCompoundPaddingBottom()) - this.f14848.getCompoundPaddingTop();
                if (measuredWidth <= 0 || height <= 0) {
                    return;
                }
                RectF rectF = f14838;
                synchronized (rectF) {
                    try {
                        rectF.setEmpty();
                        rectF.right = measuredWidth;
                        rectF.bottom = height;
                        float fM8595 = m8595(rectF);
                        if (fM8595 != this.f14848.getTextSize()) {
                            m8601(0, fM8595);
                        }
                    } finally {
                    }
                }
            }
            this.f14839 = true;
        }
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final boolean m8599() {
        if (m8600() && this.f14844 == 1) {
            if (!this.f14845 || this.f14849.length == 0) {
                int iFloor = ((int) Math.floor((this.f14842 - this.f14847) / this.f14841)) + 1;
                int[] iArr = new int[iFloor];
                for (int i = 0; i < iFloor; i++) {
                    iArr[i] = Math.round((i * this.f14841) + this.f14847);
                }
                this.f14849 = m8592(iArr);
            }
            this.f14839 = true;
        } else {
            this.f14839 = false;
        }
        return this.f14839;
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final boolean m8600() {
        return !(this.f14848 instanceof C1334);
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final void m8601(int i, float f) {
        Context context = this.f14843;
        float fApplyDimension = TypedValue.applyDimension(i, f, (context == null ? Resources.getSystem() : context.getResources()).getDisplayMetrics());
        TextView textView = this.f14848;
        if (fApplyDimension != textView.getPaint().getTextSize()) {
            textView.getPaint().setTextSize(fApplyDimension);
            boolean zIsInLayout = textView.isInLayout();
            if (textView.getLayout() != null) {
                this.f14839 = false;
                try {
                    Method methodM8593 = m8593("nullLayouts");
                    if (methodM8593 != null) {
                        methodM8593.invoke(textView, null);
                    }
                } catch (Exception unused) {
                }
                if (zIsInLayout) {
                    textView.forceLayout();
                } else {
                    textView.requestLayout();
                }
                textView.invalidate();
            }
        }
    }
}
