package com.google.android.material.appbar;

import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.OverScroller;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

/* JADX INFO: loaded from: classes2.dex */
public abstract class p extends r {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public OverScroller f22208c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f22209d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f22210e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f22211f;

    @Nullable
    private Runnable flingRunnable;

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

    @Nullable
    private VelocityTracker velocityTracker;

    public abstract void A(CoordinatorLayout coordinatorLayout, View view);

    public abstract int B(CoordinatorLayout coordinatorLayout, View view, int i10, int i11, int i12);

    public final void C(CoordinatorLayout coordinatorLayout, View view, int i10) {
        B(coordinatorLayout, view, i10, Integer.MIN_VALUE, Integer.MAX_VALUE);
    }

    @Override // d0.b
    public final boolean k(CoordinatorLayout coordinatorLayout, View view, MotionEvent motionEvent) {
        int iFindPointerIndex;
        if (this.f22212g < 0) {
            this.f22212g = ViewConfiguration.get(coordinatorLayout.getContext()).getScaledTouchSlop();
        }
        if (motionEvent.getActionMasked() == 2 && this.f22209d) {
            int i10 = this.f22210e;
            if (i10 == -1 || (iFindPointerIndex = motionEvent.findPointerIndex(i10)) == -1) {
                return false;
            }
            int y10 = (int) motionEvent.getY(iFindPointerIndex);
            if (Math.abs(y10 - this.f22211f) > this.f22212g) {
                this.f22211f = y10;
                return true;
            }
        }
        if (motionEvent.getActionMasked() == 0) {
            this.f22210e = -1;
            int x10 = (int) motionEvent.getX();
            int y11 = (int) motionEvent.getY();
            boolean z10 = y(view) && coordinatorLayout.m(view, x10, y11);
            this.f22209d = z10;
            if (z10) {
                this.f22211f = y11;
                this.f22210e = motionEvent.getPointerId(0);
                if (this.velocityTracker == null) {
                    this.velocityTracker = VelocityTracker.obtain();
                }
                OverScroller overScroller = this.f22208c;
                if (overScroller != null && !overScroller.isFinished()) {
                    this.f22208c.abortAnimation();
                    return true;
                }
            }
        }
        VelocityTracker velocityTracker = this.velocityTracker;
        if (velocityTracker != null) {
            velocityTracker.addMovement(motionEvent);
        }
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:37:0x00db  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00e4  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00eb A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:47:? A[ADDED_TO_REGION, RETURN, SYNTHETIC] */
    @Override // d0.b
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean v(CoordinatorLayout coordinatorLayout, View view, MotionEvent motionEvent) {
        boolean z10;
        VelocityTracker velocityTracker;
        VelocityTracker velocityTracker2;
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked != 1) {
            if (actionMasked == 2) {
                int iFindPointerIndex = motionEvent.findPointerIndex(this.f22210e);
                if (iFindPointerIndex == -1) {
                    return false;
                }
                int y10 = (int) motionEvent.getY(iFindPointerIndex);
                int i10 = this.f22211f - y10;
                this.f22211f = y10;
                AppBarLayout appBarLayout = (AppBarLayout) view;
                B(coordinatorLayout, view, z() - i10, appBarLayout.getTopInset() + (-appBarLayout.getDownNestedScrollRange()), 0);
            } else if (actionMasked != 3) {
                if (actionMasked == 6) {
                    int i11 = motionEvent.getActionIndex() == 0 ? 1 : 0;
                    this.f22210e = motionEvent.getPointerId(i11);
                    this.f22211f = (int) (motionEvent.getY(i11) + 0.5f);
                }
            }
            z10 = false;
            velocityTracker2 = this.velocityTracker;
            if (velocityTracker2 != null) {
                velocityTracker2.addMovement(motionEvent);
            }
            return !this.f22209d || z10;
        }
        VelocityTracker velocityTracker3 = this.velocityTracker;
        if (velocityTracker3 != null) {
            velocityTracker3.addMovement(motionEvent);
            this.velocityTracker.computeCurrentVelocity(1000);
            float yVelocity = this.velocityTracker.getYVelocity(this.f22210e);
            int i12 = -((AppBarLayout) view).getTotalScrollRange();
            Runnable runnable = this.flingRunnable;
            if (runnable != null) {
                view.removeCallbacks(runnable);
                this.flingRunnable = null;
            }
            if (this.f22208c == null) {
                this.f22208c = new OverScroller(view.getContext());
            }
            this.f22208c.fling(0, w(), 0, Math.round(yVelocity), 0, 0, i12, 0);
            if (this.f22208c.computeScrollOffset()) {
                n0.a aVar = new n0.a(this, coordinatorLayout, view, 20);
                this.flingRunnable = aVar;
                view.postOnAnimation(aVar);
            } else {
                A(coordinatorLayout, view);
            }
            z10 = true;
        }
        this.f22209d = false;
        this.f22210e = -1;
        velocityTracker = this.velocityTracker;
        if (velocityTracker != null) {
            velocityTracker.recycle();
            this.velocityTracker = null;
        }
        velocityTracker2 = this.velocityTracker;
        if (velocityTracker2 != null) {
        }
        if (this.f22209d) {
            return true;
        }
        z10 = false;
        this.f22209d = false;
        this.f22210e = -1;
        velocityTracker = this.velocityTracker;
        if (velocityTracker != null) {
        }
        velocityTracker2 = this.velocityTracker;
        if (velocityTracker2 != null) {
        }
        if (this.f22209d) {
        }
    }

    public abstract boolean y(View view);

    public abstract int z();
}
