SnapHelper.java 5.46 KB
package android.support.v7.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.Scroller;

public abstract class SnapHelper
  extends RecyclerView.OnFlingListener
{
  RecyclerView a;
  private Scroller b;
  private final RecyclerView.OnScrollListener c = new RecyclerView.OnScrollListener()
  {
    boolean a = false;
    
    public final void onScrollStateChanged(RecyclerView paramAnonymousRecyclerView, int paramAnonymousInt)
    {
      super.onScrollStateChanged(paramAnonymousRecyclerView, paramAnonymousInt);
      if ((paramAnonymousInt == 0) && (this.a))
      {
        this.a = false;
        SnapHelper.this.a();
      }
    }
    
    public final void onScrolled(RecyclerView paramAnonymousRecyclerView, int paramAnonymousInt1, int paramAnonymousInt2)
    {
      if ((paramAnonymousInt1 != 0) || (paramAnonymousInt2 != 0)) {
        this.a = true;
      }
    }
  };
  
  final void a()
  {
    if (this.a == null) {}
    Object localObject;
    do
    {
      View localView;
      do
      {
        do
        {
          return;
          localObject = this.a.getLayoutManager();
        } while (localObject == null);
        localView = findSnapView((RecyclerView.LayoutManager)localObject);
      } while (localView == null);
      localObject = calculateDistanceToFinalSnap((RecyclerView.LayoutManager)localObject, localView);
    } while ((localObject[0] == 0) && (localObject[1] == 0));
    this.a.smoothScrollBy(localObject[0], localObject[1]);
  }
  
  public void attachToRecyclerView(@Nullable RecyclerView paramRecyclerView)
    throws IllegalStateException
  {
    if (this.a == paramRecyclerView) {}
    do
    {
      return;
      if (this.a != null)
      {
        this.a.removeOnScrollListener(this.c);
        this.a.setOnFlingListener(null);
      }
      this.a = paramRecyclerView;
    } while (this.a == null);
    if (this.a.getOnFlingListener() != null) {
      throw new IllegalStateException("An instance of OnFlingListener already set.");
    }
    this.a.addOnScrollListener(this.c);
    this.a.setOnFlingListener(this);
    this.b = new Scroller(this.a.getContext(), new DecelerateInterpolator());
    a();
  }
  
  @Nullable
  public abstract int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager paramLayoutManager, @NonNull View paramView);
  
  public int[] calculateScrollDistance(int paramInt1, int paramInt2)
  {
    this.b.fling(0, 0, paramInt1, paramInt2, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
    return new int[] { this.b.getFinalX(), this.b.getFinalY() };
  }
  
  @Nullable
  protected LinearSmoothScroller createSnapScroller(RecyclerView.LayoutManager paramLayoutManager)
  {
    if (!(paramLayoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
      return null;
    }
    new LinearSmoothScroller(this.a.getContext())
    {
      protected final float calculateSpeedPerPixel(DisplayMetrics paramAnonymousDisplayMetrics)
      {
        return 100.0F / paramAnonymousDisplayMetrics.densityDpi;
      }
      
      protected final void onTargetFound(View paramAnonymousView, RecyclerView.State paramAnonymousState, RecyclerView.SmoothScroller.Action paramAnonymousAction)
      {
        paramAnonymousView = SnapHelper.this.calculateDistanceToFinalSnap(SnapHelper.this.a.getLayoutManager(), paramAnonymousView);
        int i = paramAnonymousView[0];
        int j = paramAnonymousView[1];
        int k = calculateTimeForDeceleration(Math.max(Math.abs(i), Math.abs(j)));
        if (k > 0) {
          paramAnonymousAction.update(i, j, k, this.mDecelerateInterpolator);
        }
      }
    };
  }
  
  @Nullable
  public abstract View findSnapView(RecyclerView.LayoutManager paramLayoutManager);
  
  public abstract int findTargetSnapPosition(RecyclerView.LayoutManager paramLayoutManager, int paramInt1, int paramInt2);
  
  public boolean onFling(int paramInt1, int paramInt2)
  {
    RecyclerView.LayoutManager localLayoutManager = this.a.getLayoutManager();
    if (localLayoutManager == null) {}
    for (;;)
    {
      return false;
      if (this.a.getAdapter() != null)
      {
        int i = this.a.getMinFlingVelocity();
        if ((Math.abs(paramInt2) > i) || (Math.abs(paramInt1) > i))
        {
          if (!(localLayoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
            paramInt1 = 0;
          }
          while (paramInt1 != 0)
          {
            return true;
            LinearSmoothScroller localLinearSmoothScroller = createSnapScroller(localLayoutManager);
            if (localLinearSmoothScroller == null)
            {
              paramInt1 = 0;
            }
            else
            {
              paramInt1 = findTargetSnapPosition(localLayoutManager, paramInt1, paramInt2);
              if (paramInt1 == -1)
              {
                paramInt1 = 0;
              }
              else
              {
                localLinearSmoothScroller.setTargetPosition(paramInt1);
                localLayoutManager.startSmoothScroll(localLinearSmoothScroller);
                paramInt1 = 1;
              }
            }
          }
        }
      }
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/v7/widget/SnapHelper.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */