Example usage for android.view.animation AnimationUtils currentAnimationTimeMillis

List of usage examples for android.view.animation AnimationUtils currentAnimationTimeMillis

Introduction

In this page you can find the example usage for android.view.animation AnimationUtils currentAnimationTimeMillis.

Prototype

public static long currentAnimationTimeMillis() 

Source Link

Document

Returns the current animation time in milliseconds.

Usage

From source file:com.hippo.refreshlayout.SwipeProgressBar.java

private boolean draw(Canvas canvas, boolean first) {
    Rect bounds = mBounds;//from  w  w  w . j av  a 2s  .  co  m
    final int width = bounds.width();
    final int cx = bounds.centerX();
    final int cy = bounds.centerY();
    final int colors = mColors.length;
    boolean drawTriggerWhileFinishing = false;
    boolean drawAgain = false;
    int restoreCount = canvas.save();
    canvas.clipRect(bounds);

    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % mAnimationDuration;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS_PER_COLOR;
        float rawProgress = (elapsed / (mAnimationDuration / (float) colors));

        // If we're not running anymore, that means we're running through
        // the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and
            // don't repost.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return false;
            }

            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            if (SUPPORT_CLIP_RECT_DIFFERENCE) {
                mClipRect.set(cx - clearRadius, bounds.top, cx + clearRadius, bounds.bottom);
                canvas.clipRect(mClipRect, Region.Op.DIFFERENCE);
            } else {
                if (first) {
                    // First time left
                    drawAgain = true;
                    mClipRect.set(bounds.left, bounds.top, cx - clearRadius, bounds.bottom);
                } else {
                    // Second time right
                    mClipRect.set(cx + clearRadius, bounds.top, bounds.right, bounds.bottom);
                }
                canvas.clipRect(mClipRect);
            }
            // Only draw the trigger if there is a space in the center of
            // this refreshing view that needs to be filled in by the
            // trigger. If the progress view is just still animating, let it
            // continue animating.
            drawTriggerWhileFinishing = true;
        }

        // First fill in with the last color that would have finished drawing.
        if (iterations == 0) {
            canvas.drawColor(mColors[0]);
        } else {
            int index = colors - 1;
            float left = 0.0f;
            float right = 1.0f;
            for (int i = 0; i < colors; ++i) {
                if ((rawProgress >= left && rawProgress < right) || i == colors - 1) {
                    canvas.drawColor(mColors[index]);
                    break;
                }
                index = (index + 1) % colors;
                left += 1.0f;
                right += 1.0f;
            }
        }

        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if (colors > 1) {
            if ((rawProgress >= 0.0f && rawProgress <= 1.0f)) {
                float pct = (rawProgress + 1.0f) / 2;
                drawCircle(canvas, cx, cy, mColors[0], pct);
            }
            float left = 0.0f;
            float right = 2.0f;
            for (int i = 1; i < colors; ++i) {
                if (rawProgress >= left && rawProgress <= right) {
                    float pct = (rawProgress - i + 1.0f) / 2;
                    drawCircle(canvas, cx, cy, mColors[i], pct);
                }
                left += 1.0f;
                right += 1.0f;
            }
            if ((rawProgress >= colors - 1.0f && rawProgress <= colors)) {
                float pct = (rawProgress - colors + 1.0f) / 2;
                drawCircle(canvas, cx, cy, mColors[0], pct);
            }
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,
            // then draw the trigger. Otherwise, the trigger does not appear
            // until after the bar has finished animating and appears to
            // just jump in at a larger width than expected.
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(bounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent, bounds.left, bounds.top, bounds.right, bounds.bottom);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
    return drawAgain;
}

From source file:org.srr.dev.view.refreshlayout.SwipeProgressBar.java

private boolean draw(Canvas canvas, boolean first) {
    Rect bounds = mBounds;/*w ww  . ja  v a2s .  co m*/
    final int width = bounds.width();
    final int cx = bounds.centerX();
    final int cy = bounds.centerY();
    boolean drawTriggerWhileFinishing = false;
    boolean drawAgain = false;
    int restoreCount = canvas.save();
    canvas.clipRect(bounds);

    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
        float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));

        // If we're not running anymore, that means we're running through
        // the finish animation.
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and
            // don't re-post.
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return false;
            }

            // Otherwise, use a 0 opacity alpha layer to clear the animation
            // from the inside out. This layer will prevent the circles from
            // drawing within its bounds.
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            if (SUPPORT_CLIP_RECT_DIFFERENCE) {
                mClipRect.set(cx - clearRadius, bounds.top, cx + clearRadius, bounds.bottom);
                canvas.clipRect(mClipRect, Region.Op.DIFFERENCE);
            } else {
                if (first) {
                    // First time left
                    drawAgain = true;
                    mClipRect.set(bounds.left, bounds.top, cx - clearRadius, bounds.bottom);
                } else {
                    // Second time right
                    mClipRect.set(cx + clearRadius, bounds.top, bounds.right, bounds.bottom);
                }
                canvas.clipRect(mClipRect);
            }
            // Only draw the trigger if there is a space in the center of
            // this refreshing view that needs to be filled in by the
            // trigger. If the progress view is just still animating, let it
            // continue animating.
            drawTriggerWhileFinishing = true;
        }

        // First fill in with the last color that would have finished drawing.
        if (iterations == 0) {
            canvas.drawColor(mColor1);
        } else {
            if (rawProgress >= 0 && rawProgress < 25) {
                canvas.drawColor(mColor4);
            } else if (rawProgress >= 25 && rawProgress < 50) {
                canvas.drawColor(mColor1);
            } else if (rawProgress >= 50 && rawProgress < 75) {
                canvas.drawColor(mColor2);
            } else {
                canvas.drawColor(mColor3);
            }
        }

        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far
        // along we are in the cycle.
        // progress 0-50 draw mColor2
        // progress 25-75 draw mColor3
        // progress 50-100 draw mColor4
        // progress 75 (wrap to 25) draw mColor1
        if ((rawProgress >= 0 && rawProgress <= 25)) {
            float pct = (((rawProgress + 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (rawProgress >= 0 && rawProgress <= 50) {
            float pct = ((rawProgress * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor2, pct);
        }
        if (rawProgress >= 25 && rawProgress <= 75) {
            float pct = (((rawProgress - 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor3, pct);
        }
        if (rawProgress >= 50 && rawProgress <= 100) {
            float pct = (((rawProgress - 50) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor4, pct);
        }
        if ((rawProgress >= 75 && rawProgress <= 100)) {
            float pct = (((rawProgress - 75) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,
            // then draw the trigger. Otherwise, the trigger does not appear
            // until after the bar has finished animating and appears to
            // just jump in at a larger width than expected.
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(bounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.
        ViewCompat.postInvalidateOnAnimation(mParent, bounds.left, bounds.top, bounds.right, bounds.bottom);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
    return drawAgain;
}

From source file:com.swiperefreshlayout.SwipeProgressBar.java

void draw(Canvas canvas) {
    final int width = mBounds.width();
    final int height = mBounds.height();
    final int cx = width / 2;
    //        final int cy = height / 2;  
    final int cy = mBounds.bottom - height / 2;
    boolean drawTriggerWhileFinishing = false;
    int restoreCount = canvas.save();
    canvas.clipRect(mBounds);//ww  w .j  a  va2 s.  c o  m

    if (mRunning || (mFinishTime > 0)) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS;
        long iterations = (now - mStartTime) / ANIMATION_DURATION_MS;
        float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f));

        // If we're not running anymore, that means we're running through  
        // the finish animation.  
        if (!mRunning) {
            // If the finish animation is done, don't draw anything, and  
            // don't repost.  
            if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) {
                mFinishTime = 0;
                return;
            }

            // Otherwise, use a 0 opacity alpha layer to clear the animation  
            // from the inside out. This layer will prevent the circles from  
            // drawing within its bounds.  
            long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS;
            float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f));
            float pct = (finishProgress / 100f);
            // Radius of the circle is half of the screen.  
            float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct);
            mClipRect.set(cx - clearRadius, 0, cx + clearRadius, height);
            canvas.saveLayerAlpha(mClipRect, 0, 0);
            // Only draw the trigger if there is a space in the center of  
            // this refreshing view that needs to be filled in by the  
            // trigger. If the progress view is just still animating, let it  
            // continue animating.  
            drawTriggerWhileFinishing = true;
        }

        // First fill in with the last color that would have finished drawing.  
        if (iterations == 0) {
            canvas.drawColor(mColor1);
        } else {
            if (rawProgress >= 0 && rawProgress < 25) {
                canvas.drawColor(mColor4);
            } else if (rawProgress >= 25 && rawProgress < 50) {
                canvas.drawColor(mColor1);
            } else if (rawProgress >= 50 && rawProgress < 75) {
                canvas.drawColor(mColor2);
            } else {
                canvas.drawColor(mColor3);
            }
        }

        // Then draw up to 4 overlapping concentric circles of varying radii, based on how far  
        // along we are in the cycle.  
        // progress 0-50 draw mColor2  
        // progress 25-75 draw mColor3  
        // progress 50-100 draw mColor4  
        // progress 75 (wrap to 25) draw mColor1  
        if ((rawProgress >= 0 && rawProgress <= 25)) {
            float pct = (((rawProgress + 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (rawProgress >= 0 && rawProgress <= 50) {
            float pct = ((rawProgress * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor2, pct);
        }
        if (rawProgress >= 25 && rawProgress <= 75) {
            float pct = (((rawProgress - 25) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor3, pct);
        }
        if (rawProgress >= 50 && rawProgress <= 100) {
            float pct = (((rawProgress - 50) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor4, pct);
        }
        if ((rawProgress >= 75 && rawProgress <= 100)) {
            float pct = (((rawProgress - 75) * 2) / 100f);
            drawCircle(canvas, cx, cy, mColor1, pct);
        }
        if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) {
            // There is some portion of trigger to draw. Restore the canvas,  
            // then draw the trigger. Otherwise, the trigger does not appear  
            // until after the bar has finished animating and appears to  
            // just jump in at a larger width than expected.  
            canvas.restoreToCount(restoreCount);
            restoreCount = canvas.save();
            canvas.clipRect(mBounds);
            drawTrigger(canvas, cx, cy);
        }
        // Keep running until we finish out the last cycle.  
        ViewCompat.postInvalidateOnAnimation(mParent);
    } else {
        // Otherwise if we're in the middle of a trigger, draw that.  
        if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) {
            drawTrigger(canvas, cx, cy);
        }
    }
    canvas.restoreToCount(restoreCount);
}

From source file:com.zzti.fyg.widgets.SwipeProgressBar.java

private void drawBar(Canvas canvas, int height) {
    mPaint.setAntiAlias(true);/*from   w  ww.  ja  va  2 s .  c o  m*/
    Bitmap bitmap = null;
    if (state == FINISHED) {
        bitmap = getFinishedBitmap();
    } else {
        bitmap = getBitmap();
    }

    Matrix matrix = new Matrix();
    matrix.setTranslate(bitmap.getWidth() >> 1, bitmap.getHeight() >> 1);

    if (mRunning) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        matrix.postRotate((now - mStartTime) % 360);
    } else {
        if (type == ROTATE) {
            if (state != FINISHED) {
                matrix.postRotate(height % 360);
            }
        } else {
            if (direction == 0) {
                if (state == RELEASE_TO_REFRESH) {
                    matrix.postRotate(180);
                }

            } else if (direction == 1) {
                if (state == PULL_TO_REFRESH) {
                    matrix.postRotate(180);
                }
            }
        }

    }

    dstbmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    int originalWidth = bitmap.getWidth();
    int originalHeight = bitmap.getHeight();

    int dstWidth = dstbmp.getWidth();
    int dstHeight = dstbmp.getHeight();

    int fontHeight = (int) DisplayUtil.getFontHeight(textSize);
    mPaint.setTextSize(textSize);
    mPaint.setColor(textColor);
    if (direction == 0) {
        //canvas.drawBitmap(dstbmp, (width >> 1) - ((int)mPaint.measureText(latestRefreshTime) >> 1) - drawable_margin_left - ((dstWidth >> 1) - (originalWidth >> 1)), (mBounds.bottom - (originalHeight >> 1)) + ((originalHeight >> 1) - (dstHeight >> 1)) - (fontHeight << 1) , mPaint);
        canvas.drawBitmap(dstbmp, drawable_margin_left - ((dstWidth >> 1) - (originalWidth >> 1)),
                (mBounds.bottom - (originalHeight >> 1)) + ((originalHeight >> 1) - (dstHeight >> 1))
                        - (fontHeight << 1),
                mPaint);
        mPaint.setFakeBoldText(true);

        canvas.drawText(tips, (width >> 1) - ((int) mPaint.measureText(tips) >> 1),
                (mBounds.bottom - (fontHeight << 1)), mPaint);
        mPaint.setFakeBoldText(false);
        canvas.drawText(latestRefreshTime, (width >> 1) - ((int) mPaint.measureText(latestRefreshTime) >> 1),
                (mBounds.bottom - fontHeight), mPaint);
    } else {
        float y = mBounds.top + ((textMarginTop + (fontHeight << 1)) >> 1) + textMarginTop - (dstHeight >> 1);
        //          canvas.drawBitmap(dstbmp, (width >> 1) - ((int)mPaint.measureText(latestRefreshTime) >> 1) - drawable_margin_left - ((dstWidth >> 1) - (originalWidth >> 1)), y , mPaint);
        canvas.drawBitmap(dstbmp, drawable_margin_left - ((dstWidth >> 1) - (originalWidth >> 1)), y, mPaint);
        mPaint.setFakeBoldText(true);
        canvas.drawText(tips, (width >> 1) - ((int) mPaint.measureText(tips) >> 1),
                (mBounds.top + textMarginTop + fontHeight), mPaint);
        mPaint.setFakeBoldText(false);
        canvas.drawText(latestRefreshTime, (width >> 1) - ((int) mPaint.measureText(latestRefreshTime) >> 1),
                (mBounds.top + (fontHeight << 1) + (textMarginTop << 1)), mPaint);
    }

}

From source file:com.limxing.library.PullToRefresh.SwipeProgressBar.java

private void drawBar(Canvas canvas, int height) {
    mPaint.setAntiAlias(true);/*from w w  w .j a v  a 2 s .c om*/
    Bitmap bitmap = null;
    if (state == FINISHED) {
        bitmap = getFinishedBitmap();
    } else {
        bitmap = getBitmap();
    }

    Matrix matrix = new Matrix();
    matrix.setTranslate(bitmap.getWidth() >> 1, bitmap.getHeight() >> 1);

    if (mRunning) {
        long now = AnimationUtils.currentAnimationTimeMillis();
        matrix.postRotate(((now - mStartTime) % 360) / 2);
    } else {
        if (type == ROTATE) {
            if (state != FINISHED) {
                matrix.postRotate(height % 360);
            }
        } else {
            if (direction == 0) {
                if (state == RELEASE_TO_REFRESH) {
                    matrix.postRotate(180);
                }

            } else if (direction == 1) {
                if (state == PULL_TO_REFRESH) {
                    matrix.postRotate(180);
                }
            }
        }

    }

    dstbmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    int originalWidth = bitmap.getWidth();
    int originalHeight = bitmap.getHeight();

    int dstWidth = dstbmp.getWidth();
    int dstHeight = dstbmp.getHeight();

    int fontHeight = (int) DisplayUtil.getFontHeight(textSize);
    mPaint.setTextSize(textSize);
    mPaint.setColor(textColor);
    if (direction == 0) {
        // canvas.drawBitmap(dstbmp, (width >> 1) -
        // ((int)mPaint.measureText(latestRefreshTime) >> 1) -
        // drawable_margin_left - ((dstWidth >> 1) - (originalWidth >> 1)),
        // (mBounds.bottom - (originalHeight >> 1)) + ((originalHeight >> 1)
        // - (dstHeight >> 1)) - (fontHeight << 1) , mPaint);
        canvas.drawBitmap(dstbmp, drawable_margin_left - ((dstWidth >> 1) - (originalWidth >> 1)),
                (mBounds.bottom - (originalHeight >> 1)) + ((originalHeight >> 1) - (dstHeight >> 1))
                        - (fontHeight << 1),
                mPaint);
        mPaint.setFakeBoldText(true);

        canvas.drawText(tips, (width >> 1) - ((int) mPaint.measureText(tips) >> 1),
                (mBounds.bottom - (fontHeight << 1)), mPaint);
        mPaint.setFakeBoldText(false);
        canvas.drawText(latestRefreshTime, (width >> 1) - ((int) mPaint.measureText(latestRefreshTime) >> 1),
                (mBounds.bottom - fontHeight), mPaint);
    } else {
        float y = mBounds.top + ((textMarginTop + (fontHeight << 1)) >> 1) + textMarginTop - (dstHeight >> 1);
        // canvas.drawBitmap(dstbmp, (width >> 1) -
        // ((int)mPaint.measureText(latestRefreshTime) >> 1) -
        // drawable_margin_left - ((dstWidth >> 1) - (originalWidth >> 1)),
        // y , mPaint);
        canvas.drawBitmap(dstbmp, drawable_margin_left - ((dstWidth >> 1) - (originalWidth >> 1)), y, mPaint);
        mPaint.setFakeBoldText(true);
        canvas.drawText(tips, (width >> 1) - ((int) mPaint.measureText(tips) >> 1),
                (mBounds.top + textMarginTop + fontHeight), mPaint);
        mPaint.setFakeBoldText(false);
        canvas.drawText(latestRefreshTime, (width >> 1) - ((int) mPaint.measureText(latestRefreshTime) >> 1),
                (mBounds.top + (fontHeight << 1) + (textMarginTop << 1)), mPaint);
    }

}

From source file:com.etmay.brescrollpager.ui.MyScroller.java

/**
 * Call this when you want to know the new location.  If it returns true,
 * the animation is not yet finished./*  ww  w  .j a  va  2s . c o  m*/
 */
public boolean computeScrollOffset() {
    if (mFinished) {
        return false;
    }

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

    if (timePassed < mDuration) {
        switch (mMode) {
        case SCROLL_MODE:
            final float x = mInterpolator.getInterpolation(timePassed * mDurationReciprocal);
            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);
            float distanceCoef = 1.f;
            float velocityCoef = 0.f;
            if (index < NB_SAMPLES) {
                final float t_inf = (float) index / NB_SAMPLES;
                final float t_sup = (float) (index + 1) / NB_SAMPLES;
                final float d_inf = SPLINE_POSITION[index];
                final float d_sup = SPLINE_POSITION[index + 1];
                velocityCoef = (d_sup - d_inf) / (t_sup - t_inf);
                distanceCoef = d_inf + (t - t_inf) * velocityCoef;
            }

            mCurrVelocity = velocityCoef * mDistance / mDuration * 1000.0f;

            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;
}

From source file:com.etmay.brescrollpager.ui.MyScroller.java

/**
 * Start scrolling by providing a starting point, the distance to travel,
 * and the duration of the scroll.//from w  ww.ja v a 2s .co  m
 *
 * @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;
}

From source file:com.etmay.brescrollpager.ui.MyScroller.java

/**
 * 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.//from   w  w  w  .j av  a2 s. com
 * @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.hypot(dx, 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.hypot(velocityX, velocityY);

    mVelocity = velocity;
    mDuration = getSplineFlingDuration(velocity);
    mStartTime = AnimationUtils.currentAnimationTimeMillis();
    mStartX = startX;
    mStartY = startY;

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

    double totalDistance = getSplineFlingDistance(velocity);
    mDistance = (int) (totalDistance * Math.signum(velocity));

    mMinX = minX;
    mMaxX = maxX;
    mMinY = minY;
    mMaxY = maxY;

    mFinalX = startX + (int) Math.round(totalDistance * coeffX);
    // Pin to mMinX <= mFinalX <= mMaxX
    mFinalX = Math.min(mFinalX, mMaxX);
    mFinalX = Math.max(mFinalX, mMinX);

    mFinalY = startY + (int) Math.round(totalDistance * coeffY);
    // Pin to mMinY <= mFinalY <= mMaxY
    mFinalY = Math.min(mFinalY, mMaxY);
    mFinalY = Math.max(mFinalY, mMinY);
}

From source file:com.etmay.brescrollpager.ui.MyScroller.java

/**
 * Returns the time elapsed since the beginning of the scrolling.
 *
 * @return The elapsed time in milliseconds.
 *//*w w w . ja va2s.c om*/
public int timePassed() {
    return (int) (AnimationUtils.currentAnimationTimeMillis() - mStartTime);
}

From source file:de.telekom.pde.codelibrary.ui.layout.PDESwipeRefreshLayout.java

/**
 * @brief Start showing the progress animation.
 *///from   w  w w .jav a 2s.c  o m
void start() {
    if (!mRunning) {
        mTriggerPercentage = 0;
        mStartTime = AnimationUtils.currentAnimationTimeMillis();
        mRunning = true;
        drawCirclePath();
        postInvalidate();
    }
}