Example usage for android.animation ValueAnimator INFINITE

List of usage examples for android.animation ValueAnimator INFINITE

Introduction

In this page you can find the example usage for android.animation ValueAnimator INFINITE.

Prototype

int INFINITE

To view the source code for android.animation ValueAnimator INFINITE.

Click Source Link

Document

This value used used with the #setRepeatCount(int) property to repeat the animation indefinitely.

Usage

From source file:com.box.myview.MyTopSnackBar.TSnackbar.java

/**
 * @param drawable/*w w w  .  j a v a2s. c o m*/
 * @param left
 * @param right
 * @return
 */
public TSnackbar addIconProgressLoading(Drawable drawable, boolean left, boolean right) {
    final ObjectAnimator animator = ObjectAnimator.ofInt(drawable, "level", 0, 10000);
    animator.setDuration(1000);
    animator.setInterpolator(new LinearInterpolator());
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setRepeatMode(ValueAnimator.INFINITE);
    mView.setBackgroundColor(mContext.getResources().getColor(Prompt.SUCCESS.getBackgroundColor()));
    if (left) {
        mView.getMessageView().setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
    }
    if (right) {
        mView.getMessageView().setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
    }
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCallback != null) {
                mCallback.onShown(TSnackbar.this);
            }
            SnackbarManager.getInstance().onShown(mManagerCallback);
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    animator.start();
    return this;
}

From source file:com.androidinspain.deskclock.alarms.AlarmActivity.java

@Override
public boolean onTouch(View view, MotionEvent event) {
    if (mAlarmHandled) {
        LOGGER.v("onTouch ignored: %s", event);
        return false;
    }//  www .  j  a  v a  2  s . c o  m

    final int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_DOWN) {
        LOGGER.v("onTouch started: %s", event);

        // Track the pointer that initiated the touch sequence.
        mInitialPointerIndex = event.getPointerId(event.getActionIndex());

        // Stop the pulse, allowing the last pulse to finish.
        mPulseAnimator.setRepeatCount(0);
    } else if (action == MotionEvent.ACTION_CANCEL) {
        LOGGER.v("onTouch canceled: %s", event);

        // Clear the pointer index.
        mInitialPointerIndex = MotionEvent.INVALID_POINTER_ID;

        // Reset everything.
        resetAnimations();
    }

    final int actionIndex = event.getActionIndex();
    if (mInitialPointerIndex == MotionEvent.INVALID_POINTER_ID
            || mInitialPointerIndex != event.getPointerId(actionIndex)) {
        // Ignore any pointers other than the initial one, bail early.
        return true;
    }

    final int[] contentLocation = { 0, 0 };
    mContentView.getLocationOnScreen(contentLocation);

    final float x = event.getRawX() - contentLocation[0];
    final float y = event.getRawY() - contentLocation[1];

    final int alarmLeft = mAlarmButton.getLeft() + mAlarmButton.getPaddingLeft();
    final int alarmRight = mAlarmButton.getRight() - mAlarmButton.getPaddingRight();

    final float snoozeFraction, dismissFraction;
    if (mContentView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        snoozeFraction = getFraction(alarmRight, mSnoozeButton.getLeft(), x);
        dismissFraction = getFraction(alarmLeft, mDismissButton.getRight(), x);
    } else {
        snoozeFraction = getFraction(alarmLeft, mSnoozeButton.getRight(), x);
        dismissFraction = getFraction(alarmRight, mDismissButton.getLeft(), x);
    }
    setAnimatedFractions(snoozeFraction, dismissFraction);

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
        LOGGER.v("onTouch ended: %s", event);

        mInitialPointerIndex = MotionEvent.INVALID_POINTER_ID;
        if (snoozeFraction == 1.0f) {
            snooze();
        } else if (dismissFraction == 1.0f) {
            dismiss();
        } else {
            if (snoozeFraction > 0.0f || dismissFraction > 0.0f) {
                // Animate back to the initial state.
                AnimatorUtils.reverse(mAlarmAnimator, mSnoozeAnimator, mDismissAnimator);
            } else if (mAlarmButton.getTop() <= y && y <= mAlarmButton.getBottom()) {
                // User touched the alarm button, hint the dismiss action.
                hintDismiss();
            }

            // Restart the pulse.
            mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE);
            if (!mPulseAnimator.isStarted()) {
                mPulseAnimator.start();
            }
        }
    }

    return true;
}

From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java

@TargetApi(11)
void startIdleAnimations() {
    if (mAnimationCurrent != null) {
        mAnimationCurrent.removeAllUpdateListeners();
        mAnimationCurrent.cancel();//from w w  w . j a  v a  2  s . com
        mAnimationCurrent = null;
    }
    mAnimationCurrent = ValueAnimator.ofFloat(0, mFocalRadius10Percent, 0);
    mAnimationCurrent.setInterpolator(mAnimationInterpolator);
    mAnimationCurrent.setDuration(1000);
    mAnimationCurrent.setStartDelay(225);
    mAnimationCurrent.setRepeatCount(ValueAnimator.INFINITE);
    mAnimationCurrent.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        boolean direction = true;

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final float newFocalFraction = (Float) animation.getAnimatedValue();
            boolean newDirection = direction;
            if (newFocalFraction < mFocalRippleProgress && direction) {
                newDirection = false;
            } else if (newFocalFraction > mFocalRippleProgress && !direction) {
                newDirection = true;
            }
            if (newDirection != direction && !newDirection) {
                mAnimationFocalRipple.start();
            }
            direction = newDirection;
            mFocalRippleProgress = newFocalFraction;
            mView.mFocalRadius = mBaseFocalRadius + mFocalRippleProgress;
            mView.invalidate();
        }
    });
    mAnimationCurrent.start();
    if (mAnimationFocalRipple != null) {
        mAnimationFocalRipple.removeAllUpdateListeners();
        mAnimationFocalRipple.cancel();
        mAnimationFocalRipple = null;
    }
    final float baseRadius = mBaseFocalRadius + mFocalRadius10Percent;
    mAnimationFocalRipple = ValueAnimator.ofFloat(baseRadius, baseRadius + (mFocalRadius10Percent * 6));
    mAnimationFocalRipple.setInterpolator(mAnimationInterpolator);
    mAnimationFocalRipple.setDuration(500);
    mAnimationFocalRipple.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mView.mFocalRippleSize = (float) animation.getAnimatedValue();
            final float fraction;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
                fraction = animation.getAnimatedFraction();
            } else {
                fraction = (mFocalRadius10Percent * 6)
                        / (mView.mFocalRippleSize - mBaseFocalRadius - mFocalRadius10Percent);
            }
            mView.mFocalRippleAlpha = (int) (mBaseFocalRippleAlpha * (1f - fraction));
        }
    });
}

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

@TargetApi(11)
private void startIdleAnimations() {
    if (mAnimationCurrent != null) {
        mAnimationCurrent.removeAllUpdateListeners();
        mAnimationCurrent.cancel();// w ww .  j  av a 2 s  .com
        mAnimationCurrent = null;
    }
    mAnimationCurrent = ValueAnimator.ofFloat(0, mFocalRadius10Percent, 0);
    mAnimationCurrent.setInterpolator(mAnimationInterpolator);
    mAnimationCurrent.setDuration(1000);
    mAnimationCurrent.setStartDelay(225);
    mAnimationCurrent.setRepeatCount(ValueAnimator.INFINITE);
    mAnimationCurrent.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        boolean direction = true;

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final float newFocalFraction = (Float) animation.getAnimatedValue();
            boolean newDirection = direction;
            if (newFocalFraction < mFocalRippleProgress && direction) {
                newDirection = false;
            } else if (newFocalFraction > mFocalRippleProgress && !direction) {
                newDirection = true;
            }
            if (newDirection != direction && !newDirection) {
                mAnimationFocalRipple.start();
            }
            direction = newDirection;
            mFocalRippleProgress = newFocalFraction;
            mView.mFocalRadius = mBaseFocalRadius + mFocalRippleProgress;
            mView.invalidate();
        }
    });
    mAnimationCurrent.start();
    if (mAnimationFocalRipple != null) {
        mAnimationFocalRipple.removeAllUpdateListeners();
        mAnimationFocalRipple.cancel();
        mAnimationFocalRipple = null;
    }
    final float baseRadius = mBaseFocalRadius + mFocalRadius10Percent;
    mAnimationFocalRipple = ValueAnimator.ofFloat(baseRadius, baseRadius + (mFocalRadius10Percent * 6));
    mAnimationFocalRipple.setInterpolator(mAnimationInterpolator);
    mAnimationFocalRipple.setDuration(500);
    mAnimationFocalRipple.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mView.mFocalRippleSize = (float) animation.getAnimatedValue();
            final float fraction;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
                fraction = animation.getAnimatedFraction();
            } else {
                fraction = (mFocalRadius10Percent * 6)
                        / (mView.mFocalRippleSize - mBaseFocalRadius - mFocalRadius10Percent);
            }
            mView.mFocalRippleAlpha = (int) (mBaseFocalRippleAlpha * (1f - fraction));
        }
    });
}

From source file:com.waz.zclient.ui.audiomessage.AudioMessageRecordingView.java

private void startRecordingIndicator() {
    if (recordingIndicatorDotAnimator == null) {
        recordingIndicatorDotAnimator = ObjectAnimator.ofFloat(recordingIndicatorDotView, View.ALPHA, 0f);
        recordingIndicatorDotAnimator.setRepeatCount(ValueAnimator.INFINITE);
        recordingIndicatorDotAnimator.setRepeatMode(ValueAnimator.REVERSE);
        recordingIndicatorDotAnimator.setDuration(RECORDING_INDICATOR_HIDDEN_INTERVAL);
        recordingIndicatorDotAnimator.setStartDelay(RECORDING_INDICATOR_VISIBLE_INTERVAL);
    }//from  ww w.ja  v a  2  s .  c  om
    recordingIndicatorDotAnimator.start();
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

/**
 * Set animators to initial values and restart pulse on alarm button.
 *//*from  ww  w.j a  v a  2 s  .  co m*/
private void resetAnimations() {
    // Set the animators to their initial values.
    setAnimatedFractions(0.0f /* snoozeFraction */, 0.0f /* dismissFraction */);
    // Restart the pulse.
    mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE);
    if (!mPulseAnimator.isStarted()) {
        mPulseAnimator.start();
    }
}

From source file:com.lovejjfg.demo.TouchCircleView.java

private void setupAnimations() {

    mObjectAnimatorAngle = ObjectAnimator.ofFloat(this, mAngleProperty, mCurrentGlobalAngle, 360f);
    mObjectAnimatorAngle.setInterpolator(ANGLE_INTERPOLATOR);
    mObjectAnimatorAngle.setDuration(ANGLE_ANIMATOR_DURATION);
    mObjectAnimatorAngle.setRepeatMode(ValueAnimator.RESTART);
    mObjectAnimatorAngle.setRepeatCount(ValueAnimator.INFINITE);
    mObjectAnimatorAngle.addListener(new AnimatorListenerAdapter() {
        @Override/*from w  w w .j  a v a 2 s . com*/
        public void onAnimationRepeat(Animator animation) {
            mObjectAnimatorAngle.setFloatValues(360f);
        }
    });

    mObjectAnimatorSweep = ObjectAnimator.ofFloat(this, mSweepProperty, mCurrentSweepAngle,
            360f - MIN_SWEEP_ANGLE * 2);
    mObjectAnimatorSweep.setInterpolator(SWEEP_INTERPOLATOR);
    mObjectAnimatorSweep.setDuration(SWEEP_ANIMATOR_DURATION);
    mObjectAnimatorSweep.setRepeatMode(ValueAnimator.RESTART);
    mObjectAnimatorSweep.setRepeatCount(ValueAnimator.INFINITE);
    mObjectAnimatorSweep.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationRepeat(Animator animation) {
            mObjectAnimatorSweep.setFloatValues(360f - MIN_SWEEP_ANGLE * 2);
            toggleAppearingMode();
        }
    });

    fractionAnimator = ValueAnimator.ofInt(0, ALPHA_FULL);
    fractionAnimator.setInterpolator(ANGLE_INTERPOLATOR);
    fractionAnimator.setDuration(FRACTION_DURATION);
    fractionAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            fraction = animation.getAnimatedFraction();
            mHookPaint.setAlpha((Integer) animation.getAnimatedValue());
            invalidate();
        }
    });
    fractionAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mRunning = false;
            postDelayed(idleAction, 0);
        }
    });
    translateAnimator = ValueAnimator.ofFloat(0, 100);
    translateAnimator.setInterpolator(ANGLE_INTERPOLATOR);
    translateAnimator.setDuration(200);
    translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        private float tranlateFraction;

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Float animatedValue = (Float) animation.getAnimatedValue();
            updateState(STATE_TRANSLATE_PATH, false);
            tranlateFraction = animation.getAnimatedFraction();
            if (!isBack) {
                mixPaint.setColor(ColorUtils.blendARGB(Color.RED, Color.GREEN, tranlateFraction));
                mCurrentRadius = (int) (outCirRadius + tranlateFraction * (secondRadius - outCirRadius));
            } else {
                mixPaint.setColor(ColorUtils.blendARGB(Color.GREEN, Color.RED, tranlateFraction));
                mCurrentRadius = (int) (secondRadius - tranlateFraction * (secondRadius - outCirRadius));
            }
            mCurrentPaint = mixPaint;
            resetPoints(secondRectf.centerX(), animatedValue);
            invalidate();
        }
    });
    translateAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            updateState(isBack ? STATE_DRAW_ARROW : abortReset ? STATE_DRAW_BACK : STATE_DRAW_CIRCLE,
                    abortReset);

            updateRectF();
            invalidate();
        }
    });
}