package androidx.appcompat.widget;

import android.R;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.view.Window;
import android.view.WindowInsets;
import android.widget.OverScroller;
import androidx.appcompat.view.menu.j;
import androidx.core.view.h1;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;

@SuppressLint({"UnknownNullness"})
/* loaded from: classes.dex */
public class ActionBarOverlayLayout extends ViewGroup implements d0, androidx.core.view.e0, androidx.core.view.f0 {
    static final int[] U = {h.a.f20148b, R.attr.windowContentOverlay};
    private int A;
    private int B;
    private final Rect C;
    private final Rect D;
    private final Rect E;
    private final Rect F;
    private final Rect G;
    private final Rect H;
    private final Rect I;
    private h1 J;
    private h1 K;
    private h1 L;
    private h1 M;
    private d N;
    private OverScroller O;
    ViewPropertyAnimator P;
    final AnimatorListenerAdapter Q;
    private final Runnable R;
    private final Runnable S;
    private final androidx.core.view.g0 T;

    /* renamed from: p, reason: collision with root package name */
    private int f806p;

    /* renamed from: q, reason: collision with root package name */
    private int f807q;

    /* renamed from: r, reason: collision with root package name */
    private ContentFrameLayout f808r;

    /* renamed from: s, reason: collision with root package name */
    ActionBarContainer f809s;

    /* renamed from: t, reason: collision with root package name */
    private e0 f810t;

    /* renamed from: u, reason: collision with root package name */
    private Drawable f811u;

    /* renamed from: v, reason: collision with root package name */
    private boolean f812v;

    /* renamed from: w, reason: collision with root package name */
    private boolean f813w;

    /* renamed from: x, reason: collision with root package name */
    private boolean f814x;

    /* renamed from: y, reason: collision with root package name */
    private boolean f815y;

    /* renamed from: z, reason: collision with root package name */
    boolean f816z;

    /* loaded from: classes.dex */
    class a extends AnimatorListenerAdapter {
        a() {
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationCancel(Animator animator) {
            ActionBarOverlayLayout actionBarOverlayLayout = ActionBarOverlayLayout.this;
            actionBarOverlayLayout.P = null;
            actionBarOverlayLayout.f816z = false;
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            ActionBarOverlayLayout actionBarOverlayLayout = ActionBarOverlayLayout.this;
            actionBarOverlayLayout.P = null;
            actionBarOverlayLayout.f816z = false;
        }
    }

    /* loaded from: classes.dex */
    class b implements Runnable {
        b() {
        }

        @Override // java.lang.Runnable
        public void run() {
            ActionBarOverlayLayout.this.u();
            ActionBarOverlayLayout actionBarOverlayLayout = ActionBarOverlayLayout.this;
            actionBarOverlayLayout.P = actionBarOverlayLayout.f809s.animate().translationY(BitmapDescriptorFactory.HUE_RED).setListener(ActionBarOverlayLayout.this.Q);
        }
    }

    /* loaded from: classes.dex */
    class c implements Runnable {
        c() {
        }

        @Override // java.lang.Runnable
        public void run() {
            ActionBarOverlayLayout.this.u();
            ActionBarOverlayLayout actionBarOverlayLayout = ActionBarOverlayLayout.this;
            actionBarOverlayLayout.P = actionBarOverlayLayout.f809s.animate().translationY(-ActionBarOverlayLayout.this.f809s.getHeight()).setListener(ActionBarOverlayLayout.this.Q);
        }
    }

    /* loaded from: classes.dex */
    public interface d {
        void a();

        void b();

        void c(boolean z10);

        void d();

        void e();

        void f(int i10);
    }

    /* loaded from: classes.dex */
    public static class e extends ViewGroup.MarginLayoutParams {
        public e(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
        }

        public e(int i10, int i11) {
            super(i10, i11);
        }

        public e(ViewGroup.LayoutParams layoutParams) {
            super(layoutParams);
        }
    }

    public ActionBarOverlayLayout(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f807q = 0;
        this.C = new Rect();
        this.D = new Rect();
        this.E = new Rect();
        this.F = new Rect();
        this.G = new Rect();
        this.H = new Rect();
        this.I = new Rect();
        h1 h1Var = h1.f3850b;
        this.J = h1Var;
        this.K = h1Var;
        this.L = h1Var;
        this.M = h1Var;
        this.Q = new a();
        this.R = new b();
        this.S = new c();
        v(context);
        this.T = new androidx.core.view.g0(this);
    }

    private void A() {
        u();
        this.R.run();
    }

    private boolean B(float f10) {
        this.O.fling(0, 0, 0, (int) f10, 0, 0, Integer.MIN_VALUE, Api.BaseClientBuilder.API_PRIORITY_OTHER);
        return this.O.getFinalY() > this.f809s.getHeight();
    }

    private void p() {
        u();
        this.S.run();
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x0021  */
    /* JADX WARN: Removed duplicated region for block: B:15:0x002c  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0016  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private boolean q(View view, Rect rect, boolean z10, boolean z11, boolean z12, boolean z13) {
        boolean z14;
        e eVar = (e) view.getLayoutParams();
        if (z10) {
            int i10 = ((ViewGroup.MarginLayoutParams) eVar).leftMargin;
            int i11 = rect.left;
            if (i10 != i11) {
                ((ViewGroup.MarginLayoutParams) eVar).leftMargin = i11;
                z14 = true;
                if (z11) {
                    int i12 = ((ViewGroup.MarginLayoutParams) eVar).topMargin;
                    int i13 = rect.top;
                    if (i12 != i13) {
                        ((ViewGroup.MarginLayoutParams) eVar).topMargin = i13;
                        z14 = true;
                    }
                }
                if (z13) {
                    int i14 = ((ViewGroup.MarginLayoutParams) eVar).rightMargin;
                    int i15 = rect.right;
                    if (i14 != i15) {
                        ((ViewGroup.MarginLayoutParams) eVar).rightMargin = i15;
                        z14 = true;
                    }
                }
                if (z12) {
                    int i16 = ((ViewGroup.MarginLayoutParams) eVar).bottomMargin;
                    int i17 = rect.bottom;
                    if (i16 != i17) {
                        ((ViewGroup.MarginLayoutParams) eVar).bottomMargin = i17;
                        return true;
                    }
                }
                return z14;
            }
        }
        z14 = false;
        if (z11) {
        }
        if (z13) {
        }
        if (z12) {
        }
        return z14;
    }

    /* JADX WARN: Multi-variable type inference failed */
    private e0 t(View view) {
        if (view instanceof e0) {
            return (e0) view;
        }
        if (view instanceof Toolbar) {
            return ((Toolbar) view).getWrapper();
        }
        throw new IllegalStateException("Can't make a decor toolbar out of " + view.getClass().getSimpleName());
    }

    private void v(Context context) {
        TypedArray obtainStyledAttributes = getContext().getTheme().obtainStyledAttributes(U);
        this.f806p = obtainStyledAttributes.getDimensionPixelSize(0, 0);
        Drawable drawable = obtainStyledAttributes.getDrawable(1);
        this.f811u = drawable;
        setWillNotDraw(drawable == null);
        obtainStyledAttributes.recycle();
        this.f812v = context.getApplicationInfo().targetSdkVersion < 19;
        this.O = new OverScroller(context);
    }

    private void x() {
        u();
        postDelayed(this.S, 600L);
    }

    private void y() {
        u();
        postDelayed(this.R, 600L);
    }

    @Override // androidx.appcompat.widget.d0
    public void a(Menu menu, j.a aVar) {
        z();
        this.f810t.a(menu, aVar);
    }

    @Override // androidx.core.view.f0
    public void b(View view, int i10, int i11, int i12, int i13, int i14, int[] iArr) {
        k(view, i10, i11, i12, i13, i14);
    }

    @Override // androidx.appcompat.widget.d0
    public boolean c() {
        z();
        return this.f810t.c();
    }

    @Override // android.view.ViewGroup
    protected boolean checkLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof e;
    }

    @Override // androidx.appcompat.widget.d0
    public void d() {
        z();
        this.f810t.d();
    }

    @Override // android.view.View
    public void draw(Canvas canvas) {
        super.draw(canvas);
        if (this.f811u == null || this.f812v) {
            return;
        }
        int bottom = this.f809s.getVisibility() == 0 ? (int) (this.f809s.getBottom() + this.f809s.getTranslationY() + 0.5f) : 0;
        this.f811u.setBounds(0, bottom, getWidth(), this.f811u.getIntrinsicHeight() + bottom);
        this.f811u.draw(canvas);
    }

    @Override // androidx.appcompat.widget.d0
    public boolean e() {
        z();
        return this.f810t.e();
    }

    @Override // androidx.appcompat.widget.d0
    public boolean f() {
        z();
        return this.f810t.f();
    }

    @Override // android.view.View
    protected boolean fitSystemWindows(Rect rect) {
        return super.fitSystemWindows(rect);
    }

    @Override // androidx.appcompat.widget.d0
    public boolean g() {
        z();
        return this.f810t.g();
    }

    public int getActionBarHideOffset() {
        ActionBarContainer actionBarContainer = this.f809s;
        if (actionBarContainer != null) {
            return -((int) actionBarContainer.getTranslationY());
        }
        return 0;
    }

    @Override // android.view.ViewGroup
    public int getNestedScrollAxes() {
        return this.T.a();
    }

    public CharSequence getTitle() {
        z();
        return this.f810t.getTitle();
    }

    @Override // androidx.appcompat.widget.d0
    public boolean h() {
        z();
        return this.f810t.h();
    }

    @Override // androidx.appcompat.widget.d0
    public void i(int i10) {
        z();
        if (i10 == 2) {
            this.f810t.x();
        } else if (i10 == 5) {
            this.f810t.y();
        } else {
            if (i10 != 109) {
                return;
            }
            setOverlayMode(true);
        }
    }

    @Override // androidx.appcompat.widget.d0
    public void j() {
        z();
        this.f810t.i();
    }

    @Override // androidx.core.view.e0
    public void k(View view, int i10, int i11, int i12, int i13, int i14) {
        if (i14 == 0) {
            onNestedScroll(view, i10, i11, i12, i13);
        }
    }

    @Override // androidx.core.view.e0
    public boolean l(View view, View view2, int i10, int i11) {
        return i11 == 0 && onStartNestedScroll(view, view2, i10);
    }

    @Override // androidx.core.view.e0
    public void m(View view, View view2, int i10, int i11) {
        if (i11 == 0) {
            onNestedScrollAccepted(view, view2, i10);
        }
    }

    @Override // androidx.core.view.e0
    public void n(View view, int i10) {
        if (i10 == 0) {
            onStopNestedScroll(view);
        }
    }

    @Override // androidx.core.view.e0
    public void o(View view, int i10, int i11, int[] iArr, int i12) {
        if (i12 == 0) {
            onNestedPreScroll(view, i10, i11, iArr);
        }
    }

    @Override // android.view.View
    public WindowInsets onApplyWindowInsets(WindowInsets windowInsets) {
        z();
        h1 w10 = h1.w(windowInsets, this);
        boolean q10 = q(this.f809s, new Rect(w10.j(), w10.l(), w10.k(), w10.i()), true, true, false, true);
        androidx.core.view.s0.f(this, w10, this.C);
        Rect rect = this.C;
        h1 m10 = w10.m(rect.left, rect.top, rect.right, rect.bottom);
        this.J = m10;
        boolean z10 = true;
        if (!this.K.equals(m10)) {
            this.K = this.J;
            q10 = true;
        }
        if (this.D.equals(this.C)) {
            z10 = q10;
        } else {
            this.D.set(this.C);
        }
        if (z10) {
            requestLayout();
        }
        return w10.a().c().b().u();
    }

    @Override // android.view.View
    protected void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        v(getContext());
        androidx.core.view.s0.j0(this);
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        u();
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        int childCount = getChildCount();
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        for (int i14 = 0; i14 < childCount; i14++) {
            View childAt = getChildAt(i14);
            if (childAt.getVisibility() != 8) {
                e eVar = (e) childAt.getLayoutParams();
                int measuredWidth = childAt.getMeasuredWidth();
                int measuredHeight = childAt.getMeasuredHeight();
                int i15 = ((ViewGroup.MarginLayoutParams) eVar).leftMargin + paddingLeft;
                int i16 = ((ViewGroup.MarginLayoutParams) eVar).topMargin + paddingTop;
                childAt.layout(i15, i16, measuredWidth + i15, measuredHeight + i16);
            }
        }
    }

    @Override // android.view.View
    protected void onMeasure(int i10, int i11) {
        int measuredHeight;
        z();
        measureChildWithMargins(this.f809s, i10, 0, i11, 0);
        e eVar = (e) this.f809s.getLayoutParams();
        int max = Math.max(0, this.f809s.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) eVar).leftMargin + ((ViewGroup.MarginLayoutParams) eVar).rightMargin);
        int max2 = Math.max(0, this.f809s.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) eVar).topMargin + ((ViewGroup.MarginLayoutParams) eVar).bottomMargin);
        int combineMeasuredStates = View.combineMeasuredStates(0, this.f809s.getMeasuredState());
        boolean z10 = (androidx.core.view.s0.I(this) & 256) != 0;
        if (z10) {
            measuredHeight = this.f806p;
            if (this.f814x && this.f809s.getTabContainer() != null) {
                measuredHeight += this.f806p;
            }
        } else {
            measuredHeight = this.f809s.getVisibility() != 8 ? this.f809s.getMeasuredHeight() : 0;
        }
        this.E.set(this.C);
        h1 h1Var = this.J;
        this.L = h1Var;
        if (this.f813w || z10) {
            this.L = new h1.b(this.L).c(androidx.core.graphics.b.b(h1Var.j(), this.L.l() + measuredHeight, this.L.k(), this.L.i() + 0)).a();
        } else {
            Rect rect = this.E;
            rect.top += measuredHeight;
            rect.bottom += 0;
            this.L = h1Var.m(0, measuredHeight, 0, 0);
        }
        q(this.f808r, this.E, true, true, true, true);
        if (!this.M.equals(this.L)) {
            h1 h1Var2 = this.L;
            this.M = h1Var2;
            androidx.core.view.s0.g(this.f808r, h1Var2);
        }
        measureChildWithMargins(this.f808r, i10, 0, i11, 0);
        e eVar2 = (e) this.f808r.getLayoutParams();
        int max3 = Math.max(max, this.f808r.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) eVar2).leftMargin + ((ViewGroup.MarginLayoutParams) eVar2).rightMargin);
        int max4 = Math.max(max2, this.f808r.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) eVar2).topMargin + ((ViewGroup.MarginLayoutParams) eVar2).bottomMargin);
        int combineMeasuredStates2 = View.combineMeasuredStates(combineMeasuredStates, this.f808r.getMeasuredState());
        setMeasuredDimension(View.resolveSizeAndState(Math.max(max3 + getPaddingLeft() + getPaddingRight(), getSuggestedMinimumWidth()), i10, combineMeasuredStates2), View.resolveSizeAndState(Math.max(max4 + getPaddingTop() + getPaddingBottom(), getSuggestedMinimumHeight()), i11, combineMeasuredStates2 << 16));
    }

    @Override // android.view.ViewGroup, android.view.ViewParent
    public boolean onNestedFling(View view, float f10, float f11, boolean z10) {
        if (!this.f815y || !z10) {
            return false;
        }
        if (B(f11)) {
            p();
        } else {
            A();
        }
        this.f816z = true;
        return true;
    }

    @Override // android.view.ViewGroup, android.view.ViewParent
    public boolean onNestedPreFling(View view, float f10, float f11) {
        return false;
    }

    @Override // android.view.ViewGroup, android.view.ViewParent
    public void onNestedPreScroll(View view, int i10, int i11, int[] iArr) {
    }

    @Override // android.view.ViewGroup, android.view.ViewParent
    public void onNestedScroll(View view, int i10, int i11, int i12, int i13) {
        int i14 = this.A + i11;
        this.A = i14;
        setActionBarHideOffset(i14);
    }

    @Override // android.view.ViewGroup, android.view.ViewParent
    public void onNestedScrollAccepted(View view, View view2, int i10) {
        this.T.b(view, view2, i10);
        this.A = getActionBarHideOffset();
        u();
        d dVar = this.N;
        if (dVar != null) {
            dVar.e();
        }
    }

    @Override // android.view.ViewGroup, android.view.ViewParent
    public boolean onStartNestedScroll(View view, View view2, int i10) {
        if ((i10 & 2) == 0 || this.f809s.getVisibility() != 0) {
            return false;
        }
        return this.f815y;
    }

    @Override // android.view.ViewGroup, android.view.ViewParent
    public void onStopNestedScroll(View view) {
        if (this.f815y && !this.f816z) {
            if (this.A <= this.f809s.getHeight()) {
                y();
            } else {
                x();
            }
        }
        d dVar = this.N;
        if (dVar != null) {
            dVar.b();
        }
    }

    @Override // android.view.View
    public void onWindowSystemUiVisibilityChanged(int i10) {
        super.onWindowSystemUiVisibilityChanged(i10);
        z();
        int i11 = this.B ^ i10;
        this.B = i10;
        boolean z10 = (i10 & 4) == 0;
        boolean z11 = (i10 & 256) != 0;
        d dVar = this.N;
        if (dVar != null) {
            dVar.c(!z11);
            if (z10 || !z11) {
                this.N.a();
            } else {
                this.N.d();
            }
        }
        if ((i11 & 256) == 0 || this.N == null) {
            return;
        }
        androidx.core.view.s0.j0(this);
    }

    @Override // android.view.View
    protected void onWindowVisibilityChanged(int i10) {
        super.onWindowVisibilityChanged(i10);
        this.f807q = i10;
        d dVar = this.N;
        if (dVar != null) {
            dVar.f(i10);
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.view.ViewGroup
    /* renamed from: r, reason: merged with bridge method [inline-methods] */
    public e generateDefaultLayoutParams() {
        return new e(-1, -1);
    }

    @Override // android.view.ViewGroup
    /* renamed from: s, reason: merged with bridge method [inline-methods] */
    public e generateLayoutParams(AttributeSet attributeSet) {
        return new e(getContext(), attributeSet);
    }

    public void setActionBarHideOffset(int i10) {
        u();
        this.f809s.setTranslationY(-Math.max(0, Math.min(i10, this.f809s.getHeight())));
    }

    public void setActionBarVisibilityCallback(d dVar) {
        this.N = dVar;
        if (getWindowToken() != null) {
            this.N.f(this.f807q);
            int i10 = this.B;
            if (i10 != 0) {
                onWindowSystemUiVisibilityChanged(i10);
                androidx.core.view.s0.j0(this);
            }
        }
    }

    public void setHasNonEmbeddedTabs(boolean z10) {
        this.f814x = z10;
    }

    public void setHideOnContentScrollEnabled(boolean z10) {
        if (z10 != this.f815y) {
            this.f815y = z10;
            if (z10) {
                return;
            }
            u();
            setActionBarHideOffset(0);
        }
    }

    public void setIcon(int i10) {
        z();
        this.f810t.setIcon(i10);
    }

    public void setLogo(int i10) {
        z();
        this.f810t.n(i10);
    }

    public void setOverlayMode(boolean z10) {
        this.f813w = z10;
        this.f812v = z10 && getContext().getApplicationInfo().targetSdkVersion < 19;
    }

    public void setShowingForActionMode(boolean z10) {
    }

    public void setUiOptions(int i10) {
    }

    @Override // androidx.appcompat.widget.d0
    public void setWindowCallback(Window.Callback callback) {
        z();
        this.f810t.setWindowCallback(callback);
    }

    @Override // androidx.appcompat.widget.d0
    public void setWindowTitle(CharSequence charSequence) {
        z();
        this.f810t.setWindowTitle(charSequence);
    }

    @Override // android.view.ViewGroup
    public boolean shouldDelayChildPressedState() {
        return false;
    }

    void u() {
        removeCallbacks(this.R);
        removeCallbacks(this.S);
        ViewPropertyAnimator viewPropertyAnimator = this.P;
        if (viewPropertyAnimator != null) {
            viewPropertyAnimator.cancel();
        }
    }

    public boolean w() {
        return this.f813w;
    }

    void z() {
        if (this.f808r == null) {
            this.f808r = (ContentFrameLayout) findViewById(h.f.f20218b);
            this.f809s = (ActionBarContainer) findViewById(h.f.f20219c);
            this.f810t = t(findViewById(h.f.f20217a));
        }
    }

    @Override // android.view.ViewGroup
    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return new e(layoutParams);
    }

    public void setIcon(Drawable drawable) {
        z();
        this.f810t.setIcon(drawable);
    }
}
