package android.support.design.widget;

import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build.VERSION;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import android.support.design.widget.CoordinatorLayout.b;
import android.support.v4.c.a;
import android.support.v4.view.AbsSavedState;
import android.support.v4.view.aa;
import android.support.v4.view.s;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
import java.lang.ref.WeakReference;
import java.util.List;

@b(Behavior.class)
public class AppBarLayout extends LinearLayout {
    private int mk = -1;
    private int ml = -1;
    private int mm = -1;
    boolean mn;
    int mo = 0;
    aa mp;
    List<a> mq;
    private boolean mr;
    boolean ms;
    private int[] mt;

    public static class Behavior extends HeaderBehavior<AppBarLayout> {
        private WeakReference<View> mA;
        private a mB;
        private int mv;
        private ValueAnimator mw;
        private int mx = -1;
        private boolean my;
        private float mz;

        protected static class SavedState extends AbsSavedState {
            public static final Creator<SavedState> CREATOR = new 1();
            int mF;
            float mG;
            boolean mH;

            public SavedState(Parcel parcel, ClassLoader classLoader) {
                super(parcel, classLoader);
                this.mF = parcel.readInt();
                this.mG = parcel.readFloat();
                this.mH = parcel.readByte() != (byte) 0;
            }

            public SavedState(Parcelable parcelable) {
                super(parcelable);
            }

            public void writeToParcel(Parcel parcel, int i) {
                super.writeToParcel(parcel, i);
                parcel.writeInt(this.mF);
                parcel.writeFloat(this.mG);
                parcel.writeByte((byte) (this.mH ? 1 : 0));
            }
        }

        public final /* bridge */ /* synthetic */ boolean G(int i) {
            return super.G(i);
        }

        public final /* synthetic */ void a(CoordinatorLayout coordinatorLayout, View view, View view2, int i) {
            AppBarLayout appBarLayout = (AppBarLayout) view;
            if (i == 0) {
                a(coordinatorLayout, appBarLayout);
            }
            this.mA = new WeakReference(view2);
        }

        public final /* synthetic */ Parcelable b(CoordinatorLayout coordinatorLayout, View view) {
            boolean z = false;
            AppBarLayout appBarLayout = (AppBarLayout) view;
            Parcelable b = super.b(coordinatorLayout, appBarLayout);
            int bB = super.bB();
            int childCount = appBarLayout.getChildCount();
            int i = 0;
            while (i < childCount) {
                View childAt = appBarLayout.getChildAt(i);
                int bottom = childAt.getBottom() + bB;
                if (childAt.getTop() + bB > 0 || bottom < 0) {
                    i++;
                } else {
                    SavedState savedState = new SavedState(b);
                    savedState.mF = i;
                    if (bottom == s.aa(childAt) + appBarLayout.getTopInset()) {
                        z = true;
                    }
                    savedState.mH = z;
                    savedState.mG = ((float) bottom) / ((float) childAt.getHeight());
                    return savedState;
                }
            }
            return b;
        }

        public final /* synthetic */ void b(CoordinatorLayout coordinatorLayout, View view, int i) {
            AppBarLayout appBarLayout = (AppBarLayout) view;
            if (i < 0) {
                b(coordinatorLayout, appBarLayout, i, -appBarLayout.getDownNestedScrollRange(), 0);
            }
        }

        public final /* bridge */ /* synthetic */ int bB() {
            return super.bB();
        }

        /* Access modifiers changed, original: final|synthetic */
        public final /* synthetic */ int c(View view) {
            return ((AppBarLayout) view).getTotalScrollRange();
        }

        /* Access modifiers changed, original: final|synthetic */
        public final /* synthetic */ int d(View view) {
            return -((AppBarLayout) view).getDownNestedScrollRange();
        }

        public Behavior(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
        }

        private void a(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, int i) {
            int abs = Math.abs(bz() - i);
            float abs2 = Math.abs(0.0f);
            if (abs2 > 0.0f) {
                abs = Math.round((((float) abs) / abs2) * 1000.0f) * 3;
            } else {
                abs = (int) (((((float) abs) / ((float) appBarLayout.getHeight())) + 1.0f) * 150.0f);
            }
            if (bz() != i) {
                if (this.mw == null) {
                    this.mw = new ValueAnimator();
                    this.mw.setInterpolator(a.mj);
                    this.mw.addUpdateListener(new 1(this, coordinatorLayout, appBarLayout));
                } else {
                    this.mw.cancel();
                }
                this.mw.setDuration((long) Math.min(abs, 600));
                this.mw.setIntValues(new int[]{r1, i});
                this.mw.start();
            } else if (this.mw != null && this.mw.isRunning()) {
                this.mw.cancel();
            }
        }

        private void a(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout) {
            int i;
            int bz = bz();
            int childCount = appBarLayout.getChildCount();
            for (i = 0; i < childCount; i++) {
                View childAt = appBarLayout.getChildAt(i);
                if (childAt.getTop() <= (-bz) && childAt.getBottom() >= (-bz)) {
                    childCount = i;
                    break;
                }
            }
            childCount = -1;
            if (childCount >= 0) {
                View childAt2 = appBarLayout.getChildAt(childCount);
                int i2 = ((LayoutParams) childAt2.getLayoutParams()).mI;
                if ((i2 & 17) == 17) {
                    int i3 = -childAt2.getTop();
                    i = -childAt2.getBottom();
                    if (childCount == appBarLayout.getChildCount() - 1) {
                        i += appBarLayout.getTopInset();
                    }
                    if (l(i2, 2)) {
                        i += s.aa(childAt2);
                    } else if (l(i2, 5)) {
                        childCount = s.aa(childAt2) + i;
                        if (bz < childCount) {
                            i3 = childCount;
                        } else {
                            i = childCount;
                        }
                    }
                    if (bz >= (i + i3) / 2) {
                        i = i3;
                    }
                    a(coordinatorLayout, appBarLayout, a.clamp(i, -appBarLayout.getTotalScrollRange(), 0));
                }
            }
        }

        private static boolean l(int i, int i2) {
            return (i & i2) == i2;
        }

        /* JADX WARNING: Removed duplicated region for block: B:58:? A:{SYNTHETIC, RETURN} */
        /* JADX WARNING: Removed duplicated region for block: B:45:0x00b1  */
        /* JADX WARNING: Removed duplicated region for block: B:19:0x0048  */
        /* JADX WARNING: Removed duplicated region for block: B:56:? A:{SYNTHETIC, RETURN} */
        /* JADX WARNING: Removed duplicated region for block: B:22:0x0054  */
        /* JADX WARNING: Removed duplicated region for block: B:19:0x0048  */
        /* JADX WARNING: Removed duplicated region for block: B:45:0x00b1  */
        /* JADX WARNING: Removed duplicated region for block: B:22:0x0054  */
        /* JADX WARNING: Removed duplicated region for block: B:56:? A:{SYNTHETIC, RETURN} */
        private static void a(android.support.design.widget.CoordinatorLayout r7, android.support.design.widget.AppBarLayout r8, int r9, int r10, boolean r11) {
            /*
            r1 = 1;
            r2 = 0;
            r4 = java.lang.Math.abs(r9);
            r5 = r8.getChildCount();
            r3 = r2;
        L_0x000b:
            if (r3 >= r5) goto L_0x0097;
        L_0x000d:
            r0 = r8.getChildAt(r3);
            r6 = r0.getTop();
            if (r4 < r6) goto L_0x0092;
        L_0x0017:
            r6 = r0.getBottom();
            if (r4 > r6) goto L_0x0092;
        L_0x001d:
            r3 = r0;
        L_0x001e:
            if (r3 == 0) goto L_0x0091;
        L_0x0020:
            r0 = r3.getLayoutParams();
            r0 = (android.support.design.widget.AppBarLayout.LayoutParams) r0;
            r0 = r0.mI;
            r4 = r0 & 1;
            if (r4 == 0) goto L_0x00b7;
        L_0x002c:
            r4 = android.support.v4.view.s.aa(r3);
            if (r10 <= 0) goto L_0x009c;
        L_0x0032:
            r5 = r0 & 12;
            if (r5 == 0) goto L_0x009c;
        L_0x0036:
            r0 = -r9;
            r3 = r3.getBottom();
            r3 = r3 - r4;
            r4 = r8.getTopInset();
            r3 = r3 - r4;
            if (r0 < r3) goto L_0x009a;
        L_0x0043:
            r0 = r1;
        L_0x0044:
            r3 = r8.ms;
            if (r3 == r0) goto L_0x00b1;
        L_0x0048:
            r8.ms = r0;
            r8.refreshDrawableState();
            r0 = r1;
        L_0x004e:
            r3 = android.os.Build.VERSION.SDK_INT;
            r4 = 11;
            if (r3 < r4) goto L_0x0091;
        L_0x0054:
            if (r11 != 0) goto L_0x008e;
        L_0x0056:
            if (r0 == 0) goto L_0x0091;
        L_0x0058:
            r0 = r7.pq;
            r0 = r0.J(r8);
            r3 = r7.ps;
            r3.clear();
            if (r0 == 0) goto L_0x006a;
        L_0x0065:
            r3 = r7.ps;
            r3.addAll(r0);
        L_0x006a:
            r4 = r7.ps;
            r5 = r4.size();
            r3 = r2;
        L_0x0071:
            if (r3 >= r5) goto L_0x008c;
        L_0x0073:
            r0 = r4.get(r3);
            r0 = (android.view.View) r0;
            r0 = r0.getLayoutParams();
            r0 = (android.support.design.widget.CoordinatorLayout.d) r0;
            r0 = r0.pH;
            r6 = r0 instanceof android.support.design.widget.AppBarLayout.ScrollingViewBehavior;
            if (r6 == 0) goto L_0x00b3;
        L_0x0085:
            r0 = (android.support.design.widget.AppBarLayout.ScrollingViewBehavior) r0;
            r0 = r0.qV;
            if (r0 == 0) goto L_0x008c;
        L_0x008b:
            r2 = r1;
        L_0x008c:
            if (r2 == 0) goto L_0x0091;
        L_0x008e:
            r8.jumpDrawablesToCurrentState();
        L_0x0091:
            return;
        L_0x0092:
            r0 = r3 + 1;
            r3 = r0;
            goto L_0x000b;
        L_0x0097:
            r0 = 0;
            r3 = r0;
            goto L_0x001e;
        L_0x009a:
            r0 = r2;
            goto L_0x0044;
        L_0x009c:
            r0 = r0 & 2;
            if (r0 == 0) goto L_0x00b7;
        L_0x00a0:
            r0 = -r9;
            r3 = r3.getBottom();
            r3 = r3 - r4;
            r4 = r8.getTopInset();
            r3 = r3 - r4;
            if (r0 < r3) goto L_0x00af;
        L_0x00ad:
            r0 = r1;
            goto L_0x0044;
        L_0x00af:
            r0 = r2;
            goto L_0x0044;
        L_0x00b1:
            r0 = r2;
            goto L_0x004e;
        L_0x00b3:
            r0 = r3 + 1;
            r3 = r0;
            goto L_0x0071;
        L_0x00b7:
            r0 = r2;
            goto L_0x0044;
            */
            throw new UnsupportedOperationException("Method not decompiled: android.support.design.widget.AppBarLayout$Behavior.a(android.support.design.widget.CoordinatorLayout, android.support.design.widget.AppBarLayout, int, int, boolean):void");
        }

        /* Access modifiers changed, original: final */
        public final int bz() {
            return super.bB() + this.mv;
        }

        /* Access modifiers changed, original: final|synthetic */
        public final /* synthetic */ boolean bA() {
            if (this.mB != null) {
                return this.mB.bC();
            }
            if (this.mA != null) {
                View view = (View) this.mA.get();
                if (view == null || !view.isShown() || view.canScrollVertically(-1)) {
                    return false;
                }
            }
            return true;
        }
    }

    public static class LayoutParams extends android.widget.LinearLayout.LayoutParams {
        int mI = 1;
        Interpolator mJ;

        public LayoutParams(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, android.support.design.a.a.AppBarLayout_Layout);
            this.mI = obtainStyledAttributes.getInt(0, 0);
            if (obtainStyledAttributes.hasValue(1)) {
                this.mJ = AnimationUtils.loadInterpolator(context, obtainStyledAttributes.getResourceId(1, 0));
            }
            obtainStyledAttributes.recycle();
        }

        public LayoutParams() {
            super(-1, -2);
        }

        public LayoutParams(android.view.ViewGroup.LayoutParams layoutParams) {
            super(layoutParams);
        }

        public LayoutParams(MarginLayoutParams marginLayoutParams) {
            super(marginLayoutParams);
        }

        public LayoutParams(android.widget.LinearLayout.LayoutParams layoutParams) {
            super(layoutParams);
        }
    }

    public AppBarLayout(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        setOrientation(1);
        o.G(context);
        if (VERSION.SDK_INT >= 21) {
            r.v(this);
            r.a(this, attributeSet);
        }
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, android.support.design.a.a.AppBarLayout, 0, 2131493821);
        s.a(this, obtainStyledAttributes.getDrawable(0));
        if (obtainStyledAttributes.hasValue(4)) {
            d(obtainStyledAttributes.getBoolean(4, false), false, false);
        }
        if (VERSION.SDK_INT >= 21 && obtainStyledAttributes.hasValue(3)) {
            r.b(this, (float) obtainStyledAttributes.getDimensionPixelSize(3, 0));
        }
        if (VERSION.SDK_INT >= 26) {
            if (obtainStyledAttributes.hasValue(2)) {
                setKeyboardNavigationCluster(obtainStyledAttributes.getBoolean(2, false));
            }
            if (obtainStyledAttributes.hasValue(1)) {
                setTouchscreenBlocksFocus(obtainStyledAttributes.getBoolean(1, false));
            }
        }
        obtainStyledAttributes.recycle();
        s.a(this, new 1(this));
    }

    /* Access modifiers changed, original: protected */
    public void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        by();
    }

    /* Access modifiers changed, original: protected */
    public void onLayout(boolean z, int i, int i2, int i3, int i4) {
        int i5;
        boolean z2;
        super.onLayout(z, i, i2, i3, i4);
        by();
        this.mn = false;
        int childCount = getChildCount();
        for (i5 = 0; i5 < childCount; i5++) {
            if (((LayoutParams) getChildAt(i5).getLayoutParams()).mJ != null) {
                this.mn = true;
                break;
            }
        }
        childCount = getChildCount();
        for (i5 = 0; i5 < childCount; i5++) {
            LayoutParams layoutParams = (LayoutParams) getChildAt(i5).getLayoutParams();
            if ((layoutParams.mI & 1) != 1 || (layoutParams.mI & 10) == 0) {
                z2 = false;
            } else {
                z2 = true;
            }
            if (z2) {
                z2 = true;
                break;
            }
        }
        z2 = false;
        if (this.mr != z2) {
            this.mr = z2;
            refreshDrawableState();
        }
    }

    /* Access modifiers changed, original: final */
    public final void by() {
        this.mk = -1;
        this.ml = -1;
        this.mm = -1;
    }

    public void setOrientation(int i) {
        if (i != 1) {
            throw new IllegalArgumentException("AppBarLayout is always vertical and does not support horizontal orientation");
        }
        super.setOrientation(i);
    }

    public void setExpanded(boolean z) {
        d(z, s.as(this), true);
    }

    /* Access modifiers changed, original: final */
    public final void d(boolean z, boolean z2, boolean z3) {
        int i = 0;
        int i2 = (z2 ? 4 : 0) | (z ? 1 : 2);
        if (z3) {
            i = 8;
        }
        this.mo = i | i2;
        requestLayout();
    }

    /* Access modifiers changed, original: protected */
    public boolean checkLayoutParams(android.view.ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof LayoutParams;
    }

    private LayoutParams c(AttributeSet attributeSet) {
        return new LayoutParams(getContext(), attributeSet);
    }

    private static LayoutParams a(android.view.ViewGroup.LayoutParams layoutParams) {
        if (VERSION.SDK_INT >= 19 && (layoutParams instanceof android.widget.LinearLayout.LayoutParams)) {
            return new LayoutParams((android.widget.LinearLayout.LayoutParams) layoutParams);
        }
        if (layoutParams instanceof MarginLayoutParams) {
            return new LayoutParams((MarginLayoutParams) layoutParams);
        }
        return new LayoutParams(layoutParams);
    }

    public final int getTotalScrollRange() {
        if (this.mk != -1) {
            return this.mk;
        }
        int aa;
        int childCount = getChildCount();
        int i = 0;
        for (int i2 = 0; i2 < childCount; i2++) {
            View childAt = getChildAt(i2);
            LayoutParams layoutParams = (LayoutParams) childAt.getLayoutParams();
            int measuredHeight = childAt.getMeasuredHeight();
            int i3 = layoutParams.mI;
            if ((i3 & 1) == 0) {
                break;
            }
            i += layoutParams.bottomMargin + (measuredHeight + layoutParams.topMargin);
            if ((i3 & 2) != 0) {
                aa = i - s.aa(childAt);
                break;
            }
        }
        aa = i;
        aa = Math.max(0, aa - getTopInset());
        this.mk = aa;
        return aa;
    }

    /* Access modifiers changed, original: 0000 */
    public int getUpNestedPreScrollRange() {
        return getTotalScrollRange();
    }

    /* Access modifiers changed, original: 0000 */
    public int getDownNestedPreScrollRange() {
        if (this.ml != -1) {
            return this.ml;
        }
        int i;
        int childCount = getChildCount() - 1;
        int i2 = 0;
        while (childCount >= 0) {
            View childAt = getChildAt(childCount);
            LayoutParams layoutParams = (LayoutParams) childAt.getLayoutParams();
            int measuredHeight = childAt.getMeasuredHeight();
            int i3 = layoutParams.mI;
            if ((i3 & 5) != 5) {
                if (i2 > 0) {
                    break;
                }
                i = i2;
            } else {
                i = (layoutParams.bottomMargin + layoutParams.topMargin) + i2;
                if ((i3 & 8) != 0) {
                    i += s.aa(childAt);
                } else if ((i3 & 2) != 0) {
                    i += measuredHeight - s.aa(childAt);
                } else {
                    i += measuredHeight - getTopInset();
                }
            }
            childCount--;
            i2 = i;
        }
        i = Math.max(0, i2);
        this.ml = i;
        return i;
    }

    /* Access modifiers changed, original: 0000 */
    public int getDownNestedScrollRange() {
        if (this.mm != -1) {
            return this.mm;
        }
        int i;
        int childCount = getChildCount();
        int i2 = 0;
        for (int i3 = 0; i3 < childCount; i3++) {
            View childAt = getChildAt(i3);
            LayoutParams layoutParams = (LayoutParams) childAt.getLayoutParams();
            int measuredHeight = childAt.getMeasuredHeight() + (layoutParams.topMargin + layoutParams.bottomMargin);
            i = layoutParams.mI;
            if ((i & 1) == 0) {
                break;
            }
            i2 += measuredHeight;
            if ((i & 2) != 0) {
                i = i2 - (s.aa(childAt) + getTopInset());
                break;
            }
        }
        i = i2;
        i = Math.max(0, i);
        this.mm = i;
        return i;
    }

    /* Access modifiers changed, original: final */
    public final void F(int i) {
        if (this.mq != null) {
            int size = this.mq.size();
            for (int i2 = 0; i2 < size; i2++) {
                a aVar = (a) this.mq.get(i2);
                if (aVar != null) {
                    aVar.H(i);
                }
            }
        }
    }

    /* Access modifiers changed, original: final */
    public final int getMinimumHeightForVisibleOverlappingContent() {
        int topInset = getTopInset();
        int aa = s.aa(this);
        if (aa != 0) {
            return (aa * 2) + topInset;
        }
        aa = getChildCount();
        aa = aa > 0 ? s.aa(getChildAt(aa - 1)) : 0;
        if (aa != 0) {
            return (aa * 2) + topInset;
        }
        return getHeight() / 3;
    }

    /* Access modifiers changed, original: protected */
    public int[] onCreateDrawableState(int i) {
        if (this.mt == null) {
            this.mt = new int[2];
        }
        int[] iArr = this.mt;
        int[] onCreateDrawableState = super.onCreateDrawableState(iArr.length + i);
        iArr[0] = this.mr ? 2130772103 : -2130772103;
        int i2 = (this.mr && this.ms) ? 2130772102 : -2130772102;
        iArr[1] = i2;
        return mergeDrawableStates(onCreateDrawableState, iArr);
    }

    @Deprecated
    public void setTargetElevation(float f) {
        if (VERSION.SDK_INT >= 21) {
            r.b(this, f);
        }
    }

    @Deprecated
    public float getTargetElevation() {
        return 0.0f;
    }

    /* Access modifiers changed, original: 0000 */
    public int getPendingAction() {
        return this.mo;
    }

    /* Access modifiers changed, original: final */
    public final int getTopInset() {
        return this.mp != null ? this.mp.getSystemWindowInsetTop() : 0;
    }
}
