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

The following examples show how to use android.animation.ValueAnimator#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: RefreshAnimeUtil.java    From RefreshLayout with Apache License 2.0 6 votes vote down vote up
public static void startScaleAnime(final View view,
                                   float newScale, Animator.AnimatorListener listener) {
    ValueAnimator anime = ValueAnimator.ofFloat(view.getScaleX(), newScale);
    anime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float s = Float.parseFloat(animation.getAnimatedValue().toString());
            view.setScaleX(s);
            view.setScaleY(s);
        }
    });
    if (listener != null) {
        anime.addListener(listener);
    }
    anime.setDuration(mAnimeDuration);
    anime.start();
}
 
Example 2
Source File: RenderThreadDelegate.java    From renderthread with MIT License 6 votes vote down vote up
@NonNull
protected Animator createSoftwareFloatAnimator(
        @Nullable final View view, @NonNull final SoftwareCanvasProperty<Float> property, float targetValue) {

    ValueAnimator animator = ValueAnimator.ofFloat(property.getValue(), targetValue);
    animator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    property.setValue((float) animation.getAnimatedValue());
                    if (view != null) {
                        view.invalidate();
                    }
                }
            });
    return animator;
}
 
Example 3
Source File: HazeType.java    From FakeWeather with Apache License 2.0 6 votes vote down vote up
@Override
public void endAnimation(DynamicWeatherView dynamicWeatherView, Animator.AnimatorListener listener) {
    super.endAnimation(dynamicWeatherView, listener);

    ValueAnimator animator1 = ValueAnimator.ofFloat(1, 0);
    animator1.setInterpolator(new AccelerateInterpolator());
    animator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            speed = (float) animation.getAnimatedValue() * 32;
            rotate = (float) animation.getAnimatedValue();
        }
    });

    AnimatorSet animSet = new AnimatorSet();
    animSet.play(animator1);
    animSet.setDuration(1000);
    if (listener != null) {
        animSet.addListener(listener);
    }
    animSet.start();
}
 
Example 4
Source File: SlidingSearchViewExampleFragment.java    From floatingsearchview with Apache License 2.0 6 votes vote down vote up
private void fadeDimBackground(int from, int to, Animator.AnimatorListener listener) {
    ValueAnimator anim = ValueAnimator.ofInt(from, to);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {

            int value = (Integer) animation.getAnimatedValue();
            mDimDrawable.setAlpha(value);
        }
    });
    if (listener != null) {
        anim.addListener(listener);
    }
    anim.setDuration(ANIM_DURATION);
    anim.start();
}
 
Example 5
Source File: PhoneWave.java    From mkloader with Apache License 2.0 6 votes vote down vote up
@Override public void setUpAnimation() {
  for (int i = 0; i < numberOfArc; i++) {
    final int index = i;

    ValueAnimator fadeAnimator = ValueAnimator.ofInt(126, 255, 126);
    fadeAnimator.setRepeatCount(ValueAnimator.INFINITE);
    fadeAnimator.setDuration(1000);
    fadeAnimator.setStartDelay(i * 120);
    fadeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
      @Override public void onAnimationUpdate(ValueAnimator animation) {
        arcs[index].setAlpha((int)animation.getAnimatedValue());
        if (invalidateListener != null) {
          invalidateListener.reDraw();
        }
      }
    });

    fadeAnimator.start();
  }
}
 
Example 6
Source File: FishSpinner.java    From mkloader with Apache License 2.0 6 votes vote down vote up
@Override public void setUpAnimation() {
  for (int i = 0; i < numberOfCircle; i++) {
    final int index = i;

    ValueAnimator fadeAnimator = ValueAnimator.ofFloat(0, 360);
    fadeAnimator.setRepeatCount(ValueAnimator.INFINITE);
    fadeAnimator.setDuration(1700);
    fadeAnimator.setStartDelay(index * 100);
    fadeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
      @Override public void onAnimationUpdate(ValueAnimator animation) {
        rotates[index] = (float)animation.getAnimatedValue();
        if (invalidateListener != null) {
          invalidateListener.reDraw();
        }
      }
    });

    fadeAnimator.start();
  }
}
 
Example 7
Source File: DBUpdateActivity.java    From Android with MIT License 6 votes vote down vote up
@Override
public void initView() {
    activity = this;
    toolbarTop.setBlackStyle();
    toolbarTop.setTitle(getString(R.string.Chat_Update_Database));

    ValueAnimator animator = ValueAnimator.ofInt(0, 100);
    animator.setInterpolator(new DecelerateInterpolator());
    animator.setDuration(5000).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int value = (int) animation.getAnimatedValue();
            upgradeview.setProgress(value);
            if (value < 100) {
                txt1.setText(getString(R.string.Chat_Updating_Database) + "...");
            } else if (value == 100) {
                txt1.setText(getString(R.string.Login_Update_successful) + "!");
                handler.sendEmptyMessageDelayed(50, 1000);
            }
        }
    });
}
 
Example 8
Source File: CreateConnectionVu.java    From FlyWoo with Apache License 2.0 6 votes vote down vote up
/**
 * 底部按钮flip
 */
private void hideButtonFlip() {
    //flip动画
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1).setDuration(1000);
    valueAnimator.setInterpolator(new OvershootInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        boolean first = true;

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            mHideButton.setRotationY(value * 180);
            if (value > 0.5 && first) {
                mHideButton.setImageResource(R.drawable.btn_delete_normal);
                first = false;
            }
        }
    });
    valueAnimator.start();
}
 
Example 9
Source File: AnimProcessor.java    From TwinklingRefreshLayout with Apache License 2.0 5 votes vote down vote up
public void animLayoutByTime(int start, int end, AnimatorUpdateListener listener, AnimatorListener animatorListener) {
        ValueAnimator va = ValueAnimator.ofInt(start, end);
        va.setInterpolator(new DecelerateInterpolator());
        va.addUpdateListener(listener);
        va.addListener(animatorListener);
        va.setDuration((int) (Math.abs(start - end) * animFraction));
        va.start();
//        offerToQueue(va);
    }
 
Example 10
Source File: ViewTransformer.java    From hawkular-android-client with Apache License 2.0 5 votes vote down vote up
@UiThread
public void expand() {
    view.setVisibility(View.VISIBLE);

    ValueAnimator animator = ValueAnimator.ofInt(0, Views.measureHeight(view));
    animator.setInterpolator(new LinearOutSlowInInterpolator());
    animator.setDuration(Durations.MEDIUM);

    animator.addUpdateListener(this);

    animator.start();
}
 
Example 11
Source File: CreateConnectionVu.java    From FlyWoo with Apache License 2.0 5 votes vote down vote up
/**
 * 两侧出现小人动画
 */
private void showTwoImageAnimation() {
    final int dis = PixelUtil.dp2px(160);
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1).setDuration(200);
    valueAnimator.setInterpolator(new OvershootInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            mLeftImage.setTranslationX(value * dis);
            mRightImage.setTranslationX(-value * dis);
        }
    });
    valueAnimator.start();
}
 
Example 12
Source File: MainActivity.java    From Night-Mode-Button with MIT License 5 votes vote down vote up
public void animateStatusActionBar(int colorFrom,int colorTo){
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    colorAnimation.setDuration(250); // milliseconds
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            getWindow().setStatusBarColor((int) animator.getAnimatedValue());
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable((int) animator.getAnimatedValue()));
        }

    });
    colorAnimation.start();
}
 
Example 13
Source File: AudioWidget.java    From MusicBobber with MIT License 5 votes vote down vote up
@Override
public void onReleased(float x, float y) {
    super.onReleased(x, y);
    playPauseButton.onTouchUp();
    released = true;
    if (removeWidgetShown) {
        ValueAnimator animator = ValueAnimator.ofFloat(visibleRemWidPos.y, hiddenRemWidPos.y);
        animator.setDuration(REMOVE_BTN_ANIM_DURATION);
        animator.addUpdateListener(animatorUpdateListener);
        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                removeWidgetShown = false;
                if (!shown) {
                    try {
                        windowManager.removeView(removeWidgetView);
                    } catch (IllegalArgumentException e) {
                        // view not attached to window
                    }
                }
            }
        });
        animator.start();
    }
    if (isReadyToRemove()) {
        hideInternal(false);
    } else {
        if (onWidgetStateChangedListener != null) {
            WindowManager.LayoutParams params = (WindowManager.LayoutParams) playPauseButton.getLayoutParams();
            onWidgetStateChangedListener.onWidgetPositionChanged((int) (params.x + widgetHeight), (int) (params.y + widgetHeight));
        }
    }
}
 
Example 14
Source File: MainVu.java    From FlyWoo with Apache License 2.0 5 votes vote down vote up
/**
 * 展示底部布局
 */
private void showBottomLayout() {
    if (lastCount == 0 && BaseApplication.sendFileStates.keySet().size() > 0) {
        showAnim = true;
    } else {//如果已经出现了,就不用再展示出现动画了
        showAnim = false;
    }

    if (showAnim) {
        isShowing = true;
        // 防止出现缝隙
        final int height = layout_bottom.getHeight() - 2;
        ValueAnimator va = ValueAnimator.ofFloat(0, 1).setDuration(300);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                layout_bottom.setTranslationY(-height * value);
            }
        });
        va.start();
        hideButtonAnimation();
    }

    lastCount = BaseApplication.sendFileStates.keySet().size();
    tv_select_size.setText("传输(" + lastCount + ")");
    layout_bottom.setVisibility(View.VISIBLE);
}
 
Example 15
Source File: HoldingButton.java    From HoldingButton with Apache License 2.0 5 votes vote down vote up
private ValueAnimator createAmplitudeAnimator(float newValue) {
    ValueAnimator animator = ValueAnimator.ofFloat(mAmplitude, newValue);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mAmplitude = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    int duration = (int) (DEFAULT_ANIMATION_DURATION_AMPLITUDE);
    animator.setDuration(duration);
    return animator;
}
 
Example 16
Source File: LobsterShadeSlider.java    From Lobsterpicker with Apache License 2.0 5 votes vote down vote up
private ValueAnimator getMoveAnimation() {
    ValueAnimator animator = ValueAnimator.ofInt(pointerPosition.x,
            currentAnimationEnd = (segmentLength * shadePosition) + (segmentLength / 2));
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            pointerPosition.x = (Integer) animation.getAnimatedValue();
            invalidate();
        }
    });
    return animator;
}
 
Example 17
Source File: MaterialRefreshLayout.java    From NestRefreshLayout with MIT License 5 votes vote down vote up
private void onDropPhase() {
    mWaveView.animationDropCircle();
    ValueAnimator animator = ValueAnimator.ofFloat(0, 0);
    animator.setDuration(500);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mCircleView.setTranslationY(
                    mWaveView.getCurrentCircleCenterY() + mCircleView.getHeight() / 2.f);
        }
    });
    animator.start();
    setRefreshing(true);
}
 
Example 18
Source File: FABToolbarLayout.java    From FABToolbar with MIT License 4 votes vote down vote up
public void show() {
    //TODO better handling of fast clicks
    if(!isFab) {
        return;
    }
    isFab = false;

    setClipChildren(true);

    int[] fabP = new int[2];
    fab.getLocationOnScreen(fabP);
    fabPos.set(fabP[0], fabP[1]);
    originalFABSize = fab.getWidth();

    List<Animator> animators = new ArrayList<>();


    // TRANSLATION ANIM
    int xDest = toolbarPos.x + (toolbarSize.x - fabSize.x) / 2;


    int[] fabConPos = new int[2];
    fabContainer.getLocationOnScreen(fabConPos);

    int xDelta = xDest - fabPos.x;
    final int yDelta = toolbarPos.y - fabConPos[1];

    ObjectAnimator xAnim = ObjectAnimator.ofFloat(fab, "translationX", fab.getTranslationX(), fab.getTranslationX() + xDelta);
    ObjectAnimator yAnim = ObjectAnimator.ofFloat(fabContainer, "translationY", fabContainer.getTranslationY(), fabContainer.getTranslationY() + yDelta);

    xAnim.setInterpolator(new AccelerateInterpolator());
    yAnim.setInterpolator(new DecelerateInterpolator(3f));

    xAnim.setDuration(SHOW_ANIM_DURATION / 2);
    yAnim.setDuration(SHOW_ANIM_DURATION / 2);

    animators.add(xAnim);
    animators.add(yAnim);


    // DRAWABLE ANIM
    if (fabDrawable != null && fabDrawableAnimationEnabled) {
        fabDrawable.startTransition(SHOW_ANIM_DURATION / 3);
    }
    if(!fabDrawableAnimationEnabled) {
        fab.setImageDrawable(null);
    }


    // SIZE ANIM
    // real size is 55x55 instead of 84x98
    final int startRadius = fabSize.x / 2;
    int finalRadius = (int)(Math.sqrt(Math.pow(toolbarSize.x, 2) + Math.pow(toolbarSize.y, 2))/2);
    int realRadius = (int)(98f * finalRadius / 55f);
    final ValueAnimator sizeAnim = ValueAnimator.ofFloat(startRadius, realRadius);
    sizeAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float valFloat = (Float) valueAnimator.getAnimatedValue();

            fab.setScaleX(valFloat / startRadius);
            fab.setScaleY(valFloat / startRadius);
        }
    });
    sizeAnim.setDuration(SHOW_ANIM_DURATION / 2);
    sizeAnim.setStartDelay(SHOW_ANIM_DURATION / 4);

    animators.add(sizeAnim);


    // EXPAND AND SHOW MENU ANIM
    ViewGroup toolbarLayoutViewGroup = (ViewGroup) toolbarLayout;
    List<Animator> expandAnim = ExpandAnimationUtils.build(toolbarLayoutViewGroup, pivotX != -1 ? pivotX : toolbarLayout.getWidth() / 2, pivotY != -1 ? pivotY : toolbarLayout.getHeight() / 2, fraction, SHOW_ANIM_DURATION / 3, 2 * SHOW_ANIM_DURATION / 3);

    animators.addAll(expandAnim);


    // PLAY SHOW ANIMATION
    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(animators);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            isToolbar = true;
        }
    });

    animatorSet.start();
}
 
Example 19
Source File: RefreshCircleHeader.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
public void onReleased(RefreshLayout layout, int height, int extendHeight) {
    mHeadHeight = height;
    mBollRadius = height / 6;
    DecelerateInterpolator interpolator = new DecelerateInterpolator();
    final float reboundHeight = Math.min(mWaveHeight * 0.8f, mHeadHeight / 2);
    ValueAnimator waveAnimator = ValueAnimator.ofFloat(
            mWaveHeight, 0,
            -(reboundHeight*1.0f),0,
            -(reboundHeight*0.4f),0
    );
    waveAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        float speed = 0;
        float springBollY;
        float springRatio = 0;
        int springstatus = 0;//0 还没开始弹起 1 向上弹起 2 在弹起的最高点停住
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float curValue = (float) animation.getAnimatedValue();
            if (springstatus == 0 && curValue <= 0) {
                springstatus = 1;
                speed = Math.abs(curValue - mWaveHeight);
            }
            if (springstatus == 1) {
                springRatio = -curValue / reboundHeight;
                if (springRatio >= mSpringRatio) {
                    mSpringRatio = springRatio;
                    mBollY = mHeadHeight + curValue;
                    speed = Math.abs(curValue - mWaveHeight);
                } else {
                    springstatus = 2;
                    mSpringRatio = 0;
                    mShowBoll = true;
                    mShowBollTail = true;
                    springBollY = mBollY;
                }
            }
            if (springstatus == 2) {
                if (mBollY > mHeadHeight / 2) {
                    mBollY = Math.max(mHeadHeight / 2, mBollY - speed);
                    float bolly = animation.getAnimatedFraction() * (mHeadHeight / 2 - springBollY) + springBollY;
                    if (mBollY > bolly) {
                        mBollY = bolly;
                    }
                }
            }
            if (mShowBollTail && curValue < mWaveHeight) {
                mShowOuter = true;
                mShowBollTail = false;
                mOuterIsStart = true;
                mRefreshStart = 90;
                mRefreshStop = 90;
            }
            mWaveHeight = curValue;
            RefreshCircleHeader.this.invalidate();
        }
    });
    waveAnimator.setInterpolator(interpolator);
    waveAnimator.setDuration(1000);
    waveAnimator.start();
}
 
Example 20
Source File: MainActivity.java    From PictureProgressBar with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_start = (Button) findViewById(R.id.btn_start);
        pb_1 = (PictureProgressBar) findViewById(R.id.pb_1);
        pb_1.setDrawableIds(new int[]{R.drawable.i00, R.drawable.i01, R.drawable.i02, R.drawable.i03, R.drawable.i04, R.drawable.i05, R.drawable.i06});
        pb_2 = (PictureProgressBar) findViewById(R.id.pb_2);
        pb_3 = (PictureProgressBar) findViewById(R.id.pb_3);
        pb_4 = (PictureProgressBar) findViewById(R.id.pb_4);
        pb_5 = (PictureProgressBar) findViewById(R.id.pb_5);
//        try {
//            pb_1.setBarBackgroundDrawableId(R.drawable.background_1);
//            pb_1.setBarDrawableId(R.drawable.bar_1);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

        //使用属性动画来实现进度的变化
        final ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 1000);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Log.d("sdsa", "onAnimationUpdate: " + Integer.parseInt(animation.getAnimatedValue().toString()));
                pb_1.setProgress(Integer.parseInt(animation.getAnimatedValue().toString()));
                if (pb_1.getProgress() >= pb_1.getMax()) {
                    //进度满了之后停止动画
                    pb_1.setAnimRun(false);
                }
                pb_2.setProgress(Integer.parseInt(animation.getAnimatedValue().toString()));
                if (pb_2.getProgress() >= pb_2.getMax()) {
                    //进度满了之后改变图片
                    pb_2.setPicture(R.drawable.b666);
                }
                pb_3.setProgress(Integer.parseInt(animation.getAnimatedValue().toString()));
                if (pb_3.getProgress() >= pb_3.getMax()) {
                    pb_3.setAnimRun(false);
                }
                pb_4.setProgress(Integer.parseInt(animation.getAnimatedValue().toString()));
                if (pb_4.getProgress() >= pb_4.getMax()) {
                    pb_4.setAnimRun(false);
                }
                pb_5.setProgress(Integer.parseInt(animation.getAnimatedValue().toString()));
                if (pb_5.getProgress() >= pb_5.getMax()) {
                    pb_5.setAnimRun(false);
                }
            }
        });
        valueAnimator.setDuration(10000);
        btn_start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pb_1.setAnimRun(true);
                pb_2.setPicture(R.drawable.b333);
                pb_3.setAnimRun(true);
                pb_4.setAnimRun(true);
                pb_5.setAnimRun(true);
                valueAnimator.start();
            }
        });
    }