package m;

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 e4.AbstractC0566j;
import h.AbstractC0617a;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/* JADX INFO: renamed from: m.m0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0870m0 implements l.q {

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

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

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final Handler f9198B;

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

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

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final C0890x f9202F;

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public C0879r0 f9205m;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f9207o;
    public int p;
    public boolean q;

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

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

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public T.b f9211u;

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

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public l.j f9213w;

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

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public int f9210t = 0;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final RunnableC0864j0 f9214x = new RunnableC0864j0(this, 1);

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final ViewOnTouchListenerC0868l0 f9215y = new ViewOnTouchListenerC0868l0(this);

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final C0866k0 f9216z = new C0866k0(this);

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final RunnableC0864j0 f9197A = new RunnableC0864j0(this, 0);

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

    static {
        if (Build.VERSION.SDK_INT <= 28) {
            try {
                f9195G = PopupWindow.class.getDeclaredMethod("setClipToScreenEnabled", Boolean.TYPE);
            } catch (NoSuchMethodException unused) {
                Log.i("ListPopupWindow", "Could not find method setClipToScreenEnabled() on PopupWindow. Oh well.");
            }
            try {
                f9196H = PopupWindow.class.getDeclaredMethod("setEpicenterBounds", Rect.class);
            } catch (NoSuchMethodException unused2) {
                Log.i("ListPopupWindow", "Could not find method setEpicenterBounds(Rect) on PopupWindow. Oh well.");
            }
        }
    }

    public AbstractC0870m0(Context context, int i) {
        int resourceId;
        this.f9203k = context;
        this.f9198B = new Handler(context.getMainLooper());
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(null, AbstractC0617a.f6479l, i, 0);
        this.f9207o = typedArrayObtainStyledAttributes.getDimensionPixelOffset(0, 0);
        int dimensionPixelOffset = typedArrayObtainStyledAttributes.getDimensionPixelOffset(1, 0);
        this.p = dimensionPixelOffset;
        if (dimensionPixelOffset != 0) {
            this.q = true;
        }
        typedArrayObtainStyledAttributes.recycle();
        C0890x c0890x = new C0890x(context, null, i, 0);
        TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(null, AbstractC0617a.p, i, 0);
        if (typedArrayObtainStyledAttributes2.hasValue(2)) {
            c0890x.setOverlapAnchor(typedArrayObtainStyledAttributes2.getBoolean(2, false));
        }
        c0890x.setBackgroundDrawable((!typedArrayObtainStyledAttributes2.hasValue(0) || (resourceId = typedArrayObtainStyledAttributes2.getResourceId(0, 0)) == 0) ? typedArrayObtainStyledAttributes2.getDrawable(0) : AbstractC0566j.j(context, resourceId));
        typedArrayObtainStyledAttributes2.recycle();
        this.f9202F = c0890x;
        c0890x.setInputMethodMode(1);
    }

    public final void a(ListAdapter listAdapter) {
        T.b bVar = this.f9211u;
        if (bVar == null) {
            this.f9211u = new T.b(1, this);
        } else {
            ListAdapter listAdapter2 = this.f9204l;
            if (listAdapter2 != null) {
                listAdapter2.unregisterDataSetObserver(bVar);
            }
        }
        this.f9204l = listAdapter;
        if (listAdapter != null) {
            listAdapter.registerDataSetObserver(this.f9211u);
        }
        C0879r0 c0879r0 = this.f9205m;
        if (c0879r0 != null) {
            c0879r0.setAdapter(this.f9204l);
        }
    }

    @Override // l.q
    public final ListView c() {
        return this.f9205m;
    }

    @Override // l.q
    public final void dismiss() {
        C0890x c0890x = this.f9202F;
        c0890x.dismiss();
        c0890x.setContentView(null);
        this.f9205m = null;
        this.f9198B.removeCallbacks(this.f9214x);
    }

    @Override // l.q
    public final boolean i() {
        return this.f9202F.isShowing();
    }

    @Override // l.q
    public final void show() {
        int i;
        C0879r0 c0879r0;
        C0879r0 c0879r02 = this.f9205m;
        C0890x c0890x = this.f9202F;
        Context context = this.f9203k;
        if (c0879r02 == null) {
            C0879r0 c0879r03 = new C0879r0(context, !this.f9201E);
            c0879r03.setHoverListener((C0881s0) this);
            this.f9205m = c0879r03;
            c0879r03.setAdapter(this.f9204l);
            this.f9205m.setOnItemClickListener(this.f9213w);
            this.f9205m.setFocusable(true);
            this.f9205m.setFocusableInTouchMode(true);
            this.f9205m.setOnItemSelectedListener(new C0858g0(0, this));
            this.f9205m.setOnScrollListener(this.f9216z);
            c0890x.setContentView(this.f9205m);
        }
        Drawable background = c0890x.getBackground();
        Rect rect = this.f9199C;
        if (background != null) {
            background.getPadding(rect);
            int i5 = rect.top;
            i = rect.bottom + i5;
            if (!this.q) {
                this.p = -i5;
            }
        } else {
            rect.setEmpty();
            i = 0;
        }
        int iA = AbstractC0860h0.a(c0890x, this.f9212v, this.p, c0890x.getInputMethodMode() == 2);
        int i6 = this.f9206n;
        int iA2 = this.f9205m.a(i6 != -2 ? i6 != -1 ? View.MeasureSpec.makeMeasureSpec(i6, 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.f9205m.getPaddingBottom() + this.f9205m.getPaddingTop() + i : 0);
        this.f9202F.getInputMethodMode();
        c0890x.setWindowLayoutType(1002);
        if (c0890x.isShowing()) {
            View view = this.f9212v;
            Field field = P.Q.f2392a;
            if (view.isAttachedToWindow()) {
                int width = this.f9206n;
                if (width == -1) {
                    width = -1;
                } else if (width == -2) {
                    width = this.f9212v.getWidth();
                }
                c0890x.setOutsideTouchable(true);
                c0890x.update(this.f9212v, this.f9207o, this.p, width < 0 ? -1 : width, paddingBottom < 0 ? -1 : paddingBottom);
                return;
            }
            return;
        }
        int width2 = this.f9206n;
        if (width2 == -1) {
            width2 = -1;
        } else if (width2 == -2) {
            width2 = this.f9212v.getWidth();
        }
        c0890x.setWidth(width2);
        c0890x.setHeight(paddingBottom);
        if (Build.VERSION.SDK_INT <= 28) {
            Method method = f9195G;
            if (method != null) {
                try {
                    method.invoke(c0890x, Boolean.TRUE);
                } catch (Exception unused) {
                    Log.i("ListPopupWindow", "Could not call setClipToScreenEnabled() on PopupWindow. Oh well.");
                }
            }
        } else {
            AbstractC0862i0.b(c0890x, true);
        }
        c0890x.setOutsideTouchable(true);
        c0890x.setTouchInterceptor(this.f9215y);
        if (this.f9209s) {
            c0890x.setOverlapAnchor(this.f9208r);
        }
        if (Build.VERSION.SDK_INT <= 28) {
            Method method2 = f9196H;
            if (method2 != null) {
                try {
                    method2.invoke(c0890x, this.f9200D);
                } catch (Exception e2) {
                    Log.e("ListPopupWindow", "Could not invoke setEpicenterBounds on PopupWindow", e2);
                }
            }
        } else {
            AbstractC0862i0.a(c0890x, this.f9200D);
        }
        c0890x.showAsDropDown(this.f9212v, this.f9207o, this.p, this.f9210t);
        this.f9205m.setSelection(-1);
        if ((!this.f9201E || this.f9205m.isInTouchMode()) && (c0879r0 = this.f9205m) != null) {
            c0879r0.setListSelectionHidden(true);
            c0879r0.requestLayout();
        }
        if (this.f9201E) {
            return;
        }
        this.f9198B.post(this.f9197A);
    }
}
