package defpackage;

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.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.PopupWindow;
import java.lang.reflect.Method;

/* renamed from: ᵪᵲᵟ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public class C3911 implements InterfaceC0221 {

    /* renamed from: ˊʽˎ, reason: contains not printable characters */
    public static final Method f14657;

    /* renamed from: ˎᵬˀ, reason: contains not printable characters */
    public static final Method f14658;

    /* renamed from: ᵡᵶᵡ, reason: contains not printable characters */
    public static final Method f14659;

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public int f14660;

    /* renamed from: ˀᵗᵩ, reason: contains not printable characters */
    public final Handler f14661;

    /* renamed from: ˁˑᵰ, reason: contains not printable characters */
    public AdapterView.OnItemClickListener f14662;

    /* renamed from: ˌᵪ, reason: contains not printable characters */
    public boolean f14665;

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public boolean f14666;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public boolean f14668;

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public C4905 f14669;

    /* renamed from: ᵛˈᵤ, reason: contains not printable characters */
    public Rect f14671;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public int f14674;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public ListAdapter f14675;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final Context f14678;

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public boolean f14679;

    /* renamed from: ᵳᵹᵺˋ, reason: contains not printable characters */
    public final C1496 f14680;

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public View f14681;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public C1073 f14684;

    /* renamed from: ﾞⁱ, reason: contains not printable characters */
    public AdapterView.OnItemSelectedListener f14685;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final int f14683 = -2;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public int f14676 = -2;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final int f14672 = 1002;

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public int f14677 = 0;

    /* renamed from: ᵺʙ, reason: contains not printable characters */
    public final int f14682 = Integer.MAX_VALUE;

    /* renamed from: ᵙᵢᵨᵳ, reason: contains not printable characters */
    public final RunnableC0514 f14670 = new RunnableC0514(this, 1);

    /* renamed from: ᵡᵘˎʽ, reason: contains not printable characters */
    public final ViewOnTouchListenerC5286 f14673 = new ViewOnTouchListenerC5286(this);

    /* renamed from: ˑᵝﹳᵜ, reason: contains not printable characters */
    public final C2971 f14667 = new C2971(this);

    /* renamed from: ˊᵸˊ, reason: contains not printable characters */
    public final RunnableC0514 f14664 = new RunnableC0514(this, 0);

    /* renamed from: ˆᵼᵷˊ, reason: contains not printable characters */
    public final Rect f14663 = new Rect();

    static {
        int i = Build.VERSION.SDK_INT;
        Class cls = Boolean.TYPE;
        if (i <= 28) {
            try {
                f14659 = PopupWindow.class.getDeclaredMethod("setClipToScreenEnabled", cls);
            } catch (NoSuchMethodException unused) {
            }
            try {
                f14658 = PopupWindow.class.getDeclaredMethod("setEpicenterBounds", Rect.class);
            } catch (NoSuchMethodException unused2) {
            }
        }
        if (Build.VERSION.SDK_INT == 23) {
            try {
                f14657 = PopupWindow.class.getDeclaredMethod("getMaxAvailableHeight", View.class, Integer.TYPE, cls);
            } catch (NoSuchMethodException unused3) {
            }
        }
    }

    public C3911(Context context, AttributeSet attributeSet, int i, int i2) {
        int resourceId;
        this.f14678 = context;
        this.f14661 = new Handler(context.getMainLooper());
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AbstractC0542.f2821, i, 0);
        this.f14674 = typedArrayObtainStyledAttributes.getDimensionPixelOffset(0, 0);
        int dimensionPixelOffset = typedArrayObtainStyledAttributes.getDimensionPixelOffset(1, 0);
        this.f14660 = dimensionPixelOffset;
        if (dimensionPixelOffset != 0) {
            this.f14668 = true;
        }
        typedArrayObtainStyledAttributes.recycle();
        C1496 c1496 = new C1496(context, attributeSet, i, 0);
        TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(attributeSet, AbstractC0542.f2811, i, 0);
        if (typedArrayObtainStyledAttributes2.hasValue(2)) {
            c1496.setOverlapAnchor(typedArrayObtainStyledAttributes2.getBoolean(2, false));
        }
        c1496.setBackgroundDrawable((!typedArrayObtainStyledAttributes2.hasValue(0) || (resourceId = typedArrayObtainStyledAttributes2.getResourceId(0, 0)) == 0) ? typedArrayObtainStyledAttributes2.getDrawable(0) : ᵕˏᵛ.ˑᵥˁ(context, resourceId));
        typedArrayObtainStyledAttributes2.recycle();
        this.f14680 = c1496;
        c1496.setInputMethodMode(1);
    }

    @Override // defpackage.InterfaceC0221
    public final void dismiss() {
        C1496 c1496 = this.f14680;
        c1496.dismiss();
        c1496.setContentView(null);
        this.f14684 = null;
        this.f14661.removeCallbacks(this.f14670);
    }

    /* renamed from: ˌʾˀ */
    public void mo2474(ListAdapter listAdapter) {
        C4905 c4905 = this.f14669;
        if (c4905 == null) {
            this.f14669 = new C4905(this);
        } else {
            ListAdapter listAdapter2 = this.f14675;
            if (listAdapter2 != null) {
                listAdapter2.unregisterDataSetObserver(c4905);
            }
        }
        this.f14675 = listAdapter;
        if (listAdapter != null) {
            listAdapter.registerDataSetObserver(this.f14669);
        }
        C1073 c1073 = this.f14684;
        if (c1073 != null) {
            c1073.setAdapter(this.f14675);
        }
    }

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final void m8571(int i) {
        this.f14660 = i;
        this.f14668 = true;
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final Drawable m8572() {
        return this.f14680.getBackground();
    }

    @Override // defpackage.InterfaceC0221
    /* renamed from: ˏˋٴ */
    public final void mo1522() {
        int i;
        int iM6537;
        int paddingBottom;
        C1073 c1073;
        C1073 c10732 = this.f14684;
        Context context = this.f14678;
        C1496 c1496 = this.f14680;
        int i2 = 1;
        if (c10732 == null) {
            C1073 c1073Mo6903 = mo6903(context, !this.f14665);
            this.f14684 = c1073Mo6903;
            c1073Mo6903.setAdapter(this.f14675);
            this.f14684.setOnItemClickListener(this.f14662);
            this.f14684.setFocusable(true);
            this.f14684.setFocusableInTouchMode(true);
            this.f14684.setOnItemSelectedListener(new C1372(i2, this));
            this.f14684.setOnScrollListener(this.f14667);
            AdapterView.OnItemSelectedListener onItemSelectedListener = this.f14685;
            if (onItemSelectedListener != null) {
                this.f14684.setOnItemSelectedListener(onItemSelectedListener);
            }
            c1496.setContentView(this.f14684);
        }
        Drawable background = c1496.getBackground();
        Rect rect = this.f14663;
        if (background != null) {
            background.getPadding(rect);
            int i3 = rect.top;
            i = rect.bottom + i3;
            if (!this.f14668) {
                this.f14660 = -i3;
            }
        } else {
            rect.setEmpty();
            i = 0;
        }
        boolean z = c1496.getInputMethodMode() == 2;
        View view = this.f14681;
        int i4 = this.f14660;
        if (Build.VERSION.SDK_INT == 23) {
            Method method = f14657;
            if (method != null) {
                try {
                    iM6537 = ((Integer) method.invoke(c1496, view, Integer.valueOf(i4), Boolean.valueOf(z))).intValue();
                } catch (Exception unused) {
                }
            } else {
                iM6537 = c1496.getMaxAvailableHeight(view, i4);
            }
        } else {
            iM6537 = AbstractC2602.m6537(c1496, view, i4, z);
        }
        int i5 = this.f14683;
        if (i5 == -1) {
            paddingBottom = iM6537 + i;
        } else {
            int i6 = this.f14676;
            int iM3468 = this.f14684.m3468(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), iM6537);
            paddingBottom = iM3468 + (iM3468 > 0 ? this.f14684.getPaddingBottom() + this.f14684.getPaddingTop() + i : 0);
        }
        boolean z2 = c1496.getInputMethodMode() == 2;
        c1496.setWindowLayoutType(this.f14672);
        if (c1496.isShowing()) {
            if (this.f14681.isAttachedToWindow()) {
                int width = this.f14676;
                if (width == -1) {
                    width = -1;
                } else if (width == -2) {
                    width = this.f14681.getWidth();
                }
                if (i5 == -1) {
                    i5 = z2 ? paddingBottom : -1;
                    int i7 = this.f14676;
                    if (z2) {
                        c1496.setWidth(i7 == -1 ? -1 : 0);
                        c1496.setHeight(0);
                    } else {
                        c1496.setWidth(i7 == -1 ? -1 : 0);
                        c1496.setHeight(-1);
                    }
                } else if (i5 == -2) {
                    i5 = paddingBottom;
                }
                c1496.setOutsideTouchable(true);
                int i8 = width;
                c1496.update(this.f14681, this.f14674, this.f14660, i8 < 0 ? -1 : i8, i5 < 0 ? -1 : i5);
                return;
            }
            return;
        }
        int width2 = this.f14676;
        if (width2 == -1) {
            width2 = -1;
        } else if (width2 == -2) {
            width2 = this.f14681.getWidth();
        }
        if (i5 == -1) {
            i5 = -1;
        } else if (i5 == -2) {
            i5 = paddingBottom;
        }
        c1496.setWidth(width2);
        c1496.setHeight(i5);
        if (Build.VERSION.SDK_INT <= 28) {
            Method method2 = f14659;
            if (method2 != null) {
                try {
                    method2.invoke(c1496, Boolean.TRUE);
                } catch (Exception unused2) {
                }
            }
        } else {
            AbstractC5363.m11019(c1496);
        }
        c1496.setOutsideTouchable(true);
        c1496.setTouchInterceptor(this.f14673);
        if (this.f14679) {
            c1496.setOverlapAnchor(this.f14666);
        }
        if (Build.VERSION.SDK_INT <= 28) {
            Method method3 = f14658;
            if (method3 != null) {
                try {
                    method3.invoke(c1496, this.f14671);
                } catch (Exception unused3) {
                }
            }
        } else {
            AbstractC5363.m11001(c1496, this.f14671);
        }
        c1496.showAsDropDown(this.f14681, this.f14674, this.f14660, this.f14677);
        this.f14684.setSelection(-1);
        if ((!this.f14665 || this.f14684.isInTouchMode()) && (c1073 = this.f14684) != null) {
            c1073.setListSelectionHidden(true);
            c1073.requestLayout();
        }
        if (this.f14665) {
            return;
        }
        this.f14661.post(this.f14664);
    }

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final void m8573(Drawable drawable) {
        this.f14680.setBackgroundDrawable(drawable);
    }

    /* renamed from: ᵡʠ */
    public C1073 mo6903(Context context, boolean z) {
        return new C1073(context, z);
    }

    @Override // defpackage.InterfaceC0221
    /* renamed from: ᵥᵯˎ */
    public final boolean mo1523() {
        return this.f14680.isShowing();
    }

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public final int m8574() {
        if (this.f14668) {
            return this.f14660;
        }
        return 0;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final int m8575() {
        return this.f14674;
    }

    @Override // defpackage.InterfaceC0221
    /* renamed from: ᵶᵷᵕ */
    public final C1073 mo1524() {
        return this.f14684;
    }

    /* renamed from: ᵸʓᵠ, reason: contains not printable characters */
    public final void m8576(int i) {
        Drawable background = this.f14680.getBackground();
        if (background == null) {
            this.f14676 = i;
            return;
        }
        Rect rect = this.f14663;
        background.getPadding(rect);
        this.f14676 = rect.left + rect.right + i;
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final void m8577(int i) {
        this.f14674 = i;
    }
}
