package androidx.appcompat.widget;

import android.R;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.core.view.e;
import androidx.core.view.s1;
import d.g;
import d.j;
import k.f;
import l.h2;
import l.p3;
import l.t;
import l.u;
import l.v;
import l.w;
import l.x;

/* JADX INFO: loaded from: classes.dex */
@RestrictTo({RestrictTo.Scope.f557c})
public class ActivityChooserView extends ViewGroup {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final w f633a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final x f634b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final View f635c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final FrameLayout f636d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final ImageView f637e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final FrameLayout f638f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public e f639g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final f f640h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public h2 f641i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public PopupWindow.OnDismissListener f642j;

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

    @RestrictTo({RestrictTo.Scope.f557c})
    public static class InnerLayout extends LinearLayout {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public static final int[] f644a = {R.attr.background};

        public InnerLayout(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            p3 p3Var = new p3(context, context.obtainStyledAttributes(attributeSet, f644a));
            setBackgroundDrawable(p3Var.b(0));
            p3Var.e();
        }
    }

    public ActivityChooserView(@NonNull Context context) {
        this(context, null);
    }

    public final void a() {
        if (b()) {
            getListPopupWindow().dismiss();
            ViewTreeObserver viewTreeObserver = getViewTreeObserver();
            if (viewTreeObserver.isAlive()) {
                viewTreeObserver.removeGlobalOnLayoutListener(this.f640h);
            }
        }
    }

    public final boolean b() {
        return getListPopupWindow().f29707e0.isShowing();
    }

    @RestrictTo({RestrictTo.Scope.f555a})
    public t getDataModel() {
        this.f633a.getClass();
        return null;
    }

    public h2 getListPopupWindow() {
        if (this.f641i == null) {
            h2 h2Var = new h2(getContext());
            this.f641i = h2Var;
            h2Var.setAdapter(this.f633a);
            this.f641i.setAnchorView(this);
            h2 h2Var2 = this.f641i;
            h2Var2.f29705d0 = true;
            h2Var2.f29707e0.setFocusable(true);
            h2 h2Var3 = this.f641i;
            x xVar = this.f634b;
            h2Var3.setOnItemClickListener(xVar);
            this.f641i.setOnDismissListener(xVar);
        }
        return this.f641i;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.f633a.getClass();
        this.f643k = true;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.f633a.getClass();
        ViewTreeObserver viewTreeObserver = getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver.removeGlobalOnLayoutListener(this.f640h);
        }
        if (b()) {
            a();
        }
        this.f643k = false;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        this.f635c.layout(0, 0, i12 - i10, i13 - i11);
        if (b()) {
            return;
        }
        a();
    }

    @Override // android.view.View
    public final void onMeasure(int i10, int i11) {
        if (this.f638f.getVisibility() != 0) {
            i11 = View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(i11), 1073741824);
        }
        View view = this.f635c;
        measureChild(view, i10, i11);
        setMeasuredDimension(view.getMeasuredWidth(), view.getMeasuredHeight());
    }

    @RestrictTo({RestrictTo.Scope.f555a})
    public void setActivityChooserModel(t tVar) {
        w wVar = this.f633a;
        wVar.f29876a.f633a.getClass();
        wVar.notifyDataSetChanged();
        if (b()) {
            a();
            if (b() || !this.f643k) {
                return;
            }
            wVar.getClass();
            throw new IllegalStateException("No data model. Did you call #setDataModel?");
        }
    }

    public void setDefaultActionButtonContentDescription(int i10) {
    }

    public void setExpandActivityOverflowButtonContentDescription(int i10) {
        this.f637e.setContentDescription(getContext().getString(i10));
    }

    public void setExpandActivityOverflowButtonDrawable(Drawable drawable) {
        this.f637e.setImageDrawable(drawable);
    }

    public void setInitialActivityCount(int i10) {
    }

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

    @RestrictTo({RestrictTo.Scope.f557c})
    public void setProvider(e eVar) {
        this.f639g = eVar;
    }

    public ActivityChooserView(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public ActivityChooserView(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        int i11 = 0;
        new u(this, i11);
        this.f640h = new f(this, 2);
        int[] iArr = j.ActivityChooserView;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, iArr, i10, 0);
        s1.saveAttributeDataForStyleable(this, context, iArr, attributeSet, typedArrayObtainStyledAttributes, i10, 0);
        typedArrayObtainStyledAttributes.getInt(j.ActivityChooserView_initialActivityCount, 4);
        Drawable drawable = typedArrayObtainStyledAttributes.getDrawable(j.ActivityChooserView_expandActivityOverflowButtonDrawable);
        typedArrayObtainStyledAttributes.recycle();
        LayoutInflater.from(getContext()).inflate(g.abc_activity_chooser_view, (ViewGroup) this, true);
        x xVar = new x(this);
        this.f634b = xVar;
        View viewFindViewById = findViewById(d.f.activity_chooser_view_content);
        this.f635c = viewFindViewById;
        viewFindViewById.getBackground();
        FrameLayout frameLayout = (FrameLayout) findViewById(d.f.default_activity_button);
        this.f638f = frameLayout;
        frameLayout.setOnClickListener(xVar);
        frameLayout.setOnLongClickListener(xVar);
        int i12 = d.f.image;
        FrameLayout frameLayout2 = (FrameLayout) findViewById(d.f.expand_activities_button);
        frameLayout2.setOnClickListener(xVar);
        frameLayout2.setAccessibilityDelegate(new v(this, i11));
        frameLayout2.setOnTouchListener(new k.b(this, frameLayout2));
        this.f636d = frameLayout2;
        ImageView imageView = (ImageView) frameLayout2.findViewById(i12);
        this.f637e = imageView;
        imageView.setImageDrawable(drawable);
        w wVar = new w(this);
        this.f633a = wVar;
        wVar.registerDataSetObserver(new u(this, 1));
        Resources resources = context.getResources();
        Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(d.d.abc_config_prefDialogWidth));
    }
}
