package w2;

import android.graphics.Matrix;
import android.os.Build;
import android.view.inputmethod.CursorAnchorInfo;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;

/* loaded from: classes.dex */
public abstract class d {
    /* JADX WARN: Code restructure failed: missing block: B:6:0x005d, code lost:
    
        if (c(r22, r8.j(), r8.e()) == false) goto L8;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private static final CursorAnchorInfo.Builder a(CursorAnchorInfo.Builder builder, int i10, int i11, h0 h0Var, q2.j0 j0Var, r1.i iVar) {
        int i12;
        int i13 = i10;
        int b10 = h0Var.b(i13);
        int b11 = h0Var.b(i11);
        float[] fArr = new float[(b11 - b10) * 4];
        j0Var.w().a(q2.n0.b(b10, b11), fArr, 0);
        while (i13 < i11) {
            int b12 = h0Var.b(i13);
            int i14 = (b12 - b10) * 4;
            r1.i iVar2 = new r1.i(fArr[i14], fArr[i14 + 1], fArr[i14 + 2], fArr[i14 + 3]);
            boolean r10 = iVar.r(iVar2);
            if (c(iVar, iVar2.i(), iVar2.l())) {
                i12 = r10;
            }
            i12 = (r10 ? 1 : 0) | 2;
            builder.addCharacterBounds(i13, iVar2.i(), iVar2.l(), iVar2.j(), iVar2.e(), j0Var.c(b12) == b3.i.Rtl ? i12 | 4 : i12);
            i13++;
        }
        return builder;
    }

    public static final CursorAnchorInfo b(CursorAnchorInfo.Builder builder, q0 q0Var, h0 h0Var, q2.j0 j0Var, Matrix matrix, r1.i iVar, r1.i iVar2, boolean z10, boolean z11, boolean z12, boolean z13) {
        builder.reset();
        builder.setMatrix(matrix);
        int l10 = q2.m0.l(q0Var.g());
        builder.setSelectionRange(l10, q2.m0.k(q0Var.g()));
        if (z10) {
            d(builder, l10, h0Var, j0Var, iVar);
        }
        if (z11) {
            q2.m0 f10 = q0Var.f();
            int l11 = f10 != null ? q2.m0.l(f10.r()) : -1;
            q2.m0 f11 = q0Var.f();
            int k10 = f11 != null ? q2.m0.k(f11.r()) : -1;
            boolean z14 = false;
            if (l11 >= 0 && l11 < k10) {
                z14 = true;
            }
            if (z14) {
                builder.setComposingText(l11, q0Var.h().subSequence(l11, k10));
                a(builder, l11, k10, h0Var, j0Var, iVar);
            }
        }
        int i10 = Build.VERSION.SDK_INT;
        if (i10 >= 33 && z12) {
            b.a(builder, iVar2);
        }
        if (i10 >= 34 && z13) {
            c.a(builder, j0Var, iVar);
        }
        return builder.build();
    }

    private static final boolean c(r1.i iVar, float f10, float f11) {
        if (f10 <= iVar.j() && iVar.i() <= f10) {
            if (f11 <= iVar.e() && iVar.l() <= f11) {
                return true;
            }
        }
        return false;
    }

    private static final CursorAnchorInfo.Builder d(CursorAnchorInfo.Builder builder, int i10, h0 h0Var, q2.j0 j0Var, r1.i iVar) {
        float j10;
        if (i10 < 0) {
            return builder;
        }
        int b10 = h0Var.b(i10);
        r1.i e10 = j0Var.e(b10);
        j10 = jn.o.j(e10.i(), BitmapDescriptorFactory.HUE_RED, c3.r.g(j0Var.B()));
        boolean c10 = c(iVar, j10, e10.l());
        boolean c11 = c(iVar, j10, e10.e());
        int i11 = 1;
        boolean z10 = j0Var.c(b10) == b3.i.Rtl;
        if (!c10 && !c11) {
            i11 = 0;
        }
        if (!c10 || !c11) {
            i11 |= 2;
        }
        builder.setInsertionMarkerLocation(j10, e10.l(), e10.e(), e10.e(), z10 ? i11 | 4 : i11);
        return builder;
    }
}
