package a4;

import a4.b;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import androidx.collection.u0;
import androidx.core.view.s0;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.util.ArrayList;
import java.util.List;
import t3.h;
import t3.i;
import t3.j;

/* loaded from: classes.dex */
public abstract class a extends androidx.core.view.a {

    /* renamed from: n, reason: collision with root package name */
    private static final Rect f144n = new Rect(Api.BaseClientBuilder.API_PRIORITY_OTHER, Api.BaseClientBuilder.API_PRIORITY_OTHER, Integer.MIN_VALUE, Integer.MIN_VALUE);

    /* renamed from: o, reason: collision with root package name */
    private static final b.a f145o = new C0007a();

    /* renamed from: p, reason: collision with root package name */
    private static final b.InterfaceC0008b f146p = new b();

    /* renamed from: h, reason: collision with root package name */
    private final AccessibilityManager f151h;

    /* renamed from: i, reason: collision with root package name */
    private final View f152i;

    /* renamed from: j, reason: collision with root package name */
    private c f153j;

    /* renamed from: d, reason: collision with root package name */
    private final Rect f147d = new Rect();

    /* renamed from: e, reason: collision with root package name */
    private final Rect f148e = new Rect();

    /* renamed from: f, reason: collision with root package name */
    private final Rect f149f = new Rect();

    /* renamed from: g, reason: collision with root package name */
    private final int[] f150g = new int[2];

    /* renamed from: k, reason: collision with root package name */
    int f154k = Integer.MIN_VALUE;

    /* renamed from: l, reason: collision with root package name */
    int f155l = Integer.MIN_VALUE;

    /* renamed from: m, reason: collision with root package name */
    private int f156m = Integer.MIN_VALUE;

    /* renamed from: a4.a$a, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    class C0007a implements b.a {
        C0007a() {
        }

        @Override // a4.b.a
        /* renamed from: b, reason: merged with bridge method [inline-methods] */
        public void a(h hVar, Rect rect) {
            hVar.k(rect);
        }
    }

    /* loaded from: classes.dex */
    class b implements b.InterfaceC0008b {
        b() {
        }

        @Override // a4.b.InterfaceC0008b
        /* renamed from: c, reason: merged with bridge method [inline-methods] */
        public h a(u0 u0Var, int i10) {
            return (h) u0Var.s(i10);
        }

        @Override // a4.b.InterfaceC0008b
        /* renamed from: d, reason: merged with bridge method [inline-methods] */
        public int b(u0 u0Var) {
            return u0Var.q();
        }
    }

    /* loaded from: classes.dex */
    private class c extends i {
        c() {
        }

        @Override // t3.i
        public h b(int i10) {
            return h.W(a.this.H(i10));
        }

        @Override // t3.i
        public h d(int i10) {
            int i11 = i10 == 2 ? a.this.f154k : a.this.f155l;
            if (i11 == Integer.MIN_VALUE) {
                return null;
            }
            return b(i11);
        }

        @Override // t3.i
        public boolean f(int i10, int i11, Bundle bundle) {
            return a.this.P(i10, i11, bundle);
        }
    }

    public a(View view) {
        if (view == null) {
            throw new IllegalArgumentException("View may not be null");
        }
        this.f152i = view;
        this.f151h = (AccessibilityManager) view.getContext().getSystemService("accessibility");
        view.setFocusable(true);
        if (s0.x(view) == 0) {
            s0.x0(view, 1);
        }
    }

    private static Rect D(View view, int i10, Rect rect) {
        int width = view.getWidth();
        int height = view.getHeight();
        if (i10 == 17) {
            rect.set(width, 0, width, height);
        } else if (i10 == 33) {
            rect.set(0, height, width, height);
        } else if (i10 == 66) {
            rect.set(-1, 0, -1, height);
        } else {
            if (i10 != 130) {
                throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
            }
            rect.set(0, -1, width, -1);
        }
        return rect;
    }

    private boolean E(Rect rect) {
        if (rect == null || rect.isEmpty() || this.f152i.getWindowVisibility() != 0) {
            return false;
        }
        Object parent = this.f152i.getParent();
        while (parent instanceof View) {
            View view = (View) parent;
            if (view.getAlpha() <= BitmapDescriptorFactory.HUE_RED || view.getVisibility() != 0) {
                return false;
            }
            parent = view.getParent();
        }
        return parent != null;
    }

    private static int F(int i10) {
        if (i10 == 19) {
            return 33;
        }
        if (i10 != 21) {
            return i10 != 22 ? 130 : 66;
        }
        return 17;
    }

    private boolean G(int i10, Rect rect) {
        h hVar;
        u0 y10 = y();
        int i11 = this.f155l;
        h hVar2 = i11 == Integer.MIN_VALUE ? null : (h) y10.h(i11);
        if (i10 == 1 || i10 == 2) {
            hVar = (h) a4.b.d(y10, f146p, f145o, hVar2, i10, s0.z(this.f152i) == 1, false);
        } else {
            if (i10 != 17 && i10 != 33 && i10 != 66 && i10 != 130) {
                throw new IllegalArgumentException("direction must be one of {FOCUS_FORWARD, FOCUS_BACKWARD, FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
            }
            Rect rect2 = new Rect();
            int i12 = this.f155l;
            if (i12 != Integer.MIN_VALUE) {
                z(i12, rect2);
            } else if (rect != null) {
                rect2.set(rect);
            } else {
                D(this.f152i, i10, rect2);
            }
            hVar = (h) a4.b.c(y10, f146p, f145o, hVar2, rect2, i10);
        }
        return T(hVar != null ? y10.l(y10.j(hVar)) : Integer.MIN_VALUE);
    }

    private boolean Q(int i10, int i11, Bundle bundle) {
        return i11 != 1 ? i11 != 2 ? i11 != 64 ? i11 != 128 ? J(i10, i11, bundle) : n(i10) : S(i10) : o(i10) : T(i10);
    }

    private boolean R(int i10, Bundle bundle) {
        return s0.b0(this.f152i, i10, bundle);
    }

    private boolean S(int i10) {
        int i11;
        if (!this.f151h.isEnabled() || !this.f151h.isTouchExplorationEnabled() || (i11 = this.f154k) == i10) {
            return false;
        }
        if (i11 != Integer.MIN_VALUE) {
            n(i11);
        }
        this.f154k = i10;
        this.f152i.invalidate();
        U(i10, 32768);
        return true;
    }

    private void V(int i10) {
        int i11 = this.f156m;
        if (i11 == i10) {
            return;
        }
        this.f156m = i10;
        U(i10, 128);
        U(i11, 256);
    }

    private boolean n(int i10) {
        if (this.f154k != i10) {
            return false;
        }
        this.f154k = Integer.MIN_VALUE;
        this.f152i.invalidate();
        U(i10, 65536);
        return true;
    }

    private boolean p() {
        int i10 = this.f155l;
        return i10 != Integer.MIN_VALUE && J(i10, 16, null);
    }

    private AccessibilityEvent q(int i10, int i11) {
        return i10 != -1 ? r(i10, i11) : s(i11);
    }

    private AccessibilityEvent r(int i10, int i11) {
        AccessibilityEvent obtain = AccessibilityEvent.obtain(i11);
        h H = H(i10);
        obtain.getText().add(H.y());
        obtain.setContentDescription(H.r());
        obtain.setScrollable(H.P());
        obtain.setPassword(H.O());
        obtain.setEnabled(H.I());
        obtain.setChecked(H.F());
        L(i10, obtain);
        if (obtain.getText().isEmpty() && obtain.getContentDescription() == null) {
            throw new RuntimeException("Callbacks must add text or a content description in populateEventForVirtualViewId()");
        }
        obtain.setClassName(H.o());
        j.c(obtain, this.f152i, i10);
        obtain.setPackageName(this.f152i.getContext().getPackageName());
        return obtain;
    }

    private AccessibilityEvent s(int i10) {
        AccessibilityEvent obtain = AccessibilityEvent.obtain(i10);
        this.f152i.onInitializeAccessibilityEvent(obtain);
        return obtain;
    }

    private h t(int i10) {
        h U = h.U();
        U.o0(true);
        U.q0(true);
        U.g0("android.view.View");
        Rect rect = f144n;
        U.c0(rect);
        U.d0(rect);
        U.B0(this.f152i);
        N(i10, U);
        if (U.y() == null && U.r() == null) {
            throw new RuntimeException("Callbacks must add text or a content description in populateNodeForVirtualViewId()");
        }
        U.k(this.f148e);
        if (this.f148e.equals(rect)) {
            throw new RuntimeException("Callbacks must set parent bounds in populateNodeForVirtualViewId()");
        }
        int i11 = U.i();
        if ((i11 & 64) != 0) {
            throw new RuntimeException("Callbacks must not add ACTION_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()");
        }
        if ((i11 & 128) != 0) {
            throw new RuntimeException("Callbacks must not add ACTION_CLEAR_ACCESSIBILITY_FOCUS in populateNodeForVirtualViewId()");
        }
        U.z0(this.f152i.getContext().getPackageName());
        U.K0(this.f152i, i10);
        if (this.f154k == i10) {
            U.a0(true);
            U.a(128);
        } else {
            U.a0(false);
            U.a(64);
        }
        boolean z10 = this.f155l == i10;
        if (z10) {
            U.a(2);
        } else if (U.J()) {
            U.a(1);
        }
        U.r0(z10);
        this.f152i.getLocationOnScreen(this.f150g);
        U.l(this.f147d);
        if (this.f147d.equals(rect)) {
            U.k(this.f147d);
            if (U.f36128b != -1) {
                h U2 = h.U();
                for (int i12 = U.f36128b; i12 != -1; i12 = U2.f36128b) {
                    U2.C0(this.f152i, -1);
                    U2.c0(f144n);
                    N(i12, U2);
                    U2.k(this.f148e);
                    Rect rect2 = this.f147d;
                    Rect rect3 = this.f148e;
                    rect2.offset(rect3.left, rect3.top);
                }
                U2.Y();
            }
            this.f147d.offset(this.f150g[0] - this.f152i.getScrollX(), this.f150g[1] - this.f152i.getScrollY());
        }
        if (this.f152i.getLocalVisibleRect(this.f149f)) {
            this.f149f.offset(this.f150g[0] - this.f152i.getScrollX(), this.f150g[1] - this.f152i.getScrollY());
            if (this.f147d.intersect(this.f149f)) {
                U.d0(this.f147d);
                if (E(this.f147d)) {
                    U.T0(true);
                }
            }
        }
        return U;
    }

    private h u() {
        h V = h.V(this.f152i);
        s0.Z(this.f152i, V);
        ArrayList arrayList = new ArrayList();
        C(arrayList);
        if (V.n() > 0 && arrayList.size() > 0) {
            throw new RuntimeException("Views cannot have both real and virtual children");
        }
        int size = arrayList.size();
        for (int i10 = 0; i10 < size; i10++) {
            V.d(this.f152i, ((Integer) arrayList.get(i10)).intValue());
        }
        return V;
    }

    private u0 y() {
        ArrayList arrayList = new ArrayList();
        C(arrayList);
        u0 u0Var = new u0();
        for (int i10 = 0; i10 < arrayList.size(); i10++) {
            u0Var.n(((Integer) arrayList.get(i10)).intValue(), t(((Integer) arrayList.get(i10)).intValue()));
        }
        return u0Var;
    }

    private void z(int i10, Rect rect) {
        H(i10).k(rect);
    }

    public final int A() {
        return this.f155l;
    }

    protected abstract int B(float f10, float f11);

    protected abstract void C(List list);

    h H(int i10) {
        return i10 == -1 ? u() : t(i10);
    }

    public final void I(boolean z10, int i10, Rect rect) {
        int i11 = this.f155l;
        if (i11 != Integer.MIN_VALUE) {
            o(i11);
        }
        if (z10) {
            G(i10, rect);
        }
    }

    protected abstract boolean J(int i10, int i11, Bundle bundle);

    protected void K(AccessibilityEvent accessibilityEvent) {
    }

    protected void L(int i10, AccessibilityEvent accessibilityEvent) {
    }

    protected abstract void M(h hVar);

    protected abstract void N(int i10, h hVar);

    protected abstract void O(int i10, boolean z10);

    boolean P(int i10, int i11, Bundle bundle) {
        return i10 != -1 ? Q(i10, i11, bundle) : R(i11, bundle);
    }

    public final boolean T(int i10) {
        int i11;
        if ((!this.f152i.isFocused() && !this.f152i.requestFocus()) || (i11 = this.f155l) == i10) {
            return false;
        }
        if (i11 != Integer.MIN_VALUE) {
            o(i11);
        }
        if (i10 == Integer.MIN_VALUE) {
            return false;
        }
        this.f155l = i10;
        O(i10, true);
        U(i10, 8);
        return true;
    }

    public final boolean U(int i10, int i11) {
        ViewParent parent;
        if (i10 == Integer.MIN_VALUE || !this.f151h.isEnabled() || (parent = this.f152i.getParent()) == null) {
            return false;
        }
        return parent.requestSendAccessibilityEvent(this.f152i, q(i10, i11));
    }

    @Override // androidx.core.view.a
    public i b(View view) {
        if (this.f153j == null) {
            this.f153j = new c();
        }
        return this.f153j;
    }

    @Override // androidx.core.view.a
    public void f(View view, AccessibilityEvent accessibilityEvent) {
        super.f(view, accessibilityEvent);
        K(accessibilityEvent);
    }

    @Override // androidx.core.view.a
    public void g(View view, h hVar) {
        super.g(view, hVar);
        M(hVar);
    }

    public final boolean o(int i10) {
        if (this.f155l != i10) {
            return false;
        }
        this.f155l = Integer.MIN_VALUE;
        O(i10, false);
        U(i10, 8);
        return true;
    }

    public final boolean v(MotionEvent motionEvent) {
        if (!this.f151h.isEnabled() || !this.f151h.isTouchExplorationEnabled()) {
            return false;
        }
        int action = motionEvent.getAction();
        if (action == 7 || action == 9) {
            int B = B(motionEvent.getX(), motionEvent.getY());
            V(B);
            return B != Integer.MIN_VALUE;
        }
        if (action != 10 || this.f156m == Integer.MIN_VALUE) {
            return false;
        }
        V(Integer.MIN_VALUE);
        return true;
    }

    public final boolean w(KeyEvent keyEvent) {
        int i10 = 0;
        if (keyEvent.getAction() == 1) {
            return false;
        }
        int keyCode = keyEvent.getKeyCode();
        if (keyCode == 61) {
            if (keyEvent.hasNoModifiers()) {
                return G(2, null);
            }
            if (keyEvent.hasModifiers(1)) {
                return G(1, null);
            }
            return false;
        }
        if (keyCode != 66) {
            switch (keyCode) {
                case 19:
                case 20:
                case 21:
                case 22:
                    if (!keyEvent.hasNoModifiers()) {
                        return false;
                    }
                    int F = F(keyCode);
                    int repeatCount = keyEvent.getRepeatCount() + 1;
                    boolean z10 = false;
                    while (i10 < repeatCount && G(F, null)) {
                        i10++;
                        z10 = true;
                    }
                    return z10;
                case 23:
                    break;
                default:
                    return false;
            }
        }
        if (!keyEvent.hasNoModifiers() || keyEvent.getRepeatCount() != 0) {
            return false;
        }
        p();
        return true;
    }

    public final int x() {
        return this.f154k;
    }
}
