Java Code Examples for android.animation.ValueAnimator#setFloatValues()

The following examples show how to use android.animation.ValueAnimator#setFloatValues() . 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: MarkerAnimation.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static ValueAnimator animateMarkerToHC(final MapView map, final Marker marker, final GeoPoint finalPosition, final GeoPointInterpolator GeoPointInterpolator) {
    final GeoPoint startPosition = marker.getPosition();

    ValueAnimator valueAnimator = new ValueAnimator();
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float v = animation.getAnimatedFraction();
            GeoPoint newPosition = GeoPointInterpolator.interpolate(v, startPosition, finalPosition);
            marker.setPosition(newPosition);
            map.invalidate();

        }
    });
    valueAnimator.setFloatValues(0, 1); // Ignored.
    valueAnimator.setDuration(3000);
    valueAnimator.start();
    return valueAnimator;
}
 
Example 2
Source File: Floaty.java    From Floaty with Apache License 2.0 6 votes vote down vote up
private void animateStageOut() {
    final ValueAnimator animator = new ValueAnimator();
    animator.setFloatValues(1F, 0F);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.setDuration(ANIMATION_DURATION);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            targetParent.removeView(stage);
        }
    });
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float currentAlpha = (float) valueAnimator.getAnimatedValue();
            stage.setAlpha(currentAlpha);
        }
    });
    animator.start();
}
 
Example 3
Source File: WeatherView.java    From Aurora with Apache License 2.0 6 votes vote down vote up
private void startSunShadow() {
    isDrawSunShadow=true;
    ValueAnimator valueAnimator=animMap.get(ANIM_WEATHER_SHADOW);
    if (valueAnimator==null){
        valueAnimator=ValueAnimator.ofFloat().setDuration(400);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                sunShadowWidth= (float) animation.getAnimatedValue();
            }
        });
        animMap.put(ANIM_WEATHER_SHADOW,valueAnimator);
    }
    valueAnimator.setFloatValues(0,getMeasuredWidth(),getMeasuredWidth()*0.8f);
    startValueAnimator(valueAnimator);
}
 
Example 4
Source File: FloatingActionButtonImpl.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
private ValueAnimator createElevationAnimator(@NonNull ShadowAnimatorImpl impl) {
  final ValueAnimator animator = new ValueAnimator();
  animator.setInterpolator(ELEVATION_ANIM_INTERPOLATOR);
  animator.setDuration(ELEVATION_ANIM_DURATION);
  animator.addListener(impl);
  animator.addUpdateListener(impl);
  animator.setFloatValues(0, 1);
  return animator;
}
 
Example 5
Source File: TalkingIndicatorView.java    From Plumble with GNU General Public License v3.0 5 votes vote down vote up
public TalkingIndicatorView(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray style = context.obtainStyledAttributes(attrs, new int[] {
            R.attr.arcColor,
            R.attr.arcWidth,
            R.attr.arcLength,
            R.attr.cyclePeriod
    });

    mArcOffset = 0;
    mArcLength = style.getDimensionPixelSize(2, 20);
    mArcWidth = style.getDimensionPixelSize(1, 4);

    mArcPaint = new Paint();
    mArcPaint.setAntiAlias(true);
    mArcPaint.setColor(style.getColor(0, 0xFFFF0000));
    mArcPaint.setStrokeWidth(mArcWidth);
    mArcPaint.setStyle(Paint.Style.STROKE);

    ValueAnimator cycleAnimator = new ValueAnimator();
    cycleAnimator.setRepeatCount(ValueAnimator.INFINITE);
    cycleAnimator.setDuration(style.getInteger(3, 1000));
    cycleAnimator.setFloatValues(0, 360);
    cycleAnimator.setInterpolator(new LinearInterpolator());
    cycleAnimator.addUpdateListener(this);
    cycleAnimator.start();

    style.recycle();
}
 
Example 6
Source File: FilmstripView.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
private void runAnimation(final ValueAnimator animator, final float startValue,
                          final float targetValue, final long duration_ms,
                          final TimeInterpolator interpolator)
{
    if (startValue == targetValue)
    {
        return;
    }
    animator.setInterpolator(interpolator);
    animator.setDuration(duration_ms);
    animator.setFloatValues(startValue, targetValue);
    animator.start();
}
 
Example 7
Source File: LoadingView.java    From TigerVideo with Apache License 2.0 5 votes vote down vote up
private void createBallAnimator(Ball ball, int startDelay) {

            ValueAnimator valueAnimator = new ValueAnimator();
            valueAnimator.setFloatValues(mMinRadius, mMaxRadius);
            valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
            valueAnimator.setDuration(mDuration);
            valueAnimator.addUpdateListener(new BallUpdateListener(ball));
            valueAnimator.setRepeatMode(ValueAnimator.REVERSE);
            valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
            valueAnimator.setStartDelay(startDelay);
            mBallAnimators.add(valueAnimator);
            valueAnimator.start();
        }
 
Example 8
Source File: Floaty.java    From Floaty with Apache License 2.0 5 votes vote down vote up
private void animateStageIn() {
    final ValueAnimator animator = new ValueAnimator();
    animator.setFloatValues(0F, 1F);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.setDuration(ANIMATION_DURATION);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float currentAlpha = (float) valueAnimator.getAnimatedValue();
            stage.setAlpha(currentAlpha);
        }
    });
    animator.start();
}
 
Example 9
Source File: PopupCircleView.java    From PopupCircleMenu with MIT License 5 votes vote down vote up
private void init() {
    mLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mDecorView = (ViewGroup) mContext.getWindow().getDecorView();

    mPopup = new PopupLayer(mContext, mRadius);
    mPopup.setVisibility(INVISIBLE);
    mAlphAnimator = new ValueAnimator();
    mAlphAnimator.setFloatValues(0.0f, 1.0f);
    mAlphAnimator.setDuration(mAnimDuration);
    mAlphAnimator.setInterpolator(new LinearOutSlowInInterpolator());
    mAlphAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mPopup.setShadowViewAlpha(Float.valueOf(animation.getAnimatedValue() + ""));
        }
    });

    addOnLayoutChangeListener(new OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            initButtons();
            if (onButtonPreparedListener != null)
                onButtonPreparedListener.onPrepared(mButtons);
        }
    });

}
 
Example 10
Source File: ToolbarProgressBarAnimatingView.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * @param context The Context for this view.
 * @param height The LayoutParams for this view.
 */
public ToolbarProgressBarAnimatingView(Context context, LayoutParams layoutParams) {
    super(context);
    setLayoutParams(layoutParams);
    mIsRtl = LocalizationUtils.isLayoutRtl();
    mDpToPx = getResources().getDisplayMetrics().density;

    mAnimationDrawable = new ColorDrawable(Color.WHITE);

    setImageDrawable(mAnimationDrawable);

    mListener = new ProgressBarUpdateListener();
    mAnimatorSet = new AnimatorSet();

    mSlowAnimation = new ValueAnimator();
    mSlowAnimation.setFloatValues(0.0f, 1.0f);
    mSlowAnimation.addUpdateListener(mListener);

    mFastAnimation = new ValueAnimator();
    mFastAnimation.setFloatValues(0.0f, 1.0f);
    mFastAnimation.addUpdateListener(mListener);

    updateAnimationDuration();

    mAnimatorSet.playSequentially(mSlowAnimation, mFastAnimation);

    AnimatorListener listener = new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator a) {
            // Replay the animation if it has not been canceled.
            if (mIsCanceled) return;
            // Repeats of the animation should have a start delay.
            mAnimatorSet.setStartDelay(ANIMATION_DELAY_MS);
            updateAnimationDuration();
            // Only restart the animation if the last animation is ending.
            if (a == mFastAnimation) mAnimatorSet.start();
        }
    };

    mSlowAnimation.addListener(listener);
    mFastAnimation.addListener(listener);
}
 
Example 11
Source File: ToolbarProgressBarAnimatingView.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * @param context The Context for this view.
 * @param height The LayoutParams for this view.
 */
public ToolbarProgressBarAnimatingView(Context context, LayoutParams layoutParams) {
    super(context);
    setLayoutParams(layoutParams);
    mIsRtl = LocalizationUtils.isLayoutRtl();
    mDpToPx = getResources().getDisplayMetrics().density;

    mAnimationDrawable = new ColorDrawable(Color.WHITE);

    setImageDrawable(mAnimationDrawable);

    mListener = new ProgressBarUpdateListener();
    mAnimatorSet = new AnimatorSet();

    mSlowAnimation = new ValueAnimator();
    mSlowAnimation.setFloatValues(0.0f, 1.0f);
    mSlowAnimation.addUpdateListener(mListener);

    mFastAnimation = new ValueAnimator();
    mFastAnimation.setFloatValues(0.0f, 1.0f);
    mFastAnimation.addUpdateListener(mListener);

    updateAnimationDuration();

    mAnimatorSet.playSequentially(mSlowAnimation, mFastAnimation);

    AnimatorListener listener = new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator a) {
            // Replay the animation if it has not been canceled.
            if (mIsCanceled) return;
            // Repeats of the animation should have a start delay.
            mAnimatorSet.setStartDelay(ANIMATION_DELAY_MS);
            updateAnimationDuration();
            // Only restart the animation if the last animation is ending.
            if (a == mFastAnimation) mAnimatorSet.start();
        }
    };

    mSlowAnimation.addListener(listener);
    mFastAnimation.addListener(listener);
}
 
Example 12
Source File: LauncherAnimUtils.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
public static ValueAnimator ofFloat(View target, float... values) {
    ValueAnimator anim = new ValueAnimator();
    anim.setFloatValues(values);
    cancelOnDestroyActivity(anim);
    return anim;
}
 
Example 13
Source File: LauncherAnimUtils.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
public static ValueAnimator ofFloat(View target, float... values) {
    ValueAnimator anim = new ValueAnimator();
    anim.setFloatValues(values);
    cancelOnDestroyActivity(anim);
    return anim;
}
 
Example 14
Source File: PagedView.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
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;
        }

        @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;
}
 
Example 15
Source File: ToolbarProgressBarAnimatingView.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * @param context The Context for this view.
 * @param height The LayoutParams for this view.
 */
public ToolbarProgressBarAnimatingView(Context context, LayoutParams layoutParams) {
    super(context);
    setLayoutParams(layoutParams);
    mIsRtl = LocalizationUtils.isLayoutRtl();
    mDpToPx = getResources().getDisplayMetrics().density;

    mAnimationDrawable = new ColorDrawable(Color.WHITE);

    setImageDrawable(mAnimationDrawable);

    mListener = new ProgressBarUpdateListener();
    mAnimatorSet = new AnimatorSet();

    mSlowAnimation = new ValueAnimator();
    mSlowAnimation.setFloatValues(0.0f, 1.0f);
    mSlowAnimation.addUpdateListener(mListener);

    mFastAnimation = new ValueAnimator();
    mFastAnimation.setFloatValues(0.0f, 1.0f);
    mFastAnimation.addUpdateListener(mListener);

    updateAnimationDuration();

    mAnimatorSet.playSequentially(mSlowAnimation, mFastAnimation);

    AnimatorListener listener = new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator a) {
            // Replay the animation if it has not been canceled.
            if (mIsCanceled) return;
            // Repeats of the animation should have a start delay.
            mAnimatorSet.setStartDelay(ANIMATION_DELAY_MS);
            updateAnimationDuration();
            // Only restart the animation if the last animation is ending.
            if (a == mFastAnimation) mAnimatorSet.start();
        }
    };

    mSlowAnimation.addListener(listener);
    mFastAnimation.addListener(listener);
}
 
Example 16
Source File: ProgressBar.java    From FlexibleAdapter with Apache License 2.0 4 votes vote down vote up
public ProgressBar(Context c, AttributeSet attrs) {
    super(c, attrs);

    mDensity = c.getResources().getDisplayMetrics().density;

    final TypedArray ta = c.obtainStyledAttributes(attrs, R.styleable.ProgressBar);
    try {
        mBarColor = ta.getColor(
                R.styleable.ProgressBar_barColor,
                c.getResources().getColor(android.R.color.holo_blue_light));
        mSolidBarHeight = ta.getDimensionPixelSize(
                R.styleable.ProgressBar_barHeight,
                Math.round(DEFAULT_BAR_HEIGHT_DP * mDensity));
        mSolidBarDetentWidth = ta.getDimensionPixelSize(
                R.styleable.ProgressBar_detentWidth,
                Math.round(DEFAULT_DETENT_WIDTH_DP * mDensity));
        mUseShadow = ta.getBoolean(
                R.styleable.ProgressBar_useShadow,
                false);
    } finally {
        ta.recycle();
    }

    mAnimator = new ValueAnimator();
    mAnimator.setFloatValues(1.0f, 2.0f);
    mAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mAnimator.setInterpolator(new ExponentialInterpolator());
    mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            invalidate();
        }
    });

    mPaint.setColor(mBarColor);

    if (mUseShadow) {
        mShadow = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
                new int[]{(mBarColor & 0x00ffffff) | 0x22000000, 0});
    }
}
 
Example 17
Source File: LauncherAnimUtils.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
public static ValueAnimator ofFloat(View target, float... values) {
    ValueAnimator anim = new ValueAnimator();
    anim.setFloatValues(values);
    cancelOnDestroyActivity(anim);
    return anim;
}
 
Example 18
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
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;
        }

        @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;
}
 
Example 19
Source File: LauncherAnimUtils.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public static ValueAnimator ofFloat(float... values) {
    ValueAnimator anim = new ValueAnimator();
    anim.setFloatValues(values);
    cancelOnDestroyActivity(anim);
    return anim;
}