Java Code Examples for android.view.animation.AnimationUtils.currentAnimationTimeMillis()

The following are Jave code examples for showing how to use currentAnimationTimeMillis() of the android.view.animation.AnimationUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: LaunchEnr   File: LauncherEdgeEffect.java   Source Code and License Vote up 6 votes
/**
 * Call when the effect absorbs an impact at the given velocity.
 * Used when a fling reaches the scroll boundary.
 *
 * <p>When using a {@link android.widget.Scroller} or {@link android.widget.OverScroller},
 * the method <code>getCurrVelocity</code> will provide a reasonable approximation
 * to use here.</p>
 *
 * @param velocity Velocity at impact in pixels per second.
 */
public void onAbsorb(int velocity) {
    mState = STATE_ABSORB;
    velocity = Math.min(Math.max(MIN_VELOCITY, Math.abs(velocity)), MAX_VELOCITY);

    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mDuration = 0.15f + (velocity * 0.02f);

    // The glow depends more on the velocity, and therefore starts out
    // nearly invisible.
    mGlowAlphaStart = 0.3f;
    mGlowScaleYStart = Math.max(mGlowScaleY, 0.f);


    // Growth for the size of the glow should be quadratic to properly
    // respond
    // to a user's scrolling speed. The faster the scrolling speed, the more
    // intense the effect should be for both the size and the saturation.
    mGlowScaleYFinish = Math.min(0.025f + (velocity * (velocity / 100) * 0.00015f) / 2, 1.f);
    // Alpha should change for the glow as well as size.
    mGlowAlphaFinish = Math.max(
            mGlowAlphaStart, Math.min(velocity * VELOCITY_GLOW_FACTOR * .00001f, MAX_ALPHA));
    mTargetDisplacement = 0.5f;
}
 
Example 2
Project: revolution-irc   File: LongPressSelectTouchListener.java   Source Code and License Vote up 6 votes
@Override
public void run() {
    if (mScrollDir == 0)
        return;

    long now = AnimationUtils.currentAnimationTimeMillis();
    float delta = (now - mPrevTime) * 0.001f;
    mPrevTime = now;

    mRecyclerView.scrollBy(0, (int) (delta * mAutoscrollAmount * mScrollDir));
    LinearLayoutManager llm = (LinearLayoutManager) mRecyclerView.getLayoutManager();
    updateHightlightedElements(mRecyclerView, mScrollDir > 0
            ? llm.findLastCompletelyVisibleItemPosition()
            : llm.findFirstCompletelyVisibleItemPosition());
    ViewCompat.postOnAnimation(mRecyclerView, this);
}
 
Example 3
Project: JazzyViewPager   File: OutlineContainer.java   Source Code and License Vote up 5 votes
@Override
public void start() {
	if (mIsRunning)
		return;
	mIsRunning = true;
	mStartTime = AnimationUtils.currentAnimationTimeMillis();	
	post(mUpdater);
}
 
Example 4
Project: revolution-irc   File: LongPressSelectTouchListener.java   Source Code and License Vote up 5 votes
public void setScrollDir(int dir) {
    if (mScrollDir == dir)
        return;
    if (dir != 0 && mScrollDir == 0)
        ViewCompat.postOnAnimation(mRecyclerView, this);
    mScrollDir = dir;
    mPrevTime = AnimationUtils.currentAnimationTimeMillis();
}
 
Example 5
Project: android-project-gallery   File: ValueAnimator.java   Source Code and License Vote up 5 votes
/**
 * 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.
 */
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);
    }
}
 
Example 6
Project: Rey-MusicPlayer   File: VelocityScroller.java   Source Code and License Vote up 5 votes
void fling(int start, int velocity, int min, int max, int over) {
    mOver = over;
    mFinished = false;
    mCurrVelocity = mVelocity = velocity;
    mDuration = mSplineDuration = 0;
    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mCurrentPosition = mStart = start;

    if (start > max || start < min) {
        startAfterEdge(start, min, max, velocity);
        return;
    }

    mState = SPLINE;
    double totalDistance = 0.0;

    if (velocity != 0) {
        mDuration = mSplineDuration = getSplineFlingDuration(velocity);
        totalDistance = getSplineFlingDistance(velocity);
    }

    mSplineDistance = (int) (totalDistance * Math.signum(velocity));
    mFinal = start + mSplineDistance;

    // Clamp to a valid final position
    if (mFinal < min) {
        adjustDuration(mStart, mFinal, min);
        mFinal = min;
    }

    if (mFinal > max) {
        adjustDuration(mStart, mFinal, max);
        mFinal = max;
    }
}
 
Example 7
Project: exciting-app   File: OverScroller.java   Source Code and License Vote up 5 votes
void startScroll(int start, int distance, int duration) {
    mFinished = false;

    mStart = start;
    mFinal = start + distance;

    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mDuration = duration;

    // Unused
    mDeceleration = 0.0f;
    mVelocity = 0;
}
 
Example 8
Project: airgram   File: Scroller.java   Source Code and License Vote up 5 votes
/**
 * Start scrolling by providing a starting point and the distance to travel.
 * 
 * @param startX Starting horizontal scroll offset in pixels. Positive
 *        numbers will scroll the content to the left.
 * @param startY Starting vertical scroll offset in pixels. Positive numbers
 *        will scroll the content up.
 * @param dx Horizontal distance to travel. Positive numbers will scroll the
 *        content to the left.
 * @param dy Vertical distance to travel. Positive numbers will scroll the
 *        content up.
 * @param duration Duration of the scroll in milliseconds.
 */
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
    mMode = SCROLL_MODE;
    mFinished = false;
    mDuration = duration;
    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mStartX = startX;
    mStartY = startY;
    mFinalX = startX + dx;
    mFinalY = startY + dy;
    mDeltaX = dx;
    mDeltaY = dy;
    mDurationReciprocal = 1.0f / (float) mDuration;
}
 
Example 9
Project: GitHub   File: PieRadarChartTouchListener.java   Source Code and License Vote up 4 votes
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {

    if (mGestureDetector.onTouchEvent(event))
        return true;

    // if rotation by touch is enabled
    if (mChart.isRotationEnabled()) {

        float x = event.getX();
        float y = event.getY();

        switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:

                startAction(event);

                stopDeceleration();

                resetVelocity();

                if (mChart.isDragDecelerationEnabled())
                    sampleVelocity(x, y);

                setGestureStartAngle(x, y);
                mTouchStartPoint.x = x;
                mTouchStartPoint.y = y;

                break;
            case MotionEvent.ACTION_MOVE:

                if (mChart.isDragDecelerationEnabled())
                    sampleVelocity(x, y);

                if (mTouchMode == NONE
                        && distance(x, mTouchStartPoint.x, y, mTouchStartPoint.y)
                        > Utils.convertDpToPixel(8f)) {
                    mLastGesture = ChartGesture.ROTATE;
                    mTouchMode = ROTATE;
                    mChart.disableScroll();
                } else if (mTouchMode == ROTATE) {
                    updateGestureRotation(x, y);
                    mChart.invalidate();
                }

                endAction(event);

                break;
            case MotionEvent.ACTION_UP:

                if (mChart.isDragDecelerationEnabled()) {

                    stopDeceleration();

                    sampleVelocity(x, y);

                    mDecelerationAngularVelocity = calculateVelocity();

                    if (mDecelerationAngularVelocity != 0.f) {
                        mDecelerationLastTime = AnimationUtils.currentAnimationTimeMillis();

                        Utils.postInvalidateOnAnimation(mChart); // This causes computeScroll to fire, recommended for this by Google
                    }
                }

                mChart.enableScroll();
                mTouchMode = NONE;

                endAction(event);

                break;
        }
    }

    return true;
}
 
Example 10
Project: ultrasonic   File: Scroller.java   Source Code and License Vote up 4 votes
/**
 * Call this when you want to know the new location.  If it returns true,
 * the animation is not yet finished.  loc will be altered to provide the
 * new location.
 */
public boolean computeScrollOffset() {
    if (mFinished) {
        return false;
    }

    int timePassed = (int) (AnimationUtils.currentAnimationTimeMillis() - mStartTime);

    if (timePassed < mDuration) {
        switch (mMode) {
        case SCROLL_MODE:
            float x = timePassed * mDurationReciprocal;

            if (mInterpolator == null)
                x = viscousFluid(x);
            else
                x = mInterpolator.getInterpolation(x);

            mCurrX = mStartX + Math.round(x * mDeltaX);
            mCurrY = mStartY + Math.round(x * mDeltaY);
            break;
        case FLING_MODE:
            final float t = (float) timePassed / mDuration;
            final int index = (int) (NB_SAMPLES * t);
            final float tInf = (float) index / NB_SAMPLES;
            final float tSup = (float) (index + 1) / NB_SAMPLES;
            final float dInf = SPLINE[index];
            final float dSup = SPLINE[index + 1];
            final float distanceCoef = dInf + (t - tInf) / (tSup - tInf) * (dSup - dInf);

            mCurrX = mStartX + Math.round(distanceCoef * (mFinalX - mStartX));
            // Pin to mMinX <= mCurrX <= mMaxX
            mCurrX = Math.min(mCurrX, mMaxX);
            mCurrX = Math.max(mCurrX, mMinX);

            mCurrY = mStartY + Math.round(distanceCoef * (mFinalY - mStartY));
            // Pin to mMinY <= mCurrY <= mMaxY
            mCurrY = Math.min(mCurrY, mMaxY);
            mCurrY = Math.max(mCurrY, mMinY);

            if (mCurrX == mFinalX && mCurrY == mFinalY) {
                mFinished = true;
            }

            break;
        }
    } else {
        mCurrX = mFinalX;
        mCurrY = mFinalY;
        mFinished = true;
    }
    return true;
}
 
Example 11
Project: SmartRefreshLayout   File: SmartRefreshLayout.java   Source Code and License Vote up 4 votes
@Override
public void computeScroll() {
    int lastCurY = mScroller.getCurrY();
    if (mScroller.computeScrollOffset()) {
        int finay = mScroller.getFinalY();
        if ((finay > 0 && mRefreshContent.canLoadmore())
                || (finay < 0 && mRefreshContent.canRefresh())) {
            if(mVerticalPermit) {
                int velocity;
                if (Build.VERSION.SDK_INT >= 14) {
                    velocity = (int) mScroller.getCurrVelocity();
                } else {
                    velocity = (finay - mScroller.getCurrY()) / (mScroller.getDuration() - mScroller.timePassed());
                }
                long lastTime = AnimationUtils.currentAnimationTimeMillis() - 1000 * Math.abs(mScroller.getCurrY() - lastCurY) / velocity;
                if (finay > 0) {// 手势向上划 Footer
                    if (isEnableLoadmore() || mEnableOverScrollDrag) {
                        if (mEnableAutoLoadmore && isEnableLoadmore() && !mLoadmoreFinished) {
                            animSpinnerBounce(-(int) (mFooterHeight * Math.pow(1.0 * velocity / mMaximumVelocity, 0.5)));
                            if (!mState.opening && mState != RefreshState.Loading && mState != RefreshState.LoadFinish) {
                                setStateDirectLoading();
                            }
                        } else if (mEnableOverScrollBounce) {
                            animSpinnerBounce(-(int) (mFooterHeight * Math.pow(1.0 * velocity / mMaximumVelocity, 0.5)));
                        }
                    }
                } else {// 手势向下划 Header
                    if (isEnableRefresh() || mEnableOverScrollDrag) {
                        if (mEnableOverScrollBounce) {
                            animSpinnerBounce((int) (mHeaderHeight * Math.pow(1.0 * velocity / mMaximumVelocity, 0.5)));
                        }
                    }
                }
                mVerticalPermit = false;//关闭竖直通行证
            }
            mScroller.forceFinished(true);
        } else {
            mVerticalPermit = true;//打开竖直通行证
            invalidate();
        }
    }
}
 
Example 12
Project: OverScrollableRecyclerView-Method1   File: AScroller.java   Source Code and License Vote up 4 votes
/**
 * Call this when you want to know the new location. If it returns true, the
 * animation is not yet finished.
 */
public boolean computeScrollOffset() {
    if (isFinished()) {
        return false;
    }

    switch (mMode) {
        case SCROLL_MODE:
            long time = AnimationUtils.currentAnimationTimeMillis();
            // Any scroller can be used for time, since they were started
            // together in scroll mode. We use X here.
            final long elapsedTime = time - mScrollerX.mStartTime;

            final int duration = mScrollerX.mDuration;
            if (elapsedTime < duration) {
                float q = (float) (elapsedTime) / duration;

                if (mInterpolator == null) {
                    q = ScrollerUtil.viscousFluid(q);
                } else {
                    q = mInterpolator.getInterpolation(q);
                }

                mScrollerX.updateScroll(q);
                mScrollerY.updateScroll(q);
            } else {
                abortAnimation();
            }
            break;

        case FLING_MODE:
            if (!mScrollerX.mFinished) {
                if (!mScrollerX.update()) {
                    if (!mScrollerX.continueWhenFinished()) {
                        mScrollerX.finish();
                    }
                }
            }

            if (!mScrollerY.mFinished) {
                if (!mScrollerY.update()) {
                    if (!mScrollerY.continueWhenFinished()) {
                        mScrollerY.finish();
                    }
                }
            }

            break;
    }
    return true;
}
 
Example 13
Project: OverScrollableRecyclerView-Method1   File: AScroller.java   Source Code and License Vote up 4 votes
void extendDuration(int extend) {
    final long time = AnimationUtils.currentAnimationTimeMillis();
    final int elapsedTime = (int) (time - mStartTime);
    mDuration = elapsedTime + extend;
    mFinished = false;
}
 
Example 14
Project: Hotspot-master-devp   File: Scroller.java   Source Code and License Vote up 4 votes
/**
 * Start scrolling based on a fling gesture. The distance travelled will
 * depend on the initial velocity of the fling.
 * 
 * @param startX Starting point of the scroll (X)
 * @param startY Starting point of the scroll (Y)
 * @param velocityX Initial velocity of the fling (X) measured in pixels per
 *        second.
 * @param velocityY Initial velocity of the fling (Y) measured in pixels per
 *        second
 * @param minX Minimum X value. The scroller will not scroll past this
 *        point.
 * @param maxX Maximum X value. The scroller will not scroll past this
 *        point.
 * @param minY Minimum Y value. The scroller will not scroll past this
 *        point.
 * @param maxY Maximum Y value. The scroller will not scroll past this
 *        point.
 */
public void fling(int startX, int startY, int velocityX, int velocityY,
        int minX, int maxX, int minY, int maxY) {
    // Continue a scroll or fling in progress
    if (mFlywheel && !mFinished) {
        float oldVel = getCurrVelocity();

        float dx = (float) (mFinalX - mStartX);
        float dy = (float) (mFinalY - mStartY);
        float hyp = (float)Math.sqrt(dx * dx + dy * dy);

        float ndx = dx / hyp;
        float ndy = dy / hyp;

        float oldVelocityX = ndx * oldVel;
        float oldVelocityY = ndy * oldVel;
        if (Math.signum(velocityX) == Math.signum(oldVelocityX) &&
                Math.signum(velocityY) == Math.signum(oldVelocityY)) {
            velocityX += oldVelocityX;
            velocityY += oldVelocityY;
        }
    }

    mMode = FLING_MODE;
    mFinished = false;

    float velocity = (float)Math.sqrt(velocityX * velocityX + velocityY * velocityY);
 
    mVelocity = velocity;
    final double l = Math.log(START_TENSION * velocity / ALPHA);
    mDuration = (int) (1000.0 * Math.exp(l / (DECELERATION_RATE - 1.0)));
    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mStartX = startX;
    mStartY = startY;

    float coeffX = velocity == 0 ? 1.0f : velocityX / velocity;
    float coeffY = velocity == 0 ? 1.0f : velocityY / velocity;

    int totalDistance =
            (int) (ALPHA * Math.exp(DECELERATION_RATE / (DECELERATION_RATE - 1.0) * l));
    
    mMinX = minX;
    mMaxX = maxX;
    mMinY = minY;
    mMaxY = maxY;

    mFinalX = startX + Math.round(totalDistance * coeffX);
    // Pin to mMinX <= mFinalX <= mMaxX
    mFinalX = Math.min(mFinalX, mMaxX);
    mFinalX = Math.max(mFinalX, mMinX);
    
    mFinalY = startY + Math.round(totalDistance * coeffY);
    // Pin to mMinY <= mFinalY <= mMaxY
    mFinalY = Math.min(mFinalY, mMaxY);
    mFinalY = Math.max(mFinalY, mMinY);
}
 
Example 15
Project: SimpleUILauncher   File: LauncherScroller.java   Source Code and License Vote up 3 votes
/**
 * Start scrolling by providing a starting point, the distance to travel,
 * and the duration of the scroll.
 *
 * @param startX Starting horizontal scroll offset in pixels. Positive
 *        numbers will scroll the content to the left.
 * @param startY Starting vertical scroll offset in pixels. Positive numbers
 *        will scroll the content up.
 * @param dx Horizontal distance to travel. Positive numbers will scroll the
 *        content to the left.
 * @param dy Vertical distance to travel. Positive numbers will scroll the
 *        content up.
 * @param duration Duration of the scroll in milliseconds.
 */
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
    mMode = SCROLL_MODE;
    mFinished = false;
    mDuration = duration;
    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mStartX = startX;
    mStartY = startY;
    mFinalX = startX + dx;
    mFinalY = startY + dy;
    mDeltaX = dx;
    mDeltaY = dy;
    mDurationReciprocal = 1.0f / (float) mDuration;
}
 
Example 16
Project: FlickLauncher   File: LauncherScroller.java   Source Code and License Vote up 3 votes
/**
 * Start scrolling by providing a starting point, the distance to travel,
 * and the duration of the scroll.
 *
 * @param startX Starting horizontal scroll offset in pixels. Positive
 *        numbers will scroll the content to the left.
 * @param startY Starting vertical scroll offset in pixels. Positive numbers
 *        will scroll the content up.
 * @param dx Horizontal distance to travel. Positive numbers will scroll the
 *        content to the left.
 * @param dy Vertical distance to travel. Positive numbers will scroll the
 *        content up.
 * @param duration Duration of the scroll in milliseconds.
 */
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
    mMode = SCROLL_MODE;
    mFinished = false;
    mDuration = duration;
    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mStartX = startX;
    mStartY = startY;
    mFinalX = startX + dx;
    mFinalY = startY + dy;
    mDeltaX = dx;
    mDeltaY = dy;
    mDurationReciprocal = 1.0f / (float) mDuration;
}
 
Example 17
Project: airgram   File: Scroller.java   Source Code and License Vote up 2 votes
/**
 * Returns the time elapsed since the beginning of the scrolling.
 *
 * @return The elapsed time in milliseconds.
 */
public int timePassed() {
    return (int)(AnimationUtils.currentAnimationTimeMillis() - mStartTime);
}
 
Example 18
Project: ultrasonic   File: Scroller.java   Source Code and License Vote up 2 votes
/**
 * Returns the time elapsed since the beginning of the scrolling.
 *
 * @return The elapsed time in milliseconds.
 */
public int timePassed() {
    return (int) (AnimationUtils.currentAnimationTimeMillis() - mStartTime);
}
 
Example 19
Project: ultrasonic   File: FloatScroller.java   Source Code and License Vote up 2 votes
/**
 * Returns the time elapsed since the beginning of the scrolling.
 *
 * @return The elapsed time in milliseconds.
 */
public int timePassed() {
    return (int) (AnimationUtils.currentAnimationTimeMillis() - mStartTime);
}
 
Example 20
Project: exciting-app   File: OverScroller.java   Source Code and License Vote up 2 votes
/**
 * Returns the time elapsed since the beginning of the scrolling.
 *
 * @return The elapsed time in milliseconds.
 *
 * @hide
 */
public int timePassed() {
    final long time = AnimationUtils.currentAnimationTimeMillis();
    final long startTime = Math.min(mScrollerX.mStartTime, mScrollerY.mStartTime);
    return (int) (time - startTime);
}