package p037.p041.p051;

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.TextDirectionHeuristic;
import android.text.TextDirectionHeuristics;
import android.text.TextPaint;
import android.text.method.TransformationMethod;
import android.util.Log;
import android.util.TypedValue;
import android.widget.TextView;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;

/* JADX INFO: renamed from: މ.ؠ.ގ.ޗ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C1643 {

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public static final RectF f5332 = new RectF();

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public static ConcurrentHashMap<String, Method> f5333 = new ConcurrentHashMap<>();

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public static ConcurrentHashMap<String, Field> f5334 = new ConcurrentHashMap<>();

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public int f5335 = 0;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public boolean f5336 = false;

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

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

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

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public int[] f5340 = new int[0];

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public boolean f5341 = false;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public TextPaint f5342;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final TextView f5343;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final Context f5344;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final C1646 f5345;

    /* JADX INFO: renamed from: މ.ؠ.ގ.ޗ$֏, reason: contains not printable characters */
    public static class C1644 extends C1646 {
        @Override // p037.p041.p051.C1643.C1646
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public void mo3216(StaticLayout.Builder builder, TextView textView) {
            builder.setTextDirection((TextDirectionHeuristic) C1643.m3206(textView, "getTextDirectionHeuristic", TextDirectionHeuristics.FIRSTSTRONG_LTR));
        }
    }

    /* JADX INFO: renamed from: މ.ؠ.ގ.ޗ$ؠ, reason: contains not printable characters */
    public static class C1645 extends C1644 {
        @Override // p037.p041.p051.C1643.C1644, p037.p041.p051.C1643.C1646
        /* JADX INFO: renamed from: ֏ */
        public void mo3216(StaticLayout.Builder builder, TextView textView) {
            builder.setTextDirection(textView.getTextDirectionHeuristic());
        }

        @Override // p037.p041.p051.C1643.C1646
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public boolean mo3217(TextView textView) {
            return textView.isHorizontallyScrollable();
        }
    }

    /* JADX INFO: renamed from: މ.ؠ.ގ.ޗ$ހ, reason: contains not printable characters */
    public static class C1646 {
        /* JADX INFO: renamed from: ֏ */
        public void mo3216(StaticLayout.Builder builder, TextView textView) {
        }

        /* JADX INFO: renamed from: ֏ */
        public boolean mo3217(TextView textView) {
            return ((Boolean) C1643.m3206(textView, "getHorizontallyScrolling", false)).booleanValue();
        }
    }

    public C1643(TextView textView) {
        this.f5343 = textView;
        this.f5344 = textView.getContext();
        int i = Build.VERSION.SDK_INT;
        if (i >= 29) {
            this.f5345 = new C1645();
        } else if (i >= 23) {
            this.f5345 = new C1644();
        } else {
            this.f5345 = new C1646();
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static <T> T m3206(Object obj, String str, T t) {
        try {
            return (T) m3207(str).invoke(obj, new Object[0]);
        } catch (Exception e) {
            Log.w("ACTVAutoSizeHelper", "Failed to invoke TextView#" + str + "() method", e);
            return t;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Method m3207(String str) {
        try {
            Method declaredMethod = f5333.get(str);
            if (declaredMethod == null && (declaredMethod = TextView.class.getDeclaredMethod(str, new Class[0])) != null) {
                declaredMethod.setAccessible(true);
                f5333.put(str, declaredMethod);
            }
            return declaredMethod;
        } catch (Exception e) {
            Log.w("ACTVAutoSizeHelper", "Failed to retrieve TextView#" + str + "() method", e);
            return null;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final int m3208(RectF rectF) {
        int i;
        StaticLayout staticLayout;
        CharSequence transformation;
        int length = this.f5340.length;
        if (length == 0) {
            throw new IllegalStateException("No available text sizes to choose from.");
        }
        int i2 = length - 1;
        int i3 = 0;
        int i4 = 1;
        int i5 = 0;
        while (i4 <= i2) {
            int i6 = (i4 + i2) / 2;
            int i7 = this.f5340[i6];
            CharSequence text = this.f5343.getText();
            TransformationMethod transformationMethod = this.f5343.getTransformationMethod();
            if (transformationMethod != null && (transformation = transformationMethod.getTransformation(text, this.f5343)) != null) {
                text = transformation;
            }
            int maxLines = this.f5343.getMaxLines();
            TextPaint textPaint = this.f5342;
            if (textPaint == null) {
                this.f5342 = new TextPaint();
            } else {
                textPaint.reset();
            }
            this.f5342.set(this.f5343.getPaint());
            this.f5342.setTextSize(i7);
            Layout.Alignment alignment = (Layout.Alignment) m3206(this.f5343, "getLayoutAlignment", Layout.Alignment.ALIGN_NORMAL);
            int iRound = Math.round(rectF.right);
            if (Build.VERSION.SDK_INT >= 23) {
                StaticLayout.Builder builderObtain = StaticLayout.Builder.obtain(text, i3, text.length(), this.f5342, iRound);
                builderObtain.setAlignment(alignment).setLineSpacing(this.f5343.getLineSpacingExtra(), this.f5343.getLineSpacingMultiplier()).setIncludePad(this.f5343.getIncludeFontPadding()).setBreakStrategy(this.f5343.getBreakStrategy()).setHyphenationFrequency(this.f5343.getHyphenationFrequency()).setMaxLines(maxLines == -1 ? Integer.MAX_VALUE : maxLines);
                try {
                    this.f5345.mo3216(builderObtain, this.f5343);
                } catch (ClassCastException unused) {
                    Log.w("ACTVAutoSizeHelper", "Failed to obtain TextDirectionHeuristic, auto size may be incorrect");
                }
                staticLayout = builderObtain.build();
                i = -1;
            } else {
                i = -1;
                staticLayout = new StaticLayout(text, this.f5342, iRound, alignment, this.f5343.getLineSpacingMultiplier(), this.f5343.getLineSpacingExtra(), this.f5343.getIncludeFontPadding());
            }
            if ((maxLines == i || (staticLayout.getLineCount() <= maxLines && staticLayout.getLineEnd(staticLayout.getLineCount() - 1) == text.length())) && ((float) staticLayout.getHeight()) <= rectF.bottom) {
                int i8 = i6 + 1;
                i3 = 0;
                i5 = i4;
                i4 = i8;
            } else {
                i5 = i6 - 1;
                i2 = i5;
                i3 = 0;
            }
        }
        return this.f5340[i5];
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m3209() {
        if (m3215() && this.f5335 != 0) {
            if (this.f5336) {
                if (this.f5343.getMeasuredHeight() <= 0 || this.f5343.getMeasuredWidth() <= 0) {
                    return;
                }
                int measuredWidth = this.f5345.mo3217(this.f5343) ? 1048576 : (this.f5343.getMeasuredWidth() - this.f5343.getTotalPaddingLeft()) - this.f5343.getTotalPaddingRight();
                int height = (this.f5343.getHeight() - this.f5343.getCompoundPaddingBottom()) - this.f5343.getCompoundPaddingTop();
                if (measuredWidth <= 0 || height <= 0) {
                    return;
                }
                synchronized (f5332) {
                    f5332.setEmpty();
                    f5332.right = measuredWidth;
                    f5332.bottom = height;
                    float fM3208 = m3208(f5332);
                    if (fM3208 != this.f5343.getTextSize()) {
                        m3211(0, fM3208);
                    }
                }
            }
            this.f5336 = true;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m3210(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.f5335 = 1;
        this.f5338 = f;
        this.f5339 = f2;
        this.f5337 = f3;
        this.f5341 = false;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m3211(int i, float f) {
        Context context = this.f5344;
        float fApplyDimension = TypedValue.applyDimension(i, f, (context == null ? Resources.getSystem() : context.getResources()).getDisplayMetrics());
        if (fApplyDimension != this.f5343.getPaint().getTextSize()) {
            this.f5343.getPaint().setTextSize(fApplyDimension);
            boolean zIsInLayout = this.f5343.isInLayout();
            if (this.f5343.getLayout() != null) {
                this.f5336 = false;
                try {
                    Method methodM3207 = m3207("nullLayouts");
                    if (methodM3207 != null) {
                        methodM3207.invoke(this.f5343, new Object[0]);
                    }
                } catch (Exception e) {
                    Log.w("ACTVAutoSizeHelper", "Failed to invoke TextView#nullLayouts() method", e);
                }
                if (zIsInLayout) {
                    this.f5343.forceLayout();
                } else {
                    this.f5343.requestLayout();
                }
                this.f5343.invalidate();
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final int[] m3212(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;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final boolean m3213() {
        if (m3215() && this.f5335 == 1) {
            if (!this.f5341 || this.f5340.length == 0) {
                int iFloor = ((int) Math.floor((this.f5339 - this.f5338) / this.f5337)) + 1;
                int[] iArr = new int[iFloor];
                for (int i = 0; i < iFloor; i++) {
                    iArr[i] = Math.round((i * this.f5337) + this.f5338);
                }
                this.f5340 = m3212(iArr);
            }
            this.f5336 = true;
        } else {
            this.f5336 = false;
        }
        return this.f5336;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final boolean m3214() {
        boolean z = this.f5340.length > 0;
        this.f5341 = z;
        if (z) {
            this.f5335 = 1;
            int[] iArr = this.f5340;
            this.f5338 = iArr[0];
            this.f5339 = iArr[r0 - 1];
            this.f5337 = -1.0f;
        }
        return this.f5341;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final boolean m3215() {
        return !(this.f5343 instanceof C1617);
    }
}
