package o;

import android.graphics.Matrix;
import android.os.Build;
import android.view.View;
import android.view.inputmethod.CursorAnchorInfo;
import android.view.inputmethod.InputMethodManager;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class IK {
    public final C2873x4 a;
    public final DH b;
    public boolean d;
    public boolean e;
    public boolean f;
    public boolean g;
    public boolean h;
    public boolean i;
    public C2730ve0 j;
    public Ne0 k;
    public InterfaceC1955nT l;
    public T00 m;
    public T00 n;
    public final Object c = new Object();

    /* renamed from: o, reason: collision with root package name */
    public final CursorAnchorInfo.Builder f156o = new CursorAnchorInfo.Builder();
    public final float[] p = C1570jO.a();
    public final Matrix q = new Matrix();

    public IK(C2873x4 c2873x4, DH dh) {
        this.a = c2873x4;
        this.b = dh;
    }

    public final void a() {
        DH dh;
        DH dh2 = this.b;
        InputMethodManager inputMethodManagerM = dh2.m();
        View view = (View) dh2.l;
        if (!inputMethodManagerM.isActive(view) || this.j == null || this.l == null || this.k == null || this.m == null || this.n == null) {
            return;
        }
        float[] fArr = this.p;
        C1570jO.d(fArr);
        InterfaceC1184fK interfaceC1184fK = (InterfaceC1184fK) this.a.t.C.getValue();
        if (interfaceC1184fK != null) {
            if (!interfaceC1184fK.A()) {
                interfaceC1184fK = null;
            }
            if (interfaceC1184fK != null) {
                interfaceC1184fK.D(fArr);
            }
        }
        T00 t00 = this.n;
        C1570jO.f(fArr, -t00.a, -t00.b);
        Matrix matrix = this.q;
        F3.P(matrix, fArr);
        C2730ve0 c2730ve0 = this.j;
        InterfaceC1955nT interfaceC1955nT = this.l;
        Ne0 ne0 = this.k;
        T00 t002 = this.m;
        T00 t003 = this.n;
        boolean z = this.f;
        boolean z2 = this.g;
        boolean z3 = this.h;
        boolean z4 = this.i;
        CursorAnchorInfo.Builder builder = this.f156o;
        builder.reset();
        builder.setMatrix(matrix);
        long j = c2730ve0.b;
        Ue0 ue0 = c2730ve0.c;
        int iF = Ue0.f(j);
        builder.setSelectionRange(iF, Ue0.e(c2730ve0.b));
        if (!z || iF < 0) {
            dh = dh2;
        } else {
            int iP = interfaceC1955nT.p(iF);
            T00 t00C = ne0.c(iP);
            dh = dh2;
            float fJ = AbstractC0940cn0.j(t00C.a, 0.0f, (int) (ne0.c >> 32));
            boolean zS = C1884mi0.s(t002, fJ, t00C.b);
            boolean zS2 = C1884mi0.s(t002, fJ, t00C.d);
            boolean z5 = ne0.a(iP) == 2;
            int i = (zS || zS2) ? 1 : 0;
            if (!zS || !zS2) {
                i |= 2;
            }
            if (z5) {
                i |= 4;
            }
            float f = t00C.b;
            float f2 = t00C.d;
            builder.setInsertionMarkerLocation(fJ, f, f2, f2, i);
        }
        if (z2) {
            int iF2 = ue0 != null ? Ue0.f(ue0.a) : -1;
            int iE = ue0 != null ? Ue0.e(ue0.a) : -1;
            if (iF2 >= 0 && iF2 < iE) {
                builder.setComposingText(iF2, c2730ve0.a.m.subSequence(iF2, iE));
                int iP2 = interfaceC1955nT.p(iF2);
                int iP3 = interfaceC1955nT.p(iE);
                float[] fArr2 = new float[(iP3 - iP2) * 4];
                ne0.b.a(AbstractC2378rs0.u(iP2, iP3), fArr2);
                int i2 = iF2;
                while (i2 < iE) {
                    int iP4 = interfaceC1955nT.p(i2);
                    int i3 = (iP4 - iP2) * 4;
                    float f3 = fArr2[i3];
                    float f4 = fArr2[i3 + 1];
                    int i4 = iE;
                    float f5 = fArr2[i3 + 2];
                    float f6 = fArr2[i3 + 3];
                    int i5 = iP2;
                    int i6 = (t002.a < f5 ? 1 : 0) & (f3 < t002.c ? 1 : 0) & (t002.b < f6 ? 1 : 0) & (f4 < t002.d ? 1 : 0);
                    if (!C1884mi0.s(t002, f3, f4) || !C1884mi0.s(t002, f5, f6)) {
                        i6 |= 2;
                    }
                    if (ne0.a(iP4) == 2) {
                        i6 |= 4;
                    }
                    builder.addCharacterBounds(i2, f3, f4, f5, f6, i6);
                    i2++;
                    iE = i4;
                    iP2 = i5;
                }
            }
        }
        int i7 = Build.VERSION.SDK_INT;
        if (i7 >= 33 && z3) {
            builder.setEditorBoundsInfo(B0.k().setEditorBounds(As0.X(t003)).setHandwritingBounds(As0.X(t003)).build());
        }
        if (i7 >= 34 && z4 && !t002.e()) {
            float f7 = t002.b;
            C2331rQ c2331rQ = ne0.b;
            int iE2 = c2331rQ.e(f7);
            int iE3 = c2331rQ.e(t002.d);
            if (iE2 <= iE3) {
                while (true) {
                    builder.addVisibleLineBounds(ne0.e(iE2), c2331rQ.f(iE2), ne0.f(iE2), c2331rQ.b(iE2));
                    if (iE2 == iE3) {
                        break;
                    } else {
                        iE2++;
                    }
                }
            }
        }
        dh.m().updateCursorAnchorInfo(view, builder.build());
        this.e = false;
    }
}
