content: package androidx.recyclerview.widget;
  
  import android.content.Context;
  import android.graphics.PointF;
  import android.util.DisplayMetrics;
  import android.view.View;
  import android.view.animation.DecelerateInterpolator;
  import android.view.animation.LinearInterpolator;
  import androidx.recyclerview.widget.RecyclerView;
  
  public class LinearSmoothScroller extends RecyclerView.SmoothScroller {
      private static final boolean DEBUG = false;
      private static final float MILLISECONDS_PER_INCH = 25.0f;
      public static final int SNAP_TO_ANY = 0;
      public static final int SNAP_TO_END = 1;
      public static final int SNAP_TO_START = -1;
      private static final float TARGET_SEEK_EXTRA_SCROLL_RATIO = 1.2f;
      private static final int TARGET_SEEK_SCROLL_DISTANCE_PX = 10000;
      protected final DecelerateInterpolator mDecelerateInterpolator = new DecelerateInterpolator();
      private final DisplayMetrics mDisplayMetrics;
      private boolean mHasCalculatedMillisPerPixel = false;
      protected int mInterimTargetDx = 0;
      protected int mInterimTargetDy = 0;
      protected final LinearInterpolator mLinearInterpolator = new LinearInterpolator();
      private float mMillisPerPixel;
      protected PointF mTargetVector;
  
      public LinearSmoothScroller(Context context) {
          this.mDisplayMetrics = context.getResources().getDisplayMetrics();
      }
  
      private int clampApplyScroll(int tmpDt, int dt) {
          int i = tmpDt;
          int tmpDt2 = tmpDt - dt;
          if (i * tmpDt2 <= 0) {
              return 0;
          }
          return tmpDt2;
      }
  
      private float getSpeedPerPixel() {
          if (!this.mHasCalculatedMillisPerPixel) {
              this.mMillisPerPixel = calculateSpeedPerPixel(this.mDisplayMetrics);
              this.mHasCalculatedMillisPerPixel = true;
          }
          return this.mMillisPerPixel;
      }
  
      public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) {
          switch (snapPreference) {
              case -1:
                  return boxStart - viewStart;
              case 0:
                  int i = boxStart - viewStart;
                  if (i > 0) {
                      return i;
                  }
                  int i2 = boxEnd - viewEnd;
                  if (i2 < 0) {
                      return i2;
                  }
                  return 0;
              case 1:
                  return boxEnd - viewEnd;
              default:
                  throw new IllegalArgumentException("snap preference should be one of the constants defined in SmoothScroller, starting with SNAP_");
          }
      }
  
      public int calculateDxToMakeVisible(View view, int snapPreference) {
          RecyclerView.LayoutManager layoutManager = getLayoutManager();
          if (layoutManager == null || !layoutManager.canScrollHorizontally()) {
              return 0;
          }
          RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
          return calculateDtToFit(layoutManager.getDecoratedLeft(view) - layoutParams.leftMargin, layoutManager.getDecoratedRight(view) + layoutParams.rightMargin, layoutManager.getPaddingLeft(), layoutManager.getWidth() - layoutManager.getPaddingRight(), snapPreference);
      }
  
      public int calculateDyToMakeVisible(View view, int snapPreference) {
          RecyclerView.LayoutManager layoutManager = getLayoutManager();
          if (layoutManager == null || !layoutManager.canScrollVertically()) {
              return 0;
          }
          RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
          return calculateDtToFit(layoutManager.getDecoratedTop(view) - layoutParams.topMargin, layoutManager.getDecoratedBottom(view) + layoutParams.bottomMargin, layoutManager.getPaddingTop(), layoutManager.getHeight() - layoutManager.getPaddingBottom(), snapPreference);
      }
  
      /* access modifiers changed from: protected */
      public float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
          return MILLISECONDS_PER_INCH / ((float) displayMetrics.densityDpi);
      }
  
      /* access modifiers changed from: protected */
      public int calculateTimeForDeceleration(int dx) {
          return (int) Math.ceil(((double) calculateTimeForScrolling(dx)) / 0.3356d);
      }
  
      /* access modifiers changed from: protected */
      public int calculateTimeForScrolling(int dx) {
          return (int) Math.ceil((double) (((float) Math.abs(dx)) * getSpeedPerPixel()));
      }
  
      /* access modifiers changed from: protected */
      public int getHorizontalSnapPreference() {
          PointF pointF = this.mTargetVector;
          if (pointF == null || pointF.x == 0.0f) {
              return 0;
          }
          return this.mTargetVector.x > 0.0f ? 1 : -1;
      }
  
      /* access modifiers changed from: protected */
      public int getVerticalSnapPreference() {
          PointF pointF = this.mTargetVector;
          if (pointF == null || pointF.y == 0.0f) {
              return 0;
          }
          return this.mTargetVector.y > 0.0f ? 1 : -1;
      }
  
      /* access modifiers changed from: protected */
      public void onSeekTargetStep(int dx, int dy, RecyclerView.State state, RecyclerView.SmoothScroller.Action action) {
          if (getChildCount() == 0) {
              stop();
              return;
          }
          this.mInterimTargetDx = clampApplyScroll(this.mInterimTargetDx, dx);
          int clampApplyScroll = clampApplyScroll(this.mInterimTargetDy, dy);
          this.mInterimTargetDy = clampApplyScroll;
          if (this.mInterimTargetDx == 0 && clampApplyScroll == 0) {
              updateActionForInterimTarget(action);
          }
      }
  
      /* access modifiers changed from: protected */
      public void onStart() {
      }
  
      /* access modifiers changed from: protected */
      public void onStop() {
          this.mInterimTargetDy = 0;
          this.mInterimTargetDx = 0;
          this.mTargetVector = null;
      }
  
      /* access modifiers changed from: protected */
      public void onTargetFound(View targetView, RecyclerView.State state, RecyclerView.SmoothScroller.Action action) {
          int calculateDxToMakeVisible = calculateDxToMakeVisible(targetView, getHorizontalSnapPreference());
          int calculateDyToMakeVisible = calculateDyToMakeVisible(targetView, getVerticalSnapPreference());
          int calculateTimeForDeceleration = calculateTimeForDeceleration((int) Math.sqrt((double) ((calculateDxToMakeVisible * calculateDxToMakeVisible) + (calculateDyToMakeVisible * calculateDyToMakeVisible))));
          if (calculateTimeForDeceleration > 0) {
              action.update(-calculateDxToMakeVisible, -calculateDyToMakeVisible, calculateTimeForDeceleration, this.mDecelerateInterpolator);
          }
      }
  
      /* access modifiers changed from: protected */
      public void updateActionForInterimTarget(RecyclerView.SmoothScroller.Action action) {
          PointF computeScrollVectorForPosition = computeScrollVectorForPosition(getTargetPosition());
          if (computeScrollVectorForPosition == null || (computeScrollVectorForPosition.x == 0.0f && computeScrollVectorForPosition.y == 0.0f)) {
              action.jumpTo(getTargetPosition());
              stop();
              return;
          }
          normalize(computeScrollVectorForPosition);
          this.mTargetVector = computeScrollVectorForPosition;
          this.mInterimTargetDx = (int) (computeScrollVectorForPosition.x * 10000.0f);
          this.mInterimTargetDy = (int) (computeScrollVectorForPosition.y * 10000.0f);
          action.update((int) (((float) this.mInterimTargetDx) * TARGET_SEEK_EXTRA_SCROLL_RATIO), (int) (((float) this.mInterimTargetDy) * TARGET_SEEK_EXTRA_SCROLL_RATIO), (int) (((float) calculateTimeForScrolling(TARGET_SEEK_SCROLL_DISTANCE_PX)) * TARGET_SEEK_EXTRA_SCROLL_RATIO), this.mLinearInterpolator);
      }
  }
  