| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.widget; |
| 18 |
|
| 19 |
import android.annotation.CallSuper; |
| 20 |
import android.annotation.IntDef; |
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.compat.annotation.UnsupportedAppUsage; |
| 24 |
import android.content.Context; |
| 25 |
import android.content.res.TypedArray; |
| 26 |
import android.database.Observable; |
| 27 |
import android.graphics.Canvas; |
| 28 |
import android.graphics.Matrix; |
| 29 |
import android.graphics.PointF; |
| 30 |
import android.graphics.Rect; |
| 31 |
import android.graphics.RectF; |
| 32 |
import android.os.Build; |
| 33 |
import android.os.Bundle; |
| 34 |
import android.os.Parcel; |
| 35 |
import android.os.Parcelable; |
| 36 |
import android.os.SystemClock; |
| 37 |
import android.os.Trace; |
| 38 |
import android.util.AttributeSet; |
| 39 |
import android.util.Log; |
| 40 |
import android.util.SparseArray; |
| 41 |
import android.util.TypedValue; |
| 42 |
import android.view.AbsSavedState; |
| 43 |
import android.view.Display; |
| 44 |
import android.view.FocusFinder; |
| 45 |
import android.view.InputDevice; |
| 46 |
import android.view.MotionEvent; |
| 47 |
import android.view.VelocityTracker; |
| 48 |
import android.view.View; |
| 49 |
import android.view.ViewConfiguration; |
| 50 |
import android.view.ViewGroup; |
| 51 |
import android.view.ViewParent; |
| 52 |
import android.view.accessibility.AccessibilityEvent; |
| 53 |
import android.view.accessibility.AccessibilityManager; |
| 54 |
import android.view.accessibility.AccessibilityNodeInfo; |
| 55 |
import android.view.animation.Interpolator; |
| 56 |
import android.widget.EdgeEffect; |
| 57 |
import android.widget.OverScroller; |
| 58 |
|
| 59 |
import com.android.internal.R; |
| 60 |
import com.android.internal.annotations.VisibleForTesting; |
| 61 |
import com.android.internal.widget.RecyclerView.ItemAnimator.ItemHolderInfo; |
| 62 |
|
| 63 |
import java.lang.annotation.Retention; |
| 64 |
import java.lang.annotation.RetentionPolicy; |
| 65 |
import java.lang.ref.WeakReference; |
| 66 |
import java.lang.reflect.Constructor; |
| 67 |
import java.lang.reflect.InvocationTargetException; |
| 68 |
import java.util.ArrayList; |
| 69 |
import java.util.Collections; |
| 70 |
import java.util.List; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild { |
| 138 |
|
| 139 |
static final String TAG = "RecyclerView"; |
| 140 |
|
| 141 |
static final boolean DEBUG = false; |
| 142 |
|
| 143 |
private static final int[] NESTED_SCROLLING_ATTRS = { android.R.attr.nestedScrollingEnabled }; |
| 144 |
|
| 145 |
private static final int[] CLIP_TO_PADDING_ATTR = {android.R.attr.clipToPadding}; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
static final boolean FORCE_INVALIDATE_DISPLAY_LIST = Build.VERSION.SDK_INT == 18 |
| 155 |
|| Build.VERSION.SDK_INT == 19 || Build.VERSION.SDK_INT == 20; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
static final boolean ALLOW_SIZE_IN_UNSPECIFIED_SPEC = Build.VERSION.SDK_INT >= 23; |
| 162 |
|
| 163 |
static final boolean POST_UPDATES_ON_ANIMATION = Build.VERSION.SDK_INT >= 16; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
private static final boolean ALLOW_THREAD_GAP_WORK = Build.VERSION.SDK_INT >= 21; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
private static final boolean FORCE_ABS_FOCUS_SEARCH_DIRECTION = Build.VERSION.SDK_INT <= 15; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
private static final boolean IGNORE_DETACHED_FOCUSED_CHILD = Build.VERSION.SDK_INT <= 15; |
| 186 |
|
| 187 |
static final boolean DISPATCH_TEMP_DETACH = false; |
| 188 |
public static final int HORIZONTAL = 0; |
| 189 |
public static final int VERTICAL = 1; |
| 190 |
|
| 191 |
public static final int NO_POSITION = -1; |
| 192 |
public static final long NO_ID = -1; |
| 193 |
public static final int INVALID_TYPE = -1; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public static final int TOUCH_SLOP_DEFAULT = 0; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
public static final int TOUCH_SLOP_PAGING = 1; |
| 208 |
|
| 209 |
static final int MAX_SCROLL_DURATION = 2000; |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
static final String TRACE_SCROLL_TAG = "RV Scroll"; |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
private static final String TRACE_ON_LAYOUT_TAG = "RV OnLayout"; |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
private static final String TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG = "RV FullInvalidate"; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
private static final String TRACE_HANDLE_ADAPTER_UPDATES_TAG = "RV PartialInvalidate"; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
static final String TRACE_BIND_VIEW_TAG = "RV OnBindView"; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
static final String TRACE_PREFETCH_TAG = "RV Prefetch"; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
static final String TRACE_NESTED_PREFETCH_TAG = "RV Nested Prefetch"; |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
static final String TRACE_CREATE_VIEW_TAG = "RV CreateView"; |
| 274 |
private static final Class<?>[] LAYOUT_MANAGER_CONSTRUCTOR_SIGNATURE = |
| 275 |
new Class[]{Context.class, AttributeSet.class, int.class, int.class}; |
| 276 |
|
| 277 |
private final RecyclerViewDataObserver mObserver = new RecyclerViewDataObserver(); |
| 278 |
|
| 279 |
final Recycler mRecycler = new Recycler(); |
| 280 |
|
| 281 |
private SavedState mPendingSavedState; |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
AdapterHelper mAdapterHelper; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
ChildHelper mChildHelper; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
final ViewInfoStore mViewInfoStore = new ViewInfoStore(); |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
boolean mClipToPadding; |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
final Runnable mUpdateChildViewsRunnable = new Runnable() { |
| 311 |
@Override |
| 312 |
public void run() { |
| 313 |
if (!mFirstLayoutComplete || isLayoutRequested()) { |
| 314 |
|
| 315 |
return; |
| 316 |
} |
| 317 |
if (!mIsAttached) { |
| 318 |
requestLayout(); |
| 319 |
|
| 320 |
return; |
| 321 |
} |
| 322 |
if (mLayoutFrozen) { |
| 323 |
mLayoutRequestEaten = true; |
| 324 |
return; |
| 325 |
} |
| 326 |
consumePendingUpdateOperations(); |
| 327 |
} |
| 328 |
}; |
| 329 |
|
| 330 |
final Rect mTempRect = new Rect(); |
| 331 |
private final Rect mTempRect2 = new Rect(); |
| 332 |
final RectF mTempRectF = new RectF(); |
| 333 |
Adapter mAdapter; |
| 334 |
@VisibleForTesting LayoutManager mLayout; |
| 335 |
RecyclerListener mRecyclerListener; |
| 336 |
final ArrayList<ItemDecoration> mItemDecorations = new ArrayList<>(); |
| 337 |
private final ArrayList<OnItemTouchListener> mOnItemTouchListeners = |
| 338 |
new ArrayList<>(); |
| 339 |
private OnItemTouchListener mActiveOnItemTouchListener; |
| 340 |
boolean mIsAttached; |
| 341 |
boolean mHasFixedSize; |
| 342 |
@VisibleForTesting boolean mFirstLayoutComplete; |
| 343 |
|
| 344 |
|
| 345 |
private int mEatRequestLayout = 0; |
| 346 |
|
| 347 |
boolean mLayoutRequestEaten; |
| 348 |
boolean mLayoutFrozen; |
| 349 |
private boolean mIgnoreMotionEventTillDown; |
| 350 |
|
| 351 |
|
| 352 |
private int mEatenAccessibilityChangeFlags; |
| 353 |
boolean mAdapterUpdateDuringMeasure; |
| 354 |
|
| 355 |
private final AccessibilityManager mAccessibilityManager; |
| 356 |
private List<OnChildAttachStateChangeListener> mOnChildAttachStateListeners; |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
boolean mDataSetHasChangedAfterLayout = false; |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
private int mLayoutOrScrollCounter = 0; |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
private int mDispatchScrollCounter = 0; |
| 390 |
|
| 391 |
private EdgeEffect mLeftGlow, mTopGlow, mRightGlow, mBottomGlow; |
| 392 |
|
| 393 |
ItemAnimator mItemAnimator = new DefaultItemAnimator(); |
| 394 |
|
| 395 |
private static final int INVALID_POINTER = -1; |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
public static final int SCROLL_STATE_IDLE = 0; |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
public static final int SCROLL_STATE_DRAGGING = 1; |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
public static final int SCROLL_STATE_SETTLING = 2; |
| 415 |
|
| 416 |
static final long FOREVER_NS = Long.MAX_VALUE; |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
private int mScrollState = SCROLL_STATE_IDLE; |
| 421 |
private int mScrollPointerId = INVALID_POINTER; |
| 422 |
private VelocityTracker mVelocityTracker; |
| 423 |
private int mInitialTouchX; |
| 424 |
private int mInitialTouchY; |
| 425 |
private int mLastTouchX; |
| 426 |
private int mLastTouchY; |
| 427 |
private int mTouchSlop; |
| 428 |
private OnFlingListener mOnFlingListener; |
| 429 |
private final int mMinFlingVelocity; |
| 430 |
private final int mMaxFlingVelocity; |
| 431 |
|
| 432 |
private float mScrollFactor = Float.MIN_VALUE; |
| 433 |
private boolean mPreserveFocusAfterLayout = true; |
| 434 |
|
| 435 |
final ViewFlinger mViewFlinger = new ViewFlinger(); |
| 436 |
|
| 437 |
GapWorker mGapWorker; |
| 438 |
GapWorker.LayoutPrefetchRegistryImpl mPrefetchRegistry = |
| 439 |
ALLOW_THREAD_GAP_WORK ? new GapWorker.LayoutPrefetchRegistryImpl() : null; |
| 440 |
|
| 441 |
final State mState = new State(); |
| 442 |
|
| 443 |
private OnScrollListener mScrollListener; |
| 444 |
private List<OnScrollListener> mScrollListeners; |
| 445 |
|
| 446 |
|
| 447 |
boolean mItemsAddedOrRemoved = false; |
| 448 |
boolean mItemsChanged = false; |
| 449 |
private ItemAnimator.ItemAnimatorListener mItemAnimatorListener = |
| 450 |
new ItemAnimatorRestoreListener(); |
| 451 |
boolean mPostedAnimatorRunner = false; |
| 452 |
RecyclerViewAccessibilityDelegate mAccessibilityDelegate; |
| 453 |
private ChildDrawingOrderCallback mChildDrawingOrderCallback; |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
private final int[] mMinMaxLayoutPositions = new int[2]; |
| 458 |
|
| 459 |
private final int[] mScrollOffset = new int[2]; |
| 460 |
private final int[] mScrollConsumed = new int[2]; |
| 461 |
private final int[] mNestedOffsets = new int[2]; |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
@VisibleForTesting |
| 469 |
final List<ViewHolder> mPendingAccessibilityImportanceChange = new ArrayList(); |
| 470 |
|
| 471 |
private Runnable mItemAnimatorRunner = new Runnable() { |
| 472 |
@Override |
| 473 |
public void run() { |
| 474 |
if (mItemAnimator != null) { |
| 475 |
mItemAnimator.runPendingAnimations(); |
| 476 |
} |
| 477 |
mPostedAnimatorRunner = false; |
| 478 |
} |
| 479 |
}; |
| 480 |
|
| 481 |
static final Interpolator sQuinticInterpolator = new Interpolator() { |
| 482 |
@Override |
| 483 |
public float getInterpolation(float t) { |
| 484 |
t -= 1.0f; |
| 485 |
return t * t * t * t * t + 1.0f; |
| 486 |
} |
| 487 |
}; |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
private final ViewInfoStore.ProcessCallback mViewInfoProcessCallback = |
| 493 |
new ViewInfoStore.ProcessCallback() { |
| 494 |
@Override |
| 495 |
public void processDisappeared(ViewHolder viewHolder, @NonNull ItemHolderInfo info, |
| 496 |
@Nullable ItemHolderInfo postInfo) { |
| 497 |
mRecycler.unscrapView(viewHolder); |
| 498 |
animateDisappearance(viewHolder, info, postInfo); |
| 499 |
} |
| 500 |
@Override |
| 501 |
public void processAppeared(ViewHolder viewHolder, |
| 502 |
ItemHolderInfo preInfo, ItemHolderInfo info) { |
| 503 |
animateAppearance(viewHolder, preInfo, info); |
| 504 |
} |
| 505 |
|
| 506 |
@Override |
| 507 |
public void processPersistent(ViewHolder viewHolder, |
| 508 |
@NonNull ItemHolderInfo preInfo, @NonNull ItemHolderInfo postInfo) { |
| 509 |
viewHolder.setIsRecyclable(false); |
| 510 |
if (mDataSetHasChangedAfterLayout) { |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
if (mItemAnimator.animateChange(viewHolder, viewHolder, preInfo, postInfo)) { |
| 515 |
postAnimationRunner(); |
| 516 |
} |
| 517 |
} else if (mItemAnimator.animatePersistence(viewHolder, preInfo, postInfo)) { |
| 518 |
postAnimationRunner(); |
| 519 |
} |
| 520 |
} |
| 521 |
@Override |
| 522 |
public void unused(ViewHolder viewHolder) { |
| 523 |
mLayout.removeAndRecycleView(viewHolder.itemView, mRecycler); |
| 524 |
} |
| 525 |
}; |
| 526 |
|
| 527 |
public RecyclerView(Context context) { |
| 528 |
this(context, null); |
| 529 |
} |
| 530 |
|
| 531 |
public RecyclerView(Context context, @Nullable AttributeSet attrs) { |
| 532 |
this(context, attrs, 0); |
| 533 |
} |
| 534 |
|
| 535 |
public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) { |
| 536 |
super(context, attrs, defStyle); |
| 537 |
if (attrs != null) { |
| 538 |
TypedArray a = context.obtainStyledAttributes(attrs, CLIP_TO_PADDING_ATTR, defStyle, 0); |
| 539 |
mClipToPadding = a.getBoolean(0, true); |
| 540 |
a.recycle(); |
| 541 |
} else { |
| 542 |
mClipToPadding = true; |
| 543 |
} |
| 544 |
setScrollContainer(true); |
| 545 |
setFocusableInTouchMode(true); |
| 546 |
|
| 547 |
final ViewConfiguration vc = ViewConfiguration.get(context); |
| 548 |
mTouchSlop = vc.getScaledTouchSlop(); |
| 549 |
mMinFlingVelocity = vc.getScaledMinimumFlingVelocity(); |
| 550 |
mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); |
| 551 |
setWillNotDraw(getOverScrollMode() == View.OVER_SCROLL_NEVER); |
| 552 |
|
| 553 |
mItemAnimator.setListener(mItemAnimatorListener); |
| 554 |
initAdapterManager(); |
| 555 |
initChildrenHelper(); |
| 556 |
|
| 557 |
if (getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 558 |
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 559 |
} |
| 560 |
mAccessibilityManager = (AccessibilityManager) getContext() |
| 561 |
.getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 562 |
setAccessibilityDelegateCompat(new RecyclerViewAccessibilityDelegate(this)); |
| 563 |
|
| 564 |
|
| 565 |
boolean nestedScrollingEnabled = true; |
| 566 |
|
| 567 |
if (attrs != null) { |
| 568 |
int defStyleRes = 0; |
| 569 |
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView, |
| 570 |
defStyle, defStyleRes); |
| 571 |
String layoutManagerName = a.getString(R.styleable.RecyclerView_layoutManager); |
| 572 |
int descendantFocusability = a.getInt( |
| 573 |
R.styleable.RecyclerView_descendantFocusability, -1); |
| 574 |
if (descendantFocusability == -1) { |
| 575 |
setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); |
| 576 |
} |
| 577 |
a.recycle(); |
| 578 |
createLayoutManager(context, layoutManagerName, attrs, defStyle, defStyleRes); |
| 579 |
|
| 580 |
if (Build.VERSION.SDK_INT >= 21) { |
| 581 |
a = context.obtainStyledAttributes(attrs, NESTED_SCROLLING_ATTRS, |
| 582 |
defStyle, defStyleRes); |
| 583 |
nestedScrollingEnabled = a.getBoolean(0, true); |
| 584 |
a.recycle(); |
| 585 |
} |
| 586 |
} else { |
| 587 |
setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); |
| 588 |
} |
| 589 |
|
| 590 |
TypedArray a = context.obtainStyledAttributes(attrs, |
| 591 |
com.android.internal.R.styleable.EdgeEffect); |
| 592 |
a.recycle(); |
| 593 |
|
| 594 |
|
| 595 |
setNestedScrollingEnabled(nestedScrollingEnabled); |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
public RecyclerViewAccessibilityDelegate getCompatAccessibilityDelegate() { |
| 603 |
return mAccessibilityDelegate; |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
public void setAccessibilityDelegateCompat( |
| 611 |
RecyclerViewAccessibilityDelegate accessibilityDelegate) { |
| 612 |
mAccessibilityDelegate = accessibilityDelegate; |
| 613 |
setAccessibilityDelegate(mAccessibilityDelegate); |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
private void createLayoutManager(Context context, String className, AttributeSet attrs, |
| 620 |
int defStyleAttr, int defStyleRes) { |
| 621 |
if (className != null) { |
| 622 |
className = className.trim(); |
| 623 |
if (className.length() != 0) { |
| 624 |
className = getFullClassName(context, className); |
| 625 |
try { |
| 626 |
ClassLoader classLoader; |
| 627 |
if (isInEditMode()) { |
| 628 |
|
| 629 |
classLoader = this.getClass().getClassLoader(); |
| 630 |
} else { |
| 631 |
classLoader = context.getClassLoader(); |
| 632 |
} |
| 633 |
Class<? extends LayoutManager> layoutManagerClass = |
| 634 |
classLoader.loadClass(className).asSubclass(LayoutManager.class); |
| 635 |
Constructor<? extends LayoutManager> constructor; |
| 636 |
Object[] constructorArgs = null; |
| 637 |
try { |
| 638 |
constructor = layoutManagerClass |
| 639 |
.getConstructor(LAYOUT_MANAGER_CONSTRUCTOR_SIGNATURE); |
| 640 |
constructorArgs = new Object[]{context, attrs, defStyleAttr, defStyleRes}; |
| 641 |
} catch (NoSuchMethodException e) { |
| 642 |
try { |
| 643 |
constructor = layoutManagerClass.getConstructor(); |
| 644 |
} catch (NoSuchMethodException e1) { |
| 645 |
e1.initCause(e); |
| 646 |
throw new IllegalStateException(attrs.getPositionDescription() |
| 647 |
+ ": Error creating LayoutManager " + className, e1); |
| 648 |
} |
| 649 |
} |
| 650 |
constructor.setAccessible(true); |
| 651 |
setLayoutManager(constructor.newInstance(constructorArgs)); |
| 652 |
} catch (ClassNotFoundException e) { |
| 653 |
throw new IllegalStateException(attrs.getPositionDescription() |
| 654 |
+ ": Unable to find LayoutManager " + className, e); |
| 655 |
} catch (InvocationTargetException e) { |
| 656 |
throw new IllegalStateException(attrs.getPositionDescription() |
| 657 |
+ ": Could not instantiate the LayoutManager: " + className, e); |
| 658 |
} catch (InstantiationException e) { |
| 659 |
throw new IllegalStateException(attrs.getPositionDescription() |
| 660 |
+ ": Could not instantiate the LayoutManager: " + className, e); |
| 661 |
} catch (IllegalAccessException e) { |
| 662 |
throw new IllegalStateException(attrs.getPositionDescription() |
| 663 |
+ ": Cannot access non-public constructor " + className, e); |
| 664 |
} catch (ClassCastException e) { |
| 665 |
throw new IllegalStateException(attrs.getPositionDescription() |
| 666 |
+ ": Class is not a LayoutManager " + className, e); |
| 667 |
} |
| 668 |
} |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
private String getFullClassName(Context context, String className) { |
| 673 |
if (className.charAt(0) == '.') { |
| 674 |
return context.getPackageName() + className; |
| 675 |
} |
| 676 |
if (className.contains(".")) { |
| 677 |
return className; |
| 678 |
} |
| 679 |
return RecyclerView.class.getPackage().getName() + '.' + className; |
| 680 |
} |
| 681 |
|
| 682 |
private void initChildrenHelper() { |
| 683 |
mChildHelper = new ChildHelper(new ChildHelper.Callback() { |
| 684 |
@Override |
| 685 |
public int getChildCount() { |
| 686 |
return RecyclerView.this.getChildCount(); |
| 687 |
} |
| 688 |
|
| 689 |
@Override |
| 690 |
public void addView(View child, int index) { |
| 691 |
RecyclerView.this.addView(child, index); |
| 692 |
dispatchChildAttached(child); |
| 693 |
} |
| 694 |
|
| 695 |
@Override |
| 696 |
public int indexOfChild(View view) { |
| 697 |
return RecyclerView.this.indexOfChild(view); |
| 698 |
} |
| 699 |
|
| 700 |
@Override |
| 701 |
public void removeViewAt(int index) { |
| 702 |
final View child = RecyclerView.this.getChildAt(index); |
| 703 |
if (child != null) { |
| 704 |
dispatchChildDetached(child); |
| 705 |
} |
| 706 |
RecyclerView.this.removeViewAt(index); |
| 707 |
} |
| 708 |
|
| 709 |
@Override |
| 710 |
public View getChildAt(int offset) { |
| 711 |
return RecyclerView.this.getChildAt(offset); |
| 712 |
} |
| 713 |
|
| 714 |
@Override |
| 715 |
public void removeAllViews() { |
| 716 |
final int count = getChildCount(); |
| 717 |
for (int i = 0; i < count; i++) { |
| 718 |
dispatchChildDetached(getChildAt(i)); |
| 719 |
} |
| 720 |
RecyclerView.this.removeAllViews(); |
| 721 |
} |
| 722 |
|
| 723 |
@Override |
| 724 |
public ViewHolder getChildViewHolder(View view) { |
| 725 |
return getChildViewHolderInt(view); |
| 726 |
} |
| 727 |
|
| 728 |
@Override |
| 729 |
public void attachViewToParent(View child, int index, |
| 730 |
ViewGroup.LayoutParams layoutParams) { |
| 731 |
final ViewHolder vh = getChildViewHolderInt(child); |
| 732 |
if (vh != null) { |
| 733 |
if (!vh.isTmpDetached() && !vh.shouldIgnore()) { |
| 734 |
throw new IllegalArgumentException("Called attach on a child which is not" |
| 735 |
+ " detached: " + vh); |
| 736 |
} |
| 737 |
if (DEBUG) { |
| 738 |
Log.d(TAG, "reAttach " + vh); |
| 739 |
} |
| 740 |
vh.clearTmpDetachFlag(); |
| 741 |
} |
| 742 |
RecyclerView.this.attachViewToParent(child, index, layoutParams); |
| 743 |
} |
| 744 |
|
| 745 |
@Override |
| 746 |
public void detachViewFromParent(int offset) { |
| 747 |
final View view = getChildAt(offset); |
| 748 |
if (view != null) { |
| 749 |
final ViewHolder vh = getChildViewHolderInt(view); |
| 750 |
if (vh != null) { |
| 751 |
if (vh.isTmpDetached() && !vh.shouldIgnore()) { |
| 752 |
throw new IllegalArgumentException("called detach on an already" |
| 753 |
+ " detached child " + vh); |
| 754 |
} |
| 755 |
if (DEBUG) { |
| 756 |
Log.d(TAG, "tmpDetach " + vh); |
| 757 |
} |
| 758 |
vh.addFlags(ViewHolder.FLAG_TMP_DETACHED); |
| 759 |
} |
| 760 |
} |
| 761 |
RecyclerView.this.detachViewFromParent(offset); |
| 762 |
} |
| 763 |
|
| 764 |
@Override |
| 765 |
public void onEnteredHiddenState(View child) { |
| 766 |
final ViewHolder vh = getChildViewHolderInt(child); |
| 767 |
if (vh != null) { |
| 768 |
vh.onEnteredHiddenState(RecyclerView.this); |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
@Override |
| 773 |
public void onLeftHiddenState(View child) { |
| 774 |
final ViewHolder vh = getChildViewHolderInt(child); |
| 775 |
if (vh != null) { |
| 776 |
vh.onLeftHiddenState(RecyclerView.this); |
| 777 |
} |
| 778 |
} |
| 779 |
}); |
| 780 |
} |
| 781 |
|
| 782 |
void initAdapterManager() { |
| 783 |
mAdapterHelper = new AdapterHelper(new AdapterHelper.Callback() { |
| 784 |
@Override |
| 785 |
public ViewHolder findViewHolder(int position) { |
| 786 |
final ViewHolder vh = findViewHolderForPosition(position, true); |
| 787 |
if (vh == null) { |
| 788 |
return null; |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
if (mChildHelper.isHidden(vh.itemView)) { |
| 793 |
if (DEBUG) { |
| 794 |
Log.d(TAG, "assuming view holder cannot be find because it is hidden"); |
| 795 |
} |
| 796 |
return null; |
| 797 |
} |
| 798 |
return vh; |
| 799 |
} |
| 800 |
|
| 801 |
@Override |
| 802 |
public void offsetPositionsForRemovingInvisible(int start, int count) { |
| 803 |
offsetPositionRecordsForRemove(start, count, true); |
| 804 |
mItemsAddedOrRemoved = true; |
| 805 |
mState.mDeletedInvisibleItemCountSincePreviousLayout += count; |
| 806 |
} |
| 807 |
|
| 808 |
@Override |
| 809 |
public void offsetPositionsForRemovingLaidOutOrNewView( |
| 810 |
int positionStart, int itemCount) { |
| 811 |
offsetPositionRecordsForRemove(positionStart, itemCount, false); |
| 812 |
mItemsAddedOrRemoved = true; |
| 813 |
} |
| 814 |
|
| 815 |
@Override |
| 816 |
public void markViewHoldersUpdated(int positionStart, int itemCount, Object payload) { |
| 817 |
viewRangeUpdate(positionStart, itemCount, payload); |
| 818 |
mItemsChanged = true; |
| 819 |
} |
| 820 |
|
| 821 |
@Override |
| 822 |
public void onDispatchFirstPass(AdapterHelper.UpdateOp op) { |
| 823 |
dispatchUpdate(op); |
| 824 |
} |
| 825 |
|
| 826 |
void dispatchUpdate(AdapterHelper.UpdateOp op) { |
| 827 |
switch (op.cmd) { |
| 828 |
case AdapterHelper.UpdateOp.ADD: |
| 829 |
mLayout.onItemsAdded(RecyclerView.this, op.positionStart, op.itemCount); |
| 830 |
break; |
| 831 |
case AdapterHelper.UpdateOp.REMOVE: |
| 832 |
mLayout.onItemsRemoved(RecyclerView.this, op.positionStart, op.itemCount); |
| 833 |
break; |
| 834 |
case AdapterHelper.UpdateOp.UPDATE: |
| 835 |
mLayout.onItemsUpdated(RecyclerView.this, op.positionStart, op.itemCount, |
| 836 |
op.payload); |
| 837 |
break; |
| 838 |
case AdapterHelper.UpdateOp.MOVE: |
| 839 |
mLayout.onItemsMoved(RecyclerView.this, op.positionStart, op.itemCount, 1); |
| 840 |
break; |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
@Override |
| 845 |
public void onDispatchSecondPass(AdapterHelper.UpdateOp op) { |
| 846 |
dispatchUpdate(op); |
| 847 |
} |
| 848 |
|
| 849 |
@Override |
| 850 |
public void offsetPositionsForAdd(int positionStart, int itemCount) { |
| 851 |
offsetPositionRecordsForInsert(positionStart, itemCount); |
| 852 |
mItemsAddedOrRemoved = true; |
| 853 |
} |
| 854 |
|
| 855 |
@Override |
| 856 |
public void offsetPositionsForMove(int from, int to) { |
| 857 |
offsetPositionRecordsForMove(from, to); |
| 858 |
|
| 859 |
mItemsAddedOrRemoved = true; |
| 860 |
} |
| 861 |
}); |
| 862 |
} |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
public void setHasFixedSize(boolean hasFixedSize) { |
| 876 |
mHasFixedSize = hasFixedSize; |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
public boolean hasFixedSize() { |
| 884 |
return mHasFixedSize; |
| 885 |
} |
| 886 |
|
| 887 |
@Override |
| 888 |
public void setClipToPadding(boolean clipToPadding) { |
| 889 |
if (clipToPadding != mClipToPadding) { |
| 890 |
invalidateGlows(); |
| 891 |
} |
| 892 |
mClipToPadding = clipToPadding; |
| 893 |
super.setClipToPadding(clipToPadding); |
| 894 |
if (mFirstLayoutComplete) { |
| 895 |
requestLayout(); |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
@Override |
| 912 |
public boolean getClipToPadding() { |
| 913 |
return mClipToPadding; |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
public void setScrollingTouchSlop(int slopConstant) { |
| 926 |
final ViewConfiguration vc = ViewConfiguration.get(getContext()); |
| 927 |
switch (slopConstant) { |
| 928 |
default: |
| 929 |
Log.w(TAG, "setScrollingTouchSlop(): bad argument constant " |
| 930 |
+ slopConstant + "; using default value"); |
| 931 |
|
| 932 |
case TOUCH_SLOP_DEFAULT: |
| 933 |
mTouchSlop = vc.getScaledTouchSlop(); |
| 934 |
break; |
| 935 |
|
| 936 |
case TOUCH_SLOP_PAGING: |
| 937 |
mTouchSlop = vc.getScaledPagingTouchSlop(); |
| 938 |
break; |
| 939 |
} |
| 940 |
} |
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
public void swapAdapter(Adapter adapter, boolean removeAndRecycleExistingViews) { |
| 957 |
|
| 958 |
setLayoutFrozen(false); |
| 959 |
setAdapterInternal(adapter, true, removeAndRecycleExistingViews); |
| 960 |
setDataSetChangedAfterLayout(); |
| 961 |
requestLayout(); |
| 962 |
} |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
public void setAdapter(Adapter adapter) { |
| 973 |
|
| 974 |
setLayoutFrozen(false); |
| 975 |
setAdapterInternal(adapter, false, true); |
| 976 |
requestLayout(); |
| 977 |
} |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
void removeAndRecycleViews() { |
| 983 |
|
| 984 |
if (mItemAnimator != null) { |
| 985 |
mItemAnimator.endAnimations(); |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
if (mLayout != null) { |
| 992 |
mLayout.removeAndRecycleAllViews(mRecycler); |
| 993 |
mLayout.removeAndRecycleScrapInt(mRecycler); |
| 994 |
} |
| 995 |
|
| 996 |
mRecycler.clear(); |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
private void setAdapterInternal(Adapter adapter, boolean compatibleWithPrevious, |
| 1009 |
boolean removeAndRecycleViews) { |
| 1010 |
if (mAdapter != null) { |
| 1011 |
mAdapter.unregisterAdapterDataObserver(mObserver); |
| 1012 |
mAdapter.onDetachedFromRecyclerView(this); |
| 1013 |
} |
| 1014 |
if (!compatibleWithPrevious || removeAndRecycleViews) { |
| 1015 |
removeAndRecycleViews(); |
| 1016 |
} |
| 1017 |
mAdapterHelper.reset(); |
| 1018 |
final Adapter oldAdapter = mAdapter; |
| 1019 |
mAdapter = adapter; |
| 1020 |
if (adapter != null) { |
| 1021 |
adapter.registerAdapterDataObserver(mObserver); |
| 1022 |
adapter.onAttachedToRecyclerView(this); |
| 1023 |
} |
| 1024 |
if (mLayout != null) { |
| 1025 |
mLayout.onAdapterChanged(oldAdapter, mAdapter); |
| 1026 |
} |
| 1027 |
mRecycler.onAdapterChanged(oldAdapter, mAdapter, compatibleWithPrevious); |
| 1028 |
mState.mStructureChanged = true; |
| 1029 |
markKnownViewsInvalid(); |
| 1030 |
} |
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
public Adapter getAdapter() { |
| 1039 |
return mAdapter; |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
public void setRecyclerListener(RecyclerListener listener) { |
| 1053 |
mRecyclerListener = listener; |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
@Override |
| 1065 |
public int getBaseline() { |
| 1066 |
if (mLayout != null) { |
| 1067 |
return mLayout.getBaseline(); |
| 1068 |
} else { |
| 1069 |
return super.getBaseline(); |
| 1070 |
} |
| 1071 |
} |
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
public void addOnChildAttachStateChangeListener(OnChildAttachStateChangeListener listener) { |
| 1085 |
if (mOnChildAttachStateListeners == null) { |
| 1086 |
mOnChildAttachStateListeners = new ArrayList<>(); |
| 1087 |
} |
| 1088 |
mOnChildAttachStateListeners.add(listener); |
| 1089 |
} |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
public void removeOnChildAttachStateChangeListener(OnChildAttachStateChangeListener listener) { |
| 1097 |
if (mOnChildAttachStateListeners == null) { |
| 1098 |
return; |
| 1099 |
} |
| 1100 |
mOnChildAttachStateListeners.remove(listener); |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
public void clearOnChildAttachStateChangeListeners() { |
| 1108 |
if (mOnChildAttachStateListeners != null) { |
| 1109 |
mOnChildAttachStateListeners.clear(); |
| 1110 |
} |
| 1111 |
} |
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
public void setLayoutManager(LayoutManager layout) { |
| 1126 |
if (layout == mLayout) { |
| 1127 |
return; |
| 1128 |
} |
| 1129 |
stopScroll(); |
| 1130 |
|
| 1131 |
|
| 1132 |
if (mLayout != null) { |
| 1133 |
|
| 1134 |
if (mItemAnimator != null) { |
| 1135 |
mItemAnimator.endAnimations(); |
| 1136 |
} |
| 1137 |
mLayout.removeAndRecycleAllViews(mRecycler); |
| 1138 |
mLayout.removeAndRecycleScrapInt(mRecycler); |
| 1139 |
mRecycler.clear(); |
| 1140 |
|
| 1141 |
if (mIsAttached) { |
| 1142 |
mLayout.dispatchDetachedFromWindow(this, mRecycler); |
| 1143 |
} |
| 1144 |
mLayout.setRecyclerView(null); |
| 1145 |
mLayout = null; |
| 1146 |
} else { |
| 1147 |
mRecycler.clear(); |
| 1148 |
} |
| 1149 |
|
| 1150 |
mChildHelper.removeAllViewsUnfiltered(); |
| 1151 |
mLayout = layout; |
| 1152 |
if (layout != null) { |
| 1153 |
if (layout.mRecyclerView != null) { |
| 1154 |
throw new IllegalArgumentException("LayoutManager " + layout |
| 1155 |
+ " is already attached to a RecyclerView: " + layout.mRecyclerView); |
| 1156 |
} |
| 1157 |
mLayout.setRecyclerView(this); |
| 1158 |
if (mIsAttached) { |
| 1159 |
mLayout.dispatchAttachedToWindow(this); |
| 1160 |
} |
| 1161 |
} |
| 1162 |
mRecycler.updateViewCacheSize(); |
| 1163 |
requestLayout(); |
| 1164 |
} |
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
public void setOnFlingListener(@Nullable OnFlingListener onFlingListener) { |
| 1175 |
mOnFlingListener = onFlingListener; |
| 1176 |
} |
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
@Nullable |
| 1184 |
public OnFlingListener getOnFlingListener() { |
| 1185 |
return mOnFlingListener; |
| 1186 |
} |
| 1187 |
|
| 1188 |
@Override |
| 1189 |
protected Parcelable onSaveInstanceState() { |
| 1190 |
SavedState state = new SavedState(super.onSaveInstanceState()); |
| 1191 |
if (mPendingSavedState != null) { |
| 1192 |
state.copyFrom(mPendingSavedState); |
| 1193 |
} else if (mLayout != null) { |
| 1194 |
state.mLayoutState = mLayout.onSaveInstanceState(); |
| 1195 |
} else { |
| 1196 |
state.mLayoutState = null; |
| 1197 |
} |
| 1198 |
|
| 1199 |
return state; |
| 1200 |
} |
| 1201 |
|
| 1202 |
@Override |
| 1203 |
protected void onRestoreInstanceState(Parcelable state) { |
| 1204 |
if (!(state instanceof SavedState)) { |
| 1205 |
super.onRestoreInstanceState(state); |
| 1206 |
return; |
| 1207 |
} |
| 1208 |
|
| 1209 |
mPendingSavedState = (SavedState) state; |
| 1210 |
super.onRestoreInstanceState(mPendingSavedState.getSuperState()); |
| 1211 |
if (mLayout != null && mPendingSavedState.mLayoutState != null) { |
| 1212 |
mLayout.onRestoreInstanceState(mPendingSavedState.mLayoutState); |
| 1213 |
} |
| 1214 |
} |
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
@Override |
| 1220 |
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 1221 |
dispatchFreezeSelfOnly(container); |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
@Override |
| 1228 |
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 1229 |
dispatchThawSelfOnly(container); |
| 1230 |
} |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
private void addAnimatingView(ViewHolder viewHolder) { |
| 1241 |
final View view = viewHolder.itemView; |
| 1242 |
final boolean alreadyParented = view.getParent() == this; |
| 1243 |
mRecycler.unscrapView(getChildViewHolder(view)); |
| 1244 |
if (viewHolder.isTmpDetached()) { |
| 1245 |
|
| 1246 |
mChildHelper.attachViewToParent(view, -1, view.getLayoutParams(), true); |
| 1247 |
} else if (!alreadyParented) { |
| 1248 |
mChildHelper.addView(view, true); |
| 1249 |
} else { |
| 1250 |
mChildHelper.hide(view); |
| 1251 |
} |
| 1252 |
} |
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
boolean removeAnimatingView(View view) { |
| 1261 |
eatRequestLayout(); |
| 1262 |
final boolean removed = mChildHelper.removeViewIfHidden(view); |
| 1263 |
if (removed) { |
| 1264 |
final ViewHolder viewHolder = getChildViewHolderInt(view); |
| 1265 |
mRecycler.unscrapView(viewHolder); |
| 1266 |
mRecycler.recycleViewHolderInternal(viewHolder); |
| 1267 |
if (DEBUG) { |
| 1268 |
Log.d(TAG, "after removing animated view: " + view + ", " + this); |
| 1269 |
} |
| 1270 |
} |
| 1271 |
|
| 1272 |
resumeRequestLayout(!removed); |
| 1273 |
return removed; |
| 1274 |
} |
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
public LayoutManager getLayoutManager() { |
| 1283 |
return mLayout; |
| 1284 |
} |
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
public RecycledViewPool getRecycledViewPool() { |
| 1295 |
return mRecycler.getRecycledViewPool(); |
| 1296 |
} |
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
public void setRecycledViewPool(RecycledViewPool pool) { |
| 1307 |
mRecycler.setRecycledViewPool(pool); |
| 1308 |
} |
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
public void setViewCacheExtension(ViewCacheExtension extension) { |
| 1318 |
mRecycler.setViewCacheExtension(extension); |
| 1319 |
} |
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
public void setItemViewCacheSize(int size) { |
| 1333 |
mRecycler.setViewCacheSize(size); |
| 1334 |
} |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
public int getScrollState() { |
| 1343 |
return mScrollState; |
| 1344 |
} |
| 1345 |
|
| 1346 |
void setScrollState(int state) { |
| 1347 |
if (state == mScrollState) { |
| 1348 |
return; |
| 1349 |
} |
| 1350 |
if (DEBUG) { |
| 1351 |
Log.d(TAG, "setting scroll state to " + state + " from " + mScrollState, |
| 1352 |
new Exception()); |
| 1353 |
} |
| 1354 |
mScrollState = state; |
| 1355 |
if (state != SCROLL_STATE_SETTLING) { |
| 1356 |
stopScrollersInternal(); |
| 1357 |
} |
| 1358 |
dispatchOnScrollStateChanged(state); |
| 1359 |
} |
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
public void addItemDecoration(ItemDecoration decor, int index) { |
| 1376 |
if (mLayout != null) { |
| 1377 |
mLayout.assertNotInLayoutOrScroll("Cannot add item decoration during a scroll or" |
| 1378 |
+ " layout"); |
| 1379 |
} |
| 1380 |
if (mItemDecorations.isEmpty()) { |
| 1381 |
setWillNotDraw(false); |
| 1382 |
} |
| 1383 |
if (index < 0) { |
| 1384 |
mItemDecorations.add(decor); |
| 1385 |
} else { |
| 1386 |
mItemDecorations.add(index, decor); |
| 1387 |
} |
| 1388 |
markItemDecorInsetsDirty(); |
| 1389 |
requestLayout(); |
| 1390 |
} |
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
public void addItemDecoration(ItemDecoration decor) { |
| 1405 |
addItemDecoration(decor, -1); |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
public void removeItemDecoration(ItemDecoration decor) { |
| 1418 |
if (mLayout != null) { |
| 1419 |
mLayout.assertNotInLayoutOrScroll("Cannot remove item decoration during a scroll or" |
| 1420 |
+ " layout"); |
| 1421 |
} |
| 1422 |
mItemDecorations.remove(decor); |
| 1423 |
if (mItemDecorations.isEmpty()) { |
| 1424 |
setWillNotDraw(getOverScrollMode() == View.OVER_SCROLL_NEVER); |
| 1425 |
} |
| 1426 |
markItemDecorInsetsDirty(); |
| 1427 |
requestLayout(); |
| 1428 |
} |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
public void setChildDrawingOrderCallback(ChildDrawingOrderCallback childDrawingOrderCallback) { |
| 1443 |
if (childDrawingOrderCallback == mChildDrawingOrderCallback) { |
| 1444 |
return; |
| 1445 |
} |
| 1446 |
mChildDrawingOrderCallback = childDrawingOrderCallback; |
| 1447 |
setChildrenDrawingOrderEnabled(mChildDrawingOrderCallback != null); |
| 1448 |
} |
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
@Deprecated |
| 1459 |
public void setOnScrollListener(OnScrollListener listener) { |
| 1460 |
mScrollListener = listener; |
| 1461 |
} |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
public void addOnScrollListener(OnScrollListener listener) { |
| 1473 |
if (mScrollListeners == null) { |
| 1474 |
mScrollListeners = new ArrayList<>(); |
| 1475 |
} |
| 1476 |
mScrollListeners.add(listener); |
| 1477 |
} |
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
public void removeOnScrollListener(OnScrollListener listener) { |
| 1485 |
if (mScrollListeners != null) { |
| 1486 |
mScrollListeners.remove(listener); |
| 1487 |
} |
| 1488 |
} |
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
public void clearOnScrollListeners() { |
| 1494 |
if (mScrollListeners != null) { |
| 1495 |
mScrollListeners.clear(); |
| 1496 |
} |
| 1497 |
} |
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
public void scrollToPosition(int position) { |
| 1508 |
if (mLayoutFrozen) { |
| 1509 |
return; |
| 1510 |
} |
| 1511 |
stopScroll(); |
| 1512 |
if (mLayout == null) { |
| 1513 |
Log.e(TAG, "Cannot scroll to position a LayoutManager set. " |
| 1514 |
+ "Call setLayoutManager with a non-null argument."); |
| 1515 |
return; |
| 1516 |
} |
| 1517 |
mLayout.scrollToPosition(position); |
| 1518 |
awakenScrollBars(); |
| 1519 |
} |
| 1520 |
|
| 1521 |
void jumpToPositionForSmoothScroller(int position) { |
| 1522 |
if (mLayout == null) { |
| 1523 |
return; |
| 1524 |
} |
| 1525 |
mLayout.scrollToPosition(position); |
| 1526 |
awakenScrollBars(); |
| 1527 |
} |
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
public void smoothScrollToPosition(int position) { |
| 1545 |
if (mLayoutFrozen) { |
| 1546 |
return; |
| 1547 |
} |
| 1548 |
if (mLayout == null) { |
| 1549 |
Log.e(TAG, "Cannot smooth scroll without a LayoutManager set. " |
| 1550 |
+ "Call setLayoutManager with a non-null argument."); |
| 1551 |
return; |
| 1552 |
} |
| 1553 |
mLayout.smoothScrollToPosition(this, mState, position); |
| 1554 |
} |
| 1555 |
|
| 1556 |
@Override |
| 1557 |
public void scrollTo(int x, int y) { |
| 1558 |
Log.w(TAG, "RecyclerView does not support scrolling to an absolute position. " |
| 1559 |
+ "Use scrollToPosition instead"); |
| 1560 |
} |
| 1561 |
|
| 1562 |
@Override |
| 1563 |
public void scrollBy(int x, int y) { |
| 1564 |
if (mLayout == null) { |
| 1565 |
Log.e(TAG, "Cannot scroll without a LayoutManager set. " |
| 1566 |
+ "Call setLayoutManager with a non-null argument."); |
| 1567 |
return; |
| 1568 |
} |
| 1569 |
if (mLayoutFrozen) { |
| 1570 |
return; |
| 1571 |
} |
| 1572 |
final boolean canScrollHorizontal = mLayout.canScrollHorizontally(); |
| 1573 |
final boolean canScrollVertical = mLayout.canScrollVertically(); |
| 1574 |
if (canScrollHorizontal || canScrollVertical) { |
| 1575 |
scrollByInternal(canScrollHorizontal ? x : 0, canScrollVertical ? y : 0, null); |
| 1576 |
} |
| 1577 |
} |
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
void consumePendingUpdateOperations() { |
| 1588 |
if (!mFirstLayoutComplete || mDataSetHasChangedAfterLayout) { |
| 1589 |
Trace.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG); |
| 1590 |
dispatchLayout(); |
| 1591 |
Trace.endSection(); |
| 1592 |
return; |
| 1593 |
} |
| 1594 |
if (!mAdapterHelper.hasPendingUpdates()) { |
| 1595 |
return; |
| 1596 |
} |
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
if (mAdapterHelper.hasAnyUpdateTypes(AdapterHelper.UpdateOp.UPDATE) && !mAdapterHelper |
| 1601 |
.hasAnyUpdateTypes(AdapterHelper.UpdateOp.ADD | AdapterHelper.UpdateOp.REMOVE |
| 1602 |
| AdapterHelper.UpdateOp.MOVE)) { |
| 1603 |
Trace.beginSection(TRACE_HANDLE_ADAPTER_UPDATES_TAG); |
| 1604 |
eatRequestLayout(); |
| 1605 |
onEnterLayoutOrScroll(); |
| 1606 |
mAdapterHelper.preProcess(); |
| 1607 |
if (!mLayoutRequestEaten) { |
| 1608 |
if (hasUpdatedView()) { |
| 1609 |
dispatchLayout(); |
| 1610 |
} else { |
| 1611 |
|
| 1612 |
mAdapterHelper.consumePostponedUpdates(); |
| 1613 |
} |
| 1614 |
} |
| 1615 |
resumeRequestLayout(true); |
| 1616 |
onExitLayoutOrScroll(); |
| 1617 |
Trace.endSection(); |
| 1618 |
} else if (mAdapterHelper.hasPendingUpdates()) { |
| 1619 |
Trace.beginSection(TRACE_ON_DATA_SET_CHANGE_LAYOUT_TAG); |
| 1620 |
dispatchLayout(); |
| 1621 |
Trace.endSection(); |
| 1622 |
} |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
private boolean hasUpdatedView() { |
| 1629 |
final int childCount = mChildHelper.getChildCount(); |
| 1630 |
for (int i = 0; i < childCount; i++) { |
| 1631 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getChildAt(i)); |
| 1632 |
if (holder == null || holder.shouldIgnore()) { |
| 1633 |
continue; |
| 1634 |
} |
| 1635 |
if (holder.isUpdated()) { |
| 1636 |
return true; |
| 1637 |
} |
| 1638 |
} |
| 1639 |
return false; |
| 1640 |
} |
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
boolean scrollByInternal(int x, int y, MotionEvent ev) { |
| 1654 |
int unconsumedX = 0, unconsumedY = 0; |
| 1655 |
int consumedX = 0, consumedY = 0; |
| 1656 |
|
| 1657 |
consumePendingUpdateOperations(); |
| 1658 |
if (mAdapter != null) { |
| 1659 |
eatRequestLayout(); |
| 1660 |
onEnterLayoutOrScroll(); |
| 1661 |
Trace.beginSection(TRACE_SCROLL_TAG); |
| 1662 |
if (x != 0) { |
| 1663 |
consumedX = mLayout.scrollHorizontallyBy(x, mRecycler, mState); |
| 1664 |
unconsumedX = x - consumedX; |
| 1665 |
} |
| 1666 |
if (y != 0) { |
| 1667 |
consumedY = mLayout.scrollVerticallyBy(y, mRecycler, mState); |
| 1668 |
unconsumedY = y - consumedY; |
| 1669 |
} |
| 1670 |
Trace.endSection(); |
| 1671 |
repositionShadowingViews(); |
| 1672 |
onExitLayoutOrScroll(); |
| 1673 |
resumeRequestLayout(false); |
| 1674 |
} |
| 1675 |
if (!mItemDecorations.isEmpty()) { |
| 1676 |
invalidate(); |
| 1677 |
} |
| 1678 |
|
| 1679 |
if (dispatchNestedScroll(consumedX, consumedY, unconsumedX, unconsumedY, mScrollOffset)) { |
| 1680 |
|
| 1681 |
mLastTouchX -= mScrollOffset[0]; |
| 1682 |
mLastTouchY -= mScrollOffset[1]; |
| 1683 |
if (ev != null) { |
| 1684 |
ev.offsetLocation(mScrollOffset[0], mScrollOffset[1]); |
| 1685 |
} |
| 1686 |
mNestedOffsets[0] += mScrollOffset[0]; |
| 1687 |
mNestedOffsets[1] += mScrollOffset[1]; |
| 1688 |
} else if (getOverScrollMode() != View.OVER_SCROLL_NEVER) { |
| 1689 |
if (ev != null) { |
| 1690 |
pullGlows(ev.getX(), unconsumedX, ev.getY(), unconsumedY); |
| 1691 |
} |
| 1692 |
considerReleasingGlowsOnScroll(x, y); |
| 1693 |
} |
| 1694 |
if (consumedX != 0 || consumedY != 0) { |
| 1695 |
dispatchOnScrolled(consumedX, consumedY); |
| 1696 |
} |
| 1697 |
if (!awakenScrollBars()) { |
| 1698 |
invalidate(); |
| 1699 |
} |
| 1700 |
return consumedX != 0 || consumedY != 0; |
| 1701 |
} |
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
@Override |
| 1722 |
public int computeHorizontalScrollOffset() { |
| 1723 |
if (mLayout == null) { |
| 1724 |
return 0; |
| 1725 |
} |
| 1726 |
return mLayout.canScrollHorizontally() ? mLayout.computeHorizontalScrollOffset(mState) : 0; |
| 1727 |
} |
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
@Override |
| 1747 |
public int computeHorizontalScrollExtent() { |
| 1748 |
if (mLayout == null) { |
| 1749 |
return 0; |
| 1750 |
} |
| 1751 |
return mLayout.canScrollHorizontally() ? mLayout.computeHorizontalScrollExtent(mState) : 0; |
| 1752 |
} |
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
@Override |
| 1770 |
public int computeHorizontalScrollRange() { |
| 1771 |
if (mLayout == null) { |
| 1772 |
return 0; |
| 1773 |
} |
| 1774 |
return mLayout.canScrollHorizontally() ? mLayout.computeHorizontalScrollRange(mState) : 0; |
| 1775 |
} |
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
@Override |
| 1795 |
public int computeVerticalScrollOffset() { |
| 1796 |
if (mLayout == null) { |
| 1797 |
return 0; |
| 1798 |
} |
| 1799 |
return mLayout.canScrollVertically() ? mLayout.computeVerticalScrollOffset(mState) : 0; |
| 1800 |
} |
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
@Override |
| 1819 |
public int computeVerticalScrollExtent() { |
| 1820 |
if (mLayout == null) { |
| 1821 |
return 0; |
| 1822 |
} |
| 1823 |
return mLayout.canScrollVertically() ? mLayout.computeVerticalScrollExtent(mState) : 0; |
| 1824 |
} |
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
@Override |
| 1842 |
public int computeVerticalScrollRange() { |
| 1843 |
if (mLayout == null) { |
| 1844 |
return 0; |
| 1845 |
} |
| 1846 |
return mLayout.canScrollVertically() ? mLayout.computeVerticalScrollRange(mState) : 0; |
| 1847 |
} |
| 1848 |
|
| 1849 |
|
| 1850 |
void eatRequestLayout() { |
| 1851 |
mEatRequestLayout++; |
| 1852 |
if (mEatRequestLayout == 1 && !mLayoutFrozen) { |
| 1853 |
mLayoutRequestEaten = false; |
| 1854 |
} |
| 1855 |
} |
| 1856 |
|
| 1857 |
void resumeRequestLayout(boolean performLayoutChildren) { |
| 1858 |
if (mEatRequestLayout < 1) { |
| 1859 |
|
| 1860 |
if (DEBUG) { |
| 1861 |
throw new IllegalStateException("invalid eat request layout count"); |
| 1862 |
} |
| 1863 |
mEatRequestLayout = 1; |
| 1864 |
} |
| 1865 |
if (!performLayoutChildren) { |
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
mLayoutRequestEaten = false; |
| 1875 |
} |
| 1876 |
if (mEatRequestLayout == 1) { |
| 1877 |
|
| 1878 |
if (performLayoutChildren && mLayoutRequestEaten && !mLayoutFrozen |
| 1879 |
&& mLayout != null && mAdapter != null) { |
| 1880 |
dispatchLayout(); |
| 1881 |
} |
| 1882 |
if (!mLayoutFrozen) { |
| 1883 |
mLayoutRequestEaten = false; |
| 1884 |
} |
| 1885 |
} |
| 1886 |
mEatRequestLayout--; |
| 1887 |
} |
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
public void setLayoutFrozen(boolean frozen) { |
| 1912 |
if (frozen != mLayoutFrozen) { |
| 1913 |
assertNotInLayoutOrScroll("Do not setLayoutFrozen in layout or scroll"); |
| 1914 |
if (!frozen) { |
| 1915 |
mLayoutFrozen = false; |
| 1916 |
if (mLayoutRequestEaten && mLayout != null && mAdapter != null) { |
| 1917 |
requestLayout(); |
| 1918 |
} |
| 1919 |
mLayoutRequestEaten = false; |
| 1920 |
} else { |
| 1921 |
final long now = SystemClock.uptimeMillis(); |
| 1922 |
MotionEvent cancelEvent = MotionEvent.obtain(now, now, |
| 1923 |
MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); |
| 1924 |
onTouchEvent(cancelEvent); |
| 1925 |
mLayoutFrozen = true; |
| 1926 |
mIgnoreMotionEventTillDown = true; |
| 1927 |
stopScroll(); |
| 1928 |
} |
| 1929 |
} |
| 1930 |
} |
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
public boolean isLayoutFrozen() { |
| 1939 |
return mLayoutFrozen; |
| 1940 |
} |
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
public void smoothScrollBy(int dx, int dy) { |
| 1949 |
smoothScrollBy(dx, dy, null); |
| 1950 |
} |
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
public void smoothScrollBy(int dx, int dy, Interpolator interpolator) { |
| 1961 |
if (mLayout == null) { |
| 1962 |
Log.e(TAG, "Cannot smooth scroll without a LayoutManager set. " |
| 1963 |
+ "Call setLayoutManager with a non-null argument."); |
| 1964 |
return; |
| 1965 |
} |
| 1966 |
if (mLayoutFrozen) { |
| 1967 |
return; |
| 1968 |
} |
| 1969 |
if (!mLayout.canScrollHorizontally()) { |
| 1970 |
dx = 0; |
| 1971 |
} |
| 1972 |
if (!mLayout.canScrollVertically()) { |
| 1973 |
dy = 0; |
| 1974 |
} |
| 1975 |
if (dx != 0 || dy != 0) { |
| 1976 |
mViewFlinger.smoothScrollBy(dx, dy, interpolator); |
| 1977 |
} |
| 1978 |
} |
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
public boolean fling(int velocityX, int velocityY) { |
| 1994 |
if (mLayout == null) { |
| 1995 |
Log.e(TAG, "Cannot fling without a LayoutManager set. " |
| 1996 |
+ "Call setLayoutManager with a non-null argument."); |
| 1997 |
return false; |
| 1998 |
} |
| 1999 |
if (mLayoutFrozen) { |
| 2000 |
return false; |
| 2001 |
} |
| 2002 |
|
| 2003 |
final boolean canScrollHorizontal = mLayout.canScrollHorizontally(); |
| 2004 |
final boolean canScrollVertical = mLayout.canScrollVertically(); |
| 2005 |
|
| 2006 |
if (!canScrollHorizontal || Math.abs(velocityX) < mMinFlingVelocity) { |
| 2007 |
velocityX = 0; |
| 2008 |
} |
| 2009 |
if (!canScrollVertical || Math.abs(velocityY) < mMinFlingVelocity) { |
| 2010 |
velocityY = 0; |
| 2011 |
} |
| 2012 |
if (velocityX == 0 && velocityY == 0) { |
| 2013 |
|
| 2014 |
return false; |
| 2015 |
} |
| 2016 |
|
| 2017 |
if (!dispatchNestedPreFling(velocityX, velocityY)) { |
| 2018 |
boolean consumed = false; |
| 2019 |
if (mLayout.getChildCount() > 0) { |
| 2020 |
final View firstChild = mLayout.getChildAt(0); |
| 2021 |
final View lastChild = mLayout.getChildAt(mLayout.getChildCount() - 1); |
| 2022 |
if (velocityY < 0) { |
| 2023 |
consumed = getChildAdapterPosition(firstChild) > 0 |
| 2024 |
|| firstChild.getTop() < getPaddingTop(); |
| 2025 |
} |
| 2026 |
|
| 2027 |
if (velocityY > 0) { |
| 2028 |
consumed = getChildAdapterPosition(lastChild) < mAdapter.getItemCount() - 1 |
| 2029 |
|| lastChild.getBottom() > getHeight() - getPaddingBottom(); |
| 2030 |
} |
| 2031 |
} |
| 2032 |
|
| 2033 |
dispatchNestedFling(velocityX, velocityY, consumed); |
| 2034 |
|
| 2035 |
if (mOnFlingListener != null && mOnFlingListener.onFling(velocityX, velocityY)) { |
| 2036 |
return true; |
| 2037 |
} |
| 2038 |
|
| 2039 |
final boolean canScroll = canScrollHorizontal || canScrollVertical; |
| 2040 |
|
| 2041 |
if (canScroll) { |
| 2042 |
velocityX = Math.max(-mMaxFlingVelocity, Math.min(velocityX, mMaxFlingVelocity)); |
| 2043 |
velocityY = Math.max(-mMaxFlingVelocity, Math.min(velocityY, mMaxFlingVelocity)); |
| 2044 |
mViewFlinger.fling(velocityX, velocityY); |
| 2045 |
return true; |
| 2046 |
} |
| 2047 |
} |
| 2048 |
return false; |
| 2049 |
} |
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
public void stopScroll() { |
| 2056 |
setScrollState(SCROLL_STATE_IDLE); |
| 2057 |
stopScrollersInternal(); |
| 2058 |
} |
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
private void stopScrollersInternal() { |
| 2064 |
mViewFlinger.stop(); |
| 2065 |
if (mLayout != null) { |
| 2066 |
mLayout.stopSmoothScroller(); |
| 2067 |
} |
| 2068 |
} |
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
public int getMinFlingVelocity() { |
| 2076 |
return mMinFlingVelocity; |
| 2077 |
} |
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
public int getMaxFlingVelocity() { |
| 2086 |
return mMaxFlingVelocity; |
| 2087 |
} |
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
private void pullGlows(float x, float overscrollX, float y, float overscrollY) { |
| 2093 |
boolean invalidate = false; |
| 2094 |
if (overscrollX < 0) { |
| 2095 |
ensureLeftGlow(); |
| 2096 |
mLeftGlow.onPull(-overscrollX / getWidth(), 1f - y / getHeight()); |
| 2097 |
invalidate = true; |
| 2098 |
} else if (overscrollX > 0) { |
| 2099 |
ensureRightGlow(); |
| 2100 |
mRightGlow.onPull(overscrollX / getWidth(), y / getHeight()); |
| 2101 |
invalidate = true; |
| 2102 |
} |
| 2103 |
|
| 2104 |
if (overscrollY < 0) { |
| 2105 |
ensureTopGlow(); |
| 2106 |
mTopGlow.onPull(-overscrollY / getHeight(), x / getWidth()); |
| 2107 |
invalidate = true; |
| 2108 |
} else if (overscrollY > 0) { |
| 2109 |
ensureBottomGlow(); |
| 2110 |
mBottomGlow.onPull(overscrollY / getHeight(), 1f - x / getWidth()); |
| 2111 |
invalidate = true; |
| 2112 |
} |
| 2113 |
|
| 2114 |
if (invalidate || overscrollX != 0 || overscrollY != 0) { |
| 2115 |
postInvalidateOnAnimation(); |
| 2116 |
} |
| 2117 |
} |
| 2118 |
|
| 2119 |
private void releaseGlows() { |
| 2120 |
boolean needsInvalidate = false; |
| 2121 |
if (mLeftGlow != null) { |
| 2122 |
mLeftGlow.onRelease(); |
| 2123 |
needsInvalidate = true; |
| 2124 |
} |
| 2125 |
if (mTopGlow != null) { |
| 2126 |
mTopGlow.onRelease(); |
| 2127 |
needsInvalidate = true; |
| 2128 |
} |
| 2129 |
if (mRightGlow != null) { |
| 2130 |
mRightGlow.onRelease(); |
| 2131 |
needsInvalidate = true; |
| 2132 |
} |
| 2133 |
if (mBottomGlow != null) { |
| 2134 |
mBottomGlow.onRelease(); |
| 2135 |
needsInvalidate = true; |
| 2136 |
} |
| 2137 |
if (needsInvalidate) { |
| 2138 |
postInvalidateOnAnimation(); |
| 2139 |
} |
| 2140 |
} |
| 2141 |
|
| 2142 |
void considerReleasingGlowsOnScroll(int dx, int dy) { |
| 2143 |
boolean needsInvalidate = false; |
| 2144 |
if (mLeftGlow != null && !mLeftGlow.isFinished() && dx > 0) { |
| 2145 |
mLeftGlow.onRelease(); |
| 2146 |
needsInvalidate = true; |
| 2147 |
} |
| 2148 |
if (mRightGlow != null && !mRightGlow.isFinished() && dx < 0) { |
| 2149 |
mRightGlow.onRelease(); |
| 2150 |
needsInvalidate = true; |
| 2151 |
} |
| 2152 |
if (mTopGlow != null && !mTopGlow.isFinished() && dy > 0) { |
| 2153 |
mTopGlow.onRelease(); |
| 2154 |
needsInvalidate = true; |
| 2155 |
} |
| 2156 |
if (mBottomGlow != null && !mBottomGlow.isFinished() && dy < 0) { |
| 2157 |
mBottomGlow.onRelease(); |
| 2158 |
needsInvalidate = true; |
| 2159 |
} |
| 2160 |
if (needsInvalidate) { |
| 2161 |
postInvalidateOnAnimation(); |
| 2162 |
} |
| 2163 |
} |
| 2164 |
|
| 2165 |
void absorbGlows(int velocityX, int velocityY) { |
| 2166 |
if (velocityX < 0) { |
| 2167 |
ensureLeftGlow(); |
| 2168 |
mLeftGlow.onAbsorb(-velocityX); |
| 2169 |
} else if (velocityX > 0) { |
| 2170 |
ensureRightGlow(); |
| 2171 |
mRightGlow.onAbsorb(velocityX); |
| 2172 |
} |
| 2173 |
|
| 2174 |
if (velocityY < 0) { |
| 2175 |
ensureTopGlow(); |
| 2176 |
mTopGlow.onAbsorb(-velocityY); |
| 2177 |
} else if (velocityY > 0) { |
| 2178 |
ensureBottomGlow(); |
| 2179 |
mBottomGlow.onAbsorb(velocityY); |
| 2180 |
} |
| 2181 |
|
| 2182 |
if (velocityX != 0 || velocityY != 0) { |
| 2183 |
postInvalidateOnAnimation(); |
| 2184 |
} |
| 2185 |
} |
| 2186 |
|
| 2187 |
void ensureLeftGlow() { |
| 2188 |
if (mLeftGlow != null) { |
| 2189 |
return; |
| 2190 |
} |
| 2191 |
mLeftGlow = new EdgeEffect(getContext()); |
| 2192 |
if (mClipToPadding) { |
| 2193 |
mLeftGlow.setSize(getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), |
| 2194 |
getMeasuredWidth() - getPaddingLeft() - getPaddingRight()); |
| 2195 |
} else { |
| 2196 |
mLeftGlow.setSize(getMeasuredHeight(), getMeasuredWidth()); |
| 2197 |
} |
| 2198 |
} |
| 2199 |
|
| 2200 |
void ensureRightGlow() { |
| 2201 |
if (mRightGlow != null) { |
| 2202 |
return; |
| 2203 |
} |
| 2204 |
mRightGlow = new EdgeEffect(getContext()); |
| 2205 |
if (mClipToPadding) { |
| 2206 |
mRightGlow.setSize(getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), |
| 2207 |
getMeasuredWidth() - getPaddingLeft() - getPaddingRight()); |
| 2208 |
} else { |
| 2209 |
mRightGlow.setSize(getMeasuredHeight(), getMeasuredWidth()); |
| 2210 |
} |
| 2211 |
} |
| 2212 |
|
| 2213 |
void ensureTopGlow() { |
| 2214 |
if (mTopGlow != null) { |
| 2215 |
return; |
| 2216 |
} |
| 2217 |
mTopGlow = new EdgeEffect(getContext()); |
| 2218 |
if (mClipToPadding) { |
| 2219 |
mTopGlow.setSize(getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), |
| 2220 |
getMeasuredHeight() - getPaddingTop() - getPaddingBottom()); |
| 2221 |
} else { |
| 2222 |
mTopGlow.setSize(getMeasuredWidth(), getMeasuredHeight()); |
| 2223 |
} |
| 2224 |
|
| 2225 |
} |
| 2226 |
|
| 2227 |
void ensureBottomGlow() { |
| 2228 |
if (mBottomGlow != null) { |
| 2229 |
return; |
| 2230 |
} |
| 2231 |
mBottomGlow = new EdgeEffect(getContext()); |
| 2232 |
if (mClipToPadding) { |
| 2233 |
mBottomGlow.setSize(getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), |
| 2234 |
getMeasuredHeight() - getPaddingTop() - getPaddingBottom()); |
| 2235 |
} else { |
| 2236 |
mBottomGlow.setSize(getMeasuredWidth(), getMeasuredHeight()); |
| 2237 |
} |
| 2238 |
} |
| 2239 |
|
| 2240 |
void invalidateGlows() { |
| 2241 |
mLeftGlow = mRightGlow = mTopGlow = mBottomGlow = null; |
| 2242 |
} |
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
@Override |
| 2275 |
public View focusSearch(View focused, int direction) { |
| 2276 |
View result = mLayout.onInterceptFocusSearch(focused, direction); |
| 2277 |
if (result != null) { |
| 2278 |
return result; |
| 2279 |
} |
| 2280 |
final boolean canRunFocusFailure = mAdapter != null && mLayout != null |
| 2281 |
&& !isComputingLayout() && !mLayoutFrozen; |
| 2282 |
|
| 2283 |
final FocusFinder ff = FocusFinder.getInstance(); |
| 2284 |
if (canRunFocusFailure |
| 2285 |
&& (direction == View.FOCUS_FORWARD || direction == View.FOCUS_BACKWARD)) { |
| 2286 |
|
| 2287 |
|
| 2288 |
boolean needsFocusFailureLayout = false; |
| 2289 |
if (mLayout.canScrollVertically()) { |
| 2290 |
final int absDir = |
| 2291 |
direction == View.FOCUS_FORWARD ? View.FOCUS_DOWN : View.FOCUS_UP; |
| 2292 |
final View found = ff.findNextFocus(this, focused, absDir); |
| 2293 |
needsFocusFailureLayout = found == null; |
| 2294 |
if (FORCE_ABS_FOCUS_SEARCH_DIRECTION) { |
| 2295 |
|
| 2296 |
direction = absDir; |
| 2297 |
} |
| 2298 |
} |
| 2299 |
if (!needsFocusFailureLayout && mLayout.canScrollHorizontally()) { |
| 2300 |
boolean rtl = mLayout.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; |
| 2301 |
final int absDir = (direction == View.FOCUS_FORWARD) ^ rtl |
| 2302 |
? View.FOCUS_RIGHT : View.FOCUS_LEFT; |
| 2303 |
final View found = ff.findNextFocus(this, focused, absDir); |
| 2304 |
needsFocusFailureLayout = found == null; |
| 2305 |
if (FORCE_ABS_FOCUS_SEARCH_DIRECTION) { |
| 2306 |
|
| 2307 |
direction = absDir; |
| 2308 |
} |
| 2309 |
} |
| 2310 |
if (needsFocusFailureLayout) { |
| 2311 |
consumePendingUpdateOperations(); |
| 2312 |
final View focusedItemView = findContainingItemView(focused); |
| 2313 |
if (focusedItemView == null) { |
| 2314 |
|
| 2315 |
return null; |
| 2316 |
} |
| 2317 |
eatRequestLayout(); |
| 2318 |
mLayout.onFocusSearchFailed(focused, direction, mRecycler, mState); |
| 2319 |
resumeRequestLayout(false); |
| 2320 |
} |
| 2321 |
result = ff.findNextFocus(this, focused, direction); |
| 2322 |
} else { |
| 2323 |
result = ff.findNextFocus(this, focused, direction); |
| 2324 |
if (result == null && canRunFocusFailure) { |
| 2325 |
consumePendingUpdateOperations(); |
| 2326 |
final View focusedItemView = findContainingItemView(focused); |
| 2327 |
if (focusedItemView == null) { |
| 2328 |
|
| 2329 |
return null; |
| 2330 |
} |
| 2331 |
eatRequestLayout(); |
| 2332 |
result = mLayout.onFocusSearchFailed(focused, direction, mRecycler, mState); |
| 2333 |
resumeRequestLayout(false); |
| 2334 |
} |
| 2335 |
} |
| 2336 |
return isPreferredNextFocus(focused, result, direction) |
| 2337 |
? result : super.focusSearch(focused, direction); |
| 2338 |
} |
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
private boolean isPreferredNextFocus(View focused, View next, int direction) { |
| 2349 |
if (next == null || next == this) { |
| 2350 |
return false; |
| 2351 |
} |
| 2352 |
if (focused == null) { |
| 2353 |
return true; |
| 2354 |
} |
| 2355 |
|
| 2356 |
if (direction == View.FOCUS_FORWARD || direction == View.FOCUS_BACKWARD) { |
| 2357 |
final boolean rtl = mLayout.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; |
| 2358 |
final int absHorizontal = (direction == View.FOCUS_FORWARD) ^ rtl |
| 2359 |
? View.FOCUS_RIGHT : View.FOCUS_LEFT; |
| 2360 |
if (isPreferredNextFocusAbsolute(focused, next, absHorizontal)) { |
| 2361 |
return true; |
| 2362 |
} |
| 2363 |
if (direction == View.FOCUS_FORWARD) { |
| 2364 |
return isPreferredNextFocusAbsolute(focused, next, View.FOCUS_DOWN); |
| 2365 |
} else { |
| 2366 |
return isPreferredNextFocusAbsolute(focused, next, View.FOCUS_UP); |
| 2367 |
} |
| 2368 |
} else { |
| 2369 |
return isPreferredNextFocusAbsolute(focused, next, direction); |
| 2370 |
} |
| 2371 |
|
| 2372 |
} |
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
private boolean isPreferredNextFocusAbsolute(View focused, View next, int direction) { |
| 2378 |
mTempRect.set(0, 0, focused.getWidth(), focused.getHeight()); |
| 2379 |
mTempRect2.set(0, 0, next.getWidth(), next.getHeight()); |
| 2380 |
offsetDescendantRectToMyCoords(focused, mTempRect); |
| 2381 |
offsetDescendantRectToMyCoords(next, mTempRect2); |
| 2382 |
switch (direction) { |
| 2383 |
case View.FOCUS_LEFT: |
| 2384 |
return (mTempRect.right > mTempRect2.right |
| 2385 |
|| mTempRect.left >= mTempRect2.right) |
| 2386 |
&& mTempRect.left > mTempRect2.left; |
| 2387 |
case View.FOCUS_RIGHT: |
| 2388 |
return (mTempRect.left < mTempRect2.left |
| 2389 |
|| mTempRect.right <= mTempRect2.left) |
| 2390 |
&& mTempRect.right < mTempRect2.right; |
| 2391 |
case View.FOCUS_UP: |
| 2392 |
return (mTempRect.bottom > mTempRect2.bottom |
| 2393 |
|| mTempRect.top >= mTempRect2.bottom) |
| 2394 |
&& mTempRect.top > mTempRect2.top; |
| 2395 |
case View.FOCUS_DOWN: |
| 2396 |
return (mTempRect.top < mTempRect2.top |
| 2397 |
|| mTempRect.bottom <= mTempRect2.top) |
| 2398 |
&& mTempRect.bottom < mTempRect2.bottom; |
| 2399 |
} |
| 2400 |
throw new IllegalArgumentException("direction must be absolute. received:" + direction); |
| 2401 |
} |
| 2402 |
|
| 2403 |
@Override |
| 2404 |
public void requestChildFocus(View child, View focused) { |
| 2405 |
if (!mLayout.onRequestChildFocus(this, mState, child, focused) && focused != null) { |
| 2406 |
mTempRect.set(0, 0, focused.getWidth(), focused.getHeight()); |
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
final ViewGroup.LayoutParams focusedLayoutParams = focused.getLayoutParams(); |
| 2412 |
if (focusedLayoutParams instanceof LayoutParams) { |
| 2413 |
|
| 2414 |
final LayoutParams lp = (LayoutParams) focusedLayoutParams; |
| 2415 |
if (!lp.mInsetsDirty) { |
| 2416 |
final Rect insets = lp.mDecorInsets; |
| 2417 |
mTempRect.left -= insets.left; |
| 2418 |
mTempRect.right += insets.right; |
| 2419 |
mTempRect.top -= insets.top; |
| 2420 |
mTempRect.bottom += insets.bottom; |
| 2421 |
} |
| 2422 |
} |
| 2423 |
|
| 2424 |
offsetDescendantRectToMyCoords(focused, mTempRect); |
| 2425 |
offsetRectIntoDescendantCoords(child, mTempRect); |
| 2426 |
requestChildRectangleOnScreen(child, mTempRect, !mFirstLayoutComplete); |
| 2427 |
} |
| 2428 |
super.requestChildFocus(child, focused); |
| 2429 |
} |
| 2430 |
|
| 2431 |
@Override |
| 2432 |
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) { |
| 2433 |
return mLayout.requestChildRectangleOnScreen(this, child, rect, immediate); |
| 2434 |
} |
| 2435 |
|
| 2436 |
@Override |
| 2437 |
public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
| 2438 |
if (mLayout == null || !mLayout.onAddFocusables(this, views, direction, focusableMode)) { |
| 2439 |
super.addFocusables(views, direction, focusableMode); |
| 2440 |
} |
| 2441 |
} |
| 2442 |
|
| 2443 |
@Override |
| 2444 |
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { |
| 2445 |
if (isComputingLayout()) { |
| 2446 |
|
| 2447 |
|
| 2448 |
return false; |
| 2449 |
} |
| 2450 |
return super.onRequestFocusInDescendants(direction, previouslyFocusedRect); |
| 2451 |
} |
| 2452 |
|
| 2453 |
@Override |
| 2454 |
protected void onAttachedToWindow() { |
| 2455 |
super.onAttachedToWindow(); |
| 2456 |
mLayoutOrScrollCounter = 0; |
| 2457 |
mIsAttached = true; |
| 2458 |
mFirstLayoutComplete = mFirstLayoutComplete && !isLayoutRequested(); |
| 2459 |
if (mLayout != null) { |
| 2460 |
mLayout.dispatchAttachedToWindow(this); |
| 2461 |
} |
| 2462 |
mPostedAnimatorRunner = false; |
| 2463 |
|
| 2464 |
if (ALLOW_THREAD_GAP_WORK) { |
| 2465 |
|
| 2466 |
mGapWorker = GapWorker.sGapWorker.get(); |
| 2467 |
if (mGapWorker == null) { |
| 2468 |
mGapWorker = new GapWorker(); |
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
Display display = getDisplay(); |
| 2473 |
float refreshRate = 60.0f; |
| 2474 |
if (!isInEditMode() && display != null) { |
| 2475 |
float displayRefreshRate = display.getRefreshRate(); |
| 2476 |
if (displayRefreshRate >= 30.0f) { |
| 2477 |
refreshRate = displayRefreshRate; |
| 2478 |
} |
| 2479 |
} |
| 2480 |
mGapWorker.mFrameIntervalNs = (long) (1000000000 / refreshRate); |
| 2481 |
GapWorker.sGapWorker.set(mGapWorker); |
| 2482 |
} |
| 2483 |
mGapWorker.add(this); |
| 2484 |
} |
| 2485 |
} |
| 2486 |
|
| 2487 |
@Override |
| 2488 |
protected void onDetachedFromWindow() { |
| 2489 |
super.onDetachedFromWindow(); |
| 2490 |
if (mItemAnimator != null) { |
| 2491 |
mItemAnimator.endAnimations(); |
| 2492 |
} |
| 2493 |
stopScroll(); |
| 2494 |
mIsAttached = false; |
| 2495 |
if (mLayout != null) { |
| 2496 |
mLayout.dispatchDetachedFromWindow(this, mRecycler); |
| 2497 |
} |
| 2498 |
mPendingAccessibilityImportanceChange.clear(); |
| 2499 |
removeCallbacks(mItemAnimatorRunner); |
| 2500 |
mViewInfoStore.onDetach(); |
| 2501 |
|
| 2502 |
if (ALLOW_THREAD_GAP_WORK) { |
| 2503 |
|
| 2504 |
mGapWorker.remove(this); |
| 2505 |
mGapWorker = null; |
| 2506 |
} |
| 2507 |
} |
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
public boolean isAttachedToWindow() { |
| 2514 |
return mIsAttached; |
| 2515 |
} |
| 2516 |
|
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
void assertInLayoutOrScroll(String message) { |
| 2525 |
if (!isComputingLayout()) { |
| 2526 |
if (message == null) { |
| 2527 |
throw new IllegalStateException("Cannot call this method unless RecyclerView is " |
| 2528 |
+ "computing a layout or scrolling"); |
| 2529 |
} |
| 2530 |
throw new IllegalStateException(message); |
| 2531 |
|
| 2532 |
} |
| 2533 |
} |
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
void assertNotInLayoutOrScroll(String message) { |
| 2543 |
if (isComputingLayout()) { |
| 2544 |
if (message == null) { |
| 2545 |
throw new IllegalStateException("Cannot call this method while RecyclerView is " |
| 2546 |
+ "computing a layout or scrolling"); |
| 2547 |
} |
| 2548 |
throw new IllegalStateException(message); |
| 2549 |
} |
| 2550 |
if (mDispatchScrollCounter > 0) { |
| 2551 |
Log.w(TAG, "Cannot call this method in a scroll callback. Scroll callbacks might be run" |
| 2552 |
+ " during a measure & layout pass where you cannot change the RecyclerView" |
| 2553 |
+ " data. Any method call that might change the structure of the RecyclerView" |
| 2554 |
+ " or the adapter contents should be postponed to the next frame.", |
| 2555 |
new IllegalStateException("")); |
| 2556 |
} |
| 2557 |
} |
| 2558 |
|
| 2559 |
|
| 2560 |
|
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
public void addOnItemTouchListener(OnItemTouchListener listener) { |
| 2573 |
mOnItemTouchListeners.add(listener); |
| 2574 |
} |
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
public void removeOnItemTouchListener(OnItemTouchListener listener) { |
| 2582 |
mOnItemTouchListeners.remove(listener); |
| 2583 |
if (mActiveOnItemTouchListener == listener) { |
| 2584 |
mActiveOnItemTouchListener = null; |
| 2585 |
} |
| 2586 |
} |
| 2587 |
|
| 2588 |
private boolean dispatchOnItemTouchIntercept(MotionEvent e) { |
| 2589 |
final int action = e.getAction(); |
| 2590 |
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_DOWN) { |
| 2591 |
mActiveOnItemTouchListener = null; |
| 2592 |
} |
| 2593 |
|
| 2594 |
final int listenerCount = mOnItemTouchListeners.size(); |
| 2595 |
for (int i = 0; i < listenerCount; i++) { |
| 2596 |
final OnItemTouchListener listener = mOnItemTouchListeners.get(i); |
| 2597 |
if (listener.onInterceptTouchEvent(this, e) && action != MotionEvent.ACTION_CANCEL) { |
| 2598 |
mActiveOnItemTouchListener = listener; |
| 2599 |
return true; |
| 2600 |
} |
| 2601 |
} |
| 2602 |
return false; |
| 2603 |
} |
| 2604 |
|
| 2605 |
private boolean dispatchOnItemTouch(MotionEvent e) { |
| 2606 |
final int action = e.getAction(); |
| 2607 |
if (mActiveOnItemTouchListener != null) { |
| 2608 |
if (action == MotionEvent.ACTION_DOWN) { |
| 2609 |
|
| 2610 |
mActiveOnItemTouchListener = null; |
| 2611 |
} else { |
| 2612 |
mActiveOnItemTouchListener.onTouchEvent(this, e); |
| 2613 |
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { |
| 2614 |
|
| 2615 |
mActiveOnItemTouchListener = null; |
| 2616 |
} |
| 2617 |
return true; |
| 2618 |
} |
| 2619 |
} |
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
if (action != MotionEvent.ACTION_DOWN) { |
| 2624 |
final int listenerCount = mOnItemTouchListeners.size(); |
| 2625 |
for (int i = 0; i < listenerCount; i++) { |
| 2626 |
final OnItemTouchListener listener = mOnItemTouchListeners.get(i); |
| 2627 |
if (listener.onInterceptTouchEvent(this, e)) { |
| 2628 |
mActiveOnItemTouchListener = listener; |
| 2629 |
return true; |
| 2630 |
} |
| 2631 |
} |
| 2632 |
} |
| 2633 |
return false; |
| 2634 |
} |
| 2635 |
|
| 2636 |
@Override |
| 2637 |
public boolean onInterceptTouchEvent(MotionEvent e) { |
| 2638 |
if (mLayoutFrozen) { |
| 2639 |
|
| 2640 |
|
| 2641 |
return false; |
| 2642 |
} |
| 2643 |
if (dispatchOnItemTouchIntercept(e)) { |
| 2644 |
cancelTouch(); |
| 2645 |
return true; |
| 2646 |
} |
| 2647 |
|
| 2648 |
if (mLayout == null) { |
| 2649 |
return false; |
| 2650 |
} |
| 2651 |
|
| 2652 |
final boolean canScrollHorizontally = mLayout.canScrollHorizontally(); |
| 2653 |
final boolean canScrollVertically = mLayout.canScrollVertically(); |
| 2654 |
|
| 2655 |
if (mVelocityTracker == null) { |
| 2656 |
mVelocityTracker = VelocityTracker.obtain(); |
| 2657 |
} |
| 2658 |
mVelocityTracker.addMovement(e); |
| 2659 |
|
| 2660 |
final int action = e.getActionMasked(); |
| 2661 |
final int actionIndex = e.getActionIndex(); |
| 2662 |
|
| 2663 |
switch (action) { |
| 2664 |
case MotionEvent.ACTION_DOWN: |
| 2665 |
if (mIgnoreMotionEventTillDown) { |
| 2666 |
mIgnoreMotionEventTillDown = false; |
| 2667 |
} |
| 2668 |
mScrollPointerId = e.getPointerId(0); |
| 2669 |
mInitialTouchX = mLastTouchX = (int) (e.getX() + 0.5f); |
| 2670 |
mInitialTouchY = mLastTouchY = (int) (e.getY() + 0.5f); |
| 2671 |
|
| 2672 |
if (stopGlowAnimations(e) || mScrollState == SCROLL_STATE_SETTLING) { |
| 2673 |
getParent().requestDisallowInterceptTouchEvent(true); |
| 2674 |
setScrollState(SCROLL_STATE_DRAGGING); |
| 2675 |
} |
| 2676 |
|
| 2677 |
|
| 2678 |
mNestedOffsets[0] = mNestedOffsets[1] = 0; |
| 2679 |
|
| 2680 |
int nestedScrollAxis = View.SCROLL_AXIS_NONE; |
| 2681 |
if (canScrollHorizontally) { |
| 2682 |
nestedScrollAxis |= View.SCROLL_AXIS_HORIZONTAL; |
| 2683 |
} |
| 2684 |
if (canScrollVertically) { |
| 2685 |
nestedScrollAxis |= View.SCROLL_AXIS_VERTICAL; |
| 2686 |
} |
| 2687 |
startNestedScroll(nestedScrollAxis); |
| 2688 |
break; |
| 2689 |
|
| 2690 |
case MotionEvent.ACTION_POINTER_DOWN: |
| 2691 |
mScrollPointerId = e.getPointerId(actionIndex); |
| 2692 |
mInitialTouchX = mLastTouchX = (int) (e.getX(actionIndex) + 0.5f); |
| 2693 |
mInitialTouchY = mLastTouchY = (int) (e.getY(actionIndex) + 0.5f); |
| 2694 |
break; |
| 2695 |
|
| 2696 |
case MotionEvent.ACTION_MOVE: { |
| 2697 |
final int index = e.findPointerIndex(mScrollPointerId); |
| 2698 |
if (index < 0) { |
| 2699 |
Log.e(TAG, "Error processing scroll; pointer index for id " |
| 2700 |
+ mScrollPointerId + " not found. Did any MotionEvents get skipped?"); |
| 2701 |
return false; |
| 2702 |
} |
| 2703 |
|
| 2704 |
final int x = (int) (e.getX(index) + 0.5f); |
| 2705 |
final int y = (int) (e.getY(index) + 0.5f); |
| 2706 |
if (mScrollState != SCROLL_STATE_DRAGGING) { |
| 2707 |
final int dx = x - mInitialTouchX; |
| 2708 |
final int dy = y - mInitialTouchY; |
| 2709 |
boolean startScroll = false; |
| 2710 |
if (canScrollHorizontally && Math.abs(dx) > mTouchSlop) { |
| 2711 |
mLastTouchX = mInitialTouchX + mTouchSlop * (dx < 0 ? -1 : 1); |
| 2712 |
startScroll = true; |
| 2713 |
} |
| 2714 |
if (canScrollVertically && Math.abs(dy) > mTouchSlop) { |
| 2715 |
mLastTouchY = mInitialTouchY + mTouchSlop * (dy < 0 ? -1 : 1); |
| 2716 |
startScroll = true; |
| 2717 |
} |
| 2718 |
if (startScroll) { |
| 2719 |
setScrollState(SCROLL_STATE_DRAGGING); |
| 2720 |
} |
| 2721 |
} |
| 2722 |
} break; |
| 2723 |
|
| 2724 |
case MotionEvent.ACTION_POINTER_UP: { |
| 2725 |
onPointerUp(e); |
| 2726 |
} break; |
| 2727 |
|
| 2728 |
case MotionEvent.ACTION_UP: { |
| 2729 |
mVelocityTracker.clear(); |
| 2730 |
stopNestedScroll(); |
| 2731 |
} break; |
| 2732 |
|
| 2733 |
case MotionEvent.ACTION_CANCEL: { |
| 2734 |
cancelTouch(); |
| 2735 |
} |
| 2736 |
} |
| 2737 |
return mScrollState == SCROLL_STATE_DRAGGING; |
| 2738 |
} |
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
private boolean stopGlowAnimations(MotionEvent e) { |
| 2752 |
boolean stopped = false; |
| 2753 |
if (mLeftGlow != null && mLeftGlow.getDistance() != 0) { |
| 2754 |
mLeftGlow.onPullDistance(0, 1 - (e.getY() / getHeight())); |
| 2755 |
stopped = true; |
| 2756 |
} |
| 2757 |
if (mRightGlow != null && mRightGlow.getDistance() != 0) { |
| 2758 |
mRightGlow.onPullDistance(0, e.getY() / getHeight()); |
| 2759 |
stopped = true; |
| 2760 |
} |
| 2761 |
if (mTopGlow != null && mTopGlow.getDistance() != 0) { |
| 2762 |
mTopGlow.onPullDistance(0, e.getX() / getWidth()); |
| 2763 |
stopped = true; |
| 2764 |
} |
| 2765 |
if (mBottomGlow != null && mBottomGlow.getDistance() != 0) { |
| 2766 |
mBottomGlow.onPullDistance(0, 1 - e.getX() / getWidth()); |
| 2767 |
stopped = true; |
| 2768 |
} |
| 2769 |
return stopped; |
| 2770 |
} |
| 2771 |
|
| 2772 |
@Override |
| 2773 |
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 2774 |
final int listenerCount = mOnItemTouchListeners.size(); |
| 2775 |
for (int i = 0; i < listenerCount; i++) { |
| 2776 |
final OnItemTouchListener listener = mOnItemTouchListeners.get(i); |
| 2777 |
listener.onRequestDisallowInterceptTouchEvent(disallowIntercept); |
| 2778 |
} |
| 2779 |
super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 2780 |
} |
| 2781 |
|
| 2782 |
@Override |
| 2783 |
public boolean onTouchEvent(MotionEvent e) { |
| 2784 |
if (mLayoutFrozen || mIgnoreMotionEventTillDown) { |
| 2785 |
return false; |
| 2786 |
} |
| 2787 |
if (dispatchOnItemTouch(e)) { |
| 2788 |
cancelTouch(); |
| 2789 |
return true; |
| 2790 |
} |
| 2791 |
|
| 2792 |
if (mLayout == null) { |
| 2793 |
return false; |
| 2794 |
} |
| 2795 |
|
| 2796 |
final boolean canScrollHorizontally = mLayout.canScrollHorizontally(); |
| 2797 |
final boolean canScrollVertically = mLayout.canScrollVertically(); |
| 2798 |
|
| 2799 |
if (mVelocityTracker == null) { |
| 2800 |
mVelocityTracker = VelocityTracker.obtain(); |
| 2801 |
} |
| 2802 |
boolean eventAddedToVelocityTracker = false; |
| 2803 |
|
| 2804 |
final MotionEvent vtev = MotionEvent.obtain(e); |
| 2805 |
final int action = e.getActionMasked(); |
| 2806 |
final int actionIndex = e.getActionIndex(); |
| 2807 |
|
| 2808 |
if (action == MotionEvent.ACTION_DOWN) { |
| 2809 |
mNestedOffsets[0] = mNestedOffsets[1] = 0; |
| 2810 |
} |
| 2811 |
vtev.offsetLocation(mNestedOffsets[0], mNestedOffsets[1]); |
| 2812 |
|
| 2813 |
switch (action) { |
| 2814 |
case MotionEvent.ACTION_DOWN: { |
| 2815 |
mScrollPointerId = e.getPointerId(0); |
| 2816 |
mInitialTouchX = mLastTouchX = (int) (e.getX() + 0.5f); |
| 2817 |
mInitialTouchY = mLastTouchY = (int) (e.getY() + 0.5f); |
| 2818 |
|
| 2819 |
int nestedScrollAxis = View.SCROLL_AXIS_NONE; |
| 2820 |
if (canScrollHorizontally) { |
| 2821 |
nestedScrollAxis |= View.SCROLL_AXIS_HORIZONTAL; |
| 2822 |
} |
| 2823 |
if (canScrollVertically) { |
| 2824 |
nestedScrollAxis |= View.SCROLL_AXIS_VERTICAL; |
| 2825 |
} |
| 2826 |
startNestedScroll(nestedScrollAxis); |
| 2827 |
} break; |
| 2828 |
|
| 2829 |
case MotionEvent.ACTION_POINTER_DOWN: { |
| 2830 |
mScrollPointerId = e.getPointerId(actionIndex); |
| 2831 |
mInitialTouchX = mLastTouchX = (int) (e.getX(actionIndex) + 0.5f); |
| 2832 |
mInitialTouchY = mLastTouchY = (int) (e.getY(actionIndex) + 0.5f); |
| 2833 |
} break; |
| 2834 |
|
| 2835 |
case MotionEvent.ACTION_MOVE: { |
| 2836 |
final int index = e.findPointerIndex(mScrollPointerId); |
| 2837 |
if (index < 0) { |
| 2838 |
Log.e(TAG, "Error processing scroll; pointer index for id " |
| 2839 |
+ mScrollPointerId + " not found. Did any MotionEvents get skipped?"); |
| 2840 |
vtev.recycle(); |
| 2841 |
return false; |
| 2842 |
} |
| 2843 |
|
| 2844 |
final int x = (int) (e.getX(index) + 0.5f); |
| 2845 |
final int y = (int) (e.getY(index) + 0.5f); |
| 2846 |
int dx = mLastTouchX - x; |
| 2847 |
int dy = mLastTouchY - y; |
| 2848 |
dx -= releaseHorizontalGlow(dx, e.getY()); |
| 2849 |
dy -= releaseVerticalGlow(dy, e.getX()); |
| 2850 |
|
| 2851 |
if (dispatchNestedPreScroll(dx, dy, mScrollConsumed, mScrollOffset)) { |
| 2852 |
dx -= mScrollConsumed[0]; |
| 2853 |
dy -= mScrollConsumed[1]; |
| 2854 |
vtev.offsetLocation(mScrollOffset[0], mScrollOffset[1]); |
| 2855 |
|
| 2856 |
mNestedOffsets[0] += mScrollOffset[0]; |
| 2857 |
mNestedOffsets[1] += mScrollOffset[1]; |
| 2858 |
} |
| 2859 |
|
| 2860 |
if (mScrollState != SCROLL_STATE_DRAGGING) { |
| 2861 |
boolean startScroll = false; |
| 2862 |
if (canScrollHorizontally && Math.abs(dx) > mTouchSlop) { |
| 2863 |
if (dx > 0) { |
| 2864 |
dx -= mTouchSlop; |
| 2865 |
} else { |
| 2866 |
dx += mTouchSlop; |
| 2867 |
} |
| 2868 |
startScroll = true; |
| 2869 |
} |
| 2870 |
if (canScrollVertically && Math.abs(dy) > mTouchSlop) { |
| 2871 |
if (dy > 0) { |
| 2872 |
dy -= mTouchSlop; |
| 2873 |
} else { |
| 2874 |
dy += mTouchSlop; |
| 2875 |
} |
| 2876 |
startScroll = true; |
| 2877 |
} |
| 2878 |
if (startScroll) { |
| 2879 |
setScrollState(SCROLL_STATE_DRAGGING); |
| 2880 |
} |
| 2881 |
} |
| 2882 |
|
| 2883 |
if (mScrollState == SCROLL_STATE_DRAGGING) { |
| 2884 |
mLastTouchX = x - mScrollOffset[0]; |
| 2885 |
mLastTouchY = y - mScrollOffset[1]; |
| 2886 |
|
| 2887 |
if (scrollByInternal( |
| 2888 |
canScrollHorizontally ? dx : 0, |
| 2889 |
canScrollVertically ? dy : 0, |
| 2890 |
vtev)) { |
| 2891 |
getParent().requestDisallowInterceptTouchEvent(true); |
| 2892 |
} |
| 2893 |
if (mGapWorker != null && (dx != 0 || dy != 0)) { |
| 2894 |
mGapWorker.postFromTraversal(this, dx, dy); |
| 2895 |
} |
| 2896 |
} |
| 2897 |
} break; |
| 2898 |
|
| 2899 |
case MotionEvent.ACTION_POINTER_UP: { |
| 2900 |
onPointerUp(e); |
| 2901 |
} break; |
| 2902 |
|
| 2903 |
case MotionEvent.ACTION_UP: { |
| 2904 |
mVelocityTracker.addMovement(vtev); |
| 2905 |
eventAddedToVelocityTracker = true; |
| 2906 |
mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity); |
| 2907 |
final float xvel = canScrollHorizontally |
| 2908 |
? -mVelocityTracker.getXVelocity(mScrollPointerId) : 0; |
| 2909 |
final float yvel = canScrollVertically |
| 2910 |
? -mVelocityTracker.getYVelocity(mScrollPointerId) : 0; |
| 2911 |
if (!((xvel != 0 || yvel != 0) && fling((int) xvel, (int) yvel))) { |
| 2912 |
setScrollState(SCROLL_STATE_IDLE); |
| 2913 |
} |
| 2914 |
resetTouch(); |
| 2915 |
} break; |
| 2916 |
|
| 2917 |
case MotionEvent.ACTION_CANCEL: { |
| 2918 |
cancelTouch(); |
| 2919 |
} break; |
| 2920 |
} |
| 2921 |
|
| 2922 |
if (!eventAddedToVelocityTracker) { |
| 2923 |
mVelocityTracker.addMovement(vtev); |
| 2924 |
} |
| 2925 |
vtev.recycle(); |
| 2926 |
|
| 2927 |
return true; |
| 2928 |
} |
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
private int releaseHorizontalGlow(int deltaX, float y) { |
| 2941 |
|
| 2942 |
float consumed = 0; |
| 2943 |
float displacement = y / getHeight(); |
| 2944 |
float pullDistance = (float) deltaX / getWidth(); |
| 2945 |
if (mLeftGlow != null && mLeftGlow.getDistance() != 0) { |
| 2946 |
consumed = -mLeftGlow.onPullDistance(-pullDistance, 1 - displacement); |
| 2947 |
if (mLeftGlow.getDistance() == 0) { |
| 2948 |
mLeftGlow.onRelease(); |
| 2949 |
} |
| 2950 |
} else if (mRightGlow != null && mRightGlow.getDistance() != 0) { |
| 2951 |
consumed = mRightGlow.onPullDistance(pullDistance, displacement); |
| 2952 |
if (mRightGlow.getDistance() == 0) { |
| 2953 |
mRightGlow.onRelease(); |
| 2954 |
} |
| 2955 |
} |
| 2956 |
int pixelsConsumed = Math.round(consumed * getWidth()); |
| 2957 |
if (pixelsConsumed != 0) { |
| 2958 |
invalidate(); |
| 2959 |
} |
| 2960 |
return pixelsConsumed; |
| 2961 |
} |
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
|
| 2970 |
|
| 2971 |
|
| 2972 |
|
| 2973 |
private int releaseVerticalGlow(int deltaY, float x) { |
| 2974 |
|
| 2975 |
float consumed = 0; |
| 2976 |
float displacement = x / getWidth(); |
| 2977 |
float pullDistance = (float) deltaY / getHeight(); |
| 2978 |
if (mTopGlow != null && mTopGlow.getDistance() != 0) { |
| 2979 |
consumed = -mTopGlow.onPullDistance(-pullDistance, displacement); |
| 2980 |
if (mTopGlow.getDistance() == 0) { |
| 2981 |
mTopGlow.onRelease(); |
| 2982 |
} |
| 2983 |
} else if (mBottomGlow != null && mBottomGlow.getDistance() != 0) { |
| 2984 |
consumed = mBottomGlow.onPullDistance(pullDistance, 1 - displacement); |
| 2985 |
if (mBottomGlow.getDistance() == 0) { |
| 2986 |
mBottomGlow.onRelease(); |
| 2987 |
} |
| 2988 |
} |
| 2989 |
int pixelsConsumed = Math.round(consumed * getHeight()); |
| 2990 |
if (pixelsConsumed != 0) { |
| 2991 |
invalidate(); |
| 2992 |
} |
| 2993 |
return pixelsConsumed; |
| 2994 |
} |
| 2995 |
|
| 2996 |
private void resetTouch() { |
| 2997 |
if (mVelocityTracker != null) { |
| 2998 |
mVelocityTracker.clear(); |
| 2999 |
} |
| 3000 |
stopNestedScroll(); |
| 3001 |
releaseGlows(); |
| 3002 |
} |
| 3003 |
|
| 3004 |
private void cancelTouch() { |
| 3005 |
resetTouch(); |
| 3006 |
setScrollState(SCROLL_STATE_IDLE); |
| 3007 |
} |
| 3008 |
|
| 3009 |
private void onPointerUp(MotionEvent e) { |
| 3010 |
final int actionIndex = e.getActionIndex(); |
| 3011 |
if (e.getPointerId(actionIndex) == mScrollPointerId) { |
| 3012 |
|
| 3013 |
final int newIndex = actionIndex == 0 ? 1 : 0; |
| 3014 |
mScrollPointerId = e.getPointerId(newIndex); |
| 3015 |
mInitialTouchX = mLastTouchX = (int) (e.getX(newIndex) + 0.5f); |
| 3016 |
mInitialTouchY = mLastTouchY = (int) (e.getY(newIndex) + 0.5f); |
| 3017 |
} |
| 3018 |
} |
| 3019 |
|
| 3020 |
|
| 3021 |
public boolean onGenericMotionEvent(MotionEvent event) { |
| 3022 |
if (mLayout == null) { |
| 3023 |
return false; |
| 3024 |
} |
| 3025 |
if (mLayoutFrozen) { |
| 3026 |
return false; |
| 3027 |
} |
| 3028 |
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3029 |
if (event.getAction() == MotionEvent.ACTION_SCROLL) { |
| 3030 |
final float vScroll, hScroll; |
| 3031 |
if (mLayout.canScrollVertically()) { |
| 3032 |
|
| 3033 |
|
| 3034 |
vScroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL); |
| 3035 |
} else { |
| 3036 |
vScroll = 0f; |
| 3037 |
} |
| 3038 |
if (mLayout.canScrollHorizontally()) { |
| 3039 |
hScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL); |
| 3040 |
} else { |
| 3041 |
hScroll = 0f; |
| 3042 |
} |
| 3043 |
|
| 3044 |
if (vScroll != 0 || hScroll != 0) { |
| 3045 |
final float scrollFactor = getScrollFactor(); |
| 3046 |
scrollByInternal((int) (hScroll * scrollFactor), |
| 3047 |
(int) (vScroll * scrollFactor), event); |
| 3048 |
} |
| 3049 |
} |
| 3050 |
} |
| 3051 |
return false; |
| 3052 |
} |
| 3053 |
|
| 3054 |
|
| 3055 |
|
| 3056 |
|
| 3057 |
private float getScrollFactor() { |
| 3058 |
if (mScrollFactor == Float.MIN_VALUE) { |
| 3059 |
TypedValue outValue = new TypedValue(); |
| 3060 |
if (getContext().getTheme().resolveAttribute( |
| 3061 |
android.R.attr.listPreferredItemHeight, outValue, true)) { |
| 3062 |
mScrollFactor = outValue.getDimension( |
| 3063 |
getContext().getResources().getDisplayMetrics()); |
| 3064 |
} else { |
| 3065 |
return 0; |
| 3066 |
} |
| 3067 |
} |
| 3068 |
return mScrollFactor; |
| 3069 |
} |
| 3070 |
|
| 3071 |
@Override |
| 3072 |
protected void onMeasure(int widthSpec, int heightSpec) { |
| 3073 |
if (mLayout == null) { |
| 3074 |
defaultOnMeasure(widthSpec, heightSpec); |
| 3075 |
return; |
| 3076 |
} |
| 3077 |
if (mLayout.mAutoMeasure) { |
| 3078 |
final int widthMode = MeasureSpec.getMode(widthSpec); |
| 3079 |
final int heightMode = MeasureSpec.getMode(heightSpec); |
| 3080 |
final boolean skipMeasure = widthMode == MeasureSpec.EXACTLY |
| 3081 |
&& heightMode == MeasureSpec.EXACTLY; |
| 3082 |
mLayout.onMeasure(mRecycler, mState, widthSpec, heightSpec); |
| 3083 |
if (skipMeasure || mAdapter == null) { |
| 3084 |
return; |
| 3085 |
} |
| 3086 |
if (mState.mLayoutStep == State.STEP_START) { |
| 3087 |
dispatchLayoutStep1(); |
| 3088 |
} |
| 3089 |
|
| 3090 |
|
| 3091 |
mLayout.setMeasureSpecs(widthSpec, heightSpec); |
| 3092 |
mState.mIsMeasuring = true; |
| 3093 |
dispatchLayoutStep2(); |
| 3094 |
|
| 3095 |
|
| 3096 |
mLayout.setMeasuredDimensionFromChildren(widthSpec, heightSpec); |
| 3097 |
|
| 3098 |
|
| 3099 |
|
| 3100 |
if (mLayout.shouldMeasureTwice()) { |
| 3101 |
mLayout.setMeasureSpecs( |
| 3102 |
MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY), |
| 3103 |
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY)); |
| 3104 |
mState.mIsMeasuring = true; |
| 3105 |
dispatchLayoutStep2(); |
| 3106 |
|
| 3107 |
mLayout.setMeasuredDimensionFromChildren(widthSpec, heightSpec); |
| 3108 |
} |
| 3109 |
} else { |
| 3110 |
if (mHasFixedSize) { |
| 3111 |
mLayout.onMeasure(mRecycler, mState, widthSpec, heightSpec); |
| 3112 |
return; |
| 3113 |
} |
| 3114 |
|
| 3115 |
if (mAdapterUpdateDuringMeasure) { |
| 3116 |
eatRequestLayout(); |
| 3117 |
onEnterLayoutOrScroll(); |
| 3118 |
processAdapterUpdatesAndSetAnimationFlags(); |
| 3119 |
onExitLayoutOrScroll(); |
| 3120 |
|
| 3121 |
if (mState.mRunPredictiveAnimations) { |
| 3122 |
mState.mInPreLayout = true; |
| 3123 |
} else { |
| 3124 |
|
| 3125 |
mAdapterHelper.consumeUpdatesInOnePass(); |
| 3126 |
mState.mInPreLayout = false; |
| 3127 |
} |
| 3128 |
mAdapterUpdateDuringMeasure = false; |
| 3129 |
resumeRequestLayout(false); |
| 3130 |
} |
| 3131 |
|
| 3132 |
if (mAdapter != null) { |
| 3133 |
mState.mItemCount = mAdapter.getItemCount(); |
| 3134 |
} else { |
| 3135 |
mState.mItemCount = 0; |
| 3136 |
} |
| 3137 |
eatRequestLayout(); |
| 3138 |
mLayout.onMeasure(mRecycler, mState, widthSpec, heightSpec); |
| 3139 |
resumeRequestLayout(false); |
| 3140 |
mState.mInPreLayout = false; |
| 3141 |
} |
| 3142 |
} |
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
void defaultOnMeasure(int widthSpec, int heightSpec) { |
| 3148 |
|
| 3149 |
|
| 3150 |
final int width = LayoutManager.chooseSize(widthSpec, |
| 3151 |
getPaddingLeft() + getPaddingRight(), |
| 3152 |
getMinimumWidth()); |
| 3153 |
final int height = LayoutManager.chooseSize(heightSpec, |
| 3154 |
getPaddingTop() + getPaddingBottom(), |
| 3155 |
getMinimumHeight()); |
| 3156 |
|
| 3157 |
setMeasuredDimension(width, height); |
| 3158 |
} |
| 3159 |
|
| 3160 |
@Override |
| 3161 |
protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 3162 |
super.onSizeChanged(w, h, oldw, oldh); |
| 3163 |
if (w != oldw || h != oldh) { |
| 3164 |
invalidateGlows(); |
| 3165 |
|
| 3166 |
} |
| 3167 |
} |
| 3168 |
|
| 3169 |
|
| 3170 |
|
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
public void setItemAnimator(ItemAnimator animator) { |
| 3181 |
if (mItemAnimator != null) { |
| 3182 |
mItemAnimator.endAnimations(); |
| 3183 |
mItemAnimator.setListener(null); |
| 3184 |
} |
| 3185 |
mItemAnimator = animator; |
| 3186 |
if (mItemAnimator != null) { |
| 3187 |
mItemAnimator.setListener(mItemAnimatorListener); |
| 3188 |
} |
| 3189 |
} |
| 3190 |
|
| 3191 |
void onEnterLayoutOrScroll() { |
| 3192 |
mLayoutOrScrollCounter++; |
| 3193 |
} |
| 3194 |
|
| 3195 |
void onExitLayoutOrScroll() { |
| 3196 |
mLayoutOrScrollCounter--; |
| 3197 |
if (mLayoutOrScrollCounter < 1) { |
| 3198 |
if (DEBUG && mLayoutOrScrollCounter < 0) { |
| 3199 |
throw new IllegalStateException("layout or scroll counter cannot go below zero." |
| 3200 |
+ "Some calls are not matching"); |
| 3201 |
} |
| 3202 |
mLayoutOrScrollCounter = 0; |
| 3203 |
dispatchContentChangedIfNecessary(); |
| 3204 |
dispatchPendingImportantForAccessibilityChanges(); |
| 3205 |
} |
| 3206 |
} |
| 3207 |
|
| 3208 |
boolean isAccessibilityEnabled() { |
| 3209 |
return mAccessibilityManager != null && mAccessibilityManager.isEnabled(); |
| 3210 |
} |
| 3211 |
|
| 3212 |
private void dispatchContentChangedIfNecessary() { |
| 3213 |
final int flags = mEatenAccessibilityChangeFlags; |
| 3214 |
mEatenAccessibilityChangeFlags = 0; |
| 3215 |
if (flags != 0 && isAccessibilityEnabled()) { |
| 3216 |
final AccessibilityEvent event = AccessibilityEvent.obtain(); |
| 3217 |
event.setEventType(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
| 3218 |
event.setContentChangeTypes(flags); |
| 3219 |
sendAccessibilityEventUnchecked(event); |
| 3220 |
} |
| 3221 |
} |
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
|
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
|
| 3241 |
|
| 3242 |
public boolean isComputingLayout() { |
| 3243 |
return mLayoutOrScrollCounter > 0; |
| 3244 |
} |
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
boolean shouldDeferAccessibilityEvent(AccessibilityEvent event) { |
| 3255 |
if (isComputingLayout()) { |
| 3256 |
int type = 0; |
| 3257 |
if (event != null) { |
| 3258 |
type = event.getContentChangeTypes(); |
| 3259 |
} |
| 3260 |
if (type == 0) { |
| 3261 |
type = AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED; |
| 3262 |
} |
| 3263 |
mEatenAccessibilityChangeFlags |= type; |
| 3264 |
return true; |
| 3265 |
} |
| 3266 |
return false; |
| 3267 |
} |
| 3268 |
|
| 3269 |
@Override |
| 3270 |
public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
| 3271 |
if (shouldDeferAccessibilityEvent(event)) { |
| 3272 |
return; |
| 3273 |
} |
| 3274 |
super.sendAccessibilityEventUnchecked(event); |
| 3275 |
} |
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
public ItemAnimator getItemAnimator() { |
| 3287 |
return mItemAnimator; |
| 3288 |
} |
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
void postAnimationRunner() { |
| 3295 |
if (!mPostedAnimatorRunner && mIsAttached) { |
| 3296 |
postOnAnimation(mItemAnimatorRunner); |
| 3297 |
mPostedAnimatorRunner = true; |
| 3298 |
} |
| 3299 |
} |
| 3300 |
|
| 3301 |
private boolean predictiveItemAnimationsEnabled() { |
| 3302 |
return (mItemAnimator != null && mLayout.supportsPredictiveItemAnimations()); |
| 3303 |
} |
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
private void processAdapterUpdatesAndSetAnimationFlags() { |
| 3312 |
if (mDataSetHasChangedAfterLayout) { |
| 3313 |
|
| 3314 |
|
| 3315 |
mAdapterHelper.reset(); |
| 3316 |
mLayout.onItemsChanged(this); |
| 3317 |
} |
| 3318 |
|
| 3319 |
|
| 3320 |
|
| 3321 |
if (predictiveItemAnimationsEnabled()) { |
| 3322 |
mAdapterHelper.preProcess(); |
| 3323 |
} else { |
| 3324 |
mAdapterHelper.consumeUpdatesInOnePass(); |
| 3325 |
} |
| 3326 |
boolean animationTypeSupported = mItemsAddedOrRemoved || mItemsChanged; |
| 3327 |
mState.mRunSimpleAnimations = mFirstLayoutComplete |
| 3328 |
&& mItemAnimator != null |
| 3329 |
&& (mDataSetHasChangedAfterLayout |
| 3330 |
|| animationTypeSupported |
| 3331 |
|| mLayout.mRequestedSimpleAnimations) |
| 3332 |
&& (!mDataSetHasChangedAfterLayout |
| 3333 |
|| mAdapter.hasStableIds()); |
| 3334 |
mState.mRunPredictiveAnimations = mState.mRunSimpleAnimations |
| 3335 |
&& animationTypeSupported |
| 3336 |
&& !mDataSetHasChangedAfterLayout |
| 3337 |
&& predictiveItemAnimationsEnabled(); |
| 3338 |
} |
| 3339 |
|
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
void dispatchLayout() { |
| 3366 |
if (mAdapter == null) { |
| 3367 |
Log.e(TAG, "No adapter attached; skipping layout"); |
| 3368 |
|
| 3369 |
return; |
| 3370 |
} |
| 3371 |
if (mLayout == null) { |
| 3372 |
Log.e(TAG, "No layout manager attached; skipping layout"); |
| 3373 |
|
| 3374 |
return; |
| 3375 |
} |
| 3376 |
mState.mIsMeasuring = false; |
| 3377 |
if (mState.mLayoutStep == State.STEP_START) { |
| 3378 |
dispatchLayoutStep1(); |
| 3379 |
mLayout.setExactMeasureSpecsFrom(this); |
| 3380 |
dispatchLayoutStep2(); |
| 3381 |
} else if (mAdapterHelper.hasUpdates() || mLayout.getWidth() != getWidth() |
| 3382 |
|| mLayout.getHeight() != getHeight()) { |
| 3383 |
|
| 3384 |
|
| 3385 |
mLayout.setExactMeasureSpecsFrom(this); |
| 3386 |
dispatchLayoutStep2(); |
| 3387 |
} else { |
| 3388 |
|
| 3389 |
mLayout.setExactMeasureSpecsFrom(this); |
| 3390 |
} |
| 3391 |
dispatchLayoutStep3(); |
| 3392 |
} |
| 3393 |
|
| 3394 |
private void saveFocusInfo() { |
| 3395 |
View child = null; |
| 3396 |
if (mPreserveFocusAfterLayout && hasFocus() && mAdapter != null) { |
| 3397 |
child = getFocusedChild(); |
| 3398 |
} |
| 3399 |
|
| 3400 |
final ViewHolder focusedVh = child == null ? null : findContainingViewHolder(child); |
| 3401 |
if (focusedVh == null) { |
| 3402 |
resetFocusInfo(); |
| 3403 |
} else { |
| 3404 |
mState.mFocusedItemId = mAdapter.hasStableIds() ? focusedVh.getItemId() : NO_ID; |
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
mState.mFocusedItemPosition = mDataSetHasChangedAfterLayout ? NO_POSITION |
| 3409 |
: (focusedVh.isRemoved() ? focusedVh.mOldPosition |
| 3410 |
: focusedVh.getAdapterPosition()); |
| 3411 |
mState.mFocusedSubChildId = getDeepestFocusedViewWithId(focusedVh.itemView); |
| 3412 |
} |
| 3413 |
} |
| 3414 |
|
| 3415 |
private void resetFocusInfo() { |
| 3416 |
mState.mFocusedItemId = NO_ID; |
| 3417 |
mState.mFocusedItemPosition = NO_POSITION; |
| 3418 |
mState.mFocusedSubChildId = View.NO_ID; |
| 3419 |
} |
| 3420 |
|
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
@Nullable |
| 3430 |
private View findNextViewToFocus() { |
| 3431 |
int startFocusSearchIndex = mState.mFocusedItemPosition != -1 ? mState.mFocusedItemPosition |
| 3432 |
: 0; |
| 3433 |
ViewHolder nextFocus; |
| 3434 |
final int itemCount = mState.getItemCount(); |
| 3435 |
for (int i = startFocusSearchIndex; i < itemCount; i++) { |
| 3436 |
nextFocus = findViewHolderForAdapterPosition(i); |
| 3437 |
if (nextFocus == null) { |
| 3438 |
break; |
| 3439 |
} |
| 3440 |
if (nextFocus.itemView.hasFocusable()) { |
| 3441 |
return nextFocus.itemView; |
| 3442 |
} |
| 3443 |
} |
| 3444 |
final int limit = Math.min(itemCount, startFocusSearchIndex); |
| 3445 |
for (int i = limit - 1; i >= 0; i--) { |
| 3446 |
nextFocus = findViewHolderForAdapterPosition(i); |
| 3447 |
if (nextFocus == null) { |
| 3448 |
return null; |
| 3449 |
} |
| 3450 |
if (nextFocus.itemView.hasFocusable()) { |
| 3451 |
return nextFocus.itemView; |
| 3452 |
} |
| 3453 |
} |
| 3454 |
return null; |
| 3455 |
} |
| 3456 |
|
| 3457 |
private void recoverFocusFromState() { |
| 3458 |
if (!mPreserveFocusAfterLayout || mAdapter == null || !hasFocus() |
| 3459 |
|| getDescendantFocusability() == FOCUS_BLOCK_DESCENDANTS |
| 3460 |
|| (getDescendantFocusability() == FOCUS_BEFORE_DESCENDANTS && isFocused())) { |
| 3461 |
|
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
return; |
| 3466 |
} |
| 3467 |
|
| 3468 |
if (!isFocused()) { |
| 3469 |
final View focusedChild = getFocusedChild(); |
| 3470 |
if (IGNORE_DETACHED_FOCUSED_CHILD |
| 3471 |
&& (focusedChild.getParent() == null || !focusedChild.hasFocus())) { |
| 3472 |
|
| 3473 |
|
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
|
| 3483 |
if (mChildHelper.getChildCount() == 0) { |
| 3484 |
|
| 3485 |
|
| 3486 |
requestFocus(); |
| 3487 |
return; |
| 3488 |
} |
| 3489 |
} else if (!mChildHelper.isHidden(focusedChild)) { |
| 3490 |
|
| 3491 |
|
| 3492 |
return; |
| 3493 |
} |
| 3494 |
} |
| 3495 |
ViewHolder focusTarget = null; |
| 3496 |
|
| 3497 |
|
| 3498 |
|
| 3499 |
if (mState.mFocusedItemId != NO_ID && mAdapter.hasStableIds()) { |
| 3500 |
focusTarget = findViewHolderForItemId(mState.mFocusedItemId); |
| 3501 |
} |
| 3502 |
View viewToFocus = null; |
| 3503 |
if (focusTarget == null || mChildHelper.isHidden(focusTarget.itemView) |
| 3504 |
|| !focusTarget.itemView.hasFocusable()) { |
| 3505 |
if (mChildHelper.getChildCount() > 0) { |
| 3506 |
|
| 3507 |
|
| 3508 |
|
| 3509 |
|
| 3510 |
|
| 3511 |
|
| 3512 |
viewToFocus = findNextViewToFocus(); |
| 3513 |
} |
| 3514 |
} else { |
| 3515 |
|
| 3516 |
|
| 3517 |
viewToFocus = focusTarget.itemView; |
| 3518 |
} |
| 3519 |
|
| 3520 |
if (viewToFocus != null) { |
| 3521 |
if (mState.mFocusedSubChildId != NO_ID) { |
| 3522 |
View child = viewToFocus.findViewById(mState.mFocusedSubChildId); |
| 3523 |
if (child != null && child.isFocusable()) { |
| 3524 |
viewToFocus = child; |
| 3525 |
} |
| 3526 |
} |
| 3527 |
viewToFocus.requestFocus(); |
| 3528 |
} |
| 3529 |
} |
| 3530 |
|
| 3531 |
private int getDeepestFocusedViewWithId(View view) { |
| 3532 |
int lastKnownId = view.getId(); |
| 3533 |
while (!view.isFocused() && view instanceof ViewGroup && view.hasFocus()) { |
| 3534 |
view = ((ViewGroup) view).getFocusedChild(); |
| 3535 |
final int id = view.getId(); |
| 3536 |
if (id != View.NO_ID) { |
| 3537 |
lastKnownId = view.getId(); |
| 3538 |
} |
| 3539 |
} |
| 3540 |
return lastKnownId; |
| 3541 |
} |
| 3542 |
|
| 3543 |
|
| 3544 |
|
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
|
| 3550 |
private void dispatchLayoutStep1() { |
| 3551 |
mState.assertLayoutStep(State.STEP_START); |
| 3552 |
mState.mIsMeasuring = false; |
| 3553 |
eatRequestLayout(); |
| 3554 |
mViewInfoStore.clear(); |
| 3555 |
onEnterLayoutOrScroll(); |
| 3556 |
processAdapterUpdatesAndSetAnimationFlags(); |
| 3557 |
saveFocusInfo(); |
| 3558 |
mState.mTrackOldChangeHolders = mState.mRunSimpleAnimations && mItemsChanged; |
| 3559 |
mItemsAddedOrRemoved = mItemsChanged = false; |
| 3560 |
mState.mInPreLayout = mState.mRunPredictiveAnimations; |
| 3561 |
mState.mItemCount = mAdapter.getItemCount(); |
| 3562 |
findMinMaxChildLayoutPositions(mMinMaxLayoutPositions); |
| 3563 |
|
| 3564 |
if (mState.mRunSimpleAnimations) { |
| 3565 |
|
| 3566 |
int count = mChildHelper.getChildCount(); |
| 3567 |
for (int i = 0; i < count; ++i) { |
| 3568 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getChildAt(i)); |
| 3569 |
if (holder.shouldIgnore() || (holder.isInvalid() && !mAdapter.hasStableIds())) { |
| 3570 |
continue; |
| 3571 |
} |
| 3572 |
final ItemHolderInfo animationInfo = mItemAnimator |
| 3573 |
.recordPreLayoutInformation(mState, holder, |
| 3574 |
ItemAnimator.buildAdapterChangeFlagsForAnimations(holder), |
| 3575 |
holder.getUnmodifiedPayloads()); |
| 3576 |
mViewInfoStore.addToPreLayout(holder, animationInfo); |
| 3577 |
if (mState.mTrackOldChangeHolders && holder.isUpdated() && !holder.isRemoved() |
| 3578 |
&& !holder.shouldIgnore() && !holder.isInvalid()) { |
| 3579 |
long key = getChangedHolderKey(holder); |
| 3580 |
|
| 3581 |
|
| 3582 |
|
| 3583 |
|
| 3584 |
|
| 3585 |
|
| 3586 |
|
| 3587 |
mViewInfoStore.addToOldChangeHolders(key, holder); |
| 3588 |
} |
| 3589 |
} |
| 3590 |
} |
| 3591 |
if (mState.mRunPredictiveAnimations) { |
| 3592 |
|
| 3593 |
|
| 3594 |
|
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
saveOldPositions(); |
| 3599 |
final boolean didStructureChange = mState.mStructureChanged; |
| 3600 |
mState.mStructureChanged = false; |
| 3601 |
|
| 3602 |
mLayout.onLayoutChildren(mRecycler, mState); |
| 3603 |
mState.mStructureChanged = didStructureChange; |
| 3604 |
|
| 3605 |
for (int i = 0; i < mChildHelper.getChildCount(); ++i) { |
| 3606 |
final View child = mChildHelper.getChildAt(i); |
| 3607 |
final ViewHolder viewHolder = getChildViewHolderInt(child); |
| 3608 |
if (viewHolder.shouldIgnore()) { |
| 3609 |
continue; |
| 3610 |
} |
| 3611 |
if (!mViewInfoStore.isInPreLayout(viewHolder)) { |
| 3612 |
int flags = ItemAnimator.buildAdapterChangeFlagsForAnimations(viewHolder); |
| 3613 |
boolean wasHidden = viewHolder |
| 3614 |
.hasAnyOfTheFlags(ViewHolder.FLAG_BOUNCED_FROM_HIDDEN_LIST); |
| 3615 |
if (!wasHidden) { |
| 3616 |
flags |= ItemAnimator.FLAG_APPEARED_IN_PRE_LAYOUT; |
| 3617 |
} |
| 3618 |
final ItemHolderInfo animationInfo = mItemAnimator.recordPreLayoutInformation( |
| 3619 |
mState, viewHolder, flags, viewHolder.getUnmodifiedPayloads()); |
| 3620 |
if (wasHidden) { |
| 3621 |
recordAnimationInfoIfBouncedHiddenView(viewHolder, animationInfo); |
| 3622 |
} else { |
| 3623 |
mViewInfoStore.addToAppearedInPreLayoutHolders(viewHolder, animationInfo); |
| 3624 |
} |
| 3625 |
} |
| 3626 |
} |
| 3627 |
|
| 3628 |
clearOldPositions(); |
| 3629 |
} else { |
| 3630 |
clearOldPositions(); |
| 3631 |
} |
| 3632 |
onExitLayoutOrScroll(); |
| 3633 |
resumeRequestLayout(false); |
| 3634 |
mState.mLayoutStep = State.STEP_LAYOUT; |
| 3635 |
} |
| 3636 |
|
| 3637 |
|
| 3638 |
|
| 3639 |
|
| 3640 |
|
| 3641 |
private void dispatchLayoutStep2() { |
| 3642 |
eatRequestLayout(); |
| 3643 |
onEnterLayoutOrScroll(); |
| 3644 |
mState.assertLayoutStep(State.STEP_LAYOUT | State.STEP_ANIMATIONS); |
| 3645 |
mAdapterHelper.consumeUpdatesInOnePass(); |
| 3646 |
mState.mItemCount = mAdapter.getItemCount(); |
| 3647 |
mState.mDeletedInvisibleItemCountSincePreviousLayout = 0; |
| 3648 |
|
| 3649 |
|
| 3650 |
mState.mInPreLayout = false; |
| 3651 |
mLayout.onLayoutChildren(mRecycler, mState); |
| 3652 |
|
| 3653 |
mState.mStructureChanged = false; |
| 3654 |
mPendingSavedState = null; |
| 3655 |
|
| 3656 |
|
| 3657 |
mState.mRunSimpleAnimations = mState.mRunSimpleAnimations && mItemAnimator != null; |
| 3658 |
mState.mLayoutStep = State.STEP_ANIMATIONS; |
| 3659 |
onExitLayoutOrScroll(); |
| 3660 |
resumeRequestLayout(false); |
| 3661 |
} |
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
|
| 3666 |
|
| 3667 |
private void dispatchLayoutStep3() { |
| 3668 |
mState.assertLayoutStep(State.STEP_ANIMATIONS); |
| 3669 |
eatRequestLayout(); |
| 3670 |
onEnterLayoutOrScroll(); |
| 3671 |
mState.mLayoutStep = State.STEP_START; |
| 3672 |
if (mState.mRunSimpleAnimations) { |
| 3673 |
|
| 3674 |
|
| 3675 |
|
| 3676 |
for (int i = mChildHelper.getChildCount() - 1; i >= 0; i--) { |
| 3677 |
ViewHolder holder = getChildViewHolderInt(mChildHelper.getChildAt(i)); |
| 3678 |
if (holder.shouldIgnore()) { |
| 3679 |
continue; |
| 3680 |
} |
| 3681 |
long key = getChangedHolderKey(holder); |
| 3682 |
final ItemHolderInfo animationInfo = mItemAnimator |
| 3683 |
.recordPostLayoutInformation(mState, holder); |
| 3684 |
ViewHolder oldChangeViewHolder = mViewInfoStore.getFromOldChangeHolders(key); |
| 3685 |
if (oldChangeViewHolder != null && !oldChangeViewHolder.shouldIgnore()) { |
| 3686 |
|
| 3687 |
|
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
|
| 3695 |
|
| 3696 |
final boolean oldDisappearing = mViewInfoStore.isDisappearing( |
| 3697 |
oldChangeViewHolder); |
| 3698 |
final boolean newDisappearing = mViewInfoStore.isDisappearing(holder); |
| 3699 |
if (oldDisappearing && oldChangeViewHolder == holder) { |
| 3700 |
|
| 3701 |
mViewInfoStore.addToPostLayout(holder, animationInfo); |
| 3702 |
} else { |
| 3703 |
final ItemHolderInfo preInfo = mViewInfoStore.popFromPreLayout( |
| 3704 |
oldChangeViewHolder); |
| 3705 |
|
| 3706 |
mViewInfoStore.addToPostLayout(holder, animationInfo); |
| 3707 |
ItemHolderInfo postInfo = mViewInfoStore.popFromPostLayout(holder); |
| 3708 |
if (preInfo == null) { |
| 3709 |
handleMissingPreInfoForChangeError(key, holder, oldChangeViewHolder); |
| 3710 |
} else { |
| 3711 |
animateChange(oldChangeViewHolder, holder, preInfo, postInfo, |
| 3712 |
oldDisappearing, newDisappearing); |
| 3713 |
} |
| 3714 |
} |
| 3715 |
} else { |
| 3716 |
mViewInfoStore.addToPostLayout(holder, animationInfo); |
| 3717 |
} |
| 3718 |
} |
| 3719 |
|
| 3720 |
|
| 3721 |
mViewInfoStore.process(mViewInfoProcessCallback); |
| 3722 |
} |
| 3723 |
|
| 3724 |
mLayout.removeAndRecycleScrapInt(mRecycler); |
| 3725 |
mState.mPreviousLayoutItemCount = mState.mItemCount; |
| 3726 |
mDataSetHasChangedAfterLayout = false; |
| 3727 |
mState.mRunSimpleAnimations = false; |
| 3728 |
|
| 3729 |
mState.mRunPredictiveAnimations = false; |
| 3730 |
mLayout.mRequestedSimpleAnimations = false; |
| 3731 |
if (mRecycler.mChangedScrap != null) { |
| 3732 |
mRecycler.mChangedScrap.clear(); |
| 3733 |
} |
| 3734 |
if (mLayout.mPrefetchMaxObservedInInitialPrefetch) { |
| 3735 |
|
| 3736 |
|
| 3737 |
mLayout.mPrefetchMaxCountObserved = 0; |
| 3738 |
mLayout.mPrefetchMaxObservedInInitialPrefetch = false; |
| 3739 |
mRecycler.updateViewCacheSize(); |
| 3740 |
} |
| 3741 |
|
| 3742 |
mLayout.onLayoutCompleted(mState); |
| 3743 |
onExitLayoutOrScroll(); |
| 3744 |
resumeRequestLayout(false); |
| 3745 |
mViewInfoStore.clear(); |
| 3746 |
if (didChildRangeChange(mMinMaxLayoutPositions[0], mMinMaxLayoutPositions[1])) { |
| 3747 |
dispatchOnScrolled(0, 0); |
| 3748 |
} |
| 3749 |
recoverFocusFromState(); |
| 3750 |
resetFocusInfo(); |
| 3751 |
} |
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
|
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
|
| 3764 |
|
| 3765 |
|
| 3766 |
|
| 3767 |
|
| 3768 |
private void handleMissingPreInfoForChangeError(long key, |
| 3769 |
ViewHolder holder, ViewHolder oldChangeViewHolder) { |
| 3770 |
|
| 3771 |
final int childCount = mChildHelper.getChildCount(); |
| 3772 |
for (int i = 0; i < childCount; i++) { |
| 3773 |
View view = mChildHelper.getChildAt(i); |
| 3774 |
ViewHolder other = getChildViewHolderInt(view); |
| 3775 |
if (other == holder) { |
| 3776 |
continue; |
| 3777 |
} |
| 3778 |
final long otherKey = getChangedHolderKey(other); |
| 3779 |
if (otherKey == key) { |
| 3780 |
if (mAdapter != null && mAdapter.hasStableIds()) { |
| 3781 |
throw new IllegalStateException("Two different ViewHolders have the same stable" |
| 3782 |
+ " ID. Stable IDs in your adapter MUST BE unique and SHOULD NOT" |
| 3783 |
+ " change.\n ViewHolder 1:" + other + " \n View Holder 2:" + holder); |
| 3784 |
} else { |
| 3785 |
throw new IllegalStateException("Two different ViewHolders have the same change" |
| 3786 |
+ " ID. This might happen due to inconsistent Adapter update events or" |
| 3787 |
+ " if the LayoutManager lays out the same View multiple times." |
| 3788 |
+ "\n ViewHolder 1:" + other + " \n View Holder 2:" + holder); |
| 3789 |
} |
| 3790 |
} |
| 3791 |
} |
| 3792 |
|
| 3793 |
Log.e(TAG, "Problem while matching changed view holders with the new" |
| 3794 |
+ "ones. The pre-layout information for the change holder " + oldChangeViewHolder |
| 3795 |
+ " cannot be found but it is necessary for " + holder); |
| 3796 |
} |
| 3797 |
|
| 3798 |
|
| 3799 |
|
| 3800 |
|
| 3801 |
|
| 3802 |
void recordAnimationInfoIfBouncedHiddenView(ViewHolder viewHolder, |
| 3803 |
ItemHolderInfo animationInfo) { |
| 3804 |
|
| 3805 |
viewHolder.setFlags(0, ViewHolder.FLAG_BOUNCED_FROM_HIDDEN_LIST); |
| 3806 |
if (mState.mTrackOldChangeHolders && viewHolder.isUpdated() |
| 3807 |
&& !viewHolder.isRemoved() && !viewHolder.shouldIgnore()) { |
| 3808 |
long key = getChangedHolderKey(viewHolder); |
| 3809 |
mViewInfoStore.addToOldChangeHolders(key, viewHolder); |
| 3810 |
} |
| 3811 |
mViewInfoStore.addToPreLayout(viewHolder, animationInfo); |
| 3812 |
} |
| 3813 |
|
| 3814 |
private void findMinMaxChildLayoutPositions(int[] into) { |
| 3815 |
final int count = mChildHelper.getChildCount(); |
| 3816 |
if (count == 0) { |
| 3817 |
into[0] = NO_POSITION; |
| 3818 |
into[1] = NO_POSITION; |
| 3819 |
return; |
| 3820 |
} |
| 3821 |
int minPositionPreLayout = Integer.MAX_VALUE; |
| 3822 |
int maxPositionPreLayout = Integer.MIN_VALUE; |
| 3823 |
for (int i = 0; i < count; ++i) { |
| 3824 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getChildAt(i)); |
| 3825 |
if (holder.shouldIgnore()) { |
| 3826 |
continue; |
| 3827 |
} |
| 3828 |
final int pos = holder.getLayoutPosition(); |
| 3829 |
if (pos < minPositionPreLayout) { |
| 3830 |
minPositionPreLayout = pos; |
| 3831 |
} |
| 3832 |
if (pos > maxPositionPreLayout) { |
| 3833 |
maxPositionPreLayout = pos; |
| 3834 |
} |
| 3835 |
} |
| 3836 |
into[0] = minPositionPreLayout; |
| 3837 |
into[1] = maxPositionPreLayout; |
| 3838 |
} |
| 3839 |
|
| 3840 |
private boolean didChildRangeChange(int minPositionPreLayout, int maxPositionPreLayout) { |
| 3841 |
findMinMaxChildLayoutPositions(mMinMaxLayoutPositions); |
| 3842 |
return mMinMaxLayoutPositions[0] != minPositionPreLayout |
| 3843 |
|| mMinMaxLayoutPositions[1] != maxPositionPreLayout; |
| 3844 |
} |
| 3845 |
|
| 3846 |
@Override |
| 3847 |
protected void removeDetachedView(View child, boolean animate) { |
| 3848 |
ViewHolder vh = getChildViewHolderInt(child); |
| 3849 |
if (vh != null) { |
| 3850 |
if (vh.isTmpDetached()) { |
| 3851 |
vh.clearTmpDetachFlag(); |
| 3852 |
} else if (!vh.shouldIgnore()) { |
| 3853 |
throw new IllegalArgumentException("Called removeDetachedView with a view which" |
| 3854 |
+ " is not flagged as tmp detached." + vh); |
| 3855 |
} |
| 3856 |
} |
| 3857 |
dispatchChildDetached(child); |
| 3858 |
super.removeDetachedView(child, animate); |
| 3859 |
} |
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
long getChangedHolderKey(ViewHolder holder) { |
| 3866 |
return mAdapter.hasStableIds() ? holder.getItemId() : holder.mPosition; |
| 3867 |
} |
| 3868 |
|
| 3869 |
void animateAppearance(@NonNull ViewHolder itemHolder, |
| 3870 |
@Nullable ItemHolderInfo preLayoutInfo, @NonNull ItemHolderInfo postLayoutInfo) { |
| 3871 |
itemHolder.setIsRecyclable(false); |
| 3872 |
if (mItemAnimator.animateAppearance(itemHolder, preLayoutInfo, postLayoutInfo)) { |
| 3873 |
postAnimationRunner(); |
| 3874 |
} |
| 3875 |
} |
| 3876 |
|
| 3877 |
void animateDisappearance(@NonNull ViewHolder holder, |
| 3878 |
@NonNull ItemHolderInfo preLayoutInfo, @Nullable ItemHolderInfo postLayoutInfo) { |
| 3879 |
addAnimatingView(holder); |
| 3880 |
holder.setIsRecyclable(false); |
| 3881 |
if (mItemAnimator.animateDisappearance(holder, preLayoutInfo, postLayoutInfo)) { |
| 3882 |
postAnimationRunner(); |
| 3883 |
} |
| 3884 |
} |
| 3885 |
|
| 3886 |
private void animateChange(@NonNull ViewHolder oldHolder, @NonNull ViewHolder newHolder, |
| 3887 |
@NonNull ItemHolderInfo preInfo, @NonNull ItemHolderInfo postInfo, |
| 3888 |
boolean oldHolderDisappearing, boolean newHolderDisappearing) { |
| 3889 |
oldHolder.setIsRecyclable(false); |
| 3890 |
if (oldHolderDisappearing) { |
| 3891 |
addAnimatingView(oldHolder); |
| 3892 |
} |
| 3893 |
if (oldHolder != newHolder) { |
| 3894 |
if (newHolderDisappearing) { |
| 3895 |
addAnimatingView(newHolder); |
| 3896 |
} |
| 3897 |
oldHolder.mShadowedHolder = newHolder; |
| 3898 |
|
| 3899 |
addAnimatingView(oldHolder); |
| 3900 |
mRecycler.unscrapView(oldHolder); |
| 3901 |
newHolder.setIsRecyclable(false); |
| 3902 |
newHolder.mShadowingHolder = oldHolder; |
| 3903 |
} |
| 3904 |
if (mItemAnimator.animateChange(oldHolder, newHolder, preInfo, postInfo)) { |
| 3905 |
postAnimationRunner(); |
| 3906 |
} |
| 3907 |
} |
| 3908 |
|
| 3909 |
@Override |
| 3910 |
protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 3911 |
Trace.beginSection(TRACE_ON_LAYOUT_TAG); |
| 3912 |
dispatchLayout(); |
| 3913 |
Trace.endSection(); |
| 3914 |
mFirstLayoutComplete = true; |
| 3915 |
} |
| 3916 |
|
| 3917 |
@Override |
| 3918 |
public void requestLayout() { |
| 3919 |
if (mEatRequestLayout == 0 && !mLayoutFrozen) { |
| 3920 |
super.requestLayout(); |
| 3921 |
} else { |
| 3922 |
mLayoutRequestEaten = true; |
| 3923 |
} |
| 3924 |
} |
| 3925 |
|
| 3926 |
void markItemDecorInsetsDirty() { |
| 3927 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 3928 |
for (int i = 0; i < childCount; i++) { |
| 3929 |
final View child = mChildHelper.getUnfilteredChildAt(i); |
| 3930 |
((LayoutParams) child.getLayoutParams()).mInsetsDirty = true; |
| 3931 |
} |
| 3932 |
mRecycler.markItemDecorInsetsDirty(); |
| 3933 |
} |
| 3934 |
|
| 3935 |
@Override |
| 3936 |
public void draw(Canvas c) { |
| 3937 |
super.draw(c); |
| 3938 |
|
| 3939 |
final int count = mItemDecorations.size(); |
| 3940 |
for (int i = 0; i < count; i++) { |
| 3941 |
mItemDecorations.get(i).onDrawOver(c, this, mState); |
| 3942 |
} |
| 3943 |
|
| 3944 |
|
| 3945 |
boolean needsInvalidate = false; |
| 3946 |
if (mLeftGlow != null && !mLeftGlow.isFinished()) { |
| 3947 |
final int restore = c.save(); |
| 3948 |
final int padding = mClipToPadding ? getPaddingBottom() : 0; |
| 3949 |
c.rotate(270); |
| 3950 |
c.translate(-getHeight() + padding, 0); |
| 3951 |
needsInvalidate = mLeftGlow != null && mLeftGlow.draw(c); |
| 3952 |
c.restoreToCount(restore); |
| 3953 |
} |
| 3954 |
if (mTopGlow != null && !mTopGlow.isFinished()) { |
| 3955 |
final int restore = c.save(); |
| 3956 |
if (mClipToPadding) { |
| 3957 |
c.translate(getPaddingLeft(), getPaddingTop()); |
| 3958 |
} |
| 3959 |
needsInvalidate |= mTopGlow != null && mTopGlow.draw(c); |
| 3960 |
c.restoreToCount(restore); |
| 3961 |
} |
| 3962 |
if (mRightGlow != null && !mRightGlow.isFinished()) { |
| 3963 |
final int restore = c.save(); |
| 3964 |
final int width = getWidth(); |
| 3965 |
final int padding = mClipToPadding ? getPaddingTop() : 0; |
| 3966 |
c.rotate(90); |
| 3967 |
c.translate(-padding, -width); |
| 3968 |
needsInvalidate |= mRightGlow != null && mRightGlow.draw(c); |
| 3969 |
c.restoreToCount(restore); |
| 3970 |
} |
| 3971 |
if (mBottomGlow != null && !mBottomGlow.isFinished()) { |
| 3972 |
final int restore = c.save(); |
| 3973 |
c.rotate(180); |
| 3974 |
if (mClipToPadding) { |
| 3975 |
c.translate(-getWidth() + getPaddingRight(), -getHeight() + getPaddingBottom()); |
| 3976 |
} else { |
| 3977 |
c.translate(-getWidth(), -getHeight()); |
| 3978 |
} |
| 3979 |
needsInvalidate |= mBottomGlow != null && mBottomGlow.draw(c); |
| 3980 |
c.restoreToCount(restore); |
| 3981 |
} |
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
if (!needsInvalidate && mItemAnimator != null && mItemDecorations.size() > 0 |
| 3987 |
&& mItemAnimator.isRunning()) { |
| 3988 |
needsInvalidate = true; |
| 3989 |
} |
| 3990 |
|
| 3991 |
if (needsInvalidate) { |
| 3992 |
postInvalidateOnAnimation(); |
| 3993 |
} |
| 3994 |
} |
| 3995 |
|
| 3996 |
@Override |
| 3997 |
public void onDraw(Canvas c) { |
| 3998 |
super.onDraw(c); |
| 3999 |
|
| 4000 |
final int count = mItemDecorations.size(); |
| 4001 |
for (int i = 0; i < count; i++) { |
| 4002 |
mItemDecorations.get(i).onDraw(c, this, mState); |
| 4003 |
} |
| 4004 |
} |
| 4005 |
|
| 4006 |
@Override |
| 4007 |
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { |
| 4008 |
return p instanceof LayoutParams && mLayout.checkLayoutParams((LayoutParams) p); |
| 4009 |
} |
| 4010 |
|
| 4011 |
@Override |
| 4012 |
protected ViewGroup.LayoutParams generateDefaultLayoutParams() { |
| 4013 |
if (mLayout == null) { |
| 4014 |
throw new IllegalStateException("RecyclerView has no LayoutManager"); |
| 4015 |
} |
| 4016 |
return mLayout.generateDefaultLayoutParams(); |
| 4017 |
} |
| 4018 |
|
| 4019 |
@Override |
| 4020 |
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) { |
| 4021 |
if (mLayout == null) { |
| 4022 |
throw new IllegalStateException("RecyclerView has no LayoutManager"); |
| 4023 |
} |
| 4024 |
return mLayout.generateLayoutParams(getContext(), attrs); |
| 4025 |
} |
| 4026 |
|
| 4027 |
@Override |
| 4028 |
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) { |
| 4029 |
if (mLayout == null) { |
| 4030 |
throw new IllegalStateException("RecyclerView has no LayoutManager"); |
| 4031 |
} |
| 4032 |
return mLayout.generateLayoutParams(p); |
| 4033 |
} |
| 4034 |
|
| 4035 |
|
| 4036 |
|
| 4037 |
|
| 4038 |
|
| 4039 |
|
| 4040 |
|
| 4041 |
|
| 4042 |
|
| 4043 |
public boolean isAnimating() { |
| 4044 |
return mItemAnimator != null && mItemAnimator.isRunning(); |
| 4045 |
} |
| 4046 |
|
| 4047 |
void saveOldPositions() { |
| 4048 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4049 |
for (int i = 0; i < childCount; i++) { |
| 4050 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4051 |
if (DEBUG && holder.mPosition == -1 && !holder.isRemoved()) { |
| 4052 |
throw new IllegalStateException("view holder cannot have position -1 unless it" |
| 4053 |
+ " is removed"); |
| 4054 |
} |
| 4055 |
if (!holder.shouldIgnore()) { |
| 4056 |
holder.saveOldPosition(); |
| 4057 |
} |
| 4058 |
} |
| 4059 |
} |
| 4060 |
|
| 4061 |
void clearOldPositions() { |
| 4062 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4063 |
for (int i = 0; i < childCount; i++) { |
| 4064 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4065 |
if (!holder.shouldIgnore()) { |
| 4066 |
holder.clearOldPosition(); |
| 4067 |
} |
| 4068 |
} |
| 4069 |
mRecycler.clearOldPositions(); |
| 4070 |
} |
| 4071 |
|
| 4072 |
void offsetPositionRecordsForMove(int from, int to) { |
| 4073 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4074 |
final int start, end, inBetweenOffset; |
| 4075 |
if (from < to) { |
| 4076 |
start = from; |
| 4077 |
end = to; |
| 4078 |
inBetweenOffset = -1; |
| 4079 |
} else { |
| 4080 |
start = to; |
| 4081 |
end = from; |
| 4082 |
inBetweenOffset = 1; |
| 4083 |
} |
| 4084 |
|
| 4085 |
for (int i = 0; i < childCount; i++) { |
| 4086 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4087 |
if (holder == null || holder.mPosition < start || holder.mPosition > end) { |
| 4088 |
continue; |
| 4089 |
} |
| 4090 |
if (DEBUG) { |
| 4091 |
Log.d(TAG, "offsetPositionRecordsForMove attached child " + i + " holder " |
| 4092 |
+ holder); |
| 4093 |
} |
| 4094 |
if (holder.mPosition == from) { |
| 4095 |
holder.offsetPosition(to - from, false); |
| 4096 |
} else { |
| 4097 |
holder.offsetPosition(inBetweenOffset, false); |
| 4098 |
} |
| 4099 |
|
| 4100 |
mState.mStructureChanged = true; |
| 4101 |
} |
| 4102 |
mRecycler.offsetPositionRecordsForMove(from, to); |
| 4103 |
requestLayout(); |
| 4104 |
} |
| 4105 |
|
| 4106 |
void offsetPositionRecordsForInsert(int positionStart, int itemCount) { |
| 4107 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4108 |
for (int i = 0; i < childCount; i++) { |
| 4109 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4110 |
if (holder != null && !holder.shouldIgnore() && holder.mPosition >= positionStart) { |
| 4111 |
if (DEBUG) { |
| 4112 |
Log.d(TAG, "offsetPositionRecordsForInsert attached child " + i + " holder " |
| 4113 |
+ holder + " now at position " + (holder.mPosition + itemCount)); |
| 4114 |
} |
| 4115 |
holder.offsetPosition(itemCount, false); |
| 4116 |
mState.mStructureChanged = true; |
| 4117 |
} |
| 4118 |
} |
| 4119 |
mRecycler.offsetPositionRecordsForInsert(positionStart, itemCount); |
| 4120 |
requestLayout(); |
| 4121 |
} |
| 4122 |
|
| 4123 |
void offsetPositionRecordsForRemove(int positionStart, int itemCount, |
| 4124 |
boolean applyToPreLayout) { |
| 4125 |
final int positionEnd = positionStart + itemCount; |
| 4126 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4127 |
for (int i = 0; i < childCount; i++) { |
| 4128 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4129 |
if (holder != null && !holder.shouldIgnore()) { |
| 4130 |
if (holder.mPosition >= positionEnd) { |
| 4131 |
if (DEBUG) { |
| 4132 |
Log.d(TAG, "offsetPositionRecordsForRemove attached child " + i |
| 4133 |
+ " holder " + holder + " now at position " |
| 4134 |
+ (holder.mPosition - itemCount)); |
| 4135 |
} |
| 4136 |
holder.offsetPosition(-itemCount, applyToPreLayout); |
| 4137 |
mState.mStructureChanged = true; |
| 4138 |
} else if (holder.mPosition >= positionStart) { |
| 4139 |
if (DEBUG) { |
| 4140 |
Log.d(TAG, "offsetPositionRecordsForRemove attached child " + i |
| 4141 |
+ " holder " + holder + " now REMOVED"); |
| 4142 |
} |
| 4143 |
holder.flagRemovedAndOffsetPosition(positionStart - 1, -itemCount, |
| 4144 |
applyToPreLayout); |
| 4145 |
mState.mStructureChanged = true; |
| 4146 |
} |
| 4147 |
} |
| 4148 |
} |
| 4149 |
mRecycler.offsetPositionRecordsForRemove(positionStart, itemCount, applyToPreLayout); |
| 4150 |
requestLayout(); |
| 4151 |
} |
| 4152 |
|
| 4153 |
|
| 4154 |
|
| 4155 |
|
| 4156 |
|
| 4157 |
|
| 4158 |
|
| 4159 |
void viewRangeUpdate(int positionStart, int itemCount, Object payload) { |
| 4160 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4161 |
final int positionEnd = positionStart + itemCount; |
| 4162 |
|
| 4163 |
for (int i = 0; i < childCount; i++) { |
| 4164 |
final View child = mChildHelper.getUnfilteredChildAt(i); |
| 4165 |
final ViewHolder holder = getChildViewHolderInt(child); |
| 4166 |
if (holder == null || holder.shouldIgnore()) { |
| 4167 |
continue; |
| 4168 |
} |
| 4169 |
if (holder.mPosition >= positionStart && holder.mPosition < positionEnd) { |
| 4170 |
|
| 4171 |
|
| 4172 |
holder.addFlags(ViewHolder.FLAG_UPDATE); |
| 4173 |
holder.addChangePayload(payload); |
| 4174 |
|
| 4175 |
((LayoutParams) child.getLayoutParams()).mInsetsDirty = true; |
| 4176 |
} |
| 4177 |
} |
| 4178 |
mRecycler.viewRangeUpdate(positionStart, itemCount); |
| 4179 |
} |
| 4180 |
|
| 4181 |
boolean canReuseUpdatedViewHolder(ViewHolder viewHolder) { |
| 4182 |
return mItemAnimator == null || mItemAnimator.canReuseUpdatedViewHolder(viewHolder, |
| 4183 |
viewHolder.getUnmodifiedPayloads()); |
| 4184 |
} |
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
|
| 4195 |
|
| 4196 |
|
| 4197 |
|
| 4198 |
|
| 4199 |
void setDataSetChangedAfterLayout() { |
| 4200 |
if (mDataSetHasChangedAfterLayout) { |
| 4201 |
return; |
| 4202 |
} |
| 4203 |
mDataSetHasChangedAfterLayout = true; |
| 4204 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4205 |
for (int i = 0; i < childCount; i++) { |
| 4206 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4207 |
if (holder != null && !holder.shouldIgnore()) { |
| 4208 |
holder.addFlags(ViewHolder.FLAG_ADAPTER_POSITION_UNKNOWN); |
| 4209 |
} |
| 4210 |
} |
| 4211 |
mRecycler.setAdapterPositionsAsUnknown(); |
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
markKnownViewsInvalid(); |
| 4216 |
} |
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
void markKnownViewsInvalid() { |
| 4223 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4224 |
for (int i = 0; i < childCount; i++) { |
| 4225 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4226 |
if (holder != null && !holder.shouldIgnore()) { |
| 4227 |
holder.addFlags(ViewHolder.FLAG_UPDATE | ViewHolder.FLAG_INVALID); |
| 4228 |
} |
| 4229 |
} |
| 4230 |
markItemDecorInsetsDirty(); |
| 4231 |
mRecycler.markKnownViewsInvalid(); |
| 4232 |
} |
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
|
| 4237 |
|
| 4238 |
public void invalidateItemDecorations() { |
| 4239 |
if (mItemDecorations.size() == 0) { |
| 4240 |
return; |
| 4241 |
} |
| 4242 |
if (mLayout != null) { |
| 4243 |
mLayout.assertNotInLayoutOrScroll("Cannot invalidate item decorations during a scroll" |
| 4244 |
+ " or layout"); |
| 4245 |
} |
| 4246 |
markItemDecorInsetsDirty(); |
| 4247 |
requestLayout(); |
| 4248 |
} |
| 4249 |
|
| 4250 |
|
| 4251 |
|
| 4252 |
|
| 4253 |
|
| 4254 |
|
| 4255 |
|
| 4256 |
|
| 4257 |
|
| 4258 |
|
| 4259 |
|
| 4260 |
|
| 4261 |
public boolean getPreserveFocusAfterLayout() { |
| 4262 |
return mPreserveFocusAfterLayout; |
| 4263 |
} |
| 4264 |
|
| 4265 |
|
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
|
| 4272 |
|
| 4273 |
|
| 4274 |
|
| 4275 |
|
| 4276 |
|
| 4277 |
|
| 4278 |
|
| 4279 |
public void setPreserveFocusAfterLayout(boolean preserveFocusAfterLayout) { |
| 4280 |
mPreserveFocusAfterLayout = preserveFocusAfterLayout; |
| 4281 |
} |
| 4282 |
|
| 4283 |
|
| 4284 |
|
| 4285 |
|
| 4286 |
|
| 4287 |
|
| 4288 |
|
| 4289 |
public ViewHolder getChildViewHolder(View child) { |
| 4290 |
final ViewParent parent = child.getParent(); |
| 4291 |
if (parent != null && parent != this) { |
| 4292 |
throw new IllegalArgumentException("View " + child + " is not a direct child of " |
| 4293 |
+ this); |
| 4294 |
} |
| 4295 |
return getChildViewHolderInt(child); |
| 4296 |
} |
| 4297 |
|
| 4298 |
|
| 4299 |
|
| 4300 |
|
| 4301 |
|
| 4302 |
|
| 4303 |
|
| 4304 |
|
| 4305 |
|
| 4306 |
|
| 4307 |
|
| 4308 |
|
| 4309 |
|
| 4310 |
|
| 4311 |
@Nullable |
| 4312 |
public View findContainingItemView(View view) { |
| 4313 |
ViewParent parent = view.getParent(); |
| 4314 |
while (parent != null && parent != this && parent instanceof View) { |
| 4315 |
view = (View) parent; |
| 4316 |
parent = view.getParent(); |
| 4317 |
} |
| 4318 |
return parent == this ? view : null; |
| 4319 |
} |
| 4320 |
|
| 4321 |
|
| 4322 |
|
| 4323 |
|
| 4324 |
|
| 4325 |
|
| 4326 |
|
| 4327 |
|
| 4328 |
|
| 4329 |
@Nullable |
| 4330 |
public ViewHolder findContainingViewHolder(View view) { |
| 4331 |
View itemView = findContainingItemView(view); |
| 4332 |
return itemView == null ? null : getChildViewHolder(itemView); |
| 4333 |
} |
| 4334 |
|
| 4335 |
|
| 4336 |
static ViewHolder getChildViewHolderInt(View child) { |
| 4337 |
if (child == null) { |
| 4338 |
return null; |
| 4339 |
} |
| 4340 |
return ((LayoutParams) child.getLayoutParams()).mViewHolder; |
| 4341 |
} |
| 4342 |
|
| 4343 |
|
| 4344 |
|
| 4345 |
|
| 4346 |
|
| 4347 |
@Deprecated |
| 4348 |
public int getChildPosition(View child) { |
| 4349 |
return getChildAdapterPosition(child); |
| 4350 |
} |
| 4351 |
|
| 4352 |
|
| 4353 |
|
| 4354 |
|
| 4355 |
|
| 4356 |
|
| 4357 |
|
| 4358 |
public int getChildAdapterPosition(View child) { |
| 4359 |
final ViewHolder holder = getChildViewHolderInt(child); |
| 4360 |
return holder != null ? holder.getAdapterPosition() : NO_POSITION; |
| 4361 |
} |
| 4362 |
|
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
|
| 4371 |
|
| 4372 |
|
| 4373 |
public int getChildLayoutPosition(View child) { |
| 4374 |
final ViewHolder holder = getChildViewHolderInt(child); |
| 4375 |
return holder != null ? holder.getLayoutPosition() : NO_POSITION; |
| 4376 |
} |
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
|
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
public long getChildItemId(View child) { |
| 4385 |
if (mAdapter == null || !mAdapter.hasStableIds()) { |
| 4386 |
return NO_ID; |
| 4387 |
} |
| 4388 |
final ViewHolder holder = getChildViewHolderInt(child); |
| 4389 |
return holder != null ? holder.getItemId() : NO_ID; |
| 4390 |
} |
| 4391 |
|
| 4392 |
|
| 4393 |
|
| 4394 |
|
| 4395 |
|
| 4396 |
@Deprecated |
| 4397 |
public ViewHolder findViewHolderForPosition(int position) { |
| 4398 |
return findViewHolderForPosition(position, false); |
| 4399 |
} |
| 4400 |
|
| 4401 |
|
| 4402 |
|
| 4403 |
|
| 4404 |
|
| 4405 |
|
| 4406 |
|
| 4407 |
|
| 4408 |
|
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
|
| 4415 |
|
| 4416 |
|
| 4417 |
|
| 4418 |
|
| 4419 |
|
| 4420 |
public ViewHolder findViewHolderForLayoutPosition(int position) { |
| 4421 |
return findViewHolderForPosition(position, false); |
| 4422 |
} |
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
|
| 4427 |
|
| 4428 |
|
| 4429 |
|
| 4430 |
|
| 4431 |
|
| 4432 |
|
| 4433 |
|
| 4434 |
|
| 4435 |
|
| 4436 |
|
| 4437 |
|
| 4438 |
|
| 4439 |
|
| 4440 |
|
| 4441 |
public ViewHolder findViewHolderForAdapterPosition(int position) { |
| 4442 |
if (mDataSetHasChangedAfterLayout) { |
| 4443 |
return null; |
| 4444 |
} |
| 4445 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4446 |
|
| 4447 |
ViewHolder hidden = null; |
| 4448 |
for (int i = 0; i < childCount; i++) { |
| 4449 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4450 |
if (holder != null && !holder.isRemoved() |
| 4451 |
&& getAdapterPositionFor(holder) == position) { |
| 4452 |
if (mChildHelper.isHidden(holder.itemView)) { |
| 4453 |
hidden = holder; |
| 4454 |
} else { |
| 4455 |
return holder; |
| 4456 |
} |
| 4457 |
} |
| 4458 |
} |
| 4459 |
return hidden; |
| 4460 |
} |
| 4461 |
|
| 4462 |
ViewHolder findViewHolderForPosition(int position, boolean checkNewPosition) { |
| 4463 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4464 |
ViewHolder hidden = null; |
| 4465 |
for (int i = 0; i < childCount; i++) { |
| 4466 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4467 |
if (holder != null && !holder.isRemoved()) { |
| 4468 |
if (checkNewPosition) { |
| 4469 |
if (holder.mPosition != position) { |
| 4470 |
continue; |
| 4471 |
} |
| 4472 |
} else if (holder.getLayoutPosition() != position) { |
| 4473 |
continue; |
| 4474 |
} |
| 4475 |
if (mChildHelper.isHidden(holder.itemView)) { |
| 4476 |
hidden = holder; |
| 4477 |
} else { |
| 4478 |
return holder; |
| 4479 |
} |
| 4480 |
} |
| 4481 |
} |
| 4482 |
|
| 4483 |
|
| 4484 |
|
| 4485 |
return hidden; |
| 4486 |
} |
| 4487 |
|
| 4488 |
|
| 4489 |
|
| 4490 |
|
| 4491 |
|
| 4492 |
|
| 4493 |
|
| 4494 |
|
| 4495 |
|
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
public ViewHolder findViewHolderForItemId(long id) { |
| 4503 |
if (mAdapter == null || !mAdapter.hasStableIds()) { |
| 4504 |
return null; |
| 4505 |
} |
| 4506 |
final int childCount = mChildHelper.getUnfilteredChildCount(); |
| 4507 |
ViewHolder hidden = null; |
| 4508 |
for (int i = 0; i < childCount; i++) { |
| 4509 |
final ViewHolder holder = getChildViewHolderInt(mChildHelper.getUnfilteredChildAt(i)); |
| 4510 |
if (holder != null && !holder.isRemoved() && holder.getItemId() == id) { |
| 4511 |
if (mChildHelper.isHidden(holder.itemView)) { |
| 4512 |
hidden = holder; |
| 4513 |
} else { |
| 4514 |
return holder; |
| 4515 |
} |
| 4516 |
} |
| 4517 |
} |
| 4518 |
return hidden; |
| 4519 |
} |
| 4520 |
|
| 4521 |
|
| 4522 |
|
| 4523 |
|
| 4524 |
|
| 4525 |
|
| 4526 |
|
| 4527 |
|
| 4528 |
public View findChildViewUnder(float x, float y) { |
| 4529 |
final int count = mChildHelper.getChildCount(); |
| 4530 |
for (int i = count - 1; i >= 0; i--) { |
| 4531 |
final View child = mChildHelper.getChildAt(i); |
| 4532 |
final float translationX = child.getTranslationX(); |
| 4533 |
final float translationY = child.getTranslationY(); |
| 4534 |
if (x >= child.getLeft() + translationX |
| 4535 |
&& x <= child.getRight() + translationX |
| 4536 |
&& y >= child.getTop() + translationY |
| 4537 |
&& y <= child.getBottom() + translationY) { |
| 4538 |
return child; |
| 4539 |
} |
| 4540 |
} |
| 4541 |
return null; |
| 4542 |
} |
| 4543 |
|
| 4544 |
@Override |
| 4545 |
public boolean drawChild(Canvas canvas, View child, long drawingTime) { |
| 4546 |
return super.drawChild(canvas, child, drawingTime); |
| 4547 |
} |
| 4548 |
|
| 4549 |
|
| 4550 |
|
| 4551 |
|
| 4552 |
|
| 4553 |
|
| 4554 |
|
| 4555 |
public void offsetChildrenVertical(int dy) { |
| 4556 |
final int childCount = mChildHelper.getChildCount(); |
| 4557 |
for (int i = 0; i < childCount; i++) { |
| 4558 |
mChildHelper.getChildAt(i).offsetTopAndBottom(dy); |
| 4559 |
} |
| 4560 |
} |
| 4561 |
|
| 4562 |
|
| 4563 |
|
| 4564 |
|
| 4565 |
|
| 4566 |
|
| 4567 |
|
| 4568 |
|
| 4569 |
|
| 4570 |
|
| 4571 |
|
| 4572 |
public void onChildAttachedToWindow(View child) { |
| 4573 |
} |
| 4574 |
|
| 4575 |
|
| 4576 |
|
| 4577 |
|
| 4578 |
|
| 4579 |
|
| 4580 |
|
| 4581 |
|
| 4582 |
|
| 4583 |
|
| 4584 |
public void onChildDetachedFromWindow(View child) { |
| 4585 |
} |
| 4586 |
|
| 4587 |
|
| 4588 |
|
| 4589 |
|
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
public void offsetChildrenHorizontal(int dx) { |
| 4594 |
final int childCount = mChildHelper.getChildCount(); |
| 4595 |
for (int i = 0; i < childCount; i++) { |
| 4596 |
mChildHelper.getChildAt(i).offsetLeftAndRight(dx); |
| 4597 |
} |
| 4598 |
} |
| 4599 |
|
| 4600 |
|
| 4601 |
|
| 4602 |
|
| 4603 |
|
| 4604 |
|
| 4605 |
|
| 4606 |
|
| 4607 |
public void getDecoratedBoundsWithMargins(View view, Rect outBounds) { |
| 4608 |
getDecoratedBoundsWithMarginsInt(view, outBounds); |
| 4609 |
} |
| 4610 |
|
| 4611 |
static void getDecoratedBoundsWithMarginsInt(View view, Rect outBounds) { |
| 4612 |
final LayoutParams lp = (LayoutParams) view.getLayoutParams(); |
| 4613 |
final Rect insets = lp.mDecorInsets; |
| 4614 |
outBounds.set(view.getLeft() - insets.left - lp.leftMargin, |
| 4615 |
view.getTop() - insets.top - lp.topMargin, |
| 4616 |
view.getRight() + insets.right + lp.rightMargin, |
| 4617 |
view.getBottom() + insets.bottom + lp.bottomMargin); |
| 4618 |
} |
| 4619 |
|
| 4620 |
Rect getItemDecorInsetsForChild(View child) { |
| 4621 |
final LayoutParams lp = (LayoutParams) child.getLayoutParams(); |
| 4622 |
if (!lp.mInsetsDirty) { |
| 4623 |
return lp.mDecorInsets; |
| 4624 |
} |
| 4625 |
|
| 4626 |
if (mState.isPreLayout() && (lp.isItemChanged() || lp.isViewInvalid())) { |
| 4627 |
|
| 4628 |
return lp.mDecorInsets; |
| 4629 |
} |
| 4630 |
final Rect insets = lp.mDecorInsets; |
| 4631 |
insets.set(0, 0, 0, 0); |
| 4632 |
final int decorCount = mItemDecorations.size(); |
| 4633 |
for (int i = 0; i < decorCount; i++) { |
| 4634 |
mTempRect.set(0, 0, 0, 0); |
| 4635 |
mItemDecorations.get(i).getItemOffsets(mTempRect, child, this, mState); |
| 4636 |
insets.left += mTempRect.left; |
| 4637 |
insets.top += mTempRect.top; |
| 4638 |
insets.right += mTempRect.right; |
| 4639 |
insets.bottom += mTempRect.bottom; |
| 4640 |
} |
| 4641 |
lp.mInsetsDirty = false; |
| 4642 |
return insets; |
| 4643 |
} |
| 4644 |
|
| 4645 |
|
| 4646 |
|
| 4647 |
|
| 4648 |
|
| 4649 |
|
| 4650 |
|
| 4651 |
|
| 4652 |
|
| 4653 |
|
| 4654 |
|
| 4655 |
|
| 4656 |
|
| 4657 |
|
| 4658 |
|
| 4659 |
|
| 4660 |
|
| 4661 |
|
| 4662 |
|
| 4663 |
|
| 4664 |
|
| 4665 |
public void onScrolled(int dx, int dy) { |
| 4666 |
|
| 4667 |
} |
| 4668 |
|
| 4669 |
void dispatchOnScrolled(int hresult, int vresult) { |
| 4670 |
mDispatchScrollCounter++; |
| 4671 |
|
| 4672 |
|
| 4673 |
final int scrollX = getScrollX(); |
| 4674 |
final int scrollY = getScrollY(); |
| 4675 |
onScrollChanged(scrollX, scrollY, scrollX, scrollY); |
| 4676 |
|
| 4677 |
|
| 4678 |
onScrolled(hresult, vresult); |
| 4679 |
|
| 4680 |
|
| 4681 |
|
| 4682 |
if (mScrollListener != null) { |
| 4683 |
mScrollListener.onScrolled(this, hresult, vresult); |
| 4684 |
} |
| 4685 |
if (mScrollListeners != null) { |
| 4686 |
for (int i = mScrollListeners.size() - 1; i >= 0; i--) { |
| 4687 |
mScrollListeners.get(i).onScrolled(this, hresult, vresult); |
| 4688 |
} |
| 4689 |
} |
| 4690 |
mDispatchScrollCounter--; |
| 4691 |
} |
| 4692 |
|
| 4693 |
|
| 4694 |
|
| 4695 |
|
| 4696 |
|
| 4697 |
|
| 4698 |
|
| 4699 |
|
| 4700 |
|
| 4701 |
|
| 4702 |
|
| 4703 |
public void onScrollStateChanged(int state) { |
| 4704 |
|
| 4705 |
} |
| 4706 |
|
| 4707 |
void dispatchOnScrollStateChanged(int state) { |
| 4708 |
|
| 4709 |
|
| 4710 |
if (mLayout != null) { |
| 4711 |
mLayout.onScrollStateChanged(state); |
| 4712 |
} |
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
onScrollStateChanged(state); |
| 4717 |
|
| 4718 |
|
| 4719 |
if (mScrollListener != null) { |
| 4720 |
mScrollListener.onScrollStateChanged(this, state); |
| 4721 |
} |
| 4722 |
if (mScrollListeners != null) { |
| 4723 |
for (int i = mScrollListeners.size() - 1; i >= 0; i--) { |
| 4724 |
mScrollListeners.get(i).onScrollStateChanged(this, state); |
| 4725 |
} |
| 4726 |
} |
| 4727 |
} |
| 4728 |
|
| 4729 |
|
| 4730 |
|
| 4731 |
|
| 4732 |
|
| 4733 |
|
| 4734 |
|
| 4735 |
|
| 4736 |
|
| 4737 |
|
| 4738 |
|
| 4739 |
|
| 4740 |
|
| 4741 |
|
| 4742 |
public boolean hasPendingAdapterUpdates() { |
| 4743 |
return !mFirstLayoutComplete || mDataSetHasChangedAfterLayout |
| 4744 |
|| mAdapterHelper.hasPendingUpdates(); |
| 4745 |
} |
| 4746 |
|
| 4747 |
class ViewFlinger implements Runnable { |
| 4748 |
private int mLastFlingX; |
| 4749 |
private int mLastFlingY; |
| 4750 |
private OverScroller mScroller; |
| 4751 |
Interpolator mInterpolator = sQuinticInterpolator; |
| 4752 |
|
| 4753 |
|
| 4754 |
|
| 4755 |
private boolean mEatRunOnAnimationRequest = false; |
| 4756 |
|
| 4757 |
|
| 4758 |
private boolean mReSchedulePostAnimationCallback = false; |
| 4759 |
|
| 4760 |
ViewFlinger() { |
| 4761 |
mScroller = new OverScroller(getContext(), sQuinticInterpolator); |
| 4762 |
} |
| 4763 |
|
| 4764 |
@Override |
| 4765 |
public void run() { |
| 4766 |
if (mLayout == null) { |
| 4767 |
stop(); |
| 4768 |
return; |
| 4769 |
} |
| 4770 |
disableRunOnAnimationRequests(); |
| 4771 |
consumePendingUpdateOperations(); |
| 4772 |
|
| 4773 |
|
| 4774 |
final OverScroller scroller = mScroller; |
| 4775 |
final SmoothScroller smoothScroller = mLayout.mSmoothScroller; |
| 4776 |
if (scroller.computeScrollOffset()) { |
| 4777 |
final int x = scroller.getCurrX(); |
| 4778 |
final int y = scroller.getCurrY(); |
| 4779 |
final int dx = x - mLastFlingX; |
| 4780 |
final int dy = y - mLastFlingY; |
| 4781 |
int hresult = 0; |
| 4782 |
int vresult = 0; |
| 4783 |
mLastFlingX = x; |
| 4784 |
mLastFlingY = y; |
| 4785 |
int overscrollX = 0, overscrollY = 0; |
| 4786 |
if (mAdapter != null) { |
| 4787 |
eatRequestLayout(); |
| 4788 |
onEnterLayoutOrScroll(); |
| 4789 |
Trace.beginSection(TRACE_SCROLL_TAG); |
| 4790 |
if (dx != 0) { |
| 4791 |
hresult = mLayout.scrollHorizontallyBy(dx, mRecycler, mState); |
| 4792 |
overscrollX = dx - hresult; |
| 4793 |
} |
| 4794 |
if (dy != 0) { |
| 4795 |
vresult = mLayout.scrollVerticallyBy(dy, mRecycler, mState); |
| 4796 |
overscrollY = dy - vresult; |
| 4797 |
} |
| 4798 |
Trace.endSection(); |
| 4799 |
repositionShadowingViews(); |
| 4800 |
|
| 4801 |
onExitLayoutOrScroll(); |
| 4802 |
resumeRequestLayout(false); |
| 4803 |
|
| 4804 |
if (smoothScroller != null && !smoothScroller.isPendingInitialRun() |
| 4805 |
&& smoothScroller.isRunning()) { |
| 4806 |
final int adapterSize = mState.getItemCount(); |
| 4807 |
if (adapterSize == 0) { |
| 4808 |
smoothScroller.stop(); |
| 4809 |
} else if (smoothScroller.getTargetPosition() >= adapterSize) { |
| 4810 |
smoothScroller.setTargetPosition(adapterSize - 1); |
| 4811 |
smoothScroller.onAnimation(dx - overscrollX, dy - overscrollY); |
| 4812 |
} else { |
| 4813 |
smoothScroller.onAnimation(dx - overscrollX, dy - overscrollY); |
| 4814 |
} |
| 4815 |
} |
| 4816 |
} |
| 4817 |
if (!mItemDecorations.isEmpty()) { |
| 4818 |
invalidate(); |
| 4819 |
} |
| 4820 |
if (getOverScrollMode() != View.OVER_SCROLL_NEVER) { |
| 4821 |
considerReleasingGlowsOnScroll(dx, dy); |
| 4822 |
} |
| 4823 |
if (overscrollX != 0 || overscrollY != 0) { |
| 4824 |
final int vel = (int) scroller.getCurrVelocity(); |
| 4825 |
|
| 4826 |
int velX = 0; |
| 4827 |
if (overscrollX != x) { |
| 4828 |
velX = overscrollX < 0 ? -vel : overscrollX > 0 ? vel : 0; |
| 4829 |
} |
| 4830 |
|
| 4831 |
int velY = 0; |
| 4832 |
if (overscrollY != y) { |
| 4833 |
velY = overscrollY < 0 ? -vel : overscrollY > 0 ? vel : 0; |
| 4834 |
} |
| 4835 |
|
| 4836 |
if (getOverScrollMode() != View.OVER_SCROLL_NEVER) { |
| 4837 |
absorbGlows(velX, velY); |
| 4838 |
} |
| 4839 |
if ((velX != 0 || overscrollX == x || scroller.getFinalX() == 0) |
| 4840 |
&& (velY != 0 || overscrollY == y || scroller.getFinalY() == 0)) { |
| 4841 |
scroller.abortAnimation(); |
| 4842 |
} |
| 4843 |
} |
| 4844 |
if (hresult != 0 || vresult != 0) { |
| 4845 |
dispatchOnScrolled(hresult, vresult); |
| 4846 |
} |
| 4847 |
|
| 4848 |
if (!awakenScrollBars()) { |
| 4849 |
invalidate(); |
| 4850 |
} |
| 4851 |
|
| 4852 |
final boolean fullyConsumedVertical = dy != 0 && mLayout.canScrollVertically() |
| 4853 |
&& vresult == dy; |
| 4854 |
final boolean fullyConsumedHorizontal = dx != 0 && mLayout.canScrollHorizontally() |
| 4855 |
&& hresult == dx; |
| 4856 |
final boolean fullyConsumedAny = (dx == 0 && dy == 0) || fullyConsumedHorizontal |
| 4857 |
|| fullyConsumedVertical; |
| 4858 |
|
| 4859 |
if (scroller.isFinished() || !fullyConsumedAny) { |
| 4860 |
setScrollState(SCROLL_STATE_IDLE); |
| 4861 |
if (ALLOW_THREAD_GAP_WORK) { |
| 4862 |
mPrefetchRegistry.clearPrefetchPositions(); |
| 4863 |
} |
| 4864 |
} else { |
| 4865 |
postOnAnimation(); |
| 4866 |
if (mGapWorker != null) { |
| 4867 |
mGapWorker.postFromTraversal(RecyclerView.this, dx, dy); |
| 4868 |
} |
| 4869 |
} |
| 4870 |
} |
| 4871 |
|
| 4872 |
if (smoothScroller != null) { |
| 4873 |
if (smoothScroller.isPendingInitialRun()) { |
| 4874 |
smoothScroller.onAnimation(0, 0); |
| 4875 |
} |
| 4876 |
if (!mReSchedulePostAnimationCallback) { |
| 4877 |
smoothScroller.stop(); |
| 4878 |
} |
| 4879 |
} |
| 4880 |
enableRunOnAnimationRequests(); |
| 4881 |
} |
| 4882 |
|
| 4883 |
private void disableRunOnAnimationRequests() { |
| 4884 |
mReSchedulePostAnimationCallback = false; |
| 4885 |
mEatRunOnAnimationRequest = true; |
| 4886 |
} |
| 4887 |
|
| 4888 |
private void enableRunOnAnimationRequests() { |
| 4889 |
mEatRunOnAnimationRequest = false; |
| 4890 |
if (mReSchedulePostAnimationCallback) { |
| 4891 |
postOnAnimation(); |
| 4892 |
} |
| 4893 |
} |
| 4894 |
|
| 4895 |
void postOnAnimation() { |
| 4896 |
if (mEatRunOnAnimationRequest) { |
| 4897 |
mReSchedulePostAnimationCallback = true; |
| 4898 |
} else { |
| 4899 |
removeCallbacks(this); |
| 4900 |
RecyclerView.this.postOnAnimation(this); |
| 4901 |
} |
| 4902 |
} |
| 4903 |
|
| 4904 |
public void fling(int velocityX, int velocityY) { |
| 4905 |
setScrollState(SCROLL_STATE_SETTLING); |
| 4906 |
mLastFlingX = mLastFlingY = 0; |
| 4907 |
mScroller.fling(0, 0, velocityX, velocityY, |
| 4908 |
Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE); |
| 4909 |
postOnAnimation(); |
| 4910 |
} |
| 4911 |
|
| 4912 |
public void smoothScrollBy(int dx, int dy) { |
| 4913 |
smoothScrollBy(dx, dy, 0, 0); |
| 4914 |
} |
| 4915 |
|
| 4916 |
public void smoothScrollBy(int dx, int dy, int vx, int vy) { |
| 4917 |
smoothScrollBy(dx, dy, computeScrollDuration(dx, dy, vx, vy)); |
| 4918 |
} |
| 4919 |
|
| 4920 |
private float distanceInfluenceForSnapDuration(float f) { |
| 4921 |
f -= 0.5f; |
| 4922 |
f *= 0.3f * Math.PI / 2.0f; |
| 4923 |
return (float) Math.sin(f); |
| 4924 |
} |
| 4925 |
|
| 4926 |
private int computeScrollDuration(int dx, int dy, int vx, int vy) { |
| 4927 |
final int absDx = Math.abs(dx); |
| 4928 |
final int absDy = Math.abs(dy); |
| 4929 |
final boolean horizontal = absDx > absDy; |
| 4930 |
final int velocity = (int) Math.sqrt(vx * vx + vy * vy); |
| 4931 |
final int delta = (int) Math.sqrt(dx * dx + dy * dy); |
| 4932 |
final int containerSize = horizontal ? getWidth() : getHeight(); |
| 4933 |
final int halfContainerSize = containerSize / 2; |
| 4934 |
final float distanceRatio = Math.min(1.f, 1.f * delta / containerSize); |
| 4935 |
final float distance = halfContainerSize + halfContainerSize |
| 4936 |
* distanceInfluenceForSnapDuration(distanceRatio); |
| 4937 |
|
| 4938 |
final int duration; |
| 4939 |
if (velocity > 0) { |
| 4940 |
duration = 4 * Math.round(1000 * Math.abs(distance / velocity)); |
| 4941 |
} else { |
| 4942 |
float absDelta = (float) (horizontal ? absDx : absDy); |
| 4943 |
duration = (int) (((absDelta / containerSize) + 1) * 300); |
| 4944 |
} |
| 4945 |
return Math.min(duration, MAX_SCROLL_DURATION); |
| 4946 |
} |
| 4947 |
|
| 4948 |
public void smoothScrollBy(int dx, int dy, int duration) { |
| 4949 |
smoothScrollBy(dx, dy, duration, sQuinticInterpolator); |
| 4950 |
} |
| 4951 |
|
| 4952 |
public void smoothScrollBy(int dx, int dy, Interpolator interpolator) { |
| 4953 |
smoothScrollBy(dx, dy, computeScrollDuration(dx, dy, 0, 0), |
| 4954 |
interpolator == null ? sQuinticInterpolator : interpolator); |
| 4955 |
} |
| 4956 |
|
| 4957 |
public void smoothScrollBy(int dx, int dy, int duration, Interpolator interpolator) { |
| 4958 |
if (mInterpolator != interpolator) { |
| 4959 |
mInterpolator = interpolator; |
| 4960 |
mScroller = new OverScroller(getContext(), interpolator); |
| 4961 |
} |
| 4962 |
setScrollState(SCROLL_STATE_SETTLING); |
| 4963 |
mLastFlingX = mLastFlingY = 0; |
| 4964 |
mScroller.startScroll(0, 0, dx, dy, duration); |
| 4965 |
postOnAnimation(); |
| 4966 |
} |
| 4967 |
|
| 4968 |
public void stop() { |
| 4969 |
removeCallbacks(this); |
| 4970 |
mScroller.abortAnimation(); |
| 4971 |
} |
| 4972 |
|
| 4973 |
} |
| 4974 |
|
| 4975 |
void repositionShadowingViews() { |
| 4976 |
|
| 4977 |
int count = mChildHelper.getChildCount(); |
| 4978 |
for (int i = 0; i < count; i++) { |
| 4979 |
View view = mChildHelper.getChildAt(i); |
| 4980 |
ViewHolder holder = getChildViewHolder(view); |
| 4981 |
if (holder != null && holder.mShadowingHolder != null) { |
| 4982 |
View shadowingView = holder.mShadowingHolder.itemView; |
| 4983 |
int left = view.getLeft(); |
| 4984 |
int top = view.getTop(); |
| 4985 |
if (left != shadowingView.getLeft() || top != shadowingView.getTop()) { |
| 4986 |
shadowingView.layout(left, top, |
| 4987 |
left + shadowingView.getWidth(), |
| 4988 |
top + shadowingView.getHeight()); |
| 4989 |
} |
| 4990 |
} |
| 4991 |
} |
| 4992 |
} |
| 4993 |
|
| 4994 |
private class RecyclerViewDataObserver extends AdapterDataObserver { |
| 4995 |
RecyclerViewDataObserver() { |
| 4996 |
} |
| 4997 |
|
| 4998 |
@Override |
| 4999 |
public void onChanged() { |
| 5000 |
assertNotInLayoutOrScroll(null); |
| 5001 |
mState.mStructureChanged = true; |
| 5002 |
|
| 5003 |
setDataSetChangedAfterLayout(); |
| 5004 |
if (!mAdapterHelper.hasPendingUpdates()) { |
| 5005 |
requestLayout(); |
| 5006 |
} |
| 5007 |
} |
| 5008 |
|
| 5009 |
@Override |
| 5010 |
public void onItemRangeChanged(int positionStart, int itemCount, Object payload) { |
| 5011 |
assertNotInLayoutOrScroll(null); |
| 5012 |
if (mAdapterHelper.onItemRangeChanged(positionStart, itemCount, payload)) { |
| 5013 |
triggerUpdateProcessor(); |
| 5014 |
} |
| 5015 |
} |
| 5016 |
|
| 5017 |
@Override |
| 5018 |
public void onItemRangeInserted(int positionStart, int itemCount) { |
| 5019 |
assertNotInLayoutOrScroll(null); |
| 5020 |
if (mAdapterHelper.onItemRangeInserted(positionStart, itemCount)) { |
| 5021 |
triggerUpdateProcessor(); |
| 5022 |
} |
| 5023 |
} |
| 5024 |
|
| 5025 |
@Override |
| 5026 |
public void onItemRangeRemoved(int positionStart, int itemCount) { |
| 5027 |
assertNotInLayoutOrScroll(null); |
| 5028 |
if (mAdapterHelper.onItemRangeRemoved(positionStart, itemCount)) { |
| 5029 |
triggerUpdateProcessor(); |
| 5030 |
} |
| 5031 |
} |
| 5032 |
|
| 5033 |
@Override |
| 5034 |
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { |
| 5035 |
assertNotInLayoutOrScroll(null); |
| 5036 |
if (mAdapterHelper.onItemRangeMoved(fromPosition, toPosition, itemCount)) { |
| 5037 |
triggerUpdateProcessor(); |
| 5038 |
} |
| 5039 |
} |
| 5040 |
|
| 5041 |
void triggerUpdateProcessor() { |
| 5042 |
if (POST_UPDATES_ON_ANIMATION && mHasFixedSize && mIsAttached) { |
| 5043 |
RecyclerView.this.postOnAnimation(mUpdateChildViewsRunnable); |
| 5044 |
} else { |
| 5045 |
mAdapterUpdateDuringMeasure = true; |
| 5046 |
requestLayout(); |
| 5047 |
} |
| 5048 |
} |
| 5049 |
} |
| 5050 |
|
| 5051 |
|
| 5052 |
|
| 5053 |
|
| 5054 |
|
| 5055 |
|
| 5056 |
|
| 5057 |
|
| 5058 |
|
| 5059 |
|
| 5060 |
public static class RecycledViewPool { |
| 5061 |
private static final int DEFAULT_MAX_SCRAP = 5; |
| 5062 |
|
| 5063 |
|
| 5064 |
|
| 5065 |
|
| 5066 |
|
| 5067 |
|
| 5068 |
|
| 5069 |
|
| 5070 |
|
| 5071 |
|
| 5072 |
|
| 5073 |
|
| 5074 |
|
| 5075 |
|
| 5076 |
|
| 5077 |
static class ScrapData { |
| 5078 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 5079 |
ArrayList<ViewHolder> mScrapHeap = new ArrayList<>(); |
| 5080 |
int mMaxScrap = DEFAULT_MAX_SCRAP; |
| 5081 |
long mCreateRunningAverageNs = 0; |
| 5082 |
long mBindRunningAverageNs = 0; |
| 5083 |
} |
| 5084 |
SparseArray<ScrapData> mScrap = new SparseArray<>(); |
| 5085 |
|
| 5086 |
private int mAttachCount = 0; |
| 5087 |
|
| 5088 |
public void clear() { |
| 5089 |
for (int i = 0; i < mScrap.size(); i++) { |
| 5090 |
ScrapData data = mScrap.valueAt(i); |
| 5091 |
data.mScrapHeap.clear(); |
| 5092 |
} |
| 5093 |
} |
| 5094 |
|
| 5095 |
public void setMaxRecycledViews(int viewType, int max) { |
| 5096 |
ScrapData scrapData = getScrapDataForType(viewType); |
| 5097 |
scrapData.mMaxScrap = max; |
| 5098 |
final ArrayList<ViewHolder> scrapHeap = scrapData.mScrapHeap; |
| 5099 |
if (scrapHeap != null) { |
| 5100 |
while (scrapHeap.size() > max) { |
| 5101 |
scrapHeap.remove(scrapHeap.size() - 1); |
| 5102 |
} |
| 5103 |
} |
| 5104 |
} |
| 5105 |
|
| 5106 |
|
| 5107 |
|
| 5108 |
|
| 5109 |
public int getRecycledViewCount(int viewType) { |
| 5110 |
return getScrapDataForType(viewType).mScrapHeap.size(); |
| 5111 |
} |
| 5112 |
|
| 5113 |
public ViewHolder getRecycledView(int viewType) { |
| 5114 |
final ScrapData scrapData = mScrap.get(viewType); |
| 5115 |
if (scrapData != null && !scrapData.mScrapHeap.isEmpty()) { |
| 5116 |
final ArrayList<ViewHolder> scrapHeap = scrapData.mScrapHeap; |
| 5117 |
return scrapHeap.remove(scrapHeap.size() - 1); |
| 5118 |
} |
| 5119 |
return null; |
| 5120 |
} |
| 5121 |
|
| 5122 |
int size() { |
| 5123 |
int count = 0; |
| 5124 |
for (int i = 0; i < mScrap.size(); i++) { |
| 5125 |
ArrayList<ViewHolder> viewHolders = mScrap.valueAt(i).mScrapHeap; |
| 5126 |
if (viewHolders != null) { |
| 5127 |
count += viewHolders.size(); |
| 5128 |
} |
| 5129 |
} |
| 5130 |
return count; |
| 5131 |
} |
| 5132 |
|
| 5133 |
public void putRecycledView(ViewHolder scrap) { |
| 5134 |
final int viewType = scrap.getItemViewType(); |
| 5135 |
final ArrayList scrapHeap = getScrapDataForType(viewType).mScrapHeap; |
| 5136 |
if (mScrap.get(viewType).mMaxScrap <= scrapHeap.size()) { |
| 5137 |
return; |
| 5138 |
} |
| 5139 |
if (DEBUG && scrapHeap.contains(scrap)) { |
| 5140 |
throw new IllegalArgumentException("this scrap item already exists"); |
| 5141 |
} |
| 5142 |
scrap.resetInternal(); |
| 5143 |
scrapHeap.add(scrap); |
| 5144 |
} |
| 5145 |
|
| 5146 |
long runningAverage(long oldAverage, long newValue) { |
| 5147 |
if (oldAverage == 0) { |
| 5148 |
return newValue; |
| 5149 |
} |
| 5150 |
return (oldAverage / 4 * 3) + (newValue / 4); |
| 5151 |
} |
| 5152 |
|
| 5153 |
void factorInCreateTime(int viewType, long createTimeNs) { |
| 5154 |
ScrapData scrapData = getScrapDataForType(viewType); |
| 5155 |
scrapData.mCreateRunningAverageNs = runningAverage( |
| 5156 |
scrapData.mCreateRunningAverageNs, createTimeNs); |
| 5157 |
} |
| 5158 |
|
| 5159 |
void factorInBindTime(int viewType, long bindTimeNs) { |
| 5160 |
ScrapData scrapData = getScrapDataForType(viewType); |
| 5161 |
scrapData.mBindRunningAverageNs = runningAverage( |
| 5162 |
scrapData.mBindRunningAverageNs, bindTimeNs); |
| 5163 |
} |
| 5164 |
|
| 5165 |
boolean willCreateInTime(int viewType, long approxCurrentNs, long deadlineNs) { |
| 5166 |
long expectedDurationNs = getScrapDataForType(viewType).mCreateRunningAverageNs; |
| 5167 |
return expectedDurationNs == 0 || (approxCurrentNs + expectedDurationNs < deadlineNs); |
| 5168 |
} |
| 5169 |
|
| 5170 |
boolean willBindInTime(int viewType, long approxCurrentNs, long deadlineNs) { |
| 5171 |
long expectedDurationNs = getScrapDataForType(viewType).mBindRunningAverageNs; |
| 5172 |
return expectedDurationNs == 0 || (approxCurrentNs + expectedDurationNs < deadlineNs); |
| 5173 |
} |
| 5174 |
|
| 5175 |
void attach(Adapter adapter) { |
| 5176 |
mAttachCount++; |
| 5177 |
} |
| 5178 |
|
| 5179 |
void detach() { |
| 5180 |
mAttachCount--; |
| 5181 |
} |
| 5182 |
|
| 5183 |
|
| 5184 |
|
| 5185 |
|
| 5186 |
|
| 5187 |
|
| 5188 |
|
| 5189 |
|
| 5190 |
|
| 5191 |
|
| 5192 |
|
| 5193 |
|
| 5194 |
|
| 5195 |
void onAdapterChanged(Adapter oldAdapter, Adapter newAdapter, |
| 5196 |
boolean compatibleWithPrevious) { |
| 5197 |
if (oldAdapter != null) { |
| 5198 |
detach(); |
| 5199 |
} |
| 5200 |
if (!compatibleWithPrevious && mAttachCount == 0) { |
| 5201 |
clear(); |
| 5202 |
} |
| 5203 |
if (newAdapter != null) { |
| 5204 |
attach(newAdapter); |
| 5205 |
} |
| 5206 |
} |
| 5207 |
|
| 5208 |
private ScrapData getScrapDataForType(int viewType) { |
| 5209 |
ScrapData scrapData = mScrap.get(viewType); |
| 5210 |
if (scrapData == null) { |
| 5211 |
scrapData = new ScrapData(); |
| 5212 |
mScrap.put(viewType, scrapData); |
| 5213 |
} |
| 5214 |
return scrapData; |
| 5215 |
} |
| 5216 |
} |
| 5217 |
|
| 5218 |
|
| 5219 |
|
| 5220 |
|
| 5221 |
@Nullable |
| 5222 |
static RecyclerView findNestedRecyclerView(@NonNull View view) { |
| 5223 |
if (!(view instanceof ViewGroup)) { |
| 5224 |
return null; |
| 5225 |
} |
| 5226 |
if (view instanceof RecyclerView) { |
| 5227 |
return (RecyclerView) view; |
| 5228 |
} |
| 5229 |
final ViewGroup parent = (ViewGroup) view; |
| 5230 |
final int count = parent.getChildCount(); |
| 5231 |
for (int i = 0; i < count; i++) { |
| 5232 |
final View child = parent.getChildAt(i); |
| 5233 |
final RecyclerView descendant = findNestedRecyclerView(child); |
| 5234 |
if (descendant != null) { |
| 5235 |
return descendant; |
| 5236 |
} |
| 5237 |
} |
| 5238 |
return null; |
| 5239 |
} |
| 5240 |
|
| 5241 |
|
| 5242 |
|
| 5243 |
|
| 5244 |
static void clearNestedRecyclerViewIfNotNested(@NonNull ViewHolder holder) { |
| 5245 |
if (holder.mNestedRecyclerView != null) { |
| 5246 |
View item = holder.mNestedRecyclerView.get(); |
| 5247 |
while (item != null) { |
| 5248 |
if (item == holder.itemView) { |
| 5249 |
return; |
| 5250 |
} |
| 5251 |
|
| 5252 |
ViewParent parent = item.getParent(); |
| 5253 |
if (parent instanceof View) { |
| 5254 |
item = (View) parent; |
| 5255 |
} else { |
| 5256 |
item = null; |
| 5257 |
} |
| 5258 |
} |
| 5259 |
holder.mNestedRecyclerView = null; |
| 5260 |
} |
| 5261 |
} |
| 5262 |
|
| 5263 |
|
| 5264 |
|
| 5265 |
|
| 5266 |
|
| 5267 |
|
| 5268 |
|
| 5269 |
long getNanoTime() { |
| 5270 |
if (ALLOW_THREAD_GAP_WORK) { |
| 5271 |
return System.nanoTime(); |
| 5272 |
} else { |
| 5273 |
return 0; |
| 5274 |
} |
| 5275 |
} |
| 5276 |
|
| 5277 |
|
| 5278 |
|
| 5279 |
|
| 5280 |
|
| 5281 |
|
| 5282 |
|
| 5283 |
|
| 5284 |
|
| 5285 |
|
| 5286 |
|
| 5287 |
|
| 5288 |
|
| 5289 |
|
| 5290 |
public final class Recycler { |
| 5291 |
final ArrayList<ViewHolder> mAttachedScrap = new ArrayList<>(); |
| 5292 |
ArrayList<ViewHolder> mChangedScrap = null; |
| 5293 |
|
| 5294 |
final ArrayList<ViewHolder> mCachedViews = new ArrayList<ViewHolder>(); |
| 5295 |
|
| 5296 |
private final List<ViewHolder> |
| 5297 |
mUnmodifiableAttachedScrap = Collections.unmodifiableList(mAttachedScrap); |
| 5298 |
|
| 5299 |
private int mRequestedCacheMax = DEFAULT_CACHE_SIZE; |
| 5300 |
int mViewCacheMax = DEFAULT_CACHE_SIZE; |
| 5301 |
|
| 5302 |
RecycledViewPool mRecyclerPool; |
| 5303 |
|
| 5304 |
private ViewCacheExtension mViewCacheExtension; |
| 5305 |
|
| 5306 |
static final int DEFAULT_CACHE_SIZE = 2; |
| 5307 |
|
| 5308 |
|
| 5309 |
|
| 5310 |
|
| 5311 |
|
| 5312 |
public void clear() { |
| 5313 |
mAttachedScrap.clear(); |
| 5314 |
recycleAndClearCachedViews(); |
| 5315 |
} |
| 5316 |
|
| 5317 |
|
| 5318 |
|
| 5319 |
|
| 5320 |
|
| 5321 |
|
| 5322 |
public void setViewCacheSize(int viewCount) { |
| 5323 |
mRequestedCacheMax = viewCount; |
| 5324 |
updateViewCacheSize(); |
| 5325 |
} |
| 5326 |
|
| 5327 |
void updateViewCacheSize() { |
| 5328 |
int extraCache = mLayout != null ? mLayout.mPrefetchMaxCountObserved : 0; |
| 5329 |
mViewCacheMax = mRequestedCacheMax + extraCache; |
| 5330 |
|
| 5331 |
|
| 5332 |
for (int i = mCachedViews.size() - 1; |
| 5333 |
i >= 0 && mCachedViews.size() > mViewCacheMax; i--) { |
| 5334 |
recycleCachedViewAt(i); |
| 5335 |
} |
| 5336 |
} |
| 5337 |
|
| 5338 |
|
| 5339 |
|
| 5340 |
|
| 5341 |
|
| 5342 |
|
| 5343 |
public List<ViewHolder> getScrapList() { |
| 5344 |
return mUnmodifiableAttachedScrap; |
| 5345 |
} |
| 5346 |
|
| 5347 |
|
| 5348 |
|
| 5349 |
|
| 5350 |
|
| 5351 |
|
| 5352 |
|
| 5353 |
|
| 5354 |
|
| 5355 |
boolean validateViewHolderForOffsetPosition(ViewHolder holder) { |
| 5356 |
|
| 5357 |
|
| 5358 |
if (holder.isRemoved()) { |
| 5359 |
if (DEBUG && !mState.isPreLayout()) { |
| 5360 |
throw new IllegalStateException("should not receive a removed view unless it" |
| 5361 |
+ " is pre layout"); |
| 5362 |
} |
| 5363 |
return mState.isPreLayout(); |
| 5364 |
} |
| 5365 |
if (holder.mPosition < 0 || holder.mPosition >= mAdapter.getItemCount()) { |
| 5366 |
throw new IndexOutOfBoundsException("Inconsistency detected. Invalid view holder " |
| 5367 |
+ "adapter position" + holder); |
| 5368 |
} |
| 5369 |
if (!mState.isPreLayout()) { |
| 5370 |
|
| 5371 |
final int type = mAdapter.getItemViewType(holder.mPosition); |
| 5372 |
if (type != holder.getItemViewType()) { |
| 5373 |
return false; |
| 5374 |
} |
| 5375 |
} |
| 5376 |
if (mAdapter.hasStableIds()) { |
| 5377 |
return holder.getItemId() == mAdapter.getItemId(holder.mPosition); |
| 5378 |
} |
| 5379 |
return true; |
| 5380 |
} |
| 5381 |
|
| 5382 |
|
| 5383 |
|
| 5384 |
|
| 5385 |
|
| 5386 |
|
| 5387 |
|
| 5388 |
|
| 5389 |
|
| 5390 |
|
| 5391 |
|
| 5392 |
|
| 5393 |
|
| 5394 |
private boolean tryBindViewHolderByDeadline(ViewHolder holder, int offsetPosition, |
| 5395 |
int position, long deadlineNs) { |
| 5396 |
holder.mOwnerRecyclerView = RecyclerView.this; |
| 5397 |
final int viewType = holder.getItemViewType(); |
| 5398 |
long startBindNs = getNanoTime(); |
| 5399 |
if (deadlineNs != FOREVER_NS |
| 5400 |
&& !mRecyclerPool.willBindInTime(viewType, startBindNs, deadlineNs)) { |
| 5401 |
|
| 5402 |
return false; |
| 5403 |
} |
| 5404 |
mAdapter.bindViewHolder(holder, offsetPosition); |
| 5405 |
long endBindNs = getNanoTime(); |
| 5406 |
mRecyclerPool.factorInBindTime(holder.getItemViewType(), endBindNs - startBindNs); |
| 5407 |
attachAccessibilityDelegate(holder.itemView); |
| 5408 |
if (mState.isPreLayout()) { |
| 5409 |
holder.mPreLayoutPosition = position; |
| 5410 |
} |
| 5411 |
return true; |
| 5412 |
} |
| 5413 |
|
| 5414 |
|
| 5415 |
|
| 5416 |
|
| 5417 |
|
| 5418 |
|
| 5419 |
|
| 5420 |
|
| 5421 |
|
| 5422 |
|
| 5423 |
|
| 5424 |
|
| 5425 |
|
| 5426 |
|
| 5427 |
|
| 5428 |
|
| 5429 |
public void bindViewToPosition(View view, int position) { |
| 5430 |
ViewHolder holder = getChildViewHolderInt(view); |
| 5431 |
if (holder == null) { |
| 5432 |
throw new IllegalArgumentException("The view does not have a ViewHolder. You cannot" |
| 5433 |
+ " pass arbitrary views to this method, they should be created by the " |
| 5434 |
+ "Adapter"); |
| 5435 |
} |
| 5436 |
final int offsetPosition = mAdapterHelper.findPositionOffset(position); |
| 5437 |
if (offsetPosition < 0 || offsetPosition >= mAdapter.getItemCount()) { |
| 5438 |
throw new IndexOutOfBoundsException("Inconsistency detected. Invalid item " |
| 5439 |
+ "position " + position + "(offset:" + offsetPosition + ")." |
| 5440 |
+ "state:" + mState.getItemCount()); |
| 5441 |
} |
| 5442 |
tryBindViewHolderByDeadline(holder, offsetPosition, position, FOREVER_NS); |
| 5443 |
|
| 5444 |
final ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); |
| 5445 |
final LayoutParams rvLayoutParams; |
| 5446 |
if (lp == null) { |
| 5447 |
rvLayoutParams = (LayoutParams) generateDefaultLayoutParams(); |
| 5448 |
holder.itemView.setLayoutParams(rvLayoutParams); |
| 5449 |
} else if (!checkLayoutParams(lp)) { |
| 5450 |
rvLayoutParams = (LayoutParams) generateLayoutParams(lp); |
| 5451 |
holder.itemView.setLayoutParams(rvLayoutParams); |
| 5452 |
} else { |
| 5453 |
rvLayoutParams = (LayoutParams) lp; |
| 5454 |
} |
| 5455 |
|
| 5456 |
rvLayoutParams.mInsetsDirty = true; |
| 5457 |
rvLayoutParams.mViewHolder = holder; |
| 5458 |
rvLayoutParams.mPendingInvalidate = holder.itemView.getParent() == null; |
| 5459 |
} |
| 5460 |
|
| 5461 |
|
| 5462 |
|
| 5463 |
|
| 5464 |
|
| 5465 |
|
| 5466 |
|
| 5467 |
|
| 5468 |
|
| 5469 |
|
| 5470 |
|
| 5471 |
|
| 5472 |
|
| 5473 |
|
| 5474 |
|
| 5475 |
|
| 5476 |
|
| 5477 |
|
| 5478 |
|
| 5479 |
public int convertPreLayoutPositionToPostLayout(int position) { |
| 5480 |
if (position < 0 || position >= mState.getItemCount()) { |
| 5481 |
throw new IndexOutOfBoundsException("invalid position " + position + ". State " |
| 5482 |
+ "item count is " + mState.getItemCount()); |
| 5483 |
} |
| 5484 |
if (!mState.isPreLayout()) { |
| 5485 |
return position; |
| 5486 |
} |
| 5487 |
return mAdapterHelper.findPositionOffset(position); |
| 5488 |
} |
| 5489 |
|
| 5490 |
|
| 5491 |
|
| 5492 |
|
| 5493 |
|
| 5494 |
|
| 5495 |
|
| 5496 |
|
| 5497 |
|
| 5498 |
|
| 5499 |
|
| 5500 |
|
| 5501 |
|
| 5502 |
|
| 5503 |
|
| 5504 |
public View getViewForPosition(int position) { |
| 5505 |
return getViewForPosition(position, false); |
| 5506 |
} |
| 5507 |
|
| 5508 |
View getViewForPosition(int position, boolean dryRun) { |
| 5509 |
return tryGetViewHolderForPositionByDeadline(position, dryRun, FOREVER_NS).itemView; |
| 5510 |
} |
| 5511 |
|
| 5512 |
|
| 5513 |
|
| 5514 |
|
| 5515 |
|
| 5516 |
|
| 5517 |
|
| 5518 |
|
| 5519 |
|
| 5520 |
|
| 5521 |
|
| 5522 |
|
| 5523 |
|
| 5524 |
|
| 5525 |
|
| 5526 |
|
| 5527 |
|
| 5528 |
|
| 5529 |
|
| 5530 |
@Nullable |
| 5531 |
ViewHolder tryGetViewHolderForPositionByDeadline(int position, |
| 5532 |
boolean dryRun, long deadlineNs) { |
| 5533 |
if (position < 0 || position >= mState.getItemCount()) { |
| 5534 |
throw new IndexOutOfBoundsException("Invalid item position " + position |
| 5535 |
+ "(" + position + "). Item count:" + mState.getItemCount()); |
| 5536 |
} |
| 5537 |
boolean fromScrapOrHiddenOrCache = false; |
| 5538 |
ViewHolder holder = null; |
| 5539 |
|
| 5540 |
if (mState.isPreLayout()) { |
| 5541 |
holder = getChangedScrapViewForPosition(position); |
| 5542 |
fromScrapOrHiddenOrCache = holder != null; |
| 5543 |
} |
| 5544 |
|
| 5545 |
if (holder == null) { |
| 5546 |
holder = getScrapOrHiddenOrCachedHolderForPosition(position, dryRun); |
| 5547 |
if (holder != null) { |
| 5548 |
if (!validateViewHolderForOffsetPosition(holder)) { |
| 5549 |
|
| 5550 |
if (!dryRun) { |
| 5551 |
|
| 5552 |
|
| 5553 |
holder.addFlags(ViewHolder.FLAG_INVALID); |
| 5554 |
if (holder.isScrap()) { |
| 5555 |
removeDetachedView(holder.itemView, false); |
| 5556 |
holder.unScrap(); |
| 5557 |
} else if (holder.wasReturnedFromScrap()) { |
| 5558 |
holder.clearReturnedFromScrapFlag(); |
| 5559 |
} |
| 5560 |
recycleViewHolderInternal(holder); |
| 5561 |
} |
| 5562 |
holder = null; |
| 5563 |
} else { |
| 5564 |
fromScrapOrHiddenOrCache = true; |
| 5565 |
} |
| 5566 |
} |
| 5567 |
} |
| 5568 |
if (holder == null) { |
| 5569 |
final int offsetPosition = mAdapterHelper.findPositionOffset(position); |
| 5570 |
if (offsetPosition < 0 || offsetPosition >= mAdapter.getItemCount()) { |
| 5571 |
throw new IndexOutOfBoundsException("Inconsistency detected. Invalid item " |
| 5572 |
+ "position " + position + "(offset:" + offsetPosition + ")." |
| 5573 |
+ "state:" + mState.getItemCount()); |
| 5574 |
} |
| 5575 |
|
| 5576 |
final int type = mAdapter.getItemViewType(offsetPosition); |
| 5577 |
|
| 5578 |
if (mAdapter.hasStableIds()) { |
| 5579 |
holder = getScrapOrCachedViewForId(mAdapter.getItemId(offsetPosition), |
| 5580 |
type, dryRun); |
| 5581 |
if (holder != null) { |
| 5582 |
|
| 5583 |
holder.mPosition = offsetPosition; |
| 5584 |
fromScrapOrHiddenOrCache = true; |
| 5585 |
} |
| 5586 |
} |
| 5587 |
if (holder == null && mViewCacheExtension != null) { |
| 5588 |
|
| 5589 |
|
| 5590 |
final View view = mViewCacheExtension |
| 5591 |
.getViewForPositionAndType(this, position, type); |
| 5592 |
if (view != null) { |
| 5593 |
holder = getChildViewHolder(view); |
| 5594 |
if (holder == null) { |
| 5595 |
throw new IllegalArgumentException("getViewForPositionAndType returned" |
| 5596 |
+ " a view which does not have a ViewHolder"); |
| 5597 |
} else if (holder.shouldIgnore()) { |
| 5598 |
throw new IllegalArgumentException("getViewForPositionAndType returned" |
| 5599 |
+ " a view that is ignored. You must call stopIgnoring before" |
| 5600 |
+ " returning this view."); |
| 5601 |
} |
| 5602 |
} |
| 5603 |
} |
| 5604 |
if (holder == null) { |
| 5605 |
if (DEBUG) { |
| 5606 |
Log.d(TAG, "tryGetViewHolderForPositionByDeadline(" |
| 5607 |
+ position + ") fetching from shared pool"); |
| 5608 |
} |
| 5609 |
holder = getRecycledViewPool().getRecycledView(type); |
| 5610 |
if (holder != null) { |
| 5611 |
holder.resetInternal(); |
| 5612 |
if (FORCE_INVALIDATE_DISPLAY_LIST) { |
| 5613 |
invalidateDisplayListInt(holder); |
| 5614 |
} |
| 5615 |
} |
| 5616 |
} |
| 5617 |
if (holder == null) { |
| 5618 |
long start = getNanoTime(); |
| 5619 |
if (deadlineNs != FOREVER_NS |
| 5620 |
&& !mRecyclerPool.willCreateInTime(type, start, deadlineNs)) { |
| 5621 |
|
| 5622 |
return null; |
| 5623 |
} |
| 5624 |
holder = mAdapter.createViewHolder(RecyclerView.this, type); |
| 5625 |
if (ALLOW_THREAD_GAP_WORK) { |
| 5626 |
|
| 5627 |
RecyclerView innerView = findNestedRecyclerView(holder.itemView); |
| 5628 |
if (innerView != null) { |
| 5629 |
holder.mNestedRecyclerView = new WeakReference<>(innerView); |
| 5630 |
} |
| 5631 |
} |
| 5632 |
|
| 5633 |
long end = getNanoTime(); |
| 5634 |
mRecyclerPool.factorInCreateTime(type, end - start); |
| 5635 |
if (DEBUG) { |
| 5636 |
Log.d(TAG, "tryGetViewHolderForPositionByDeadline created new ViewHolder"); |
| 5637 |
} |
| 5638 |
} |
| 5639 |
} |
| 5640 |
|
| 5641 |
|
| 5642 |
|
| 5643 |
|
| 5644 |
if (fromScrapOrHiddenOrCache && !mState.isPreLayout() && holder |
| 5645 |
.hasAnyOfTheFlags(ViewHolder.FLAG_BOUNCED_FROM_HIDDEN_LIST)) { |
| 5646 |
holder.setFlags(0, ViewHolder.FLAG_BOUNCED_FROM_HIDDEN_LIST); |
| 5647 |
if (mState.mRunSimpleAnimations) { |
| 5648 |
int changeFlags = ItemAnimator |
| 5649 |
.buildAdapterChangeFlagsForAnimations(holder); |
| 5650 |
changeFlags |= ItemAnimator.FLAG_APPEARED_IN_PRE_LAYOUT; |
| 5651 |
final ItemHolderInfo info = mItemAnimator.recordPreLayoutInformation(mState, |
| 5652 |
holder, changeFlags, holder.getUnmodifiedPayloads()); |
| 5653 |
recordAnimationInfoIfBouncedHiddenView(holder, info); |
| 5654 |
} |
| 5655 |
} |
| 5656 |
|
| 5657 |
boolean bound = false; |
| 5658 |
if (mState.isPreLayout() && holder.isBound()) { |
| 5659 |
|
| 5660 |
holder.mPreLayoutPosition = position; |
| 5661 |
} else if (!holder.isBound() || holder.needsUpdate() || holder.isInvalid()) { |
| 5662 |
if (DEBUG && holder.isRemoved()) { |
| 5663 |
throw new IllegalStateException("Removed holder should be bound and it should" |
| 5664 |
+ " come here only in pre-layout. Holder: " + holder); |
| 5665 |
} |
| 5666 |
final int offsetPosition = mAdapterHelper.findPositionOffset(position); |
| 5667 |
bound = tryBindViewHolderByDeadline(holder, offsetPosition, position, deadlineNs); |
| 5668 |
} |
| 5669 |
|
| 5670 |
final ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); |
| 5671 |
final LayoutParams rvLayoutParams; |
| 5672 |
if (lp == null) { |
| 5673 |
rvLayoutParams = (LayoutParams) generateDefaultLayoutParams(); |
| 5674 |
holder.itemView.setLayoutParams(rvLayoutParams); |
| 5675 |
} else if (!checkLayoutParams(lp)) { |
| 5676 |
rvLayoutParams = (LayoutParams) generateLayoutParams(lp); |
| 5677 |
holder.itemView.setLayoutParams(rvLayoutParams); |
| 5678 |
} else { |
| 5679 |
rvLayoutParams = (LayoutParams) lp; |
| 5680 |
} |
| 5681 |
rvLayoutParams.mViewHolder = holder; |
| 5682 |
rvLayoutParams.mPendingInvalidate = fromScrapOrHiddenOrCache && bound; |
| 5683 |
return holder; |
| 5684 |
} |
| 5685 |
|
| 5686 |
private void attachAccessibilityDelegate(View itemView) { |
| 5687 |
if (isAccessibilityEnabled()) { |
| 5688 |
if (itemView.getImportantForAccessibility() |
| 5689 |
== View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 5690 |
itemView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 5691 |
} |
| 5692 |
|
| 5693 |
if (itemView.getAccessibilityDelegate() == null) { |
| 5694 |
itemView.setAccessibilityDelegate(mAccessibilityDelegate.getItemDelegate()); |
| 5695 |
} |
| 5696 |
} |
| 5697 |
} |
| 5698 |
|
| 5699 |
private void invalidateDisplayListInt(ViewHolder holder) { |
| 5700 |
if (holder.itemView instanceof ViewGroup) { |
| 5701 |
invalidateDisplayListInt((ViewGroup) holder.itemView, false); |
| 5702 |
} |
| 5703 |
} |
| 5704 |
|
| 5705 |
private void invalidateDisplayListInt(ViewGroup viewGroup, boolean invalidateThis) { |
| 5706 |
for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) { |
| 5707 |
final View view = viewGroup.getChildAt(i); |
| 5708 |
if (view instanceof ViewGroup) { |
| 5709 |
invalidateDisplayListInt((ViewGroup) view, true); |
| 5710 |
} |
| 5711 |
} |
| 5712 |
if (!invalidateThis) { |
| 5713 |
return; |
| 5714 |
} |
| 5715 |
|
| 5716 |
if (viewGroup.getVisibility() == View.INVISIBLE) { |
| 5717 |
viewGroup.setVisibility(View.VISIBLE); |
| 5718 |
viewGroup.setVisibility(View.INVISIBLE); |
| 5719 |
} else { |
| 5720 |
final int visibility = viewGroup.getVisibility(); |
| 5721 |
viewGroup.setVisibility(View.INVISIBLE); |
| 5722 |
viewGroup.setVisibility(visibility); |
| 5723 |
} |
| 5724 |
} |
| 5725 |
|
| 5726 |
|
| 5727 |
|
| 5728 |
|
| 5729 |
|
| 5730 |
|
| 5731 |
|
| 5732 |
|
| 5733 |
|
| 5734 |
|
| 5735 |
|
| 5736 |
public void recycleView(View view) { |
| 5737 |
|
| 5738 |
|
| 5739 |
ViewHolder holder = getChildViewHolderInt(view); |
| 5740 |
if (holder.isTmpDetached()) { |
| 5741 |
removeDetachedView(view, false); |
| 5742 |
} |
| 5743 |
if (holder.isScrap()) { |
| 5744 |
holder.unScrap(); |
| 5745 |
} else if (holder.wasReturnedFromScrap()) { |
| 5746 |
holder.clearReturnedFromScrapFlag(); |
| 5747 |
} |
| 5748 |
recycleViewHolderInternal(holder); |
| 5749 |
} |
| 5750 |
|
| 5751 |
|
| 5752 |
|
| 5753 |
|
| 5754 |
|
| 5755 |
|
| 5756 |
void recycleViewInternal(View view) { |
| 5757 |
recycleViewHolderInternal(getChildViewHolderInt(view)); |
| 5758 |
} |
| 5759 |
|
| 5760 |
void recycleAndClearCachedViews() { |
| 5761 |
final int count = mCachedViews.size(); |
| 5762 |
for (int i = count - 1; i >= 0; i--) { |
| 5763 |
recycleCachedViewAt(i); |
| 5764 |
} |
| 5765 |
mCachedViews.clear(); |
| 5766 |
if (ALLOW_THREAD_GAP_WORK) { |
| 5767 |
mPrefetchRegistry.clearPrefetchPositions(); |
| 5768 |
} |
| 5769 |
} |
| 5770 |
|
| 5771 |
|
| 5772 |
|
| 5773 |
|
| 5774 |
|
| 5775 |
|
| 5776 |
|
| 5777 |
|
| 5778 |
|
| 5779 |
|
| 5780 |
|
| 5781 |
|
| 5782 |
void recycleCachedViewAt(int cachedViewIndex) { |
| 5783 |
if (DEBUG) { |
| 5784 |
Log.d(TAG, "Recycling cached view at index " + cachedViewIndex); |
| 5785 |
} |
| 5786 |
ViewHolder viewHolder = mCachedViews.get(cachedViewIndex); |
| 5787 |
if (DEBUG) { |
| 5788 |
Log.d(TAG, "CachedViewHolder to be recycled: " + viewHolder); |
| 5789 |
} |
| 5790 |
addViewHolderToRecycledViewPool(viewHolder, true); |
| 5791 |
mCachedViews.remove(cachedViewIndex); |
| 5792 |
} |
| 5793 |
|
| 5794 |
|
| 5795 |
|
| 5796 |
|
| 5797 |
|
| 5798 |
|
| 5799 |
void recycleViewHolderInternal(ViewHolder holder) { |
| 5800 |
if (holder.isScrap() || holder.itemView.getParent() != null) { |
| 5801 |
throw new IllegalArgumentException( |
| 5802 |
"Scrapped or attached views may not be recycled. isScrap:" |
| 5803 |
+ holder.isScrap() + " isAttached:" |
| 5804 |
+ (holder.itemView.getParent() != null)); |
| 5805 |
} |
| 5806 |
|
| 5807 |
if (holder.isTmpDetached()) { |
| 5808 |
throw new IllegalArgumentException("Tmp detached view should be removed " |
| 5809 |
+ "from RecyclerView before it can be recycled: " + holder); |
| 5810 |
} |
| 5811 |
|
| 5812 |
if (holder.shouldIgnore()) { |
| 5813 |
throw new IllegalArgumentException("Trying to recycle an ignored view holder. You" |
| 5814 |
+ " should first call stopIgnoringView(view) before calling recycle."); |
| 5815 |
} |
| 5816 |
|
| 5817 |
final boolean transientStatePreventsRecycling = holder |
| 5818 |
.doesTransientStatePreventRecycling(); |
| 5819 |
final boolean forceRecycle = mAdapter != null |
| 5820 |
&& transientStatePreventsRecycling |
| 5821 |
&& mAdapter.onFailedToRecycleView(holder); |
| 5822 |
boolean cached = false; |
| 5823 |
boolean recycled = false; |
| 5824 |
if (DEBUG && mCachedViews.contains(holder)) { |
| 5825 |
throw new IllegalArgumentException("cached view received recycle internal? " |
| 5826 |
+ holder); |
| 5827 |
} |
| 5828 |
if (forceRecycle || holder.isRecyclable()) { |
| 5829 |
if (mViewCacheMax > 0 |
| 5830 |
&& !holder.hasAnyOfTheFlags(ViewHolder.FLAG_INVALID |
| 5831 |
| ViewHolder.FLAG_REMOVED |
| 5832 |
| ViewHolder.FLAG_UPDATE |
| 5833 |
| ViewHolder.FLAG_ADAPTER_POSITION_UNKNOWN)) { |
| 5834 |
|
| 5835 |
int cachedViewSize = mCachedViews.size(); |
| 5836 |
if (cachedViewSize >= mViewCacheMax && cachedViewSize > 0) { |
| 5837 |
recycleCachedViewAt(0); |
| 5838 |
cachedViewSize--; |
| 5839 |
} |
| 5840 |
|
| 5841 |
int targetCacheIndex = cachedViewSize; |
| 5842 |
if (ALLOW_THREAD_GAP_WORK |
| 5843 |
&& cachedViewSize > 0 |
| 5844 |
&& !mPrefetchRegistry.lastPrefetchIncludedPosition(holder.mPosition)) { |
| 5845 |
|
| 5846 |
int cacheIndex = cachedViewSize - 1; |
| 5847 |
while (cacheIndex >= 0) { |
| 5848 |
int cachedPos = mCachedViews.get(cacheIndex).mPosition; |
| 5849 |
if (!mPrefetchRegistry.lastPrefetchIncludedPosition(cachedPos)) { |
| 5850 |
break; |
| 5851 |
} |
| 5852 |
cacheIndex--; |
| 5853 |
} |
| 5854 |
targetCacheIndex = cacheIndex + 1; |
| 5855 |
} |
| 5856 |
mCachedViews.add(targetCacheIndex, holder); |
| 5857 |
cached = true; |
| 5858 |
} |
| 5859 |
if (!cached) { |
| 5860 |
addViewHolderToRecycledViewPool(holder, true); |
| 5861 |
recycled = true; |
| 5862 |
} |
| 5863 |
} else { |
| 5864 |
|
| 5865 |
|
| 5866 |
|
| 5867 |
|
| 5868 |
|
| 5869 |
|
| 5870 |
if (DEBUG) { |
| 5871 |
Log.d(TAG, "trying to recycle a non-recycleable holder. Hopefully, it will " |
| 5872 |
+ "re-visit here. We are still removing it from animation lists"); |
| 5873 |
} |
| 5874 |
} |
| 5875 |
|
| 5876 |
|
| 5877 |
mViewInfoStore.removeViewHolder(holder); |
| 5878 |
if (!cached && !recycled && transientStatePreventsRecycling) { |
| 5879 |
holder.mOwnerRecyclerView = null; |
| 5880 |
} |
| 5881 |
} |
| 5882 |
|
| 5883 |
|
| 5884 |
|
| 5885 |
|
| 5886 |
|
| 5887 |
|
| 5888 |
|
| 5889 |
|
| 5890 |
|
| 5891 |
void addViewHolderToRecycledViewPool(ViewHolder holder, boolean dispatchRecycled) { |
| 5892 |
clearNestedRecyclerViewIfNotNested(holder); |
| 5893 |
holder.itemView.setAccessibilityDelegate(null); |
| 5894 |
if (dispatchRecycled) { |
| 5895 |
dispatchViewRecycled(holder); |
| 5896 |
} |
| 5897 |
holder.mOwnerRecyclerView = null; |
| 5898 |
getRecycledViewPool().putRecycledView(holder); |
| 5899 |
} |
| 5900 |
|
| 5901 |
|
| 5902 |
|
| 5903 |
|
| 5904 |
|
| 5905 |
|
| 5906 |
void quickRecycleScrapView(View view) { |
| 5907 |
final ViewHolder holder = getChildViewHolderInt(view); |
| 5908 |
holder.mScrapContainer = null; |
| 5909 |
holder.mInChangeScrap = false; |
| 5910 |
holder.clearReturnedFromScrapFlag(); |
| 5911 |
recycleViewHolderInternal(holder); |
| 5912 |
} |
| 5913 |
|
| 5914 |
|
| 5915 |
|
| 5916 |
|
| 5917 |
|
| 5918 |
|
| 5919 |
|
| 5920 |
|
| 5921 |
|
| 5922 |
|
| 5923 |
void scrapView(View view) { |
| 5924 |
final ViewHolder holder = getChildViewHolderInt(view); |
| 5925 |
if (holder.hasAnyOfTheFlags(ViewHolder.FLAG_REMOVED | ViewHolder.FLAG_INVALID) |
| 5926 |
|| !holder.isUpdated() || canReuseUpdatedViewHolder(holder)) { |
| 5927 |
if (holder.isInvalid() && !holder.isRemoved() && !mAdapter.hasStableIds()) { |
| 5928 |
throw new IllegalArgumentException("Called scrap view with an invalid view." |
| 5929 |
+ " Invalid views cannot be reused from scrap, they should rebound from" |
| 5930 |
+ " recycler pool."); |
| 5931 |
} |
| 5932 |
holder.setScrapContainer(this, false); |
| 5933 |
mAttachedScrap.add(holder); |
| 5934 |
} else { |
| 5935 |
if (mChangedScrap == null) { |
| 5936 |
mChangedScrap = new ArrayList<ViewHolder>(); |
| 5937 |
} |
| 5938 |
holder.setScrapContainer(this, true); |
| 5939 |
mChangedScrap.add(holder); |
| 5940 |
} |
| 5941 |
} |
| 5942 |
|
| 5943 |
|
| 5944 |
|
| 5945 |
|
| 5946 |
|
| 5947 |
|
| 5948 |
|
| 5949 |
void unscrapView(ViewHolder holder) { |
| 5950 |
if (holder.mInChangeScrap) { |
| 5951 |
mChangedScrap.remove(holder); |
| 5952 |
} else { |
| 5953 |
mAttachedScrap.remove(holder); |
| 5954 |
} |
| 5955 |
holder.mScrapContainer = null; |
| 5956 |
holder.mInChangeScrap = false; |
| 5957 |
holder.clearReturnedFromScrapFlag(); |
| 5958 |
} |
| 5959 |
|
| 5960 |
int getScrapCount() { |
| 5961 |
return mAttachedScrap.size(); |
| 5962 |
} |
| 5963 |
|
| 5964 |
View getScrapViewAt(int index) { |
| 5965 |
return mAttachedScrap.get(index).itemView; |
| 5966 |
} |
| 5967 |
|
| 5968 |
void clearScrap() { |
| 5969 |
mAttachedScrap.clear(); |
| 5970 |
if (mChangedScrap != null) { |
| 5971 |
mChangedScrap.clear(); |
| 5972 |
} |
| 5973 |
} |
| 5974 |
|
| 5975 |
ViewHolder getChangedScrapViewForPosition(int position) { |
| 5976 |
|
| 5977 |
final int changedScrapSize; |
| 5978 |
if (mChangedScrap == null || (changedScrapSize = mChangedScrap.size()) == 0) { |
| 5979 |
return null; |
| 5980 |
} |
| 5981 |
|
| 5982 |
for (int i = 0; i < changedScrapSize; i++) { |
| 5983 |
final ViewHolder holder = mChangedScrap.get(i); |
| 5984 |
if (!holder.wasReturnedFromScrap() && holder.getLayoutPosition() == position) { |
| 5985 |
holder.addFlags(ViewHolder.FLAG_RETURNED_FROM_SCRAP); |
| 5986 |
return holder; |
| 5987 |
} |
| 5988 |
} |
| 5989 |
|
| 5990 |
if (mAdapter.hasStableIds()) { |
| 5991 |
final int offsetPosition = mAdapterHelper.findPositionOffset(position); |
| 5992 |
if (offsetPosition > 0 && offsetPosition < mAdapter.getItemCount()) { |
| 5993 |
final long id = mAdapter.getItemId(offsetPosition); |
| 5994 |
for (int i = 0; i < changedScrapSize; i++) { |
| 5995 |
final ViewHolder holder = mChangedScrap.get(i); |
| 5996 |
if (!holder.wasReturnedFromScrap() && holder.getItemId() == id) { |
| 5997 |
holder.addFlags(ViewHolder.FLAG_RETURNED_FROM_SCRAP); |
| 5998 |
return holder; |
| 5999 |
} |
| 6000 |
} |
| 6001 |
} |
| 6002 |
} |
| 6003 |
return null; |
| 6004 |
} |
| 6005 |
|
| 6006 |
|
| 6007 |
|
| 6008 |
|
| 6009 |
|
| 6010 |
|
| 6011 |
|
| 6012 |
|
| 6013 |
ViewHolder getScrapOrHiddenOrCachedHolderForPosition(int position, boolean dryRun) { |
| 6014 |
final int scrapCount = mAttachedScrap.size(); |
| 6015 |
|
| 6016 |
|
| 6017 |
for (int i = 0; i < scrapCount; i++) { |
| 6018 |
final ViewHolder holder = mAttachedScrap.get(i); |
| 6019 |
if (!holder.wasReturnedFromScrap() && holder.getLayoutPosition() == position |
| 6020 |
&& !holder.isInvalid() && (mState.mInPreLayout || !holder.isRemoved())) { |
| 6021 |
holder.addFlags(ViewHolder.FLAG_RETURNED_FROM_SCRAP); |
| 6022 |
return holder; |
| 6023 |
} |
| 6024 |
} |
| 6025 |
|
| 6026 |
if (!dryRun) { |
| 6027 |
View view = mChildHelper.findHiddenNonRemovedView(position); |
| 6028 |
if (view != null) { |
| 6029 |
|
| 6030 |
|
| 6031 |
final ViewHolder vh = getChildViewHolderInt(view); |
| 6032 |
mChildHelper.unhide(view); |
| 6033 |
int layoutIndex = mChildHelper.indexOfChild(view); |
| 6034 |
if (layoutIndex == RecyclerView.NO_POSITION) { |
| 6035 |
throw new IllegalStateException("layout index should not be -1 after " |
| 6036 |
+ "unhiding a view:" + vh); |
| 6037 |
} |
| 6038 |
mChildHelper.detachViewFromParent(layoutIndex); |
| 6039 |
scrapView(view); |
| 6040 |
vh.addFlags(ViewHolder.FLAG_RETURNED_FROM_SCRAP |
| 6041 |
| ViewHolder.FLAG_BOUNCED_FROM_HIDDEN_LIST); |
| 6042 |
return vh; |
| 6043 |
} |
| 6044 |
} |
| 6045 |
|
| 6046 |
|
| 6047 |
final int cacheSize = mCachedViews.size(); |
| 6048 |
for (int i = 0; i < cacheSize; i++) { |
| 6049 |
final ViewHolder holder = mCachedViews.get(i); |
| 6050 |
|
| 6051 |
|
| 6052 |
if (!holder.isInvalid() && holder.getLayoutPosition() == position) { |
| 6053 |
if (!dryRun) { |
| 6054 |
mCachedViews.remove(i); |
| 6055 |
} |
| 6056 |
if (DEBUG) { |
| 6057 |
Log.d(TAG, "getScrapOrHiddenOrCachedHolderForPosition(" + position |
| 6058 |
+ ") found match in cache: " + holder); |
| 6059 |
} |
| 6060 |
return holder; |
| 6061 |
} |
| 6062 |
} |
| 6063 |
return null; |
| 6064 |
} |
| 6065 |
|
| 6066 |
ViewHolder getScrapOrCachedViewForId(long id, int type, boolean dryRun) { |
| 6067 |
|
| 6068 |
final int count = mAttachedScrap.size(); |
| 6069 |
for (int i = count - 1; i >= 0; i--) { |
| 6070 |
final ViewHolder holder = mAttachedScrap.get(i); |
| 6071 |
if (holder.getItemId() == id && !holder.wasReturnedFromScrap()) { |
| 6072 |
if (type == holder.getItemViewType()) { |
| 6073 |
holder.addFlags(ViewHolder.FLAG_RETURNED_FROM_SCRAP); |
| 6074 |
if (holder.isRemoved()) { |
| 6075 |
|
| 6076 |
|
| 6077 |
|
| 6078 |
|
| 6079 |
|
| 6080 |
|
| 6081 |
|
| 6082 |
|
| 6083 |
if (!mState.isPreLayout()) { |
| 6084 |
holder.setFlags(ViewHolder.FLAG_UPDATE, ViewHolder.FLAG_UPDATE |
| 6085 |
| ViewHolder.FLAG_INVALID | ViewHolder.FLAG_REMOVED); |
| 6086 |
} |
| 6087 |
} |
| 6088 |
return holder; |
| 6089 |
} else if (!dryRun) { |
| 6090 |
|
| 6091 |
|
| 6092 |
|
| 6093 |
mAttachedScrap.remove(i); |
| 6094 |
removeDetachedView(holder.itemView, false); |
| 6095 |
quickRecycleScrapView(holder.itemView); |
| 6096 |
} |
| 6097 |
} |
| 6098 |
} |
| 6099 |
|
| 6100 |
|
| 6101 |
final int cacheSize = mCachedViews.size(); |
| 6102 |
for (int i = cacheSize - 1; i >= 0; i--) { |
| 6103 |
final ViewHolder holder = mCachedViews.get(i); |
| 6104 |
if (holder.getItemId() == id) { |
| 6105 |
if (type == holder.getItemViewType()) { |
| 6106 |
if (!dryRun) { |
| 6107 |
mCachedViews.remove(i); |
| 6108 |
} |
| 6109 |
return holder; |
| 6110 |
} else if (!dryRun) { |
| 6111 |
recycleCachedViewAt(i); |
| 6112 |
return null; |
| 6113 |
} |
| 6114 |
} |
| 6115 |
} |
| 6116 |
return null; |
| 6117 |
} |
| 6118 |
|
| 6119 |
void dispatchViewRecycled(ViewHolder holder) { |
| 6120 |
if (mRecyclerListener != null) { |
| 6121 |
mRecyclerListener.onViewRecycled(holder); |
| 6122 |
} |
| 6123 |
if (mAdapter != null) { |
| 6124 |
mAdapter.onViewRecycled(holder); |
| 6125 |
} |
| 6126 |
if (mState != null) { |
| 6127 |
mViewInfoStore.removeViewHolder(holder); |
| 6128 |
} |
| 6129 |
if (DEBUG) Log.d(TAG, "dispatchViewRecycled: " + holder); |
| 6130 |
} |
| 6131 |
|
| 6132 |
void onAdapterChanged(Adapter oldAdapter, Adapter newAdapter, |
| 6133 |
boolean compatibleWithPrevious) { |
| 6134 |
clear(); |
| 6135 |
getRecycledViewPool().onAdapterChanged(oldAdapter, newAdapter, compatibleWithPrevious); |
| 6136 |
} |
| 6137 |
|
| 6138 |
void offsetPositionRecordsForMove(int from, int to) { |
| 6139 |
final int start, end, inBetweenOffset; |
| 6140 |
if (from < to) { |
| 6141 |
start = from; |
| 6142 |
end = to; |
| 6143 |
inBetweenOffset = -1; |
| 6144 |
} else { |
| 6145 |
start = to; |
| 6146 |
end = from; |
| 6147 |
inBetweenOffset = 1; |
| 6148 |
} |
| 6149 |
final int cachedCount = mCachedViews.size(); |
| 6150 |
for (int i = 0; i < cachedCount; i++) { |
| 6151 |
final ViewHolder holder = mCachedViews.get(i); |
| 6152 |
if (holder == null || holder.mPosition < start || holder.mPosition > end) { |
| 6153 |
continue; |
| 6154 |
} |
| 6155 |
if (holder.mPosition == from) { |
| 6156 |
holder.offsetPosition(to - from, false); |
| 6157 |
} else { |
| 6158 |
holder.offsetPosition(inBetweenOffset, false); |
| 6159 |
} |
| 6160 |
if (DEBUG) { |
| 6161 |
Log.d(TAG, "offsetPositionRecordsForMove cached child " + i + " holder " |
| 6162 |
+ holder); |
| 6163 |
} |
| 6164 |
} |
| 6165 |
} |
| 6166 |
|
| 6167 |
void offsetPositionRecordsForInsert(int insertedAt, int count) { |
| 6168 |
final int cachedCount = mCachedViews.size(); |
| 6169 |
for (int i = 0; i < cachedCount; i++) { |
| 6170 |
final ViewHolder holder = mCachedViews.get(i); |
| 6171 |
if (holder != null && holder.mPosition >= insertedAt) { |
| 6172 |
if (DEBUG) { |
| 6173 |
Log.d(TAG, "offsetPositionRecordsForInsert cached " + i + " holder " |
| 6174 |
+ holder + " now at position " + (holder.mPosition + count)); |
| 6175 |
} |
| 6176 |
holder.offsetPosition(count, true); |
| 6177 |
} |
| 6178 |
} |
| 6179 |
} |
| 6180 |
|
| 6181 |
|
| 6182 |
|
| 6183 |
|
| 6184 |
|
| 6185 |
|
| 6186 |
|
| 6187 |
void offsetPositionRecordsForRemove(int removedFrom, int count, boolean applyToPreLayout) { |
| 6188 |
final int removedEnd = removedFrom + count; |
| 6189 |
final int cachedCount = mCachedViews.size(); |
| 6190 |
for (int i = cachedCount - 1; i >= 0; i--) { |
| 6191 |
final ViewHolder holder = mCachedViews.get(i); |
| 6192 |
if (holder != null) { |
| 6193 |
if (holder.mPosition >= removedEnd) { |
| 6194 |
if (DEBUG) { |
| 6195 |
Log.d(TAG, "offsetPositionRecordsForRemove cached " + i |
| 6196 |
+ " holder " + holder + " now at position " |
| 6197 |
+ (holder.mPosition - count)); |
| 6198 |
} |
| 6199 |
holder.offsetPosition(-count, applyToPreLayout); |
| 6200 |
} else if (holder.mPosition >= removedFrom) { |
| 6201 |
|
| 6202 |
holder.addFlags(ViewHolder.FLAG_REMOVED); |
| 6203 |
recycleCachedViewAt(i); |
| 6204 |
} |
| 6205 |
} |
| 6206 |
} |
| 6207 |
} |
| 6208 |
|
| 6209 |
void setViewCacheExtension(ViewCacheExtension extension) { |
| 6210 |
mViewCacheExtension = extension; |
| 6211 |
} |
| 6212 |
|
| 6213 |
void setRecycledViewPool(RecycledViewPool pool) { |
| 6214 |
if (mRecyclerPool != null) { |
| 6215 |
mRecyclerPool.detach(); |
| 6216 |
} |
| 6217 |
mRecyclerPool = pool; |
| 6218 |
if (pool != null) { |
| 6219 |
mRecyclerPool.attach(getAdapter()); |
| 6220 |
} |
| 6221 |
} |
| 6222 |
|
| 6223 |
RecycledViewPool getRecycledViewPool() { |
| 6224 |
if (mRecyclerPool == null) { |
| 6225 |
mRecyclerPool = new RecycledViewPool(); |
| 6226 |
} |
| 6227 |
return mRecyclerPool; |
| 6228 |
} |
| 6229 |
|
| 6230 |
void viewRangeUpdate(int positionStart, int itemCount) { |
| 6231 |
final int positionEnd = positionStart + itemCount; |
| 6232 |
final int cachedCount = mCachedViews.size(); |
| 6233 |
for (int i = cachedCount - 1; i >= 0; i--) { |
| 6234 |
final ViewHolder holder = mCachedViews.get(i); |
| 6235 |
if (holder == null) { |
| 6236 |
continue; |
| 6237 |
} |
| 6238 |
|
| 6239 |
final int pos = holder.getLayoutPosition(); |
| 6240 |
if (pos >= positionStart && pos < positionEnd) { |
| 6241 |
holder.addFlags(ViewHolder.FLAG_UPDATE); |
| 6242 |
recycleCachedViewAt(i); |
| 6243 |
|
| 6244 |
|
| 6245 |
} |
| 6246 |
} |
| 6247 |
} |
| 6248 |
|
| 6249 |
void setAdapterPositionsAsUnknown() { |
| 6250 |
final int cachedCount = mCachedViews.size(); |
| 6251 |
for (int i = 0; i < cachedCount; i++) { |
| 6252 |
final ViewHolder holder = mCachedViews.get(i); |
| 6253 |
if (holder != null) { |
| 6254 |
holder.addFlags(ViewHolder.FLAG_ADAPTER_POSITION_UNKNOWN); |
| 6255 |
} |
| 6256 |
} |
| 6257 |
} |
| 6258 |
|
| 6259 |
void markKnownViewsInvalid() { |
| 6260 |
if (mAdapter != null && mAdapter.hasStableIds()) { |
| 6261 |
final int cachedCount = mCachedViews.size(); |
| 6262 |
for (int i = 0; i < cachedCount; i++) { |
| 6263 |
final ViewHolder holder = mCachedViews.get(i); |
| 6264 |
if (holder != null) { |
| 6265 |
holder.addFlags(ViewHolder.FLAG_UPDATE | ViewHolder.FLAG_INVALID); |
| 6266 |
holder.addChangePayload(null); |
| 6267 |
} |
| 6268 |
} |
| 6269 |
} else { |
| 6270 |
|
| 6271 |
recycleAndClearCachedViews(); |
| 6272 |
} |
| 6273 |
} |
| 6274 |
|
| 6275 |
void clearOldPositions() { |
| 6276 |
final int cachedCount = mCachedViews.size(); |
| 6277 |
for (int i = 0; i < cachedCount; i++) { |
| 6278 |
final ViewHolder holder = mCachedViews.get(i); |
| 6279 |
holder.clearOldPosition(); |
| 6280 |
} |
| 6281 |
final int scrapCount = mAttachedScrap.size(); |
| 6282 |
for (int i = 0; i < scrapCount; i++) { |
| 6283 |
mAttachedScrap.get(i).clearOldPosition(); |
| 6284 |
} |
| 6285 |
if (mChangedScrap != null) { |
| 6286 |
final int changedScrapCount = mChangedScrap.size(); |
| 6287 |
for (int i = 0; i < changedScrapCount; i++) { |
| 6288 |
mChangedScrap.get(i).clearOldPosition(); |
| 6289 |
} |
| 6290 |
} |
| 6291 |
} |
| 6292 |
|
| 6293 |
void markItemDecorInsetsDirty() { |
| 6294 |
final int cachedCount = mCachedViews.size(); |
| 6295 |
for (int i = 0; i < cachedCount; i++) { |
| 6296 |
final ViewHolder holder = mCachedViews.get(i); |
| 6297 |
LayoutParams layoutParams = (LayoutParams) holder.itemView.getLayoutParams(); |
| 6298 |
if (layoutParams != null) { |
| 6299 |
layoutParams.mInsetsDirty = true; |
| 6300 |
} |
| 6301 |
} |
| 6302 |
} |
| 6303 |
} |
| 6304 |
|
| 6305 |
|
| 6306 |
|
| 6307 |
|
| 6308 |
|
| 6309 |
|
| 6310 |
|
| 6311 |
|
| 6312 |
|
| 6313 |
|
| 6314 |
|
| 6315 |
|
| 6316 |
|
| 6317 |
|
| 6318 |
public abstract static class ViewCacheExtension { |
| 6319 |
|
| 6320 |
|
| 6321 |
|
| 6322 |
|
| 6323 |
|
| 6324 |
|
| 6325 |
|
| 6326 |
|
| 6327 |
|
| 6328 |
|
| 6329 |
|
| 6330 |
|
| 6331 |
|
| 6332 |
|
| 6333 |
|
| 6334 |
|
| 6335 |
|
| 6336 |
public abstract View getViewForPositionAndType(Recycler recycler, int position, int type); |
| 6337 |
} |
| 6338 |
|
| 6339 |
|
| 6340 |
|
| 6341 |
|
| 6342 |
|
| 6343 |
|
| 6344 |
|
| 6345 |
|
| 6346 |
|
| 6347 |
public abstract static class Adapter<VH extends ViewHolder> { |
| 6348 |
private final AdapterDataObservable mObservable = new AdapterDataObservable(); |
| 6349 |
private boolean mHasStableIds = false; |
| 6350 |
|
| 6351 |
|
| 6352 |
|
| 6353 |
|
| 6354 |
|
| 6355 |
|
| 6356 |
|
| 6357 |
|
| 6358 |
|
| 6359 |
|
| 6360 |
|
| 6361 |
|
| 6362 |
|
| 6363 |
|
| 6364 |
|
| 6365 |
|
| 6366 |
|
| 6367 |
|
| 6368 |
|
| 6369 |
|
| 6370 |
|
| 6371 |
|
| 6372 |
public abstract VH onCreateViewHolder(ViewGroup parent, int viewType); |
| 6373 |
|
| 6374 |
|
| 6375 |
|
| 6376 |
|
| 6377 |
|
| 6378 |
|
| 6379 |
|
| 6380 |
|
| 6381 |
|
| 6382 |
|
| 6383 |
|
| 6384 |
|
| 6385 |
|
| 6386 |
|
| 6387 |
|
| 6388 |
|
| 6389 |
|
| 6390 |
|
| 6391 |
|
| 6392 |
|
| 6393 |
|
| 6394 |
public abstract void onBindViewHolder(VH holder, int position); |
| 6395 |
|
| 6396 |
|
| 6397 |
|
| 6398 |
|
| 6399 |
|
| 6400 |
|
| 6401 |
|
| 6402 |
|
| 6403 |
|
| 6404 |
|
| 6405 |
|
| 6406 |
|
| 6407 |
|
| 6408 |
|
| 6409 |
|
| 6410 |
|
| 6411 |
|
| 6412 |
|
| 6413 |
|
| 6414 |
|
| 6415 |
|
| 6416 |
|
| 6417 |
|
| 6418 |
|
| 6419 |
|
| 6420 |
|
| 6421 |
|
| 6422 |
|
| 6423 |
|
| 6424 |
|
| 6425 |
public void onBindViewHolder(VH holder, int position, List<Object> payloads) { |
| 6426 |
onBindViewHolder(holder, position); |
| 6427 |
} |
| 6428 |
|
| 6429 |
|
| 6430 |
|
| 6431 |
|
| 6432 |
|
| 6433 |
|
| 6434 |
|
| 6435 |
public final VH createViewHolder(ViewGroup parent, int viewType) { |
| 6436 |
Trace.beginSection(TRACE_CREATE_VIEW_TAG); |
| 6437 |
final VH holder = onCreateViewHolder(parent, viewType); |
| 6438 |
holder.mItemViewType = viewType; |
| 6439 |
Trace.endSection(); |
| 6440 |
return holder; |
| 6441 |
} |
| 6442 |
|
| 6443 |
|
| 6444 |
|
| 6445 |
|
| 6446 |
|
| 6447 |
|
| 6448 |
|
| 6449 |
|
| 6450 |
public final void bindViewHolder(VH holder, int position) { |
| 6451 |
holder.mPosition = position; |
| 6452 |
if (hasStableIds()) { |
| 6453 |
holder.mItemId = getItemId(position); |
| 6454 |
} |
| 6455 |
holder.setFlags(ViewHolder.FLAG_BOUND, |
| 6456 |
ViewHolder.FLAG_BOUND | ViewHolder.FLAG_UPDATE | ViewHolder.FLAG_INVALID |
| 6457 |
| ViewHolder.FLAG_ADAPTER_POSITION_UNKNOWN); |
| 6458 |
Trace.beginSection(TRACE_BIND_VIEW_TAG); |
| 6459 |
onBindViewHolder(holder, position, holder.getUnmodifiedPayloads()); |
| 6460 |
holder.clearPayload(); |
| 6461 |
final ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams(); |
| 6462 |
if (layoutParams instanceof RecyclerView.LayoutParams) { |
| 6463 |
((LayoutParams) layoutParams).mInsetsDirty = true; |
| 6464 |
} |
| 6465 |
Trace.endSection(); |
| 6466 |
} |
| 6467 |
|
| 6468 |
|
| 6469 |
|
| 6470 |
|
| 6471 |
|
| 6472 |
|
| 6473 |
|
| 6474 |
|
| 6475 |
|
| 6476 |
|
| 6477 |
|
| 6478 |
|
| 6479 |
|
| 6480 |
public int getItemViewType(int position) { |
| 6481 |
return 0; |
| 6482 |
} |
| 6483 |
|
| 6484 |
|
| 6485 |
|
| 6486 |
|
| 6487 |
|
| 6488 |
|
| 6489 |
|
| 6490 |
|
| 6491 |
|
| 6492 |
public void setHasStableIds(boolean hasStableIds) { |
| 6493 |
if (hasObservers()) { |
| 6494 |
throw new IllegalStateException("Cannot change whether this adapter has " |
| 6495 |
+ "stable IDs while the adapter has registered observers."); |
| 6496 |
} |
| 6497 |
mHasStableIds = hasStableIds; |
| 6498 |
} |
| 6499 |
|
| 6500 |
|
| 6501 |
|
| 6502 |
|
| 6503 |
|
| 6504 |
|
| 6505 |
|
| 6506 |
|
| 6507 |
|
| 6508 |
public long getItemId(int position) { |
| 6509 |
return NO_ID; |
| 6510 |
} |
| 6511 |
|
| 6512 |
|
| 6513 |
|
| 6514 |
|
| 6515 |
|
| 6516 |
|
| 6517 |
public abstract int getItemCount(); |
| 6518 |
|
| 6519 |
|
| 6520 |
|
| 6521 |
|
| 6522 |
|
| 6523 |
|
| 6524 |
|
| 6525 |
|
| 6526 |
public final boolean hasStableIds() { |
| 6527 |
return mHasStableIds; |
| 6528 |
} |
| 6529 |
|
| 6530 |
|
| 6531 |
|
| 6532 |
|
| 6533 |
|
| 6534 |
|
| 6535 |
|
| 6536 |
|
| 6537 |
|
| 6538 |
|
| 6539 |
|
| 6540 |
|
| 6541 |
|
| 6542 |
|
| 6543 |
|
| 6544 |
|
| 6545 |
|
| 6546 |
|
| 6547 |
public void onViewRecycled(VH holder) { |
| 6548 |
} |
| 6549 |
|
| 6550 |
|
| 6551 |
|
| 6552 |
|
| 6553 |
|
| 6554 |
|
| 6555 |
|
| 6556 |
|
| 6557 |
|
| 6558 |
|
| 6559 |
|
| 6560 |
|
| 6561 |
|
| 6562 |
|
| 6563 |
|
| 6564 |
|
| 6565 |
|
| 6566 |
|
| 6567 |
|
| 6568 |
|
| 6569 |
|
| 6570 |
|
| 6571 |
|
| 6572 |
|
| 6573 |
|
| 6574 |
|
| 6575 |
|
| 6576 |
|
| 6577 |
|
| 6578 |
|
| 6579 |
|
| 6580 |
|
| 6581 |
|
| 6582 |
|
| 6583 |
|
| 6584 |
public boolean onFailedToRecycleView(VH holder) { |
| 6585 |
return false; |
| 6586 |
} |
| 6587 |
|
| 6588 |
|
| 6589 |
|
| 6590 |
|
| 6591 |
|
| 6592 |
|
| 6593 |
|
| 6594 |
|
| 6595 |
|
| 6596 |
|
| 6597 |
|
| 6598 |
public void onViewAttachedToWindow(VH holder) { |
| 6599 |
} |
| 6600 |
|
| 6601 |
|
| 6602 |
|
| 6603 |
|
| 6604 |
|
| 6605 |
|
| 6606 |
|
| 6607 |
|
| 6608 |
|
| 6609 |
|
| 6610 |
public void onViewDetachedFromWindow(VH holder) { |
| 6611 |
} |
| 6612 |
|
| 6613 |
|
| 6614 |
|
| 6615 |
|
| 6616 |
|
| 6617 |
|
| 6618 |
public final boolean hasObservers() { |
| 6619 |
return mObservable.hasObservers(); |
| 6620 |
} |
| 6621 |
|
| 6622 |
|
| 6623 |
|
| 6624 |
|
| 6625 |
|
| 6626 |
|
| 6627 |
|
| 6628 |
|
| 6629 |
|
| 6630 |
|
| 6631 |
|
| 6632 |
|
| 6633 |
|
| 6634 |
|
| 6635 |
|
| 6636 |
|
| 6637 |
|
| 6638 |
public void registerAdapterDataObserver(AdapterDataObserver observer) { |
| 6639 |
mObservable.registerObserver(observer); |
| 6640 |
} |
| 6641 |
|
| 6642 |
|
| 6643 |
|
| 6644 |
|
| 6645 |
|
| 6646 |
|
| 6647 |
|
| 6648 |
|
| 6649 |
|
| 6650 |
|
| 6651 |
|
| 6652 |
public void unregisterAdapterDataObserver(AdapterDataObserver observer) { |
| 6653 |
mObservable.unregisterObserver(observer); |
| 6654 |
} |
| 6655 |
|
| 6656 |
|
| 6657 |
|
| 6658 |
|
| 6659 |
|
| 6660 |
|
| 6661 |
|
| 6662 |
|
| 6663 |
|
| 6664 |
public void onAttachedToRecyclerView(RecyclerView recyclerView) { |
| 6665 |
} |
| 6666 |
|
| 6667 |
|
| 6668 |
|
| 6669 |
|
| 6670 |
|
| 6671 |
|
| 6672 |
|
| 6673 |
public void onDetachedFromRecyclerView(RecyclerView recyclerView) { |
| 6674 |
} |
| 6675 |
|
| 6676 |
|
| 6677 |
|
| 6678 |
|
| 6679 |
|
| 6680 |
|
| 6681 |
|
| 6682 |
|
| 6683 |
|
| 6684 |
|
| 6685 |
|
| 6686 |
|
| 6687 |
|
| 6688 |
|
| 6689 |
|
| 6690 |
|
| 6691 |
|
| 6692 |
|
| 6693 |
|
| 6694 |
|
| 6695 |
|
| 6696 |
|
| 6697 |
|
| 6698 |
|
| 6699 |
|
| 6700 |
|
| 6701 |
|
| 6702 |
|
| 6703 |
|
| 6704 |
|
| 6705 |
public final void notifyDataSetChanged() { |
| 6706 |
mObservable.notifyChanged(); |
| 6707 |
} |
| 6708 |
|
| 6709 |
|
| 6710 |
|
| 6711 |
|
| 6712 |
|
| 6713 |
|
| 6714 |
|
| 6715 |
|
| 6716 |
|
| 6717 |
|
| 6718 |
|
| 6719 |
|
| 6720 |
|
| 6721 |
public final void notifyItemChanged(int position) { |
| 6722 |
mObservable.notifyItemRangeChanged(position, 1); |
| 6723 |
} |
| 6724 |
|
| 6725 |
|
| 6726 |
|
| 6727 |
|
| 6728 |
|
| 6729 |
|
| 6730 |
|
| 6731 |
|
| 6732 |
|
| 6733 |
|
| 6734 |
|
| 6735 |
|
| 6736 |
|
| 6737 |
|
| 6738 |
|
| 6739 |
|
| 6740 |
|
| 6741 |
|
| 6742 |
|
| 6743 |
|
| 6744 |
|
| 6745 |
|
| 6746 |
|
| 6747 |
|
| 6748 |
|
| 6749 |
public final void notifyItemChanged(int position, Object payload) { |
| 6750 |
mObservable.notifyItemRangeChanged(position, 1, payload); |
| 6751 |
} |
| 6752 |
|
| 6753 |
|
| 6754 |
|
| 6755 |
|
| 6756 |
|
| 6757 |
|
| 6758 |
|
| 6759 |
|
| 6760 |
|
| 6761 |
|
| 6762 |
|
| 6763 |
|
| 6764 |
|
| 6765 |
|
| 6766 |
|
| 6767 |
public final void notifyItemRangeChanged(int positionStart, int itemCount) { |
| 6768 |
mObservable.notifyItemRangeChanged(positionStart, itemCount); |
| 6769 |
} |
| 6770 |
|
| 6771 |
|
| 6772 |
|
| 6773 |
|
| 6774 |
|
| 6775 |
|
| 6776 |
|
| 6777 |
|
| 6778 |
|
| 6779 |
|
| 6780 |
|
| 6781 |
|
| 6782 |
|
| 6783 |
|
| 6784 |
|
| 6785 |
|
| 6786 |
|
| 6787 |
|
| 6788 |
|
| 6789 |
|
| 6790 |
|
| 6791 |
|
| 6792 |
|
| 6793 |
|
| 6794 |
|
| 6795 |
|
| 6796 |
|
| 6797 |
public final void notifyItemRangeChanged(int positionStart, int itemCount, Object payload) { |
| 6798 |
mObservable.notifyItemRangeChanged(positionStart, itemCount, payload); |
| 6799 |
} |
| 6800 |
|
| 6801 |
|
| 6802 |
|
| 6803 |
|
| 6804 |
|
| 6805 |
|
| 6806 |
|
| 6807 |
|
| 6808 |
|
| 6809 |
|
| 6810 |
|
| 6811 |
|
| 6812 |
|
| 6813 |
|
| 6814 |
public final void notifyItemInserted(int position) { |
| 6815 |
mObservable.notifyItemRangeInserted(position, 1); |
| 6816 |
} |
| 6817 |
|
| 6818 |
|
| 6819 |
|
| 6820 |
|
| 6821 |
|
| 6822 |
|
| 6823 |
|
| 6824 |
|
| 6825 |
|
| 6826 |
|
| 6827 |
|
| 6828 |
|
| 6829 |
public final void notifyItemMoved(int fromPosition, int toPosition) { |
| 6830 |
mObservable.notifyItemMoved(fromPosition, toPosition); |
| 6831 |
} |
| 6832 |
|
| 6833 |
|
| 6834 |
|
| 6835 |
|
| 6836 |
|
| 6837 |
|
| 6838 |
|
| 6839 |
|
| 6840 |
|
| 6841 |
|
| 6842 |
|
| 6843 |
|
| 6844 |
|
| 6845 |
|
| 6846 |
|
| 6847 |
|
| 6848 |
public final void notifyItemRangeInserted(int positionStart, int itemCount) { |
| 6849 |
mObservable.notifyItemRangeInserted(positionStart, itemCount); |
| 6850 |
} |
| 6851 |
|
| 6852 |
|
| 6853 |
|
| 6854 |
|
| 6855 |
|
| 6856 |
|
| 6857 |
|
| 6858 |
|
| 6859 |
|
| 6860 |
|
| 6861 |
|
| 6862 |
|
| 6863 |
|
| 6864 |
|
| 6865 |
public final void notifyItemRemoved(int position) { |
| 6866 |
mObservable.notifyItemRangeRemoved(position, 1); |
| 6867 |
} |
| 6868 |
|
| 6869 |
|
| 6870 |
|
| 6871 |
|
| 6872 |
|
| 6873 |
|
| 6874 |
|
| 6875 |
|
| 6876 |
|
| 6877 |
|
| 6878 |
|
| 6879 |
|
| 6880 |
|
| 6881 |
|
| 6882 |
public final void notifyItemRangeRemoved(int positionStart, int itemCount) { |
| 6883 |
mObservable.notifyItemRangeRemoved(positionStart, itemCount); |
| 6884 |
} |
| 6885 |
} |
| 6886 |
|
| 6887 |
void dispatchChildDetached(View child) { |
| 6888 |
final ViewHolder viewHolder = getChildViewHolderInt(child); |
| 6889 |
onChildDetachedFromWindow(child); |
| 6890 |
if (mAdapter != null && viewHolder != null) { |
| 6891 |
mAdapter.onViewDetachedFromWindow(viewHolder); |
| 6892 |
} |
| 6893 |
if (mOnChildAttachStateListeners != null) { |
| 6894 |
final int cnt = mOnChildAttachStateListeners.size(); |
| 6895 |
for (int i = cnt - 1; i >= 0; i--) { |
| 6896 |
mOnChildAttachStateListeners.get(i).onChildViewDetachedFromWindow(child); |
| 6897 |
} |
| 6898 |
} |
| 6899 |
} |
| 6900 |
|
| 6901 |
void dispatchChildAttached(View child) { |
| 6902 |
final ViewHolder viewHolder = getChildViewHolderInt(child); |
| 6903 |
onChildAttachedToWindow(child); |
| 6904 |
if (mAdapter != null && viewHolder != null) { |
| 6905 |
mAdapter.onViewAttachedToWindow(viewHolder); |
| 6906 |
} |
| 6907 |
if (mOnChildAttachStateListeners != null) { |
| 6908 |
final int cnt = mOnChildAttachStateListeners.size(); |
| 6909 |
for (int i = cnt - 1; i >= 0; i--) { |
| 6910 |
mOnChildAttachStateListeners.get(i).onChildViewAttachedToWindow(child); |
| 6911 |
} |
| 6912 |
} |
| 6913 |
} |
| 6914 |
|
| 6915 |
|
| 6916 |
|
| 6917 |
|
| 6918 |
|
| 6919 |
|
| 6920 |
|
| 6921 |
|
| 6922 |
|
| 6923 |
|
| 6924 |
|
| 6925 |
|
| 6926 |
|
| 6927 |
|
| 6928 |
|
| 6929 |
|
| 6930 |
|
| 6931 |
public abstract static class LayoutManager { |
| 6932 |
ChildHelper mChildHelper; |
| 6933 |
RecyclerView mRecyclerView; |
| 6934 |
|
| 6935 |
@Nullable |
| 6936 |
SmoothScroller mSmoothScroller; |
| 6937 |
|
| 6938 |
boolean mRequestedSimpleAnimations = false; |
| 6939 |
|
| 6940 |
boolean mIsAttachedToWindow = false; |
| 6941 |
|
| 6942 |
boolean mAutoMeasure = false; |
| 6943 |
|
| 6944 |
|
| 6945 |
|
| 6946 |
|
| 6947 |
|
| 6948 |
private boolean mMeasurementCacheEnabled = true; |
| 6949 |
|
| 6950 |
private boolean mItemPrefetchEnabled = true; |
| 6951 |
|
| 6952 |
|
| 6953 |
|
| 6954 |
|
| 6955 |
|
| 6956 |
|
| 6957 |
|
| 6958 |
|
| 6959 |
|
| 6960 |
|
| 6961 |
int mPrefetchMaxCountObserved; |
| 6962 |
|
| 6963 |
|
| 6964 |
|
| 6965 |
|
| 6966 |
boolean mPrefetchMaxObservedInInitialPrefetch; |
| 6967 |
|
| 6968 |
|
| 6969 |
|
| 6970 |
|
| 6971 |
|
| 6972 |
|
| 6973 |
|
| 6974 |
|
| 6975 |
|
| 6976 |
|
| 6977 |
|
| 6978 |
|
| 6979 |
private int mWidthMode, mHeightMode; |
| 6980 |
private int mWidth, mHeight; |
| 6981 |
|
| 6982 |
|
| 6983 |
|
| 6984 |
|
| 6985 |
|
| 6986 |
|
| 6987 |
|
| 6988 |
|
| 6989 |
|
| 6990 |
public interface LayoutPrefetchRegistry { |
| 6991 |
|
| 6992 |
|
| 6993 |
|
| 6994 |
|
| 6995 |
|
| 6996 |
|
| 6997 |
|
| 6998 |
|
| 6999 |
void addPosition(int layoutPosition, int pixelDistance); |
| 7000 |
} |
| 7001 |
|
| 7002 |
void setRecyclerView(RecyclerView recyclerView) { |
| 7003 |
if (recyclerView == null) { |
| 7004 |
mRecyclerView = null; |
| 7005 |
mChildHelper = null; |
| 7006 |
mWidth = 0; |
| 7007 |
mHeight = 0; |
| 7008 |
} else { |
| 7009 |
mRecyclerView = recyclerView; |
| 7010 |
mChildHelper = recyclerView.mChildHelper; |
| 7011 |
mWidth = recyclerView.getWidth(); |
| 7012 |
mHeight = recyclerView.getHeight(); |
| 7013 |
} |
| 7014 |
mWidthMode = MeasureSpec.EXACTLY; |
| 7015 |
mHeightMode = MeasureSpec.EXACTLY; |
| 7016 |
} |
| 7017 |
|
| 7018 |
void setMeasureSpecs(int wSpec, int hSpec) { |
| 7019 |
mWidth = MeasureSpec.getSize(wSpec); |
| 7020 |
mWidthMode = MeasureSpec.getMode(wSpec); |
| 7021 |
if (mWidthMode == MeasureSpec.UNSPECIFIED && !ALLOW_SIZE_IN_UNSPECIFIED_SPEC) { |
| 7022 |
mWidth = 0; |
| 7023 |
} |
| 7024 |
|
| 7025 |
mHeight = MeasureSpec.getSize(hSpec); |
| 7026 |
mHeightMode = MeasureSpec.getMode(hSpec); |
| 7027 |
if (mHeightMode == MeasureSpec.UNSPECIFIED && !ALLOW_SIZE_IN_UNSPECIFIED_SPEC) { |
| 7028 |
mHeight = 0; |
| 7029 |
} |
| 7030 |
} |
| 7031 |
|
| 7032 |
|
| 7033 |
|
| 7034 |
|
| 7035 |
|
| 7036 |
|
| 7037 |
|
| 7038 |
|
| 7039 |
|
| 7040 |
|
| 7041 |
|
| 7042 |
|
| 7043 |
|
| 7044 |
|
| 7045 |
void setMeasuredDimensionFromChildren(int widthSpec, int heightSpec) { |
| 7046 |
final int count = getChildCount(); |
| 7047 |
if (count == 0) { |
| 7048 |
mRecyclerView.defaultOnMeasure(widthSpec, heightSpec); |
| 7049 |
return; |
| 7050 |
} |
| 7051 |
int minX = Integer.MAX_VALUE; |
| 7052 |
int minY = Integer.MAX_VALUE; |
| 7053 |
int maxX = Integer.MIN_VALUE; |
| 7054 |
int maxY = Integer.MIN_VALUE; |
| 7055 |
|
| 7056 |
for (int i = 0; i < count; i++) { |
| 7057 |
View child = getChildAt(i); |
| 7058 |
final Rect bounds = mRecyclerView.mTempRect; |
| 7059 |
getDecoratedBoundsWithMargins(child, bounds); |
| 7060 |
if (bounds.left < minX) { |
| 7061 |
minX = bounds.left; |
| 7062 |
} |
| 7063 |
if (bounds.right > maxX) { |
| 7064 |
maxX = bounds.right; |
| 7065 |
} |
| 7066 |
if (bounds.top < minY) { |
| 7067 |
minY = bounds.top; |
| 7068 |
} |
| 7069 |
if (bounds.bottom > maxY) { |
| 7070 |
maxY = bounds.bottom; |
| 7071 |
} |
| 7072 |
} |
| 7073 |
mRecyclerView.mTempRect.set(minX, minY, maxX, maxY); |
| 7074 |
setMeasuredDimension(mRecyclerView.mTempRect, widthSpec, heightSpec); |
| 7075 |
} |
| 7076 |
|
| 7077 |
|
| 7078 |
|
| 7079 |
|
| 7080 |
|
| 7081 |
|
| 7082 |
|
| 7083 |
|
| 7084 |
|
| 7085 |
|
| 7086 |
|
| 7087 |
|
| 7088 |
|
| 7089 |
|
| 7090 |
|
| 7091 |
|
| 7092 |
|
| 7093 |
|
| 7094 |
|
| 7095 |
|
| 7096 |
public void setMeasuredDimension(Rect childrenBounds, int wSpec, int hSpec) { |
| 7097 |
int usedWidth = childrenBounds.width() + getPaddingLeft() + getPaddingRight(); |
| 7098 |
int usedHeight = childrenBounds.height() + getPaddingTop() + getPaddingBottom(); |
| 7099 |
int width = chooseSize(wSpec, usedWidth, getMinimumWidth()); |
| 7100 |
int height = chooseSize(hSpec, usedHeight, getMinimumHeight()); |
| 7101 |
setMeasuredDimension(width, height); |
| 7102 |
} |
| 7103 |
|
| 7104 |
|
| 7105 |
|
| 7106 |
|
| 7107 |
public void requestLayout() { |
| 7108 |
if (mRecyclerView != null) { |
| 7109 |
mRecyclerView.requestLayout(); |
| 7110 |
} |
| 7111 |
} |
| 7112 |
|
| 7113 |
|
| 7114 |
|
| 7115 |
|
| 7116 |
|
| 7117 |
|
| 7118 |
|
| 7119 |
|
| 7120 |
public void assertInLayoutOrScroll(String message) { |
| 7121 |
if (mRecyclerView != null) { |
| 7122 |
mRecyclerView.assertInLayoutOrScroll(message); |
| 7123 |
} |
| 7124 |
} |
| 7125 |
|
| 7126 |
|
| 7127 |
|
| 7128 |
|
| 7129 |
|
| 7130 |
|
| 7131 |
|
| 7132 |
|
| 7133 |
|
| 7134 |
|
| 7135 |
|
| 7136 |
public static int chooseSize(int spec, int desired, int min) { |
| 7137 |
final int mode = View.MeasureSpec.getMode(spec); |
| 7138 |
final int size = View.MeasureSpec.getSize(spec); |
| 7139 |
switch (mode) { |
| 7140 |
case View.MeasureSpec.EXACTLY: |
| 7141 |
return size; |
| 7142 |
case View.MeasureSpec.AT_MOST: |
| 7143 |
return Math.min(size, Math.max(desired, min)); |
| 7144 |
case View.MeasureSpec.UNSPECIFIED: |
| 7145 |
default: |
| 7146 |
return Math.max(desired, min); |
| 7147 |
} |
| 7148 |
} |
| 7149 |
|
| 7150 |
|
| 7151 |
|
| 7152 |
|
| 7153 |
|
| 7154 |
|
| 7155 |
|
| 7156 |
|
| 7157 |
public void assertNotInLayoutOrScroll(String message) { |
| 7158 |
if (mRecyclerView != null) { |
| 7159 |
mRecyclerView.assertNotInLayoutOrScroll(message); |
| 7160 |
} |
| 7161 |
} |
| 7162 |
|
| 7163 |
|
| 7164 |
|
| 7165 |
|
| 7166 |
|
| 7167 |
|
| 7168 |
|
| 7169 |
|
| 7170 |
|
| 7171 |
|
| 7172 |
|
| 7173 |
|
| 7174 |
|
| 7175 |
|
| 7176 |
|
| 7177 |
|
| 7178 |
|
| 7179 |
|
| 7180 |
|
| 7181 |
|
| 7182 |
|
| 7183 |
|
| 7184 |
|
| 7185 |
|
| 7186 |
|
| 7187 |
|
| 7188 |
|
| 7189 |
|
| 7190 |
|
| 7191 |
|
| 7192 |
|
| 7193 |
|
| 7194 |
|
| 7195 |
|
| 7196 |
|
| 7197 |
|
| 7198 |
|
| 7199 |
|
| 7200 |
|
| 7201 |
|
| 7202 |
|
| 7203 |
|
| 7204 |
|
| 7205 |
|
| 7206 |
|
| 7207 |
|
| 7208 |
|
| 7209 |
|
| 7210 |
|
| 7211 |
|
| 7212 |
|
| 7213 |
|
| 7214 |
|
| 7215 |
|
| 7216 |
|
| 7217 |
|
| 7218 |
|
| 7219 |
|
| 7220 |
|
| 7221 |
|
| 7222 |
|
| 7223 |
|
| 7224 |
|
| 7225 |
|
| 7226 |
|
| 7227 |
public void setAutoMeasureEnabled(boolean enabled) { |
| 7228 |
mAutoMeasure = enabled; |
| 7229 |
} |
| 7230 |
|
| 7231 |
|
| 7232 |
|
| 7233 |
|
| 7234 |
|
| 7235 |
|
| 7236 |
|
| 7237 |
|
| 7238 |
|
| 7239 |
public boolean isAutoMeasureEnabled() { |
| 7240 |
return mAutoMeasure; |
| 7241 |
} |
| 7242 |
|
| 7243 |
|
| 7244 |
|
| 7245 |
|
| 7246 |
|
| 7247 |
|
| 7248 |
|
| 7249 |
|
| 7250 |
|
| 7251 |
|
| 7252 |
|
| 7253 |
|
| 7254 |
|
| 7255 |
|
| 7256 |
|
| 7257 |
|
| 7258 |
|
| 7259 |
|
| 7260 |
|
| 7261 |
|
| 7262 |
|
| 7263 |
public boolean supportsPredictiveItemAnimations() { |
| 7264 |
return false; |
| 7265 |
} |
| 7266 |
|
| 7267 |
|
| 7268 |
|
| 7269 |
|
| 7270 |
|
| 7271 |
|
| 7272 |
|
| 7273 |
|
| 7274 |
|
| 7275 |
|
| 7276 |
|
| 7277 |
|
| 7278 |
|
| 7279 |
|
| 7280 |
|
| 7281 |
|
| 7282 |
|
| 7283 |
|
| 7284 |
|
| 7285 |
|
| 7286 |
public final void setItemPrefetchEnabled(boolean enabled) { |
| 7287 |
if (enabled != mItemPrefetchEnabled) { |
| 7288 |
mItemPrefetchEnabled = enabled; |
| 7289 |
mPrefetchMaxCountObserved = 0; |
| 7290 |
if (mRecyclerView != null) { |
| 7291 |
mRecyclerView.mRecycler.updateViewCacheSize(); |
| 7292 |
} |
| 7293 |
} |
| 7294 |
} |
| 7295 |
|
| 7296 |
|
| 7297 |
|
| 7298 |
|
| 7299 |
|
| 7300 |
|
| 7301 |
|
| 7302 |
|
| 7303 |
|
| 7304 |
public final boolean isItemPrefetchEnabled() { |
| 7305 |
return mItemPrefetchEnabled; |
| 7306 |
} |
| 7307 |
|
| 7308 |
|
| 7309 |
|
| 7310 |
|
| 7311 |
|
| 7312 |
|
| 7313 |
|
| 7314 |
|
| 7315 |
|
| 7316 |
|
| 7317 |
|
| 7318 |
|
| 7319 |
|
| 7320 |
|
| 7321 |
|
| 7322 |
|
| 7323 |
|
| 7324 |
|
| 7325 |
|
| 7326 |
|
| 7327 |
|
| 7328 |
public void collectAdjacentPrefetchPositions(int dx, int dy, State state, |
| 7329 |
LayoutPrefetchRegistry layoutPrefetchRegistry) {} |
| 7330 |
|
| 7331 |
|
| 7332 |
|
| 7333 |
|
| 7334 |
|
| 7335 |
|
| 7336 |
|
| 7337 |
|
| 7338 |
|
| 7339 |
|
| 7340 |
|
| 7341 |
|
| 7342 |
|
| 7343 |
|
| 7344 |
|
| 7345 |
|
| 7346 |
|
| 7347 |
|
| 7348 |
|
| 7349 |
|
| 7350 |
|
| 7351 |
|
| 7352 |
|
| 7353 |
|
| 7354 |
|
| 7355 |
|
| 7356 |
public void collectInitialPrefetchPositions(int adapterItemCount, |
| 7357 |
LayoutPrefetchRegistry layoutPrefetchRegistry) {} |
| 7358 |
|
| 7359 |
void dispatchAttachedToWindow(RecyclerView view) { |
| 7360 |
mIsAttachedToWindow = true; |
| 7361 |
onAttachedToWindow(view); |
| 7362 |
} |
| 7363 |
|
| 7364 |
void dispatchDetachedFromWindow(RecyclerView view, Recycler recycler) { |
| 7365 |
mIsAttachedToWindow = false; |
| 7366 |
onDetachedFromWindow(view, recycler); |
| 7367 |
} |
| 7368 |
|
| 7369 |
|
| 7370 |
|
| 7371 |
|
| 7372 |
|
| 7373 |
|
| 7374 |
|
| 7375 |
|
| 7376 |
public boolean isAttachedToWindow() { |
| 7377 |
return mIsAttachedToWindow; |
| 7378 |
} |
| 7379 |
|
| 7380 |
|
| 7381 |
|
| 7382 |
|
| 7383 |
|
| 7384 |
|
| 7385 |
|
| 7386 |
|
| 7387 |
|
| 7388 |
|
| 7389 |
|
| 7390 |
public void postOnAnimation(Runnable action) { |
| 7391 |
if (mRecyclerView != null) { |
| 7392 |
mRecyclerView.postOnAnimation(action); |
| 7393 |
} |
| 7394 |
} |
| 7395 |
|
| 7396 |
|
| 7397 |
|
| 7398 |
|
| 7399 |
|
| 7400 |
|
| 7401 |
|
| 7402 |
|
| 7403 |
|
| 7404 |
|
| 7405 |
|
| 7406 |
|
| 7407 |
|
| 7408 |
|
| 7409 |
|
| 7410 |
public boolean removeCallbacks(Runnable action) { |
| 7411 |
if (mRecyclerView != null) { |
| 7412 |
return mRecyclerView.removeCallbacks(action); |
| 7413 |
} |
| 7414 |
return false; |
| 7415 |
} |
| 7416 |
|
| 7417 |
|
| 7418 |
|
| 7419 |
|
| 7420 |
|
| 7421 |
|
| 7422 |
|
| 7423 |
|
| 7424 |
|
| 7425 |
|
| 7426 |
|
| 7427 |
|
| 7428 |
|
| 7429 |
|
| 7430 |
@CallSuper |
| 7431 |
public void onAttachedToWindow(RecyclerView view) { |
| 7432 |
} |
| 7433 |
|
| 7434 |
|
| 7435 |
|
| 7436 |
|
| 7437 |
|
| 7438 |
@Deprecated |
| 7439 |
public void onDetachedFromWindow(RecyclerView view) { |
| 7440 |
|
| 7441 |
} |
| 7442 |
|
| 7443 |
|
| 7444 |
|
| 7445 |
|
| 7446 |
|
| 7447 |
|
| 7448 |
|
| 7449 |
|
| 7450 |
|
| 7451 |
|
| 7452 |
|
| 7453 |
|
| 7454 |
|
| 7455 |
|
| 7456 |
|
| 7457 |
|
| 7458 |
|
| 7459 |
|
| 7460 |
|
| 7461 |
|
| 7462 |
|
| 7463 |
|
| 7464 |
|
| 7465 |
|
| 7466 |
@CallSuper |
| 7467 |
public void onDetachedFromWindow(RecyclerView view, Recycler recycler) { |
| 7468 |
onDetachedFromWindow(view); |
| 7469 |
} |
| 7470 |
|
| 7471 |
|
| 7472 |
|
| 7473 |
|
| 7474 |
|
| 7475 |
|
| 7476 |
public boolean getClipToPadding() { |
| 7477 |
return mRecyclerView != null && mRecyclerView.mClipToPadding; |
| 7478 |
} |
| 7479 |
|
| 7480 |
|
| 7481 |
|
| 7482 |
|
| 7483 |
|
| 7484 |
|
| 7485 |
|
| 7486 |
|
| 7487 |
|
| 7488 |
|
| 7489 |
|
| 7490 |
|
| 7491 |
|
| 7492 |
|
| 7493 |
|
| 7494 |
|
| 7495 |
|
| 7496 |
|
| 7497 |
|
| 7498 |
|
| 7499 |
|
| 7500 |
|
| 7501 |
|
| 7502 |
|
| 7503 |
|
| 7504 |
|
| 7505 |
|
| 7506 |
|
| 7507 |
|
| 7508 |
|
| 7509 |
|
| 7510 |
|
| 7511 |
|
| 7512 |
|
| 7513 |
|
| 7514 |
|
| 7515 |
|
| 7516 |
|
| 7517 |
|
| 7518 |
|
| 7519 |
|
| 7520 |
|
| 7521 |
|
| 7522 |
|
| 7523 |
|
| 7524 |
|
| 7525 |
|
| 7526 |
|
| 7527 |
|
| 7528 |
|
| 7529 |
|
| 7530 |
|
| 7531 |
public void onLayoutChildren(Recycler recycler, State state) { |
| 7532 |
Log.e(TAG, "You must override onLayoutChildren(Recycler recycler, State state) "); |
| 7533 |
} |
| 7534 |
|
| 7535 |
|
| 7536 |
|
| 7537 |
|
| 7538 |
|
| 7539 |
|
| 7540 |
|
| 7541 |
|
| 7542 |
|
| 7543 |
|
| 7544 |
|
| 7545 |
|
| 7546 |
public void onLayoutCompleted(State state) { |
| 7547 |
} |
| 7548 |
|
| 7549 |
|
| 7550 |
|
| 7551 |
|
| 7552 |
|
| 7553 |
|
| 7554 |
|
| 7555 |
|
| 7556 |
|
| 7557 |
|
| 7558 |
|
| 7559 |
|
| 7560 |
|
| 7561 |
|
| 7562 |
|
| 7563 |
|
| 7564 |
public abstract LayoutParams generateDefaultLayoutParams(); |
| 7565 |
|
| 7566 |
|
| 7567 |
|
| 7568 |
|
| 7569 |
|
| 7570 |
|
| 7571 |
|
| 7572 |
|
| 7573 |
|
| 7574 |
|
| 7575 |
|
| 7576 |
public boolean checkLayoutParams(LayoutParams lp) { |
| 7577 |
return lp != null; |
| 7578 |
} |
| 7579 |
|
| 7580 |
|
| 7581 |
|
| 7582 |
|
| 7583 |
|
| 7584 |
|
| 7585 |
|
| 7586 |
|
| 7587 |
|
| 7588 |
|
| 7589 |
|
| 7590 |
|
| 7591 |
|
| 7592 |
|
| 7593 |
public LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) { |
| 7594 |
if (lp instanceof LayoutParams) { |
| 7595 |
return new LayoutParams((LayoutParams) lp); |
| 7596 |
} else if (lp instanceof MarginLayoutParams) { |
| 7597 |
return new LayoutParams((MarginLayoutParams) lp); |
| 7598 |
} else { |
| 7599 |
return new LayoutParams(lp); |
| 7600 |
} |
| 7601 |
} |
| 7602 |
|
| 7603 |
|
| 7604 |
|
| 7605 |
|
| 7606 |
|
| 7607 |
|
| 7608 |
|
| 7609 |
|
| 7610 |
|
| 7611 |
|
| 7612 |
|
| 7613 |
|
| 7614 |
|
| 7615 |
|
| 7616 |
|
| 7617 |
public LayoutParams generateLayoutParams(Context c, AttributeSet attrs) { |
| 7618 |
return new LayoutParams(c, attrs); |
| 7619 |
} |
| 7620 |
|
| 7621 |
|
| 7622 |
|
| 7623 |
|
| 7624 |
|
| 7625 |
|
| 7626 |
|
| 7627 |
|
| 7628 |
|
| 7629 |
|
| 7630 |
|
| 7631 |
|
| 7632 |
|
| 7633 |
|
| 7634 |
public int scrollHorizontallyBy(int dx, Recycler recycler, State state) { |
| 7635 |
return 0; |
| 7636 |
} |
| 7637 |
|
| 7638 |
|
| 7639 |
|
| 7640 |
|
| 7641 |
|
| 7642 |
|
| 7643 |
|
| 7644 |
|
| 7645 |
|
| 7646 |
|
| 7647 |
|
| 7648 |
|
| 7649 |
|
| 7650 |
|
| 7651 |
public int scrollVerticallyBy(int dy, Recycler recycler, State state) { |
| 7652 |
return 0; |
| 7653 |
} |
| 7654 |
|
| 7655 |
|
| 7656 |
|
| 7657 |
|
| 7658 |
|
| 7659 |
|
| 7660 |
|
| 7661 |
public boolean canScrollHorizontally() { |
| 7662 |
return false; |
| 7663 |
} |
| 7664 |
|
| 7665 |
|
| 7666 |
|
| 7667 |
|
| 7668 |
|
| 7669 |
|
| 7670 |
|
| 7671 |
public boolean canScrollVertically() { |
| 7672 |
return false; |
| 7673 |
} |
| 7674 |
|
| 7675 |
|
| 7676 |
|
| 7677 |
|
| 7678 |
|
| 7679 |
|
| 7680 |
|
| 7681 |
public void scrollToPosition(int position) { |
| 7682 |
if (DEBUG) { |
| 7683 |
Log.e(TAG, "You MUST implement scrollToPosition. It will soon become abstract"); |
| 7684 |
} |
| 7685 |
} |
| 7686 |
|
| 7687 |
|
| 7688 |
|
| 7689 |
|
| 7690 |
|
| 7691 |
|
| 7692 |
|
| 7693 |
|
| 7694 |
|
| 7695 |
|
| 7696 |
public void smoothScrollToPosition(RecyclerView recyclerView, State state, |
| 7697 |
int position) { |
| 7698 |
Log.e(TAG, "You must override smoothScrollToPosition to support smooth scrolling"); |
| 7699 |
} |
| 7700 |
|
| 7701 |
|
| 7702 |
|
| 7703 |
|
| 7704 |
|
| 7705 |
|
| 7706 |
public void startSmoothScroll(SmoothScroller smoothScroller) { |
| 7707 |
if (mSmoothScroller != null && smoothScroller != mSmoothScroller |
| 7708 |
&& mSmoothScroller.isRunning()) { |
| 7709 |
mSmoothScroller.stop(); |
| 7710 |
} |
| 7711 |
mSmoothScroller = smoothScroller; |
| 7712 |
mSmoothScroller.start(mRecyclerView, this); |
| 7713 |
} |
| 7714 |
|
| 7715 |
|
| 7716 |
|
| 7717 |
|
| 7718 |
public boolean isSmoothScrolling() { |
| 7719 |
return mSmoothScroller != null && mSmoothScroller.isRunning(); |
| 7720 |
} |
| 7721 |
|
| 7722 |
|
| 7723 |
|
| 7724 |
|
| 7725 |
|
| 7726 |
|
| 7727 |
|
| 7728 |
|
| 7729 |
|
| 7730 |
|
| 7731 |
public int getLayoutDirection() { |
| 7732 |
return mRecyclerView.getLayoutDirection(); |
| 7733 |
} |
| 7734 |
|
| 7735 |
|
| 7736 |
|
| 7737 |
|
| 7738 |
|
| 7739 |
|
| 7740 |
|
| 7741 |
public void endAnimation(View view) { |
| 7742 |
if (mRecyclerView.mItemAnimator != null) { |
| 7743 |
mRecyclerView.mItemAnimator.endAnimation(getChildViewHolderInt(view)); |
| 7744 |
} |
| 7745 |
} |
| 7746 |
|
| 7747 |
|
| 7748 |
|
| 7749 |
|
| 7750 |
|
| 7751 |
|
| 7752 |
|
| 7753 |
|
| 7754 |
|
| 7755 |
|
| 7756 |
|
| 7757 |
|
| 7758 |
|
| 7759 |
|
| 7760 |
public void addDisappearingView(View child) { |
| 7761 |
addDisappearingView(child, -1); |
| 7762 |
} |
| 7763 |
|
| 7764 |
|
| 7765 |
|
| 7766 |
|
| 7767 |
|
| 7768 |
|
| 7769 |
|
| 7770 |
|
| 7771 |
|
| 7772 |
|
| 7773 |
|
| 7774 |
|
| 7775 |
|
| 7776 |
|
| 7777 |
|
| 7778 |
public void addDisappearingView(View child, int index) { |
| 7779 |
addViewInt(child, index, true); |
| 7780 |
} |
| 7781 |
|
| 7782 |
|
| 7783 |
|
| 7784 |
|
| 7785 |
|
| 7786 |
|
| 7787 |
|
| 7788 |
|
| 7789 |
public void addView(View child) { |
| 7790 |
addView(child, -1); |
| 7791 |
} |
| 7792 |
|
| 7793 |
|
| 7794 |
|
| 7795 |
|
| 7796 |
|
| 7797 |
|
| 7798 |
|
| 7799 |
|
| 7800 |
|
| 7801 |
public void addView(View child, int index) { |
| 7802 |
addViewInt(child, index, false); |
| 7803 |
} |
| 7804 |
|
| 7805 |
private void addViewInt(View child, int index, boolean disappearing) { |
| 7806 |
final ViewHolder holder = getChildViewHolderInt(child); |
| 7807 |
if (disappearing || holder.isRemoved()) { |
| 7808 |
|
| 7809 |
mRecyclerView.mViewInfoStore.addToDisappearedInLayout(holder); |
| 7810 |
} else { |
| 7811 |
|
| 7812 |
|
| 7813 |
|
| 7814 |
|
| 7815 |
|
| 7816 |
mRecyclerView.mViewInfoStore.removeFromDisappearedInLayout(holder); |
| 7817 |
} |
| 7818 |
final LayoutParams lp = (LayoutParams) child.getLayoutParams(); |
| 7819 |
if (holder.wasReturnedFromScrap() || holder.isScrap()) { |
| 7820 |
if (holder.isScrap()) { |
| 7821 |
holder.unScrap(); |
| 7822 |
} else { |
| 7823 |
holder.clearReturnedFromScrapFlag(); |
| 7824 |
} |
| 7825 |
mChildHelper.attachViewToParent(child, index, child.getLayoutParams(), false); |
| 7826 |
if (DISPATCH_TEMP_DETACH) { |
| 7827 |
child.dispatchFinishTemporaryDetach(); |
| 7828 |
} |
| 7829 |
} else if (child.getParent() == mRecyclerView) { |
| 7830 |
|
| 7831 |
int currentIndex = mChildHelper.indexOfChild(child); |
| 7832 |
if (index == -1) { |
| 7833 |
index = mChildHelper.getChildCount(); |
| 7834 |
} |
| 7835 |
if (currentIndex == -1) { |
| 7836 |
throw new IllegalStateException("Added View has RecyclerView as parent but" |
| 7837 |
+ " view is not a real child. Unfiltered index:" |
| 7838 |
+ mRecyclerView.indexOfChild(child)); |
| 7839 |
} |
| 7840 |
if (currentIndex != index) { |
| 7841 |
mRecyclerView.mLayout.moveView(currentIndex, index); |
| 7842 |
} |
| 7843 |
} else { |
| 7844 |
mChildHelper.addView(child, index, false); |
| 7845 |
lp.mInsetsDirty = true; |
| 7846 |
if (mSmoothScroller != null && mSmoothScroller.isRunning()) { |
| 7847 |
mSmoothScroller.onChildAttachedToWindow(child); |
| 7848 |
} |
| 7849 |
} |
| 7850 |
if (lp.mPendingInvalidate) { |
| 7851 |
if (DEBUG) { |
| 7852 |
Log.d(TAG, "consuming pending invalidate on child " + lp.mViewHolder); |
| 7853 |
} |
| 7854 |
holder.itemView.invalidate(); |
| 7855 |
lp.mPendingInvalidate = false; |
| 7856 |
} |
| 7857 |
} |
| 7858 |
|
| 7859 |
|
| 7860 |
|
| 7861 |
|
| 7862 |
|
| 7863 |
|
| 7864 |
|
| 7865 |
|
| 7866 |
|
| 7867 |
public void removeView(View child) { |
| 7868 |
mChildHelper.removeView(child); |
| 7869 |
} |
| 7870 |
|
| 7871 |
|
| 7872 |
|
| 7873 |
|
| 7874 |
|
| 7875 |
|
| 7876 |
|
| 7877 |
|
| 7878 |
|
| 7879 |
public void removeViewAt(int index) { |
| 7880 |
final View child = getChildAt(index); |
| 7881 |
if (child != null) { |
| 7882 |
mChildHelper.removeViewAt(index); |
| 7883 |
} |
| 7884 |
} |
| 7885 |
|
| 7886 |
|
| 7887 |
|
| 7888 |
|
| 7889 |
|
| 7890 |
public void removeAllViews() { |
| 7891 |
|
| 7892 |
final int childCount = getChildCount(); |
| 7893 |
for (int i = childCount - 1; i >= 0; i--) { |
| 7894 |
mChildHelper.removeViewAt(i); |
| 7895 |
} |
| 7896 |
} |
| 7897 |
|
| 7898 |
|
| 7899 |
|
| 7900 |
|
| 7901 |
|
| 7902 |
|
| 7903 |
|
| 7904 |
public int getBaseline() { |
| 7905 |
return -1; |
| 7906 |
} |
| 7907 |
|
| 7908 |
|
| 7909 |
|
| 7910 |
|
| 7911 |
|
| 7912 |
|
| 7913 |
|
| 7914 |
|
| 7915 |
public int getPosition(View view) { |
| 7916 |
return ((RecyclerView.LayoutParams) view.getLayoutParams()).getViewLayoutPosition(); |
| 7917 |
} |
| 7918 |
|
| 7919 |
|
| 7920 |
|
| 7921 |
|
| 7922 |
|
| 7923 |
|
| 7924 |
|
| 7925 |
public int getItemViewType(View view) { |
| 7926 |
return getChildViewHolderInt(view).getItemViewType(); |
| 7927 |
} |
| 7928 |
|
| 7929 |
|
| 7930 |
|
| 7931 |
|
| 7932 |
|
| 7933 |
|
| 7934 |
|
| 7935 |
|
| 7936 |
|
| 7937 |
|
| 7938 |
|
| 7939 |
|
| 7940 |
|
| 7941 |
|
| 7942 |
|
| 7943 |
|
| 7944 |
@Nullable |
| 7945 |
public View findContainingItemView(View view) { |
| 7946 |
if (mRecyclerView == null) { |
| 7947 |
return null; |
| 7948 |
} |
| 7949 |
View found = mRecyclerView.findContainingItemView(view); |
| 7950 |
if (found == null) { |
| 7951 |
return null; |
| 7952 |
} |
| 7953 |
if (mChildHelper.isHidden(found)) { |
| 7954 |
return null; |
| 7955 |
} |
| 7956 |
return found; |
| 7957 |
} |
| 7958 |
|
| 7959 |
|
| 7960 |
|
| 7961 |
|
| 7962 |
|
| 7963 |
|
| 7964 |
|
| 7965 |
|
| 7966 |
|
| 7967 |
|
| 7968 |
|
| 7969 |
|
| 7970 |
|
| 7971 |
|
| 7972 |
public View findViewByPosition(int position) { |
| 7973 |
final int childCount = getChildCount(); |
| 7974 |
for (int i = 0; i < childCount; i++) { |
| 7975 |
View child = getChildAt(i); |
| 7976 |
ViewHolder vh = getChildViewHolderInt(child); |
| 7977 |
if (vh == null) { |
| 7978 |
continue; |
| 7979 |
} |
| 7980 |
if (vh.getLayoutPosition() == position && !vh.shouldIgnore() |
| 7981 |
&& (mRecyclerView.mState.isPreLayout() || !vh.isRemoved())) { |
| 7982 |
return child; |
| 7983 |
} |
| 7984 |
} |
| 7985 |
return null; |
| 7986 |
} |
| 7987 |
|
| 7988 |
|
| 7989 |
|
| 7990 |
|
| 7991 |
|
| 7992 |
|
| 7993 |
|
| 7994 |
|
| 7995 |
|
| 7996 |
|
| 7997 |
|
| 7998 |
|
| 7999 |
|
| 8000 |
|
| 8001 |
|
| 8002 |
|
| 8003 |
public void detachView(View child) { |
| 8004 |
final int ind = mChildHelper.indexOfChild(child); |
| 8005 |
if (ind >= 0) { |
| 8006 |
detachViewInternal(ind, child); |
| 8007 |
} |
| 8008 |
} |
| 8009 |
|
| 8010 |
|
| 8011 |
|
| 8012 |
|
| 8013 |
|
| 8014 |
|
| 8015 |
|
| 8016 |
|
| 8017 |
|
| 8018 |
|
| 8019 |
|
| 8020 |
|
| 8021 |
|
| 8022 |
|
| 8023 |
|
| 8024 |
|
| 8025 |
public void detachViewAt(int index) { |
| 8026 |
detachViewInternal(index, getChildAt(index)); |
| 8027 |
} |
| 8028 |
|
| 8029 |
private void detachViewInternal(int index, View view) { |
| 8030 |
if (DISPATCH_TEMP_DETACH) { |
| 8031 |
view.dispatchStartTemporaryDetach(); |
| 8032 |
} |
| 8033 |
mChildHelper.detachViewFromParent(index); |
| 8034 |
} |
| 8035 |
|
| 8036 |
|
| 8037 |
|
| 8038 |
|
| 8039 |
|
| 8040 |
|
| 8041 |
|
| 8042 |
|
| 8043 |
|
| 8044 |
|
| 8045 |
public void attachView(View child, int index, LayoutParams lp) { |
| 8046 |
ViewHolder vh = getChildViewHolderInt(child); |
| 8047 |
if (vh.isRemoved()) { |
| 8048 |
mRecyclerView.mViewInfoStore.addToDisappearedInLayout(vh); |
| 8049 |
} else { |
| 8050 |
mRecyclerView.mViewInfoStore.removeFromDisappearedInLayout(vh); |
| 8051 |
} |
| 8052 |
mChildHelper.attachViewToParent(child, index, lp, vh.isRemoved()); |
| 8053 |
if (DISPATCH_TEMP_DETACH) { |
| 8054 |
child.dispatchFinishTemporaryDetach(); |
| 8055 |
} |
| 8056 |
} |
| 8057 |
|
| 8058 |
|
| 8059 |
|
| 8060 |
|
| 8061 |
|
| 8062 |
|
| 8063 |
|
| 8064 |
|
| 8065 |
|
| 8066 |
public void attachView(View child, int index) { |
| 8067 |
attachView(child, index, (LayoutParams) child.getLayoutParams()); |
| 8068 |
} |
| 8069 |
|
| 8070 |
|
| 8071 |
|
| 8072 |
|
| 8073 |
|
| 8074 |
|
| 8075 |
|
| 8076 |
|
| 8077 |
public void attachView(View child) { |
| 8078 |
attachView(child, -1); |
| 8079 |
} |
| 8080 |
|
| 8081 |
|
| 8082 |
|
| 8083 |
|
| 8084 |
|
| 8085 |
|
| 8086 |
|
| 8087 |
public void removeDetachedView(View child) { |
| 8088 |
mRecyclerView.removeDetachedView(child, false); |
| 8089 |
} |
| 8090 |
|
| 8091 |
|
| 8092 |
|
| 8093 |
|
| 8094 |
|
| 8095 |
|
| 8096 |
|
| 8097 |
public void moveView(int fromIndex, int toIndex) { |
| 8098 |
View view = getChildAt(fromIndex); |
| 8099 |
if (view == null) { |
| 8100 |
throw new IllegalArgumentException("Cannot move a child from non-existing index:" |
| 8101 |
+ fromIndex); |
| 8102 |
} |
| 8103 |
detachViewAt(fromIndex); |
| 8104 |
attachView(view, toIndex); |
| 8105 |
} |
| 8106 |
|
| 8107 |
|
| 8108 |
|
| 8109 |
|
| 8110 |
|
| 8111 |
|
| 8112 |
|
| 8113 |
|
| 8114 |
|
| 8115 |
|
| 8116 |
public void detachAndScrapView(View child, Recycler recycler) { |
| 8117 |
int index = mChildHelper.indexOfChild(child); |
| 8118 |
scrapOrRecycleView(recycler, index, child); |
| 8119 |
} |
| 8120 |
|
| 8121 |
|
| 8122 |
|
| 8123 |
|
| 8124 |
|
| 8125 |
|
| 8126 |
|
| 8127 |
|
| 8128 |
|
| 8129 |
|
| 8130 |
public void detachAndScrapViewAt(int index, Recycler recycler) { |
| 8131 |
final View child = getChildAt(index); |
| 8132 |
scrapOrRecycleView(recycler, index, child); |
| 8133 |
} |
| 8134 |
|
| 8135 |
|
| 8136 |
|
| 8137 |
|
| 8138 |
|
| 8139 |
|
| 8140 |
|
| 8141 |
public void removeAndRecycleView(View child, Recycler recycler) { |
| 8142 |
removeView(child); |
| 8143 |
recycler.recycleView(child); |
| 8144 |
} |
| 8145 |
|
| 8146 |
|
| 8147 |
|
| 8148 |
|
| 8149 |
|
| 8150 |
|
| 8151 |
|
| 8152 |
public void removeAndRecycleViewAt(int index, Recycler recycler) { |
| 8153 |
final View view = getChildAt(index); |
| 8154 |
removeViewAt(index); |
| 8155 |
recycler.recycleView(view); |
| 8156 |
} |
| 8157 |
|
| 8158 |
|
| 8159 |
|
| 8160 |
|
| 8161 |
|
| 8162 |
|
| 8163 |
|
| 8164 |
public int getChildCount() { |
| 8165 |
return mChildHelper != null ? mChildHelper.getChildCount() : 0; |
| 8166 |
} |
| 8167 |
|
| 8168 |
|
| 8169 |
|
| 8170 |
|
| 8171 |
|
| 8172 |
|
| 8173 |
public View getChildAt(int index) { |
| 8174 |
return mChildHelper != null ? mChildHelper.getChildAt(index) : null; |
| 8175 |
} |
| 8176 |
|
| 8177 |
|
| 8178 |
|
| 8179 |
|
| 8180 |
|
| 8181 |
|
| 8182 |
|
| 8183 |
|
| 8184 |
|
| 8185 |
|
| 8186 |
|
| 8187 |
|
| 8188 |
|
| 8189 |
|
| 8190 |
|
| 8191 |
public int getWidthMode() { |
| 8192 |
return mWidthMode; |
| 8193 |
} |
| 8194 |
|
| 8195 |
|
| 8196 |
|
| 8197 |
|
| 8198 |
|
| 8199 |
|
| 8200 |
|
| 8201 |
|
| 8202 |
|
| 8203 |
|
| 8204 |
|
| 8205 |
|
| 8206 |
|
| 8207 |
|
| 8208 |
|
| 8209 |
public int getHeightMode() { |
| 8210 |
return mHeightMode; |
| 8211 |
} |
| 8212 |
|
| 8213 |
|
| 8214 |
|
| 8215 |
|
| 8216 |
|
| 8217 |
|
| 8218 |
public int getWidth() { |
| 8219 |
return mWidth; |
| 8220 |
} |
| 8221 |
|
| 8222 |
|
| 8223 |
|
| 8224 |
|
| 8225 |
|
| 8226 |
|
| 8227 |
public int getHeight() { |
| 8228 |
return mHeight; |
| 8229 |
} |
| 8230 |
|
| 8231 |
|
| 8232 |
|
| 8233 |
|
| 8234 |
|
| 8235 |
|
| 8236 |
public int getPaddingLeft() { |
| 8237 |
return mRecyclerView != null ? mRecyclerView.getPaddingLeft() : 0; |
| 8238 |
} |
| 8239 |
|
| 8240 |
|
| 8241 |
|
| 8242 |
|
| 8243 |
|
| 8244 |
|
| 8245 |
public int getPaddingTop() { |
| 8246 |
return mRecyclerView != null ? mRecyclerView.getPaddingTop() : 0; |
| 8247 |
} |
| 8248 |
|
| 8249 |
|
| 8250 |
|
| 8251 |
|
| 8252 |
|
| 8253 |
|
| 8254 |
public int getPaddingRight() { |
| 8255 |
return mRecyclerView != null ? mRecyclerView.getPaddingRight() : 0; |
| 8256 |
} |
| 8257 |
|
| 8258 |
|
| 8259 |
|
| 8260 |
|
| 8261 |
|
| 8262 |
|
| 8263 |
public int getPaddingBottom() { |
| 8264 |
return mRecyclerView != null ? mRecyclerView.getPaddingBottom() : 0; |
| 8265 |
} |
| 8266 |
|
| 8267 |
|
| 8268 |
|
| 8269 |
|
| 8270 |
|
| 8271 |
|
| 8272 |
public int getPaddingStart() { |
| 8273 |
return mRecyclerView != null ? mRecyclerView.getPaddingStart() : 0; |
| 8274 |
} |
| 8275 |
|
| 8276 |
|
| 8277 |
|
| 8278 |
|
| 8279 |
|
| 8280 |
|
| 8281 |
public int getPaddingEnd() { |
| 8282 |
return mRecyclerView != null ? mRecyclerView.getPaddingEnd() : 0; |
| 8283 |
} |
| 8284 |
|
| 8285 |
|
| 8286 |
|
| 8287 |
|
| 8288 |
|
| 8289 |
|
| 8290 |
|
| 8291 |
public boolean isFocused() { |
| 8292 |
return mRecyclerView != null && mRecyclerView.isFocused(); |
| 8293 |
} |
| 8294 |
|
| 8295 |
|
| 8296 |
|
| 8297 |
|
| 8298 |
|
| 8299 |
|
| 8300 |
|
| 8301 |
public boolean hasFocus() { |
| 8302 |
return mRecyclerView != null && mRecyclerView.hasFocus(); |
| 8303 |
} |
| 8304 |
|
| 8305 |
|
| 8306 |
|
| 8307 |
|
| 8308 |
|
| 8309 |
|
| 8310 |
public View getFocusedChild() { |
| 8311 |
if (mRecyclerView == null) { |
| 8312 |
return null; |
| 8313 |
} |
| 8314 |
final View focused = mRecyclerView.getFocusedChild(); |
| 8315 |
if (focused == null || mChildHelper.isHidden(focused)) { |
| 8316 |
return null; |
| 8317 |
} |
| 8318 |
return focused; |
| 8319 |
} |
| 8320 |
|
| 8321 |
|
| 8322 |
|
| 8323 |
|
| 8324 |
|
| 8325 |
|
| 8326 |
|
| 8327 |
|
| 8328 |
|
| 8329 |
|
| 8330 |
|
| 8331 |
|
| 8332 |
|
| 8333 |
public int getItemCount() { |
| 8334 |
final Adapter a = mRecyclerView != null ? mRecyclerView.getAdapter() : null; |
| 8335 |
return a != null ? a.getItemCount() : 0; |
| 8336 |
} |
| 8337 |
|
| 8338 |
|
| 8339 |
|
| 8340 |
|
| 8341 |
|
| 8342 |
|
| 8343 |
|
| 8344 |
public void offsetChildrenHorizontal(int dx) { |
| 8345 |
if (mRecyclerView != null) { |
| 8346 |
mRecyclerView.offsetChildrenHorizontal(dx); |
| 8347 |
} |
| 8348 |
} |
| 8349 |
|
| 8350 |
|
| 8351 |
|
| 8352 |
|
| 8353 |
|
| 8354 |
|
| 8355 |
|
| 8356 |
public void offsetChildrenVertical(int dy) { |
| 8357 |
if (mRecyclerView != null) { |
| 8358 |
mRecyclerView.offsetChildrenVertical(dy); |
| 8359 |
} |
| 8360 |
} |
| 8361 |
|
| 8362 |
|
| 8363 |
|
| 8364 |
|
| 8365 |
|
| 8366 |
|
| 8367 |
|
| 8368 |
|
| 8369 |
|
| 8370 |
|
| 8371 |
|
| 8372 |
|
| 8373 |
|
| 8374 |
|
| 8375 |
|
| 8376 |
|
| 8377 |
|
| 8378 |
public void ignoreView(View view) { |
| 8379 |
if (view.getParent() != mRecyclerView || mRecyclerView.indexOfChild(view) == -1) { |
| 8380 |
|
| 8381 |
|
| 8382 |
throw new IllegalArgumentException("View should be fully attached to be ignored"); |
| 8383 |
} |
| 8384 |
final ViewHolder vh = getChildViewHolderInt(view); |
| 8385 |
vh.addFlags(ViewHolder.FLAG_IGNORE); |
| 8386 |
mRecyclerView.mViewInfoStore.removeViewHolder(vh); |
| 8387 |
} |
| 8388 |
|
| 8389 |
|
| 8390 |
|
| 8391 |
|
| 8392 |
|
| 8393 |
|
| 8394 |
|
| 8395 |
|
| 8396 |
|
| 8397 |
|
| 8398 |
public void stopIgnoringView(View view) { |
| 8399 |
final ViewHolder vh = getChildViewHolderInt(view); |
| 8400 |
vh.stopIgnoring(); |
| 8401 |
vh.resetInternal(); |
| 8402 |
vh.addFlags(ViewHolder.FLAG_INVALID); |
| 8403 |
} |
| 8404 |
|
| 8405 |
|
| 8406 |
|
| 8407 |
|
| 8408 |
|
| 8409 |
|
| 8410 |
|
| 8411 |
|
| 8412 |
public void detachAndScrapAttachedViews(Recycler recycler) { |
| 8413 |
final int childCount = getChildCount(); |
| 8414 |
for (int i = childCount - 1; i >= 0; i--) { |
| 8415 |
final View v = getChildAt(i); |
| 8416 |
scrapOrRecycleView(recycler, i, v); |
| 8417 |
} |
| 8418 |
} |
| 8419 |
|
| 8420 |
private void scrapOrRecycleView(Recycler recycler, int index, View view) { |
| 8421 |
final ViewHolder viewHolder = getChildViewHolderInt(view); |
| 8422 |
if (viewHolder.shouldIgnore()) { |
| 8423 |
if (DEBUG) { |
| 8424 |
Log.d(TAG, "ignoring view " + viewHolder); |
| 8425 |
} |
| 8426 |
return; |
| 8427 |
} |
| 8428 |
if (viewHolder.isInvalid() && !viewHolder.isRemoved() |
| 8429 |
&& !mRecyclerView.mAdapter.hasStableIds()) { |
| 8430 |
removeViewAt(index); |
| 8431 |
recycler.recycleViewHolderInternal(viewHolder); |
| 8432 |
} else { |
| 8433 |
detachViewAt(index); |
| 8434 |
recycler.scrapView(view); |
| 8435 |
mRecyclerView.mViewInfoStore.onViewDetached(viewHolder); |
| 8436 |
} |
| 8437 |
} |
| 8438 |
|
| 8439 |
|
| 8440 |
|
| 8441 |
|
| 8442 |
|
| 8443 |
|
| 8444 |
|
| 8445 |
|
| 8446 |
|
| 8447 |
|
| 8448 |
void removeAndRecycleScrapInt(Recycler recycler) { |
| 8449 |
final int scrapCount = recycler.getScrapCount(); |
| 8450 |
|
| 8451 |
for (int i = scrapCount - 1; i >= 0; i--) { |
| 8452 |
final View scrap = recycler.getScrapViewAt(i); |
| 8453 |
final ViewHolder vh = getChildViewHolderInt(scrap); |
| 8454 |
if (vh.shouldIgnore()) { |
| 8455 |
continue; |
| 8456 |
} |
| 8457 |
|
| 8458 |
|
| 8459 |
|
| 8460 |
|
| 8461 |
|
| 8462 |
vh.setIsRecyclable(false); |
| 8463 |
if (vh.isTmpDetached()) { |
| 8464 |
mRecyclerView.removeDetachedView(scrap, false); |
| 8465 |
} |
| 8466 |
if (mRecyclerView.mItemAnimator != null) { |
| 8467 |
mRecyclerView.mItemAnimator.endAnimation(vh); |
| 8468 |
} |
| 8469 |
vh.setIsRecyclable(true); |
| 8470 |
recycler.quickRecycleScrapView(scrap); |
| 8471 |
} |
| 8472 |
recycler.clearScrap(); |
| 8473 |
if (scrapCount > 0) { |
| 8474 |
mRecyclerView.invalidate(); |
| 8475 |
} |
| 8476 |
} |
| 8477 |
|
| 8478 |
|
| 8479 |
|
| 8480 |
|
| 8481 |
|
| 8482 |
|
| 8483 |
|
| 8484 |
|
| 8485 |
|
| 8486 |
|
| 8487 |
|
| 8488 |
|
| 8489 |
|
| 8490 |
public void measureChild(View child, int widthUsed, int heightUsed) { |
| 8491 |
final LayoutParams lp = (LayoutParams) child.getLayoutParams(); |
| 8492 |
|
| 8493 |
final Rect insets = mRecyclerView.getItemDecorInsetsForChild(child); |
| 8494 |
widthUsed += insets.left + insets.right; |
| 8495 |
heightUsed += insets.top + insets.bottom; |
| 8496 |
final int widthSpec = getChildMeasureSpec(getWidth(), getWidthMode(), |
| 8497 |
getPaddingLeft() + getPaddingRight() + widthUsed, lp.width, |
| 8498 |
canScrollHorizontally()); |
| 8499 |
final int heightSpec = getChildMeasureSpec(getHeight(), getHeightMode(), |
| 8500 |
getPaddingTop() + getPaddingBottom() + heightUsed, lp.height, |
| 8501 |
canScrollVertically()); |
| 8502 |
if (shouldMeasureChild(child, widthSpec, heightSpec, lp)) { |
| 8503 |
child.measure(widthSpec, heightSpec); |
| 8504 |
} |
| 8505 |
} |
| 8506 |
|
| 8507 |
|
| 8508 |
|
| 8509 |
|
| 8510 |
|
| 8511 |
|
| 8512 |
|
| 8513 |
boolean shouldReMeasureChild(View child, int widthSpec, int heightSpec, LayoutParams lp) { |
| 8514 |
return !mMeasurementCacheEnabled |
| 8515 |
|| !isMeasurementUpToDate(child.getMeasuredWidth(), widthSpec, lp.width) |
| 8516 |
|| !isMeasurementUpToDate(child.getMeasuredHeight(), heightSpec, lp.height); |
| 8517 |
} |
| 8518 |
|
| 8519 |
|
| 8520 |
|
| 8521 |
|
| 8522 |
|
| 8523 |
|
| 8524 |
|
| 8525 |
|
| 8526 |
|
| 8527 |
boolean shouldMeasureChild(View child, int widthSpec, int heightSpec, LayoutParams lp) { |
| 8528 |
return child.isLayoutRequested() |
| 8529 |
|| !mMeasurementCacheEnabled |
| 8530 |
|| !isMeasurementUpToDate(child.getWidth(), widthSpec, lp.width) |
| 8531 |
|| !isMeasurementUpToDate(child.getHeight(), heightSpec, lp.height); |
| 8532 |
} |
| 8533 |
|
| 8534 |
|
| 8535 |
|
| 8536 |
|
| 8537 |
|
| 8538 |
|
| 8539 |
|
| 8540 |
|
| 8541 |
|
| 8542 |
|
| 8543 |
|
| 8544 |
public boolean isMeasurementCacheEnabled() { |
| 8545 |
return mMeasurementCacheEnabled; |
| 8546 |
} |
| 8547 |
|
| 8548 |
|
| 8549 |
|
| 8550 |
|
| 8551 |
|
| 8552 |
|
| 8553 |
|
| 8554 |
|
| 8555 |
|
| 8556 |
public void setMeasurementCacheEnabled(boolean measurementCacheEnabled) { |
| 8557 |
mMeasurementCacheEnabled = measurementCacheEnabled; |
| 8558 |
} |
| 8559 |
|
| 8560 |
private static boolean isMeasurementUpToDate(int childSize, int spec, int dimension) { |
| 8561 |
final int specMode = MeasureSpec.getMode(spec); |
| 8562 |
final int specSize = MeasureSpec.getSize(spec); |
| 8563 |
if (dimension > 0 && childSize != dimension) { |
| 8564 |
return false; |
| 8565 |
} |
| 8566 |
switch (specMode) { |
| 8567 |
case MeasureSpec.UNSPECIFIED: |
| 8568 |
return true; |
| 8569 |
case MeasureSpec.AT_MOST: |
| 8570 |
return specSize >= childSize; |
| 8571 |
case MeasureSpec.EXACTLY: |
| 8572 |
return specSize == childSize; |
| 8573 |
} |
| 8574 |
return false; |
| 8575 |
} |
| 8576 |
|
| 8577 |
|
| 8578 |
|
| 8579 |
|
| 8580 |
|
| 8581 |
|
| 8582 |
|
| 8583 |
|
| 8584 |
|
| 8585 |
|
| 8586 |
|
| 8587 |
|
| 8588 |
|
| 8589 |
public void measureChildWithMargins(View child, int widthUsed, int heightUsed) { |
| 8590 |
final LayoutParams lp = (LayoutParams) child.getLayoutParams(); |
| 8591 |
|
| 8592 |
final Rect insets = mRecyclerView.getItemDecorInsetsForChild(child); |
| 8593 |
widthUsed += insets.left + insets.right; |
| 8594 |
heightUsed += insets.top + insets.bottom; |
| 8595 |
|
| 8596 |
final int widthSpec = getChildMeasureSpec(getWidth(), getWidthMode(), |
| 8597 |
getPaddingLeft() + getPaddingRight() |
| 8598 |
+ lp.leftMargin + lp.rightMargin + widthUsed, lp.width, |
| 8599 |
canScrollHorizontally()); |
| 8600 |
final int heightSpec = getChildMeasureSpec(getHeight(), getHeightMode(), |
| 8601 |
getPaddingTop() + getPaddingBottom() |
| 8602 |
+ lp.topMargin + lp.bottomMargin + heightUsed, lp.height, |
| 8603 |
canScrollVertically()); |
| 8604 |
if (shouldMeasureChild(child, widthSpec, heightSpec, lp)) { |
| 8605 |
child.measure(widthSpec, heightSpec); |
| 8606 |
} |
| 8607 |
} |
| 8608 |
|
| 8609 |
|
| 8610 |
|
| 8611 |
|
| 8612 |
|
| 8613 |
|
| 8614 |
|
| 8615 |
|
| 8616 |
|
| 8617 |
|
| 8618 |
|
| 8619 |
|
| 8620 |
|
| 8621 |
@Deprecated |
| 8622 |
public static int getChildMeasureSpec(int parentSize, int padding, int childDimension, |
| 8623 |
boolean canScroll) { |
| 8624 |
int size = Math.max(0, parentSize - padding); |
| 8625 |
int resultSize = 0; |
| 8626 |
int resultMode = 0; |
| 8627 |
if (canScroll) { |
| 8628 |
if (childDimension >= 0) { |
| 8629 |
resultSize = childDimension; |
| 8630 |
resultMode = MeasureSpec.EXACTLY; |
| 8631 |
} else { |
| 8632 |
|
| 8633 |
|
| 8634 |
resultSize = 0; |
| 8635 |
resultMode = MeasureSpec.UNSPECIFIED; |
| 8636 |
} |
| 8637 |
} else { |
| 8638 |
if (childDimension >= 0) { |
| 8639 |
resultSize = childDimension; |
| 8640 |
resultMode = MeasureSpec.EXACTLY; |
| 8641 |
} else if (childDimension == LayoutParams.MATCH_PARENT) { |
| 8642 |
resultSize = size; |
| 8643 |
|
| 8644 |
resultMode = MeasureSpec.EXACTLY; |
| 8645 |
} else if (childDimension == LayoutParams.WRAP_CONTENT) { |
| 8646 |
resultSize = size; |
| 8647 |
resultMode = MeasureSpec.AT_MOST; |
| 8648 |
} |
| 8649 |
} |
| 8650 |
return MeasureSpec.makeMeasureSpec(resultSize, resultMode); |
| 8651 |
} |
| 8652 |
|
| 8653 |
|
| 8654 |
|
| 8655 |
|
| 8656 |
|
| 8657 |
|
| 8658 |
|
| 8659 |
|
| 8660 |
|
| 8661 |
|
| 8662 |
|
| 8663 |
|
| 8664 |
|
| 8665 |
public static int getChildMeasureSpec(int parentSize, int parentMode, int padding, |
| 8666 |
int childDimension, boolean canScroll) { |
| 8667 |
int size = Math.max(0, parentSize - padding); |
| 8668 |
int resultSize = 0; |
| 8669 |
int resultMode = 0; |
| 8670 |
if (canScroll) { |
| 8671 |
if (childDimension >= 0) { |
| 8672 |
resultSize = childDimension; |
| 8673 |
resultMode = MeasureSpec.EXACTLY; |
| 8674 |
} else if (childDimension == LayoutParams.MATCH_PARENT) { |
| 8675 |
switch (parentMode) { |
| 8676 |
case MeasureSpec.AT_MOST: |
| 8677 |
case MeasureSpec.EXACTLY: |
| 8678 |
resultSize = size; |
| 8679 |
resultMode = parentMode; |
| 8680 |
break; |
| 8681 |
case MeasureSpec.UNSPECIFIED: |
| 8682 |
resultSize = 0; |
| 8683 |
resultMode = MeasureSpec.UNSPECIFIED; |
| 8684 |
break; |
| 8685 |
} |
| 8686 |
} else if (childDimension == LayoutParams.WRAP_CONTENT) { |
| 8687 |
resultSize = 0; |
| 8688 |
resultMode = MeasureSpec.UNSPECIFIED; |
| 8689 |
} |
| 8690 |
} else { |
| 8691 |
if (childDimension >= 0) { |
| 8692 |
resultSize = childDimension; |
| 8693 |
resultMode = MeasureSpec.EXACTLY; |
| 8694 |
} else if (childDimension == LayoutParams.MATCH_PARENT) { |
| 8695 |
resultSize = size; |
| 8696 |
resultMode = parentMode; |
| 8697 |
} else if (childDimension == LayoutParams.WRAP_CONTENT) { |
| 8698 |
resultSize = size; |
| 8699 |
if (parentMode == MeasureSpec.AT_MOST || parentMode == MeasureSpec.EXACTLY) { |
| 8700 |
resultMode = MeasureSpec.AT_MOST; |
| 8701 |
} else { |
| 8702 |
resultMode = MeasureSpec.UNSPECIFIED; |
| 8703 |
} |
| 8704 |
|
| 8705 |
} |
| 8706 |
} |
| 8707 |
|
| 8708 |
return MeasureSpec.makeMeasureSpec(resultSize, resultMode); |
| 8709 |
} |
| 8710 |
|
| 8711 |
|
| 8712 |
|
| 8713 |
|
| 8714 |
|
| 8715 |
|
| 8716 |
|
| 8717 |
|
| 8718 |
|
| 8719 |
|
| 8720 |
public int getDecoratedMeasuredWidth(View child) { |
| 8721 |
final Rect insets = ((LayoutParams) child.getLayoutParams()).mDecorInsets; |
| 8722 |
return child.getMeasuredWidth() + insets.left + insets.right; |
| 8723 |
} |
| 8724 |
|
| 8725 |
|
| 8726 |
|
| 8727 |
|
| 8728 |
|
| 8729 |
|
| 8730 |
|
| 8731 |
|
| 8732 |
|
| 8733 |
|
| 8734 |
public int getDecoratedMeasuredHeight(View child) { |
| 8735 |
final Rect insets = ((LayoutParams) child.getLayoutParams()).mDecorInsets; |
| 8736 |
return child.getMeasuredHeight() + insets.top + insets.bottom; |
| 8737 |
} |
| 8738 |
|
| 8739 |
|
| 8740 |
|
| 8741 |
|
| 8742 |
|
| 8743 |
|
| 8744 |
|
| 8745 |
|
| 8746 |
|
| 8747 |
|
| 8748 |
|
| 8749 |
|
| 8750 |
|
| 8751 |
|
| 8752 |
|
| 8753 |
|
| 8754 |
|
| 8755 |
|
| 8756 |
|
| 8757 |
|
| 8758 |
|
| 8759 |
|
| 8760 |
|
| 8761 |
|
| 8762 |
|
| 8763 |
|
| 8764 |
|
| 8765 |
|
| 8766 |
|
| 8767 |
|
| 8768 |
|
| 8769 |
public void layoutDecorated(View child, int left, int top, int right, int bottom) { |
| 8770 |
final Rect insets = ((LayoutParams) child.getLayoutParams()).mDecorInsets; |
| 8771 |
child.layout(left + insets.left, top + insets.top, right - insets.right, |
| 8772 |
bottom - insets.bottom); |
| 8773 |
} |
| 8774 |
|
| 8775 |
|
| 8776 |
|
| 8777 |
|
| 8778 |
|
| 8779 |
|
| 8780 |
|
| 8781 |
|
| 8782 |
|
| 8783 |
|
| 8784 |
|
| 8785 |
|
| 8786 |
|
| 8787 |
|
| 8788 |
|
| 8789 |
|
| 8790 |
|
| 8791 |
|
| 8792 |
|
| 8793 |
|
| 8794 |
|
| 8795 |
|
| 8796 |
|
| 8797 |
|
| 8798 |
|
| 8799 |
|
| 8800 |
|
| 8801 |
|
| 8802 |
|
| 8803 |
|
| 8804 |
public void layoutDecoratedWithMargins(View child, int left, int top, int right, |
| 8805 |
int bottom) { |
| 8806 |
final LayoutParams lp = (LayoutParams) child.getLayoutParams(); |
| 8807 |
final Rect insets = lp.mDecorInsets; |
| 8808 |
child.layout(left + insets.left + lp.leftMargin, top + insets.top + lp.topMargin, |
| 8809 |
right - insets.right - lp.rightMargin, |
| 8810 |
bottom - insets.bottom - lp.bottomMargin); |
| 8811 |
} |
| 8812 |
|
| 8813 |
|
| 8814 |
|
| 8815 |
|
| 8816 |
|
| 8817 |
|
| 8818 |
|
| 8819 |
|
| 8820 |
|
| 8821 |
|
| 8822 |
|
| 8823 |
|
| 8824 |
public void getTransformedBoundingBox(View child, boolean includeDecorInsets, Rect out) { |
| 8825 |
if (includeDecorInsets) { |
| 8826 |
Rect insets = ((LayoutParams) child.getLayoutParams()).mDecorInsets; |
| 8827 |
out.set(-insets.left, -insets.top, |
| 8828 |
child.getWidth() + insets.right, child.getHeight() + insets.bottom); |
| 8829 |
} else { |
| 8830 |
out.set(0, 0, child.getWidth(), child.getHeight()); |
| 8831 |
} |
| 8832 |
|
| 8833 |
if (mRecyclerView != null) { |
| 8834 |
final Matrix childMatrix = child.getMatrix(); |
| 8835 |
if (childMatrix != null && !childMatrix.isIdentity()) { |
| 8836 |
final RectF tempRectF = mRecyclerView.mTempRectF; |
| 8837 |
tempRectF.set(out); |
| 8838 |
childMatrix.mapRect(tempRectF); |
| 8839 |
out.set( |
| 8840 |
(int) Math.floor(tempRectF.left), |
| 8841 |
(int) Math.floor(tempRectF.top), |
| 8842 |
(int) Math.ceil(tempRectF.right), |
| 8843 |
(int) Math.ceil(tempRectF.bottom) |
| 8844 |
); |
| 8845 |
} |
| 8846 |
} |
| 8847 |
out.offset(child.getLeft(), child.getTop()); |
| 8848 |
} |
| 8849 |
|
| 8850 |
|
| 8851 |
|
| 8852 |
|
| 8853 |
|
| 8854 |
|
| 8855 |
|
| 8856 |
|
| 8857 |
public void getDecoratedBoundsWithMargins(View view, Rect outBounds) { |
| 8858 |
RecyclerView.getDecoratedBoundsWithMarginsInt(view, outBounds); |
| 8859 |
} |
| 8860 |
|
| 8861 |
|
| 8862 |
|
| 8863 |
|
| 8864 |
|
| 8865 |
|
| 8866 |
|
| 8867 |
|
| 8868 |
|
| 8869 |
public int getDecoratedLeft(View child) { |
| 8870 |
return child.getLeft() - getLeftDecorationWidth(child); |
| 8871 |
} |
| 8872 |
|
| 8873 |
|
| 8874 |
|
| 8875 |
|
| 8876 |
|
| 8877 |
|
| 8878 |
|
| 8879 |
|
| 8880 |
|
| 8881 |
public int getDecoratedTop(View child) { |
| 8882 |
return child.getTop() - getTopDecorationHeight(child); |
| 8883 |
} |
| 8884 |
|
| 8885 |
|
| 8886 |
|
| 8887 |
|
| 8888 |
|
| 8889 |
|
| 8890 |
|
| 8891 |
|
| 8892 |
|
| 8893 |
public int getDecoratedRight(View child) { |
| 8894 |
return child.getRight() + getRightDecorationWidth(child); |
| 8895 |
} |
| 8896 |
|
| 8897 |
|
| 8898 |
|
| 8899 |
|
| 8900 |
|
| 8901 |
|
| 8902 |
|
| 8903 |
|
| 8904 |
|
| 8905 |
public int getDecoratedBottom(View child) { |
| 8906 |
return child.getBottom() + getBottomDecorationHeight(child); |
| 8907 |
} |
| 8908 |
|
| 8909 |
|
| 8910 |
|
| 8911 |
|
| 8912 |
|
| 8913 |
|
| 8914 |
|
| 8915 |
|
| 8916 |
|
| 8917 |
|
| 8918 |
|
| 8919 |
|
| 8920 |
|
| 8921 |
|
| 8922 |
|
| 8923 |
|
| 8924 |
|
| 8925 |
|
| 8926 |
public void calculateItemDecorationsForChild(View child, Rect outRect) { |
| 8927 |
if (mRecyclerView == null) { |
| 8928 |
outRect.set(0, 0, 0, 0); |
| 8929 |
return; |
| 8930 |
} |
| 8931 |
Rect insets = mRecyclerView.getItemDecorInsetsForChild(child); |
| 8932 |
outRect.set(insets); |
| 8933 |
} |
| 8934 |
|
| 8935 |
|
| 8936 |
|
| 8937 |
|
| 8938 |
|
| 8939 |
|
| 8940 |
|
| 8941 |
|
| 8942 |
|
| 8943 |
|
| 8944 |
|
| 8945 |
|
| 8946 |
public int getTopDecorationHeight(View child) { |
| 8947 |
return ((LayoutParams) child.getLayoutParams()).mDecorInsets.top; |
| 8948 |
} |
| 8949 |
|
| 8950 |
|
| 8951 |
|
| 8952 |
|
| 8953 |
|
| 8954 |
|
| 8955 |
|
| 8956 |
|
| 8957 |
|
| 8958 |
|
| 8959 |
|
| 8960 |
|
| 8961 |
public int getBottomDecorationHeight(View child) { |
| 8962 |
return ((LayoutParams) child.getLayoutParams()).mDecorInsets.bottom; |
| 8963 |
} |
| 8964 |
|
| 8965 |
|
| 8966 |
|
| 8967 |
|
| 8968 |
|
| 8969 |
|
| 8970 |
|
| 8971 |
|
| 8972 |
|
| 8973 |
|
| 8974 |
|
| 8975 |
|
| 8976 |
public int getLeftDecorationWidth(View child) { |
| 8977 |
return ((LayoutParams) child.getLayoutParams()).mDecorInsets.left; |
| 8978 |
} |
| 8979 |
|
| 8980 |
|
| 8981 |
|
| 8982 |
|
| 8983 |
|
| 8984 |
|
| 8985 |
|
| 8986 |
|
| 8987 |
|
| 8988 |
|
| 8989 |
|
| 8990 |
|
| 8991 |
public int getRightDecorationWidth(View child) { |
| 8992 |
return ((LayoutParams) child.getLayoutParams()).mDecorInsets.right; |
| 8993 |
} |
| 8994 |
|
| 8995 |
|
| 8996 |
|
| 8997 |
|
| 8998 |
|
| 8999 |
|
| 9000 |
|
| 9001 |
|
| 9002 |
|
| 9003 |
|
| 9004 |
|
| 9005 |
|
| 9006 |
|
| 9007 |
|
| 9008 |
|
| 9009 |
|
| 9010 |
|
| 9011 |
|
| 9012 |
@Nullable |
| 9013 |
public View onFocusSearchFailed(View focused, int direction, Recycler recycler, |
| 9014 |
State state) { |
| 9015 |
return null; |
| 9016 |
} |
| 9017 |
|
| 9018 |
|
| 9019 |
|
| 9020 |
|
| 9021 |
|
| 9022 |
|
| 9023 |
|
| 9024 |
|
| 9025 |
|
| 9026 |
|
| 9027 |
|
| 9028 |
|
| 9029 |
|
| 9030 |
|
| 9031 |
|
| 9032 |
|
| 9033 |
|
| 9034 |
public View onInterceptFocusSearch(View focused, int direction) { |
| 9035 |
return null; |
| 9036 |
} |
| 9037 |
|
| 9038 |
|
| 9039 |
|
| 9040 |
|
| 9041 |
|
| 9042 |
|
| 9043 |
|
| 9044 |
|
| 9045 |
|
| 9046 |
|
| 9047 |
|
| 9048 |
|
| 9049 |
|
| 9050 |
|
| 9051 |
|
| 9052 |
|
| 9053 |
public boolean requestChildRectangleOnScreen(RecyclerView parent, View child, Rect rect, |
| 9054 |
boolean immediate) { |
| 9055 |
final int parentLeft = getPaddingLeft(); |
| 9056 |
final int parentTop = getPaddingTop(); |
| 9057 |
final int parentRight = getWidth() - getPaddingRight(); |
| 9058 |
final int parentBottom = getHeight() - getPaddingBottom(); |
| 9059 |
final int childLeft = child.getLeft() + rect.left - child.getScrollX(); |
| 9060 |
final int childTop = child.getTop() + rect.top - child.getScrollY(); |
| 9061 |
final int childRight = childLeft + rect.width(); |
| 9062 |
final int childBottom = childTop + rect.height(); |
| 9063 |
|
| 9064 |
final int offScreenLeft = Math.min(0, childLeft - parentLeft); |
| 9065 |
final int offScreenTop = Math.min(0, childTop - parentTop); |
| 9066 |
final int offScreenRight = Math.max(0, childRight - parentRight); |
| 9067 |
final int offScreenBottom = Math.max(0, childBottom - parentBottom); |
| 9068 |
|
| 9069 |
|
| 9070 |
|
| 9071 |
|
| 9072 |
final int dx; |
| 9073 |
if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { |
| 9074 |
dx = offScreenRight != 0 ? offScreenRight |
| 9075 |
: Math.max(offScreenLeft, childRight - parentRight); |
| 9076 |
} else { |
| 9077 |
dx = offScreenLeft != 0 ? offScreenLeft |
| 9078 |
: Math.min(childLeft - parentLeft, offScreenRight); |
| 9079 |
} |
| 9080 |
|
| 9081 |
|
| 9082 |
|
| 9083 |
final int dy = offScreenTop != 0 ? offScreenTop |
| 9084 |
: Math.min(childTop - parentTop, offScreenBottom); |
| 9085 |
|
| 9086 |
if (dx != 0 || dy != 0) { |
| 9087 |
if (immediate) { |
| 9088 |
parent.scrollBy(dx, dy); |
| 9089 |
} else { |
| 9090 |
parent.smoothScrollBy(dx, dy); |
| 9091 |
} |
| 9092 |
return true; |
| 9093 |
} |
| 9094 |
return false; |
| 9095 |
} |
| 9096 |
|
| 9097 |
|
| 9098 |
|
| 9099 |
|
| 9100 |
@Deprecated |
| 9101 |
public boolean onRequestChildFocus(RecyclerView parent, View child, View focused) { |
| 9102 |
|
| 9103 |
return isSmoothScrolling() || parent.isComputingLayout(); |
| 9104 |
} |
| 9105 |
|
| 9106 |
|
| 9107 |
|
| 9108 |
|
| 9109 |
|
| 9110 |
|
| 9111 |
|
| 9112 |
|
| 9113 |
|
| 9114 |
|
| 9115 |
|
| 9116 |
|
| 9117 |
|
| 9118 |
|
| 9119 |
|
| 9120 |
|
| 9121 |
|
| 9122 |
|
| 9123 |
public boolean onRequestChildFocus(RecyclerView parent, State state, View child, |
| 9124 |
View focused) { |
| 9125 |
return onRequestChildFocus(parent, child, focused); |
| 9126 |
} |
| 9127 |
|
| 9128 |
|
| 9129 |
|
| 9130 |
|
| 9131 |
|
| 9132 |
|
| 9133 |
|
| 9134 |
|
| 9135 |
|
| 9136 |
|
| 9137 |
|
| 9138 |
|
| 9139 |
|
| 9140 |
public void onAdapterChanged(Adapter oldAdapter, Adapter newAdapter) { |
| 9141 |
} |
| 9142 |
|
| 9143 |
|
| 9144 |
|
| 9145 |
|
| 9146 |
|
| 9147 |
|
| 9148 |
|
| 9149 |
|
| 9150 |
|
| 9151 |
|
| 9152 |
|
| 9153 |
|
| 9154 |
|
| 9155 |
|
| 9156 |
|
| 9157 |
|
| 9158 |
|
| 9159 |
|
| 9160 |
|
| 9161 |
|
| 9162 |
|
| 9163 |
|
| 9164 |
|
| 9165 |
|
| 9166 |
|
| 9167 |
public boolean onAddFocusables(RecyclerView recyclerView, ArrayList<View> views, |
| 9168 |
int direction, int focusableMode) { |
| 9169 |
return false; |
| 9170 |
} |
| 9171 |
|
| 9172 |
|
| 9173 |
|
| 9174 |
|
| 9175 |
|
| 9176 |
|
| 9177 |
|
| 9178 |
public void onItemsChanged(RecyclerView recyclerView) { |
| 9179 |
} |
| 9180 |
|
| 9181 |
|
| 9182 |
|
| 9183 |
|
| 9184 |
|
| 9185 |
|
| 9186 |
|
| 9187 |
|
| 9188 |
|
| 9189 |
|
| 9190 |
public void onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount) { |
| 9191 |
} |
| 9192 |
|
| 9193 |
|
| 9194 |
|
| 9195 |
|
| 9196 |
|
| 9197 |
|
| 9198 |
|
| 9199 |
|
| 9200 |
public void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount) { |
| 9201 |
} |
| 9202 |
|
| 9203 |
|
| 9204 |
|
| 9205 |
|
| 9206 |
|
| 9207 |
|
| 9208 |
|
| 9209 |
|
| 9210 |
|
| 9211 |
|
| 9212 |
public void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount) { |
| 9213 |
} |
| 9214 |
|
| 9215 |
|
| 9216 |
|
| 9217 |
|
| 9218 |
|
| 9219 |
|
| 9220 |
|
| 9221 |
|
| 9222 |
|
| 9223 |
|
| 9224 |
public void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount, |
| 9225 |
Object payload) { |
| 9226 |
onItemsUpdated(recyclerView, positionStart, itemCount); |
| 9227 |
} |
| 9228 |
|
| 9229 |
|
| 9230 |
|
| 9231 |
|
| 9232 |
|
| 9233 |
|
| 9234 |
|
| 9235 |
|
| 9236 |
|
| 9237 |
|
| 9238 |
|
| 9239 |
|
| 9240 |
|
| 9241 |
public void onItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount) { |
| 9242 |
|
| 9243 |
} |
| 9244 |
|
| 9245 |
|
| 9246 |
|
| 9247 |
|
| 9248 |
|
| 9249 |
|
| 9250 |
|
| 9251 |
|
| 9252 |
|
| 9253 |
|
| 9254 |
|
| 9255 |
|
| 9256 |
|
| 9257 |
public int computeHorizontalScrollExtent(State state) { |
| 9258 |
return 0; |
| 9259 |
} |
| 9260 |
|
| 9261 |
|
| 9262 |
|
| 9263 |
|
| 9264 |
|
| 9265 |
|
| 9266 |
|
| 9267 |
|
| 9268 |
|
| 9269 |
|
| 9270 |
|
| 9271 |
|
| 9272 |
public int computeHorizontalScrollOffset(State state) { |
| 9273 |
return 0; |
| 9274 |
} |
| 9275 |
|
| 9276 |
|
| 9277 |
|
| 9278 |
|
| 9279 |
|
| 9280 |
|
| 9281 |
|
| 9282 |
|
| 9283 |
|
| 9284 |
|
| 9285 |
|
| 9286 |
|
| 9287 |
public int computeHorizontalScrollRange(State state) { |
| 9288 |
return 0; |
| 9289 |
} |
| 9290 |
|
| 9291 |
|
| 9292 |
|
| 9293 |
|
| 9294 |
|
| 9295 |
|
| 9296 |
|
| 9297 |
|
| 9298 |
|
| 9299 |
|
| 9300 |
|
| 9301 |
|
| 9302 |
public int computeVerticalScrollExtent(State state) { |
| 9303 |
return 0; |
| 9304 |
} |
| 9305 |
|
| 9306 |
|
| 9307 |
|
| 9308 |
|
| 9309 |
|
| 9310 |
|
| 9311 |
|
| 9312 |
|
| 9313 |
|
| 9314 |
|
| 9315 |
|
| 9316 |
|
| 9317 |
public int computeVerticalScrollOffset(State state) { |
| 9318 |
return 0; |
| 9319 |
} |
| 9320 |
|
| 9321 |
|
| 9322 |
|
| 9323 |
|
| 9324 |
|
| 9325 |
|
| 9326 |
|
| 9327 |
|
| 9328 |
|
| 9329 |
|
| 9330 |
|
| 9331 |
|
| 9332 |
public int computeVerticalScrollRange(State state) { |
| 9333 |
return 0; |
| 9334 |
} |
| 9335 |
|
| 9336 |
|
| 9337 |
|
| 9338 |
|
| 9339 |
|
| 9340 |
|
| 9341 |
|
| 9342 |
|
| 9343 |
|
| 9344 |
|
| 9345 |
|
| 9346 |
|
| 9347 |
|
| 9348 |
|
| 9349 |
|
| 9350 |
public void onMeasure(Recycler recycler, State state, int widthSpec, int heightSpec) { |
| 9351 |
mRecyclerView.defaultOnMeasure(widthSpec, heightSpec); |
| 9352 |
} |
| 9353 |
|
| 9354 |
|
| 9355 |
|
| 9356 |
|
| 9357 |
|
| 9358 |
|
| 9359 |
|
| 9360 |
|
| 9361 |
public void setMeasuredDimension(int widthSize, int heightSize) { |
| 9362 |
mRecyclerView.setMeasuredDimension(widthSize, heightSize); |
| 9363 |
} |
| 9364 |
|
| 9365 |
|
| 9366 |
|
| 9367 |
|
| 9368 |
public int getMinimumWidth() { |
| 9369 |
return mRecyclerView.getMinimumWidth(); |
| 9370 |
} |
| 9371 |
|
| 9372 |
|
| 9373 |
|
| 9374 |
|
| 9375 |
public int getMinimumHeight() { |
| 9376 |
return mRecyclerView.getMinimumHeight(); |
| 9377 |
} |
| 9378 |
|
| 9379 |
|
| 9380 |
|
| 9381 |
|
| 9382 |
|
| 9383 |
|
| 9384 |
|
| 9385 |
|
| 9386 |
|
| 9387 |
|
| 9388 |
public Parcelable onSaveInstanceState() { |
| 9389 |
return null; |
| 9390 |
} |
| 9391 |
|
| 9392 |
|
| 9393 |
public void onRestoreInstanceState(Parcelable state) { |
| 9394 |
|
| 9395 |
} |
| 9396 |
|
| 9397 |
void stopSmoothScroller() { |
| 9398 |
if (mSmoothScroller != null) { |
| 9399 |
mSmoothScroller.stop(); |
| 9400 |
} |
| 9401 |
} |
| 9402 |
|
| 9403 |
private void onSmoothScrollerStopped(SmoothScroller smoothScroller) { |
| 9404 |
if (mSmoothScroller == smoothScroller) { |
| 9405 |
mSmoothScroller = null; |
| 9406 |
} |
| 9407 |
} |
| 9408 |
|
| 9409 |
|
| 9410 |
|
| 9411 |
|
| 9412 |
|
| 9413 |
|
| 9414 |
public void onScrollStateChanged(int state) { |
| 9415 |
} |
| 9416 |
|
| 9417 |
|
| 9418 |
|
| 9419 |
|
| 9420 |
|
| 9421 |
|
| 9422 |
|
| 9423 |
|
| 9424 |
|
| 9425 |
|
| 9426 |
|
| 9427 |
|
| 9428 |
|
| 9429 |
public void removeAndRecycleAllViews(Recycler recycler) { |
| 9430 |
for (int i = getChildCount() - 1; i >= 0; i--) { |
| 9431 |
final View view = getChildAt(i); |
| 9432 |
if (!getChildViewHolderInt(view).shouldIgnore()) { |
| 9433 |
removeAndRecycleViewAt(i, recycler); |
| 9434 |
} |
| 9435 |
} |
| 9436 |
} |
| 9437 |
|
| 9438 |
|
| 9439 |
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 9440 |
onInitializeAccessibilityNodeInfo(mRecyclerView.mRecycler, mRecyclerView.mState, info); |
| 9441 |
} |
| 9442 |
|
| 9443 |
|
| 9444 |
|
| 9445 |
|
| 9446 |
|
| 9447 |
|
| 9448 |
|
| 9449 |
|
| 9450 |
|
| 9451 |
|
| 9452 |
|
| 9453 |
|
| 9454 |
|
| 9455 |
|
| 9456 |
|
| 9457 |
|
| 9458 |
|
| 9459 |
|
| 9460 |
|
| 9461 |
|
| 9462 |
|
| 9463 |
|
| 9464 |
|
| 9465 |
|
| 9466 |
|
| 9467 |
|
| 9468 |
public void onInitializeAccessibilityNodeInfo(Recycler recycler, State state, |
| 9469 |
AccessibilityNodeInfo info) { |
| 9470 |
if (mRecyclerView.canScrollVertically(-1) |
| 9471 |
|| mRecyclerView.canScrollHorizontally(-1)) { |
| 9472 |
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD); |
| 9473 |
info.setScrollable(true); |
| 9474 |
} |
| 9475 |
if (mRecyclerView.canScrollVertically(1) |
| 9476 |
|| mRecyclerView.canScrollHorizontally(1)) { |
| 9477 |
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); |
| 9478 |
info.setScrollable(true); |
| 9479 |
} |
| 9480 |
final AccessibilityNodeInfo.CollectionInfo collectionInfo = |
| 9481 |
AccessibilityNodeInfo.CollectionInfo |
| 9482 |
.obtain(getRowCountForAccessibility(recycler, state), |
| 9483 |
getColumnCountForAccessibility(recycler, state), |
| 9484 |
isLayoutHierarchical(recycler, state), |
| 9485 |
getSelectionModeForAccessibility(recycler, state)); |
| 9486 |
info.setCollectionInfo(collectionInfo); |
| 9487 |
} |
| 9488 |
|
| 9489 |
|
| 9490 |
public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 9491 |
onInitializeAccessibilityEvent(mRecyclerView.mRecycler, mRecyclerView.mState, event); |
| 9492 |
} |
| 9493 |
|
| 9494 |
|
| 9495 |
|
| 9496 |
|
| 9497 |
|
| 9498 |
|
| 9499 |
|
| 9500 |
|
| 9501 |
|
| 9502 |
|
| 9503 |
|
| 9504 |
|
| 9505 |
public void onInitializeAccessibilityEvent(Recycler recycler, State state, |
| 9506 |
AccessibilityEvent event) { |
| 9507 |
if (mRecyclerView == null || event == null) { |
| 9508 |
return; |
| 9509 |
} |
| 9510 |
event.setScrollable(mRecyclerView.canScrollVertically(1) |
| 9511 |
|| mRecyclerView.canScrollVertically(-1) |
| 9512 |
|| mRecyclerView.canScrollHorizontally(-1) |
| 9513 |
|| mRecyclerView.canScrollHorizontally(1)); |
| 9514 |
|
| 9515 |
if (mRecyclerView.mAdapter != null) { |
| 9516 |
event.setItemCount(mRecyclerView.mAdapter.getItemCount()); |
| 9517 |
} |
| 9518 |
} |
| 9519 |
|
| 9520 |
|
| 9521 |
void onInitializeAccessibilityNodeInfoForItem(View host, AccessibilityNodeInfo info) { |
| 9522 |
final ViewHolder vh = getChildViewHolderInt(host); |
| 9523 |
|
| 9524 |
if (vh != null && !vh.isRemoved() && !mChildHelper.isHidden(vh.itemView)) { |
| 9525 |
onInitializeAccessibilityNodeInfoForItem(mRecyclerView.mRecycler, |
| 9526 |
mRecyclerView.mState, host, info); |
| 9527 |
} |
| 9528 |
} |
| 9529 |
|
| 9530 |
|
| 9531 |
|
| 9532 |
|
| 9533 |
|
| 9534 |
|
| 9535 |
|
| 9536 |
|
| 9537 |
|
| 9538 |
|
| 9539 |
|
| 9540 |
|
| 9541 |
|
| 9542 |
|
| 9543 |
|
| 9544 |
public void onInitializeAccessibilityNodeInfoForItem(Recycler recycler, State state, |
| 9545 |
View host, AccessibilityNodeInfo info) { |
| 9546 |
int rowIndexGuess = canScrollVertically() ? getPosition(host) : 0; |
| 9547 |
int columnIndexGuess = canScrollHorizontally() ? getPosition(host) : 0; |
| 9548 |
final AccessibilityNodeInfo.CollectionItemInfo itemInfo = |
| 9549 |
AccessibilityNodeInfo.CollectionItemInfo.obtain(rowIndexGuess, 1, |
| 9550 |
columnIndexGuess, 1, false, false); |
| 9551 |
info.setCollectionItemInfo(itemInfo); |
| 9552 |
} |
| 9553 |
|
| 9554 |
|
| 9555 |
|
| 9556 |
|
| 9557 |
|
| 9558 |
|
| 9559 |
|
| 9560 |
|
| 9561 |
|
| 9562 |
|
| 9563 |
|
| 9564 |
public void requestSimpleAnimationsInNextLayout() { |
| 9565 |
mRequestedSimpleAnimations = true; |
| 9566 |
} |
| 9567 |
|
| 9568 |
|
| 9569 |
|
| 9570 |
|
| 9571 |
|
| 9572 |
|
| 9573 |
|
| 9574 |
|
| 9575 |
|
| 9576 |
|
| 9577 |
|
| 9578 |
|
| 9579 |
|
| 9580 |
|
| 9581 |
|
| 9582 |
|
| 9583 |
public int getSelectionModeForAccessibility(Recycler recycler, State state) { |
| 9584 |
return AccessibilityNodeInfo.CollectionInfo.SELECTION_MODE_NONE; |
| 9585 |
} |
| 9586 |
|
| 9587 |
|
| 9588 |
|
| 9589 |
|
| 9590 |
|
| 9591 |
|
| 9592 |
|
| 9593 |
|
| 9594 |
|
| 9595 |
|
| 9596 |
|
| 9597 |
|
| 9598 |
|
| 9599 |
public int getRowCountForAccessibility(Recycler recycler, State state) { |
| 9600 |
if (mRecyclerView == null || mRecyclerView.mAdapter == null) { |
| 9601 |
return 1; |
| 9602 |
} |
| 9603 |
return canScrollVertically() ? mRecyclerView.mAdapter.getItemCount() : 1; |
| 9604 |
} |
| 9605 |
|
| 9606 |
|
| 9607 |
|
| 9608 |
|
| 9609 |
|
| 9610 |
|
| 9611 |
|
| 9612 |
|
| 9613 |
|
| 9614 |
|
| 9615 |
|
| 9616 |
|
| 9617 |
|
| 9618 |
public int getColumnCountForAccessibility(Recycler recycler, State state) { |
| 9619 |
if (mRecyclerView == null || mRecyclerView.mAdapter == null) { |
| 9620 |
return 1; |
| 9621 |
} |
| 9622 |
return canScrollHorizontally() ? mRecyclerView.mAdapter.getItemCount() : 1; |
| 9623 |
} |
| 9624 |
|
| 9625 |
|
| 9626 |
|
| 9627 |
|
| 9628 |
|
| 9629 |
|
| 9630 |
|
| 9631 |
|
| 9632 |
|
| 9633 |
|
| 9634 |
|
| 9635 |
public boolean isLayoutHierarchical(Recycler recycler, State state) { |
| 9636 |
return false; |
| 9637 |
} |
| 9638 |
|
| 9639 |
|
| 9640 |
boolean performAccessibilityAction(int action, Bundle args) { |
| 9641 |
return performAccessibilityAction(mRecyclerView.mRecycler, mRecyclerView.mState, |
| 9642 |
action, args); |
| 9643 |
} |
| 9644 |
|
| 9645 |
|
| 9646 |
|
| 9647 |
|
| 9648 |
|
| 9649 |
|
| 9650 |
|
| 9651 |
|
| 9652 |
|
| 9653 |
|
| 9654 |
|
| 9655 |
public boolean performAccessibilityAction(Recycler recycler, State state, int action, |
| 9656 |
Bundle args) { |
| 9657 |
if (mRecyclerView == null) { |
| 9658 |
return false; |
| 9659 |
} |
| 9660 |
int vScroll = 0, hScroll = 0; |
| 9661 |
switch (action) { |
| 9662 |
case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: |
| 9663 |
if (mRecyclerView.canScrollVertically(-1)) { |
| 9664 |
vScroll = -(getHeight() - getPaddingTop() - getPaddingBottom()); |
| 9665 |
} |
| 9666 |
if (mRecyclerView.canScrollHorizontally(-1)) { |
| 9667 |
hScroll = -(getWidth() - getPaddingLeft() - getPaddingRight()); |
| 9668 |
} |
| 9669 |
break; |
| 9670 |
case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: |
| 9671 |
if (mRecyclerView.canScrollVertically(1)) { |
| 9672 |
vScroll = getHeight() - getPaddingTop() - getPaddingBottom(); |
| 9673 |
} |
| 9674 |
if (mRecyclerView.canScrollHorizontally(1)) { |
| 9675 |
hScroll = getWidth() - getPaddingLeft() - getPaddingRight(); |
| 9676 |
} |
| 9677 |
break; |
| 9678 |
} |
| 9679 |
if (vScroll == 0 && hScroll == 0) { |
| 9680 |
return false; |
| 9681 |
} |
| 9682 |
mRecyclerView.smoothScrollBy(hScroll, vScroll); |
| 9683 |
return true; |
| 9684 |
} |
| 9685 |
|
| 9686 |
|
| 9687 |
boolean performAccessibilityActionForItem(View view, int action, Bundle args) { |
| 9688 |
return performAccessibilityActionForItem(mRecyclerView.mRecycler, mRecyclerView.mState, |
| 9689 |
view, action, args); |
| 9690 |
} |
| 9691 |
|
| 9692 |
|
| 9693 |
|
| 9694 |
|
| 9695 |
|
| 9696 |
|
| 9697 |
|
| 9698 |
|
| 9699 |
|
| 9700 |
|
| 9701 |
|
| 9702 |
|
| 9703 |
|
| 9704 |
|
| 9705 |
|
| 9706 |
|
| 9707 |
public boolean performAccessibilityActionForItem(Recycler recycler, State state, View view, |
| 9708 |
int action, Bundle args) { |
| 9709 |
return false; |
| 9710 |
} |
| 9711 |
|
| 9712 |
|
| 9713 |
|
| 9714 |
|
| 9715 |
|
| 9716 |
|
| 9717 |
public static Properties getProperties(Context context, AttributeSet attrs, |
| 9718 |
int defStyleAttr, int defStyleRes) { |
| 9719 |
Properties properties = new Properties(); |
| 9720 |
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView, |
| 9721 |
defStyleAttr, defStyleRes); |
| 9722 |
properties.orientation = a.getInt(R.styleable.RecyclerView_orientation, VERTICAL); |
| 9723 |
properties.spanCount = a.getInt(R.styleable.RecyclerView_spanCount, 1); |
| 9724 |
properties.reverseLayout = a.getBoolean(R.styleable.RecyclerView_reverseLayout, false); |
| 9725 |
properties.stackFromEnd = a.getBoolean(R.styleable.RecyclerView_stackFromEnd, false); |
| 9726 |
a.recycle(); |
| 9727 |
return properties; |
| 9728 |
} |
| 9729 |
|
| 9730 |
void setExactMeasureSpecsFrom(RecyclerView recyclerView) { |
| 9731 |
setMeasureSpecs( |
| 9732 |
MeasureSpec.makeMeasureSpec(recyclerView.getWidth(), MeasureSpec.EXACTLY), |
| 9733 |
MeasureSpec.makeMeasureSpec(recyclerView.getHeight(), MeasureSpec.EXACTLY) |
| 9734 |
); |
| 9735 |
} |
| 9736 |
|
| 9737 |
|
| 9738 |
|
| 9739 |
|
| 9740 |
|
| 9741 |
|
| 9742 |
|
| 9743 |
|
| 9744 |
|
| 9745 |
|
| 9746 |
|
| 9747 |
boolean shouldMeasureTwice() { |
| 9748 |
return false; |
| 9749 |
} |
| 9750 |
|
| 9751 |
boolean hasFlexibleChildInBothOrientations() { |
| 9752 |
final int childCount = getChildCount(); |
| 9753 |
for (int i = 0; i < childCount; i++) { |
| 9754 |
final View child = getChildAt(i); |
| 9755 |
final ViewGroup.LayoutParams lp = child.getLayoutParams(); |
| 9756 |
if (lp.width < 0 && lp.height < 0) { |
| 9757 |
return true; |
| 9758 |
} |
| 9759 |
} |
| 9760 |
return false; |
| 9761 |
} |
| 9762 |
|
| 9763 |
|
| 9764 |
|
| 9765 |
|
| 9766 |
public static class Properties { |
| 9767 |
|
| 9768 |
public int orientation; |
| 9769 |
|
| 9770 |
public int spanCount; |
| 9771 |
|
| 9772 |
public boolean reverseLayout; |
| 9773 |
|
| 9774 |
public boolean stackFromEnd; |
| 9775 |
} |
| 9776 |
} |
| 9777 |
|
| 9778 |
|
| 9779 |
|
| 9780 |
|
| 9781 |
|
| 9782 |
|
| 9783 |
|
| 9784 |
|
| 9785 |
|
| 9786 |
|
| 9787 |
|
| 9788 |
public abstract static class ItemDecoration { |
| 9789 |
|
| 9790 |
|
| 9791 |
|
| 9792 |
|
| 9793 |
|
| 9794 |
|
| 9795 |
|
| 9796 |
|
| 9797 |
|
| 9798 |
public void onDraw(Canvas c, RecyclerView parent, State state) { |
| 9799 |
onDraw(c, parent); |
| 9800 |
} |
| 9801 |
|
| 9802 |
|
| 9803 |
|
| 9804 |
|
| 9805 |
|
| 9806 |
@Deprecated |
| 9807 |
public void onDraw(Canvas c, RecyclerView parent) { |
| 9808 |
} |
| 9809 |
|
| 9810 |
|
| 9811 |
|
| 9812 |
|
| 9813 |
|
| 9814 |
|
| 9815 |
|
| 9816 |
|
| 9817 |
|
| 9818 |
|
| 9819 |
public void onDrawOver(Canvas c, RecyclerView parent, State state) { |
| 9820 |
onDrawOver(c, parent); |
| 9821 |
} |
| 9822 |
|
| 9823 |
|
| 9824 |
|
| 9825 |
|
| 9826 |
|
| 9827 |
@Deprecated |
| 9828 |
public void onDrawOver(Canvas c, RecyclerView parent) { |
| 9829 |
} |
| 9830 |
|
| 9831 |
|
| 9832 |
|
| 9833 |
|
| 9834 |
|
| 9835 |
|
| 9836 |
@Deprecated |
| 9837 |
public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { |
| 9838 |
outRect.set(0, 0, 0, 0); |
| 9839 |
} |
| 9840 |
|
| 9841 |
|
| 9842 |
|
| 9843 |
|
| 9844 |
|
| 9845 |
|
| 9846 |
|
| 9847 |
|
| 9848 |
|
| 9849 |
|
| 9850 |
|
| 9851 |
|
| 9852 |
|
| 9853 |
|
| 9854 |
|
| 9855 |
|
| 9856 |
|
| 9857 |
|
| 9858 |
|
| 9859 |
|
| 9860 |
|
| 9861 |
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) { |
| 9862 |
getItemOffsets(outRect, ((LayoutParams) view.getLayoutParams()).getViewLayoutPosition(), |
| 9863 |
parent); |
| 9864 |
} |
| 9865 |
} |
| 9866 |
|
| 9867 |
|
| 9868 |
|
| 9869 |
|
| 9870 |
|
| 9871 |
|
| 9872 |
|
| 9873 |
|
| 9874 |
|
| 9875 |
|
| 9876 |
|
| 9877 |
|
| 9878 |
|
| 9879 |
public interface OnItemTouchListener { |
| 9880 |
|
| 9881 |
|
| 9882 |
|
| 9883 |
|
| 9884 |
|
| 9885 |
|
| 9886 |
|
| 9887 |
|
| 9888 |
|
| 9889 |
|
| 9890 |
|
| 9891 |
|
| 9892 |
|
| 9893 |
|
| 9894 |
boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e); |
| 9895 |
|
| 9896 |
|
| 9897 |
|
| 9898 |
|
| 9899 |
|
| 9900 |
|
| 9901 |
|
| 9902 |
|
| 9903 |
void onTouchEvent(RecyclerView rv, MotionEvent e); |
| 9904 |
|
| 9905 |
|
| 9906 |
|
| 9907 |
|
| 9908 |
|
| 9909 |
|
| 9910 |
|
| 9911 |
|
| 9912 |
|
| 9913 |
|
| 9914 |
void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept); |
| 9915 |
} |
| 9916 |
|
| 9917 |
|
| 9918 |
|
| 9919 |
|
| 9920 |
|
| 9921 |
|
| 9922 |
|
| 9923 |
|
| 9924 |
|
| 9925 |
|
| 9926 |
public static class SimpleOnItemTouchListener implements RecyclerView.OnItemTouchListener { |
| 9927 |
@Override |
| 9928 |
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { |
| 9929 |
return false; |
| 9930 |
} |
| 9931 |
|
| 9932 |
@Override |
| 9933 |
public void onTouchEvent(RecyclerView rv, MotionEvent e) { |
| 9934 |
} |
| 9935 |
|
| 9936 |
@Override |
| 9937 |
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 9938 |
} |
| 9939 |
} |
| 9940 |
|
| 9941 |
|
| 9942 |
|
| 9943 |
|
| 9944 |
|
| 9945 |
|
| 9946 |
|
| 9947 |
|
| 9948 |
|
| 9949 |
|
| 9950 |
public abstract static class OnScrollListener { |
| 9951 |
|
| 9952 |
|
| 9953 |
|
| 9954 |
|
| 9955 |
|
| 9956 |
|
| 9957 |
|
| 9958 |
public void onScrollStateChanged(RecyclerView recyclerView, int newState){} |
| 9959 |
|
| 9960 |
|
| 9961 |
|
| 9962 |
|
| 9963 |
|
| 9964 |
|
| 9965 |
|
| 9966 |
|
| 9967 |
|
| 9968 |
|
| 9969 |
|
| 9970 |
|
| 9971 |
public void onScrolled(RecyclerView recyclerView, int dx, int dy){} |
| 9972 |
} |
| 9973 |
|
| 9974 |
|
| 9975 |
|
| 9976 |
|
| 9977 |
|
| 9978 |
|
| 9979 |
|
| 9980 |
public interface RecyclerListener { |
| 9981 |
|
| 9982 |
|
| 9983 |
|
| 9984 |
|
| 9985 |
|
| 9986 |
|
| 9987 |
|
| 9988 |
|
| 9989 |
|
| 9990 |
|
| 9991 |
|
| 9992 |
void onViewRecycled(ViewHolder holder); |
| 9993 |
} |
| 9994 |
|
| 9995 |
|
| 9996 |
|
| 9997 |
|
| 9998 |
|
| 9999 |
public interface OnChildAttachStateChangeListener { |
| 10000 |
|
| 10001 |
|
| 10002 |
|
| 10003 |
|
| 10004 |
|
| 10005 |
|
| 10006 |
void onChildViewAttachedToWindow(View view); |
| 10007 |
|
| 10008 |
|
| 10009 |
|
| 10010 |
|
| 10011 |
|
| 10012 |
|
| 10013 |
void onChildViewDetachedFromWindow(View view); |
| 10014 |
} |
| 10015 |
|
| 10016 |
|
| 10017 |
|
| 10018 |
|
| 10019 |
|
| 10020 |
|
| 10021 |
|
| 10022 |
|
| 10023 |
|
| 10024 |
|
| 10025 |
|
| 10026 |
|
| 10027 |
|
| 10028 |
|
| 10029 |
public abstract static class ViewHolder { |
| 10030 |
public final View itemView; |
| 10031 |
WeakReference<RecyclerView> mNestedRecyclerView; |
| 10032 |
int mPosition = NO_POSITION; |
| 10033 |
int mOldPosition = NO_POSITION; |
| 10034 |
long mItemId = NO_ID; |
| 10035 |
int mItemViewType = INVALID_TYPE; |
| 10036 |
int mPreLayoutPosition = NO_POSITION; |
| 10037 |
|
| 10038 |
|
| 10039 |
ViewHolder mShadowedHolder = null; |
| 10040 |
|
| 10041 |
ViewHolder mShadowingHolder = null; |
| 10042 |
|
| 10043 |
|
| 10044 |
|
| 10045 |
|
| 10046 |
|
| 10047 |
static final int FLAG_BOUND = 1 << 0; |
| 10048 |
|
| 10049 |
|
| 10050 |
|
| 10051 |
|
| 10052 |
|
| 10053 |
static final int FLAG_UPDATE = 1 << 1; |
| 10054 |
|
| 10055 |
|
| 10056 |
|
| 10057 |
|
| 10058 |
|
| 10059 |
|
| 10060 |
static final int FLAG_INVALID = 1 << 2; |
| 10061 |
|
| 10062 |
|
| 10063 |
|
| 10064 |
|
| 10065 |
|
| 10066 |
static final int FLAG_REMOVED = 1 << 3; |
| 10067 |
|
| 10068 |
|
| 10069 |
|
| 10070 |
|
| 10071 |
|
| 10072 |
static final int FLAG_NOT_RECYCLABLE = 1 << 4; |
| 10073 |
|
| 10074 |
|
| 10075 |
|
| 10076 |
|
| 10077 |
|
| 10078 |
|
| 10079 |
|
| 10080 |
static final int FLAG_RETURNED_FROM_SCRAP = 1 << 5; |
| 10081 |
|
| 10082 |
|
| 10083 |
|
| 10084 |
|
| 10085 |
|
| 10086 |
|
| 10087 |
static final int FLAG_IGNORE = 1 << 7; |
| 10088 |
|
| 10089 |
|
| 10090 |
|
| 10091 |
|
| 10092 |
|
| 10093 |
static final int FLAG_TMP_DETACHED = 1 << 8; |
| 10094 |
|
| 10095 |
|
| 10096 |
|
| 10097 |
|
| 10098 |
|
| 10099 |
|
| 10100 |
|
| 10101 |
|
| 10102 |
static final int FLAG_ADAPTER_POSITION_UNKNOWN = 1 << 9; |
| 10103 |
|
| 10104 |
|
| 10105 |
|
| 10106 |
|
| 10107 |
static final int FLAG_ADAPTER_FULLUPDATE = 1 << 10; |
| 10108 |
|
| 10109 |
|
| 10110 |
|
| 10111 |
|
| 10112 |
static final int FLAG_MOVED = 1 << 11; |
| 10113 |
|
| 10114 |
|
| 10115 |
|
| 10116 |
|
| 10117 |
static final int FLAG_APPEARED_IN_PRE_LAYOUT = 1 << 12; |
| 10118 |
|
| 10119 |
static final int PENDING_ACCESSIBILITY_STATE_NOT_SET = -1; |
| 10120 |
|
| 10121 |
|
| 10122 |
|
| 10123 |
|
| 10124 |
|
| 10125 |
|
| 10126 |
|
| 10127 |
|
| 10128 |
|
| 10129 |
|
| 10130 |
|
| 10131 |
|
| 10132 |
|
| 10133 |
|
| 10134 |
static final int FLAG_BOUNCED_FROM_HIDDEN_LIST = 1 << 13; |
| 10135 |
|
| 10136 |
private int mFlags; |
| 10137 |
|
| 10138 |
private static final List<Object> FULLUPDATE_PAYLOADS = Collections.EMPTY_LIST; |
| 10139 |
|
| 10140 |
List<Object> mPayloads = null; |
| 10141 |
List<Object> mUnmodifiedPayloads = null; |
| 10142 |
|
| 10143 |
private int mIsRecyclableCount = 0; |
| 10144 |
|
| 10145 |
|
| 10146 |
|
| 10147 |
private Recycler mScrapContainer = null; |
| 10148 |
|
| 10149 |
private boolean mInChangeScrap = false; |
| 10150 |
|
| 10151 |
|
| 10152 |
|
| 10153 |
private int mWasImportantForAccessibilityBeforeHidden = |
| 10154 |
View.IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 10155 |
|
| 10156 |
@VisibleForTesting |
| 10157 |
int mPendingAccessibilityState = PENDING_ACCESSIBILITY_STATE_NOT_SET; |
| 10158 |
|
| 10159 |
|
| 10160 |
|
| 10161 |
|
| 10162 |
|
| 10163 |
RecyclerView mOwnerRecyclerView; |
| 10164 |
|
| 10165 |
public ViewHolder(View itemView) { |
| 10166 |
if (itemView == null) { |
| 10167 |
throw new IllegalArgumentException("itemView may not be null"); |
| 10168 |
} |
| 10169 |
this.itemView = itemView; |
| 10170 |
} |
| 10171 |
|
| 10172 |
void flagRemovedAndOffsetPosition(int mNewPosition, int offset, boolean applyToPreLayout) { |
| 10173 |
addFlags(ViewHolder.FLAG_REMOVED); |
| 10174 |
offsetPosition(offset, applyToPreLayout); |
| 10175 |
mPosition = mNewPosition; |
| 10176 |
} |
| 10177 |
|
| 10178 |
void offsetPosition(int offset, boolean applyToPreLayout) { |
| 10179 |
if (mOldPosition == NO_POSITION) { |
| 10180 |
mOldPosition = mPosition; |
| 10181 |
} |
| 10182 |
if (mPreLayoutPosition == NO_POSITION) { |
| 10183 |
mPreLayoutPosition = mPosition; |
| 10184 |
} |
| 10185 |
if (applyToPreLayout) { |
| 10186 |
mPreLayoutPosition += offset; |
| 10187 |
} |
| 10188 |
mPosition += offset; |
| 10189 |
if (itemView.getLayoutParams() != null) { |
| 10190 |
((LayoutParams) itemView.getLayoutParams()).mInsetsDirty = true; |
| 10191 |
} |
| 10192 |
} |
| 10193 |
|
| 10194 |
void clearOldPosition() { |
| 10195 |
mOldPosition = NO_POSITION; |
| 10196 |
mPreLayoutPosition = NO_POSITION; |
| 10197 |
} |
| 10198 |
|
| 10199 |
void saveOldPosition() { |
| 10200 |
if (mOldPosition == NO_POSITION) { |
| 10201 |
mOldPosition = mPosition; |
| 10202 |
} |
| 10203 |
} |
| 10204 |
|
| 10205 |
boolean shouldIgnore() { |
| 10206 |
return (mFlags & FLAG_IGNORE) != 0; |
| 10207 |
} |
| 10208 |
|
| 10209 |
|
| 10210 |
|
| 10211 |
|
| 10212 |
|
| 10213 |
|
| 10214 |
|
| 10215 |
|
| 10216 |
|
| 10217 |
@Deprecated |
| 10218 |
public final int getPosition() { |
| 10219 |
return mPreLayoutPosition == NO_POSITION ? mPosition : mPreLayoutPosition; |
| 10220 |
} |
| 10221 |
|
| 10222 |
|
| 10223 |
|
| 10224 |
|
| 10225 |
|
| 10226 |
|
| 10227 |
|
| 10228 |
|
| 10229 |
|
| 10230 |
|
| 10231 |
|
| 10232 |
|
| 10233 |
|
| 10234 |
|
| 10235 |
|
| 10236 |
|
| 10237 |
|
| 10238 |
|
| 10239 |
|
| 10240 |
|
| 10241 |
|
| 10242 |
|
| 10243 |
|
| 10244 |
public final int getLayoutPosition() { |
| 10245 |
return mPreLayoutPosition == NO_POSITION ? mPosition : mPreLayoutPosition; |
| 10246 |
} |
| 10247 |
|
| 10248 |
|
| 10249 |
|
| 10250 |
|
| 10251 |
|
| 10252 |
|
| 10253 |
|
| 10254 |
|
| 10255 |
|
| 10256 |
|
| 10257 |
|
| 10258 |
|
| 10259 |
|
| 10260 |
|
| 10261 |
|
| 10262 |
|
| 10263 |
|
| 10264 |
|
| 10265 |
|
| 10266 |
|
| 10267 |
|
| 10268 |
|
| 10269 |
|
| 10270 |
public final int getAdapterPosition() { |
| 10271 |
if (mOwnerRecyclerView == null) { |
| 10272 |
return NO_POSITION; |
| 10273 |
} |
| 10274 |
return mOwnerRecyclerView.getAdapterPositionFor(this); |
| 10275 |
} |
| 10276 |
|
| 10277 |
|
| 10278 |
|
| 10279 |
|
| 10280 |
|
| 10281 |
|
| 10282 |
|
| 10283 |
|
| 10284 |
|
| 10285 |
|
| 10286 |
|
| 10287 |
|
| 10288 |
public final int getOldPosition() { |
| 10289 |
return mOldPosition; |
| 10290 |
} |
| 10291 |
|
| 10292 |
|
| 10293 |
|
| 10294 |
|
| 10295 |
|
| 10296 |
|
| 10297 |
|
| 10298 |
public final long getItemId() { |
| 10299 |
return mItemId; |
| 10300 |
} |
| 10301 |
|
| 10302 |
|
| 10303 |
|
| 10304 |
|
| 10305 |
public final int getItemViewType() { |
| 10306 |
return mItemViewType; |
| 10307 |
} |
| 10308 |
|
| 10309 |
boolean isScrap() { |
| 10310 |
return mScrapContainer != null; |
| 10311 |
} |
| 10312 |
|
| 10313 |
void unScrap() { |
| 10314 |
mScrapContainer.unscrapView(this); |
| 10315 |
} |
| 10316 |
|
| 10317 |
boolean wasReturnedFromScrap() { |
| 10318 |
return (mFlags & FLAG_RETURNED_FROM_SCRAP) != 0; |
| 10319 |
} |
| 10320 |
|
| 10321 |
void clearReturnedFromScrapFlag() { |
| 10322 |
mFlags = mFlags & ~FLAG_RETURNED_FROM_SCRAP; |
| 10323 |
} |
| 10324 |
|
| 10325 |
void clearTmpDetachFlag() { |
| 10326 |
mFlags = mFlags & ~FLAG_TMP_DETACHED; |
| 10327 |
} |
| 10328 |
|
| 10329 |
void stopIgnoring() { |
| 10330 |
mFlags = mFlags & ~FLAG_IGNORE; |
| 10331 |
} |
| 10332 |
|
| 10333 |
void setScrapContainer(Recycler recycler, boolean isChangeScrap) { |
| 10334 |
mScrapContainer = recycler; |
| 10335 |
mInChangeScrap = isChangeScrap; |
| 10336 |
} |
| 10337 |
|
| 10338 |
boolean isInvalid() { |
| 10339 |
return (mFlags & FLAG_INVALID) != 0; |
| 10340 |
} |
| 10341 |
|
| 10342 |
boolean needsUpdate() { |
| 10343 |
return (mFlags & FLAG_UPDATE) != 0; |
| 10344 |
} |
| 10345 |
|
| 10346 |
boolean isBound() { |
| 10347 |
return (mFlags & FLAG_BOUND) != 0; |
| 10348 |
} |
| 10349 |
|
| 10350 |
boolean isRemoved() { |
| 10351 |
return (mFlags & FLAG_REMOVED) != 0; |
| 10352 |
} |
| 10353 |
|
| 10354 |
boolean hasAnyOfTheFlags(int flags) { |
| 10355 |
return (mFlags & flags) != 0; |
| 10356 |
} |
| 10357 |
|
| 10358 |
boolean isTmpDetached() { |
| 10359 |
return (mFlags & FLAG_TMP_DETACHED) != 0; |
| 10360 |
} |
| 10361 |
|
| 10362 |
boolean isAdapterPositionUnknown() { |
| 10363 |
return (mFlags & FLAG_ADAPTER_POSITION_UNKNOWN) != 0 || isInvalid(); |
| 10364 |
} |
| 10365 |
|
| 10366 |
void setFlags(int flags, int mask) { |
| 10367 |
mFlags = (mFlags & ~mask) | (flags & mask); |
| 10368 |
} |
| 10369 |
|
| 10370 |
void addFlags(int flags) { |
| 10371 |
mFlags |= flags; |
| 10372 |
} |
| 10373 |
|
| 10374 |
void addChangePayload(Object payload) { |
| 10375 |
if (payload == null) { |
| 10376 |
addFlags(FLAG_ADAPTER_FULLUPDATE); |
| 10377 |
} else if ((mFlags & FLAG_ADAPTER_FULLUPDATE) == 0) { |
| 10378 |
createPayloadsIfNeeded(); |
| 10379 |
mPayloads.add(payload); |
| 10380 |
} |
| 10381 |
} |
| 10382 |
|
| 10383 |
private void createPayloadsIfNeeded() { |
| 10384 |
if (mPayloads == null) { |
| 10385 |
mPayloads = new ArrayList<Object>(); |
| 10386 |
mUnmodifiedPayloads = Collections.unmodifiableList(mPayloads); |
| 10387 |
} |
| 10388 |
} |
| 10389 |
|
| 10390 |
void clearPayload() { |
| 10391 |
if (mPayloads != null) { |
| 10392 |
mPayloads.clear(); |
| 10393 |
} |
| 10394 |
mFlags = mFlags & ~FLAG_ADAPTER_FULLUPDATE; |
| 10395 |
} |
| 10396 |
|
| 10397 |
List<Object> getUnmodifiedPayloads() { |
| 10398 |
if ((mFlags & FLAG_ADAPTER_FULLUPDATE) == 0) { |
| 10399 |
if (mPayloads == null || mPayloads.size() == 0) { |
| 10400 |
|
| 10401 |
return FULLUPDATE_PAYLOADS; |
| 10402 |
} |
| 10403 |
|
| 10404 |
return mUnmodifiedPayloads; |
| 10405 |
} else { |
| 10406 |
|
| 10407 |
return FULLUPDATE_PAYLOADS; |
| 10408 |
} |
| 10409 |
} |
| 10410 |
|
| 10411 |
void resetInternal() { |
| 10412 |
mFlags = 0; |
| 10413 |
mPosition = NO_POSITION; |
| 10414 |
mOldPosition = NO_POSITION; |
| 10415 |
mItemId = NO_ID; |
| 10416 |
mPreLayoutPosition = NO_POSITION; |
| 10417 |
mIsRecyclableCount = 0; |
| 10418 |
mShadowedHolder = null; |
| 10419 |
mShadowingHolder = null; |
| 10420 |
clearPayload(); |
| 10421 |
mWasImportantForAccessibilityBeforeHidden = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 10422 |
mPendingAccessibilityState = PENDING_ACCESSIBILITY_STATE_NOT_SET; |
| 10423 |
clearNestedRecyclerViewIfNotNested(this); |
| 10424 |
} |
| 10425 |
|
| 10426 |
|
| 10427 |
|
| 10428 |
|
| 10429 |
private void onEnteredHiddenState(RecyclerView parent) { |
| 10430 |
|
| 10431 |
mWasImportantForAccessibilityBeforeHidden = |
| 10432 |
itemView.getImportantForAccessibility(); |
| 10433 |
parent.setChildImportantForAccessibilityInternal(this, |
| 10434 |
View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); |
| 10435 |
} |
| 10436 |
|
| 10437 |
|
| 10438 |
|
| 10439 |
|
| 10440 |
private void onLeftHiddenState(RecyclerView parent) { |
| 10441 |
parent.setChildImportantForAccessibilityInternal(this, |
| 10442 |
mWasImportantForAccessibilityBeforeHidden); |
| 10443 |
mWasImportantForAccessibilityBeforeHidden = View.IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 10444 |
} |
| 10445 |
|
| 10446 |
@Override |
| 10447 |
public String toString() { |
| 10448 |
final StringBuilder sb = new StringBuilder("ViewHolder{" |
| 10449 |
+ Integer.toHexString(hashCode()) + " position=" + mPosition + " id=" + mItemId |
| 10450 |
+ ", oldPos=" + mOldPosition + ", pLpos:" + mPreLayoutPosition); |
| 10451 |
if (isScrap()) { |
| 10452 |
sb.append(" scrap ") |
| 10453 |
.append(mInChangeScrap ? "[changeScrap]" : "[attachedScrap]"); |
| 10454 |
} |
| 10455 |
if (isInvalid()) sb.append(" invalid"); |
| 10456 |
if (!isBound()) sb.append(" unbound"); |
| 10457 |
if (needsUpdate()) sb.append(" update"); |
| 10458 |
if (isRemoved()) sb.append(" removed"); |
| 10459 |
if (shouldIgnore()) sb.append(" ignored"); |
| 10460 |
if (isTmpDetached()) sb.append(" tmpDetached"); |
| 10461 |
if (!isRecyclable()) sb.append(" not recyclable(" + mIsRecyclableCount + ")"); |
| 10462 |
if (isAdapterPositionUnknown()) sb.append(" undefined adapter position"); |
| 10463 |
|
| 10464 |
if (itemView.getParent() == null) sb.append(" no parent"); |
| 10465 |
sb.append("}"); |
| 10466 |
return sb.toString(); |
| 10467 |
} |
| 10468 |
|
| 10469 |
|
| 10470 |
|
| 10471 |
|
| 10472 |
|
| 10473 |
|
| 10474 |
|
| 10475 |
|
| 10476 |
|
| 10477 |
|
| 10478 |
|
| 10479 |
|
| 10480 |
|
| 10481 |
|
| 10482 |
public final void setIsRecyclable(boolean recyclable) { |
| 10483 |
mIsRecyclableCount = recyclable ? mIsRecyclableCount - 1 : mIsRecyclableCount + 1; |
| 10484 |
if (mIsRecyclableCount < 0) { |
| 10485 |
mIsRecyclableCount = 0; |
| 10486 |
if (DEBUG) { |
| 10487 |
throw new RuntimeException("isRecyclable decremented below 0: " |
| 10488 |
+ "unmatched pair of setIsRecyable() calls for " + this); |
| 10489 |
} |
| 10490 |
Log.e(VIEW_LOG_TAG, "isRecyclable decremented below 0: " |
| 10491 |
+ "unmatched pair of setIsRecyable() calls for " + this); |
| 10492 |
} else if (!recyclable && mIsRecyclableCount == 1) { |
| 10493 |
mFlags |= FLAG_NOT_RECYCLABLE; |
| 10494 |
} else if (recyclable && mIsRecyclableCount == 0) { |
| 10495 |
mFlags &= ~FLAG_NOT_RECYCLABLE; |
| 10496 |
} |
| 10497 |
if (DEBUG) { |
| 10498 |
Log.d(TAG, "setIsRecyclable val:" + recyclable + ":" + this); |
| 10499 |
} |
| 10500 |
} |
| 10501 |
|
| 10502 |
|
| 10503 |
|
| 10504 |
|
| 10505 |
|
| 10506 |
|
| 10507 |
public final boolean isRecyclable() { |
| 10508 |
return (mFlags & FLAG_NOT_RECYCLABLE) == 0 |
| 10509 |
&& !itemView.hasTransientState(); |
| 10510 |
} |
| 10511 |
|
| 10512 |
|
| 10513 |
|
| 10514 |
|
| 10515 |
|
| 10516 |
private boolean shouldBeKeptAsChild() { |
| 10517 |
return (mFlags & FLAG_NOT_RECYCLABLE) != 0; |
| 10518 |
} |
| 10519 |
|
| 10520 |
|
| 10521 |
|
| 10522 |
|
| 10523 |
|
| 10524 |
private boolean doesTransientStatePreventRecycling() { |
| 10525 |
return (mFlags & FLAG_NOT_RECYCLABLE) == 0 && itemView.hasTransientState(); |
| 10526 |
} |
| 10527 |
|
| 10528 |
boolean isUpdated() { |
| 10529 |
return (mFlags & FLAG_UPDATE) != 0; |
| 10530 |
} |
| 10531 |
} |
| 10532 |
|
| 10533 |
|
| 10534 |
|
| 10535 |
|
| 10536 |
@VisibleForTesting |
| 10537 |
boolean setChildImportantForAccessibilityInternal(ViewHolder viewHolder, |
| 10538 |
int importantForAccessibility) { |
| 10539 |
if (isComputingLayout()) { |
| 10540 |
viewHolder.mPendingAccessibilityState = importantForAccessibility; |
| 10541 |
mPendingAccessibilityImportanceChange.add(viewHolder); |
| 10542 |
return false; |
| 10543 |
} |
| 10544 |
viewHolder.itemView.setImportantForAccessibility(importantForAccessibility); |
| 10545 |
return true; |
| 10546 |
} |
| 10547 |
|
| 10548 |
void dispatchPendingImportantForAccessibilityChanges() { |
| 10549 |
for (int i = mPendingAccessibilityImportanceChange.size() - 1; i >= 0; i--) { |
| 10550 |
ViewHolder viewHolder = mPendingAccessibilityImportanceChange.get(i); |
| 10551 |
if (viewHolder.itemView.getParent() != this || viewHolder.shouldIgnore()) { |
| 10552 |
continue; |
| 10553 |
} |
| 10554 |
int state = viewHolder.mPendingAccessibilityState; |
| 10555 |
if (state != ViewHolder.PENDING_ACCESSIBILITY_STATE_NOT_SET) { |
| 10556 |
|
| 10557 |
viewHolder.itemView.setImportantForAccessibility(state); |
| 10558 |
viewHolder.mPendingAccessibilityState = |
| 10559 |
ViewHolder.PENDING_ACCESSIBILITY_STATE_NOT_SET; |
| 10560 |
} |
| 10561 |
} |
| 10562 |
mPendingAccessibilityImportanceChange.clear(); |
| 10563 |
} |
| 10564 |
|
| 10565 |
int getAdapterPositionFor(ViewHolder viewHolder) { |
| 10566 |
if (viewHolder.hasAnyOfTheFlags(ViewHolder.FLAG_INVALID |
| 10567 |
| ViewHolder.FLAG_REMOVED | ViewHolder.FLAG_ADAPTER_POSITION_UNKNOWN) |
| 10568 |
|| !viewHolder.isBound()) { |
| 10569 |
return RecyclerView.NO_POSITION; |
| 10570 |
} |
| 10571 |
return mAdapterHelper.applyPendingUpdatesToPosition(viewHolder.mPosition); |
| 10572 |
} |
| 10573 |
|
| 10574 |
|
| 10575 |
|
| 10576 |
|
| 10577 |
|
| 10578 |
|
| 10579 |
|
| 10580 |
public static class LayoutParams extends android.view.ViewGroup.MarginLayoutParams { |
| 10581 |
ViewHolder mViewHolder; |
| 10582 |
final Rect mDecorInsets = new Rect(); |
| 10583 |
boolean mInsetsDirty = true; |
| 10584 |
|
| 10585 |
|
| 10586 |
|
| 10587 |
boolean mPendingInvalidate = false; |
| 10588 |
|
| 10589 |
public LayoutParams(Context c, AttributeSet attrs) { |
| 10590 |
super(c, attrs); |
| 10591 |
} |
| 10592 |
|
| 10593 |
public LayoutParams(int width, int height) { |
| 10594 |
super(width, height); |
| 10595 |
} |
| 10596 |
|
| 10597 |
public LayoutParams(MarginLayoutParams source) { |
| 10598 |
super(source); |
| 10599 |
} |
| 10600 |
|
| 10601 |
public LayoutParams(ViewGroup.LayoutParams source) { |
| 10602 |
super(source); |
| 10603 |
} |
| 10604 |
|
| 10605 |
public LayoutParams(LayoutParams source) { |
| 10606 |
super((ViewGroup.LayoutParams) source); |
| 10607 |
} |
| 10608 |
|
| 10609 |
|
| 10610 |
|
| 10611 |
|
| 10612 |
|
| 10613 |
|
| 10614 |
|
| 10615 |
public boolean viewNeedsUpdate() { |
| 10616 |
return mViewHolder.needsUpdate(); |
| 10617 |
} |
| 10618 |
|
| 10619 |
|
| 10620 |
|
| 10621 |
|
| 10622 |
|
| 10623 |
|
| 10624 |
|
| 10625 |
public boolean isViewInvalid() { |
| 10626 |
return mViewHolder.isInvalid(); |
| 10627 |
} |
| 10628 |
|
| 10629 |
|
| 10630 |
|
| 10631 |
|
| 10632 |
|
| 10633 |
|
| 10634 |
|
| 10635 |
|
| 10636 |
public boolean isItemRemoved() { |
| 10637 |
return mViewHolder.isRemoved(); |
| 10638 |
} |
| 10639 |
|
| 10640 |
|
| 10641 |
|
| 10642 |
|
| 10643 |
|
| 10644 |
|
| 10645 |
|
| 10646 |
|
| 10647 |
public boolean isItemChanged() { |
| 10648 |
return mViewHolder.isUpdated(); |
| 10649 |
} |
| 10650 |
|
| 10651 |
|
| 10652 |
|
| 10653 |
|
| 10654 |
@Deprecated |
| 10655 |
public int getViewPosition() { |
| 10656 |
return mViewHolder.getPosition(); |
| 10657 |
} |
| 10658 |
|
| 10659 |
|
| 10660 |
|
| 10661 |
|
| 10662 |
|
| 10663 |
|
| 10664 |
|
| 10665 |
public int getViewLayoutPosition() { |
| 10666 |
return mViewHolder.getLayoutPosition(); |
| 10667 |
} |
| 10668 |
|
| 10669 |
|
| 10670 |
|
| 10671 |
|
| 10672 |
|
| 10673 |
|
| 10674 |
|
| 10675 |
|
| 10676 |
|
| 10677 |
public int getViewAdapterPosition() { |
| 10678 |
return mViewHolder.getAdapterPosition(); |
| 10679 |
} |
| 10680 |
} |
| 10681 |
|
| 10682 |
|
| 10683 |
|
| 10684 |
|
| 10685 |
|
| 10686 |
public abstract static class AdapterDataObserver { |
| 10687 |
public void onChanged() { |
| 10688 |
|
| 10689 |
} |
| 10690 |
|
| 10691 |
public void onItemRangeChanged(int positionStart, int itemCount) { |
| 10692 |
|
| 10693 |
} |
| 10694 |
|
| 10695 |
public void onItemRangeChanged(int positionStart, int itemCount, Object payload) { |
| 10696 |
|
| 10697 |
|
| 10698 |
onItemRangeChanged(positionStart, itemCount); |
| 10699 |
} |
| 10700 |
|
| 10701 |
public void onItemRangeInserted(int positionStart, int itemCount) { |
| 10702 |
|
| 10703 |
} |
| 10704 |
|
| 10705 |
public void onItemRangeRemoved(int positionStart, int itemCount) { |
| 10706 |
|
| 10707 |
} |
| 10708 |
|
| 10709 |
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { |
| 10710 |
|
| 10711 |
} |
| 10712 |
} |
| 10713 |
|
| 10714 |
|
| 10715 |
|
| 10716 |
|
| 10717 |
|
| 10718 |
|
| 10719 |
|
| 10720 |
public abstract static class SmoothScroller { |
| 10721 |
|
| 10722 |
private int mTargetPosition = RecyclerView.NO_POSITION; |
| 10723 |
|
| 10724 |
private RecyclerView mRecyclerView; |
| 10725 |
|
| 10726 |
private LayoutManager mLayoutManager; |
| 10727 |
|
| 10728 |
private boolean mPendingInitialRun; |
| 10729 |
|
| 10730 |
private boolean mRunning; |
| 10731 |
|
| 10732 |
private View mTargetView; |
| 10733 |
|
| 10734 |
private final Action mRecyclingAction; |
| 10735 |
|
| 10736 |
public SmoothScroller() { |
| 10737 |
mRecyclingAction = new Action(0, 0); |
| 10738 |
} |
| 10739 |
|
| 10740 |
|
| 10741 |
|
| 10742 |
|
| 10743 |
|
| 10744 |
|
| 10745 |
|
| 10746 |
|
| 10747 |
|
| 10748 |
|
| 10749 |
|
| 10750 |
|
| 10751 |
|
| 10752 |
void start(RecyclerView recyclerView, LayoutManager layoutManager) { |
| 10753 |
mRecyclerView = recyclerView; |
| 10754 |
mLayoutManager = layoutManager; |
| 10755 |
if (mTargetPosition == RecyclerView.NO_POSITION) { |
| 10756 |
throw new IllegalArgumentException("Invalid target position"); |
| 10757 |
} |
| 10758 |
mRecyclerView.mState.mTargetPosition = mTargetPosition; |
| 10759 |
mRunning = true; |
| 10760 |
mPendingInitialRun = true; |
| 10761 |
mTargetView = findViewByPosition(getTargetPosition()); |
| 10762 |
onStart(); |
| 10763 |
mRecyclerView.mViewFlinger.postOnAnimation(); |
| 10764 |
} |
| 10765 |
|
| 10766 |
public void setTargetPosition(int targetPosition) { |
| 10767 |
mTargetPosition = targetPosition; |
| 10768 |
} |
| 10769 |
|
| 10770 |
|
| 10771 |
|
| 10772 |
|
| 10773 |
|
| 10774 |
@Nullable |
| 10775 |
public LayoutManager getLayoutManager() { |
| 10776 |
return mLayoutManager; |
| 10777 |
} |
| 10778 |
|
| 10779 |
|
| 10780 |
|
| 10781 |
|
| 10782 |
|
| 10783 |
|
| 10784 |
|
| 10785 |
protected final void stop() { |
| 10786 |
if (!mRunning) { |
| 10787 |
return; |
| 10788 |
} |
| 10789 |
onStop(); |
| 10790 |
mRecyclerView.mState.mTargetPosition = RecyclerView.NO_POSITION; |
| 10791 |
mTargetView = null; |
| 10792 |
mTargetPosition = RecyclerView.NO_POSITION; |
| 10793 |
mPendingInitialRun = false; |
| 10794 |
mRunning = false; |
| 10795 |
|
| 10796 |
mLayoutManager.onSmoothScrollerStopped(this); |
| 10797 |
|
| 10798 |
mLayoutManager = null; |
| 10799 |
mRecyclerView = null; |
| 10800 |
} |
| 10801 |
|
| 10802 |
|
| 10803 |
|
| 10804 |
|
| 10805 |
|
| 10806 |
|
| 10807 |
|
| 10808 |
|
| 10809 |
public boolean isPendingInitialRun() { |
| 10810 |
return mPendingInitialRun; |
| 10811 |
} |
| 10812 |
|
| 10813 |
|
| 10814 |
|
| 10815 |
|
| 10816 |
|
| 10817 |
public boolean isRunning() { |
| 10818 |
return mRunning; |
| 10819 |
} |
| 10820 |
|
| 10821 |
|
| 10822 |
|
| 10823 |
|
| 10824 |
|
| 10825 |
|
| 10826 |
|
| 10827 |
public int getTargetPosition() { |
| 10828 |
return mTargetPosition; |
| 10829 |
} |
| 10830 |
|
| 10831 |
private void onAnimation(int dx, int dy) { |
| 10832 |
final RecyclerView recyclerView = mRecyclerView; |
| 10833 |
if (!mRunning || mTargetPosition == RecyclerView.NO_POSITION || recyclerView == null) { |
| 10834 |
stop(); |
| 10835 |
} |
| 10836 |
mPendingInitialRun = false; |
| 10837 |
if (mTargetView != null) { |
| 10838 |
|
| 10839 |
if (getChildPosition(mTargetView) == mTargetPosition) { |
| 10840 |
onTargetFound(mTargetView, recyclerView.mState, mRecyclingAction); |
| 10841 |
mRecyclingAction.runIfNecessary(recyclerView); |
| 10842 |
stop(); |
| 10843 |
} else { |
| 10844 |
Log.e(TAG, "Passed over target position while smooth scrolling."); |
| 10845 |
mTargetView = null; |
| 10846 |
} |
| 10847 |
} |
| 10848 |
if (mRunning) { |
| 10849 |
onSeekTargetStep(dx, dy, recyclerView.mState, mRecyclingAction); |
| 10850 |
boolean hadJumpTarget = mRecyclingAction.hasJumpTarget(); |
| 10851 |
mRecyclingAction.runIfNecessary(recyclerView); |
| 10852 |
if (hadJumpTarget) { |
| 10853 |
|
| 10854 |
if (mRunning) { |
| 10855 |
mPendingInitialRun = true; |
| 10856 |
recyclerView.mViewFlinger.postOnAnimation(); |
| 10857 |
} else { |
| 10858 |
stop(); |
| 10859 |
} |
| 10860 |
} |
| 10861 |
} |
| 10862 |
} |
| 10863 |
|
| 10864 |
|
| 10865 |
|
| 10866 |
|
| 10867 |
public int getChildPosition(View view) { |
| 10868 |
return mRecyclerView.getChildLayoutPosition(view); |
| 10869 |
} |
| 10870 |
|
| 10871 |
|
| 10872 |
|
| 10873 |
|
| 10874 |
public int getChildCount() { |
| 10875 |
return mRecyclerView.mLayout.getChildCount(); |
| 10876 |
} |
| 10877 |
|
| 10878 |
|
| 10879 |
|
| 10880 |
|
| 10881 |
public View findViewByPosition(int position) { |
| 10882 |
return mRecyclerView.mLayout.findViewByPosition(position); |
| 10883 |
} |
| 10884 |
|
| 10885 |
|
| 10886 |
|
| 10887 |
|
| 10888 |
|
| 10889 |
@Deprecated |
| 10890 |
public void instantScrollToPosition(int position) { |
| 10891 |
mRecyclerView.scrollToPosition(position); |
| 10892 |
} |
| 10893 |
|
| 10894 |
protected void onChildAttachedToWindow(View child) { |
| 10895 |
if (getChildPosition(child) == getTargetPosition()) { |
| 10896 |
mTargetView = child; |
| 10897 |
if (DEBUG) { |
| 10898 |
Log.d(TAG, "smooth scroll target view has been attached"); |
| 10899 |
} |
| 10900 |
} |
| 10901 |
} |
| 10902 |
|
| 10903 |
|
| 10904 |
|
| 10905 |
|
| 10906 |
|
| 10907 |
protected void normalize(PointF scrollVector) { |
| 10908 |
final double magnitude = Math.sqrt(scrollVector.x * scrollVector.x + scrollVector.y |
| 10909 |
* scrollVector.y); |
| 10910 |
scrollVector.x /= magnitude; |
| 10911 |
scrollVector.y /= magnitude; |
| 10912 |
} |
| 10913 |
|
| 10914 |
|
| 10915 |
|
| 10916 |
|
| 10917 |
protected abstract void onStart(); |
| 10918 |
|
| 10919 |
|
| 10920 |
|
| 10921 |
|
| 10922 |
|
| 10923 |
protected abstract void onStop(); |
| 10924 |
|
| 10925 |
|
| 10926 |
|
| 10927 |
|
| 10928 |
|
| 10929 |
|
| 10930 |
|
| 10931 |
|
| 10932 |
|
| 10933 |
|
| 10934 |
|
| 10935 |
|
| 10936 |
|
| 10937 |
protected abstract void onSeekTargetStep(int dx, int dy, State state, Action action); |
| 10938 |
|
| 10939 |
|
| 10940 |
|
| 10941 |
|
| 10942 |
|
| 10943 |
|
| 10944 |
|
| 10945 |
|
| 10946 |
|
| 10947 |
|
| 10948 |
protected abstract void onTargetFound(View targetView, State state, Action action); |
| 10949 |
|
| 10950 |
|
| 10951 |
|
| 10952 |
|
| 10953 |
public static class Action { |
| 10954 |
|
| 10955 |
public static final int UNDEFINED_DURATION = Integer.MIN_VALUE; |
| 10956 |
|
| 10957 |
private int mDx; |
| 10958 |
|
| 10959 |
private int mDy; |
| 10960 |
|
| 10961 |
private int mDuration; |
| 10962 |
|
| 10963 |
private int mJumpToPosition = NO_POSITION; |
| 10964 |
|
| 10965 |
private Interpolator mInterpolator; |
| 10966 |
|
| 10967 |
private boolean mChanged = false; |
| 10968 |
|
| 10969 |
|
| 10970 |
|
| 10971 |
private int mConsecutiveUpdates = 0; |
| 10972 |
|
| 10973 |
|
| 10974 |
|
| 10975 |
|
| 10976 |
|
| 10977 |
public Action(int dx, int dy) { |
| 10978 |
this(dx, dy, UNDEFINED_DURATION, null); |
| 10979 |
} |
| 10980 |
|
| 10981 |
|
| 10982 |
|
| 10983 |
|
| 10984 |
|
| 10985 |
|
| 10986 |
public Action(int dx, int dy, int duration) { |
| 10987 |
this(dx, dy, duration, null); |
| 10988 |
} |
| 10989 |
|
| 10990 |
|
| 10991 |
|
| 10992 |
|
| 10993 |
|
| 10994 |
|
| 10995 |
|
| 10996 |
|
| 10997 |
public Action(int dx, int dy, int duration, Interpolator interpolator) { |
| 10998 |
mDx = dx; |
| 10999 |
mDy = dy; |
| 11000 |
mDuration = duration; |
| 11001 |
mInterpolator = interpolator; |
| 11002 |
} |
| 11003 |
|
| 11004 |
|
| 11005 |
|
| 11006 |
|
| 11007 |
|
| 11008 |
|
| 11009 |
|
| 11010 |
|
| 11011 |
|
| 11012 |
|
| 11013 |
|
| 11014 |
|
| 11015 |
|
| 11016 |
|
| 11017 |
|
| 11018 |
|
| 11019 |
public void jumpTo(int targetPosition) { |
| 11020 |
mJumpToPosition = targetPosition; |
| 11021 |
} |
| 11022 |
|
| 11023 |
boolean hasJumpTarget() { |
| 11024 |
return mJumpToPosition >= 0; |
| 11025 |
} |
| 11026 |
|
| 11027 |
void runIfNecessary(RecyclerView recyclerView) { |
| 11028 |
if (mJumpToPosition >= 0) { |
| 11029 |
final int position = mJumpToPosition; |
| 11030 |
mJumpToPosition = NO_POSITION; |
| 11031 |
recyclerView.jumpToPositionForSmoothScroller(position); |
| 11032 |
mChanged = false; |
| 11033 |
return; |
| 11034 |
} |
| 11035 |
if (mChanged) { |
| 11036 |
validate(); |
| 11037 |
if (mInterpolator == null) { |
| 11038 |
if (mDuration == UNDEFINED_DURATION) { |
| 11039 |
recyclerView.mViewFlinger.smoothScrollBy(mDx, mDy); |
| 11040 |
} else { |
| 11041 |
recyclerView.mViewFlinger.smoothScrollBy(mDx, mDy, mDuration); |
| 11042 |
} |
| 11043 |
} else { |
| 11044 |
recyclerView.mViewFlinger.smoothScrollBy( |
| 11045 |
mDx, mDy, mDuration, mInterpolator); |
| 11046 |
} |
| 11047 |
mConsecutiveUpdates++; |
| 11048 |
if (mConsecutiveUpdates > 10) { |
| 11049 |
|
| 11050 |
|
| 11051 |
Log.e(TAG, "Smooth Scroll action is being updated too frequently. Make sure" |
| 11052 |
+ " you are not changing it unless necessary"); |
| 11053 |
} |
| 11054 |
mChanged = false; |
| 11055 |
} else { |
| 11056 |
mConsecutiveUpdates = 0; |
| 11057 |
} |
| 11058 |
} |
| 11059 |
|
| 11060 |
private void validate() { |
| 11061 |
if (mInterpolator != null && mDuration < 1) { |
| 11062 |
throw new IllegalStateException("If you provide an interpolator, you must" |
| 11063 |
+ " set a positive duration"); |
| 11064 |
} else if (mDuration < 1) { |
| 11065 |
throw new IllegalStateException("Scroll duration must be a positive number"); |
| 11066 |
} |
| 11067 |
} |
| 11068 |
|
| 11069 |
public int getDx() { |
| 11070 |
return mDx; |
| 11071 |
} |
| 11072 |
|
| 11073 |
public void setDx(int dx) { |
| 11074 |
mChanged = true; |
| 11075 |
mDx = dx; |
| 11076 |
} |
| 11077 |
|
| 11078 |
public int getDy() { |
| 11079 |
return mDy; |
| 11080 |
} |
| 11081 |
|
| 11082 |
public void setDy(int dy) { |
| 11083 |
mChanged = true; |
| 11084 |
mDy = dy; |
| 11085 |
} |
| 11086 |
|
| 11087 |
public int getDuration() { |
| 11088 |
return mDuration; |
| 11089 |
} |
| 11090 |
|
| 11091 |
public void setDuration(int duration) { |
| 11092 |
mChanged = true; |
| 11093 |
mDuration = duration; |
| 11094 |
} |
| 11095 |
|
| 11096 |
public Interpolator getInterpolator() { |
| 11097 |
return mInterpolator; |
| 11098 |
} |
| 11099 |
|
| 11100 |
|
| 11101 |
|
| 11102 |
|
| 11103 |
|
| 11104 |
|
| 11105 |
|
| 11106 |
public void setInterpolator(Interpolator interpolator) { |
| 11107 |
mChanged = true; |
| 11108 |
mInterpolator = interpolator; |
| 11109 |
} |
| 11110 |
|
| 11111 |
|
| 11112 |
|
| 11113 |
|
| 11114 |
|
| 11115 |
|
| 11116 |
|
| 11117 |
|
| 11118 |
|
| 11119 |
public void update(int dx, int dy, int duration, Interpolator interpolator) { |
| 11120 |
mDx = dx; |
| 11121 |
mDy = dy; |
| 11122 |
mDuration = duration; |
| 11123 |
mInterpolator = interpolator; |
| 11124 |
mChanged = true; |
| 11125 |
} |
| 11126 |
} |
| 11127 |
|
| 11128 |
|
| 11129 |
|
| 11130 |
|
| 11131 |
|
| 11132 |
public interface ScrollVectorProvider { |
| 11133 |
|
| 11134 |
|
| 11135 |
|
| 11136 |
|
| 11137 |
|
| 11138 |
|
| 11139 |
|
| 11140 |
|
| 11141 |
|
| 11142 |
|
| 11143 |
|
| 11144 |
|
| 11145 |
|
| 11146 |
|
| 11147 |
|
| 11148 |
|
| 11149 |
PointF computeScrollVectorForPosition(int targetPosition); |
| 11150 |
} |
| 11151 |
} |
| 11152 |
|
| 11153 |
static class AdapterDataObservable extends Observable<AdapterDataObserver> { |
| 11154 |
public boolean hasObservers() { |
| 11155 |
return !mObservers.isEmpty(); |
| 11156 |
} |
| 11157 |
|
| 11158 |
public void notifyChanged() { |
| 11159 |
|
| 11160 |
|
| 11161 |
|
| 11162 |
|
| 11163 |
for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 11164 |
mObservers.get(i).onChanged(); |
| 11165 |
} |
| 11166 |
} |
| 11167 |
|
| 11168 |
public void notifyItemRangeChanged(int positionStart, int itemCount) { |
| 11169 |
notifyItemRangeChanged(positionStart, itemCount, null); |
| 11170 |
} |
| 11171 |
|
| 11172 |
public void notifyItemRangeChanged(int positionStart, int itemCount, Object payload) { |
| 11173 |
|
| 11174 |
|
| 11175 |
|
| 11176 |
|
| 11177 |
for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 11178 |
mObservers.get(i).onItemRangeChanged(positionStart, itemCount, payload); |
| 11179 |
} |
| 11180 |
} |
| 11181 |
|
| 11182 |
public void notifyItemRangeInserted(int positionStart, int itemCount) { |
| 11183 |
|
| 11184 |
|
| 11185 |
|
| 11186 |
|
| 11187 |
for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 11188 |
mObservers.get(i).onItemRangeInserted(positionStart, itemCount); |
| 11189 |
} |
| 11190 |
} |
| 11191 |
|
| 11192 |
public void notifyItemRangeRemoved(int positionStart, int itemCount) { |
| 11193 |
|
| 11194 |
|
| 11195 |
|
| 11196 |
|
| 11197 |
for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 11198 |
mObservers.get(i).onItemRangeRemoved(positionStart, itemCount); |
| 11199 |
} |
| 11200 |
} |
| 11201 |
|
| 11202 |
public void notifyItemMoved(int fromPosition, int toPosition) { |
| 11203 |
for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 11204 |
mObservers.get(i).onItemRangeMoved(fromPosition, toPosition, 1); |
| 11205 |
} |
| 11206 |
} |
| 11207 |
} |
| 11208 |
|
| 11209 |
|
| 11210 |
|
| 11211 |
|
| 11212 |
|
| 11213 |
public static class SavedState extends AbsSavedState { |
| 11214 |
|
| 11215 |
Parcelable mLayoutState; |
| 11216 |
|
| 11217 |
|
| 11218 |
|
| 11219 |
|
| 11220 |
SavedState(Parcel in) { |
| 11221 |
super(in); |
| 11222 |
mLayoutState = in.readParcelable(LayoutManager.class.getClassLoader()); |
| 11223 |
} |
| 11224 |
|
| 11225 |
|
| 11226 |
|
| 11227 |
|
| 11228 |
SavedState(Parcelable superState) { |
| 11229 |
super(superState); |
| 11230 |
} |
| 11231 |
|
| 11232 |
@Override |
| 11233 |
public void writeToParcel(Parcel dest, int flags) { |
| 11234 |
super.writeToParcel(dest, flags); |
| 11235 |
dest.writeParcelable(mLayoutState, 0); |
| 11236 |
} |
| 11237 |
|
| 11238 |
void copyFrom(SavedState other) { |
| 11239 |
mLayoutState = other.mLayoutState; |
| 11240 |
} |
| 11241 |
|
| 11242 |
public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() { |
| 11243 |
@Override |
| 11244 |
public SavedState createFromParcel(Parcel in) { |
| 11245 |
return new SavedState(in); |
| 11246 |
} |
| 11247 |
|
| 11248 |
@Override |
| 11249 |
public SavedState[] newArray(int size) { |
| 11250 |
return new SavedState[size]; |
| 11251 |
} |
| 11252 |
}; |
| 11253 |
} |
| 11254 |
|
| 11255 |
|
| 11256 |
|
| 11257 |
|
| 11258 |
|
| 11259 |
|
| 11260 |
|
| 11261 |
|
| 11262 |
|
| 11263 |
|
| 11264 |
public static class State { |
| 11265 |
static final int STEP_START = 1; |
| 11266 |
static final int STEP_LAYOUT = 1 << 1; |
| 11267 |
static final int STEP_ANIMATIONS = 1 << 2; |
| 11268 |
|
| 11269 |
void assertLayoutStep(int accepted) { |
| 11270 |
if ((accepted & mLayoutStep) == 0) { |
| 11271 |
throw new IllegalStateException("Layout state should be one of " |
| 11272 |
+ Integer.toBinaryString(accepted) + " but it is " |
| 11273 |
+ Integer.toBinaryString(mLayoutStep)); |
| 11274 |
} |
| 11275 |
} |
| 11276 |
|
| 11277 |
|
| 11278 |
|
| 11279 |
private int mTargetPosition = RecyclerView.NO_POSITION; |
| 11280 |
|
| 11281 |
private SparseArray<Object> mData; |
| 11282 |
|
| 11283 |
|
| 11284 |
|
| 11285 |
|
| 11286 |
|
| 11287 |
|
| 11288 |
|
| 11289 |
|
| 11290 |
int mPreviousLayoutItemCount = 0; |
| 11291 |
|
| 11292 |
|
| 11293 |
|
| 11294 |
|
| 11295 |
|
| 11296 |
int mDeletedInvisibleItemCountSincePreviousLayout = 0; |
| 11297 |
|
| 11298 |
|
| 11299 |
|
| 11300 |
|
| 11301 |
|
| 11302 |
@IntDef(flag = true, value = { |
| 11303 |
STEP_START, STEP_LAYOUT, STEP_ANIMATIONS |
| 11304 |
}) |
| 11305 |
@Retention(RetentionPolicy.SOURCE) |
| 11306 |
@interface LayoutState {} |
| 11307 |
|
| 11308 |
@LayoutState |
| 11309 |
int mLayoutStep = STEP_START; |
| 11310 |
|
| 11311 |
|
| 11312 |
|
| 11313 |
|
| 11314 |
int mItemCount = 0; |
| 11315 |
|
| 11316 |
boolean mStructureChanged = false; |
| 11317 |
|
| 11318 |
boolean mInPreLayout = false; |
| 11319 |
|
| 11320 |
boolean mTrackOldChangeHolders = false; |
| 11321 |
|
| 11322 |
boolean mIsMeasuring = false; |
| 11323 |
|
| 11324 |
|
| 11325 |
|
| 11326 |
|
| 11327 |
|
| 11328 |
boolean mRunSimpleAnimations = false; |
| 11329 |
|
| 11330 |
boolean mRunPredictiveAnimations = false; |
| 11331 |
|
| 11332 |
|
| 11333 |
|
| 11334 |
|
| 11335 |
|
| 11336 |
|
| 11337 |
int mFocusedItemPosition; |
| 11338 |
long mFocusedItemId; |
| 11339 |
|
| 11340 |
|
| 11341 |
int mFocusedSubChildId; |
| 11342 |
|
| 11343 |
|
| 11344 |
|
| 11345 |
State reset() { |
| 11346 |
mTargetPosition = RecyclerView.NO_POSITION; |
| 11347 |
if (mData != null) { |
| 11348 |
mData.clear(); |
| 11349 |
} |
| 11350 |
mItemCount = 0; |
| 11351 |
mStructureChanged = false; |
| 11352 |
mIsMeasuring = false; |
| 11353 |
return this; |
| 11354 |
} |
| 11355 |
|
| 11356 |
|
| 11357 |
|
| 11358 |
|
| 11359 |
|
| 11360 |
|
| 11361 |
|
| 11362 |
|
| 11363 |
void prepareForNestedPrefetch(Adapter adapter) { |
| 11364 |
mLayoutStep = STEP_START; |
| 11365 |
mItemCount = adapter.getItemCount(); |
| 11366 |
mStructureChanged = false; |
| 11367 |
mInPreLayout = false; |
| 11368 |
mTrackOldChangeHolders = false; |
| 11369 |
mIsMeasuring = false; |
| 11370 |
} |
| 11371 |
|
| 11372 |
|
| 11373 |
|
| 11374 |
|
| 11375 |
|
| 11376 |
|
| 11377 |
|
| 11378 |
|
| 11379 |
|
| 11380 |
|
| 11381 |
|
| 11382 |
|
| 11383 |
|
| 11384 |
|
| 11385 |
|
| 11386 |
public boolean isMeasuring() { |
| 11387 |
return mIsMeasuring; |
| 11388 |
} |
| 11389 |
|
| 11390 |
|
| 11391 |
|
| 11392 |
|
| 11393 |
|
| 11394 |
public boolean isPreLayout() { |
| 11395 |
return mInPreLayout; |
| 11396 |
} |
| 11397 |
|
| 11398 |
|
| 11399 |
|
| 11400 |
|
| 11401 |
|
| 11402 |
|
| 11403 |
|
| 11404 |
|
| 11405 |
public boolean willRunPredictiveAnimations() { |
| 11406 |
return mRunPredictiveAnimations; |
| 11407 |
} |
| 11408 |
|
| 11409 |
|
| 11410 |
|
| 11411 |
|
| 11412 |
|
| 11413 |
|
| 11414 |
|
| 11415 |
|
| 11416 |
public boolean willRunSimpleAnimations() { |
| 11417 |
return mRunSimpleAnimations; |
| 11418 |
} |
| 11419 |
|
| 11420 |
|
| 11421 |
|
| 11422 |
|
| 11423 |
|
| 11424 |
|
| 11425 |
public void remove(int resourceId) { |
| 11426 |
if (mData == null) { |
| 11427 |
return; |
| 11428 |
} |
| 11429 |
mData.remove(resourceId); |
| 11430 |
} |
| 11431 |
|
| 11432 |
|
| 11433 |
|
| 11434 |
|
| 11435 |
|
| 11436 |
|
| 11437 |
|
| 11438 |
|
| 11439 |
|
| 11440 |
public <T> T get(int resourceId) { |
| 11441 |
if (mData == null) { |
| 11442 |
return null; |
| 11443 |
} |
| 11444 |
return (T) mData.get(resourceId); |
| 11445 |
} |
| 11446 |
|
| 11447 |
|
| 11448 |
|
| 11449 |
|
| 11450 |
|
| 11451 |
|
| 11452 |
|
| 11453 |
|
| 11454 |
|
| 11455 |
public void put(int resourceId, Object data) { |
| 11456 |
if (mData == null) { |
| 11457 |
mData = new SparseArray<Object>(); |
| 11458 |
} |
| 11459 |
mData.put(resourceId, data); |
| 11460 |
} |
| 11461 |
|
| 11462 |
|
| 11463 |
|
| 11464 |
|
| 11465 |
|
| 11466 |
|
| 11467 |
|
| 11468 |
|
| 11469 |
public int getTargetScrollPosition() { |
| 11470 |
return mTargetPosition; |
| 11471 |
} |
| 11472 |
|
| 11473 |
|
| 11474 |
|
| 11475 |
|
| 11476 |
|
| 11477 |
|
| 11478 |
public boolean hasTargetScrollPosition() { |
| 11479 |
return mTargetPosition != RecyclerView.NO_POSITION; |
| 11480 |
} |
| 11481 |
|
| 11482 |
|
| 11483 |
|
| 11484 |
|
| 11485 |
|
| 11486 |
public boolean didStructureChange() { |
| 11487 |
return mStructureChanged; |
| 11488 |
} |
| 11489 |
|
| 11490 |
|
| 11491 |
|
| 11492 |
|
| 11493 |
|
| 11494 |
|
| 11495 |
|
| 11496 |
|
| 11497 |
|
| 11498 |
|
| 11499 |
|
| 11500 |
|
| 11501 |
|
| 11502 |
|
| 11503 |
|
| 11504 |
|
| 11505 |
|
| 11506 |
|
| 11507 |
|
| 11508 |
|
| 11509 |
|
| 11510 |
|
| 11511 |
|
| 11512 |
|
| 11513 |
|
| 11514 |
public int getItemCount() { |
| 11515 |
return mInPreLayout |
| 11516 |
? (mPreviousLayoutItemCount - mDeletedInvisibleItemCountSincePreviousLayout) |
| 11517 |
: mItemCount; |
| 11518 |
} |
| 11519 |
|
| 11520 |
@Override |
| 11521 |
public String toString() { |
| 11522 |
return "State{" |
| 11523 |
+ "mTargetPosition=" + mTargetPosition |
| 11524 |
+ ", mData=" + mData |
| 11525 |
+ ", mItemCount=" + mItemCount |
| 11526 |
+ ", mPreviousLayoutItemCount=" + mPreviousLayoutItemCount |
| 11527 |
+ ", mDeletedInvisibleItemCountSincePreviousLayout=" |
| 11528 |
+ mDeletedInvisibleItemCountSincePreviousLayout |
| 11529 |
+ ", mStructureChanged=" + mStructureChanged |
| 11530 |
+ ", mInPreLayout=" + mInPreLayout |
| 11531 |
+ ", mRunSimpleAnimations=" + mRunSimpleAnimations |
| 11532 |
+ ", mRunPredictiveAnimations=" + mRunPredictiveAnimations |
| 11533 |
+ '}'; |
| 11534 |
} |
| 11535 |
} |
| 11536 |
|
| 11537 |
|
| 11538 |
|
| 11539 |
|
| 11540 |
|
| 11541 |
|
| 11542 |
|
| 11543 |
|
| 11544 |
public abstract static class OnFlingListener { |
| 11545 |
|
| 11546 |
|
| 11547 |
|
| 11548 |
|
| 11549 |
|
| 11550 |
|
| 11551 |
|
| 11552 |
|
| 11553 |
|
| 11554 |
|
| 11555 |
|
| 11556 |
public abstract boolean onFling(int velocityX, int velocityY); |
| 11557 |
} |
| 11558 |
|
| 11559 |
|
| 11560 |
|
| 11561 |
|
| 11562 |
|
| 11563 |
|
| 11564 |
|
| 11565 |
private class ItemAnimatorRestoreListener implements ItemAnimator.ItemAnimatorListener { |
| 11566 |
|
| 11567 |
ItemAnimatorRestoreListener() { |
| 11568 |
} |
| 11569 |
|
| 11570 |
@Override |
| 11571 |
public void onAnimationFinished(ViewHolder item) { |
| 11572 |
item.setIsRecyclable(true); |
| 11573 |
if (item.mShadowedHolder != null && item.mShadowingHolder == null) { |
| 11574 |
item.mShadowedHolder = null; |
| 11575 |
} |
| 11576 |
|
| 11577 |
|
| 11578 |
item.mShadowingHolder = null; |
| 11579 |
if (!item.shouldBeKeptAsChild()) { |
| 11580 |
if (!removeAnimatingView(item.itemView) && item.isTmpDetached()) { |
| 11581 |
removeDetachedView(item.itemView, false); |
| 11582 |
} |
| 11583 |
} |
| 11584 |
} |
| 11585 |
} |
| 11586 |
|
| 11587 |
|
| 11588 |
|
| 11589 |
|
| 11590 |
|
| 11591 |
|
| 11592 |
|
| 11593 |
|
| 11594 |
|
| 11595 |
|
| 11596 |
|
| 11597 |
|
| 11598 |
|
| 11599 |
|
| 11600 |
|
| 11601 |
|
| 11602 |
|
| 11603 |
|
| 11604 |
|
| 11605 |
|
| 11606 |
|
| 11607 |
|
| 11608 |
@SuppressWarnings("UnusedParameters") |
| 11609 |
public abstract static class ItemAnimator { |
| 11610 |
|
| 11611 |
|
| 11612 |
|
| 11613 |
|
| 11614 |
|
| 11615 |
|
| 11616 |
public static final int FLAG_CHANGED = ViewHolder.FLAG_UPDATE; |
| 11617 |
|
| 11618 |
|
| 11619 |
|
| 11620 |
|
| 11621 |
|
| 11622 |
|
| 11623 |
public static final int FLAG_REMOVED = ViewHolder.FLAG_REMOVED; |
| 11624 |
|
| 11625 |
|
| 11626 |
|
| 11627 |
|
| 11628 |
|
| 11629 |
|
| 11630 |
|
| 11631 |
public static final int FLAG_INVALIDATED = ViewHolder.FLAG_INVALID; |
| 11632 |
|
| 11633 |
|
| 11634 |
|
| 11635 |
|
| 11636 |
|
| 11637 |
|
| 11638 |
|
| 11639 |
|
| 11640 |
|
| 11641 |
public static final int FLAG_MOVED = ViewHolder.FLAG_MOVED; |
| 11642 |
|
| 11643 |
|
| 11644 |
|
| 11645 |
|
| 11646 |
|
| 11647 |
|
| 11648 |
|
| 11649 |
|
| 11650 |
|
| 11651 |
|
| 11652 |
public static final int FLAG_APPEARED_IN_PRE_LAYOUT = |
| 11653 |
ViewHolder.FLAG_APPEARED_IN_PRE_LAYOUT; |
| 11654 |
|
| 11655 |
|
| 11656 |
|
| 11657 |
|
| 11658 |
|
| 11659 |
@IntDef(flag = true, value = { |
| 11660 |
FLAG_CHANGED, FLAG_REMOVED, FLAG_MOVED, FLAG_INVALIDATED, |
| 11661 |
FLAG_APPEARED_IN_PRE_LAYOUT |
| 11662 |
}) |
| 11663 |
@Retention(RetentionPolicy.SOURCE) |
| 11664 |
public @interface AdapterChanges {} |
| 11665 |
private ItemAnimatorListener mListener = null; |
| 11666 |
private ArrayList<ItemAnimatorFinishedListener> mFinishedListeners = |
| 11667 |
new ArrayList<ItemAnimatorFinishedListener>(); |
| 11668 |
|
| 11669 |
private long mAddDuration = 120; |
| 11670 |
private long mRemoveDuration = 120; |
| 11671 |
private long mMoveDuration = 250; |
| 11672 |
private long mChangeDuration = 250; |
| 11673 |
|
| 11674 |
|
| 11675 |
|
| 11676 |
|
| 11677 |
|
| 11678 |
|
| 11679 |
public long getMoveDuration() { |
| 11680 |
return mMoveDuration; |
| 11681 |
} |
| 11682 |
|
| 11683 |
|
| 11684 |
|
| 11685 |
|
| 11686 |
|
| 11687 |
|
| 11688 |
public void setMoveDuration(long moveDuration) { |
| 11689 |
mMoveDuration = moveDuration; |
| 11690 |
} |
| 11691 |
|
| 11692 |
|
| 11693 |
|
| 11694 |
|
| 11695 |
|
| 11696 |
|
| 11697 |
public long getAddDuration() { |
| 11698 |
return mAddDuration; |
| 11699 |
} |
| 11700 |
|
| 11701 |
|
| 11702 |
|
| 11703 |
|
| 11704 |
|
| 11705 |
|
| 11706 |
public void setAddDuration(long addDuration) { |
| 11707 |
mAddDuration = addDuration; |
| 11708 |
} |
| 11709 |
|
| 11710 |
|
| 11711 |
|
| 11712 |
|
| 11713 |
|
| 11714 |
|
| 11715 |
public long getRemoveDuration() { |
| 11716 |
return mRemoveDuration; |
| 11717 |
} |
| 11718 |
|
| 11719 |
|
| 11720 |
|
| 11721 |
|
| 11722 |
|
| 11723 |
|
| 11724 |
public void setRemoveDuration(long removeDuration) { |
| 11725 |
mRemoveDuration = removeDuration; |
| 11726 |
} |
| 11727 |
|
| 11728 |
|
| 11729 |
|
| 11730 |
|
| 11731 |
|
| 11732 |
|
| 11733 |
public long getChangeDuration() { |
| 11734 |
return mChangeDuration; |
| 11735 |
} |
| 11736 |
|
| 11737 |
|
| 11738 |
|
| 11739 |
|
| 11740 |
|
| 11741 |
|
| 11742 |
public void setChangeDuration(long changeDuration) { |
| 11743 |
mChangeDuration = changeDuration; |
| 11744 |
} |
| 11745 |
|
| 11746 |
|
| 11747 |
|
| 11748 |
|
| 11749 |
|
| 11750 |
|
| 11751 |
|
| 11752 |
|
| 11753 |
|
| 11754 |
void setListener(ItemAnimatorListener listener) { |
| 11755 |
mListener = listener; |
| 11756 |
} |
| 11757 |
|
| 11758 |
|
| 11759 |
|
| 11760 |
|
| 11761 |
|
| 11762 |
|
| 11763 |
|
| 11764 |
|
| 11765 |
|
| 11766 |
|
| 11767 |
|
| 11768 |
|
| 11769 |
|
| 11770 |
|
| 11771 |
|
| 11772 |
|
| 11773 |
|
| 11774 |
|
| 11775 |
|
| 11776 |
|
| 11777 |
|
| 11778 |
|
| 11779 |
|
| 11780 |
|
| 11781 |
|
| 11782 |
|
| 11783 |
|
| 11784 |
|
| 11785 |
|
| 11786 |
|
| 11787 |
|
| 11788 |
|
| 11789 |
|
| 11790 |
|
| 11791 |
public @NonNull ItemHolderInfo recordPreLayoutInformation(@NonNull State state, |
| 11792 |
@NonNull ViewHolder viewHolder, @AdapterChanges int changeFlags, |
| 11793 |
@NonNull List<Object> payloads) { |
| 11794 |
return obtainHolderInfo().setFrom(viewHolder); |
| 11795 |
} |
| 11796 |
|
| 11797 |
|
| 11798 |
|
| 11799 |
|
| 11800 |
|
| 11801 |
|
| 11802 |
|
| 11803 |
|
| 11804 |
|
| 11805 |
|
| 11806 |
|
| 11807 |
|
| 11808 |
|
| 11809 |
|
| 11810 |
|
| 11811 |
|
| 11812 |
|
| 11813 |
|
| 11814 |
|
| 11815 |
|
| 11816 |
|
| 11817 |
|
| 11818 |
|
| 11819 |
|
| 11820 |
|
| 11821 |
public @NonNull ItemHolderInfo recordPostLayoutInformation(@NonNull State state, |
| 11822 |
@NonNull ViewHolder viewHolder) { |
| 11823 |
return obtainHolderInfo().setFrom(viewHolder); |
| 11824 |
} |
| 11825 |
|
| 11826 |
|
| 11827 |
|
| 11828 |
|
| 11829 |
|
| 11830 |
|
| 11831 |
|
| 11832 |
|
| 11833 |
|
| 11834 |
|
| 11835 |
|
| 11836 |
|
| 11837 |
|
| 11838 |
|
| 11839 |
|
| 11840 |
|
| 11841 |
|
| 11842 |
|
| 11843 |
|
| 11844 |
|
| 11845 |
|
| 11846 |
|
| 11847 |
|
| 11848 |
|
| 11849 |
|
| 11850 |
|
| 11851 |
|
| 11852 |
|
| 11853 |
|
| 11854 |
|
| 11855 |
|
| 11856 |
|
| 11857 |
|
| 11858 |
|
| 11859 |
|
| 11860 |
|
| 11861 |
|
| 11862 |
|
| 11863 |
|
| 11864 |
|
| 11865 |
|
| 11866 |
public abstract boolean animateDisappearance(@NonNull ViewHolder viewHolder, |
| 11867 |
@NonNull ItemHolderInfo preLayoutInfo, @Nullable ItemHolderInfo postLayoutInfo); |
| 11868 |
|
| 11869 |
|
| 11870 |
|
| 11871 |
|
| 11872 |
|
| 11873 |
|
| 11874 |
|
| 11875 |
|
| 11876 |
|
| 11877 |
|
| 11878 |
|
| 11879 |
|
| 11880 |
|
| 11881 |
|
| 11882 |
|
| 11883 |
|
| 11884 |
|
| 11885 |
|
| 11886 |
|
| 11887 |
|
| 11888 |
|
| 11889 |
|
| 11890 |
|
| 11891 |
|
| 11892 |
public abstract boolean animateAppearance(@NonNull ViewHolder viewHolder, |
| 11893 |
@Nullable ItemHolderInfo preLayoutInfo, @NonNull ItemHolderInfo postLayoutInfo); |
| 11894 |
|
| 11895 |
|
| 11896 |
|
| 11897 |
|
| 11898 |
|
| 11899 |
|
| 11900 |
|
| 11901 |
|
| 11902 |
|
| 11903 |
|
| 11904 |
|
| 11905 |
|
| 11906 |
|
| 11907 |
|
| 11908 |
|
| 11909 |
|
| 11910 |
|
| 11911 |
|
| 11912 |
|
| 11913 |
|
| 11914 |
|
| 11915 |
|
| 11916 |
|
| 11917 |
|
| 11918 |
|
| 11919 |
|
| 11920 |
|
| 11921 |
|
| 11922 |
public abstract boolean animatePersistence(@NonNull ViewHolder viewHolder, |
| 11923 |
@NonNull ItemHolderInfo preLayoutInfo, @NonNull ItemHolderInfo postLayoutInfo); |
| 11924 |
|
| 11925 |
|
| 11926 |
|
| 11927 |
|
| 11928 |
|
| 11929 |
|
| 11930 |
|
| 11931 |
|
| 11932 |
|
| 11933 |
|
| 11934 |
|
| 11935 |
|
| 11936 |
|
| 11937 |
|
| 11938 |
|
| 11939 |
|
| 11940 |
|
| 11941 |
|
| 11942 |
|
| 11943 |
|
| 11944 |
|
| 11945 |
|
| 11946 |
|
| 11947 |
|
| 11948 |
|
| 11949 |
|
| 11950 |
|
| 11951 |
|
| 11952 |
|
| 11953 |
|
| 11954 |
|
| 11955 |
|
| 11956 |
|
| 11957 |
|
| 11958 |
|
| 11959 |
|
| 11960 |
|
| 11961 |
|
| 11962 |
|
| 11963 |
|
| 11964 |
|
| 11965 |
|
| 11966 |
|
| 11967 |
|
| 11968 |
|
| 11969 |
|
| 11970 |
|
| 11971 |
|
| 11972 |
|
| 11973 |
|
| 11974 |
|
| 11975 |
|
| 11976 |
|
| 11977 |
|
| 11978 |
|
| 11979 |
|
| 11980 |
|
| 11981 |
|
| 11982 |
|
| 11983 |
|
| 11984 |
|
| 11985 |
|
| 11986 |
|
| 11987 |
|
| 11988 |
|
| 11989 |
public abstract boolean animateChange(@NonNull ViewHolder oldHolder, |
| 11990 |
@NonNull ViewHolder newHolder, |
| 11991 |
@NonNull ItemHolderInfo preLayoutInfo, @NonNull ItemHolderInfo postLayoutInfo); |
| 11992 |
|
| 11993 |
@AdapterChanges static int buildAdapterChangeFlagsForAnimations(ViewHolder viewHolder) { |
| 11994 |
int flags = viewHolder.mFlags & (FLAG_INVALIDATED | FLAG_REMOVED | FLAG_CHANGED); |
| 11995 |
if (viewHolder.isInvalid()) { |
| 11996 |
return FLAG_INVALIDATED; |
| 11997 |
} |
| 11998 |
if ((flags & FLAG_INVALIDATED) == 0) { |
| 11999 |
final int oldPos = viewHolder.getOldPosition(); |
| 12000 |
final int pos = viewHolder.getAdapterPosition(); |
| 12001 |
if (oldPos != NO_POSITION && pos != NO_POSITION && oldPos != pos) { |
| 12002 |
flags |= FLAG_MOVED; |
| 12003 |
} |
| 12004 |
} |
| 12005 |
return flags; |
| 12006 |
} |
| 12007 |
|
| 12008 |
|
| 12009 |
|
| 12010 |
|
| 12011 |
|
| 12012 |
|
| 12013 |
|
| 12014 |
|
| 12015 |
|
| 12016 |
|
| 12017 |
|
| 12018 |
|
| 12019 |
|
| 12020 |
|
| 12021 |
|
| 12022 |
public abstract void runPendingAnimations(); |
| 12023 |
|
| 12024 |
|
| 12025 |
|
| 12026 |
|
| 12027 |
|
| 12028 |
|
| 12029 |
|
| 12030 |
|
| 12031 |
|
| 12032 |
|
| 12033 |
|
| 12034 |
|
| 12035 |
public abstract void endAnimation(ViewHolder item); |
| 12036 |
|
| 12037 |
|
| 12038 |
|
| 12039 |
|
| 12040 |
|
| 12041 |
|
| 12042 |
|
| 12043 |
|
| 12044 |
|
| 12045 |
|
| 12046 |
public abstract void endAnimations(); |
| 12047 |
|
| 12048 |
|
| 12049 |
|
| 12050 |
|
| 12051 |
|
| 12052 |
|
| 12053 |
|
| 12054 |
|
| 12055 |
public abstract boolean isRunning(); |
| 12056 |
|
| 12057 |
|
| 12058 |
|
| 12059 |
|
| 12060 |
|
| 12061 |
|
| 12062 |
|
| 12063 |
|
| 12064 |
|
| 12065 |
|
| 12066 |
|
| 12067 |
|
| 12068 |
|
| 12069 |
|
| 12070 |
|
| 12071 |
|
| 12072 |
|
| 12073 |
|
| 12074 |
|
| 12075 |
|
| 12076 |
|
| 12077 |
public final void dispatchAnimationFinished(ViewHolder viewHolder) { |
| 12078 |
onAnimationFinished(viewHolder); |
| 12079 |
if (mListener != null) { |
| 12080 |
mListener.onAnimationFinished(viewHolder); |
| 12081 |
} |
| 12082 |
} |
| 12083 |
|
| 12084 |
|
| 12085 |
|
| 12086 |
|
| 12087 |
|
| 12088 |
|
| 12089 |
|
| 12090 |
|
| 12091 |
|
| 12092 |
public void onAnimationFinished(ViewHolder viewHolder) { |
| 12093 |
} |
| 12094 |
|
| 12095 |
|
| 12096 |
|
| 12097 |
|
| 12098 |
|
| 12099 |
|
| 12100 |
|
| 12101 |
|
| 12102 |
|
| 12103 |
|
| 12104 |
|
| 12105 |
|
| 12106 |
|
| 12107 |
|
| 12108 |
|
| 12109 |
|
| 12110 |
|
| 12111 |
|
| 12112 |
|
| 12113 |
|
| 12114 |
|
| 12115 |
|
| 12116 |
|
| 12117 |
|
| 12118 |
public final void dispatchAnimationStarted(ViewHolder viewHolder) { |
| 12119 |
onAnimationStarted(viewHolder); |
| 12120 |
} |
| 12121 |
|
| 12122 |
|
| 12123 |
|
| 12124 |
|
| 12125 |
|
| 12126 |
|
| 12127 |
|
| 12128 |
|
| 12129 |
public void onAnimationStarted(ViewHolder viewHolder) { |
| 12130 |
|
| 12131 |
} |
| 12132 |
|
| 12133 |
|
| 12134 |
|
| 12135 |
|
| 12136 |
|
| 12137 |
|
| 12138 |
|
| 12139 |
|
| 12140 |
|
| 12141 |
|
| 12142 |
|
| 12143 |
|
| 12144 |
|
| 12145 |
|
| 12146 |
|
| 12147 |
|
| 12148 |
|
| 12149 |
public final boolean isRunning(ItemAnimatorFinishedListener listener) { |
| 12150 |
boolean running = isRunning(); |
| 12151 |
if (listener != null) { |
| 12152 |
if (!running) { |
| 12153 |
listener.onAnimationsFinished(); |
| 12154 |
} else { |
| 12155 |
mFinishedListeners.add(listener); |
| 12156 |
} |
| 12157 |
} |
| 12158 |
return running; |
| 12159 |
} |
| 12160 |
|
| 12161 |
|
| 12162 |
|
| 12163 |
|
| 12164 |
|
| 12165 |
|
| 12166 |
|
| 12167 |
|
| 12168 |
|
| 12169 |
|
| 12170 |
|
| 12171 |
|
| 12172 |
|
| 12173 |
|
| 12174 |
|
| 12175 |
|
| 12176 |
|
| 12177 |
|
| 12178 |
|
| 12179 |
|
| 12180 |
|
| 12181 |
|
| 12182 |
public boolean canReuseUpdatedViewHolder(@NonNull ViewHolder viewHolder) { |
| 12183 |
return true; |
| 12184 |
} |
| 12185 |
|
| 12186 |
|
| 12187 |
|
| 12188 |
|
| 12189 |
|
| 12190 |
|
| 12191 |
|
| 12192 |
|
| 12193 |
|
| 12194 |
|
| 12195 |
|
| 12196 |
|
| 12197 |
|
| 12198 |
|
| 12199 |
|
| 12200 |
|
| 12201 |
|
| 12202 |
|
| 12203 |
|
| 12204 |
|
| 12205 |
|
| 12206 |
|
| 12207 |
|
| 12208 |
|
| 12209 |
|
| 12210 |
|
| 12211 |
public boolean canReuseUpdatedViewHolder(@NonNull ViewHolder viewHolder, |
| 12212 |
@NonNull List<Object> payloads) { |
| 12213 |
return canReuseUpdatedViewHolder(viewHolder); |
| 12214 |
} |
| 12215 |
|
| 12216 |
|
| 12217 |
|
| 12218 |
|
| 12219 |
|
| 12220 |
public final void dispatchAnimationsFinished() { |
| 12221 |
final int count = mFinishedListeners.size(); |
| 12222 |
for (int i = 0; i < count; ++i) { |
| 12223 |
mFinishedListeners.get(i).onAnimationsFinished(); |
| 12224 |
} |
| 12225 |
mFinishedListeners.clear(); |
| 12226 |
} |
| 12227 |
|
| 12228 |
|
| 12229 |
|
| 12230 |
|
| 12231 |
|
| 12232 |
|
| 12233 |
|
| 12234 |
|
| 12235 |
|
| 12236 |
|
| 12237 |
public ItemHolderInfo obtainHolderInfo() { |
| 12238 |
return new ItemHolderInfo(); |
| 12239 |
} |
| 12240 |
|
| 12241 |
|
| 12242 |
|
| 12243 |
|
| 12244 |
|
| 12245 |
|
| 12246 |
interface ItemAnimatorListener { |
| 12247 |
void onAnimationFinished(ViewHolder item); |
| 12248 |
} |
| 12249 |
|
| 12250 |
|
| 12251 |
|
| 12252 |
|
| 12253 |
|
| 12254 |
|
| 12255 |
|
| 12256 |
|
| 12257 |
public interface ItemAnimatorFinishedListener { |
| 12258 |
|
| 12259 |
|
| 12260 |
|
| 12261 |
void onAnimationsFinished(); |
| 12262 |
} |
| 12263 |
|
| 12264 |
|
| 12265 |
|
| 12266 |
|
| 12267 |
|
| 12268 |
|
| 12269 |
|
| 12270 |
|
| 12271 |
|
| 12272 |
|
| 12273 |
|
| 12274 |
|
| 12275 |
|
| 12276 |
public static class ItemHolderInfo { |
| 12277 |
|
| 12278 |
|
| 12279 |
|
| 12280 |
|
| 12281 |
public int left; |
| 12282 |
|
| 12283 |
|
| 12284 |
|
| 12285 |
|
| 12286 |
public int top; |
| 12287 |
|
| 12288 |
|
| 12289 |
|
| 12290 |
|
| 12291 |
public int right; |
| 12292 |
|
| 12293 |
|
| 12294 |
|
| 12295 |
|
| 12296 |
public int bottom; |
| 12297 |
|
| 12298 |
|
| 12299 |
|
| 12300 |
|
| 12301 |
|
| 12302 |
@AdapterChanges |
| 12303 |
public int changeFlags; |
| 12304 |
|
| 12305 |
public ItemHolderInfo() { |
| 12306 |
} |
| 12307 |
|
| 12308 |
|
| 12309 |
|
| 12310 |
|
| 12311 |
|
| 12312 |
|
| 12313 |
|
| 12314 |
|
| 12315 |
public ItemHolderInfo setFrom(RecyclerView.ViewHolder holder) { |
| 12316 |
return setFrom(holder, 0); |
| 12317 |
} |
| 12318 |
|
| 12319 |
|
| 12320 |
|
| 12321 |
|
| 12322 |
|
| 12323 |
|
| 12324 |
|
| 12325 |
|
| 12326 |
|
| 12327 |
|
| 12328 |
|
| 12329 |
public ItemHolderInfo setFrom(RecyclerView.ViewHolder holder, |
| 12330 |
@AdapterChanges int flags) { |
| 12331 |
final View view = holder.itemView; |
| 12332 |
this.left = view.getLeft(); |
| 12333 |
this.top = view.getTop(); |
| 12334 |
this.right = view.getRight(); |
| 12335 |
this.bottom = view.getBottom(); |
| 12336 |
return this; |
| 12337 |
} |
| 12338 |
} |
| 12339 |
} |
| 12340 |
|
| 12341 |
@Override |
| 12342 |
protected int getChildDrawingOrder(int childCount, int i) { |
| 12343 |
if (mChildDrawingOrderCallback == null) { |
| 12344 |
return super.getChildDrawingOrder(childCount, i); |
| 12345 |
} else { |
| 12346 |
return mChildDrawingOrderCallback.onGetChildDrawingOrder(childCount, i); |
| 12347 |
} |
| 12348 |
} |
| 12349 |
|
| 12350 |
|
| 12351 |
|
| 12352 |
|
| 12353 |
|
| 12354 |
|
| 12355 |
|
| 12356 |
|
| 12357 |
|
| 12358 |
public interface ChildDrawingOrderCallback { |
| 12359 |
|
| 12360 |
|
| 12361 |
|
| 12362 |
|
| 12363 |
|
| 12364 |
|
| 12365 |
|
| 12366 |
|
| 12367 |
|
| 12368 |
|
| 12369 |
int onGetChildDrawingOrder(int childCount, int i); |
| 12370 |
} |
| 12371 |
} |