package o;

import android.R;
import android.os.Build;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Handler;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.DeleteGesture;
import android.view.inputmethod.DeleteRangeGesture;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputContentInfo;
import android.view.inputmethod.PreviewableHandwritingGesture;
import android.view.inputmethod.SelectGesture;
import android.view.inputmethod.SelectRangeGesture;
import java.lang.ref.WeakReference;
import java.util.ArrayList;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class R00 implements InputConnection {
    public final C0247Jn a;
    public final boolean b;
    public final MK c;
    public final C2066oe0 d;
    public final Qj0 e;
    public int f;
    public C2730ve0 g;
    public int h;
    public boolean i;
    public final ArrayList j = new ArrayList();
    public boolean k = true;

    public R00(C2730ve0 c2730ve0, C0247Jn c0247Jn, boolean z, MK mk, C2066oe0 c2066oe0, Qj0 qj0) {
        this.a = c0247Jn;
        this.b = z;
        this.c = mk;
        this.d = c2066oe0;
        this.e = qj0;
        this.g = c2730ve0;
    }

    public final void a(InterfaceC0764av interfaceC0764av) {
        this.f++;
        try {
            this.j.add(interfaceC0764av);
        } finally {
            b();
        }
    }

    public final boolean b() {
        int i = this.f - 1;
        this.f = i;
        if (i == 0) {
            ArrayList arrayList = this.j;
            if (!arrayList.isEmpty()) {
                ((NK) this.a.m).c.g(new ArrayList(arrayList));
                arrayList.clear();
            }
        }
        return this.f > 0;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean beginBatchEdit() {
        boolean z = this.k;
        if (!z) {
            return z;
        }
        this.f++;
        return true;
    }

    public final void c(int i) {
        sendKeyEvent(new KeyEvent(0, i));
        sendKeyEvent(new KeyEvent(1, i));
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean clearMetaKeyStates(int i) {
        boolean z = this.k;
        if (z) {
            return false;
        }
        return z;
    }

    @Override // android.view.inputmethod.InputConnection
    public final void closeConnection() {
        this.j.clear();
        this.f = 0;
        this.k = false;
        ArrayList arrayList = ((NK) this.a.m).j;
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            if (F3.c(((WeakReference) arrayList.get(i)).get(), this)) {
                arrayList.remove(i);
                return;
            }
        }
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean commitCompletion(CompletionInfo completionInfo) {
        boolean z = this.k;
        if (z) {
            return false;
        }
        return z;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean commitContent(InputContentInfo inputContentInfo, int i, Bundle bundle) {
        boolean z = this.k;
        if (z) {
            return false;
        }
        return z;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean commitCorrection(CorrectionInfo correctionInfo) {
        boolean z = this.k;
        return z ? this.b : z;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean commitText(CharSequence charSequence, int i) {
        boolean z = this.k;
        if (z) {
            a(new C1314gj(String.valueOf(charSequence), i));
        }
        return z;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean deleteSurroundingText(int i, int i2) {
        boolean z = this.k;
        if (!z) {
            return z;
        }
        a(new C1711kr(i, i2));
        return true;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean deleteSurroundingTextInCodePoints(int i, int i2) {
        boolean z = this.k;
        if (!z) {
            return z;
        }
        a(new C1806lr(i, i2));
        return true;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean endBatchEdit() {
        return b();
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean finishComposingText() {
        boolean z = this.k;
        if (!z) {
            return z;
        }
        a(new C2957xy());
        return true;
    }

    @Override // android.view.inputmethod.InputConnection
    public final int getCursorCapsMode(int i) {
        C2730ve0 c2730ve0 = this.g;
        return TextUtils.getCapsMode(c2730ve0.a.m, Ue0.f(c2730ve0.b), i);
    }

    @Override // android.view.inputmethod.InputConnection
    public final ExtractedText getExtractedText(ExtractedTextRequest extractedTextRequest, int i) {
        boolean z = (i & 1) != 0;
        this.i = z;
        if (z) {
            this.h = extractedTextRequest != null ? extractedTextRequest.token : 0;
        }
        return AbstractC2378rs0.B(this.g);
    }

    @Override // android.view.inputmethod.InputConnection
    public final Handler getHandler() {
        return null;
    }

    @Override // android.view.inputmethod.InputConnection
    public final CharSequence getSelectedText(int i) {
        if (Ue0.c(this.g.b)) {
            return null;
        }
        return AbstractC0940cn0.w(this.g).m;
    }

    @Override // android.view.inputmethod.InputConnection
    public final CharSequence getTextAfterCursor(int i, int i2) {
        return AbstractC0940cn0.x(this.g, i).m;
    }

    @Override // android.view.inputmethod.InputConnection
    public final CharSequence getTextBeforeCursor(int i, int i2) {
        return AbstractC0940cn0.y(this.g, i).m;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean performContextMenuAction(int i) {
        boolean z = this.k;
        if (z) {
            z = false;
            switch (i) {
                case R.id.selectAll:
                    a(new C2500t70(0, this.g.a.m.length()));
                    break;
                case R.id.cut:
                    c(277);
                    return false;
                case R.id.copy:
                    c(278);
                    return false;
                case R.id.paste:
                    c(279);
                    return false;
                default:
                    return false;
            }
        }
        return z;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x000a  */
    @Override // android.view.inputmethod.InputConnection
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean performEditorAction(int r4) {
        /*
            r3 = this;
            boolean r0 = r3.k
            if (r0 == 0) goto L27
            r0 = 1
            if (r4 == 0) goto La
            switch(r4) {
                case 2: goto L16;
                case 3: goto L14;
                case 4: goto L12;
                case 5: goto L10;
                case 6: goto Le;
                case 7: goto Lc;
                default: goto La;
            }
        La:
            r4 = r0
            goto L17
        Lc:
            r4 = 5
            goto L17
        Le:
            r4 = 7
            goto L17
        L10:
            r4 = 6
            goto L17
        L12:
            r4 = 4
            goto L17
        L14:
            r4 = 3
            goto L17
        L16:
            r4 = 2
        L17:
            o.Jn r1 = r3.a
            java.lang.Object r1 = r1.m
            o.NK r1 = (o.NK) r1
            o.OC r1 = r1.d
            o.GG r2 = new o.GG
            r2.<init>(r4)
            r1.g(r2)
        L27:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: o.R00.performEditorAction(int):boolean");
    }

    /* JADX WARN: Removed duplicated region for block: B:131:0x02d0  */
    @Override // android.view.inputmethod.InputConnection
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void performHandwritingGesture(android.view.inputmethod.HandwritingGesture r20, java.util.concurrent.Executor r21, java.util.function.IntConsumer r22) {
        /*
            Method dump skipped, instructions count: 924
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.R00.performHandwritingGesture(android.view.inputmethod.HandwritingGesture, java.util.concurrent.Executor, java.util.function.IntConsumer):void");
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean performPrivateCommand(String str, Bundle bundle) {
        boolean z = this.k;
        if (z) {
            return true;
        }
        return z;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean previewHandwritingGesture(PreviewableHandwritingGesture previewableHandwritingGesture, CancellationSignal cancellationSignal) {
        MK mk;
        C0977d7 c0977d7;
        Me0 me0;
        if (Build.VERSION.SDK_INT >= 34 && (mk = this.c) != null && (c0977d7 = mk.j) != null) {
            Oe0 oe0D = mk.d();
            if (c0977d7.equals((oe0D == null || (me0 = oe0D.a.a) == null) ? null : me0.a)) {
                boolean zR = AbstractC2588u4.r(previewableHandwritingGesture);
                EnumC3079zE enumC3079zE = EnumC3079zE.l;
                C2066oe0 c2066oe0 = this.d;
                if (zR) {
                    SelectGesture selectGestureK = AbstractC2588u4.k(previewableHandwritingGesture);
                    if (c2066oe0 != null) {
                        long jU = AbstractC2378rs0.U(mk, As0.a0(selectGestureK.getSelectionArea()), selectGestureK.getGranularity() != 1 ? 0 : 1);
                        MK mk2 = c2066oe0.d;
                        if (mk2 != null) {
                            mk2.f(jU);
                        }
                        MK mk3 = c2066oe0.d;
                        if (mk3 != null) {
                            mk3.e(Ue0.b);
                        }
                        if (!Ue0.c(jU)) {
                            c2066oe0.s(false);
                            c2066oe0.p(enumC3079zE);
                        }
                    }
                } else if (AbstractC2588u4.y(previewableHandwritingGesture)) {
                    DeleteGesture deleteGestureJ = EE.j(previewableHandwritingGesture);
                    if (c2066oe0 != null) {
                        long jU2 = AbstractC2378rs0.U(mk, As0.a0(deleteGestureJ.getDeletionArea()), deleteGestureJ.getGranularity() != 1 ? 0 : 1);
                        MK mk4 = c2066oe0.d;
                        if (mk4 != null) {
                            mk4.e(jU2);
                        }
                        MK mk5 = c2066oe0.d;
                        if (mk5 != null) {
                            mk5.f(Ue0.b);
                        }
                        if (!Ue0.c(jU2)) {
                            c2066oe0.s(false);
                            c2066oe0.p(enumC3079zE);
                        }
                    }
                } else if (EE.w(previewableHandwritingGesture)) {
                    SelectRangeGesture selectRangeGestureP = EE.p(previewableHandwritingGesture);
                    if (c2066oe0 != null) {
                        long jX = AbstractC2378rs0.x(mk, As0.a0(selectRangeGestureP.getSelectionStartArea()), As0.a0(selectRangeGestureP.getSelectionEndArea()), selectRangeGestureP.getGranularity() != 1 ? 0 : 1);
                        MK mk6 = c2066oe0.d;
                        if (mk6 != null) {
                            mk6.f(jX);
                        }
                        MK mk7 = c2066oe0.d;
                        if (mk7 != null) {
                            mk7.e(Ue0.b);
                        }
                        if (!Ue0.c(jX)) {
                            c2066oe0.s(false);
                            c2066oe0.p(enumC3079zE);
                        }
                    }
                } else if (EE.z(previewableHandwritingGesture)) {
                    DeleteRangeGesture deleteRangeGestureK = EE.k(previewableHandwritingGesture);
                    if (c2066oe0 != null) {
                        long jX2 = AbstractC2378rs0.x(mk, As0.a0(deleteRangeGestureK.getDeletionStartArea()), As0.a0(deleteRangeGestureK.getDeletionEndArea()), deleteRangeGestureK.getGranularity() != 1 ? 0 : 1);
                        MK mk8 = c2066oe0.d;
                        if (mk8 != null) {
                            mk8.e(jX2);
                        }
                        MK mk9 = c2066oe0.d;
                        if (mk9 != null) {
                            mk9.f(Ue0.b);
                        }
                        if (!Ue0.c(jX2)) {
                            c2066oe0.s(false);
                            c2066oe0.p(enumC3079zE);
                        }
                    }
                }
                if (cancellationSignal != null) {
                    cancellationSignal.setOnCancelListener(new C3121zk(1, c2066oe0));
                }
                return true;
            }
        }
        return false;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean reportFullscreenMode(boolean z) {
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:57:0x005b A[EXC_TOP_SPLITTER, SYNTHETIC] */
    @Override // android.view.inputmethod.InputConnection
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean requestCursorUpdates(int r10) {
        /*
            r9 = this;
            boolean r0 = r9.k
            if (r0 == 0) goto L77
            r0 = r10 & 1
            r1 = 0
            r2 = 1
            if (r0 == 0) goto Lc
            r0 = r2
            goto Ld
        Lc:
            r0 = r1
        Ld:
            r3 = r10 & 2
            if (r3 == 0) goto L13
            r3 = r2
            goto L14
        L13:
            r3 = r1
        L14:
            int r4 = android.os.Build.VERSION.SDK_INT
            r5 = 33
            if (r4 < r5) goto L4d
            r5 = r10 & 16
            if (r5 == 0) goto L20
            r5 = r2
            goto L21
        L20:
            r5 = r1
        L21:
            r6 = r10 & 8
            if (r6 == 0) goto L27
            r6 = r2
            goto L28
        L27:
            r6 = r1
        L28:
            r7 = r10 & 4
            if (r7 == 0) goto L2e
            r7 = r2
            goto L2f
        L2e:
            r7 = r1
        L2f:
            r8 = 34
            if (r4 < r8) goto L38
            r10 = r10 & 32
            if (r10 == 0) goto L38
            r1 = r2
        L38:
            if (r5 != 0) goto L4a
            if (r6 != 0) goto L4a
            if (r7 != 0) goto L4a
            if (r1 != 0) goto L4a
            if (r4 < r8) goto L47
            r10 = r2
            r1 = r10
        L44:
            r5 = r1
        L45:
            r6 = r5
            goto L50
        L47:
            r10 = r1
            r1 = r2
            goto L44
        L4a:
            r10 = r1
            r1 = r7
            goto L50
        L4d:
            r10 = r1
            r5 = r2
            goto L45
        L50:
            o.Jn r4 = r9.a
            java.lang.Object r4 = r4.m
            o.NK r4 = (o.NK) r4
            o.IK r4 = r4.m
            java.lang.Object r7 = r4.c
            monitor-enter(r7)
            r4.f = r5     // Catch: java.lang.Throwable -> L6f
            r4.g = r6     // Catch: java.lang.Throwable -> L6f
            r4.h = r1     // Catch: java.lang.Throwable -> L6f
            r4.i = r10     // Catch: java.lang.Throwable -> L6f
            if (r0 == 0) goto L71
            r4.e = r2     // Catch: java.lang.Throwable -> L6f
            o.ve0 r10 = r4.j     // Catch: java.lang.Throwable -> L6f
            if (r10 == 0) goto L71
            r4.a()     // Catch: java.lang.Throwable -> L6f
            goto L71
        L6f:
            r10 = move-exception
            goto L75
        L71:
            r4.d = r3     // Catch: java.lang.Throwable -> L6f
            monitor-exit(r7)
            return r2
        L75:
            monitor-exit(r7)
            throw r10
        L77:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: o.R00.requestCursorUpdates(int):boolean");
    }

    /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, o.zK] */
    @Override // android.view.inputmethod.InputConnection
    public final boolean sendKeyEvent(KeyEvent keyEvent) {
        boolean z = this.k;
        if (!z) {
            return z;
        }
        ((BaseInputConnection) ((NK) this.a.m).k.getValue()).sendKeyEvent(keyEvent);
        return true;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean setComposingRegion(int i, int i2) {
        boolean z = this.k;
        if (z) {
            a(new C2310r70(i, i2));
        }
        return z;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean setComposingText(CharSequence charSequence, int i) {
        boolean z = this.k;
        if (z) {
            a(new C2405s70(String.valueOf(charSequence), i));
        }
        return z;
    }

    @Override // android.view.inputmethod.InputConnection
    public final boolean setSelection(int i, int i2) {
        boolean z = this.k;
        if (!z) {
            return z;
        }
        a(new C2500t70(i, i2));
        return true;
    }
}
