package c.a.g;

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.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.widget.TextView;
import c.c.c.b.e;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Objects;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes.dex */
public class n {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public j0 f5007b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public j0 f5008c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public j0 f5009d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public j0 f5010e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public j0 f5011f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public j0 f5012g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public j0 f5013h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final q f5014i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int f5015j = 0;
    public int k = -1;
    public Typeface l;
    public boolean m;

    public class a extends e.a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final /* synthetic */ int f5016a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final /* synthetic */ int f5017b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public final /* synthetic */ WeakReference f5018c;

        public a(int i2, int i3, WeakReference weakReference) {
            this.f5016a = i2;
            this.f5017b = i3;
            this.f5018c = weakReference;
        }

        @Override // c.c.c.b.e.a
        public void d(Typeface typeface) {
            int i2;
            if (Build.VERSION.SDK_INT >= 28 && (i2 = this.f5016a) != -1) {
                typeface = Typeface.create(typeface, i2, (this.f5017b & 2) != 0);
            }
            n nVar = n.this;
            WeakReference weakReference = this.f5018c;
            if (nVar.m) {
                nVar.l = typeface;
                TextView textView = (TextView) weakReference.get();
                if (textView != null) {
                    WeakHashMap<View, c.c.i.q> weakHashMap = c.c.i.k.f5288a;
                    if (textView.isAttachedToWindow()) {
                        textView.post(new o(nVar, textView, typeface, nVar.f5015j));
                    } else {
                        textView.setTypeface(typeface, nVar.f5015j);
                    }
                }
            }
        }
    }

    public n(TextView textView) {
        this.f5006a = textView;
        this.f5014i = new q(textView);
    }

    public static j0 c(Context context, f fVar, int i2) {
        ColorStateList colorStateListC = fVar.c(context, i2);
        if (colorStateListC == null) {
            return null;
        }
        j0 j0Var = new j0();
        j0Var.f4997d = true;
        j0Var.f4994a = colorStateListC;
        return j0Var;
    }

    public final void a(Drawable drawable, j0 j0Var) {
        if (drawable == null || j0Var == null) {
            return;
        }
        f.e(drawable, j0Var, this.f5006a.getDrawableState());
    }

    public void b() {
        if (this.f5007b != null || this.f5008c != null || this.f5009d != null || this.f5010e != null) {
            Drawable[] compoundDrawables = this.f5006a.getCompoundDrawables();
            a(compoundDrawables[0], this.f5007b);
            a(compoundDrawables[1], this.f5008c);
            a(compoundDrawables[2], this.f5009d);
            a(compoundDrawables[3], this.f5010e);
        }
        if (this.f5011f == null && this.f5012g == null) {
            return;
        }
        Drawable[] compoundDrawablesRelative = this.f5006a.getCompoundDrawablesRelative();
        a(compoundDrawablesRelative[0], this.f5011f);
        a(compoundDrawablesRelative[2], this.f5012g);
    }

    public boolean d() {
        q qVar = this.f5014i;
        return qVar.i() && qVar.f5060d != 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:210:0x0371  */
    @android.annotation.SuppressLint({"NewApi"})
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void e(android.util.AttributeSet r23, int r24) {
        /*
            Method dump skipped, instruction units count: 964
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: c.a.g.n.e(android.util.AttributeSet, int):void");
    }

    public void f(Context context, int i2) {
        String strJ;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(i2, c.a.b.v);
        l0 l0Var = new l0(context, typedArrayObtainStyledAttributes);
        if (l0Var.l(14)) {
            this.f5006a.setAllCaps(l0Var.a(14, false));
        }
        int i3 = Build.VERSION.SDK_INT;
        if (l0Var.l(0) && l0Var.d(0, -1) == 0) {
            this.f5006a.setTextSize(0, 0.0f);
        }
        m(context, l0Var);
        if (i3 >= 26 && l0Var.l(13) && (strJ = l0Var.j(13)) != null) {
            this.f5006a.setFontVariationSettings(strJ);
        }
        typedArrayObtainStyledAttributes.recycle();
        Typeface typeface = this.l;
        if (typeface != null) {
            this.f5006a.setTypeface(typeface, this.f5015j);
        }
    }

    public void g(TextView textView, InputConnection inputConnection, EditorInfo editorInfo) {
        int i2 = Build.VERSION.SDK_INT;
        if (i2 >= 30 || inputConnection == null) {
            return;
        }
        CharSequence text = textView.getText();
        if (i2 >= 30) {
            editorInfo.setInitialSurroundingSubText(text, 0);
            return;
        }
        Objects.requireNonNull(text);
        if (i2 >= 30) {
            editorInfo.setInitialSurroundingSubText(text, 0);
            return;
        }
        int i3 = editorInfo.initialSelStart;
        int i4 = editorInfo.initialSelEnd;
        int i5 = i3 > i4 ? i4 + 0 : i3 + 0;
        int i6 = i3 > i4 ? i3 - 0 : i4 + 0;
        int length = text.length();
        if (i5 >= 0 && i6 <= length) {
            int i7 = editorInfo.inputType & 4095;
            if (!(i7 == 129 || i7 == 225 || i7 == 18)) {
                if (length <= 2048) {
                    c.c.i.w.a.b(editorInfo, text, i5, i6);
                    return;
                }
                int i8 = i6 - i5;
                int i9 = i8 > 1024 ? 0 : i8;
                int i10 = 2048 - i9;
                int iMin = Math.min(text.length() - i6, i10 - Math.min(i5, (int) (((double) i10) * 0.8d)));
                int iMin2 = Math.min(i5, i10 - iMin);
                int i11 = i5 - iMin2;
                if (c.c.i.w.a.a(text, i11, 0)) {
                    i11++;
                    iMin2--;
                }
                if (c.c.i.w.a.a(text, (i6 + iMin) - 1, 1)) {
                    iMin--;
                }
                CharSequence charSequenceConcat = i9 != i8 ? TextUtils.concat(text.subSequence(i11, i11 + iMin2), text.subSequence(i6, iMin + i6)) : text.subSequence(i11, iMin2 + i9 + iMin + i11);
                int i12 = iMin2 + 0;
                c.c.i.w.a.b(editorInfo, charSequenceConcat, i12, i9 + i12);
                return;
            }
        }
        c.c.i.w.a.b(editorInfo, null, 0, 0);
    }

    public void h(int i2, int i3, int i4, int i5) {
        q qVar = this.f5014i;
        if (qVar.i()) {
            DisplayMetrics displayMetrics = qVar.m.getResources().getDisplayMetrics();
            qVar.j(TypedValue.applyDimension(i5, i2, displayMetrics), TypedValue.applyDimension(i5, i3, displayMetrics), TypedValue.applyDimension(i5, i4, displayMetrics));
            if (qVar.g()) {
                qVar.a();
            }
        }
    }

    public void i(int[] iArr, int i2) {
        q qVar = this.f5014i;
        if (qVar.i()) {
            int length = iArr.length;
            if (length > 0) {
                int[] iArrCopyOf = new int[length];
                if (i2 == 0) {
                    iArrCopyOf = Arrays.copyOf(iArr, length);
                } else {
                    DisplayMetrics displayMetrics = qVar.m.getResources().getDisplayMetrics();
                    for (int i3 = 0; i3 < length; i3++) {
                        iArrCopyOf[i3] = Math.round(TypedValue.applyDimension(i2, iArr[i3], displayMetrics));
                    }
                }
                qVar.f5065i = qVar.b(iArrCopyOf);
                if (!qVar.h()) {
                    StringBuilder sbC = a.b.c.a.a.C("None of the preset sizes is valid: ");
                    sbC.append(Arrays.toString(iArr));
                    throw new IllegalArgumentException(sbC.toString());
                }
            } else {
                qVar.f5066j = false;
            }
            if (qVar.g()) {
                qVar.a();
            }
        }
    }

    public void j(int i2) {
        q qVar = this.f5014i;
        if (qVar.i()) {
            if (i2 == 0) {
                qVar.f5060d = 0;
                qVar.f5063g = -1.0f;
                qVar.f5064h = -1.0f;
                qVar.f5062f = -1.0f;
                qVar.f5065i = new int[0];
                qVar.f5061e = false;
                return;
            }
            if (i2 != 1) {
                throw new IllegalArgumentException(a.b.c.a.a.o("Unknown auto-size text type: ", i2));
            }
            DisplayMetrics displayMetrics = qVar.m.getResources().getDisplayMetrics();
            qVar.j(TypedValue.applyDimension(2, 12.0f, displayMetrics), TypedValue.applyDimension(2, 112.0f, displayMetrics), 1.0f);
            if (qVar.g()) {
                qVar.a();
            }
        }
    }

    public void k(ColorStateList colorStateList) {
        if (this.f5013h == null) {
            this.f5013h = new j0();
        }
        j0 j0Var = this.f5013h;
        j0Var.f4994a = colorStateList;
        j0Var.f4997d = colorStateList != null;
        this.f5007b = j0Var;
        this.f5008c = j0Var;
        this.f5009d = j0Var;
        this.f5010e = j0Var;
        this.f5011f = j0Var;
        this.f5012g = j0Var;
    }

    public void l(PorterDuff.Mode mode) {
        if (this.f5013h == null) {
            this.f5013h = new j0();
        }
        j0 j0Var = this.f5013h;
        j0Var.f4995b = mode;
        j0Var.f4996c = mode != null;
        this.f5007b = j0Var;
        this.f5008c = j0Var;
        this.f5009d = j0Var;
        this.f5010e = j0Var;
        this.f5011f = j0Var;
        this.f5012g = j0Var;
    }

    public final void m(Context context, l0 l0Var) {
        String strJ;
        Typeface typefaceCreate;
        Typeface typeface;
        this.f5015j = l0Var.g(2, this.f5015j);
        int i2 = Build.VERSION.SDK_INT;
        if (i2 >= 28) {
            int iG = l0Var.g(11, -1);
            this.k = iG;
            if (iG != -1) {
                this.f5015j = (this.f5015j & 2) | 0;
            }
        }
        if (!l0Var.l(10) && !l0Var.l(12)) {
            if (l0Var.l(1)) {
                this.m = false;
                int iG2 = l0Var.g(1, 1);
                if (iG2 == 1) {
                    typeface = Typeface.SANS_SERIF;
                } else if (iG2 == 2) {
                    typeface = Typeface.SERIF;
                } else if (iG2 != 3) {
                    return;
                } else {
                    typeface = Typeface.MONOSPACE;
                }
                this.l = typeface;
                return;
            }
            return;
        }
        this.l = null;
        int i3 = l0Var.l(12) ? 12 : 10;
        int i4 = this.k;
        int i5 = this.f5015j;
        if (!context.isRestricted()) {
            try {
                Typeface typefaceF = l0Var.f(i3, this.f5015j, new a(i4, i5, new WeakReference(this.f5006a)));
                if (typefaceF != null) {
                    if (i2 >= 28 && this.k != -1) {
                        typefaceF = Typeface.create(Typeface.create(typefaceF, 0), this.k, (this.f5015j & 2) != 0);
                    }
                    this.l = typefaceF;
                }
                this.m = this.l == null;
            } catch (Resources.NotFoundException | UnsupportedOperationException unused) {
            }
        }
        if (this.l != null || (strJ = l0Var.j(i3)) == null) {
            return;
        }
        if (Build.VERSION.SDK_INT < 28 || this.k == -1) {
            typefaceCreate = Typeface.create(strJ, this.f5015j);
        } else {
            typefaceCreate = Typeface.create(Typeface.create(strJ, 0), this.k, (this.f5015j & 2) != 0);
        }
        this.l = typefaceCreate;
    }
}
