package o;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewParent;
import android.view.WindowInsets;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.PathInterpolator;
import com.google.android.gms.common.R;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Objects;
import java.util.WeakHashMap;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public abstract class Oj0 {
    public static WeakHashMap a = null;
    public static Field b = null;
    public static boolean c = false;
    public static final int[] d = {R.id.accessibility_custom_action_0, R.id.accessibility_custom_action_1, R.id.accessibility_custom_action_2, R.id.accessibility_custom_action_3, R.id.accessibility_custom_action_4, R.id.accessibility_custom_action_5, R.id.accessibility_custom_action_6, R.id.accessibility_custom_action_7, R.id.accessibility_custom_action_8, R.id.accessibility_custom_action_9, R.id.accessibility_custom_action_10, R.id.accessibility_custom_action_11, R.id.accessibility_custom_action_12, R.id.accessibility_custom_action_13, R.id.accessibility_custom_action_14, R.id.accessibility_custom_action_15, R.id.accessibility_custom_action_16, R.id.accessibility_custom_action_17, R.id.accessibility_custom_action_18, R.id.accessibility_custom_action_19, R.id.accessibility_custom_action_20, R.id.accessibility_custom_action_21, R.id.accessibility_custom_action_22, R.id.accessibility_custom_action_23, R.id.accessibility_custom_action_24, R.id.accessibility_custom_action_25, R.id.accessibility_custom_action_26, R.id.accessibility_custom_action_27, R.id.accessibility_custom_action_28, R.id.accessibility_custom_action_29, R.id.accessibility_custom_action_30, R.id.accessibility_custom_action_31};
    public static final Bj0 e = new Bj0();
    public static final Dj0 f = new Dj0();

    public static C1698kk0 a(View view) {
        if (a == null) {
            a = new WeakHashMap();
        }
        C1698kk0 c1698kk0 = (C1698kk0) a.get(view);
        if (c1698kk0 != null) {
            return c1698kk0;
        }
        C1698kk0 c1698kk02 = new C1698kk0(view);
        a.put(view, c1698kk02);
        return c1698kk02;
    }

    public static void b(View view, Kl0 kl0) {
        int i = Build.VERSION.SDK_INT;
        WindowInsets windowInsetsF = kl0.f();
        if (windowInsetsF != null) {
            WindowInsets windowInsetsA = i >= 30 ? Lj0.a(view, windowInsetsF) : Ej0.a(view, windowInsetsF);
            if (windowInsetsA.equals(windowInsetsF)) {
                return;
            }
            Kl0.g(view, windowInsetsA);
        }
    }

    public static boolean c(View view, KeyEvent keyEvent) {
        if (Build.VERSION.SDK_INT >= 28) {
            return false;
        }
        ArrayList arrayList = Nj0.d;
        Nj0 nj0 = (Nj0) view.getTag(R.id.tag_unhandled_key_event_manager);
        if (nj0 == null) {
            nj0 = new Nj0();
            nj0.a = null;
            nj0.b = null;
            nj0.c = null;
            view.setTag(R.id.tag_unhandled_key_event_manager, nj0);
        }
        if (keyEvent.getAction() == 0) {
            WeakHashMap weakHashMap = nj0.a;
            if (weakHashMap != null) {
                weakHashMap.clear();
            }
            ArrayList arrayList2 = Nj0.d;
            if (!arrayList2.isEmpty()) {
                synchronized (arrayList2) {
                    try {
                        if (nj0.a == null) {
                            nj0.a = new WeakHashMap();
                        }
                        for (int size = arrayList2.size() - 1; size >= 0; size--) {
                            ArrayList arrayList3 = Nj0.d;
                            View view2 = (View) ((WeakReference) arrayList3.get(size)).get();
                            if (view2 == null) {
                                arrayList3.remove(size);
                            } else {
                                nj0.a.put(view2, Boolean.TRUE);
                                for (ViewParent parent = view2.getParent(); parent instanceof View; parent = parent.getParent()) {
                                    nj0.a.put((View) parent, Boolean.TRUE);
                                }
                            }
                        }
                    } finally {
                    }
                }
            }
        }
        View viewA = nj0.a(view);
        if (keyEvent.getAction() == 0) {
            int keyCode = keyEvent.getKeyCode();
            if (viewA != null && !KeyEvent.isModifierKey(keyCode)) {
                if (nj0.b == null) {
                    nj0.b = new SparseArray();
                }
                nj0.b.put(keyCode, new WeakReference(viewA));
            }
        }
        return viewA != null;
    }

    public static View.AccessibilityDelegate d(View view) {
        if (Build.VERSION.SDK_INT >= 29) {
            return Kj0.a(view);
        }
        if (c) {
            return null;
        }
        if (b == null) {
            try {
                Field declaredField = View.class.getDeclaredField("mAccessibilityDelegate");
                b = declaredField;
                declaredField.setAccessible(true);
            } catch (Throwable unused) {
                c = true;
                return null;
            }
        }
        try {
            Object obj = b.get(view);
            if (obj instanceof View.AccessibilityDelegate) {
                return (View.AccessibilityDelegate) obj;
            }
            return null;
        } catch (Throwable unused2) {
            c = true;
            return null;
        }
    }

    public static CharSequence e(View view) {
        Object tag;
        if (Build.VERSION.SDK_INT >= 28) {
            tag = Jj0.a(view);
        } else {
            tag = view.getTag(R.id.tag_accessibility_pane_title);
            if (!CharSequence.class.isInstance(tag)) {
                tag = null;
            }
        }
        return (CharSequence) tag;
    }

    public static ArrayList f(View view) {
        ArrayList arrayList = (ArrayList) view.getTag(R.id.tag_accessibility_actions);
        if (arrayList != null) {
            return arrayList;
        }
        ArrayList arrayList2 = new ArrayList();
        view.setTag(R.id.tag_accessibility_actions, arrayList2);
        return arrayList2;
    }

    public static String[] g(X7 x7) {
        return Build.VERSION.SDK_INT >= 31 ? Mj0.a(x7) : (String[]) x7.getTag(R.id.tag_on_receive_content_mime_types);
    }

    public static void h(View view, int i) {
        AccessibilityManager accessibilityManager = (AccessibilityManager) view.getContext().getSystemService("accessibility");
        if (accessibilityManager.isEnabled()) {
            boolean z = e(view) != null && view.isShown() && view.getWindowVisibility() == 0;
            if (view.getAccessibilityLiveRegion() != 0 || z) {
                AccessibilityEvent accessibilityEventObtain = AccessibilityEvent.obtain();
                accessibilityEventObtain.setEventType(z ? 32 : 2048);
                accessibilityEventObtain.setContentChangeTypes(i);
                if (z) {
                    accessibilityEventObtain.getText().add(e(view));
                    if (view.getImportantForAccessibility() == 0) {
                        view.setImportantForAccessibility(1);
                    }
                }
                view.sendAccessibilityEventUnchecked(accessibilityEventObtain);
                return;
            }
            if (i != 32) {
                if (view.getParent() != null) {
                    try {
                        view.getParent().notifySubtreeAccessibilityStateChanged(view, view, i);
                        return;
                    } catch (AbstractMethodError unused) {
                        view.getParent().getClass();
                        return;
                    }
                }
                return;
            }
            AccessibilityEvent accessibilityEventObtain2 = AccessibilityEvent.obtain();
            view.onInitializeAccessibilityEvent(accessibilityEventObtain2);
            accessibilityEventObtain2.setEventType(32);
            accessibilityEventObtain2.setContentChangeTypes(i);
            accessibilityEventObtain2.setSource(view);
            view.onPopulateAccessibilityEvent(accessibilityEventObtain2);
            accessibilityEventObtain2.getText().add(e(view));
            accessibilityManager.sendAccessibilityEvent(accessibilityEventObtain2);
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static C2271qm i(View view, C2271qm c2271qm) {
        if (Log.isLoggable("ViewCompat", 3)) {
            Objects.toString(c2271qm);
            view.getClass();
            view.getId();
        }
        if (Build.VERSION.SDK_INT >= 31) {
            return Mj0.b(view, c2271qm);
        }
        C1307gf0 c1307gf0 = (C1307gf0) view.getTag(R.id.tag_on_receive_content_listener);
        QT qt = e;
        if (c1307gf0 == null) {
            if (view instanceof QT) {
                qt = (QT) view;
            }
            return qt.a(c2271qm);
        }
        C2271qm c2271qmA = C1307gf0.a(view, c2271qm);
        if (c2271qmA == null) {
            return null;
        }
        if (view instanceof QT) {
            qt = (QT) view;
        }
        return qt.a(c2271qmA);
    }

    public static void j(View view, int i) {
        ArrayList arrayListF = f(view);
        for (int i2 = 0; i2 < arrayListF.size(); i2++) {
            if (((C0) arrayListF.get(i2)).a() == i) {
                arrayListF.remove(i2);
                return;
            }
        }
    }

    public static void k(View view, C0 c0, S0 s0) {
        C0 c02 = new C0(null, c0.b, null, s0, c0.c);
        View.AccessibilityDelegate accessibilityDelegateD = d(view);
        C2011o0 c2011o0 = accessibilityDelegateD == null ? null : accessibilityDelegateD instanceof C1916n0 ? ((C1916n0) accessibilityDelegateD).a : new C2011o0(accessibilityDelegateD);
        if (c2011o0 == null) {
            c2011o0 = new C2011o0();
        }
        m(view, c2011o0);
        j(view, c02.a());
        f(view).add(c02);
        h(view, 0);
    }

    public static void l(View view, Context context, int[] iArr, AttributeSet attributeSet, TypedArray typedArray, int i) {
        if (Build.VERSION.SDK_INT >= 29) {
            Kj0.b(view, context, iArr, attributeSet, typedArray, i, 0);
        }
    }

    public static void m(View view, C2011o0 c2011o0) {
        if (c2011o0 == null && (d(view) instanceof C1916n0)) {
            c2011o0 = new C2011o0();
        }
        if (view.getImportantForAccessibility() == 0) {
            view.setImportantForAccessibility(1);
        }
        view.setAccessibilityDelegate(c2011o0 == null ? null : c2011o0.b);
    }

    public static void n(View view, CharSequence charSequence) {
        new Cj0(R.id.tag_accessibility_pane_title, CharSequence.class, 8, 28, 1).f(view, charSequence);
        Dj0 dj0 = f;
        if (charSequence == null) {
            dj0.l.remove(view);
            view.removeOnAttachStateChangeListener(dj0);
            view.getViewTreeObserver().removeOnGlobalLayoutListener(dj0);
        } else {
            dj0.l.put(view, Boolean.valueOf(view.isShown() && view.getWindowVisibility() == 0));
            view.addOnAttachStateChangeListener(dj0);
            if (view.isAttachedToWindow()) {
                view.getViewTreeObserver().addOnGlobalLayoutListener(dj0);
            }
        }
    }

    public static void o(View view, AbstractC2071oh abstractC2071oh) {
        if (Build.VERSION.SDK_INT >= 30) {
            view.setWindowInsetsAnimationCallback(abstractC2071oh != null ? new C2270ql0(abstractC2071oh) : null);
            return;
        }
        PathInterpolator pathInterpolator = C2080ol0.e;
        View.OnApplyWindowInsetsListener viewOnApplyWindowInsetsListenerC1985nl0 = abstractC2071oh != null ? new ViewOnApplyWindowInsetsListenerC1985nl0(view, abstractC2071oh) : null;
        view.setTag(R.id.tag_window_insets_animation_callback, viewOnApplyWindowInsetsListenerC1985nl0);
        if (view.getTag(R.id.tag_compat_insets_dispatch) == null && view.getTag(R.id.tag_on_apply_window_listener) == null) {
            view.setOnApplyWindowInsetsListener(viewOnApplyWindowInsetsListenerC1985nl0);
        }
    }
}
