package androidx.appcompat.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.ActionMode;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.RestrictTo;
import d.f;
import d.j;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public ScrollingTabContainerView f588b;

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Drawable f592f;

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

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final int f596j;

    public ActionBarContainer(Context context) {
        this(context, null);
    }

    public static int a(View view) {
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
        return view.getMeasuredHeight() + layoutParams.topMargin + layoutParams.bottomMargin;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void drawableStateChanged() {
        super.drawableStateChanged();
        Drawable drawable = this.f591e;
        if (drawable != null && drawable.isStateful()) {
            this.f591e.setState(getDrawableState());
        }
        Drawable drawable2 = this.f592f;
        if (drawable2 != null && drawable2.isStateful()) {
            this.f592f.setState(getDrawableState());
        }
        Drawable drawable3 = this.f593g;
        if (drawable3 == null || !drawable3.isStateful()) {
            return;
        }
        this.f593g.setState(getDrawableState());
    }

    public View getTabContainer() {
        return this.f588b;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void jumpDrawablesToCurrentState() {
        super.jumpDrawablesToCurrentState();
        Drawable drawable = this.f591e;
        if (drawable != null) {
            drawable.jumpToCurrentState();
        }
        Drawable drawable2 = this.f592f;
        if (drawable2 != null) {
            drawable2.jumpToCurrentState();
        }
        Drawable drawable3 = this.f593g;
        if (drawable3 != null) {
            drawable3.jumpToCurrentState();
        }
    }

    @Override // android.view.View
    public final void onFinishInflate() {
        super.onFinishInflate();
        this.f589c = findViewById(f.action_bar);
        this.f590d = findViewById(f.action_context_bar);
    }

    @Override // android.view.View
    public final boolean onHoverEvent(MotionEvent motionEvent) {
        super.onHoverEvent(motionEvent);
        return true;
    }

    @Override // android.view.ViewGroup
    public final boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        return this.f587a || super.onInterceptTouchEvent(motionEvent);
    }

    @Override // android.widget.FrameLayout, android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        Drawable drawable;
        super.onLayout(z10, i10, i11, i12, i13);
        ScrollingTabContainerView scrollingTabContainerView = this.f588b;
        boolean z11 = true;
        boolean z12 = (scrollingTabContainerView == null || scrollingTabContainerView.getVisibility() == 8) ? false : true;
        if (scrollingTabContainerView != null && scrollingTabContainerView.getVisibility() != 8) {
            int measuredHeight = getMeasuredHeight();
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) scrollingTabContainerView.getLayoutParams();
            int measuredHeight2 = measuredHeight - scrollingTabContainerView.getMeasuredHeight();
            int i14 = layoutParams.bottomMargin;
            scrollingTabContainerView.layout(i10, measuredHeight2 - i14, i12, measuredHeight - i14);
        }
        if (this.f594h) {
            Drawable drawable2 = this.f593g;
            if (drawable2 == null) {
                return;
            } else {
                drawable2.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
            }
        } else {
            if (this.f591e == null) {
                z11 = false;
            } else if (this.f589c.getVisibility() == 0) {
                this.f591e.setBounds(this.f589c.getLeft(), this.f589c.getTop(), this.f589c.getRight(), this.f589c.getBottom());
            } else {
                View view = this.f590d;
                if (view == null || view.getVisibility() != 0) {
                    this.f591e.setBounds(0, 0, 0, 0);
                } else {
                    this.f591e.setBounds(this.f590d.getLeft(), this.f590d.getTop(), this.f590d.getRight(), this.f590d.getBottom());
                }
            }
            this.f595i = z12;
            if (z12 && (drawable = this.f592f) != null) {
                drawable.setBounds(scrollingTabContainerView.getLeft(), scrollingTabContainerView.getTop(), scrollingTabContainerView.getRight(), scrollingTabContainerView.getBottom());
            } else if (!z11) {
                return;
            }
        }
        invalidate();
    }

    @Override // android.widget.FrameLayout, android.view.View
    public final void onMeasure(int i10, int i11) {
        int iA;
        int i12;
        if (this.f589c == null && View.MeasureSpec.getMode(i11) == Integer.MIN_VALUE && (i12 = this.f596j) >= 0) {
            i11 = View.MeasureSpec.makeMeasureSpec(Math.min(i12, View.MeasureSpec.getSize(i11)), Integer.MIN_VALUE);
        }
        super.onMeasure(i10, i11);
        if (this.f589c == null) {
            return;
        }
        int mode = View.MeasureSpec.getMode(i11);
        ScrollingTabContainerView scrollingTabContainerView = this.f588b;
        if (scrollingTabContainerView == null || scrollingTabContainerView.getVisibility() == 8 || mode == 1073741824) {
            return;
        }
        View view = this.f589c;
        if (view == null || view.getVisibility() == 8 || view.getMeasuredHeight() == 0) {
            View view2 = this.f590d;
            iA = (view2 == null || view2.getVisibility() == 8 || view2.getMeasuredHeight() == 0) ? 0 : a(this.f590d);
        } else {
            iA = a(this.f589c);
        }
        setMeasuredDimension(getMeasuredWidth(), Math.min(a(this.f588b) + iA, mode == Integer.MIN_VALUE ? View.MeasureSpec.getSize(i11) : Integer.MAX_VALUE));
    }

    @Override // android.view.View
    public final boolean onTouchEvent(MotionEvent motionEvent) {
        super.onTouchEvent(motionEvent);
        return true;
    }

    public void setPrimaryBackground(Drawable drawable) {
        Drawable drawable2 = this.f591e;
        if (drawable2 != null) {
            drawable2.setCallback(null);
            unscheduleDrawable(this.f591e);
        }
        this.f591e = drawable;
        if (drawable != null) {
            drawable.setCallback(this);
            View view = this.f589c;
            if (view != null) {
                this.f591e.setBounds(view.getLeft(), this.f589c.getTop(), this.f589c.getRight(), this.f589c.getBottom());
            }
        }
        boolean z10 = false;
        if (!this.f594h ? !(this.f591e != null || this.f592f != null) : this.f593g == null) {
            z10 = true;
        }
        setWillNotDraw(z10);
        invalidate();
        invalidateOutline();
    }

    public void setSplitBackground(Drawable drawable) {
        Drawable drawable2;
        Drawable drawable3 = this.f593g;
        if (drawable3 != null) {
            drawable3.setCallback(null);
            unscheduleDrawable(this.f593g);
        }
        this.f593g = drawable;
        boolean z10 = this.f594h;
        boolean z11 = false;
        if (drawable != null) {
            drawable.setCallback(this);
            if (z10 && (drawable2 = this.f593g) != null) {
                drawable2.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
            }
        }
        if (!z10 ? !(this.f591e != null || this.f592f != null) : this.f593g == null) {
            z11 = true;
        }
        setWillNotDraw(z11);
        invalidate();
        invalidateOutline();
    }

    public void setStackedBackground(Drawable drawable) {
        Drawable drawable2;
        Drawable drawable3 = this.f592f;
        if (drawable3 != null) {
            drawable3.setCallback(null);
            unscheduleDrawable(this.f592f);
        }
        this.f592f = drawable;
        if (drawable != null) {
            drawable.setCallback(this);
            if (this.f595i && (drawable2 = this.f592f) != null) {
                drawable2.setBounds(this.f588b.getLeft(), this.f588b.getTop(), this.f588b.getRight(), this.f588b.getBottom());
            }
        }
        boolean z10 = false;
        if (!this.f594h ? !(this.f591e != null || this.f592f != null) : this.f593g == null) {
            z10 = true;
        }
        setWillNotDraw(z10);
        invalidate();
        invalidateOutline();
    }

    public void setTabContainer(ScrollingTabContainerView scrollingTabContainerView) {
        ScrollingTabContainerView scrollingTabContainerView2 = this.f588b;
        if (scrollingTabContainerView2 != null) {
            removeView(scrollingTabContainerView2);
        }
        this.f588b = scrollingTabContainerView;
        if (scrollingTabContainerView != null) {
            addView(scrollingTabContainerView);
            ViewGroup.LayoutParams layoutParams = scrollingTabContainerView.getLayoutParams();
            layoutParams.width = -1;
            layoutParams.height = -2;
            scrollingTabContainerView.setAllowCollapse(false);
        }
    }

    public void setTransitioning(boolean z10) {
        this.f587a = z10;
        setDescendantFocusability(z10 ? 393216 : 262144);
    }

    @Override // android.view.View
    public void setVisibility(int i10) {
        super.setVisibility(i10);
        boolean z10 = i10 == 0;
        Drawable drawable = this.f591e;
        if (drawable != null) {
            drawable.setVisible(z10, false);
        }
        Drawable drawable2 = this.f592f;
        if (drawable2 != null) {
            drawable2.setVisible(z10, false);
        }
        Drawable drawable3 = this.f593g;
        if (drawable3 != null) {
            drawable3.setVisible(z10, false);
        }
    }

    @Override // android.view.ViewGroup, android.view.ViewParent
    public final ActionMode startActionModeForChild(View view, ActionMode.Callback callback) {
        return null;
    }

    @Override // android.view.View
    public final boolean verifyDrawable(Drawable drawable) {
        Drawable drawable2 = this.f591e;
        boolean z10 = this.f594h;
        return (drawable == drawable2 && !z10) || (drawable == this.f592f && this.f595i) || ((drawable == this.f593g && z10) || super.verifyDrawable(drawable));
    }

    public ActionBarContainer(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        setBackground(new l.c(this));
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, j.ActionBar);
        this.f591e = typedArrayObtainStyledAttributes.getDrawable(j.ActionBar_background);
        this.f592f = typedArrayObtainStyledAttributes.getDrawable(j.ActionBar_backgroundStacked);
        this.f596j = typedArrayObtainStyledAttributes.getDimensionPixelSize(j.ActionBar_height, -1);
        boolean z10 = true;
        if (getId() == f.split_action_bar) {
            this.f594h = true;
            this.f593g = typedArrayObtainStyledAttributes.getDrawable(j.ActionBar_backgroundSplit);
        }
        typedArrayObtainStyledAttributes.recycle();
        if (!this.f594h ? this.f591e != null || this.f592f != null : this.f593g != null) {
            z10 = false;
        }
        setWillNotDraw(z10);
    }

    @Override // android.view.ViewGroup, android.view.ViewParent
    public final ActionMode startActionModeForChild(View view, ActionMode.Callback callback, int i10) {
        if (i10 != 0) {
            return super.startActionModeForChild(view, callback, i10);
        }
        return null;
    }
}
