package n;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import m.AbstractC1149j;
import m.InterfaceC1156q;

/* JADX INFO: renamed from: n.j0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC1217j0 implements InterfaceC1156q {

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public static final Method f14872M;

    /* JADX INFO: renamed from: N, reason: collision with root package name */
    public static final Method f14873N;

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    public static final Method f14874O;

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public Q.b f14875A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public View f14876B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public AbstractC1149j f14877C;
    public final Handler H;

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    public Rect f14882J;

    /* JADX INFO: renamed from: K, reason: collision with root package name */
    public boolean f14883K;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public final C1239v f14884L;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final Context f14885q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public ListAdapter f14886r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public C1227o0 f14887s;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public int f14889u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public int f14890v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public boolean f14891w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public boolean f14892x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public boolean f14893y;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public int f14888t = -2;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public int f14894z = 0;
    public final RunnableC1211g0 D = new RunnableC1211g0(this, 1);

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public final ViewOnTouchListenerC1215i0 f14878E = new ViewOnTouchListenerC1215i0(this);

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final C1213h0 f14879F = new C1213h0(this);

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public final RunnableC1211g0 f14880G = new RunnableC1211g0(this, 0);

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public final Rect f14881I = new Rect();

    static {
        int i = Build.VERSION.SDK_INT;
        Class cls = Boolean.TYPE;
        if (i <= 28) {
            try {
                f14872M = PopupWindow.class.getDeclaredMethod("setClipToScreenEnabled", cls);
            } catch (NoSuchMethodException unused) {
                Log.i("ListPopupWindow", "Could not find method setClipToScreenEnabled() on PopupWindow. Oh well.");
            }
            try {
                f14874O = PopupWindow.class.getDeclaredMethod("setEpicenterBounds", Rect.class);
            } catch (NoSuchMethodException unused2) {
                Log.i("ListPopupWindow", "Could not find method setEpicenterBounds(Rect) on PopupWindow. Oh well.");
            }
        }
        if (Build.VERSION.SDK_INT <= 23) {
            try {
                f14873N = PopupWindow.class.getDeclaredMethod("getMaxAvailableHeight", View.class, Integer.TYPE, cls);
            } catch (NoSuchMethodException unused3) {
                Log.i("ListPopupWindow", "Could not find method getMaxAvailableHeight(View, int, boolean) on PopupWindow. Oh well.");
            }
        }
    }

    public AbstractC1217j0(Context context, int i) {
        int resourceId;
        this.f14885q = context;
        this.H = new Handler(context.getMainLooper());
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(null, h.a.f13015l, i, 0);
        this.f14889u = typedArrayObtainStyledAttributes.getDimensionPixelOffset(0, 0);
        int dimensionPixelOffset = typedArrayObtainStyledAttributes.getDimensionPixelOffset(1, 0);
        this.f14890v = dimensionPixelOffset;
        if (dimensionPixelOffset != 0) {
            this.f14891w = true;
        }
        typedArrayObtainStyledAttributes.recycle();
        C1239v c1239v = new C1239v(context, null, i, 0);
        TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(null, h.a.f13019p, i, 0);
        if (typedArrayObtainStyledAttributes2.hasValue(2)) {
            c1239v.setOverlapAnchor(typedArrayObtainStyledAttributes2.getBoolean(2, false));
        }
        c1239v.setBackgroundDrawable((!typedArrayObtainStyledAttributes2.hasValue(0) || (resourceId = typedArrayObtainStyledAttributes2.getResourceId(0, 0)) == 0) ? typedArrayObtainStyledAttributes2.getDrawable(0) : android.support.v4.media.session.a.l(context, resourceId));
        typedArrayObtainStyledAttributes2.recycle();
        this.f14884L = c1239v;
        c1239v.setInputMethodMode(1);
    }

    public final void a(ListAdapter listAdapter) {
        Q.b bVar = this.f14875A;
        if (bVar == null) {
            this.f14875A = new Q.b(1, this);
        } else {
            ListAdapter listAdapter2 = this.f14886r;
            if (listAdapter2 != null) {
                listAdapter2.unregisterDataSetObserver(bVar);
            }
        }
        this.f14886r = listAdapter;
        if (listAdapter != null) {
            listAdapter.registerDataSetObserver(this.f14875A);
        }
        C1227o0 c1227o0 = this.f14887s;
        if (c1227o0 != null) {
            c1227o0.setAdapter(this.f14886r);
        }
    }

    @Override // m.InterfaceC1156q
    public final void c() {
        int i;
        int iA;
        C1227o0 c1227o0;
        C1227o0 c1227o02 = this.f14887s;
        C1239v c1239v = this.f14884L;
        Context context = this.f14885q;
        if (c1227o02 == null) {
            C1227o0 c1227o03 = new C1227o0(context, !this.f14883K);
            c1227o03.setHoverListener((C1229p0) this);
            this.f14887s = c1227o03;
            c1227o03.setAdapter(this.f14886r);
            this.f14887s.setOnItemClickListener(this.f14877C);
            this.f14887s.setFocusable(true);
            this.f14887s.setFocusableInTouchMode(true);
            this.f14887s.setOnItemSelectedListener(new C1205d0(0, this));
            this.f14887s.setOnScrollListener(this.f14879F);
            c1239v.setContentView(this.f14887s);
        }
        Drawable background = c1239v.getBackground();
        Rect rect = this.f14881I;
        if (background != null) {
            background.getPadding(rect);
            int i5 = rect.top;
            i = rect.bottom + i5;
            if (!this.f14891w) {
                this.f14890v = -i5;
            }
        } else {
            rect.setEmpty();
            i = 0;
        }
        boolean z8 = c1239v.getInputMethodMode() == 2;
        View view = this.f14876B;
        int i8 = this.f14890v;
        if (Build.VERSION.SDK_INT <= 23) {
            Method method = f14873N;
            if (method != null) {
                try {
                    iA = ((Integer) method.invoke(c1239v, view, Integer.valueOf(i8), Boolean.valueOf(z8))).intValue();
                } catch (Exception unused) {
                    Log.i("ListPopupWindow", "Could not call getMaxAvailableHeightMethod(View, int, boolean) on PopupWindow. Using the public version.");
                    iA = c1239v.getMaxAvailableHeight(view, i8);
                }
            } else {
                iA = c1239v.getMaxAvailableHeight(view, i8);
            }
        } else {
            iA = AbstractC1207e0.a(c1239v, view, i8, z8);
        }
        int i9 = this.f14888t;
        int iA2 = this.f14887s.a(i9 != -2 ? i9 != -1 ? View.MeasureSpec.makeMeasureSpec(i9, 1073741824) : View.MeasureSpec.makeMeasureSpec(context.getResources().getDisplayMetrics().widthPixels - (rect.left + rect.right), 1073741824) : View.MeasureSpec.makeMeasureSpec(context.getResources().getDisplayMetrics().widthPixels - (rect.left + rect.right), Integer.MIN_VALUE), iA);
        int paddingBottom = iA2 + (iA2 > 0 ? this.f14887s.getPaddingBottom() + this.f14887s.getPaddingTop() + i : 0);
        this.f14884L.getInputMethodMode();
        c1239v.setWindowLayoutType(1002);
        if (c1239v.isShowing()) {
            View view2 = this.f14876B;
            Field field = M.J.f4065a;
            if (view2.isAttachedToWindow()) {
                int width = this.f14888t;
                if (width == -1) {
                    width = -1;
                } else if (width == -2) {
                    width = this.f14876B.getWidth();
                }
                c1239v.setOutsideTouchable(true);
                c1239v.update(this.f14876B, this.f14889u, this.f14890v, width < 0 ? -1 : width, paddingBottom >= 0 ? paddingBottom : -1);
                return;
            }
            return;
        }
        int width2 = this.f14888t;
        if (width2 == -1) {
            width2 = -1;
        } else if (width2 == -2) {
            width2 = this.f14876B.getWidth();
        }
        c1239v.setWidth(width2);
        c1239v.setHeight(paddingBottom);
        if (Build.VERSION.SDK_INT <= 28) {
            Method method2 = f14872M;
            if (method2 != null) {
                try {
                    method2.invoke(c1239v, Boolean.TRUE);
                } catch (Exception unused2) {
                    Log.i("ListPopupWindow", "Could not call setClipToScreenEnabled() on PopupWindow. Oh well.");
                }
            }
        } else {
            AbstractC1209f0.b(c1239v, true);
        }
        c1239v.setOutsideTouchable(true);
        c1239v.setTouchInterceptor(this.f14878E);
        if (this.f14893y) {
            c1239v.setOverlapAnchor(this.f14892x);
        }
        if (Build.VERSION.SDK_INT <= 28) {
            Method method3 = f14874O;
            if (method3 != null) {
                try {
                    method3.invoke(c1239v, this.f14882J);
                } catch (Exception e8) {
                    Log.e("ListPopupWindow", "Could not invoke setEpicenterBounds on PopupWindow", e8);
                }
            }
        } else {
            AbstractC1209f0.a(c1239v, this.f14882J);
        }
        c1239v.showAsDropDown(this.f14876B, this.f14889u, this.f14890v, this.f14894z);
        this.f14887s.setSelection(-1);
        if ((!this.f14883K || this.f14887s.isInTouchMode()) && (c1227o0 = this.f14887s) != null) {
            c1227o0.setListSelectionHidden(true);
            c1227o0.requestLayout();
        }
        if (this.f14883K) {
            return;
        }
        this.H.post(this.f14880G);
    }

    @Override // m.InterfaceC1156q
    public final void dismiss() {
        C1239v c1239v = this.f14884L;
        c1239v.dismiss();
        c1239v.setContentView(null);
        this.f14887s = null;
        this.H.removeCallbacks(this.D);
    }

    @Override // m.InterfaceC1156q
    public final boolean h() {
        return this.f14884L.isShowing();
    }

    @Override // m.InterfaceC1156q
    public final ListView i() {
        return this.f14887s;
    }
}
