androidx.recyclerview.widget.RecyclerView.ItemAnimator Java Examples

The following examples show how to use androidx.recyclerview.widget.RecyclerView.ItemAnimator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EpoxyVisibilityTracker.java    From epoxy with Apache License 2.0 6 votes vote down vote up
/**
 * Process a change event.
 * @param debug: string for debug usually the source of the call
 * @param checkItemAnimator: true if it need to check if ItemAnimator is running
 */
private void processChangeEvent(String debug, boolean checkItemAnimator) {
  final RecyclerView recyclerView = attachedRecyclerView;
  if (recyclerView != null) {
    final ItemAnimator itemAnimator = recyclerView.getItemAnimator();
    if (checkItemAnimator && itemAnimator != null) {
      // `itemAnimatorFinishedListener.onAnimationsFinished` will process visibility check
      // - If the animations are running `onAnimationsFinished` will be invoked on animations end.
      // - If the animations are not running `onAnimationsFinished` will be invoked right away.
      if (itemAnimator.isRunning(itemAnimatorFinishedListener)) {
        // If running process visibility now as `onAnimationsFinished` was not yet called
        processChangeEventWithDetachedView(null, debug);
      }
    } else {
      processChangeEventWithDetachedView(null, debug);
    }
  }
}
 
Example #2
Source File: FeatureAnimatorController.java    From FeatureAdapter with Apache License 2.0 5 votes vote down vote up
public boolean animateChange(@NonNull ItemAnimator itemAnimator, @NonNull ViewHolder oldHolder, @NonNull ViewHolder newHolder, @NonNull ItemHolderInfo preInfo, @NonNull ItemHolderInfo postInfo) {
  final FeatureAnimatorListener listener = viewTypeFeatureAnimatorMap.get(oldHolder.getItemViewType());
  if (listener != null) {
    final Animator animator = listener.setupChangeAnimation(itemAnimator, oldHolder, newHolder, preInfo, postInfo);
    if (animator != null) {
      animator.addListener(new CustomAnimationEndListener(itemAnimator, newHolder));
      viewHolderAnimatorMap.put(newHolder, animator);
      return true;
    }
  }
  return false;
}
 
Example #3
Source File: FeatureAnimatorController.java    From FeatureAdapter with Apache License 2.0 4 votes vote down vote up
CustomAnimationEndListener(ItemAnimator itemAnimator, ViewHolder holder) {
  this.holder = holder;
  this.itemAnimator = itemAnimator;
}
 
Example #4
Source File: RecyclerSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) boolean hasFixedSize,
    @Prop(optional = true) boolean clipToPadding,
    @Prop(optional = true) int leftPadding,
    @Prop(optional = true) int rightPadding,
    @Prop(optional = true) int topPadding,
    @Prop(optional = true) int bottomPadding,
    @Prop(optional = true, resType = ResType.COLOR) @Nullable
        Integer refreshProgressBarBackgroundColor,
    @Prop(optional = true, resType = ResType.COLOR) int refreshProgressBarColor,
    @Prop(optional = true) boolean clipChildren,
    @Prop(optional = true) boolean nestedScrollingEnabled,
    @Prop(optional = true) int scrollBarStyle,
    @Prop(optional = true) RecyclerView.ItemDecoration itemDecoration,
    @Prop(optional = true) boolean horizontalFadingEdgeEnabled,
    @Prop(optional = true) boolean verticalFadingEdgeEnabled,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) int fadingEdgeLength,
    @Prop(optional = true) @IdRes int recyclerViewId,
    @Prop(optional = true) int overScrollMode,
    @Prop(optional = true, isCommonProp = true) CharSequence contentDescription,
    @Prop(optional = true) ItemAnimator itemAnimator) {
  final RecyclerView recyclerView = sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout");
  }
  recyclerView.setContentDescription(contentDescription);
  recyclerView.setHasFixedSize(hasFixedSize);
  recyclerView.setClipToPadding(clipToPadding);
  sectionsRecycler.setClipToPadding(clipToPadding);
  ViewCompat.setPaddingRelative(
      recyclerView, leftPadding, topPadding, rightPadding, bottomPadding);
  recyclerView.setClipChildren(clipChildren);
  sectionsRecycler.setClipChildren(clipChildren);
  recyclerView.setNestedScrollingEnabled(nestedScrollingEnabled);
  sectionsRecycler.setNestedScrollingEnabled(nestedScrollingEnabled);
  recyclerView.setScrollBarStyle(scrollBarStyle);
  recyclerView.setHorizontalFadingEdgeEnabled(horizontalFadingEdgeEnabled);
  recyclerView.setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled);
  recyclerView.setFadingEdgeLength(fadingEdgeLength);
  // TODO (t14949498) determine if this is necessary
  recyclerView.setId(recyclerViewId);
  recyclerView.setOverScrollMode(overScrollMode);
  if (refreshProgressBarBackgroundColor != null) {
    sectionsRecycler.setProgressBackgroundColorSchemeColor(refreshProgressBarBackgroundColor);
  }
  sectionsRecycler.setColorSchemeColors(refreshProgressBarColor);

  if (itemDecoration != null) {
    recyclerView.addItemDecoration(itemDecoration);
  }

  sectionsRecycler.setItemAnimator(
      itemAnimator != RecyclerSpec.itemAnimator ? itemAnimator : new NoUpdateItemAnimator());

  binder.mount(recyclerView);
}
 
Example #5
Source File: RecyclerSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@ShouldUpdate(onMount = true)
protected static boolean shouldUpdate(
    @Prop Diff<Binder<RecyclerView>> binder,
    @Prop(optional = true) Diff<Boolean> hasFixedSize,
    @Prop(optional = true) Diff<Boolean> clipToPadding,
    @Prop(optional = true) Diff<Integer> leftPadding,
    @Prop(optional = true) Diff<Integer> rightPadding,
    @Prop(optional = true) Diff<Integer> topPadding,
    @Prop(optional = true) Diff<Integer> bottomPadding,
    @Prop(optional = true, resType = ResType.COLOR)
        Diff<Integer> refreshProgressBarBackgroundColor,
    @Prop(optional = true, resType = ResType.COLOR) Diff<Integer> refreshProgressBarColor,
    @Prop(optional = true) Diff<Boolean> clipChildren,
    @Prop(optional = true) Diff<Integer> scrollBarStyle,
    @Prop(optional = true) Diff<RecyclerView.ItemDecoration> itemDecoration,
    @Prop(optional = true) Diff<Boolean> horizontalFadingEdgeEnabled,
    @Prop(optional = true) Diff<Boolean> verticalFadingEdgeEnabled,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) Diff<Integer> fadingEdgeLength,
    @Prop(optional = true) Diff<ItemAnimator> itemAnimator,
    @State Diff<Integer> measureVersion) {

  if (measureVersion.getPrevious().intValue() != measureVersion.getNext().intValue()) {
    return true;
  }

  if (binder.getPrevious() != binder.getNext()) {
    return true;
  }

  if (!hasFixedSize.getPrevious().equals(hasFixedSize.getNext())) {
    return true;
  }

  if (!clipToPadding.getPrevious().equals(clipToPadding.getNext())) {
    return true;
  }

  if (!leftPadding.getPrevious().equals(leftPadding.getNext())) {
    return true;
  }

  if (!rightPadding.getPrevious().equals(rightPadding.getNext())) {
    return true;
  }

  if (!topPadding.getPrevious().equals(topPadding.getNext())) {
    return true;
  }

  if (!bottomPadding.getPrevious().equals(bottomPadding.getNext())) {
    return true;
  }

  if (!clipChildren.getPrevious().equals(clipChildren.getNext())) {
    return true;
  }

  if (!scrollBarStyle.getPrevious().equals(scrollBarStyle.getNext())) {
    return true;
  }

  if (!horizontalFadingEdgeEnabled.getPrevious().equals(horizontalFadingEdgeEnabled.getNext())) {
    return true;
  }

  if (!verticalFadingEdgeEnabled.getPrevious().equals(verticalFadingEdgeEnabled.getNext())) {
    return true;
  }

  if (!fadingEdgeLength.getPrevious().equals(fadingEdgeLength.getNext())) {
    return true;
  }

  Integer previousRefreshBgColor = refreshProgressBarBackgroundColor.getPrevious();
  Integer nextRefreshBgColor = refreshProgressBarBackgroundColor.getNext();
  if (previousRefreshBgColor == null
      ? nextRefreshBgColor != null
      : !previousRefreshBgColor.equals(nextRefreshBgColor)) {
    return true;
  }

  if (!refreshProgressBarColor.getPrevious().equals(refreshProgressBarColor.getNext())) {
    return true;
  }

  final ItemAnimator previousItemAnimator = itemAnimator.getPrevious();
  final ItemAnimator nextItemAnimator = itemAnimator.getNext();

  if (previousItemAnimator == null
      ? nextItemAnimator != null
      : !previousItemAnimator.getClass().equals(nextItemAnimator.getClass())) {
    return true;
  }

  final RecyclerView.ItemDecoration previous = itemDecoration.getPrevious();
  final RecyclerView.ItemDecoration next = itemDecoration.getNext();
  final boolean itemDecorationIsEqual =
      (previous == null) ? (next == null) : previous.equals(next);

  return !itemDecorationIsEqual;
}
 
Example #6
Source File: SectionsRecyclerView.java    From litho with Apache License 2.0 4 votes vote down vote up
public void setItemAnimator(ItemAnimator itemAnimator) {
  mDetachedItemAnimator = mRecyclerView.getItemAnimator();
  mRecyclerView.setItemAnimator(itemAnimator);
}