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

The following examples show how to use android.animation.ValueAnimator#setDuration() . 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: HoldingButton.java    From HoldingButton with Apache License 2.0 6 votes vote down vote up
private ValueAnimator createCancelValueAnimator() {
    final int from = mIsCancel ? mDefaultColor : mCancelColor;
    final int to = mIsCancel ? mCancelColor : mDefaultColor;
    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator a) {
            int color = ColorHelper.blend(from, to, (float) a.getAnimatedValue());
            mPaint.setColor(color);
            mSecondPaint.setColor(color);
            mSecondPaint.setAlpha(mSecondAlpha);
            invalidate();
        }
    });
    animator.setDuration(DEFAULT_ANIMATION_DURATION_CANCEL);
    return animator;
}
 
Example 2
Source File: Case1Scene.java    From scene with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
protected Animator onPushAnimator(AnimationInfo from, final AnimationInfo to) {
    final View fromView = from.mSceneView;
    final View toView = to.mSceneView;

    ValueAnimator fromAlphaAnimator = ObjectAnimator.ofFloat(fromView, View.ALPHA, 1.0f, 1.0f);//之前是0.7,但是动画后面会露出NavigationScene的背景色白色很怪异
    fromAlphaAnimator.setInterpolator(new FastOutSlowInInterpolator());
    fromAlphaAnimator.setDuration(120 * 20);

    ValueAnimator toAlphaAnimator = ObjectAnimator.ofFloat(toView, View.ALPHA, 0.0f, 1.0f);
    toAlphaAnimator.setInterpolator(new DecelerateInterpolator(2));
    toAlphaAnimator.setDuration(120 * 20);

    ValueAnimator toTranslateAnimator = ObjectAnimator.ofFloat(toView, View.TRANSLATION_Y, 0.08f * toView.getHeight(), 0);
    toTranslateAnimator.setInterpolator(new DecelerateInterpolator(2.5f));
    toTranslateAnimator.setDuration(200 * 20);
    return TransitionUtils.mergeAnimators(fromAlphaAnimator, toAlphaAnimator, toTranslateAnimator);
}
 
Example 3
Source File: LikeController.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
private void colorAnimateImageView() {
    final int activatedColor = context.getResources().getColor(R.color.like_icon_activated);

    final ValueAnimator colorAnim = !isLiked ? ObjectAnimator.ofFloat(0f, 1f)
            : ObjectAnimator.ofFloat(1f, 0f);
    colorAnim.setDuration(ANIMATION_DURATION);
    colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float mul = (Float) animation.getAnimatedValue();
            int alpha = adjustAlpha(activatedColor, mul);
            likesImageView.setColorFilter(alpha, PorterDuff.Mode.SRC_ATOP);
            if (mul == 0.0) {
                likesImageView.setColorFilter(null);
            }
        }
    });

    colorAnim.start();
}
 
Example 4
Source File: ChatListItemAnimator.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void runPendingAnimations() {
    boolean runTranslationFromBottom = false;
    if (shouldAnimateEnterFromBottom) {
        for (int i = 0; i < mPendingAdditions.size(); i++) {
            if (mPendingAdditions.get(i).getLayoutPosition() == 0) {
                runTranslationFromBottom = true;
            }
        }
    }

    onAnimationStart();

    if (runTranslationFromBottom) {
        runMessageEnterTransition();
    } else {
        runAlphaEnterTransition();
    }

    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1f);
    valueAnimator.addUpdateListener(animation -> {
        activity.onListItemAniamtorTick();
    });
    valueAnimator.setDuration(getRemoveDuration() + getMoveDuration());
    valueAnimator.start();
}
 
Example 5
Source File: ScreenUtils.java    From BookReader with Apache License 2.0 6 votes vote down vote up
/**
 * 调整窗口的透明度  1.0f,0.5f 变暗
 *
 * @param from    from>=0&&from<=1.0f
 * @param to      to>=0&&to<=1.0f
 * @param context 当前的activity
 */
public static void dimBackground(final float from, final float to, Activity context) {
    final Window window = context.getWindow();
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to);
    valueAnimator.setDuration(500);
    valueAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    WindowManager.LayoutParams params = window.getAttributes();
                    params.alpha = (Float) animation.getAnimatedValue();
                    window.setAttributes(params);
                }
            });
    valueAnimator.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: Playlist.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
private void runOpenInfoSectionAnimation(long duration) {
    final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) rlPlayerInfoSection.getLayoutParams();

    if (animationFirstRun) {
        animationFirstRun = false;
    }

    int animateMarginTo = -(lnPlaylist.getHeight() - lnPlayerContorls.getHeight() - rlPlayerUnderbar.getHeight()); //should me minus value
    ValueAnimator animator = ValueAnimator.ofInt(params.topMargin, animateMarginTo);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            params.topMargin = (Integer) valueAnimator.getAnimatedValue();
            rlPlayerInfoSection.requestLayout();
        }
    });
    animator.setDuration(duration);
    animator.start();
}
 
Example 8
Source File: LineScalePulseOutRapidIndicator.java    From LRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public ArrayList<ValueAnimator> onCreateAnimators() {
    ArrayList<ValueAnimator> animators=new ArrayList<>();
    long[] delays=new long[]{400,200,0,200,400};
    for (int i = 0; i < 5; i++) {
        final int index=i;
        ValueAnimator scaleAnim= ValueAnimator.ofFloat(1,0.4f,1);
        scaleAnim.setDuration(1000);
        scaleAnim.setRepeatCount(-1);
        scaleAnim.setStartDelay(delays[i]);
        addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                scaleYFloats[index] = (float) animation.getAnimatedValue();
                postInvalidate();
            }
        });
        animators.add(scaleAnim);
    }
    return animators;
}
 
Example 9
Source File: MaterialWaveView.java    From MousePaint with MIT License 6 votes vote down vote up
@Override
public void onRefreshing(MaterialRefreshLayout br) {
    setHeadHeight((int) (Util.dip2px(getContext(), DefaulHeadHeight)));
    ValueAnimator animator = ValueAnimator.ofInt(getWaveHeight(),0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Log.i("anim", "value--->" + (int) animation.getAnimatedValue());
            setWaveHeight((int) animation.getAnimatedValue());
            invalidate();
        }
    });
    animator.setInterpolator(new BounceInterpolator());
    animator.setDuration(200);
    animator.start();
}
 
Example 10
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 11
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 12
Source File: DragView.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
public void crossFade(int duration) {
    ValueAnimator va = LauncherAnimUtils.ofFloat(this, 0f, 1f);
    va.setDuration(duration);
    va.setInterpolator(new DecelerateInterpolator(1.5f));
    va.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCrossFadeProgress = animation.getAnimatedFraction();
        }
    });
    va.start();
}
 
Example 13
Source File: CircularActivity.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
private void simulateSuccessProgress(final CircularProgressButton button) {
    ValueAnimator widthAnimation = ValueAnimator.ofInt(1, 100);
    widthAnimation.setDuration(1500);
    widthAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    widthAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Integer value = (Integer) animation.getAnimatedValue();
            button.setProgress(value);
        }
    });
    widthAnimation.start();
}
 
Example 14
Source File: InsightsAnimatorSetFactory.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static @Nullable Animator createPercentSecureAnimator(@Nullable UpdateListener updateListener) {
  if (updateListener == null) return null;

  final ValueAnimator percentSecureAnimator = ValueAnimator.ofFloat(1f, PERCENT_SECURE_MAX_SCALE, 1f);

  percentSecureAnimator.setStartDelay(ANIMATION_START_DELAY);
  percentSecureAnimator.setDuration(PERCENT_SECURE_ANIMATION_DURATION);
  percentSecureAnimator.addUpdateListener(animation -> updateListener.onUpdate((float) animation.getAnimatedValue()));

  return percentSecureAnimator;
}
 
Example 15
Source File: DialogSceneAnimatorExecutor.java    From scene with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
protected Animator onPopAnimator(final AnimationInfo fromInfo, final AnimationInfo toInfo) {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(fromInfo.mSceneView.getAlpha(), 0.0f);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            fromInfo.mSceneView.setAlpha((float) animation.getAnimatedValue());
        }
    });
    valueAnimator.setInterpolator(new DecelerateInterpolator());
    valueAnimator.setDuration(ANIMATION_DURATION);
    return valueAnimator;
}
 
Example 16
Source File: Playlist.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
private void runCloseInfoSectionAnimation(long duration) {
    final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) rlPlayerInfoSection.getLayoutParams();
    ValueAnimator animator = ValueAnimator.ofInt(params.topMargin, 0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            params.topMargin = (Integer) valueAnimator.getAnimatedValue();
            rlPlayerInfoSection.requestLayout();
        }
    });
    animator.setDuration(duration);
    animator.start();
}
 
Example 17
Source File: NewHomeActivity.java    From Newslly with MIT License 5 votes vote down vote up
protected void setNightModeOff(){
    isNight=false;
    switch (currentPos){
        case 0:{
            FeedFragment.setNighMode(true);
            break;
        }
        case 1:{
            TopHeadlinesFragment.setNighMode(true);
            break;
        }
        case 2:{
            FeedCustomizationFragment.setNighMode(true);

            break;
        }
    }
    ValueAnimator valueAnimator = ValueAnimator.ofArgb(Color.parseColor("#1e1e1e"),Color.parseColor("#ffffff"));
    valueAnimator.setDuration(400);
    valueAnimator.start();
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            getWindow().setStatusBarColor((int)animation.getAnimatedValue());
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

        int flags = getWindow().getDecorView().getSystemUiVisibility();
        flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        getWindow().getDecorView().setSystemUiVisibility(flags);
        getWindow().setStatusBarColor(Color.WHITE);
    }


}
 
Example 18
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 19
Source File: WaveDrawable.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
private ValueAnimator getDefaultAnimator() {
    ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
    animator.setInterpolator(new DecelerateInterpolator());
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setDuration(5000);
    return animator;
}
 
Example 20
Source File: ColorAnimation.java    From Android-Image-Slider with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public ValueAnimator createAnimator() {
    ValueAnimator animator = new ValueAnimator();
    animator.setDuration(BaseAnimation.DEFAULT_ANIMATION_TIME);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            onAnimateUpdated(animation);
        }
    });

    return animator;
}