use of android.support.v7.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.
the class FlexibleItemAnimator method animateChangeImpl.
private void animateChangeImpl(final ChangeInfo changeInfo) {
final ViewHolder holder = changeInfo.oldHolder;
final View view = holder == null ? null : holder.itemView;
final ViewHolder newHolder = changeInfo.newHolder;
final View newView = newHolder != null ? newHolder.itemView : null;
if (view != null) {
final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(view).setDuration(getChangeDuration());
mChangeAnimations.add(changeInfo.oldHolder);
oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() {
@Override
public void onAnimationStart(View view) {
dispatchChangeStarting(changeInfo.oldHolder, true);
}
@Override
public void onAnimationEnd(View view) {
oldViewAnim.setListener(null);
ViewCompat.setAlpha(view, 1);
ViewCompat.setTranslationX(view, 0);
ViewCompat.setTranslationY(view, 0);
dispatchChangeFinished(changeInfo.oldHolder, true);
mChangeAnimations.remove(changeInfo.oldHolder);
dispatchFinishedWhenDone();
}
}).start();
}
if (newView != null) {
final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newView);
mChangeAnimations.add(changeInfo.newHolder);
newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).alpha(1).setListener(new VpaListenerAdapter() {
@Override
public void onAnimationStart(View view) {
dispatchChangeStarting(changeInfo.newHolder, false);
}
@Override
public void onAnimationEnd(View view) {
newViewAnimation.setListener(null);
ViewCompat.setAlpha(newView, 1);
ViewCompat.setTranslationX(newView, 0);
ViewCompat.setTranslationY(newView, 0);
dispatchChangeFinished(changeInfo.newHolder, false);
mChangeAnimations.remove(changeInfo.newHolder);
dispatchFinishedWhenDone();
}
}).start();
}
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.
the class FlexibleItemAnimator 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)) {
clear(item.itemView);
dispatchRemoveFinished(item);
}
if (mPendingAdditions.remove(item)) {
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)) {
clear(item.itemView);
dispatchAddFinished(item);
if (additions.isEmpty()) {
mAdditionsList.remove(i);
}
}
}
// Animations should be ended by the cancel above.
// Used during DEBUGGING; Commented in final version.
// if (mRemoveAnimations.remove(item)) {
// throw new IllegalStateException(
// "After animation is cancelled, item should not be in mRemoveAnimations list");
// }
// if (mAddAnimations.remove(item)) {
// throw new IllegalStateException(
// "After animation is cancelled, item should not be in mAddAnimations list");
// }
// if (mChangeAnimations.remove(item)) {
// throw new IllegalStateException(
// "After animation is cancelled, item should not be in mChangeAnimations list");
// }
// if (mMoveAnimations.remove(item)) {
// throw new IllegalStateException(
// "After animation is cancelled, item should not be in mMoveAnimations list");
// }
dispatchFinishedWhenDone();
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.
the class FlexibleItemAnimator 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.RecyclerView.ViewHolder in project plaid by nickbutcher.
the class GridItemDividerDecoration method onDrawOver.
@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
if (parent.isAnimating())
return;
final int childCount = parent.getChildCount();
final RecyclerView.LayoutManager lm = parent.getLayoutManager();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);
if (requiresDivider(viewHolder)) {
final int right = lm.getDecoratedRight(child);
final int bottom = lm.getDecoratedBottom(child);
// draw the bottom divider
canvas.drawRect(lm.getDecoratedLeft(child), bottom - dividerSize, right, bottom, paint);
// draw the right edge divider
canvas.drawRect(right - dividerSize, lm.getDecoratedTop(child), right, bottom - dividerSize, paint);
}
}
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project Android by WilliamYi96.
the class FruitAdapter method onCreateViewHolder.
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fruit_item, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
Aggregations