package com.google.android.material.appbar;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.OverScroller;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.y;

/* JADX INFO: compiled from: HeaderBehavior.java */
/* JADX INFO: loaded from: classes.dex */
abstract class a<V extends View> extends c<V> {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private Runnable f3551d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    OverScroller f3552e;

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

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

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

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

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

    /* JADX INFO: renamed from: com.google.android.material.appbar.a$a, reason: collision with other inner class name */
    /* JADX INFO: compiled from: HeaderBehavior.java */
    private class RunnableC0045a implements Runnable {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private final CoordinatorLayout f3558e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private final V f3559f;

        RunnableC0045a(CoordinatorLayout coordinatorLayout, V v2) {
            this.f3558e = coordinatorLayout;
            this.f3559f = v2;
        }

        @Override // java.lang.Runnable
        public void run() {
            OverScroller overScroller;
            if (this.f3559f == null || (overScroller = a.this.f3552e) == null) {
                return;
            }
            if (!overScroller.computeScrollOffset()) {
                a.this.N(this.f3558e, this.f3559f);
                return;
            }
            a aVar = a.this;
            aVar.P(this.f3558e, this.f3559f, aVar.f3552e.getCurrY());
            y.j0(this.f3559f, this);
        }
    }

    public a() {
        this.f3554g = -1;
        this.f3556i = -1;
    }

    private void I() {
        if (this.f3557j == null) {
            this.f3557j = VelocityTracker.obtain();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:27:0x007b  */
    /* JADX WARN: Removed duplicated region for block: B:30:0x0085  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x008c A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:37:? A[ADDED_TO_REGION, RETURN, SYNTHETIC] */
    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean D(androidx.coordinatorlayout.widget.CoordinatorLayout r12, V r13, android.view.MotionEvent r14) {
        /*
            r11 = this;
            int r0 = r14.getActionMasked()
            r1 = -1
            r2 = 1
            r3 = 0
            if (r0 == r2) goto L4e
            r4 = 2
            if (r0 == r4) goto L2d
            r12 = 3
            if (r0 == r12) goto L72
            r12 = 6
            if (r0 == r12) goto L13
            goto L4c
        L13:
            int r12 = r14.getActionIndex()
            if (r12 != 0) goto L1b
            r12 = r2
            goto L1c
        L1b:
            r12 = r3
        L1c:
            int r13 = r14.getPointerId(r12)
            r11.f3554g = r13
            float r12 = r14.getY(r12)
            r13 = 1056964608(0x3f000000, float:0.5)
            float r12 = r12 + r13
            int r12 = (int) r12
            r11.f3555h = r12
            goto L4c
        L2d:
            int r0 = r11.f3554g
            int r0 = r14.findPointerIndex(r0)
            if (r0 != r1) goto L36
            return r3
        L36:
            float r0 = r14.getY(r0)
            int r0 = (int) r0
            int r1 = r11.f3555h
            int r7 = r1 - r0
            r11.f3555h = r0
            int r8 = r11.K(r13)
            r9 = 0
            r4 = r11
            r5 = r12
            r6 = r13
            r4.O(r5, r6, r7, r8, r9)
        L4c:
            r12 = r3
            goto L81
        L4e:
            android.view.VelocityTracker r0 = r11.f3557j
            if (r0 == 0) goto L72
            r0.addMovement(r14)
            android.view.VelocityTracker r0 = r11.f3557j
            r4 = 1000(0x3e8, float:1.401E-42)
            r0.computeCurrentVelocity(r4)
            android.view.VelocityTracker r0 = r11.f3557j
            int r4 = r11.f3554g
            float r10 = r0.getYVelocity(r4)
            int r0 = r11.L(r13)
            int r8 = -r0
            r9 = 0
            r5 = r11
            r6 = r12
            r7 = r13
            r5.J(r6, r7, r8, r9, r10)
            r12 = r2
            goto L73
        L72:
            r12 = r3
        L73:
            r11.f3553f = r3
            r11.f3554g = r1
            android.view.VelocityTracker r13 = r11.f3557j
            if (r13 == 0) goto L81
            r13.recycle()
            r13 = 0
            r11.f3557j = r13
        L81:
            android.view.VelocityTracker r13 = r11.f3557j
            if (r13 == 0) goto L88
            r13.addMovement(r14)
        L88:
            boolean r11 = r11.f3553f
            if (r11 != 0) goto L90
            if (r12 == 0) goto L8f
            goto L90
        L8f:
            r2 = r3
        L90:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.appbar.a.D(androidx.coordinatorlayout.widget.CoordinatorLayout, android.view.View, android.view.MotionEvent):boolean");
    }

    abstract boolean H(V v2);

    final boolean J(CoordinatorLayout coordinatorLayout, V v2, int i3, int i4, float f3) {
        Runnable runnable = this.f3551d;
        if (runnable != null) {
            v2.removeCallbacks(runnable);
            this.f3551d = null;
        }
        if (this.f3552e == null) {
            this.f3552e = new OverScroller(v2.getContext());
        }
        this.f3552e.fling(0, E(), 0, Math.round(f3), 0, 0, i3, i4);
        if (!this.f3552e.computeScrollOffset()) {
            N(coordinatorLayout, v2);
            return false;
        }
        RunnableC0045a runnableC0045a = new RunnableC0045a(coordinatorLayout, v2);
        this.f3551d = runnableC0045a;
        y.j0(v2, runnableC0045a);
        return true;
    }

    abstract int K(V v2);

    abstract int L(V v2);

    abstract int M();

    abstract void N(CoordinatorLayout coordinatorLayout, V v2);

    final int O(CoordinatorLayout coordinatorLayout, V v2, int i3, int i4, int i5) {
        return Q(coordinatorLayout, v2, M() - i3, i4, i5);
    }

    int P(CoordinatorLayout coordinatorLayout, V v2, int i3) {
        return Q(coordinatorLayout, v2, i3, Integer.MIN_VALUE, Integer.MAX_VALUE);
    }

    abstract int Q(CoordinatorLayout coordinatorLayout, V v2, int i3, int i4, int i5);

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean k(CoordinatorLayout coordinatorLayout, V v2, MotionEvent motionEvent) {
        int iFindPointerIndex;
        if (this.f3556i < 0) {
            this.f3556i = ViewConfiguration.get(coordinatorLayout.getContext()).getScaledTouchSlop();
        }
        if (motionEvent.getActionMasked() == 2 && this.f3553f) {
            int i3 = this.f3554g;
            if (i3 == -1 || (iFindPointerIndex = motionEvent.findPointerIndex(i3)) == -1) {
                return false;
            }
            int y2 = (int) motionEvent.getY(iFindPointerIndex);
            if (Math.abs(y2 - this.f3555h) > this.f3556i) {
                this.f3555h = y2;
                return true;
            }
        }
        if (motionEvent.getActionMasked() == 0) {
            this.f3554g = -1;
            int x2 = (int) motionEvent.getX();
            int y3 = (int) motionEvent.getY();
            boolean z2 = H(v2) && coordinatorLayout.B(v2, x2, y3);
            this.f3553f = z2;
            if (z2) {
                this.f3555h = y3;
                this.f3554g = motionEvent.getPointerId(0);
                I();
                OverScroller overScroller = this.f3552e;
                if (overScroller != null && !overScroller.isFinished()) {
                    this.f3552e.abortAnimation();
                    return true;
                }
            }
        }
        VelocityTracker velocityTracker = this.f3557j;
        if (velocityTracker != null) {
            velocityTracker.addMovement(motionEvent);
        }
        return false;
    }

    public a(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f3554g = -1;
        this.f3556i = -1;
    }
}
