package m;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.text.method.PasswordTransformationMethod;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.widget.TextView;
import h.AbstractC0617a;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import p0.AbstractC0928a;

/* JADX INFO: renamed from: m.F, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0837F {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final TextView f9000a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public K4.h f9001b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public K4.h f9002c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public K4.h f9003d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public K4.h f9004e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public K4.h f9005f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public K4.h f9006g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public K4.h f9007h;
    public final P i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int f9008j = 0;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public int f9009k = -1;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public Typeface f9010l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public boolean f9011m;

    public C0837F(TextView textView) {
        this.f9000a = textView;
        this.i = new P(textView);
    }

    public static K4.h c(Context context, r rVar, int i) {
        ColorStateList colorStateListF;
        synchronized (rVar) {
            colorStateListF = rVar.f9238a.f(context, i);
        }
        if (colorStateListF == null) {
            return null;
        }
        K4.h hVar = new K4.h();
        hVar.f1122b = true;
        hVar.f1123c = colorStateListF;
        return hVar;
    }

    public static void f(EditorInfo editorInfo, InputConnection inputConnection, TextView textView) {
        int i = Build.VERSION.SDK_INT;
        if (i >= 30 || inputConnection == null) {
            return;
        }
        CharSequence text = textView.getText();
        if (i >= 30) {
            R.b.a(editorInfo, text);
            return;
        }
        text.getClass();
        if (i >= 30) {
            R.b.a(editorInfo, text);
            return;
        }
        int i5 = editorInfo.initialSelStart;
        int i6 = editorInfo.initialSelEnd;
        int i7 = i5 > i6 ? i6 : i5;
        if (i5 <= i6) {
            i5 = i6;
        }
        int length = text.length();
        if (i7 < 0 || i5 > length) {
            R.d.b(editorInfo, null, 0, 0);
            return;
        }
        int i8 = editorInfo.inputType & 4095;
        if (i8 == 129 || i8 == 225 || i8 == 18) {
            R.d.b(editorInfo, null, 0, 0);
            return;
        }
        if (length <= 2048) {
            R.d.b(editorInfo, text, i7, i5);
            return;
        }
        int i9 = i5 - i7;
        int i10 = i9 > 1024 ? 0 : i9;
        int i11 = 2048 - i10;
        int iMin = Math.min(text.length() - i5, i11 - Math.min(i7, (int) (((double) i11) * 0.8d)));
        int iMin2 = Math.min(i7, i11 - iMin);
        int i12 = i7 - iMin2;
        if (Character.isLowSurrogate(text.charAt(i12))) {
            i12++;
            iMin2--;
        }
        if (Character.isHighSurrogate(text.charAt((i5 + iMin) - 1))) {
            iMin--;
        }
        int i13 = iMin2 + i10;
        R.d.b(editorInfo, i10 != i9 ? TextUtils.concat(text.subSequence(i12, i12 + iMin2), text.subSequence(i5, iMin + i5)) : text.subSequence(i12, i13 + iMin + i12), iMin2, i13);
    }

    public final void a(Drawable drawable, K4.h hVar) {
        if (drawable == null || hVar == null) {
            return;
        }
        r.d(drawable, hVar, this.f9000a.getDrawableState());
    }

    public final void b() {
        K4.h hVar = this.f9001b;
        TextView textView = this.f9000a;
        if (hVar != null || this.f9002c != null || this.f9003d != null || this.f9004e != null) {
            Drawable[] compoundDrawables = textView.getCompoundDrawables();
            a(compoundDrawables[0], this.f9001b);
            a(compoundDrawables[1], this.f9002c);
            a(compoundDrawables[2], this.f9003d);
            a(compoundDrawables[3], this.f9004e);
        }
        if (this.f9005f == null && this.f9006g == null) {
            return;
        }
        Drawable[] drawableArrA = AbstractC0833B.a(textView);
        a(drawableArrA[0], this.f9005f);
        a(drawableArrA[2], this.f9006g);
    }

    public final void d(AttributeSet attributeSet, int i) {
        r rVar;
        boolean z5;
        boolean z6;
        String string;
        String string2;
        ColorStateList colorStateList;
        int resourceId;
        int i5;
        int resourceId2;
        TextView textView = this.f9000a;
        Context context = textView.getContext();
        PorterDuff.Mode mode = r.f9236b;
        synchronized (r.class) {
            try {
                if (r.f9237c == null) {
                    r.c();
                }
                rVar = r.f9237c;
            } catch (Throwable th) {
                throw th;
            }
        }
        int[] iArr = AbstractC0617a.f6474f;
        B2.a aVarA = B2.a.A(context, attributeSet, iArr, i);
        TextView textView2 = this.f9000a;
        P.Q.j(textView2, textView2.getContext(), iArr, attributeSet, (TypedArray) aVarA.f136n, i);
        TypedArray typedArray = (TypedArray) aVarA.f136n;
        int resourceId3 = typedArray.getResourceId(0, -1);
        if (typedArray.hasValue(3)) {
            this.f9001b = c(context, rVar, typedArray.getResourceId(3, 0));
        }
        if (typedArray.hasValue(1)) {
            this.f9002c = c(context, rVar, typedArray.getResourceId(1, 0));
        }
        if (typedArray.hasValue(4)) {
            this.f9003d = c(context, rVar, typedArray.getResourceId(4, 0));
        }
        if (typedArray.hasValue(2)) {
            this.f9004e = c(context, rVar, typedArray.getResourceId(2, 0));
        }
        int i6 = Build.VERSION.SDK_INT;
        if (typedArray.hasValue(5)) {
            this.f9005f = c(context, rVar, typedArray.getResourceId(5, 0));
        }
        if (typedArray.hasValue(6)) {
            this.f9006g = c(context, rVar, typedArray.getResourceId(6, 0));
        }
        aVarA.D();
        boolean z7 = textView.getTransformationMethod() instanceof PasswordTransformationMethod;
        int[] iArr2 = AbstractC0617a.f6485t;
        if (resourceId3 != -1) {
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(resourceId3, iArr2);
            B2.a aVar = new B2.a(context, typedArrayObtainStyledAttributes);
            if (z7 || !typedArrayObtainStyledAttributes.hasValue(14)) {
                z5 = false;
                z6 = false;
            } else {
                z6 = typedArrayObtainStyledAttributes.getBoolean(14, false);
                z5 = true;
            }
            l(context, aVar);
            string2 = typedArrayObtainStyledAttributes.hasValue(15) ? typedArrayObtainStyledAttributes.getString(15) : null;
            string = (i6 < 26 || !typedArrayObtainStyledAttributes.hasValue(13)) ? null : typedArrayObtainStyledAttributes.getString(13);
            aVar.D();
        } else {
            z5 = false;
            z6 = false;
            string = null;
            string2 = null;
        }
        TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(attributeSet, iArr2, i, 0);
        B2.a aVar2 = new B2.a(context, typedArrayObtainStyledAttributes2);
        if (!z7 && typedArrayObtainStyledAttributes2.hasValue(14)) {
            z6 = typedArrayObtainStyledAttributes2.getBoolean(14, false);
            z5 = true;
        }
        boolean z8 = z6;
        if (typedArrayObtainStyledAttributes2.hasValue(15)) {
            string2 = typedArrayObtainStyledAttributes2.getString(15);
        }
        if (i6 >= 26 && typedArrayObtainStyledAttributes2.hasValue(13)) {
            string = typedArrayObtainStyledAttributes2.getString(13);
        }
        if (i6 >= 28 && typedArrayObtainStyledAttributes2.hasValue(0) && typedArrayObtainStyledAttributes2.getDimensionPixelSize(0, -1) == 0) {
            textView.setTextSize(0, 0.0f);
        }
        l(context, aVar2);
        aVar2.D();
        if (!z7 && z5) {
            this.f9000a.setAllCaps(z8);
        }
        Typeface typeface = this.f9010l;
        if (typeface != null) {
            if (this.f9009k == -1) {
                textView.setTypeface(typeface, this.f9008j);
            } else {
                textView.setTypeface(typeface);
            }
        }
        if (string != null) {
            AbstractC0835D.d(textView, string);
        }
        if (string2 != null) {
            AbstractC0834C.b(textView, AbstractC0834C.a(string2));
        }
        int[] iArr3 = AbstractC0617a.f6475g;
        P p = this.i;
        Context context2 = p.f9068j;
        TypedArray typedArrayObtainStyledAttributes3 = context2.obtainStyledAttributes(attributeSet, iArr3, i, 0);
        TextView textView3 = p.i;
        P.Q.j(textView3, textView3.getContext(), iArr3, attributeSet, typedArrayObtainStyledAttributes3, i);
        if (typedArrayObtainStyledAttributes3.hasValue(5)) {
            p.f9060a = typedArrayObtainStyledAttributes3.getInt(5, 0);
        }
        float dimension = typedArrayObtainStyledAttributes3.hasValue(4) ? typedArrayObtainStyledAttributes3.getDimension(4, -1.0f) : -1.0f;
        float dimension2 = typedArrayObtainStyledAttributes3.hasValue(2) ? typedArrayObtainStyledAttributes3.getDimension(2, -1.0f) : -1.0f;
        float dimension3 = typedArrayObtainStyledAttributes3.hasValue(1) ? typedArrayObtainStyledAttributes3.getDimension(1, -1.0f) : -1.0f;
        if (typedArrayObtainStyledAttributes3.hasValue(3) && (resourceId2 = typedArrayObtainStyledAttributes3.getResourceId(3, 0)) > 0) {
            TypedArray typedArrayObtainTypedArray = typedArrayObtainStyledAttributes3.getResources().obtainTypedArray(resourceId2);
            int length = typedArrayObtainTypedArray.length();
            int[] iArr4 = new int[length];
            if (length > 0) {
                for (int i7 = 0; i7 < length; i7++) {
                    iArr4[i7] = typedArrayObtainTypedArray.getDimensionPixelSize(i7, -1);
                }
                p.f9065f = P.b(iArr4);
                p.i();
            }
            typedArrayObtainTypedArray.recycle();
        }
        typedArrayObtainStyledAttributes3.recycle();
        if (!p.j()) {
            p.f9060a = 0;
        } else if (p.f9060a == 1) {
            if (!p.f9066g) {
                DisplayMetrics displayMetrics = context2.getResources().getDisplayMetrics();
                if (dimension2 == -1.0f) {
                    i5 = 2;
                    dimension2 = TypedValue.applyDimension(2, 12.0f, displayMetrics);
                } else {
                    i5 = 2;
                }
                if (dimension3 == -1.0f) {
                    dimension3 = TypedValue.applyDimension(i5, 112.0f, displayMetrics);
                }
                float f6 = dimension3;
                if (dimension == -1.0f) {
                    dimension = 1.0f;
                }
                p.k(dimension2, f6, dimension);
            }
            p.h();
        }
        if (d1.f9141a && p.f9060a != 0) {
            int[] iArr5 = p.f9065f;
            if (iArr5.length > 0) {
                if (AbstractC0835D.a(textView) != -1.0f) {
                    AbstractC0835D.b(textView, Math.round(p.f9063d), Math.round(p.f9064e), Math.round(p.f9062c), 0);
                } else {
                    AbstractC0835D.c(textView, iArr5, 0);
                }
            }
        }
        TypedArray typedArrayObtainStyledAttributes4 = context.obtainStyledAttributes(attributeSet, iArr3);
        int resourceId4 = typedArrayObtainStyledAttributes4.getResourceId(8, -1);
        Drawable drawableA = resourceId4 != -1 ? rVar.a(context, resourceId4) : null;
        int resourceId5 = typedArrayObtainStyledAttributes4.getResourceId(13, -1);
        Drawable drawableA2 = resourceId5 != -1 ? rVar.a(context, resourceId5) : null;
        int resourceId6 = typedArrayObtainStyledAttributes4.getResourceId(9, -1);
        Drawable drawableA3 = resourceId6 != -1 ? rVar.a(context, resourceId6) : null;
        int resourceId7 = typedArrayObtainStyledAttributes4.getResourceId(6, -1);
        Drawable drawableA4 = resourceId7 != -1 ? rVar.a(context, resourceId7) : null;
        int resourceId8 = typedArrayObtainStyledAttributes4.getResourceId(10, -1);
        Drawable drawableA5 = resourceId8 != -1 ? rVar.a(context, resourceId8) : null;
        int resourceId9 = typedArrayObtainStyledAttributes4.getResourceId(7, -1);
        Drawable drawableA6 = resourceId9 != -1 ? rVar.a(context, resourceId9) : null;
        if (drawableA5 != null || drawableA6 != null) {
            Drawable[] drawableArrA = AbstractC0833B.a(textView);
            if (drawableA5 == null) {
                drawableA5 = drawableArrA[0];
            }
            if (drawableA2 == null) {
                drawableA2 = drawableArrA[1];
            }
            if (drawableA6 == null) {
                drawableA6 = drawableArrA[2];
            }
            if (drawableA4 == null) {
                drawableA4 = drawableArrA[3];
            }
            AbstractC0833B.b(textView, drawableA5, drawableA2, drawableA6, drawableA4);
        } else if (drawableA != null || drawableA2 != null || drawableA3 != null || drawableA4 != null) {
            Drawable[] drawableArrA2 = AbstractC0833B.a(textView);
            Drawable drawable = drawableArrA2[0];
            if (drawable == null && drawableArrA2[2] == null) {
                Drawable[] compoundDrawables = textView.getCompoundDrawables();
                if (drawableA == null) {
                    drawableA = compoundDrawables[0];
                }
                if (drawableA2 == null) {
                    drawableA2 = compoundDrawables[1];
                }
                if (drawableA3 == null) {
                    drawableA3 = compoundDrawables[2];
                }
                if (drawableA4 == null) {
                    drawableA4 = compoundDrawables[3];
                }
                textView.setCompoundDrawablesWithIntrinsicBounds(drawableA, drawableA2, drawableA3, drawableA4);
            } else {
                if (drawableA2 == null) {
                    drawableA2 = drawableArrA2[1];
                }
                Drawable drawable2 = drawableArrA2[2];
                if (drawableA4 == null) {
                    drawableA4 = drawableArrA2[3];
                }
                AbstractC0833B.b(textView, drawable, drawableA2, drawable2, drawableA4);
            }
        }
        if (typedArrayObtainStyledAttributes4.hasValue(11)) {
            if (!typedArrayObtainStyledAttributes4.hasValue(11) || (resourceId = typedArrayObtainStyledAttributes4.getResourceId(11, 0)) == 0 || (colorStateList = E.c.c(context, resourceId)) == null) {
                colorStateList = typedArrayObtainStyledAttributes4.getColorStateList(11);
            }
            textView.setCompoundDrawableTintList(colorStateList);
        }
        if (typedArrayObtainStyledAttributes4.hasValue(12)) {
            textView.setCompoundDrawableTintMode(V.c(typedArrayObtainStyledAttributes4.getInt(12, -1), null));
        }
        int dimensionPixelSize = typedArrayObtainStyledAttributes4.getDimensionPixelSize(15, -1);
        int dimensionPixelSize2 = typedArrayObtainStyledAttributes4.getDimensionPixelSize(18, -1);
        int dimensionPixelSize3 = typedArrayObtainStyledAttributes4.getDimensionPixelSize(19, -1);
        typedArrayObtainStyledAttributes4.recycle();
        if (dimensionPixelSize != -1) {
            S4.d.E(textView, dimensionPixelSize);
        }
        if (dimensionPixelSize2 != -1) {
            S4.d.F(textView, dimensionPixelSize2);
        }
        if (dimensionPixelSize3 != -1) {
            S4.d.e(dimensionPixelSize3);
            if (dimensionPixelSize3 != textView.getPaint().getFontMetricsInt(null)) {
                textView.setLineSpacing(dimensionPixelSize3 - r0, 1.0f);
            }
        }
    }

    public final void e(Context context, int i) {
        String string;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(i, AbstractC0617a.f6485t);
        B2.a aVar = new B2.a(context, typedArrayObtainStyledAttributes);
        boolean zHasValue = typedArrayObtainStyledAttributes.hasValue(14);
        TextView textView = this.f9000a;
        if (zHasValue) {
            textView.setAllCaps(typedArrayObtainStyledAttributes.getBoolean(14, false));
        }
        int i5 = Build.VERSION.SDK_INT;
        if (typedArrayObtainStyledAttributes.hasValue(0) && typedArrayObtainStyledAttributes.getDimensionPixelSize(0, -1) == 0) {
            textView.setTextSize(0, 0.0f);
        }
        l(context, aVar);
        if (i5 >= 26 && typedArrayObtainStyledAttributes.hasValue(13) && (string = typedArrayObtainStyledAttributes.getString(13)) != null) {
            AbstractC0835D.d(textView, string);
        }
        aVar.D();
        Typeface typeface = this.f9010l;
        if (typeface != null) {
            textView.setTypeface(typeface, this.f9008j);
        }
    }

    public final void g(int i, int i5, int i6, int i7) {
        P p = this.i;
        if (p.j()) {
            DisplayMetrics displayMetrics = p.f9068j.getResources().getDisplayMetrics();
            p.k(TypedValue.applyDimension(i7, i, displayMetrics), TypedValue.applyDimension(i7, i5, displayMetrics), TypedValue.applyDimension(i7, i6, displayMetrics));
            if (p.h()) {
                p.a();
            }
        }
    }

    public final void h(int[] iArr, int i) {
        P p = this.i;
        if (p.j()) {
            int length = iArr.length;
            if (length > 0) {
                int[] iArrCopyOf = new int[length];
                if (i == 0) {
                    iArrCopyOf = Arrays.copyOf(iArr, length);
                } else {
                    DisplayMetrics displayMetrics = p.f9068j.getResources().getDisplayMetrics();
                    for (int i5 = 0; i5 < length; i5++) {
                        iArrCopyOf[i5] = Math.round(TypedValue.applyDimension(i, iArr[i5], displayMetrics));
                    }
                }
                p.f9065f = P.b(iArrCopyOf);
                if (!p.i()) {
                    throw new IllegalArgumentException("None of the preset sizes is valid: " + Arrays.toString(iArr));
                }
            } else {
                p.f9066g = false;
            }
            if (p.h()) {
                p.a();
            }
        }
    }

    public final void i(int i) {
        P p = this.i;
        if (p.j()) {
            if (i == 0) {
                p.f9060a = 0;
                p.f9063d = -1.0f;
                p.f9064e = -1.0f;
                p.f9062c = -1.0f;
                p.f9065f = new int[0];
                p.f9061b = false;
                return;
            }
            if (i != 1) {
                throw new IllegalArgumentException(AbstractC0928a.i(i, "Unknown auto-size text type: "));
            }
            DisplayMetrics displayMetrics = p.f9068j.getResources().getDisplayMetrics();
            p.k(TypedValue.applyDimension(2, 12.0f, displayMetrics), TypedValue.applyDimension(2, 112.0f, displayMetrics), 1.0f);
            if (p.h()) {
                p.a();
            }
        }
    }

    public final void j(ColorStateList colorStateList) {
        if (this.f9007h == null) {
            this.f9007h = new K4.h();
        }
        K4.h hVar = this.f9007h;
        hVar.f1123c = colorStateList;
        hVar.f1122b = colorStateList != null;
        this.f9001b = hVar;
        this.f9002c = hVar;
        this.f9003d = hVar;
        this.f9004e = hVar;
        this.f9005f = hVar;
        this.f9006g = hVar;
    }

    public final void k(PorterDuff.Mode mode) {
        if (this.f9007h == null) {
            this.f9007h = new K4.h();
        }
        K4.h hVar = this.f9007h;
        hVar.f1124d = mode;
        hVar.f1121a = mode != null;
        this.f9001b = hVar;
        this.f9002c = hVar;
        this.f9003d = hVar;
        this.f9004e = hVar;
        this.f9005f = hVar;
        this.f9006g = hVar;
    }

    public final void l(Context context, B2.a aVar) {
        String string;
        int i = this.f9008j;
        TypedArray typedArray = (TypedArray) aVar.f136n;
        this.f9008j = typedArray.getInt(2, i);
        int i5 = Build.VERSION.SDK_INT;
        if (i5 >= 28) {
            int i6 = typedArray.getInt(11, -1);
            this.f9009k = i6;
            if (i6 != -1) {
                this.f9008j &= 2;
            }
        }
        if (!typedArray.hasValue(10) && !typedArray.hasValue(12)) {
            if (typedArray.hasValue(1)) {
                this.f9011m = false;
                int i7 = typedArray.getInt(1, 1);
                if (i7 == 1) {
                    this.f9010l = Typeface.SANS_SERIF;
                    return;
                } else if (i7 == 2) {
                    this.f9010l = Typeface.SERIF;
                    return;
                } else {
                    if (i7 != 3) {
                        return;
                    }
                    this.f9010l = Typeface.MONOSPACE;
                    return;
                }
            }
            return;
        }
        this.f9010l = null;
        int i8 = typedArray.hasValue(12) ? 12 : 10;
        int i9 = this.f9009k;
        int i10 = this.f9008j;
        if (!context.isRestricted()) {
            try {
                Typeface typefaceU = aVar.u(i8, this.f9008j, new C0832A(this, i9, i10, new WeakReference(this.f9000a)));
                if (typefaceU != null) {
                    if (i5 < 28 || this.f9009k == -1) {
                        this.f9010l = typefaceU;
                    } else {
                        this.f9010l = AbstractC0836E.a(Typeface.create(typefaceU, 0), this.f9009k, (this.f9008j & 2) != 0);
                    }
                }
                this.f9011m = this.f9010l == null;
            } catch (Resources.NotFoundException | UnsupportedOperationException unused) {
            }
        }
        if (this.f9010l != null || (string = typedArray.getString(i8)) == null) {
            return;
        }
        if (Build.VERSION.SDK_INT < 28 || this.f9009k == -1) {
            this.f9010l = Typeface.create(string, this.f9008j);
        } else {
            this.f9010l = AbstractC0836E.a(Typeface.create(string, 0), this.f9009k, (this.f9008j & 2) != 0);
        }
    }
}
