package X6FRs_4.KQgRr5e_0.LGe8pk_15;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.RectF;
import android.os.Build;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextDirectionHeuristic;
import android.text.TextDirectionHeuristics;
import android.text.TextPaint;
import android.text.method.TransformationMethod;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatEditText;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
/* compiled from: AppCompatTextViewAutoSizeHelper.java */
/* loaded from: classes.dex */
public class KNBe_11 {
    public static final RectF KQgRr5e_0 = new RectF();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static ConcurrentHashMap<String, Method> f695KQgRr5e_0 = new ConcurrentHashMap<>();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Context f698KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public TextPaint f699KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final TextView f700KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public int f697KQgRr5e_0 = 0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public boolean f701KQgRr5e_0 = false;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public float f696KQgRr5e_0 = -1.0f;
    public float QxJ9d_1 = -1.0f;
    public float PGPF6hQ_2 = -1.0f;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public int[] f702KQgRr5e_0 = new int[0];

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public boolean f703QxJ9d_1 = false;

    public KNBe_11(TextView textView) {
        this.f700KQgRr5e_0 = textView;
        this.f698KQgRr5e_0 = textView.getContext();
    }

    public void KQgRr5e_0(AttributeSet attributeSet, int i) {
        int resourceId;
        TypedArray obtainStyledAttributes = this.f698KQgRr5e_0.obtainStyledAttributes(attributeSet, X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView, i, 0);
        if (obtainStyledAttributes.hasValue(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizeTextType)) {
            this.f697KQgRr5e_0 = obtainStyledAttributes.getInt(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizeTextType, 0);
        }
        float dimension = obtainStyledAttributes.hasValue(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizeStepGranularity) ? obtainStyledAttributes.getDimension(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizeStepGranularity, -1.0f) : -1.0f;
        float dimension2 = obtainStyledAttributes.hasValue(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizeMinTextSize) ? obtainStyledAttributes.getDimension(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizeMinTextSize, -1.0f) : -1.0f;
        float dimension3 = obtainStyledAttributes.hasValue(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizeMaxTextSize) ? obtainStyledAttributes.getDimension(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizeMaxTextSize, -1.0f) : -1.0f;
        if (obtainStyledAttributes.hasValue(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizePresetSizes) && (resourceId = obtainStyledAttributes.getResourceId(X6FRs_4.KQgRr5e_0.XnFJ5_9.AppCompatTextView_autoSizePresetSizes, 0)) > 0) {
            TypedArray obtainTypedArray = obtainStyledAttributes.getResources().obtainTypedArray(resourceId);
            KQgRr5e_0(obtainTypedArray);
            obtainTypedArray.recycle();
        }
        obtainStyledAttributes.recycle();
        if (m400Mqv2r_3()) {
            if (this.f697KQgRr5e_0 == 1) {
                if (!this.f703QxJ9d_1) {
                    DisplayMetrics displayMetrics = this.f698KQgRr5e_0.getResources().getDisplayMetrics();
                    if (dimension2 == -1.0f) {
                        dimension2 = TypedValue.applyDimension(2, 12.0f, displayMetrics);
                    }
                    if (dimension3 == -1.0f) {
                        dimension3 = TypedValue.applyDimension(2, 112.0f, displayMetrics);
                    }
                    if (dimension == -1.0f) {
                        dimension = 1.0f;
                    }
                    KQgRr5e_0(dimension2, dimension3, dimension);
                }
                m403QxJ9d_1();
                return;
            }
            return;
        }
        this.f697KQgRr5e_0 = 0;
    }

    public int Mqv2r_3() {
        return this.f697KQgRr5e_0;
    }

    public int PGPF6hQ_2() {
        return Math.round(this.f696KQgRr5e_0);
    }

    public int QxJ9d_1() {
        return Math.round(this.QxJ9d_1);
    }

    /* renamed from: Mqv2r_3  reason: collision with other method in class */
    public final boolean m400Mqv2r_3() {
        return !(this.f700KQgRr5e_0 instanceof AppCompatEditText);
    }

    /* renamed from: PGPF6hQ_2  reason: collision with other method in class */
    public final boolean m401PGPF6hQ_2() {
        int length = this.f702KQgRr5e_0.length;
        boolean z = length > 0;
        this.f703QxJ9d_1 = z;
        if (z) {
            this.f697KQgRr5e_0 = 1;
            int[] iArr = this.f702KQgRr5e_0;
            this.QxJ9d_1 = iArr[0];
            this.PGPF6hQ_2 = iArr[length - 1];
            this.f696KQgRr5e_0 = -1.0f;
        }
        return this.f703QxJ9d_1;
    }

    /* renamed from: QxJ9d_1  reason: collision with other method in class */
    public final boolean m403QxJ9d_1() {
        if (m400Mqv2r_3() && this.f697KQgRr5e_0 == 1) {
            if (!this.f703QxJ9d_1 || this.f702KQgRr5e_0.length == 0) {
                float round = Math.round(this.QxJ9d_1);
                int i = 1;
                while (Math.round(this.f696KQgRr5e_0 + round) <= Math.round(this.PGPF6hQ_2)) {
                    i++;
                    round += this.f696KQgRr5e_0;
                }
                int[] iArr = new int[i];
                float f = this.QxJ9d_1;
                for (int i2 = 0; i2 < i; i2++) {
                    iArr[i2] = Math.round(f);
                    f += this.f696KQgRr5e_0;
                }
                this.f702KQgRr5e_0 = KQgRr5e_0(iArr);
            }
            this.f701KQgRr5e_0 = true;
        } else {
            this.f701KQgRr5e_0 = false;
        }
        return this.f701KQgRr5e_0;
    }

    /* renamed from: QxJ9d_1  reason: collision with other method in class */
    public final void m402QxJ9d_1() {
        this.f697KQgRr5e_0 = 0;
        this.QxJ9d_1 = -1.0f;
        this.PGPF6hQ_2 = -1.0f;
        this.f696KQgRr5e_0 = -1.0f;
        this.f702KQgRr5e_0 = new int[0];
        this.f701KQgRr5e_0 = false;
    }

    public void KQgRr5e_0(int i) {
        if (m400Mqv2r_3()) {
            if (i == 0) {
                m402QxJ9d_1();
            } else if (i == 1) {
                DisplayMetrics displayMetrics = this.f698KQgRr5e_0.getResources().getDisplayMetrics();
                KQgRr5e_0(TypedValue.applyDimension(2, 12.0f, displayMetrics), TypedValue.applyDimension(2, 112.0f, displayMetrics), 1.0f);
                if (m403QxJ9d_1()) {
                    m397KQgRr5e_0();
                }
            } else {
                throw new IllegalArgumentException("Unknown auto-size text type: " + i);
            }
        }
    }

    public void KQgRr5e_0(int i, int i2, int i3, int i4) throws IllegalArgumentException {
        if (m400Mqv2r_3()) {
            DisplayMetrics displayMetrics = this.f698KQgRr5e_0.getResources().getDisplayMetrics();
            KQgRr5e_0(TypedValue.applyDimension(i4, i, displayMetrics), TypedValue.applyDimension(i4, i2, displayMetrics), TypedValue.applyDimension(i4, i3, displayMetrics));
            if (m403QxJ9d_1()) {
                m397KQgRr5e_0();
            }
        }
    }

    public void KQgRr5e_0(int[] iArr, int i) throws IllegalArgumentException {
        if (m400Mqv2r_3()) {
            int length = iArr.length;
            if (length > 0) {
                int[] iArr2 = new int[length];
                if (i == 0) {
                    iArr2 = Arrays.copyOf(iArr, length);
                } else {
                    DisplayMetrics displayMetrics = this.f698KQgRr5e_0.getResources().getDisplayMetrics();
                    for (int i2 = 0; i2 < length; i2++) {
                        iArr2[i2] = Math.round(TypedValue.applyDimension(i, iArr[i2], displayMetrics));
                    }
                }
                this.f702KQgRr5e_0 = KQgRr5e_0(iArr2);
                if (!m401PGPF6hQ_2()) {
                    throw new IllegalArgumentException("None of the preset sizes is valid: " + Arrays.toString(iArr));
                }
            } else {
                this.f703QxJ9d_1 = false;
            }
            if (m403QxJ9d_1()) {
                m397KQgRr5e_0();
            }
        }
    }

    public int KQgRr5e_0() {
        return Math.round(this.PGPF6hQ_2);
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public int[] m399KQgRr5e_0() {
        return this.f702KQgRr5e_0;
    }

    public final void KQgRr5e_0(TypedArray typedArray) {
        int length = typedArray.length();
        int[] iArr = new int[length];
        if (length > 0) {
            for (int i = 0; i < length; i++) {
                iArr[i] = typedArray.getDimensionPixelSize(i, -1);
            }
            this.f702KQgRr5e_0 = KQgRr5e_0(iArr);
            m401PGPF6hQ_2();
        }
    }

    public final int[] KQgRr5e_0(int[] iArr) {
        int length = iArr.length;
        if (length == 0) {
            return iArr;
        }
        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()) {
            return iArr;
        }
        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;
    }

    public final void KQgRr5e_0(float f, float f2, float f3) throws IllegalArgumentException {
        if (f <= 0.0f) {
            throw new IllegalArgumentException("Minimum auto-size text size (" + f + "px) is less or equal to (0px)");
        } else 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)");
        } else if (f3 > 0.0f) {
            this.f697KQgRr5e_0 = 1;
            this.QxJ9d_1 = f;
            this.PGPF6hQ_2 = f2;
            this.f696KQgRr5e_0 = f3;
            this.f703QxJ9d_1 = false;
        } else {
            throw new IllegalArgumentException("The auto-size step granularity (" + f3 + "px) is less or equal to (0px)");
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public void m397KQgRr5e_0() {
        if (m398KQgRr5e_0()) {
            if (this.f701KQgRr5e_0) {
                if (this.f700KQgRr5e_0.getMeasuredHeight() <= 0 || this.f700KQgRr5e_0.getMeasuredWidth() <= 0) {
                    return;
                }
                int measuredWidth = ((Boolean) KQgRr5e_0((Object) this.f700KQgRr5e_0, "getHorizontallyScrolling", (String) false)).booleanValue() ? 1048576 : (this.f700KQgRr5e_0.getMeasuredWidth() - this.f700KQgRr5e_0.getTotalPaddingLeft()) - this.f700KQgRr5e_0.getTotalPaddingRight();
                int height = (this.f700KQgRr5e_0.getHeight() - this.f700KQgRr5e_0.getCompoundPaddingBottom()) - this.f700KQgRr5e_0.getCompoundPaddingTop();
                if (measuredWidth <= 0 || height <= 0) {
                    return;
                }
                synchronized (KQgRr5e_0) {
                    KQgRr5e_0.setEmpty();
                    KQgRr5e_0.right = measuredWidth;
                    KQgRr5e_0.bottom = height;
                    float KQgRr5e_02 = KQgRr5e_0(KQgRr5e_0);
                    if (KQgRr5e_02 != this.f700KQgRr5e_0.getTextSize()) {
                        KQgRr5e_0(0, KQgRr5e_02);
                    }
                }
            }
            this.f701KQgRr5e_0 = true;
        }
    }

    public void KQgRr5e_0(int i, float f) {
        Resources resources;
        Context context = this.f698KQgRr5e_0;
        if (context == null) {
            resources = Resources.getSystem();
        } else {
            resources = context.getResources();
        }
        KQgRr5e_0(TypedValue.applyDimension(i, f, resources.getDisplayMetrics()));
    }

    public final void KQgRr5e_0(float f) {
        if (f != this.f700KQgRr5e_0.getPaint().getTextSize()) {
            this.f700KQgRr5e_0.getPaint().setTextSize(f);
            boolean isInLayout = Build.VERSION.SDK_INT >= 18 ? this.f700KQgRr5e_0.isInLayout() : false;
            if (this.f700KQgRr5e_0.getLayout() != null) {
                this.f701KQgRr5e_0 = false;
                try {
                    Method KQgRr5e_02 = KQgRr5e_0("nullLayouts");
                    if (KQgRr5e_02 != null) {
                        KQgRr5e_02.invoke(this.f700KQgRr5e_0, new Object[0]);
                    }
                } catch (Exception e) {
                    Log.w("ACTVAutoSizeHelper", "Failed to invoke TextView#nullLayouts() method", e);
                }
                if (!isInLayout) {
                    this.f700KQgRr5e_0.requestLayout();
                } else {
                    this.f700KQgRr5e_0.forceLayout();
                }
                this.f700KQgRr5e_0.invalidate();
            }
        }
    }

    public final int KQgRr5e_0(RectF rectF) {
        int length = this.f702KQgRr5e_0.length;
        if (length != 0) {
            int i = length - 1;
            int i2 = 1;
            int i3 = 0;
            while (i2 <= i) {
                int i4 = (i2 + i) / 2;
                if (KQgRr5e_0(this.f702KQgRr5e_0[i4], rectF)) {
                    int i5 = i4 + 1;
                    i3 = i2;
                    i2 = i5;
                } else {
                    i3 = i4 - 1;
                    i = i3;
                }
            }
            return this.f702KQgRr5e_0[i3];
        }
        throw new IllegalStateException("No available text sizes to choose from.");
    }

    public final boolean KQgRr5e_0(int i, RectF rectF) {
        StaticLayout KQgRr5e_02;
        CharSequence transformation;
        CharSequence text = this.f700KQgRr5e_0.getText();
        TransformationMethod transformationMethod = this.f700KQgRr5e_0.getTransformationMethod();
        if (transformationMethod != null && (transformation = transformationMethod.getTransformation(text, this.f700KQgRr5e_0)) != null) {
            text = transformation;
        }
        int maxLines = Build.VERSION.SDK_INT >= 16 ? this.f700KQgRr5e_0.getMaxLines() : -1;
        TextPaint textPaint = this.f699KQgRr5e_0;
        if (textPaint == null) {
            this.f699KQgRr5e_0 = new TextPaint();
        } else {
            textPaint.reset();
        }
        this.f699KQgRr5e_0.set(this.f700KQgRr5e_0.getPaint());
        this.f699KQgRr5e_0.setTextSize(i);
        Layout.Alignment alignment = (Layout.Alignment) KQgRr5e_0((Object) this.f700KQgRr5e_0, "getLayoutAlignment", (String) Layout.Alignment.ALIGN_NORMAL);
        if (Build.VERSION.SDK_INT >= 23) {
            KQgRr5e_02 = KQgRr5e_0(text, alignment, Math.round(rectF.right), maxLines);
        } else {
            KQgRr5e_02 = KQgRr5e_0(text, alignment, Math.round(rectF.right));
        }
        return (maxLines == -1 || (KQgRr5e_02.getLineCount() <= maxLines && KQgRr5e_02.getLineEnd(KQgRr5e_02.getLineCount() - 1) == text.length())) && ((float) KQgRr5e_02.getHeight()) <= rectF.bottom;
    }

    public final StaticLayout KQgRr5e_0(CharSequence charSequence, Layout.Alignment alignment, int i, int i2) {
        TextDirectionHeuristic textDirectionHeuristic = (TextDirectionHeuristic) KQgRr5e_0((Object) this.f700KQgRr5e_0, "getTextDirectionHeuristic", (String) TextDirectionHeuristics.FIRSTSTRONG_LTR);
        StaticLayout.Builder hyphenationFrequency = StaticLayout.Builder.obtain(charSequence, 0, charSequence.length(), this.f699KQgRr5e_0, i).setAlignment(alignment).setLineSpacing(this.f700KQgRr5e_0.getLineSpacingExtra(), this.f700KQgRr5e_0.getLineSpacingMultiplier()).setIncludePad(this.f700KQgRr5e_0.getIncludeFontPadding()).setBreakStrategy(this.f700KQgRr5e_0.getBreakStrategy()).setHyphenationFrequency(this.f700KQgRr5e_0.getHyphenationFrequency());
        if (i2 == -1) {
            i2 = Integer.MAX_VALUE;
        }
        return hyphenationFrequency.setMaxLines(i2).setTextDirection(textDirectionHeuristic).build();
    }

    public final StaticLayout KQgRr5e_0(CharSequence charSequence, Layout.Alignment alignment, int i) {
        float floatValue;
        float floatValue2;
        boolean booleanValue;
        if (Build.VERSION.SDK_INT >= 16) {
            floatValue = this.f700KQgRr5e_0.getLineSpacingMultiplier();
            floatValue2 = this.f700KQgRr5e_0.getLineSpacingExtra();
            booleanValue = this.f700KQgRr5e_0.getIncludeFontPadding();
        } else {
            floatValue = ((Float) KQgRr5e_0((Object) this.f700KQgRr5e_0, "getLineSpacingMultiplier", (String) Float.valueOf(1.0f))).floatValue();
            floatValue2 = ((Float) KQgRr5e_0((Object) this.f700KQgRr5e_0, "getLineSpacingExtra", (String) Float.valueOf(0.0f))).floatValue();
            booleanValue = ((Boolean) KQgRr5e_0((Object) this.f700KQgRr5e_0, "getIncludeFontPadding", (String) true)).booleanValue();
        }
        return new StaticLayout(charSequence, this.f699KQgRr5e_0, i, alignment, floatValue, floatValue2, booleanValue);
    }

    public final <T> T KQgRr5e_0(Object obj, String str, T t) {
        try {
            return (T) KQgRr5e_0(str).invoke(obj, new Object[0]);
        } catch (Exception e) {
            Log.w("ACTVAutoSizeHelper", "Failed to invoke TextView#" + str + "() method", e);
            return t;
        }
    }

    public final Method KQgRr5e_0(String str) {
        try {
            Method method = f695KQgRr5e_0.get(str);
            if (method == null && (method = TextView.class.getDeclaredMethod(str, new Class[0])) != null) {
                method.setAccessible(true);
                f695KQgRr5e_0.put(str, method);
            }
            return method;
        } catch (Exception e) {
            Log.w("ACTVAutoSizeHelper", "Failed to retrieve TextView#" + str + "() method", e);
            return null;
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public boolean m398KQgRr5e_0() {
        return m400Mqv2r_3() && this.f697KQgRr5e_0 != 0;
    }
}
