android.support.v7.widget.RecyclerView.ViewHolder Java Examples

The following examples show how to use android.support.v7.widget.RecyclerView.ViewHolder. 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: HeaderAdapter.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
void disposeLoad(final ViewHolder holder) {
  //
  final ViewGroup parent =
      holder.itemView instanceof ViewGroup ? (ViewGroup) holder.itemView : null;
  if (parent != null) {
    for (int i = 0; i < parent.getChildCount(); i++) {
      final View childView = parent.getChildAt(i);
      if (childView instanceof SimpleDraweeView) {
        final Object tag = childView.getTag();
        if (tag instanceof Disposable) {
          final Disposable disposable = (Disposable) tag;
          if (!disposable.isDisposed()) {
            disposable.dispose();
          }
          childView.setTag(null);
        }
      }
    }
  }
}
 
Example #2
Source File: ScaleInItemAnimator.java    From androidexamples with Apache License 2.0 6 votes vote down vote up
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) {
    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder == item) {
        changeInfo.oldHolder = null;
        oldItem = true;
    } else {
        return false;
    }
    ViewCompat.setAlpha(item.itemView, 1);
    ViewCompat.setTranslationX(item.itemView, 0);
    ViewCompat.setTranslationY(item.itemView, 0);
    dispatchChangeFinished(item, oldItem);
    return true;
}
 
Example #3
Source File: BaseItemAnimator.java    From RecyclerviewAnimators with Apache License 2.0 6 votes vote down vote up
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) {
    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder == item) {
        changeInfo.oldHolder = null;
        oldItem = true;
    } else {
        return false;
    }
    ViewCompat.setAlpha(item.itemView, 1);
    ViewCompat.setTranslationX(item.itemView, 0);
    ViewCompat.setTranslationY(item.itemView, 0);
    dispatchChangeFinished(item, oldItem);
    return true;
}
 
Example #4
Source File: CustomItemAnimator.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) {
    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder == item) {
        changeInfo.oldHolder = null;
        oldItem = true;
    } else {
        return false;
    }
    ViewCompat.setAlpha(item.itemView, 1);
    ViewCompat.setTranslationX(item.itemView, 0);
    ViewCompat.setTranslationY(item.itemView, 0);
    dispatchChangeFinished(item, oldItem);
    return true;
}
 
Example #5
Source File: ItemDragHelperCallback.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onMoved(RecyclerView recyclerView, ViewHolder viewHolder, int fromPos, ViewHolder target, int toPos, int x, int y) {
    if (recyclerView.getAdapter() instanceof OnGridItemMoveListener) {
        OnGridItemMoveListener listener = (OnGridItemMoveListener) recyclerView.getAdapter();
        ChannelFragmentAdapter adapter = (ChannelFragmentAdapter) recyclerView.getAdapter();
        int itemSize = adapter.getItemCount();
        int topSize = adapter.getTopSize();
        if (fromPos > toPos) {
            if (toPos == topSize + 1) {
                callBack(listener, viewHolder, fromPos, target, toPos, true, false);
            } else {
                callBack(listener, viewHolder, fromPos, target, toPos, false, false);
            }
        } else if (toPos == itemSize - 1) {
            callBack(listener, viewHolder, fromPos, target, toPos, false, true);
        } else {
            callBack(listener, viewHolder, fromPos, target, toPos, false, false);
        }
    }
}
 
Example #6
Source File: ScaleInItemAnimator.java    From androidexamples with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
                             int fromX, int fromY, int toX, int toY) {
    final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    endAnimation(oldHolder);
    int deltaX = (int) (toX - fromX - prevTranslationX);
    int deltaY = (int) (toY - fromY - prevTranslationY);
    // recover prev translation state after ending animation
    ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
    ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
    ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
    if (newHolder != null && newHolder.itemView != null) {
        // carry over translation values
        endAnimation(newHolder);
        ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
        ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
        ViewCompat.setAlpha(newHolder.itemView, 0);
    }
    mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
    return true;
}
 
Example #7
Source File: BaseItemAnimator.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) {
  boolean oldItem = false;
  if (changeInfo.newHolder == item) {
    changeInfo.newHolder = null;
  } else if (changeInfo.oldHolder == item) {
    changeInfo.oldHolder = null;
    oldItem = true;
  } else {
    return false;
  }
  ViewCompat.setAlpha(item.itemView, 1);
  ViewCompat.setTranslationX(item.itemView, 0);
  ViewCompat.setTranslationY(item.itemView, 0);
  dispatchChangeFinished(item, oldItem);
  return true;
}
 
Example #8
Source File: BookmarkItemsAdapter.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    BookmarkId id = getItem(position);

    switch (getItemViewType(position)) {
        case PROMO_HEADER_VIEW:
        case DIVIDER_VIEW:
            break;
        case FOLDER_VIEW:
            ((BookmarkRow) holder.itemView).setBookmarkId(id);
            break;
        case BOOKMARK_VIEW:
            ((BookmarkRow) holder.itemView).setBookmarkId(id);
            break;
        default:
            assert false : "View type not supported!";
    }
}
 
Example #9
Source File: BaseItemAnimator.java    From MultiView with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateMove(final ViewHolder holder, int fromX, int fromY,
                           int toX, int toY) {
    final View view = holder.itemView;
    fromX += ViewCompat.getTranslationX(holder.itemView);
    fromY += ViewCompat.getTranslationY(holder.itemView);
    endAnimation(holder);
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    // pre-translate here while waiting for the other(remove) to finish
    if (deltaX != 0) {
        ViewCompat.setTranslationX(view, -deltaX);
    }
    if (deltaY != 0) {
        ViewCompat.setTranslationY(view, -deltaY);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example #10
Source File: BasicAdapter.java    From basic-adapter with MIT License 5 votes vote down vote up
private void configLoad(ViewHolder holder) {
    //if size of data is 0,empty view shows if exists and loading/loaded view  hides.
    if (mData.size() == 0) {
        return;
    }
    if (mParams.loading != null && isLoadEnable()) {
        mParams.loading.setVisibility(View.VISIBLE);
        if (mParams.onLoadMoreListener == null) {
            throw new RuntimeException("OnLoadMoreListener must be init when build loading view !");
        }
        mParams.onLoadMoreListener.onLoad();
    }
}
 
Example #11
Source File: BaseItemAnimator.java    From MultiView with Apache License 2.0 5 votes vote down vote up
private ChangeInfo(ViewHolder oldHolder, ViewHolder newHolder,
                   int fromX, int fromY, int toX, int toY) {
    this(oldHolder, newHolder);
    this.fromX = fromX;
    this.fromY = fromY;
    this.toX = toX;
    this.toY = toY;
}
 
Example #12
Source File: RepositoryAdapter.java    From agera with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the {@link RepositoryAdapter} that presents the provided repositories in order and
 * observes the repositories as well as any additional observables while the provided
 * {@link Activity} is started (between (between {@link Activity#onStart()} and
 * {@link Activity#onStop()}).
 * <p>
 * Note: Can only be called from {@link Activity#onCreate} ()}
 */
@TargetApi(14)
@NonNull
public Adapter<ViewHolder> whileStarted(@NonNull final Activity activity) {
  final RepositoryAdapter repositoryAdapter = new RepositoryAdapter(this);
  activity.getApplication().registerActivityLifecycleCallbacks(
      new WhileStartedActivityLifecycleCallbacks(activity, repositoryAdapter));
  return repositoryAdapter;
}
 
Example #13
Source File: RepositoryAdapterTest.java    From agera with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCallRecycleForOnFailedToRecycleViewForLayoutPresenter() {
  repositoryAdapter.getItemCount(); //Trigger a refresh

  repositoryAdapter.startObserving();
  updateDispatcher.update();
  runUiThreadTasksIncludingDelayedTasks();
  repositoryAdapter.stopObserving();
  final ViewHolder viewHolder = new ViewHolder(view) {};
  repositoryAdapter.onBindViewHolder(viewHolder, 4);

  repositoryAdapter.onFailedToRecycleView(viewHolder);

  verify(layoutPresenter).recycle(view);
}
 
Example #14
Source File: BookmarkPromoHeader.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return Signin promo header {@link ViewHolder} instance that can be used with
 *         {@link RecyclerView}.
 */
ViewHolder createHolder(ViewGroup parent) {
    SigninAndSyncView.Listener listener = new SigninAndSyncView.Listener() {
        @Override
        public void onViewDismissed() {
            setSigninPromoDeclined();
            updateShouldShow(true);
        }
    };

    return new ViewHolder(
            SigninAndSyncView.create(parent, listener, SigninAccessPoint.BOOKMARK_MANAGER)) {};
}
 
Example #15
Source File: CustomItemAnimator.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
                             int fromX, int fromY, int toX, int toY) {
    if (oldHolder == newHolder) {
        // Don't know how to run change animations when the same view holder is re-used.
        // run a move animation to handle position changes.
        return animateMove(oldHolder, fromX, fromY, toX, toY);
    }
    final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    resetAnimation(oldHolder);
    int deltaX = (int) (toX - fromX - prevTranslationX);
    int deltaY = (int) (toY - fromY - prevTranslationY);
    // recover prev translation state after ending animation
    ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
    ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
    ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
    if (newHolder != null) {
        // carry over translation values
        resetAnimation(newHolder);
        ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
        ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
        ViewCompat.setAlpha(newHolder.itemView, 0);
    }
    mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
    return false;
}
 
Example #16
Source File: VerticalItemAnimator.java    From JumpGo with Mozilla Public License 2.0 5 votes vote down vote up
private ChangeInfo(ViewHolder oldHolder, ViewHolder newHolder,
                   int fromX, int fromY, int toX, int toY) {
    this(oldHolder, newHolder);
    this.fromX = fromX;
    this.fromY = fromY;
    this.toX = toX;
    this.toY = toY;
}
 
Example #17
Source File: BaseItemAnimator.java    From onboarding-examples-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
                             int fromX, int fromY, int toX, int toY) {
    if (oldHolder == newHolder) {
        // Don't know how to run change animations when the same view holder is re-used.
        // run a move animation to handle position changes.
        return animateMove(oldHolder, fromX, fromY, toX, toY);
    }
    final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    resetAnimation(oldHolder);
    int deltaX = (int) (toX - fromX - prevTranslationX);
    int deltaY = (int) (toY - fromY - prevTranslationY);
    // recover prev translation state after ending animation
    ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
    ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
    ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
    if (newHolder != null) {
        // carry over translation values
        resetAnimation(newHolder);
        ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
        ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
        ViewCompat.setAlpha(newHolder.itemView, 0);
    }
    mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
    return true;
}
 
Example #18
Source File: XRecylerAdapter.java    From android-Stupid-Adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder vh, int position) {
	XRecyclerViewHolder<T> holder = null;
	if (vh.itemView.getTag() instanceof XRecyclerViewHolder) {
		holder = (XRecyclerViewHolder<T>) vh.itemView.getTag();
		holder.onDestory(position, getItemCount());
		holder.setView(vh.itemView).getView(mData.get(position), position,
				isOnScrolling());
	}

}
 
Example #19
Source File: ItemDragHelperCallback.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean onMove(RecyclerView recyclerView, ViewHolder viewHolder, ViewHolder target) {
    if (viewHolder.getItemViewType() != target.getItemViewType() && !(recyclerView.getAdapter() instanceof OnGridItemMoveListener)) {
        return false;
    }
    if (recyclerView.getAdapter() instanceof OnItemMoveListener) {
        ((OnItemMoveListener) recyclerView.getAdapter()).onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
    }
    return true;
}
 
Example #20
Source File: BaseItemAnimator.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
private MoveInfo(ViewHolder holder, int fromX, int fromY, int toX, int toY) {
  this.holder = holder;
  this.fromX = fromX;
  this.fromY = fromY;
  this.toX = toX;
  this.toY = toY;
}
 
Example #21
Source File: ItemAnimator.java    From FancyAccordionView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canReuseUpdatedViewHolder(@NonNull ViewHolder viewHolder,
                                         @NonNull List<Object> payloads) {
    final boolean defaultReusePolicy = super.canReuseUpdatedViewHolder(viewHolder, payloads);
    // Whenever we have a payload, this is an in-place animation.
    return !payloads.isEmpty() || defaultReusePolicy;
}
 
Example #22
Source File: DownloadHistoryAdapter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public ViewHolder createViewHolder(ViewGroup parent) {
    DownloadItemView v = (DownloadItemView) LayoutInflater.from(parent.getContext()).inflate(
            R.layout.download_item_view, parent, false);
    v.setSelectionDelegate(getSelectionDelegate());
    return new DownloadHistoryItemViewHolder(v);
}
 
Example #23
Source File: BaseItemAnimator.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
private void doAnimateRemove(final RecyclerView.ViewHolder holder) {
  if (holder instanceof AnimateViewHolder) {
    ((AnimateViewHolder) holder).animateRemoveImpl(new DefaultRemoveVpaListener(holder));
  } else {
    animateRemoveImpl(holder);
  }

  mRemoveAnimations.add(holder);
}
 
Example #24
Source File: ItemAnimator.java    From FancyAccordionView with Apache License 2.0 5 votes vote down vote up
@Override
public
@NonNull
ItemHolderInfo recordPreLayoutInformation(@NonNull State state,
                                          @NonNull ViewHolder viewHolder, @AdapterChanges int changeFlags,
                                          @NonNull List<Object> payloads) {
    final ItemHolderInfo itemHolderInfo = super.recordPreLayoutInformation(state, viewHolder,
            changeFlags, payloads);
    if (itemHolderInfo instanceof PayloadItemHolderInfo) {
        ((PayloadItemHolderInfo) itemHolderInfo).setPayloads(payloads);
    }
    return itemHolderInfo;
}
 
Example #25
Source File: CustomItemAnimator.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
private MoveInfo(ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    this.holder = holder;
    this.fromX = fromX;
    this.fromY = fromY;
    this.toX = toX;
    this.toY = toY;
}
 
Example #26
Source File: BookmarkItemsAdapter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    assert mDelegate != null;

    switch (viewType) {
        case PROMO_HEADER_VIEW:
            ViewHolder promoView = mPromoHeaderManager.createHolder(parent);
            MarginResizer.createWithViewAdapter(promoView.itemView,
                    mDelegate.getSelectableListLayout().getUiConfig(),
                    parent.getResources().getDimensionPixelSize(
                            R.dimen.signin_and_sync_view_padding),
                    SelectableListLayout.getDefaultListItemLateralShadowSizePx(
                            parent.getResources()));
            return promoView;
        case FOLDER_VIEW:
            BookmarkFolderRow folder = (BookmarkFolderRow) LayoutInflater.from(
                    parent.getContext()).inflate(R.layout.bookmark_folder_row, parent, false);
            folder.onBookmarkDelegateInitialized(mDelegate);
            folder.configureWideDisplayStyle(mDelegate.getSelectableListLayout().getUiConfig());
            mFolderRows.add(folder);
            return new ItemViewHolder(folder);
        case BOOKMARK_VIEW:
            BookmarkItemRow item = (BookmarkItemRow) LayoutInflater.from(
                    parent.getContext()).inflate(R.layout.bookmark_item_row, parent, false);
            item.onBookmarkDelegateInitialized(mDelegate);
            item.configureWideDisplayStyle(mDelegate.getSelectableListLayout().getUiConfig());
            mBookmarkRows.add(item);
            return new ItemViewHolder(item);
        default:
            assert false;
            return null;
    }
}
 
Example #27
Source File: NewTabPageAdapter.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, ViewHolder viewHolder,
        float dX, float dY, int actionState, boolean isCurrentlyActive) {
    assert viewHolder instanceof NewTabPageViewHolder;

    ((NewTabPageViewHolder) viewHolder).updateViewStateForDismiss(dX);
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
 
Example #28
Source File: HorizontalItemAnimator.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean animateAdd(final ViewHolder holder) {
    resetAnimation(holder);
    ViewCompat.setAlpha(holder.itemView, 0);
    ViewCompat.setTranslationY(holder.itemView, holder.itemView.getHeight());
    mPendingAdditions.add(holder);
    return true;
}
 
Example #29
Source File: ScaleInItemAnimator.java    From androidexamples with Apache License 2.0 5 votes vote down vote up
@Override
public boolean animateAdd(final ViewHolder holder) {
    endAnimation(holder);
    ViewCompat.setAlpha(holder.itemView, 0);

    mPendingAdditions.add(holder);
    return true;
}
 
Example #30
Source File: ImageRecyclerAdapter.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    if (holder instanceof CameraViewHolder){
        ((CameraViewHolder)holder).bindCamera();
    }else if (holder instanceof ImageViewHolder){
        ((ImageViewHolder)holder).bind(position);
    }
}