Java Code Examples for android.animation.ObjectAnimator#addUpdateListener()

The following examples show how to use android.animation.ObjectAnimator#addUpdateListener() . 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: RadialSelectorView.java    From cathode with Apache License 2.0 6 votes vote down vote up
public ObjectAnimator getDisappearAnimator() {
    if (!mIsInitialized || !mDrawValuesReady) {
        Log.e(TAG, "RadialSelectorView was not ready for animation.");
        return null;
    }

    Keyframe kf0, kf1, kf2;
    float midwayPoint = 0.2f;
    int duration = 500;

    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe(
            "animationRadiusMultiplier", kf0, kf1, kf2);

    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);

    ObjectAnimator disappearAnimator = ObjectAnimator.ofPropertyValuesHolder(
            this, radiusDisappear, fadeOut).setDuration(duration);
    disappearAnimator.addUpdateListener(mInvalidateUpdateListener);

    return disappearAnimator;
}
 
Example 2
Source File: PieRadarChartBase.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * Applys a spin animation to the Chart.
 * 
 * @param durationmillis
 * @param fromangle
 * @param toangle
 */
@SuppressLint("NewApi")
public void spin(int durationmillis, float fromangle, float toangle, Easing.EasingOption easing) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    setRotationAngle(fromangle);

    ObjectAnimator spinAnimator = ObjectAnimator.ofFloat(this, "rotationAngle", fromangle,
            toangle);
    spinAnimator.setDuration(durationmillis);
    spinAnimator.setInterpolator(Easing.getEasingFunctionFromOption(easing));

    spinAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            postInvalidate();
        }
    });
    spinAnimator.start();
}
 
Example 3
Source File: RadialSelectorView.java    From PersianDateRangePicker with Apache License 2.0 6 votes vote down vote up
public ObjectAnimator getDisappearAnimator() {
  if (!mIsInitialized || !mDrawValuesReady) {
    Log.e(TAG, "RadialSelectorView was not ready for animation.");
    return null;
  }

  Keyframe kf0, kf1, kf2;
  float midwayPoint = 0.2f;
  int duration = 500;

  kf0 = Keyframe.ofFloat(0f, 1);
  kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
  kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
  PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe(
    "animationRadiusMultiplier", kf0, kf1, kf2);

  kf0 = Keyframe.ofFloat(0f, 1f);
  kf1 = Keyframe.ofFloat(1f, 0f);
  PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);

  ObjectAnimator disappearAnimator = ObjectAnimator.ofPropertyValuesHolder(
    this, radiusDisappear, fadeOut).setDuration(duration);
  disappearAnimator.addUpdateListener(mInvalidateUpdateListener);

  return disappearAnimator;
}
 
Example 4
Source File: RadialSelectorView.java    From MaterialDateRangePicker with Apache License 2.0 6 votes vote down vote up
public ObjectAnimator getDisappearAnimator() {
    if (!mIsInitialized || !mDrawValuesReady) {
        Log.e(TAG, "RadialSelectorView was not ready for animation.");
        return null;
    }

    Keyframe kf0, kf1, kf2;
    float midwayPoint = 0.2f;
    int duration = 500;

    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe(
            "animationRadiusMultiplier", kf0, kf1, kf2);

    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);

    ObjectAnimator disappearAnimator = ObjectAnimator.ofPropertyValuesHolder(
            this, radiusDisappear, fadeOut).setDuration(duration);
    disappearAnimator.addUpdateListener(mInvalidateUpdateListener);

    return disappearAnimator;
}
 
Example 5
Source File: WhatsappCameraActivity.java    From WhatsAppCamera with MIT License 6 votes vote down vote up
private void scaleDownAnimation() {
    ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(imgCapture, "scaleX", 1f);
    ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(imgCapture, "scaleY", 1f);
    scaleDownX.setDuration(100);
    scaleDownY.setDuration(100);
    AnimatorSet scaleDown = new AnimatorSet();
    scaleDown.play(scaleDownX).with(scaleDownY);

    scaleDownX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {

            View p = (View) imgCapture.getParent();
            p.invalidate();
        }
    });
    scaleDown.start();
}
 
Example 6
Source File: ChartAnimator.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Animates the rendering of the chart on the x-axis with the specified
 * animation time. If animate(...) is called, no further calling of
 * invalidate() is necessary to refresh the chart.
 *
 * @param durationMillis
 * @param easing
 */
public void animateX(int durationMillis, EasingFunction easing) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, "phaseX", 0f, 1f);
    animatorX.setInterpolator(easing);
    animatorX.setDuration(durationMillis);
    animatorX.addUpdateListener(mListener);
    animatorX.start();
}
 
Example 7
Source File: ChartAnimator.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the drawing / rendering of the chart on both x- and y-axis with
 * the specified animation time. If animate(...) is called, no further
 * calling of invalidate() is necessary to refresh the chart.
 *
 * @param durationMillisX
 * @param durationMillisY
 * @param easingX
 * @param easingY
 */
public void animateXY(int durationMillisX, int durationMillisY, EasingFunction easingX,
        EasingFunction easingY) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
    animatorY.setInterpolator(easingY);
    animatorY.setDuration(
            durationMillisY);
    ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, "phaseX", 0f, 1f);
    animatorX.setInterpolator(easingX);
    animatorX.setDuration(
            durationMillisX);

    // make sure only one animator produces update-callbacks (which then
    // call invalidate())
    if (durationMillisX > durationMillisY) {
        animatorX.addUpdateListener(mListener);
    } else {
        animatorY.addUpdateListener(mListener);
    }

    animatorX.start();
    animatorY.start();
}
 
Example 8
Source File: ChartAnimator.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Animates the rendering of the chart on the x-axis with the specified
 * animation time. If animate(...) is called, no further calling of
 * invalidate() is necessary to refresh the chart.
 *
 * @param durationMillis
 * @param easing
 */
public void animateX(int durationMillis, Easing.EasingOption easing) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, "phaseX", 0f, 1f);
    animatorX.setInterpolator(Easing.getEasingFunctionFromOption(easing));
    animatorX.setDuration(durationMillis);
    animatorX.addUpdateListener(mListener);
    animatorX.start();
}
 
Example 9
Source File: ChartAnimator.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the drawing / rendering of the chart on both x- and y-axis with
 * the specified animation time. If animate(...) is called, no further
 * calling of invalidate() is necessary to refresh the chart.
 *
 * @param durationMillisX
 * @param durationMillisY
 * @param easingX
 * @param easingY
 */
public void animateXY(int durationMillisX, int durationMillisY, EasingFunction easingX,
        EasingFunction easingY) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
    animatorY.setInterpolator(easingY);
    animatorY.setDuration(
            durationMillisY);
    ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, "phaseX", 0f, 1f);
    animatorX.setInterpolator(easingX);
    animatorX.setDuration(
            durationMillisX);

    // make sure only one animator produces update-callbacks (which then
    // call invalidate())
    if (durationMillisX > durationMillisY) {
        animatorX.addUpdateListener(mListener);
    } else {
        animatorY.addUpdateListener(mListener);
    }

    animatorX.start();
    animatorY.start();
}
 
Example 10
Source File: ChartAnimator.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the rendering of the chart on the x-axis with the specified
 * animation time. If animate(...) is called, no further calling of
 * invalidate() is necessary to refresh the chart.
 *
 * @param durationMillis
 */
public void animateX(int durationMillis) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, "phaseX", 0f, 1f);
    animatorX.setDuration(durationMillis);
    animatorX.addUpdateListener(mListener);
    animatorX.start();
}
 
Example 11
Source File: ChartAnimator.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the rendering of the chart on the y-axis with the specified
 * animation time. If animate(...) is called, no further calling of
 * invalidate() is necessary to refresh the chart.
 *
 * @param durationMillis
 * @param easing
 */
public void animateY(int durationMillis, Easing.EasingOption easing) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
    animatorY.setInterpolator(Easing.getEasingFunctionFromOption(easing));
    animatorY.setDuration(durationMillis);
    animatorY.addUpdateListener(mListener);
    animatorY.start();
}
 
Example 12
Source File: ChartAnimator.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Animates the rendering of the chart on the y-axis with the specified
 * animation time. If animate(...) is called, no further calling of
 * invalidate() is necessary to refresh the chart.
 *
 * @param durationMillis
 */
public void animateY(int durationMillis) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
    animatorY.setDuration(durationMillis);
    animatorY.addUpdateListener(mListener);
    animatorY.start();
}
 
Example 13
Source File: ChartAnimator.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * Animates values along the X axis.
 *
 * @param durationMillis animation duration
 * @param easing EasingFunction
 */
@RequiresApi(11)
public void animateX(int durationMillis, EasingFunction easing) {

    ObjectAnimator animatorX = xAnimator(durationMillis, easing);
    animatorX.addUpdateListener(mListener);
    animatorX.start();
}
 
Example 14
Source File: ChartAnimator.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the rendering of the chart on the y-axis with the specified
 * animation time. If animate(...) is called, no further calling of
 * invalidate() is necessary to refresh the chart.
 *
 * @param durationMillis
 * @param easing
 */
public void animateY(int durationMillis, EasingFunction easing) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
    animatorY.setInterpolator(easing);
    animatorY.setDuration(durationMillis);
    animatorY.addUpdateListener(mListener);
    animatorY.start();
}
 
Example 15
Source File: ChartAnimator.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Animates the rendering of the chart on the y-axis with the specified
 * animation time. If animate(...) is called, no further calling of
 * invalidate() is necessary to refresh the chart.
 *
 * @param durationMillis
 * @param easing
 */
public void animateY(int durationMillis, EasingFunction easing) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
    animatorY.setInterpolator(easing);
    animatorY.setDuration(durationMillis);
    animatorY.addUpdateListener(mListener);
    animatorY.start();
}
 
Example 16
Source File: RadialSelectorView.java    From StyleableDateTimePicker with MIT License 5 votes vote down vote up
public ObjectAnimator getReappearAnimator() {
    if (!mIsInitialized || !mDrawValuesReady) {
        Log.e(TAG, "RadialSelectorView was not ready for animation.");
        return null;
    }

    Keyframe kf0, kf1, kf2, kf3;
    float midwayPoint = 0.2f;
    int duration = 500;

    // The time points are half of what they would normally be, because this animation is
    // staggered against the disappear so they happen seamlessly. The reappear starts
    // halfway into the disappear.
    float delayMultiplier = 0.25f;
    float transitionDurationMultiplier = 1f;
    float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    int totalDuration = (int) (duration * totalDurationMultiplier);
    float delayPoint = (delayMultiplier * duration) / totalDuration;
    midwayPoint = 1 - (midwayPoint * (1 - delayPoint));

    kf0 = Keyframe.ofFloat(0f, mTransitionEndRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, mTransitionEndRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear = PropertyValuesHolder.ofKeyframe(
            "animationRadiusMultiplier", kf0, kf1, kf2, kf3);

    kf0 = Keyframe.ofFloat(0f, 0f);
    kf1 = Keyframe.ofFloat(delayPoint, 0f);
    kf2 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2);

    ObjectAnimator reappearAnimator = ObjectAnimator.ofPropertyValuesHolder(
            this, radiusReappear, fadeIn).setDuration(totalDuration);
    reappearAnimator.addUpdateListener(mInvalidateUpdateListener);
    return reappearAnimator;
}
 
Example 17
Source File: ChartAnimator.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * Animates the rendering of the chart on the y-axis with the specified
 * animation time. If animate(...) is called, no further calling of
 * invalidate() is necessary to refresh the chart.
 *
 * @param durationMillis
 */
public void animateY(int durationMillis) {

    if (android.os.Build.VERSION.SDK_INT < 11)
        return;

    ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
    animatorY.setDuration(durationMillis);
    animatorY.addUpdateListener(mListener);
    animatorY.start();
}
 
Example 18
Source File: TabSelectAdapter.java    From V2EX with GNU General Public License v3.0 4 votes vote down vote up
private boolean onTouch(View vi, MotionEvent event) {

            if (ANIMATING)  return false;
            switch (event.getAction()){
                case MotionEvent.ACTION_DOWN:
                    mStartX = event.getX();
                    mGlideTimeSpan = System.currentTimeMillis();
                    break;
                case MotionEvent.ACTION_MOVE:
                    mIncrement = Math.abs(event.getX() - mStartX);
                    if (mIncrement > 20 || mCanGlide){
                        mContainer.setX(mContainer.getX() + event.getX() - mStartX);
                        mCanGlide = true;
                    }
                    break;
                case MotionEvent.ACTION_CANCEL:
                    cancelDeleteAnim(mContainer);
                    break;
                case MotionEvent.ACTION_UP:
                default:
                    mGlideTimeSpan = System.currentTimeMillis() - mGlideTimeSpan;
                    float s = (mContainerWidth - Math.abs(mContainer.getX())) / mGlideTimeSpan;
                    if (Math.abs(mContainer.getX()) > 250){
                        int moveToX = mContainerWidth * (mContainer.getX() > 0 ? 1: - 1);
                        long speed = (long) (mContainerWidth / s);
                        ObjectAnimator animator = ObjectAnimator.ofFloat(
                                mContainer, "X", moveToX).setDuration(speed);
                        ViewWrapper viewWrapper = new ViewWrapper(mContainer);
                        ObjectAnimator animator1 = ObjectAnimator.ofInt(
                                viewWrapper, "height", 0).setDuration(500);
                        int p = mViewHolder.getAdapterPosition();
                        animator.addUpdateListener(animation -> {
                            if (Math.abs((float)animation.getAnimatedValue()) == mContainerWidth){
                                mContainer.setVisibility(View.GONE);
                                animator1.start();
                            }
                        });
                        animator1.addUpdateListener( animation -> {
                            if ((int)animation.getAnimatedValue() == 0) {
                                mTabs.remove(p);
                                notifyItemRemoved(p);
                                ANIMATING = false;
                            }
                        });
                        ANIMATING = true;
                        animator.start();
                    } else{
                        cancelDeleteAnim(mContainer);
                    }
            }
            return true;
        }
 
Example 19
Source File: AnimationSVGImageViewSampleActivity.java    From SVG-Android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animation_svg_imageview_sample);
    setTitle(getIntent().getStringExtra("title"));

    final SVGImageView imageView1 = (SVGImageView) findViewById(R.id.animation_svgimageview_image1);
    ObjectAnimator animatorRotation = ObjectAnimator.ofFloat(imageView1, "svgRotation", 0, 360);
    animatorRotation.setDuration(2000);
    animatorRotation.setRepeatCount(ValueAnimator.INFINITE);
    animatorRotation.setInterpolator(new LinearInterpolator());
    animatorRotation.start();

    SVGImageView imageView2 = (SVGImageView) findViewById(R.id.animation_svgimageview_image2);
    ObjectAnimator animatorAlpha = ObjectAnimator.ofFloat(imageView2, "svgAlpha", 0, 1);
    animatorAlpha.setDuration(4000);
    animatorAlpha.setRepeatCount(ValueAnimator.INFINITE);
    animatorAlpha.setRepeatMode(ValueAnimator.REVERSE);
    animatorAlpha.setInterpolator(new LinearInterpolator());
    animatorAlpha.start();

    final SVGImageView imageView3 = (SVGImageView) findViewById(R.id.animation_svgimageview_image3);
    ObjectAnimator animatorWidth = ObjectAnimator.ofInt(imageView3, "svgWidth", 50, 150);
    animatorWidth.setDuration(2000);
    animatorWidth.setInterpolator(new LinearInterpolator());
    animatorWidth.setRepeatCount(ValueAnimator.INFINITE);
    animatorWidth.setRepeatMode(ValueAnimator.REVERSE);
    animatorWidth.start();
    animatorWidth.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // There is a bug in ImageView(ImageButton), in this case, we must call requestLayout() here.
            imageView3.requestLayout();
        }
    });

    SVGImageView imageView4 = (SVGImageView) findViewById(R.id.animation_svgimageview_image4);
    ObjectAnimator animatorColor = ObjectAnimator.ofInt(imageView4, "svgColor", Color.BLACK, Color.BLUE);
    animatorColor.setDuration(2000);
    animatorColor.setRepeatCount(ValueAnimator.INFINITE);
    animatorColor.setRepeatMode(ValueAnimator.REVERSE);
    animatorColor.setInterpolator(new LinearInterpolator());
    animatorColor.start();

}
 
Example 20
Source File: CircleIndicator.java    From ViewPagerHelper with Apache License 2.0 4 votes vote down vote up
/**
 * 用于小圆点的放大缩小
 *
 * @param view
 * @param type
 */
private void doScaleAnim(final ImageView view, final int type) {
    AnimatorSet animatorSet = new AnimatorSet();
    ObjectAnimator scaleX;
    ObjectAnimator scaleY;
    ObjectAnimator colorAnim;
    final GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.OVAL);
    drawable.setSize(mSize, mSize);
    if (type == ANIM_OUT) {
        scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1, mScaleFactor);
        scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1, mScaleFactor);
        animatorSet.setDuration(ANIM_OUT_TIME);
        colorAnim = ObjectAnimator.ofInt(view, "color", mDefaultColor, mSelectedColor);

    } else {
        scaleX = ObjectAnimator.ofFloat(view, "scaleX", mScaleFactor, 1);
        scaleY = ObjectAnimator.ofFloat(view, "scaleY", mScaleFactor, 1);


        colorAnim = ObjectAnimator.ofInt(view, "color", mSelectedColor, mDefaultColor);

        animatorSet.setDuration(ANIM_IN_TIME);

    }
    colorAnim.setEvaluator(new HsvEvaluator());
    animatorSet.play(scaleX).with(scaleY).with(colorAnim);

    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.start();

    colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int color = (int) animation.getAnimatedValue();
            drawable.setColor(color);
            view.setBackground(drawable);
        }
    });


}