package o;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.ViewTreeObserver;
import android.widget.ListAdapter;
import com.google.android.gms.common.R;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.q8, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2217q8 extends UL implements InterfaceC2406s8 {
    public CharSequence N;
    public C1932n8 O;
    public final Rect P;
    public int Q;
    public final /* synthetic */ C2501t8 R;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C2217q8(C2501t8 c2501t8, Context context, AttributeSet attributeSet) {
        super(context, attributeSet, R.attr.spinnerStyle, 0);
        this.R = c2501t8;
        this.P = new Rect();
        this.z = c2501t8;
        this.J = true;
        this.K.setFocusable(true);
        this.A = new C2027o8(0, this);
    }

    @Override // o.InterfaceC2406s8
    public final void i(CharSequence charSequence) {
        this.N = charSequence;
    }

    @Override // o.InterfaceC2406s8
    public final void l(int i) {
        this.Q = i;
    }

    @Override // o.InterfaceC2406s8
    public final void n(int i, int i2) {
        ViewTreeObserver viewTreeObserver;
        C0979d8 c0979d8 = this.K;
        boolean zIsShowing = c0979d8.isShowing();
        s();
        c0979d8.setInputMethodMode(2);
        e();
        C0097Dt c0097Dt = this.n;
        c0097Dt.setChoiceMode(1);
        c0097Dt.setTextDirection(i);
        c0097Dt.setTextAlignment(i2);
        C2501t8 c2501t8 = this.R;
        int selectedItemPosition = c2501t8.getSelectedItemPosition();
        C0097Dt c0097Dt2 = this.n;
        if (c0979d8.isShowing() && c0097Dt2 != null) {
            c0097Dt2.setListSelectionHidden(false);
            c0097Dt2.setSelection(selectedItemPosition);
            if (c0097Dt2.getChoiceMode() != 0) {
                c0097Dt2.setItemChecked(selectedItemPosition, true);
            }
        }
        if (zIsShowing || (viewTreeObserver = c2501t8.getViewTreeObserver()) == null) {
            return;
        }
        ViewTreeObserverOnGlobalLayoutListenerC1647k8 viewTreeObserverOnGlobalLayoutListenerC1647k8 = new ViewTreeObserverOnGlobalLayoutListenerC1647k8(1, this);
        viewTreeObserver.addOnGlobalLayoutListener(viewTreeObserverOnGlobalLayoutListenerC1647k8);
        c0979d8.setOnDismissListener(new C2122p8(this, viewTreeObserverOnGlobalLayoutListenerC1647k8));
    }

    @Override // o.InterfaceC2406s8
    public final CharSequence p() {
        return this.N;
    }

    @Override // o.UL, o.InterfaceC2406s8
    public final void q(ListAdapter listAdapter) {
        super.q(listAdapter);
        this.O = (C1932n8) listAdapter;
    }

    public final void s() {
        int i;
        C2501t8 c2501t8 = this.R;
        Rect rect = c2501t8.s;
        C0979d8 c0979d8 = this.K;
        Drawable background = c0979d8.getBackground();
        if (background != null) {
            background.getPadding(rect);
            boolean z = AbstractC2457sk0.a;
            i = c2501t8.getLayoutDirection() == 1 ? rect.right : -rect.left;
        } else {
            i = 0;
            rect.right = 0;
            rect.left = 0;
        }
        int paddingLeft = c2501t8.getPaddingLeft();
        int paddingRight = c2501t8.getPaddingRight();
        int width = c2501t8.getWidth();
        int i2 = c2501t8.r;
        if (i2 == -2) {
            int iA = c2501t8.a(this.O, c0979d8.getBackground());
            int i3 = (c2501t8.getContext().getResources().getDisplayMetrics().widthPixels - rect.left) - rect.right;
            if (iA > i3) {
                iA = i3;
            }
            r(Math.max(iA, (width - paddingLeft) - paddingRight));
        } else if (i2 == -1) {
            r((width - paddingLeft) - paddingRight);
        } else {
            r(i2);
        }
        boolean z2 = AbstractC2457sk0.a;
        this.q = c2501t8.getLayoutDirection() == 1 ? (((width - paddingRight) - this.p) - this.Q) + i : paddingLeft + this.Q + i;
    }
}
