use of com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter in project UltimateAndroid by cymcsg.
the class ContextualUndoListViewTouchListener method handleUpCancelEvent.
@SuppressWarnings("UnusedParameters")
private boolean handleUpCancelEvent(final View view, final MotionEvent motionEvent) {
mDisallowSwipe = false;
if (mVelocityTracker == null) {
return false;
}
float deltaX = motionEvent.getRawX() - mDownX;
mVelocityTracker.addMovement(motionEvent);
mVelocityTracker.computeCurrentVelocity(1000);
float velocityX = Math.abs(mVelocityTracker.getXVelocity());
float velocityY = Math.abs(mVelocityTracker.getYVelocity());
boolean dismiss = false;
boolean dismissRight = false;
final float absDeltaX = Math.abs(deltaX);
if (absDeltaX > mViewWidth / 2) {
dismiss = true;
dismissRight = deltaX > 0;
} else if (mMinFlingVelocity <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX && absDeltaX > mSlop) {
dismiss = true;
dismissRight = mVelocityTracker.getXVelocity() > 0;
}
if (dismiss) {
// dismiss
final long itemId = ((ContextualUndoView) mDownView).getItemId();
// before animation ends
final int downPosition = mDownPosition;
animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0).setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(final Animator animation) {
mCallback.onViewSwiped(itemId, downPosition);
}
});
} else {
// cancel
animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
}
mVelocityTracker.recycle();
mVelocityTracker = null;
mDownX = 0;
mDownView = null;
mDownPosition = AdapterView.INVALID_POSITION;
mSwiping = false;
return false;
}
use of com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter in project UltimateAndroid by cymcsg.
the class PanningViewAttacher method animate.
private void animate(float start, float end, long duration) {
Log.d(TAG, "startPanning : " + start + " to " + end + ", in " + duration + "ms");
mCurrentAnimator = ValueAnimator.ofFloat(start, end);
mCurrentAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = (Float) animation.getAnimatedValue();
mMatrix.reset();
applyScaleOnMatrix();
if (mIsPortrait) {
mMatrix.postTranslate(value, 0);
} else {
mMatrix.postTranslate(0, value);
}
refreshDisplayRect();
mCurrentPlayTime = animation.getCurrentPlayTime();
setCurrentImageMatrix();
}
});
mCurrentAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
Log.d(TAG, "animation has finished, startPanning in the other way");
changeWay();
animate_();
}
@Override
public void onAnimationCancel(Animator animation) {
Log.d(TAG, "panning animation canceled");
}
});
mCurrentAnimator.setDuration(duration);
mCurrentAnimator.setInterpolator(mLinearInterpolator);
mCurrentAnimator.start();
}
use of com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter in project UltimateAndroid by cymcsg.
the class AnimateDismissAdapter method animateDismiss.
/**
* Animate dismissal of the items at given positions.
*/
public void animateDismiss(final Collection<Integer> positions) {
final List<Integer> positionsCopy = new ArrayList<Integer>(positions);
if (getAbsListView() == null) {
throw new IllegalStateException("Call setAbsListView() on this AnimateDismissAdapter before calling setAdapter()!");
}
List<View> views = getVisibleViewsForPositions(positionsCopy);
if (!views.isEmpty()) {
List<Animator> animators = new ArrayList<Animator>();
for (final View view : views) {
animators.add(createAnimatorForView(view));
}
AnimatorSet animatorSet = new AnimatorSet();
Animator[] animatorsArray = new Animator[animators.size()];
for (int i = 0; i < animatorsArray.length; i++) {
animatorsArray[i] = animators.get(i);
}
animatorSet.playTogether(animatorsArray);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(final Animator animator) {
invokeCallback(positionsCopy);
}
});
animatorSet.start();
} else {
invokeCallback(positionsCopy);
}
}
use of com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter in project UltimateAndroid by cymcsg.
the class FilckerAnimationListView method doAnimation.
private void doAnimation() {
setEnabled(false);
animating = true;
final float durationUnit = (float) MAX_ANIM_DURATION / getHeight();
animatePreLayout(durationUnit, new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(final Animator animation) {
adapter.notifyDataSetChanged();
getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
getViewTreeObserver().removeOnPreDrawListener(this);
animatePostLayout(durationUnit);
return true;
}
});
}
});
}
Aggregations