List of usage examples for android.view.animation AnimationUtils currentAnimationTimeMillis
public static long currentAnimationTimeMillis()
From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java
private void driveAnimation() { float elapsed = (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / 1000.0f; if (elapsed >= mDuration) endAnimation();/*www.j av a 2 s . c o m*/ else { updateAnimationAtElapsed(elapsed); post(mAnimationRunnable); } }
From source file:com.dolphinwang.imagecoverflow.CoverFlowView.java
private void startAnimation(double speed) { if (mAnimationRunnable != null) return;/* w ww . j a v a 2 s . c o m*/ double delta = speed * speed / (FRICTION * 2); if (speed < 0) delta = -delta; double nearest = mStartOffset + delta; nearest = Math.floor(nearest + 0.5); mStartSpeed = (float) Math.sqrt(Math.abs(nearest - mStartOffset) * FRICTION * 2); if (nearest < mStartOffset) mStartSpeed = -mStartSpeed; mDuration = Math.abs(mStartSpeed / FRICTION); mStartTime = AnimationUtils.currentAnimationTimeMillis(); mAnimationRunnable = new Runnable() { @Override public void run() { driveAnimation(); } }; post(mAnimationRunnable); }
From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.java
/** * Like {@link View#scrollBy}, but scroll smoothly instead of immediately. * * @param x the number of pixels to scroll by on the X axis * @param y the number of pixels to scroll by on the Y axis * @param velocity the velocity associated with a fling, if applicable. (0 otherwise) *///from w w w . j a v a 2s . co m void smoothScrollTo(int x, int y, int velocity) { if (getChildCount() == 0) { // Nothing to do. setScrollingCacheEnabled(false); return; } int sx = getScrollX(); int sy = getScrollY(); int dx = x - sx; int dy = y - sy; if (dx == 0 && dy == 0) { completeScroll(false); populate(); setScrollState(SCROLL_STATE_IDLE); return; } setScrollingCacheEnabled(true); setScrollState(SCROLL_STATE_SETTLING); final int width = getClientWidth(); final int halfWidth = width / 2; final float distanceRatio = Math.min(1f, 1.0f * Math.abs(dx) / width); final float distance = halfWidth + halfWidth * distanceInfluenceForSnapDuration(distanceRatio); int duration = 0; velocity = Math.abs(velocity); if (velocity > 0) { duration = 4 * Math.round(1000 * Math.abs(distance / velocity)); } else { final float pageWidth = width * mAdapter.getPageWidth(mCurItem); final float pageDelta = (float) Math.abs(dx) / (pageWidth + mPageMargin); duration = (int) ((pageDelta + 1) * 100); } duration = Math.min(duration, MAX_SETTLE_DURATION); mScrollStartTime = AnimationUtils.currentAnimationTimeMillis(); mScrollDuration = duration; mScroller.startScroll(sx, sy, dx, dy, duration); ViewCompat.postInvalidateOnAnimation(this); }
From source file:com.actionbarsherlock.internal.nineoldandroids.animation.ValueAnimator.java
/** * Plays the ValueAnimator in reverse. If the animation is already running, * it will stop itself and play backwards from the point reached when reverse was called. * If the animation is not currently running, then it will start from the end and * play backwards. This behavior is only set for the current animation; future playing * of the animation will use the default behavior of playing forward. *//*from ww w .ja v a 2s . com*/ public void reverse() { mPlayingBackwards = !mPlayingBackwards; if (mPlayingState == RUNNING) { long currentTime = AnimationUtils.currentAnimationTimeMillis(); long currentPlayTime = currentTime - mStartTime; long timeLeft = mDuration - currentPlayTime; mStartTime = currentTime - timeLeft; } else { start(true); } }
From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java
/** * Like {@link View#scrollBy}, but scroll smoothly instead of immediately. * * @param dx the number of pixels to scroll by on the X axis * @param dy the number of pixels to scroll by on the Y axis */// w ww . j a v a 2s.co m public final void smoothScrollBy(int dx, int dy) { if (getChildCount() == 0) { // Nothing to do. return; } long duration = AnimationUtils.currentAnimationTimeMillis() - mLastScroll; if (duration > ANIMATED_SCROLL_GAP) { final int height = getHeight() - getPaddingBottom() - getPaddingTop(); final int bottom = getChildAt(0).getHeight(); final int maxY = Math.max(0, bottom - height); final int scrollY = getScrollY(); dy = Math.max(0, Math.min(scrollY + dy, maxY)) - scrollY; mScroller.startScroll(getScrollX(), scrollY, 0, dy); ViewCompat.postInvalidateOnAnimation(this); } else { if (!mScroller.isFinished()) { mScroller.abortAnimation(); } scrollBy(dx, dy); } mLastScroll = AnimationUtils.currentAnimationTimeMillis(); }
From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java
/** * Like {@link View#scrollBy}, but scroll smoothly instead of immediately. * * @param dx//from w ww . java2 s .c o m * the number of pixels to scroll by on the X axis * @param dy * the number of pixels to scroll by on the Y axis */ public final void smoothScrollBy(int dx, int dy) { if (getChildCount() == 0) { // Nothing to do. return; } long duration = AnimationUtils.currentAnimationTimeMillis() - mLastScroll; if (duration > ANIMATED_SCROLL_GAP) { if (scrollDirection == DIRECTION_VERTICAL) { final int height = getHeight() - getPaddingBottom() - getPaddingTop(); final int bottom = getChildAt(0).getHeight(); final int maxY = Math.max(0, bottom - height); final int scrollY = getScrollY(); dy = Math.max(0, Math.min(scrollY + dy, maxY)) - scrollY; mScroller.startScroll(getScrollX(), scrollY, 0, dy); ViewCompat.postInvalidateOnAnimation(this); } else if (scrollDirection == DIRECTION_HORIZONTAL) { final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int right = getChildAt(0).getHeight(); final int maxX = Math.max(0, right - width); final int scrollX = getScrollX(); dx = Math.max(Math.min(scrollX + dx, maxX), 0) - scrollX; mScroller.startScroll(scrollX, getScrollY(), dx, 0); ViewCompat.postInvalidateOnAnimation(this); } } else { if (!mScroller.isFinished()) { mScroller.abortAnimation(); } scrollBy(dx, dy); } mLastScroll = AnimationUtils.currentAnimationTimeMillis(); }
From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.java
private void recomputeScrollPosition(int width, int oldWidth, int margin, int oldMargin) { if (oldWidth > 0 && !mItems.isEmpty()) { final int widthWithMargin = width - getPaddingLeft() - getPaddingRight() + margin; final int oldWidthWithMargin = oldWidth - getPaddingLeft() - getPaddingRight() + oldMargin; final int xpos = getScrollX(); final float pageOffset = (float) xpos / oldWidthWithMargin; final int newOffsetPixels = (int) (pageOffset * widthWithMargin); scrollTo(newOffsetPixels, getScrollY()); if (!mScroller.isFinished()) { // We now return to your regularly scheduled scroll, already in progress. final int newDuration = Math.max(0, (int) (mScrollDuration - AnimationUtils.currentAnimationTimeMillis() - mScrollStartTime)); ItemInfo targetInfo = infoForPosition(mCurItem); mScrollStartTime = AnimationUtils.currentAnimationTimeMillis(); mScrollDuration = newDuration; mScroller.startScroll(newOffsetPixels, 0, (int) (targetInfo.offset * width), 0, newDuration); }//from w w w.java2 s .c o m } else { final ItemInfo ii = infoForPosition(mCurItem); final float scrollOffset = ii != null ? Math.min(ii.offset, mLastOffset) : 0; final int scrollPos = (int) (scrollOffset * (width - getPaddingLeft() - getPaddingRight())); if (scrollPos != getScrollX()) { completeScroll(false); scrollTo(scrollPos, getScrollY()); } } }
From source file:com.hippo.widget.BothScrollView.java
/** * Like {@link View#scrollBy}, but scroll smoothly instead of immediately. * * @param dx the number of pixels to scroll by on the X axis * @param dy the number of pixels to scroll by on the Y axis *//*from w w w . j a v a 2s .c o m*/ public final void smoothScrollBy(int dx, int dy) { if (getChildCount() == 0) { // Nothing to do. return; } long duration = AnimationUtils.currentAnimationTimeMillis() - mLastScroll; if (duration > ANIMATED_SCROLL_GAP) { final int width = getWidth() - getPaddingRight() - getPaddingLeft(); final int height = getHeight() - getPaddingBottom() - getPaddingTop(); final int right = getChildAt(0).getWidth(); final int bottom = getChildAt(0).getHeight(); final int maxX = Math.max(0, right - width); final int maxY = Math.max(0, bottom - height); final int scrollX = getScrollX(); final int scrollY = getScrollY(); dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX; dy = Math.max(0, Math.min(scrollY + dy, maxY)) - scrollY; mScroller.startScroll(scrollX, scrollY, dx, dy); ViewCompat.postInvalidateOnAnimation(this); } else { if (!mScroller.isFinished()) { mScroller.abortAnimation(); } scrollBy(dx, dy); } mLastScroll = AnimationUtils.currentAnimationTimeMillis(); }
From source file:cc.flydev.launcher.Page.java
public void onFlingToDelete(PointF vel) { final long startTime = AnimationUtils.currentAnimationTimeMillis(); // NOTE: Because it takes time for the first frame of animation to actually be // called and we expect the animation to be a continuation of the fling, we have // to account for the time that has elapsed since the fling finished. And since // we don't have a startDelay, we will always get call to update when we call // start() (which we want to ignore). final TimeInterpolator tInterpolator = new TimeInterpolator() { private int mCount = -1; private long mStartTime; private float mOffset; /* Anonymous inner class ctor */ { mStartTime = startTime;// w w w . j ava 2 s .c o m } @Override public float getInterpolation(float t) { if (mCount < 0) { mCount++; } else if (mCount == 0) { mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION); mCount++; } return Math.min(1f, mOffset + t); } }; final Rect from = new Rect(); final View dragView = mDragView; from.left = (int) dragView.getTranslationX(); from.top = (int) dragView.getTranslationY(); AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION); final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView); // Create and start the animation ValueAnimator mDropAnim = new ValueAnimator(); mDropAnim.setInterpolator(tInterpolator); mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION); mDropAnim.setFloatValues(0f, 1f); mDropAnim.addUpdateListener(updateCb); mDropAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { onAnimationEndRunnable.run(); } }); mDropAnim.start(); mDeferringForDelete = true; }
From source file:saftyos.android.launcher3.Page.java
public void onFlingToDelete(PointF vel) { final long startTime = AnimationUtils.currentAnimationTimeMillis(); // NOTE: Because it takes time for the first frame of animation to actually be // called and we expect the animation to be a continuation of the fling, we have // to account for the time that has elapsed since the fling finished. And since // we don't have a startDelay, we will always get call to update when we call // start() (which we want to ignore). final TimeInterpolator tInterpolator = new TimeInterpolator() { private int mCount = -1; private long mStartTime; private float mOffset; /* Anonymous inner class ctor */ { mStartTime = startTime;//from w ww .j av a 2 s.c om } @Override public float getInterpolation(float t) { if (mCount < 0) { mCount++; } else if (mCount == 0) { mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION); mCount++; } return Math.min(1f, mOffset + t); } }; final Rect from = new Rect(); final View dragView = mDragView; from.left = (int) dragView.getTranslationX(); from.top = (int) dragView.getTranslationY(); AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION); final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView); // Create and start the animation ValueAnimator mDropAnim = new ValueAnimator(); mDropAnim.setInterpolator(tInterpolator); mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION); mDropAnim.setFloatValues(0f, 1f); mDropAnim.addUpdateListener(updateCb); mDropAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { onAnimationEndRunnable.run(); } }); mDropAnim.start(); mDeferringForDelete = true; }