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

The following examples show how to use android.view.animation.AnimationUtils#currentAnimationTimeMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueAnimator.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the position of the animation to the specified fraction. This fraction should
 * be between 0 and the total fraction of the animation, including any repetition. That is,
 * a fraction of 0 will position the animation at the beginning, a value of 1 at the end,
 * and a value of 2 at the end of a reversing animator that repeats once. If
 * the animation has not yet been started, then it will not advance forward after it is
 * set to this fraction; it will simply set the fraction to this value and perform any
 * appropriate actions based on that fraction. If the animation is already running, then
 * setCurrentFraction() will set the current fraction to this value and continue
 * playing from that point. {@link Animator.AnimatorListener} events are not called
 * due to changing the fraction; those events are only processed while the animation
 * is running.
 *
 * @param fraction The fraction to which the animation is advanced or rewound. Values
 * outside the range of 0 to the maximum fraction for the animator will be clamped to
 * the correct range.
 */
public void setCurrentFraction(float fraction) {
    initAnimation();
    fraction = clampFraction(fraction);
    mStartTimeCommitted = true; // do not allow start time to be compensated for jank
    if (isPulsingInternal()) {
        long seekTime = (long) (getScaledDuration() * fraction);
        long currentTime = AnimationUtils.currentAnimationTimeMillis();
        // Only modify the start time when the animation is running. Seek fraction will ensure
        // non-running animations skip to the correct start time.
        mStartTime = currentTime - seekTime;
    } else {
        // If the animation loop hasn't started, or during start delay, the startTime will be
        // adjusted once the delay has passed based on seek fraction.
        mSeekFraction = fraction;
    }
    mOverallFraction = fraction;
    final float currentIterationFraction = getCurrentIterationFraction(fraction, mReversing);
    animateValue(currentIterationFraction);
}
 
Example 2
Source File: EdgeEffect.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Call when the object is released after being pulled.
 * This will begin the "decay" phase of the effect. After calling this method
 * the host view should {@link android.view.View#invalidate()} and thereby
 * draw the results accordingly.
 */
public void onRelease() {
    mPullDistance = 0;

    if (mState != STATE_PULL && mState != STATE_PULL_DECAY) {
        return;
    }

    mState = STATE_RECEDE;
    mGlowAlphaStart = mGlowAlpha;
    mGlowScaleYStart = mGlowScaleY;

    mGlowAlphaFinish = 0.f;
    mGlowScaleYFinish = 0.f;

    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mDuration = RECEDE_TIME;
}
 
Example 3
Source File: ScaleHelper.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
boolean computeScale() {
    if (isFinished()) {
        return false;
    }
    long time = AnimationUtils.currentAnimationTimeMillis();
    final long elapsedTime = time - mStartTime;

    final long duration = mDuration;
    if (elapsedTime < duration) {
        final float q = mInterpolator.getInterpolation(elapsedTime / (float) duration);
        mScale = mStartScale + (mTargetScale - mStartScale) * q;
    } else {
        mScale = mTargetScale;
        abortAnimation();
    }
    if (mFirst) {
        mFirst = false;
    }
    return true;
}
 
Example 4
Source File: SwipeProgressBar.java    From TiCollectionView with MIT License 5 votes vote down vote up
/**
 * Stop showing the progress animation.
 */
void stop() {
    if (mRunning) {
        mTriggerPercentage = 0;
        mFinishTime = AnimationUtils.currentAnimationTimeMillis();
        mRunning = false;
        mParent.postInvalidate();
    }
}
 
Example 5
Source File: LauncherEdgeEffect.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A view should call this when content is pulled away from an edge by the user.
 * This will update the state of the current visual effect and its associated animation.
 * The host view should always {@link android.view.View#invalidate()} after this
 * and draw the results accordingly.
 *
 * @param deltaDistance Change in distance since the last call. Values may be 0 (no change) to
 *                      1.f (full length of the view) or negative values to express change
 *                      back toward the edge reached to initiate the effect.
 * @param displacement The displacement from the starting side of the effect of the point
 *                     initiating the pull. In the case of touch this is the finger position.
 *                     Values may be from 0-1.
 */
public void onPull(float deltaDistance, float displacement) {
    final long now = AnimationUtils.currentAnimationTimeMillis();
    mTargetDisplacement = displacement;
    if (mState == STATE_PULL_DECAY && now - mStartTime < mDuration) {
        return;
    }
    if (mState != STATE_PULL) {
        mGlowScaleY = Math.max(PULL_GLOW_BEGIN, mGlowScaleY);
    }
    mState = STATE_PULL;

    mStartTime = now;
    mDuration = PULL_TIME;

    mPullDistance += deltaDistance;

    final float absdd = Math.abs(deltaDistance);
    mGlowAlpha = mGlowAlphaStart = Math.min(MAX_ALPHA,
            mGlowAlpha + (absdd * PULL_DISTANCE_ALPHA_GLOW_FACTOR));

    if (mPullDistance == 0) {
        mGlowScaleY = mGlowScaleYStart = 0;
    } else {
        final float scale = (float) (Math.max(0, 1 - 1 /
                Math.sqrt(Math.abs(mPullDistance) * mBounds.height()) - 0.3d) / 0.7d);

        mGlowScaleY = mGlowScaleYStart = scale;
    }

    mGlowAlphaFinish = mGlowAlpha;
    mGlowScaleYFinish = mGlowScaleY;
}
 
Example 6
Source File: OutlineContainer.java    From JazzyViewPager with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
	if (mIsRunning)
		return;
	mIsRunning = true;
	mStartTime = AnimationUtils.currentAnimationTimeMillis();	
	post(mUpdater);
}
 
Example 7
Source File: SwipeProgressBar.java    From TiCollectionView with MIT License 5 votes vote down vote up
/**
 * Start showing the progress animation.
 */
void start() {
    if (!mRunning) {
        mTriggerPercentage = 0;
        mStartTime = AnimationUtils.currentAnimationTimeMillis();
        mRunning = true;
        mParent.postInvalidate();
    }
}
 
Example 8
Source File: OutlineContainer.java    From Contacts with MIT License 5 votes vote down vote up
@Override
public void start() {
	if (mIsRunning)
		return;
	mIsRunning = true;
	mStartTime = AnimationUtils.currentAnimationTimeMillis();	
	post(mUpdater);
}
 
Example 9
Source File: Scroller.java    From zen4android with MIT License 5 votes vote down vote up
/**
 * 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 10
Source File: VelocityViewPager.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
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);
        }
    } 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());
        }
    }
}
 
Example 11
Source File: SwipeProgressBar.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
void start() {
    if (!this.mRunning) {
        this.mTriggerPercentage = 0.0F;
        this.mStartTime = AnimationUtils.currentAnimationTimeMillis();
        this.mRunning = true;
        ViewCompat.postInvalidateOnAnimation(this.mParent);
    }

}
 
Example 12
Source File: AutoScrollHelper.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the scroller at the current animation time.
 */
public void start() {
    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mStopTime = -1;
    mDeltaTime = mStartTime;
    mStopValue = 0.5f;
    mDeltaX = 0;
    mDeltaY = 0;
}
 
Example 13
Source File: OutlineContainer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
	if (mIsRunning)
		return;
	mIsRunning = true;
	mStartTime = AnimationUtils.currentAnimationTimeMillis();	
	post(mUpdater);
}
 
Example 14
Source File: TwoDScrollView.java    From AndroidQuick with MIT License 5 votes vote down vote up
/**
 * 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
 */
public final void smoothScrollBy(int dx, int dy) {
    long duration = AnimationUtils.currentAnimationTimeMillis() - mLastScroll;
    if (duration > ANIMATED_SCROLL_GAP) {
        mScroller.startScroll(getScrollX(), getScrollY(), dx, dy);
        awakenScrollBars(mScroller.getDuration());
        invalidate();
    } else {
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }
        scrollBy(dx, dy);
    }
    mLastScroll = AnimationUtils.currentAnimationTimeMillis();
}
 
Example 15
Source File: ValueAnimator.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public void setCurrentPlayTime(long l1)
{
    a();
    long l2 = AnimationUtils.currentAnimationTimeMillis();
    if (i != 1)
    {
        h = l1;
        i = 2;
    }
    g = l2 - l1;
    a(l2);
}
 
Example 16
Source File: BarLineChartTouchListener.java    From JNChartDemo with Apache License 2.0 5 votes vote down vote up
public void computeScroll() {

        if (mDecelerationVelocity.x == 0.f && mDecelerationVelocity.y == 0.f)
            return; // There's no deceleration in progress

        final long currentTime = AnimationUtils.currentAnimationTimeMillis();

        mDecelerationVelocity.x *= mChart.getDragDecelerationFrictionCoef();
        mDecelerationVelocity.y *= mChart.getDragDecelerationFrictionCoef();

        final float timeInterval = (float) (currentTime - mDecelerationLastTime) / 1000.f;

        float distanceX = mDecelerationVelocity.x * timeInterval;
        float distanceY = mDecelerationVelocity.y * timeInterval;

        mDecelerationCurrentPoint.x += distanceX;
        mDecelerationCurrentPoint.y += distanceY;

        MotionEvent event = MotionEvent.obtain(currentTime, currentTime, MotionEvent.ACTION_MOVE, mDecelerationCurrentPoint.x, mDecelerationCurrentPoint.y, 0);
        performDrag(event);
        event.recycle();
        mMatrix = mChart.getViewPortHandler().refresh(mMatrix, mChart, false);

        mDecelerationLastTime = currentTime;

        if (Math.abs(mDecelerationVelocity.x) >= 0.01 || Math.abs(mDecelerationVelocity.y) >= 0.01)
            Utils.postInvalidateOnAnimation(mChart); // This causes computeScroll to fire, recommended for this by Google
        else {
            // Range might have changed, which means that Y-axis labels
            // could have changed in size, affecting Y-axis size.
            // So we need to recalculate offsets.
            mChart.calculateOffsets();
            mChart.postInvalidate();

            stopDeceleration();
        }
    }
 
Example 17
Source File: EdgeEffect.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void update() {
    final long time = AnimationUtils.currentAnimationTimeMillis();
    final float t = Math.min((time - mStartTime) / mDuration, 1.f);

    final float interp = mInterpolator.getInterpolation(t);

    mGlowAlpha = mGlowAlphaStart + (mGlowAlphaFinish - mGlowAlphaStart) * interp;
    mGlowScaleY = mGlowScaleYStart + (mGlowScaleYFinish - mGlowScaleYStart) * interp;
    mDisplacement = (mDisplacement + mTargetDisplacement) / 2;

    if (t >= 1.f - EPSILON) {
        switch (mState) {
            case STATE_ABSORB:
                mState = STATE_RECEDE;
                mStartTime = AnimationUtils.currentAnimationTimeMillis();
                mDuration = RECEDE_TIME;

                mGlowAlphaStart = mGlowAlpha;
                mGlowScaleYStart = mGlowScaleY;

                // After absorb, the glow should fade to nothing.
                mGlowAlphaFinish = 0.f;
                mGlowScaleYFinish = 0.f;
                break;
            case STATE_PULL:
                mState = STATE_PULL_DECAY;
                mStartTime = AnimationUtils.currentAnimationTimeMillis();
                mDuration = PULL_DECAY_TIME;

                mGlowAlphaStart = mGlowAlpha;
                mGlowScaleYStart = mGlowScaleY;

                // After pull, the glow should fade to nothing.
                mGlowAlphaFinish = 0.f;
                mGlowScaleYFinish = 0.f;
                break;
            case STATE_PULL_DECAY:
                mState = STATE_RECEDE;
                break;
            case STATE_RECEDE:
                mState = STATE_IDLE;
                break;
        }
    }
}
 
Example 18
Source File: JelloToggle.java    From JelloToggle with MIT License 4 votes vote down vote up
private void startJello() {
    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    post(mJelloRunnable);
}
 
Example 19
Source File: Scroller.java    From UltimateAndroid with Apache License 2.0 2 votes vote down vote up
/**
 * 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
Source File: LauncherScroller.java    From TurboLauncher with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the time elapsed since the beginning of the scrolling.
 *
 * @return The elapsed time in milliseconds.
 */
public int timePassed() {
    return (int)(AnimationUtils.currentAnimationTimeMillis() - mStartTime);
}