package androidx.recyclerview.widget;

import android.graphics.PointF;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
public abstract class e2 {
    private q1 mLayoutManager;
    private boolean mPendingInitialRun;
    private RecyclerView mRecyclerView;
    private boolean mRunning;
    private boolean mStarted;
    private View mTargetView;
    private int mTargetPosition = -1;
    private final c2 mRecyclingAction = new c2(0, 0, Integer.MIN_VALUE, null);

    @Nullable
    public PointF computeScrollVectorForPosition(int i10) {
        Object layoutManager = getLayoutManager();
        if (layoutManager instanceof d2) {
            return ((d2) layoutManager).computeScrollVectorForPosition(i10);
        }
        return null;
    }

    public View findViewByPosition(int i10) {
        return this.mRecyclerView.mLayout.findViewByPosition(i10);
    }

    public int getChildCount() {
        return this.mRecyclerView.mLayout.getChildCount();
    }

    public int getChildPosition(View view) {
        return this.mRecyclerView.getChildLayoutPosition(view);
    }

    @Nullable
    public q1 getLayoutManager() {
        return this.mLayoutManager;
    }

    public int getTargetPosition() {
        return this.mTargetPosition;
    }

    @Deprecated
    public void instantScrollToPosition(int i10) {
        this.mRecyclerView.scrollToPosition(i10);
    }

    public boolean isPendingInitialRun() {
        return this.mPendingInitialRun;
    }

    public boolean isRunning() {
        return this.mRunning;
    }

    public void normalize(@NonNull PointF pointF) {
        float f10 = pointF.x;
        float f11 = pointF.y;
        float fSqrt = (float) Math.sqrt((f11 * f11) + (f10 * f10));
        pointF.x /= fSqrt;
        pointF.y /= fSqrt;
    }

    public void onAnimation(int i10, int i11) {
        PointF pointFComputeScrollVectorForPosition;
        RecyclerView recyclerView = this.mRecyclerView;
        if (this.mTargetPosition == -1 || recyclerView == null) {
            stop();
        }
        if (this.mPendingInitialRun && this.mTargetView == null && this.mLayoutManager != null && (pointFComputeScrollVectorForPosition = computeScrollVectorForPosition(this.mTargetPosition)) != null) {
            float f10 = pointFComputeScrollVectorForPosition.x;
            if (f10 != 0.0f || pointFComputeScrollVectorForPosition.y != 0.0f) {
                recyclerView.scrollStep((int) Math.signum(f10), (int) Math.signum(pointFComputeScrollVectorForPosition.y), null);
            }
        }
        this.mPendingInitialRun = false;
        View view = this.mTargetView;
        if (view != null) {
            if (getChildPosition(view) == this.mTargetPosition) {
                onTargetFound(this.mTargetView, recyclerView.mState, this.mRecyclingAction);
                this.mRecyclingAction.a(recyclerView);
                stop();
            } else {
                this.mTargetView = null;
            }
        }
        if (this.mRunning) {
            onSeekTargetStep(i10, i11, recyclerView.mState, this.mRecyclingAction);
            c2 c2Var = this.mRecyclingAction;
            boolean z10 = c2Var.f3684d >= 0;
            c2Var.a(recyclerView);
            if (z10 && this.mRunning) {
                this.mPendingInitialRun = true;
                recyclerView.mViewFlinger.b();
            }
        }
    }

    public void onChildAttachedToWindow(View view) {
        if (getChildPosition(view) == getTargetPosition()) {
            this.mTargetView = view;
            int i10 = RecyclerView.HORIZONTAL;
        }
    }

    public abstract void onSeekTargetStep(int i10, int i11, f2 f2Var, c2 c2Var);

    public abstract void onStart();

    public abstract void onStop();

    public abstract void onTargetFound(View view, f2 f2Var, c2 c2Var);

    public void setTargetPosition(int i10) {
        this.mTargetPosition = i10;
    }

    public void start(RecyclerView recyclerView, q1 q1Var) {
        i2 i2Var = recyclerView.mViewFlinger;
        i2Var.f3735g.removeCallbacks(i2Var);
        i2Var.f3731c.abortAnimation();
        this.mRecyclerView = recyclerView;
        this.mLayoutManager = q1Var;
        int i10 = this.mTargetPosition;
        if (i10 == -1) {
            throw new IllegalArgumentException("Invalid target position");
        }
        recyclerView.mState.f3700a = i10;
        this.mRunning = true;
        this.mPendingInitialRun = true;
        this.mTargetView = findViewByPosition(getTargetPosition());
        onStart();
        this.mRecyclerView.mViewFlinger.b();
        this.mStarted = true;
    }

    public final void stop() {
        if (this.mRunning) {
            this.mRunning = false;
            onStop();
            this.mRecyclerView.mState.f3700a = -1;
            this.mTargetView = null;
            this.mTargetPosition = -1;
            this.mPendingInitialRun = false;
            this.mLayoutManager.onSmoothScrollerStopped(this);
            this.mLayoutManager = null;
            this.mRecyclerView = null;
        }
    }
}
