package c.b.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.e.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 f4992a;

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int f5001j = 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 f5002a;

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

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

        public a(int i2, int i3, WeakReference weakReference) {
            this.f5002a = i2;
            this.f5003b = i3;
            this.f5004c = weakReference;
        }

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

    public n(TextView textView) {
        this.f4992a = textView;
        this.f5000i = 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.f4983d = true;
        j0Var.f4980a = colorStateListC;
        return j0Var;
    }

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

    public void b() {
        if (this.f4993b != null || this.f4994c != null || this.f4995d != null || this.f4996e != null) {
            Drawable[] compoundDrawables = this.f4992a.getCompoundDrawables();
            a(compoundDrawables[0], this.f4993b);
            a(compoundDrawables[1], this.f4994c);
            a(compoundDrawables[2], this.f4995d);
            a(compoundDrawables[3], this.f4996e);
        }
        if (this.f4997f == null && this.f4998g == null) {
            return;
        }
        Drawable[] compoundDrawablesRelative = this.f4992a.getCompoundDrawablesRelative();
        a(compoundDrawablesRelative[0], this.f4997f);
        a(compoundDrawablesRelative[2], this.f4998g);
    }

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

    /* JADX WARN: Removed duplicated region for block: B:207:0x036a  */
    @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: 957
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.g.n.e(android.util.AttributeSet, int):void");
    }

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

    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.e.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.e.i.w.a.a(text, i11, 0)) {
                    i11++;
                    iMin2--;
                }
                if (c.e.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.e.i.w.a.b(editorInfo, charSequenceConcat, i12, i9 + i12);
                return;
            }
        }
        c.e.i.w.a.b(editorInfo, null, 0, 0);
    }

    public void h(int i2, int i3, int i4, int i5) {
        q qVar = this.f5000i;
        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.f5000i;
        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.f5034i = 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.f5035j = false;
            }
            if (qVar.g()) {
                qVar.a();
            }
        }
    }

    public void j(int i2) {
        q qVar = this.f5000i;
        if (qVar.i()) {
            if (i2 == 0) {
                qVar.f5029d = 0;
                qVar.f5032g = -1.0f;
                qVar.f5033h = -1.0f;
                qVar.f5031f = -1.0f;
                qVar.f5034i = new int[0];
                qVar.f5030e = 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.f4999h == null) {
            this.f4999h = new j0();
        }
        j0 j0Var = this.f4999h;
        j0Var.f4980a = colorStateList;
        j0Var.f4983d = colorStateList != null;
        this.f4993b = j0Var;
        this.f4994c = j0Var;
        this.f4995d = j0Var;
        this.f4996e = j0Var;
        this.f4997f = j0Var;
        this.f4998g = j0Var;
    }

    public void l(PorterDuff.Mode mode) {
        if (this.f4999h == null) {
            this.f4999h = new j0();
        }
        j0 j0Var = this.f4999h;
        j0Var.f4981b = mode;
        j0Var.f4982c = mode != null;
        this.f4993b = j0Var;
        this.f4994c = j0Var;
        this.f4995d = j0Var;
        this.f4996e = j0Var;
        this.f4997f = j0Var;
        this.f4998g = j0Var;
    }

    public final void m(Context context, l0 l0Var) {
        String strJ;
        Typeface typefaceCreate;
        Typeface typeface;
        this.f5001j = l0Var.g(2, this.f5001j);
        int i2 = Build.VERSION.SDK_INT;
        if (i2 >= 28) {
            int iG = l0Var.g(11, -1);
            this.k = iG;
            if (iG != -1) {
                this.f5001j = (this.f5001j & 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.f5001j;
        if (!context.isRestricted()) {
            try {
                Typeface typefaceF = l0Var.f(i3, this.f5001j, new a(i4, i5, new WeakReference(this.f4992a)));
                if (typefaceF != null) {
                    if (i2 >= 28 && this.k != -1) {
                        typefaceF = Typeface.create(Typeface.create(typefaceF, 0), this.k, (this.f5001j & 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.f5001j);
        } else {
            typefaceCreate = Typeface.create(Typeface.create(strJ, 0), this.k, (this.f5001j & 2) != 0);
        }
        this.l = typefaceCreate;
    }
}
