Пример #1
0
  /**
   * @param startChild View closest to start of the list. (top or left)
   * @param endChild View closest to end of the list (bottom or right)
   */
  static int computeScrollOffset(
      RecyclerView.State state,
      OrientationHelper orientation,
      View startChild,
      View endChild,
      RecyclerView.LayoutManager lm,
      boolean smoothScrollbarEnabled,
      boolean reverseLayout) {
    if (lm.getChildCount() == 0
        || state.getItemCount() == 0
        || startChild == null
        || endChild == null) {
      return 0;
    }
    final int minPosition = Math.min(lm.getPosition(startChild), lm.getPosition(endChild));
    final int maxPosition = Math.max(lm.getPosition(startChild), lm.getPosition(endChild));
    final int itemsBefore =
        reverseLayout
            ? Math.max(0, state.getItemCount() - maxPosition - 1)
            : Math.max(0, minPosition - 1);
    if (!smoothScrollbarEnabled) {
      return itemsBefore;
    }
    final int laidOutArea =
        Math.abs(orientation.getDecoratedEnd(endChild) - orientation.getDecoratedStart(startChild));
    final int itemRange = Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1;
    final float avgSizePerRow = (float) laidOutArea / itemRange;

    return Math.round(
        itemsBefore * avgSizePerRow
            + (orientation.getStartAfterPadding() - orientation.getDecoratedStart(startChild)));
  }
 @Override
 public void onRestoreInstanceState(Parcelable state) {
   super.onRestoreInstanceState(state);
   if (state instanceof LayoutManagerSavedState) {
     mUuid = ((LayoutManagerSavedState) state).mUuid;
   }
 }
 @Override
 public void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter) {
   super.onAdapterChanged(oldAdapter, newAdapter);
   mPrevAdapter = oldAdapter;
   mNextAdapter = newAdapter;
   mAdapterChangedCount++;
 }
Пример #4
0
 /**
  * @param startChild View closest to start of the list. (top or left)
  * @param endChild View closest to end of the list (bottom or right)
  */
 static int computeScrollExtent(
     RecyclerView.State state,
     OrientationHelper orientation,
     View startChild,
     View endChild,
     RecyclerView.LayoutManager lm,
     boolean smoothScrollbarEnabled) {
   if (lm.getChildCount() == 0
       || state.getItemCount() == 0
       || startChild == null
       || endChild == null) {
     return 0;
   }
   if (!smoothScrollbarEnabled) {
     return Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1;
   }
   final int extend =
       orientation.getDecoratedEnd(endChild) - orientation.getDecoratedStart(startChild);
   return Math.min(orientation.getTotalSpace(), extend);
 }
Пример #5
0
 /**
  * @param startChild View closest to start of the list. (top or left)
  * @param endChild View closest to end of the list (bottom or right)
  */
 static int computeScrollRange(
     RecyclerView.State state,
     OrientationHelper orientation,
     View startChild,
     View endChild,
     RecyclerView.LayoutManager lm,
     boolean smoothScrollbarEnabled) {
   if (lm.getChildCount() == 0
       || state.getItemCount() == 0
       || startChild == null
       || endChild == null) {
     return 0;
   }
   if (!smoothScrollbarEnabled) {
     return state.getItemCount();
   }
   // smooth scrollbar enabled. try to estimate better.
   final int laidOutArea =
       orientation.getDecoratedEnd(endChild) - orientation.getDecoratedStart(startChild);
   final int laidOutRange = Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1;
   // estimate a size for full list.
   return (int) ((float) laidOutArea / laidOutRange * state.getItemCount());
 }
 static int computeScrollExtent(
     RecyclerView.State paramState,
     OrientationHelper paramOrientationHelper,
     View paramView1,
     View paramView2,
     RecyclerView.LayoutManager paramLayoutManager,
     boolean paramBoolean) {
   if ((paramLayoutManager.getChildCount() == 0)
       || (paramState.getItemCount() == 0)
       || (paramView1 == null)
       || (paramView2 == null)) {
     return 0;
   }
   if (!paramBoolean) {
     return Math.abs(
             paramLayoutManager.getPosition(paramView1)
                 - paramLayoutManager.getPosition(paramView2))
         + 1;
   }
   int i = paramOrientationHelper.getDecoratedEnd(paramView2);
   int j = paramOrientationHelper.getDecoratedStart(paramView1);
   return Math.min(paramOrientationHelper.getTotalSpace(), i - j);
 }
 @Override
 protected int getHorizontalGravity(RecyclerView.LayoutManager layoutManager) {
   boolean rtl = layoutManager.getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL;
   if (mConfig.mOrientation == VERTICAL) {
     if (rtl) {
       return Gravity.RIGHT;
     }
     return Gravity.LEFT;
   }
   boolean end = mConfig.mReverseLayout ^ mConfig.mStackFromEnd;
   if (rtl ^ end) {
     return Gravity.RIGHT;
   }
   return Gravity.LEFT;
 }
 static int computeScrollRange(
     RecyclerView.State paramState,
     OrientationHelper paramOrientationHelper,
     View paramView1,
     View paramView2,
     RecyclerView.LayoutManager paramLayoutManager,
     boolean paramBoolean) {
   if ((paramLayoutManager.getChildCount() == 0)
       || (paramState.getItemCount() == 0)
       || (paramView1 == null)
       || (paramView2 == null)) {
     return 0;
   }
   if (!paramBoolean) {
     return paramState.getItemCount();
   }
   int i = paramOrientationHelper.getDecoratedEnd(paramView2);
   int j = paramOrientationHelper.getDecoratedStart(paramView1);
   int k =
       Math.abs(
           paramLayoutManager.getPosition(paramView1)
               - paramLayoutManager.getPosition(paramView2));
   return (int) ((i - j) / (k + 1) * paramState.getItemCount());
 }
 static int computeScrollOffset(
     RecyclerView.State paramState,
     OrientationHelper paramOrientationHelper,
     View paramView1,
     View paramView2,
     RecyclerView.LayoutManager paramLayoutManager,
     boolean paramBoolean1,
     boolean paramBoolean2) {
   int i = 0;
   int j = i;
   if (paramLayoutManager.getChildCount() != 0) {
     j = i;
     if (paramState.getItemCount() != 0) {
       j = i;
       if (paramView1 != null) {
         if (paramView2 != null) {
           break label45;
         }
         j = i;
       }
     }
   }
   return j;
   label45:
   i =
       Math.min(
           paramLayoutManager.getPosition(paramView1), paramLayoutManager.getPosition(paramView2));
   j =
       Math.max(
           paramLayoutManager.getPosition(paramView1), paramLayoutManager.getPosition(paramView2));
   if (paramBoolean2) {}
   for (i = Math.max(0, paramState.getItemCount() - j - 1); ; i = Math.max(0, i)) {
     j = i;
     if (!paramBoolean1) {
       break;
     }
     j =
         Math.abs(
             paramOrientationHelper.getDecoratedEnd(paramView2)
                 - paramOrientationHelper.getDecoratedStart(paramView1));
     int k =
         Math.abs(
             paramLayoutManager.getPosition(paramView1)
                 - paramLayoutManager.getPosition(paramView2));
     float f = j / (k + 1);
     return Math.round(
         i * f
             + (paramOrientationHelper.getStartAfterPadding()
                 - paramOrientationHelper.getDecoratedStart(paramView1)));
   }
 }