package androidx.appcompat.widget;

import android.R;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
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.os.Build;
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.widget.OverScroller;
import androidx.appcompat.view.menu.o;

/* JADX INFO: loaded from: classes.dex */
public class ActionBarOverlayLayout extends ViewGroup implements a0, g.e.j.k {
    static final int[] D = {g.a.a.actionBarSize, R.attr.windowContentOverlay};
    private final Runnable A;
    private final Runnable B;
    private final g.e.j.l C;
    private int b;
    private int d;
    private ContentFrameLayout e;
    ActionBarContainer f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private b0 f118g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private Drawable f119h;

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private boolean f121j;

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private boolean f123l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    boolean f124m;
    private int n;
    private int o;
    private final Rect p;
    private final Rect q;
    private final Rect r;
    private final Rect s;
    private final Rect t;
    private final Rect u;
    private final Rect v;
    private d w;
    private OverScroller x;
    ViewPropertyAnimator y;
    final AnimatorListenerAdapter z;

    class a extends AnimatorListenerAdapter {
        a() {
        }

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

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

    class b implements Runnable {
        b() {
        }

        @Override // java.lang.Runnable
        public void run() {
            ActionBarOverlayLayout.this.t();
            ActionBarOverlayLayout actionBarOverlayLayout = ActionBarOverlayLayout.this;
            actionBarOverlayLayout.y = actionBarOverlayLayout.f.animate().translationY(0.0f).setListener(ActionBarOverlayLayout.this.z);
        }
    }

    class c implements Runnable {
        c() {
        }

        @Override // java.lang.Runnable
        public void run() {
            ActionBarOverlayLayout.this.t();
            ActionBarOverlayLayout actionBarOverlayLayout = ActionBarOverlayLayout.this;
            actionBarOverlayLayout.y = actionBarOverlayLayout.f.animate().translationY(-ActionBarOverlayLayout.this.f.getHeight()).setListener(ActionBarOverlayLayout.this.z);
        }
    }

    public interface d {
        void a();

        void b();

        void c(int i2);

        void d();

        void e(boolean z);

        void f();
    }

    public static class e extends ViewGroup.MarginLayoutParams {
        public e(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
        }

        public e(int i2, int i3) {
            super(i2, i3);
        }

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

    public ActionBarOverlayLayout(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.d = 0;
        this.p = new Rect();
        this.q = new Rect();
        this.r = new Rect();
        this.s = new Rect();
        this.t = new Rect();
        this.u = new Rect();
        this.v = new Rect();
        this.z = new a();
        this.A = new b();
        this.B = new c();
        u(context);
        this.C = new g.e.j.l(this);
    }

    private boolean A(float f, float f2) {
        this.x.fling(0, 0, 0, (int) f2, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
        return this.x.getFinalY() > this.f.getHeight();
    }

    private void o() {
        t();
        this.B.run();
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private boolean p(android.view.View r3, android.graphics.Rect r4, boolean r5, boolean r6, boolean r7, boolean r8) {
        /*
            r2 = this;
            android.view.ViewGroup$LayoutParams r3 = r3.getLayoutParams()
            androidx.appcompat.widget.ActionBarOverlayLayout$e r3 = (androidx.appcompat.widget.ActionBarOverlayLayout.e) r3
            r0 = 1
            if (r5 == 0) goto L13
            int r5 = r3.leftMargin
            int r1 = r4.left
            if (r5 == r1) goto L13
            r3.leftMargin = r1
            r5 = r0
            goto L14
        L13:
            r5 = 0
        L14:
            if (r6 == 0) goto L1f
            int r6 = r3.topMargin
            int r1 = r4.top
            if (r6 == r1) goto L1f
            r3.topMargin = r1
            r5 = r0
        L1f:
            if (r8 == 0) goto L2a
            int r6 = r3.rightMargin
            int r8 = r4.right
            if (r6 == r8) goto L2a
            r3.rightMargin = r8
            r5 = r0
        L2a:
            if (r7 == 0) goto L35
            int r6 = r3.bottomMargin
            int r4 = r4.bottom
            if (r6 == r4) goto L35
            r3.bottomMargin = r4
            goto L36
        L35:
            r0 = r5
        L36:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.appcompat.widget.ActionBarOverlayLayout.p(android.view.View, android.graphics.Rect, boolean, boolean, boolean, boolean):boolean");
    }

    /* JADX WARN: Multi-variable type inference failed */
    private b0 s(View view) {
        if (view instanceof b0) {
            return (b0) 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 u(Context context) {
        TypedArray typedArrayObtainStyledAttributes = getContext().getTheme().obtainStyledAttributes(D);
        this.b = typedArrayObtainStyledAttributes.getDimensionPixelSize(0, 0);
        Drawable drawable = typedArrayObtainStyledAttributes.getDrawable(1);
        this.f119h = drawable;
        setWillNotDraw(drawable == null);
        typedArrayObtainStyledAttributes.recycle();
        this.f120i = context.getApplicationInfo().targetSdkVersion < 19;
        this.x = new OverScroller(context);
    }

    private void w() {
        t();
        postDelayed(this.B, 600L);
    }

    private void x() {
        t();
        postDelayed(this.A, 600L);
    }

    private void z() {
        t();
        this.A.run();
    }

    @Override // androidx.appcompat.widget.a0
    public void a(Menu menu, o.a aVar) {
        y();
        this.f118g.a(menu, aVar);
    }

    @Override // androidx.appcompat.widget.a0
    public boolean b() {
        y();
        return this.f118g.b();
    }

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

    @Override // androidx.appcompat.widget.a0
    public void d() {
        y();
        this.f118g.d();
    }

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

    @Override // androidx.appcompat.widget.a0
    public boolean e() {
        y();
        return this.f118g.e();
    }

    @Override // androidx.appcompat.widget.a0
    public boolean f() {
        y();
        return this.f118g.f();
    }

    @Override // android.view.View
    protected boolean fitSystemWindows(Rect rect) {
        y();
        int i2 = g.e.j.o.i(this) & 256;
        boolean zP = p(this.f, rect, true, true, false, true);
        this.s.set(rect);
        z0.a(this, this.s, this.p);
        if (!this.t.equals(this.s)) {
            this.t.set(this.s);
            zP = true;
        }
        if (!this.q.equals(this.p)) {
            this.q.set(this.p);
            zP = true;
        }
        if (zP) {
            requestLayout();
        }
        return true;
    }

    @Override // androidx.appcompat.widget.a0
    public boolean g() {
        y();
        return this.f118g.g();
    }

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

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

    public CharSequence getTitle() {
        y();
        return this.f118g.getTitle();
    }

    @Override // androidx.appcompat.widget.a0
    public boolean h() {
        y();
        return this.f118g.h();
    }

    @Override // androidx.appcompat.widget.a0
    public void k(int i2) {
        y();
        if (i2 == 2) {
            this.f118g.t();
        } else if (i2 == 5) {
            this.f118g.u();
        } else {
            if (i2 != 109) {
                return;
            }
            setOverlayMode(true);
        }
    }

    @Override // androidx.appcompat.widget.a0
    public void l() {
        y();
        this.f118g.i();
    }

    @Override // android.view.View
    protected void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        u(getContext());
        g.e.j.o.r(this);
    }

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

    @Override // android.view.ViewGroup, android.view.View
    protected void onLayout(boolean z, int i2, int i3, int i4, int i5) {
        int childCount = getChildCount();
        int paddingLeft = getPaddingLeft();
        getPaddingRight();
        int paddingTop = getPaddingTop();
        getPaddingBottom();
        for (int i6 = 0; i6 < childCount; i6++) {
            View childAt = getChildAt(i6);
            if (childAt.getVisibility() != 8) {
                e eVar = (e) childAt.getLayoutParams();
                int measuredWidth = childAt.getMeasuredWidth();
                int measuredHeight = childAt.getMeasuredHeight();
                int i7 = ((ViewGroup.MarginLayoutParams) eVar).leftMargin + paddingLeft;
                int i8 = ((ViewGroup.MarginLayoutParams) eVar).topMargin + paddingTop;
                childAt.layout(i7, i8, measuredWidth + i7, measuredHeight + i8);
            }
        }
    }

    @Override // android.view.View
    protected void onMeasure(int i2, int i3) {
        int measuredHeight;
        y();
        measureChildWithMargins(this.f, i2, 0, i3, 0);
        e eVar = (e) this.f.getLayoutParams();
        int iMax = Math.max(0, this.f.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) eVar).leftMargin + ((ViewGroup.MarginLayoutParams) eVar).rightMargin);
        int iMax2 = Math.max(0, this.f.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) eVar).topMargin + ((ViewGroup.MarginLayoutParams) eVar).bottomMargin);
        int iCombineMeasuredStates = View.combineMeasuredStates(0, this.f.getMeasuredState());
        boolean z = (g.e.j.o.i(this) & 256) != 0;
        if (z) {
            measuredHeight = this.b;
            if (this.f122k && this.f.getTabContainer() != null) {
                measuredHeight += this.b;
            }
        } else {
            measuredHeight = this.f.getVisibility() != 8 ? this.f.getMeasuredHeight() : 0;
        }
        this.r.set(this.p);
        this.u.set(this.s);
        if (this.f121j || z) {
            Rect rect = this.u;
            rect.top += measuredHeight;
            rect.bottom += 0;
        } else {
            Rect rect2 = this.r;
            rect2.top += measuredHeight;
            rect2.bottom += 0;
        }
        p(this.e, this.r, true, true, true, true);
        if (!this.v.equals(this.u)) {
            this.v.set(this.u);
            this.e.a(this.u);
        }
        measureChildWithMargins(this.e, i2, 0, i3, 0);
        e eVar2 = (e) this.e.getLayoutParams();
        int iMax3 = Math.max(iMax, this.e.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) eVar2).leftMargin + ((ViewGroup.MarginLayoutParams) eVar2).rightMargin);
        int iMax4 = Math.max(iMax2, this.e.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) eVar2).topMargin + ((ViewGroup.MarginLayoutParams) eVar2).bottomMargin);
        int iCombineMeasuredStates2 = View.combineMeasuredStates(iCombineMeasuredStates, this.e.getMeasuredState());
        setMeasuredDimension(View.resolveSizeAndState(Math.max(iMax3 + getPaddingLeft() + getPaddingRight(), getSuggestedMinimumWidth()), i2, iCombineMeasuredStates2), View.resolveSizeAndState(Math.max(iMax4 + getPaddingTop() + getPaddingBottom(), getSuggestedMinimumHeight()), i3, iCombineMeasuredStates2 << 16));
    }

    @Override // android.view.ViewGroup, android.view.ViewParent, g.e.j.k
    public boolean onNestedFling(View view, float f, float f2, boolean z) {
        if (!this.f123l || !z) {
            return false;
        }
        if (A(f, f2)) {
            o();
        } else {
            z();
        }
        this.f124m = true;
        return true;
    }

    @Override // android.view.ViewGroup, android.view.ViewParent, g.e.j.k
    public boolean onNestedPreFling(View view, float f, float f2) {
        return false;
    }

    @Override // android.view.ViewGroup, android.view.ViewParent, g.e.j.k
    public void onNestedPreScroll(View view, int i2, int i3, int[] iArr) {
    }

    @Override // android.view.ViewGroup, android.view.ViewParent, g.e.j.k
    public void onNestedScroll(View view, int i2, int i3, int i4, int i5) {
        int i6 = this.n + i3;
        this.n = i6;
        setActionBarHideOffset(i6);
    }

    @Override // android.view.ViewGroup, android.view.ViewParent, g.e.j.k
    public void onNestedScrollAccepted(View view, View view2, int i2) {
        this.C.b(view, view2, i2);
        this.n = getActionBarHideOffset();
        t();
        d dVar = this.w;
        if (dVar != null) {
            dVar.b();
        }
    }

    @Override // android.view.ViewGroup, android.view.ViewParent, g.e.j.k
    public boolean onStartNestedScroll(View view, View view2, int i2) {
        if ((i2 & 2) == 0 || this.f.getVisibility() != 0) {
            return false;
        }
        return this.f123l;
    }

    @Override // android.view.ViewGroup, android.view.ViewParent, g.e.j.k
    public void onStopNestedScroll(View view) {
        if (this.f123l && !this.f124m) {
            if (this.n <= this.f.getHeight()) {
                x();
            } else {
                w();
            }
        }
        d dVar = this.w;
        if (dVar != null) {
            dVar.d();
        }
    }

    @Override // android.view.View
    public void onWindowSystemUiVisibilityChanged(int i2) {
        if (Build.VERSION.SDK_INT >= 16) {
            super.onWindowSystemUiVisibilityChanged(i2);
        }
        y();
        int i3 = this.o ^ i2;
        this.o = i2;
        boolean z = (i2 & 4) == 0;
        boolean z2 = (i2 & 256) != 0;
        d dVar = this.w;
        if (dVar != null) {
            dVar.e(!z2);
            if (z || !z2) {
                this.w.a();
            } else {
                this.w.f();
            }
        }
        if ((i3 & 256) == 0 || this.w == null) {
            return;
        }
        g.e.j.o.r(this);
    }

    @Override // android.view.View
    protected void onWindowVisibilityChanged(int i2) {
        super.onWindowVisibilityChanged(i2);
        this.d = i2;
        d dVar = this.w;
        if (dVar != null) {
            dVar.c(i2);
        }
    }

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

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

    public void setActionBarHideOffset(int i2) {
        t();
        this.f.setTranslationY(-Math.max(0, Math.min(i2, this.f.getHeight())));
    }

    public void setActionBarVisibilityCallback(d dVar) {
        this.w = dVar;
        if (getWindowToken() != null) {
            this.w.c(this.d);
            int i2 = this.o;
            if (i2 != 0) {
                onWindowSystemUiVisibilityChanged(i2);
                g.e.j.o.r(this);
            }
        }
    }

    public void setHasNonEmbeddedTabs(boolean z) {
        this.f122k = z;
    }

    public void setHideOnContentScrollEnabled(boolean z) {
        if (z != this.f123l) {
            this.f123l = z;
            if (z) {
                return;
            }
            t();
            setActionBarHideOffset(0);
        }
    }

    public void setIcon(int i2) {
        y();
        this.f118g.setIcon(i2);
    }

    public void setLogo(int i2) {
        y();
        this.f118g.q(i2);
    }

    public void setOverlayMode(boolean z) {
        this.f121j = z;
        this.f120i = z && getContext().getApplicationInfo().targetSdkVersion < 19;
    }

    public void setShowingForActionMode(boolean z) {
    }

    public void setUiOptions(int i2) {
    }

    @Override // androidx.appcompat.widget.a0
    public void setWindowCallback(Window.Callback callback) {
        y();
        this.f118g.setWindowCallback(callback);
    }

    @Override // androidx.appcompat.widget.a0
    public void setWindowTitle(CharSequence charSequence) {
        y();
        this.f118g.setWindowTitle(charSequence);
    }

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

    void t() {
        removeCallbacks(this.A);
        removeCallbacks(this.B);
        ViewPropertyAnimator viewPropertyAnimator = this.y;
        if (viewPropertyAnimator != null) {
            viewPropertyAnimator.cancel();
        }
    }

    public boolean v() {
        return this.f121j;
    }

    void y() {
        if (this.e == null) {
            this.e = (ContentFrameLayout) findViewById(g.a.f.action_bar_activity_content);
            this.f = (ActionBarContainer) findViewById(g.a.f.action_bar_container);
            this.f118g = s(findViewById(g.a.f.action_bar));
        }
    }

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

    public void setIcon(Drawable drawable) {
        y();
        this.f118g.setIcon(drawable);
    }
}
