package d.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.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.widget.TextView;
import d.h.c.b.h;
import d.h.j.y;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public class z {
    public final TextView a;

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

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

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

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

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

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

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

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

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

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

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

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

    public class a extends h.b {
        public final /* synthetic */ int a;

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

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

        public a(int i2, int i3, WeakReference weakReference) {
            this.a = i2;
            this.f2135b = i3;
            this.f2136c = weakReference;
        }

        @Override // d.h.c.b.h.b
        public void d(int i2) {
        }

        @Override // d.h.c.b.h.b
        public void e(Typeface typeface) {
            int i2;
            if (Build.VERSION.SDK_INT >= 28 && (i2 = this.a) != -1) {
                typeface = Typeface.create(typeface, i2, (this.f2135b & 2) != 0);
            }
            z zVar = z.this;
            WeakReference weakReference = this.f2136c;
            if (zVar.f2134m) {
                zVar.f2133l = typeface;
                TextView textView = (TextView) weakReference.get();
                if (textView != null) {
                    AtomicInteger atomicInteger = d.h.j.y.a;
                    if (y.f.b(textView)) {
                        textView.post(new a0(zVar, textView, typeface, zVar.f2131j));
                    } else {
                        textView.setTypeface(typeface, zVar.f2131j);
                    }
                }
            }
        }
    }

    public z(TextView textView) {
        this.a = textView;
        this.f2130i = new c0(textView);
    }

    public static x0 c(Context context, j jVar, int i2) {
        ColorStateList colorStateListD = jVar.d(context, i2);
        if (colorStateListD == null) {
            return null;
        }
        x0 x0Var = new x0();
        x0Var.f2121d = true;
        x0Var.a = colorStateListD;
        return x0Var;
    }

    public final void a(Drawable drawable, x0 x0Var) {
        if (drawable == null || x0Var == null) {
            return;
        }
        j.f(drawable, x0Var, this.a.getDrawableState());
    }

    public void b() {
        if (this.f2123b != null || this.f2124c != null || this.f2125d != null || this.f2126e != null) {
            Drawable[] compoundDrawables = this.a.getCompoundDrawables();
            a(compoundDrawables[0], this.f2123b);
            a(compoundDrawables[1], this.f2124c);
            a(compoundDrawables[2], this.f2125d);
            a(compoundDrawables[3], this.f2126e);
        }
        if (this.f2127f == null && this.f2128g == null) {
            return;
        }
        Drawable[] compoundDrawablesRelative = this.a.getCompoundDrawablesRelative();
        a(compoundDrawablesRelative[0], this.f2127f);
        a(compoundDrawablesRelative[2], this.f2128g);
    }

    public boolean d() {
        c0 c0Var = this.f2130i;
        return c0Var.i() && c0Var.f1932d != 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: d.b.g.z.e(android.util.AttributeSet, int):void");
    }

    public void f(Context context, int i2) {
        String strM;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(i2, d.b.b.f1549v);
        z0 z0Var = new z0(context, typedArrayObtainStyledAttributes);
        if (z0Var.o(14)) {
            this.a.setAllCaps(z0Var.a(14, false));
        }
        if (z0Var.o(0) && z0Var.f(0, -1) == 0) {
            this.a.setTextSize(0, 0.0f);
        }
        m(context, z0Var);
        if (z0Var.o(13) && (strM = z0Var.m(13)) != null) {
            this.a.setFontVariationSettings(strM);
        }
        typedArrayObtainStyledAttributes.recycle();
        Typeface typeface = this.f2133l;
        if (typeface != null) {
            this.a.setTypeface(typeface, this.f2131j);
        }
    }

    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) {
                    d.h.j.j0.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 (d.h.j.j0.a.a(text, i11, 0)) {
                    i11++;
                    iMin2--;
                }
                if (d.h.j.j0.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;
                d.h.j.j0.a.b(editorInfo, charSequenceConcat, i12, i9 + i12);
                return;
            }
        }
        d.h.j.j0.a.b(editorInfo, null, 0, 0);
    }

    public void h(int i2, int i3, int i4, int i5) {
        c0 c0Var = this.f2130i;
        if (c0Var.i()) {
            DisplayMetrics displayMetrics = c0Var.f1941m.getResources().getDisplayMetrics();
            c0Var.j(TypedValue.applyDimension(i5, i2, displayMetrics), TypedValue.applyDimension(i5, i3, displayMetrics), TypedValue.applyDimension(i5, i4, displayMetrics));
            if (c0Var.g()) {
                c0Var.a();
            }
        }
    }

    public void i(int[] iArr, int i2) {
        c0 c0Var = this.f2130i;
        if (c0Var.i()) {
            int length = iArr.length;
            if (length > 0) {
                int[] iArrCopyOf = new int[length];
                if (i2 == 0) {
                    iArrCopyOf = Arrays.copyOf(iArr, length);
                } else {
                    DisplayMetrics displayMetrics = c0Var.f1941m.getResources().getDisplayMetrics();
                    for (int i3 = 0; i3 < length; i3++) {
                        iArrCopyOf[i3] = Math.round(TypedValue.applyDimension(i2, iArr[i3], displayMetrics));
                    }
                }
                c0Var.f1937i = c0Var.b(iArrCopyOf);
                if (!c0Var.h()) {
                    StringBuilder sbF = g.a.a.a.a.F("None of the preset sizes is valid: ");
                    sbF.append(Arrays.toString(iArr));
                    throw new IllegalArgumentException(sbF.toString());
                }
            } else {
                c0Var.f1938j = false;
            }
            if (c0Var.g()) {
                c0Var.a();
            }
        }
    }

    public void j(int i2) {
        c0 c0Var = this.f2130i;
        if (c0Var.i()) {
            if (i2 == 0) {
                c0Var.f1932d = 0;
                c0Var.f1935g = -1.0f;
                c0Var.f1936h = -1.0f;
                c0Var.f1934f = -1.0f;
                c0Var.f1937i = new int[0];
                c0Var.f1933e = false;
                return;
            }
            if (i2 != 1) {
                throw new IllegalArgumentException(g.a.a.a.a.l("Unknown auto-size text type: ", i2));
            }
            DisplayMetrics displayMetrics = c0Var.f1941m.getResources().getDisplayMetrics();
            c0Var.j(TypedValue.applyDimension(2, 12.0f, displayMetrics), TypedValue.applyDimension(2, 112.0f, displayMetrics), 1.0f);
            if (c0Var.g()) {
                c0Var.a();
            }
        }
    }

    public void k(ColorStateList colorStateList) {
        if (this.f2129h == null) {
            this.f2129h = new x0();
        }
        x0 x0Var = this.f2129h;
        x0Var.a = colorStateList;
        x0Var.f2121d = colorStateList != null;
        this.f2123b = x0Var;
        this.f2124c = x0Var;
        this.f2125d = x0Var;
        this.f2126e = x0Var;
        this.f2127f = x0Var;
        this.f2128g = x0Var;
    }

    public void l(PorterDuff.Mode mode) {
        if (this.f2129h == null) {
            this.f2129h = new x0();
        }
        x0 x0Var = this.f2129h;
        x0Var.f2119b = mode;
        x0Var.f2120c = mode != null;
        this.f2123b = x0Var;
        this.f2124c = x0Var;
        this.f2125d = x0Var;
        this.f2126e = x0Var;
        this.f2127f = x0Var;
        this.f2128g = x0Var;
    }

    public final void m(Context context, z0 z0Var) {
        String strM;
        Typeface typefaceCreate;
        Typeface typeface;
        this.f2131j = z0Var.j(2, this.f2131j);
        int i2 = Build.VERSION.SDK_INT;
        if (i2 >= 28) {
            int iJ = z0Var.j(11, -1);
            this.f2132k = iJ;
            if (iJ != -1) {
                this.f2131j = (this.f2131j & 2) | 0;
            }
        }
        if (!z0Var.o(10) && !z0Var.o(12)) {
            if (z0Var.o(1)) {
                this.f2134m = false;
                int iJ2 = z0Var.j(1, 1);
                if (iJ2 == 1) {
                    typeface = Typeface.SANS_SERIF;
                } else if (iJ2 == 2) {
                    typeface = Typeface.SERIF;
                } else if (iJ2 != 3) {
                    return;
                } else {
                    typeface = Typeface.MONOSPACE;
                }
                this.f2133l = typeface;
                return;
            }
            return;
        }
        this.f2133l = null;
        int i3 = z0Var.o(12) ? 12 : 10;
        int i4 = this.f2132k;
        int i5 = this.f2131j;
        if (!context.isRestricted()) {
            try {
                Typeface typefaceI = z0Var.i(i3, this.f2131j, new a(i4, i5, new WeakReference(this.a)));
                if (typefaceI != null) {
                    if (i2 >= 28 && this.f2132k != -1) {
                        typefaceI = Typeface.create(Typeface.create(typefaceI, 0), this.f2132k, (this.f2131j & 2) != 0);
                    }
                    this.f2133l = typefaceI;
                }
                this.f2134m = this.f2133l == null;
            } catch (Resources.NotFoundException | UnsupportedOperationException unused) {
            }
        }
        if (this.f2133l != null || (strM = z0Var.m(i3)) == null) {
            return;
        }
        if (Build.VERSION.SDK_INT < 28 || this.f2132k == -1) {
            typefaceCreate = Typeface.create(strM, this.f2131j);
        } else {
            typefaceCreate = Typeface.create(Typeface.create(strM, 0), this.f2132k, (this.f2131j & 2) != 0);
        }
        this.f2133l = typefaceCreate;
    }
}
