use of android.support.v7.widget.helper.ItemTouchHelper.END in project recyclerview-animators by wasabeef.
the class BaseItemAnimator method animateMoveImpl.
private void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
final View view = holder.itemView;
final int deltaX = toX - fromX;
final int deltaY = toY - fromY;
if (deltaX != 0) {
ViewCompat.animate(view).translationX(0);
}
if (deltaY != 0) {
ViewCompat.animate(view).translationY(0);
}
// TODO: make EndActions end listeners instead, since end actions aren't called when
// vpas are canceled (and can't end them. why?)
// need listener functionality in VPACompat for this. Ick.
mMoveAnimations.add(holder);
final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
animation.setDuration(getMoveDuration()).setListener(new VpaListenerAdapter() {
@Override
public void onAnimationStart(View view) {
dispatchMoveStarting(holder);
}
@Override
public void onAnimationCancel(View view) {
if (deltaX != 0) {
ViewCompat.setTranslationX(view, 0);
}
if (deltaY != 0) {
ViewCompat.setTranslationY(view, 0);
}
}
@Override
public void onAnimationEnd(View view) {
animation.setListener(null);
dispatchMoveFinished(holder);
mMoveAnimations.remove(holder);
dispatchFinishedWhenDone();
}
}).start();
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project recyclerview-animators by wasabeef.
the class BaseItemAnimator method endAnimation.
@Override
public void endAnimation(ViewHolder item) {
final View view = item.itemView;
// this will trigger end callback which should set properties to their target values.
ViewCompat.animate(view).cancel();
// TODO if some other animations are chained to end, how do we cancel them as well?
for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
MoveInfo moveInfo = mPendingMoves.get(i);
if (moveInfo.holder == item) {
ViewCompat.setTranslationY(view, 0);
ViewCompat.setTranslationX(view, 0);
dispatchMoveFinished(item);
mPendingMoves.remove(i);
}
}
endChangeAnimation(mPendingChanges, item);
if (mPendingRemovals.remove(item)) {
ViewHelper.clear(item.itemView);
dispatchRemoveFinished(item);
}
if (mPendingAdditions.remove(item)) {
ViewHelper.clear(item.itemView);
dispatchAddFinished(item);
}
for (int i = mChangesList.size() - 1; i >= 0; i--) {
ArrayList<ChangeInfo> changes = mChangesList.get(i);
endChangeAnimation(changes, item);
if (changes.isEmpty()) {
mChangesList.remove(i);
}
}
for (int i = mMovesList.size() - 1; i >= 0; i--) {
ArrayList<MoveInfo> moves = mMovesList.get(i);
for (int j = moves.size() - 1; j >= 0; j--) {
MoveInfo moveInfo = moves.get(j);
if (moveInfo.holder == item) {
ViewCompat.setTranslationY(view, 0);
ViewCompat.setTranslationX(view, 0);
dispatchMoveFinished(item);
moves.remove(j);
if (moves.isEmpty()) {
mMovesList.remove(i);
}
break;
}
}
}
for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
ArrayList<ViewHolder> additions = mAdditionsList.get(i);
if (additions.remove(item)) {
ViewHelper.clear(item.itemView);
dispatchAddFinished(item);
if (additions.isEmpty()) {
mAdditionsList.remove(i);
}
}
}
// animations should be ended by the cancel above.
if (mRemoveAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mRemoveAnimations list");
}
if (mAddAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mAddAnimations list");
}
if (mChangeAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mChangeAnimations list");
}
if (mMoveAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mMoveAnimations list");
}
dispatchFinishedWhenDone();
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project WordPress-Android by wordpress-mobile.
the class MediaGridAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(GridViewHolder holder, int position) {
if (!isValidPosition(position)) {
return;
}
mCursor.moveToPosition(position);
final int localMediaId = mCursor.getInt(mCursor.getColumnIndex(MediaModelTable.ID));
String state = mCursor.getString(mCursor.getColumnIndex(MediaModelTable.UPLOAD_STATE));
String fileName = mCursor.getString(mCursor.getColumnIndex(MediaModelTable.FILE_NAME));
String title = mCursor.getString(mCursor.getColumnIndex(MediaModelTable.TITLE));
String filePath = mCursor.getString(mCursor.getColumnIndex(MediaModelTable.FILE_PATH));
String thumbUrl = WordPressMediaUtils.getNetworkThumbnailUrl(mCursor, mSite, mThumbWidth);
String mimeType = StringUtils.notNullStr(mCursor.getString(mCursor.getColumnIndex(MediaModelTable.MIME_TYPE)));
boolean isLocalFile = MediaUtils.isLocalFile(state);
boolean isSelected = isItemSelected(localMediaId);
holder.titleView.setText(TextUtils.isEmpty(title) ? fileName : title);
String fileExtension = MediaUtils.getExtensionForMimeType(mimeType);
holder.fileTypeView.setText(fileExtension.toUpperCase());
if (isLocalFile) {
loadLocalImage(filePath, holder.imageView);
} else if (!TextUtils.isEmpty(thumbUrl)) {
WordPressMediaUtils.loadNetworkImage(thumbUrl, holder.imageView, mImageLoader);
} else {
holder.imageView.setImageDrawable(null);
}
// show selection count when selected
holder.selectionCountTextView.setVisibility(isSelected ? View.VISIBLE : View.GONE);
if (isSelected) {
int count = mSelectedItems.indexOf(localMediaId) + 1;
holder.selectionCountTextView.setText(Integer.toString(count));
}
// make sure the thumbnail scale reflects its selection state
float scale = isSelected ? SCALE_SELECTED : SCALE_NORMAL;
if (holder.imageView.getScaleX() != scale) {
holder.imageView.setScaleX(scale);
holder.imageView.setScaleY(scale);
}
// show upload state unless it's already uploaded
if (!TextUtils.isEmpty(state) && !state.equalsIgnoreCase(MediaUploadState.UPLOADED.name())) {
holder.stateContainer.setVisibility(View.VISIBLE);
holder.stateTextView.setText(state);
// hide progressbar and add onclick to retry failed uploads
if (state.equalsIgnoreCase(MediaUploadState.FAILED.name())) {
holder.progressUpload.setVisibility(View.GONE);
holder.stateTextView.setText(mContext.getString(R.string.retry));
holder.stateTextView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.media_retry_image, 0, 0);
holder.stateTextView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!isInMultiSelect()) {
((TextView) v).setText(R.string.upload_queued);
((TextView) v).setCompoundDrawables(null, null, null, null);
v.setOnClickListener(null);
if (mCallback != null) {
mCallback.onAdapterRetryUpload(localMediaId);
}
}
}
});
} else {
holder.progressUpload.setVisibility(View.VISIBLE);
holder.stateTextView.setOnClickListener(null);
holder.stateTextView.setCompoundDrawables(null, null, null, null);
}
} else {
holder.stateContainer.setVisibility(View.GONE);
holder.stateContainer.setOnClickListener(null);
}
// if we are near the end, make a call to fetch more
if (position == getItemCount() - 1 && !mHasRetrievedAll && mCallback != null) {
mCallback.onAdapterFetchMoreData();
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project WordPress-Android by wordpress-mobile.
the class PostsListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
// nothing to do if this is the static endlist indicator
if (getItemViewType(position) == VIEW_TYPE_ENDLIST_INDICATOR) {
return;
}
final PostModel post = mPosts.get(position);
Context context = holder.itemView.getContext();
if (holder instanceof PostViewHolder) {
PostViewHolder postHolder = (PostViewHolder) holder;
if (StringUtils.isNotEmpty(post.getTitle())) {
postHolder.txtTitle.setText(post.getTitle());
} else {
postHolder.txtTitle.setText("(" + context.getResources().getText(R.string.untitled) + ")");
}
String cleanPostExcerpt = PostUtils.getPostListExcerptFromPost(post);
if (StringUtils.isNotEmpty(cleanPostExcerpt)) {
postHolder.txtExcerpt.setVisibility(View.VISIBLE);
postHolder.txtExcerpt.setText(PostUtils.collapseShortcodes(cleanPostExcerpt));
} else {
postHolder.txtExcerpt.setVisibility(View.GONE);
}
if (post.getFeaturedImageId() > 0 || mFeaturedImageUrls.containsKey(post.getId())) {
postHolder.imgFeatured.setVisibility(View.VISIBLE);
postHolder.imgFeatured.setImageUrl(mFeaturedImageUrls.get(post.getId()), WPNetworkImageView.ImageType.PHOTO);
} else {
postHolder.imgFeatured.setVisibility(View.GONE);
}
// local drafts say "delete" instead of "trash"
if (post.isLocalDraft()) {
postHolder.txtDate.setVisibility(View.GONE);
postHolder.btnTrash.setButtonType(PostListButton.BUTTON_DELETE);
} else {
postHolder.txtDate.setText(PostUtils.getFormattedDate(post));
postHolder.txtDate.setVisibility(View.VISIBLE);
postHolder.btnTrash.setButtonType(PostListButton.BUTTON_TRASH);
}
if (PostUploadService.isPostUploading(post)) {
postHolder.disabledOverlay.setVisibility(View.VISIBLE);
} else {
postHolder.disabledOverlay.setVisibility(View.GONE);
}
updateStatusText(postHolder.txtStatus, post);
configurePostButtons(postHolder, post);
} else if (holder instanceof PageViewHolder) {
PageViewHolder pageHolder = (PageViewHolder) holder;
if (StringUtils.isNotEmpty(post.getTitle())) {
pageHolder.txtTitle.setText(post.getTitle());
} else {
pageHolder.txtTitle.setText("(" + context.getResources().getText(R.string.untitled) + ")");
}
String dateStr = getPageDateHeaderText(context, post);
pageHolder.txtDate.setText(dateStr);
updateStatusText(pageHolder.txtStatus, post);
// don't show date header if same as previous
boolean showDate;
if (position > 0) {
String prevDateStr = getPageDateHeaderText(context, mPosts.get(position - 1));
showDate = !prevDateStr.equals(dateStr);
} else {
showDate = true;
}
pageHolder.dateHeader.setVisibility(showDate ? View.VISIBLE : View.GONE);
// no "..." more button when uploading
pageHolder.btnMore.setVisibility(PostUploadService.isPostUploading(post) ? View.GONE : View.VISIBLE);
pageHolder.btnMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showPagePopupMenu(v, post);
}
});
// only show the top divider for the first item
pageHolder.dividerTop.setVisibility(position == 0 ? View.VISIBLE : View.GONE);
if (PostUploadService.isPostUploading(post)) {
pageHolder.disabledOverlay.setVisibility(View.VISIBLE);
} else {
pageHolder.disabledOverlay.setVisibility(View.GONE);
}
}
// load more posts when we near the end
if (mOnLoadMoreListener != null && position >= mPosts.size() - 1 && position >= PostsListFragment.POSTS_REQUEST_COUNT - 1) {
mOnLoadMoreListener.onLoadMore();
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnPostSelectedListener != null) {
mOnPostSelectedListener.onPostSelected(post);
}
}
});
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project Lightning-Browser by anthonycr.
the class VerticalItemAnimator method endAnimation.
@Override
public void endAnimation(ViewHolder item) {
final View view = item.itemView;
// this will trigger end callback which should set properties to their target values.
ViewCompat.animate(view).cancel();
// TODO if some other animations are chained to end, how do we cancel them as well?
for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
MoveInfo moveInfo = mPendingMoves.get(i);
if (moveInfo.holder == item) {
ViewCompat.setTranslationY(view, 0);
ViewCompat.setTranslationX(view, 0);
dispatchMoveFinished(item);
mPendingMoves.remove(i);
}
}
endChangeAnimation(mPendingChanges, item);
if (mPendingRemovals.remove(item)) {
ViewCompat.setAlpha(view, 1);
dispatchRemoveFinished(item);
}
if (mPendingAdditions.remove(item)) {
ViewCompat.setAlpha(view, 1);
dispatchAddFinished(item);
}
for (int i = mChangesList.size() - 1; i >= 0; i--) {
ArrayList<ChangeInfo> changes = mChangesList.get(i);
endChangeAnimation(changes, item);
if (changes.isEmpty()) {
mChangesList.remove(i);
}
}
for (int i = mMovesList.size() - 1; i >= 0; i--) {
ArrayList<MoveInfo> moves = mMovesList.get(i);
for (int j = moves.size() - 1; j >= 0; j--) {
MoveInfo moveInfo = moves.get(j);
if (moveInfo.holder == item) {
ViewCompat.setTranslationY(view, 0);
ViewCompat.setTranslationX(view, 0);
dispatchMoveFinished(item);
moves.remove(j);
if (moves.isEmpty()) {
mMovesList.remove(i);
}
break;
}
}
}
for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
ArrayList<ViewHolder> additions = mAdditionsList.get(i);
if (additions.remove(item)) {
ViewCompat.setAlpha(view, 1);
dispatchAddFinished(item);
if (additions.isEmpty()) {
mAdditionsList.remove(i);
}
}
}
//noinspection PointlessBooleanExpression,ConstantConditions
if (mRemoveAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mRemoveAnimations list");
}
//noinspection PointlessBooleanExpression,ConstantConditions
if (mAddAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mAddAnimations list");
}
//noinspection PointlessBooleanExpression,ConstantConditions
if (mChangeAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mChangeAnimations list");
}
//noinspection PointlessBooleanExpression,ConstantConditions
if (mMoveAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mMoveAnimations list");
}
dispatchFinishedWhenDone();
}
Aggregations