package ῲ.ῲ.㴹;

import android.content.Context;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import androidx.appcompat.R$styleable;
import java.lang.reflect.Method;
import ඓ.K.K.K.C1293;
import ῲ.ᨨ.ᨨ.C1729;
import ῲ.ῲ.ඓ.㳳.AbstractC1903;
import K.K.K.ʬ.C2369;

/* renamed from: ῲ.ῲ.㴹.Ԛ  reason: contains not printable characters */
/* compiled from: ListPopupWindow */
public class C1995 implements AbstractC1903 {

    /* renamed from: В  reason: contains not printable characters */
    public static Method f6768 = PopupWindow.class.getDeclaredMethod("setEpicenterBounds", Rect.class);

    /* renamed from: ሽ  reason: contains not printable characters */
    public static Method f6769;

    /* renamed from: ᑾ  reason: contains not printable characters */
    public static Method f6770 = PopupWindow.class.getDeclaredMethod("getMaxAvailableHeight", View.class, Integer.TYPE, Boolean.TYPE);

    /* renamed from: ʬ  reason: contains not printable characters */
    public ListAdapter f6771;

    /* renamed from: Ԕ  reason: contains not printable characters */
    public boolean f6772 = false;

    /* renamed from: Ԛ  reason: contains not printable characters */
    public Drawable f6773;

    /* renamed from: ؿ  reason: contains not printable characters */
    public int f6774 = Integer.MAX_VALUE;

    /* renamed from: ݜ  reason: contains not printable characters */
    public DataSetObserver f6775;

    /* renamed from: ඓ  reason: contains not printable characters */
    public int f6776 = -2;

    /* renamed from: ᆯ  reason: contains not printable characters */
    public boolean f6777;

    /* renamed from: ᑓ  reason: contains not printable characters */
    public final View$OnTouchListenerC1997 f6778 = new View$OnTouchListenerC1997();

    /* renamed from: ᓆ  reason: contains not printable characters */
    public AdapterView.OnItemSelectedListener f6779;

    /* renamed from: ᓣ  reason: contains not printable characters */
    public View f6780;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public boolean f6781;

    /* renamed from: ᝁ  reason: contains not printable characters */
    public Rect f6782;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public int f6783 = 1002;

    /* renamed from: ῲ  reason: contains not printable characters */
    public Context f6784;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public int f6785;

    /* renamed from: ⶍ  reason: contains not printable characters */
    public PopupWindow f6786;

    /* renamed from: ゎ  reason: contains not printable characters */
    public final C2001 f6787 = new C2001();

    /* renamed from: ト  reason: contains not printable characters */
    public final RunnableC1998 f6788 = new RunnableC1998();

    /* renamed from: 㑃  reason: contains not printable characters */
    public boolean f6789;

    /* renamed from: 㗗  reason: contains not printable characters */
    public boolean f6790 = false;

    /* renamed from: 㗽  reason: contains not printable characters */
    public int f6791 = 0;

    /* renamed from: 㮔  reason: contains not printable characters */
    public final Handler f6792;

    /* renamed from: 㳳  reason: contains not printable characters */
    public boolean f6793;

    /* renamed from: 㴪  reason: contains not printable characters */
    public final RunnableC2000 f6794 = new RunnableC2000();

    /* renamed from: 㴹  reason: contains not printable characters */
    public int f6795 = -2;

    /* renamed from: 㶋  reason: contains not printable characters */
    public AdapterView.OnItemClickListener f6796;

    /* renamed from: 㸾  reason: contains not printable characters */
    public C2035 f6797;

    /* renamed from: 㿎  reason: contains not printable characters */
    public int f6798;

    /* renamed from: 䀟  reason: contains not printable characters */
    public View f6799;

    /* renamed from: 䁗  reason: contains not printable characters */
    public int f6800 = 0;

    /* renamed from: 䃖  reason: contains not printable characters */
    public final Rect f6801 = new Rect();

    /* renamed from: ῲ.ῲ.㴹.Ԛ$ʬ  reason: contains not printable characters */
    /* compiled from: ListPopupWindow */
    public class C1996 extends DataSetObserver {
        public C1996() {
        }

        public void onChanged() {
            if (C1995.this.m5180()) {
                C1995.this.show();
            }
        }

        public void onInvalidated() {
            C1995.this.dismiss();
        }
    }

    /* renamed from: ῲ.ῲ.㴹.Ԛ$ඓ  reason: contains not printable characters */
    /* compiled from: ListPopupWindow */
    public class View$OnTouchListenerC1997 implements View.OnTouchListener {
        public View$OnTouchListenerC1997() {
        }

        public boolean onTouch(View view, MotionEvent motionEvent) {
            PopupWindow popupWindow;
            int action = motionEvent.getAction();
            int x = (int) motionEvent.getX();
            int y = (int) motionEvent.getY();
            if (action == 0 && (popupWindow = C1995.this.f6786) != null && popupWindow.isShowing() && x >= 0 && x < C1995.this.f6786.getWidth() && y >= 0 && y < C1995.this.f6786.getHeight()) {
                C1995 r3 = C1995.this;
                r3.f6792.postDelayed(r3.f6794, 250);
                return false;
            } else if (action != 1) {
                return false;
            } else {
                C1995 r32 = C1995.this;
                r32.f6792.removeCallbacks(r32.f6794);
                return false;
            }
        }
    }

    /* renamed from: ῲ.ῲ.㴹.Ԛ$ῲ  reason: contains not printable characters */
    /* compiled from: ListPopupWindow */
    public class RunnableC1998 implements Runnable {
        public RunnableC1998() {
        }

        public void run() {
            C1995.this.m5172();
        }
    }

    /* renamed from: ῲ.ῲ.㴹.Ԛ$K  reason: contains not printable characters */
    /* compiled from: ListPopupWindow */
    public class C1999 extends AbstractView$OnTouchListenerC2051 {
        public C1999(View view) {
            super(view);
        }

        @Override // ῲ.ῲ.㴹.AbstractView$OnTouchListenerC2051
        /* renamed from: ῲ  reason: contains not printable characters */
        public AbstractC1903 m5192() {
            return C1995.this;
        }
    }

    /* renamed from: ῲ.ῲ.㴹.Ԛ$㴹  reason: contains not printable characters */
    /* compiled from: ListPopupWindow */
    public class RunnableC2000 implements Runnable {
        public RunnableC2000() {
        }

        public void run() {
            C2035 r0 = C1995.this.f6797;
            if (r0 != null && C1729.m4498(r0) && C1995.this.f6797.getCount() > C1995.this.f6797.getChildCount()) {
                int childCount = C1995.this.f6797.getChildCount();
                C1995 r1 = C1995.this;
                if (childCount <= r1.f6774) {
                    r1.f6786.setInputMethodMode(2);
                    C1995.this.show();
                }
            }
        }
    }

    /* renamed from: ῲ.ῲ.㴹.Ԛ$㸾  reason: contains not printable characters */
    /* compiled from: ListPopupWindow */
    public class C2001 implements AbsListView.OnScrollListener {
        public C2001() {
        }

        public void onScroll(AbsListView absListView, int i, int i2, int i3) {
        }

        public void onScrollStateChanged(AbsListView absListView, int i) {
            if (i == 1 && !C1995.this.m5162() && C1995.this.f6786.getContentView() != null) {
                C1995 r1 = C1995.this;
                r1.f6792.removeCallbacks(r1.f6794);
                C1995.this.f6794.run();
            }
        }
    }

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

    public C1995(Context context, AttributeSet attributeSet, int i, int i2) {
        this.f6784 = context;
        this.f6792 = new Handler(context.getMainLooper());
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R$styleable.ListPopupWindow, i, i2);
        this.f6785 = obtainStyledAttributes.getDimensionPixelOffset(R$styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0);
        this.f6798 = obtainStyledAttributes.getDimensionPixelOffset(R$styleable.ListPopupWindow_android_dropDownVerticalOffset, 0);
        if (this.f6798 != 0) {
            this.f6793 = true;
        }
        obtainStyledAttributes.recycle();
        this.f6786 = new C2050(context, attributeSet, i, i2);
        this.f6786.setInputMethodMode(1);
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1903
    public void dismiss() {
        this.f6786.dismiss();
        View view = this.f6780;
        if (view != null) {
            ViewParent parent = view.getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(this.f6780);
            }
        }
        this.f6786.setContentView(null);
        this.f6797 = null;
        this.f6792.removeCallbacks(this.f6794);
    }

    public void setBackgroundDrawable(Drawable drawable) {
        this.f6786.setBackgroundDrawable(drawable);
    }

    public void setOnDismissListener(PopupWindow.OnDismissListener onDismissListener) {
        this.f6786.setOnDismissListener(onDismissListener);
    }

    public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
        this.f6796 = onItemClickListener;
    }

    public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener onItemSelectedListener) {
        this.f6779 = onItemSelectedListener;
    }

    /* JADX DEBUG: Multi-variable search result rejected for r8v25, resolved type: android.widget.LinearLayout */
    /* JADX WARN: Multi-variable type inference failed */
    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1903
    public void show() {
        int i;
        int i2;
        int i3;
        int i4;
        int i5;
        int i6;
        boolean z = true;
        if (this.f6797 == null) {
            Context context = this.f6784;
            new RunnableC2046(this);
            this.f6797 = m5175(context, !this.f6777);
            Drawable drawable = this.f6773;
            if (drawable != null) {
                this.f6797.setSelector(drawable);
            }
            this.f6797.setAdapter(this.f6771);
            this.f6797.setOnItemClickListener(this.f6796);
            this.f6797.setFocusable(true);
            this.f6797.setFocusableInTouchMode(true);
            this.f6797.setOnItemSelectedListener(new C2020(this));
            this.f6797.setOnScrollListener(this.f6787);
            AdapterView.OnItemSelectedListener onItemSelectedListener = this.f6779;
            if (onItemSelectedListener != null) {
                this.f6797.setOnItemSelectedListener(onItemSelectedListener);
            }
            C2035 r6 = this.f6797;
            View view = this.f6780;
            if (view != null) {
                LinearLayout linearLayout = new LinearLayout(context);
                linearLayout.setOrientation(1);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, 0, 1.0f);
                int i7 = this.f6791;
                if (i7 == 0) {
                    linearLayout.addView(view);
                    linearLayout.addView(r6, layoutParams);
                } else if (i7 != 1) {
                    StringBuilder r0 = C1293.m3416("Invalid hint position ");
                    r0.append(this.f6791);
                    Log.e("ListPopupWindow", r0.toString());
                } else {
                    linearLayout.addView(r6, layoutParams);
                    linearLayout.addView(view);
                }
                int i8 = this.f6795;
                if (i8 >= 0) {
                    i6 = Integer.MIN_VALUE;
                } else {
                    i8 = 0;
                    i6 = 0;
                }
                view.measure(View.MeasureSpec.makeMeasureSpec(i8, i6), 0);
                LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) view.getLayoutParams();
                i = view.getMeasuredHeight() + layoutParams2.topMargin + layoutParams2.bottomMargin;
                r6 = linearLayout;
            } else {
                i = 0;
            }
            this.f6786.setContentView(r6);
        } else {
            ViewGroup viewGroup = (ViewGroup) this.f6786.getContentView();
            View view2 = this.f6780;
            if (view2 != null) {
                LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) view2.getLayoutParams();
                i = view2.getMeasuredHeight() + layoutParams3.topMargin + layoutParams3.bottomMargin;
            } else {
                i = 0;
            }
        }
        Drawable background = this.f6786.getBackground();
        if (background != null) {
            background.getPadding(this.f6801);
            Rect rect = this.f6801;
            int i9 = rect.top;
            i2 = rect.bottom + i9;
            if (!this.f6793) {
                this.f6798 = -i9;
            }
        } else {
            this.f6801.setEmpty();
            i2 = 0;
        }
        boolean z2 = this.f6786.getInputMethodMode() == 2;
        View r9 = m5189();
        int i10 = this.f6798;
        if (Build.VERSION.SDK_INT <= 23) {
            Method method = f6770;
            if (method != null) {
                try {
                    i3 = ((Integer) method.invoke(this.f6786, r9, Integer.valueOf(i10), Boolean.valueOf(z2))).intValue();
                } catch (Exception unused) {
                    Log.i("ListPopupWindow", "Could not call getMaxAvailableHeightMethod(View, int, boolean) on PopupWindow. Using the public version.");
                }
            }
            i3 = this.f6786.getMaxAvailableHeight(r9, i10);
        } else {
            i3 = this.f6786.getMaxAvailableHeight(r9, i10, z2);
        }
        if (this.f6772 || this.f6776 == -1) {
            i4 = i3 + i2;
        } else {
            int i11 = this.f6795;
            if (i11 == -2) {
                int i12 = this.f6784.getResources().getDisplayMetrics().widthPixels;
                Rect rect2 = this.f6801;
                i5 = View.MeasureSpec.makeMeasureSpec(i12 - (rect2.left + rect2.right), Integer.MIN_VALUE);
            } else if (i11 != -1) {
                i5 = View.MeasureSpec.makeMeasureSpec(i11, 1073741824);
            } else {
                int i13 = this.f6784.getResources().getDisplayMetrics().widthPixels;
                Rect rect3 = this.f6801;
                i5 = View.MeasureSpec.makeMeasureSpec(i13 - (rect3.left + rect3.right), 1073741824);
            }
            int r1 = this.f6797.m5276(i5, i3 - i, -1);
            if (r1 > 0) {
                i += this.f6797.getPaddingBottom() + this.f6797.getPaddingTop() + i2;
            }
            i4 = r1 + i;
        }
        boolean r02 = m5162();
        C2369.m6332(this.f6786, this.f6783);
        if (!this.f6786.isShowing()) {
            int i14 = this.f6795;
            if (i14 == -1) {
                i14 = -1;
            } else if (i14 == -2) {
                i14 = m5189().getWidth();
            }
            int i15 = this.f6776;
            if (i15 == -1) {
                i4 = -1;
            } else if (i15 != -2) {
                i4 = i15;
            }
            this.f6786.setWidth(i14);
            this.f6786.setHeight(i4);
            if (Build.VERSION.SDK_INT <= 28) {
                Method method2 = f6769;
                if (method2 != null) {
                    try {
                        method2.invoke(this.f6786, true);
                    } catch (Exception unused2) {
                        Log.i("ListPopupWindow", "Could not call setClipToScreenEnabled() on PopupWindow. Oh well.");
                    }
                }
            } else {
                this.f6786.setIsClippedToScreen(true);
            }
            this.f6786.setOutsideTouchable(!this.f6790 && !this.f6772);
            this.f6786.setTouchInterceptor(this.f6778);
            if (this.f6789) {
                C2369.m6333(this.f6786, this.f6781);
            }
            if (Build.VERSION.SDK_INT <= 28) {
                Method method3 = f6768;
                if (method3 != null) {
                    try {
                        method3.invoke(this.f6786, this.f6782);
                    } catch (Exception e) {
                        Log.e("ListPopupWindow", "Could not invoke setEpicenterBounds on PopupWindow", e);
                    }
                }
            } else {
                this.f6786.setEpicenterBounds(this.f6782);
            }
            PopupWindow popupWindow = this.f6786;
            View r12 = m5189();
            int i16 = this.f6785;
            int i17 = this.f6798;
            int i18 = this.f6800;
            int i19 = Build.VERSION.SDK_INT;
            popupWindow.showAsDropDown(r12, i16, i17, i18);
            this.f6797.setSelection(-1);
            if (!this.f6777 || this.f6797.isInTouchMode()) {
                m5172();
            }
            if (!this.f6777) {
                this.f6792.post(this.f6788);
            }
        } else if (C1729.m4498(m5189())) {
            int i20 = this.f6795;
            if (i20 == -1) {
                i20 = -1;
            } else if (i20 == -2) {
                i20 = m5189().getWidth();
            }
            int i21 = this.f6776;
            if (i21 == -1) {
                if (!r02) {
                    i4 = -1;
                }
                if (r02) {
                    this.f6786.setWidth(this.f6795 == -1 ? -1 : 0);
                    this.f6786.setHeight(0);
                } else {
                    this.f6786.setWidth(this.f6795 == -1 ? -1 : 0);
                    this.f6786.setHeight(-1);
                }
            } else if (i21 != -2) {
                i4 = i21;
            }
            PopupWindow popupWindow2 = this.f6786;
            if (this.f6790 || this.f6772) {
                z = false;
            }
            popupWindow2.setOutsideTouchable(z);
            this.f6786.update(m5189(), this.f6785, this.f6798, i20 < 0 ? -1 : i20, i4 < 0 ? -1 : i4);
        }
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public int m5161() {
        if (!this.f6793) {
            return 0;
        }
        return this.f6798;
    }

    /* renamed from: Ԕ  reason: contains not printable characters */
    public boolean m5162() {
        return this.f6786.getInputMethodMode() == 2;
    }

    /* renamed from: ඓ  reason: contains not printable characters */
    public void m5163(int i) {
        Drawable background = this.f6786.getBackground();
        if (background != null) {
            background.getPadding(this.f6801);
            Rect rect = this.f6801;
            this.f6795 = rect.left + rect.right + i;
            return;
        }
        m5165(i);
    }

    /* renamed from: ᕣ  reason: contains not printable characters */
    public void m5165(int i) {
        this.f6795 = i;
    }

    /* renamed from: ᨨ  reason: contains not printable characters */
    public void m5167(int i) {
        this.f6791 = i;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m5170(View view) {
        this.f6799 = view;
    }

    /* renamed from: ⁱ  reason: contains not printable characters */
    public void m5173(int i) {
        if (i >= 0 || -2 == i || -1 == i) {
            this.f6776 = i;
            return;
        }
        throw new IllegalArgumentException("Invalid height. Must be a positive value, MATCH_PARENT, or WRAP_CONTENT.");
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m5178(ListAdapter listAdapter) {
        DataSetObserver dataSetObserver = this.f6775;
        if (dataSetObserver == null) {
            this.f6775 = new C1996();
        } else {
            ListAdapter listAdapter2 = this.f6771;
            if (listAdapter2 != null) {
                listAdapter2.unregisterDataSetObserver(dataSetObserver);
            }
        }
        this.f6771 = listAdapter;
        if (listAdapter != null) {
            listAdapter.registerDataSetObserver(this.f6775);
        }
        C2035 r3 = this.f6797;
        if (r3 != null) {
            r3.setAdapter(this.f6771);
        }
    }

    /* renamed from: 㑃  reason: contains not printable characters */
    public View m5181() {
        if (!m5180()) {
            return null;
        }
        return this.f6797.getSelectedView();
    }

    /* renamed from: 㗗  reason: contains not printable characters */
    public boolean m5182() {
        return this.f6777;
    }

    /* renamed from: 㳳  reason: contains not printable characters */
    public void m5184(int i) {
        C2035 r0 = this.f6797;
        if (m5180() && r0 != null) {
            r0.setListSelectionHidden(false);
            r0.setSelection(i);
            if (r0.getChoiceMode() != 0) {
                r0.setItemChecked(i, true);
            }
        }
    }

    /* renamed from: 㴹  reason: contains not printable characters */
    public void m5186(int i) {
        this.f6800 = i;
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public Drawable m5187() {
        return this.f6786.getBackground();
    }

    /* renamed from: 㿎  reason: contains not printable characters */
    public View m5189() {
        return this.f6799;
    }

    /* renamed from: 䁗  reason: contains not printable characters */
    public int m5191() {
        return this.f6795;
    }

    /* renamed from: ᕣ  reason: contains not printable characters */
    public int m5164() {
        if (!m5180()) {
            return -1;
        }
        return this.f6797.getSelectedItemPosition();
    }

    /* renamed from: ᨨ  reason: contains not printable characters */
    public Object m5166() {
        if (!m5180()) {
            return null;
        }
        return this.f6797.getSelectedItem();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public int m5168() {
        return this.f6785;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1903
    /* renamed from: 㴹  reason: contains not printable characters */
    public ListView m5185() {
        return this.f6797;
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public void m5188(int i) {
        this.f6786.setAnimationStyle(i);
    }

    /* renamed from: 㿎  reason: contains not printable characters */
    public void m5190(int i) {
        this.f6786.setInputMethodMode(i);
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m5169(int i) {
        this.f6798 = i;
        this.f6793 = true;
    }

    /* renamed from: ⁱ  reason: contains not printable characters */
    public void m5172() {
        C2035 r0 = this.f6797;
        if (r0 != null) {
            r0.setListSelectionHidden(true);
            r0.requestLayout();
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m5171(boolean z) {
        this.f6789 = true;
        this.f6781 = z;
    }

    /* renamed from: 㳳  reason: contains not printable characters */
    public long m5183() {
        if (!m5180()) {
            return Long.MIN_VALUE;
        }
        return this.f6797.getSelectedItemId();
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m5179(boolean z) {
        this.f6777 = z;
        this.f6786.setFocusable(z);
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m5176(int i) {
        this.f6785 = i;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m5177(Rect rect) {
        this.f6782 = rect != null ? new Rect(rect) : null;
    }

    @Override // ῲ.ῲ.ඓ.㳳.AbstractC1903
    /* renamed from: K  reason: contains not printable characters */
    public boolean m5180() {
        return this.f6786.isShowing();
    }

    /* renamed from: K  reason: contains not printable characters */
    public C2035 m5175(Context context, boolean z) {
        return new C2035(context, z);
    }

    /* renamed from: K  reason: contains not printable characters */
    public View.OnTouchListener m5174(View view) {
        return new C1999(view);
    }
}
