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 c.f.l.t;
import com.cvte.vman.impl.FwUpgradeManager;

/* 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 f1698d;

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

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

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

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

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

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

    /* 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: b, reason: collision with root package name */
        private final CoordinatorLayout f1705b;

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

        RunnableC0045a(CoordinatorLayout coordinatorLayout, V v) {
            this.f1705b = coordinatorLayout;
            this.f1706f = v;
        }

        @Override // java.lang.Runnable
        public void run() {
            OverScroller overScroller;
            if (this.f1706f == null || (overScroller = a.this.f1699e) == null) {
                return;
            }
            if (!overScroller.computeScrollOffset()) {
                a.this.M(this.f1705b, this.f1706f);
                return;
            }
            a aVar = a.this;
            aVar.O(this.f1705b, this.f1706f, aVar.f1699e.getCurrY());
            t.R(this.f1706f, this);
        }
    }

    public a() {
        this.f1701g = -1;
        this.f1703i = -1;
    }

    private void H() {
        if (this.f1704j == null) {
            this.f1704j = VelocityTracker.obtain();
        }
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean C(CoordinatorLayout coordinatorLayout, V v, MotionEvent motionEvent) {
        if (this.f1703i < 0) {
            this.f1703i = ViewConfiguration.get(coordinatorLayout.getContext()).getScaledTouchSlop();
        }
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked != 0) {
            if (actionMasked == 1) {
                VelocityTracker velocityTracker = this.f1704j;
                if (velocityTracker != null) {
                    velocityTracker.addMovement(motionEvent);
                    this.f1704j.computeCurrentVelocity(FwUpgradeManager.TYPE_FW_CVTE_CAMERA);
                    I(coordinatorLayout, v, -K(v), 0, this.f1704j.getYVelocity(this.f1701g));
                }
            } else if (actionMasked == 2) {
                int iFindPointerIndex = motionEvent.findPointerIndex(this.f1701g);
                if (iFindPointerIndex == -1) {
                    return false;
                }
                int y = (int) motionEvent.getY(iFindPointerIndex);
                int i2 = this.f1702h - y;
                if (!this.f1700f) {
                    int iAbs = Math.abs(i2);
                    int i3 = this.f1703i;
                    if (iAbs > i3) {
                        this.f1700f = true;
                        i2 = i2 > 0 ? i2 - i3 : i2 + i3;
                    }
                }
                int i4 = i2;
                if (this.f1700f) {
                    this.f1702h = y;
                    N(coordinatorLayout, v, i4, J(v), 0);
                }
            } else if (actionMasked == 3) {
            }
            this.f1700f = false;
            this.f1701g = -1;
            VelocityTracker velocityTracker2 = this.f1704j;
            if (velocityTracker2 != null) {
                velocityTracker2.recycle();
                this.f1704j = null;
            }
        } else {
            int x = (int) motionEvent.getX();
            int y2 = (int) motionEvent.getY();
            if (!coordinatorLayout.B(v, x, y2) || !G(v)) {
                return false;
            }
            this.f1702h = y2;
            this.f1701g = motionEvent.getPointerId(0);
            H();
        }
        VelocityTracker velocityTracker3 = this.f1704j;
        if (velocityTracker3 != null) {
            velocityTracker3.addMovement(motionEvent);
        }
        return true;
    }

    abstract boolean G(V v);

    final boolean I(CoordinatorLayout coordinatorLayout, V v, int i2, int i3, float f2) {
        Runnable runnable = this.f1698d;
        if (runnable != null) {
            v.removeCallbacks(runnable);
            this.f1698d = null;
        }
        if (this.f1699e == null) {
            this.f1699e = new OverScroller(v.getContext());
        }
        this.f1699e.fling(0, D(), 0, Math.round(f2), 0, 0, i2, i3);
        if (!this.f1699e.computeScrollOffset()) {
            M(coordinatorLayout, v);
            return false;
        }
        RunnableC0045a runnableC0045a = new RunnableC0045a(coordinatorLayout, v);
        this.f1698d = runnableC0045a;
        t.R(v, runnableC0045a);
        return true;
    }

    abstract int J(V v);

    abstract int K(V v);

    abstract int L();

    abstract void M(CoordinatorLayout coordinatorLayout, V v);

    final int N(CoordinatorLayout coordinatorLayout, V v, int i2, int i3, int i4) {
        return P(coordinatorLayout, v, L() - i2, i3, i4);
    }

    int O(CoordinatorLayout coordinatorLayout, V v, int i2) {
        return P(coordinatorLayout, v, i2, Integer.MIN_VALUE, Integer.MAX_VALUE);
    }

    abstract int P(CoordinatorLayout coordinatorLayout, V v, int i2, int i3, int i4);

    /* JADX WARN: Removed duplicated region for block: B:27:0x0051  */
    @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 k(androidx.coordinatorlayout.widget.CoordinatorLayout r5, V r6, android.view.MotionEvent r7) {
        /*
            r4 = this;
            int r0 = r4.f1703i
            if (r0 >= 0) goto L12
            android.content.Context r0 = r5.getContext()
            android.view.ViewConfiguration r0 = android.view.ViewConfiguration.get(r0)
            int r0 = r0.getScaledTouchSlop()
            r4.f1703i = r0
        L12:
            int r0 = r7.getAction()
            r1 = 2
            r2 = 1
            if (r0 != r1) goto L1f
            boolean r0 = r4.f1700f
            if (r0 == 0) goto L1f
            return r2
        L1f:
            int r0 = r7.getActionMasked()
            r3 = 0
            if (r0 == 0) goto L60
            r5 = -1
            if (r0 == r2) goto L51
            if (r0 == r1) goto L2f
            r6 = 3
            if (r0 == r6) goto L51
            goto L83
        L2f:
            int r6 = r4.f1701g
            if (r6 != r5) goto L34
            goto L83
        L34:
            int r6 = r7.findPointerIndex(r6)
            if (r6 != r5) goto L3b
            goto L83
        L3b:
            float r5 = r7.getY(r6)
            int r5 = (int) r5
            int r6 = r4.f1702h
            int r6 = r5 - r6
            int r6 = java.lang.Math.abs(r6)
            int r0 = r4.f1703i
            if (r6 <= r0) goto L83
            r4.f1700f = r2
            r4.f1702h = r5
            goto L83
        L51:
            r4.f1700f = r3
            r4.f1701g = r5
            android.view.VelocityTracker r5 = r4.f1704j
            if (r5 == 0) goto L83
            r5.recycle()
            r5 = 0
            r4.f1704j = r5
            goto L83
        L60:
            r4.f1700f = r3
            float r0 = r7.getX()
            int r0 = (int) r0
            float r1 = r7.getY()
            int r1 = (int) r1
            boolean r2 = r4.G(r6)
            if (r2 == 0) goto L83
            boolean r5 = r5.B(r6, r0, r1)
            if (r5 == 0) goto L83
            r4.f1702h = r1
            int r5 = r7.getPointerId(r3)
            r4.f1701g = r5
            r4.H()
        L83:
            android.view.VelocityTracker r5 = r4.f1704j
            if (r5 == 0) goto L8a
            r5.addMovement(r7)
        L8a:
            boolean r5 = r4.f1700f
            return r5
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.appbar.a.k(androidx.coordinatorlayout.widget.CoordinatorLayout, android.view.View, android.view.MotionEvent):boolean");
    }

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