List of usage examples for android.animation ValueAnimator setDuration
@Override public ValueAnimator setDuration(long duration)
From source file:org.mythtv.client.ui.BackendStatusFragment.java
private void animateCardLinearLayout(final LinearLayout linearLayout, long startDelay) { linearLayout.setAlpha(1);/* ww w . j a v a2s . com*/ // animator that translates linearlayout AnimatorUpdateListener translationAnimatorListener = new AnimatorUpdateListener() { /* (non-Javadoc) * @see android.animation.ValueAnimator.AnimatorUpdateListener#onAnimationUpdate(android.animation.ValueAnimator) */ @Override public void onAnimationUpdate(ValueAnimator animation) { Float w = (Float) animation.getAnimatedValue(); linearLayout.setTranslationY(w); } }; ValueAnimator scaleAnimator = ValueAnimator.ofFloat(linearLayout.getTranslationY(), 0f); scaleAnimator.setDuration(500); scaleAnimator.setRepeatCount(0); scaleAnimator.setStartDelay(startDelay); scaleAnimator.addUpdateListener(translationAnimatorListener); scaleAnimator.start(); }
From source file:com.musenkishi.wally.activities.ImageDetailsActivity.java
private void setupPaddings(final Size size, boolean animate) { int animationDuration = animate ? 300 : 0; photoView.setScaleType(ImageView.ScaleType.CENTER_CROP); photoViewAttacher.setScaleType(ImageView.ScaleType.CENTER_CROP); final int sidePadding = getResources() .getDimensionPixelSize(R.dimen.activity_details_scrollview_side_padding); int fabPadding = getResources().getDimensionPixelSize(R.dimen.fab_padding_positive); int minimumAllowedHeight = fabPadding; if (size.getHeight() < minimumAllowedHeight) { size.setHeight(size.getHeight()); ValueAnimator valueAnimator = ValueAnimator.ofInt(photoLayoutHolder.getPaddingTop()); valueAnimator.setInterpolator(new EaseInOutBezierInterpolator()); valueAnimator.setDuration(animationDuration); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from w ww . jav a2 s . c om*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { photoLayoutHolder.setPadding(0, (Integer) valueAnimator.getAnimatedValue(), 0, 0); } }); valueAnimator.start(); } else { photoLayoutHolder.setPadding(0, 0, 0, 0); } scrollView.setPadding(0, 0, 0, -fabPadding); specsLayout.setPadding(0, 0, 0, fabPadding); ValueAnimator valueAnimator = ValueAnimator.ofInt(detailsViewGroup.getPaddingTop(), size.getHeight()); valueAnimator.setInterpolator(new EaseInOutBezierInterpolator()); valueAnimator.setDuration(animationDuration); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { detailsViewGroup.setPadding(sidePadding, (Integer) valueAnimator.getAnimatedValue(), sidePadding, detailsViewGroup.getPaddingBottom()); } }); valueAnimator.start(); }
From source file:com.roughike.bottombar.BottomBarTab.java
private void setTopPaddingAnimated(int start, int end) { if (type == Type.TABLET || isTitleless) { return;/*from w w w .j a va 2 s. co m*/ } ValueAnimator paddingAnimator = ValueAnimator.ofInt(start, end); paddingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { iconView.setPadding(iconView.getPaddingLeft(), (Integer) animation.getAnimatedValue(), iconView.getPaddingRight(), iconView.getPaddingBottom()); } }); paddingAnimator.setDuration(ANIMATION_DURATION); paddingAnimator.start(); }
From source file:com.bitants.wally.activities.ImageDetailsActivity.java
/** * Animations animations animations./* w w w. j a v a 2 s .co m*/ */ private void toggleZoomImage() { int animationDuration = 400; if (isInFullscreen()) { scrollView.smoothScrollTo(0, (Integer) scrollView.getTag()); if (photoViewAttacher != null) { photoViewAttacher.cleanup(); photoViewAttacher = null; photoView.setScaleType(ImageView.ScaleType.CENTER_CROP); } } else { scrollView.setTag(scrollView.getScrollY()); scrollView.smoothScrollTo(0, 0); if (photoViewAttacher == null) { photoViewAttacher = new PhotoViewAttacher(photoView); photoViewAttacher.setZoomable(true); photoViewAttacher.setScaleType(ImageView.ScaleType.CENTER_CROP); } } if (getSupportActionBar() != null) { getToolbar().animate().translationY(isInFullscreen() ? 0.0f : -getToolbar().getMeasuredHeight()) .alpha(isInFullscreen() ? 1.0f : 0.0f).setDuration(500) .setInterpolator(new EaseInOutBezierInterpolator()).start(); } findViewById(R.id.image_details_protective_shadow).animate().alpha(isInFullscreen() ? 1.0f : 0.0f) .setDuration(500).setInterpolator(new EaseInOutBezierInterpolator()).start(); int minimumAllowedHeight = getToolbar().getMeasuredHeight() + getResources().getDimensionPixelSize(R.dimen.fab_padding_positive); if (imageSize.getHeight() < minimumAllowedHeight) { int topFrom; int topTo; if (isInFullscreen()) { topFrom = 0; topTo = getToolbar().getMeasuredHeight(); } else { topFrom = photoLayoutHolder.getPaddingTop(); topTo = 0; } ValueAnimator topValueAnimator = ValueAnimator.ofInt(topFrom, topTo); topValueAnimator.setDuration(animationDuration); topValueAnimator.setInterpolator(new EaseInOutBezierInterpolator()); topValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); photoLayoutHolder.setPadding(photoLayoutHolder.getPaddingLeft(), val, photoLayoutHolder.getPaddingRight(), photoLayoutHolder.getPaddingBottom()); } }); topValueAnimator.start(); } if (photoLayoutHolder.getTranslationY() != 0.0f) { photoLayoutHolder.animate().translationY(0.0f).setInterpolator(new EaseInOutBezierInterpolator()) .setDuration(animationDuration).start(); } WindowManager win = getWindowManager(); Display d = win.getDefaultDisplay(); int from = photoView.getMeasuredHeight(); int to = isInFullscreen() ? imageSize.getHeight() : d.getHeight(); ValueAnimator valueAnimator = ValueAnimator.ofInt(from, to); valueAnimator.setDuration(animationDuration); valueAnimator.setInterpolator(new EaseInOutBezierInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); RelativeLayout.LayoutParams toolbarParams = (RelativeLayout.LayoutParams) photoView .getLayoutParams(); toolbarParams.height = val; photoView.setLayoutParams(toolbarParams); } }); valueAnimator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { if (photoViewAttacher != null) { photoViewAttacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() { @Override public void onPhotoTap(View view, float v, float v2) { toggleZoomImage(); } }); } } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); valueAnimator.start(); int scrollTo = isInFullscreen() ? 0 : d.getHeight(); scrollView.animate().y(scrollTo).setDuration(animationDuration) .setInterpolator(new EaseInOutBezierInterpolator()).start(); isInFullscreen = !isInFullscreen; }
From source file:com.bitants.wally.activities.ImageDetailsActivity.java
private void setupPaddings(final Size size, boolean animate) { int animationDuration = animate ? 300 : 0; final int sidePadding = getResources() .getDimensionPixelSize(R.dimen.activity_details_scrollview_side_padding); int fabPadding = getResources().getDimensionPixelSize(R.dimen.fab_padding_positive); int minimumAllowedHeight = fabPadding; if (size.getHeight() < minimumAllowedHeight) { size.setHeight(size.getHeight()); ValueAnimator valueAnimator = ValueAnimator.ofInt(photoLayoutHolder.getPaddingTop()); valueAnimator.setInterpolator(new EaseInOutBezierInterpolator()); valueAnimator.setDuration(animationDuration); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*www .j a v a 2s . c o m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { photoLayoutHolder.setPadding(0, (Integer) valueAnimator.getAnimatedValue(), 0, 0); } }); valueAnimator.start(); } else { photoLayoutHolder.setPadding(0, 0, 0, 0); } scrollView.setPadding(0, 0, 0, -fabPadding); specsLayout.setPadding(0, 0, 0, fabPadding); ValueAnimator valueAnimator = ValueAnimator.ofInt(detailsViewGroup.getPaddingTop(), size.getHeight()); valueAnimator.setInterpolator(new EaseInOutBezierInterpolator()); valueAnimator.setDuration(animationDuration); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { detailsViewGroup.setPadding(sidePadding, (Integer) valueAnimator.getAnimatedValue(), sidePadding, detailsViewGroup.getPaddingBottom()); } }); valueAnimator.start(); }
From source file:arun.com.chromer.browsing.article.view.ElasticDragDismissFrameLayout.java
@Override public void onStopNestedScroll(View child) { if (enabled) { if (Math.abs(totalDrag) >= dragDismissDistance) { dispatchDismissCallback();/*from ww w . java 2s . co m*/ } else { // settle back to natural position if (fastOutSlowInInterpolator == null) { fastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.fast_out_slow_in); } getChildAt(0).animate().translationY(0f).scaleX(1f).scaleY(1f).setDuration(200L) .setInterpolator(fastOutSlowInInterpolator).setListener(null).start(); ValueAnimator animator = null; if (draggingUp) { animator = ValueAnimator.ofFloat(draggingBackground.top, draggingBackground.bottom); animator.addUpdateListener(valueAnimator -> { draggingBackground.top = (float) valueAnimator.getAnimatedValue(); invalidate(); }); } else if (draggingDown) { animator = ValueAnimator.ofFloat(draggingBackground.bottom, draggingBackground.top); animator.addUpdateListener(valueAnimator -> { draggingBackground.bottom = (float) valueAnimator.getAnimatedValue(); invalidate(); }); } if (animator != null) { animator.setInterpolator(fastOutSlowInInterpolator); animator.setDuration(200L); animator.start(); } totalDrag = 0; draggingDown = draggingUp = false; dispatchDragCallback(0f, 0f, 0f, 0f); } } }
From source file:com.telenav.nodeflow.NodeFlowLayout.java
/** * perform alpha animation associated with closing or opening a node * * @param startIndex start index of child views to be animated * @param endIndex end index of child views to be animated * @param destAlpha final alpha of child views to be animated *///from w w w. j a va 2 s .c o m private void animateDrillAlpha(final int startIndex, final int endIndex, final int destAlpha) { ValueAnimator animator = ValueAnimator.ofFloat(1 - destAlpha, destAlpha); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { for (int i = startIndex; i < endIndex; ++i) { getChildAt(i).setAlpha(((Float) animation.getAnimatedValue())); } } }); animator.addListener(new CustomAnimationListener() { @Override public void onAnimationStart(Animator animator) { for (int i = startIndex; i < getChildCount(); ++i) { getChildAt(i).setAlpha(1 - destAlpha); } } }); animator.setDuration(duration); if (destAlpha == 1) animator.setInterpolator(new AccelerateInterpolator()); else animator.setInterpolator(new DecelerateInterpolator(2)); animator.start(); }
From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java
private void fadeIn(boolean enter) { ValueAnimator backgroundAnim; if (Build.VERSION.SDK_INT >= 19) { backgroundAnim = ObjectAnimator.ofInt(backgroundDrawable, "alpha", enter ? 255 : 0); } else {/* w w w . j a v a 2s . c om*/ backgroundAnim = ValueAnimator.ofInt(enter ? 0 : 255, enter ? 255 : 0); backgroundAnim.addUpdateListener(animation -> { int value = (Integer) animation.getAnimatedValue(); backgroundDrawable.setAlpha(value); }); } backgroundAnim.setDuration(enter ? DEFAULT_DURATION_ENTER : DEFAULT_DURATION_EXIT); backgroundAnim.setInterpolator(enter ? DECELERATE : ACCELERATE); backgroundAnim.start(); Drawable icon = unwrap(getIcon()); if (icon != null) { ObjectAnimator iconAnim = ObjectAnimator.ofFloat(icon, "progress", enter ? 1 : 0); iconAnim.setDuration(backgroundAnim.getDuration()); iconAnim.setInterpolator(backgroundAnim.getInterpolator()); iconAnim.start(); } }
From source file:com.android.settings.widget.DotsPageIndicator.java
private ValueAnimator createJoiningAnimator(final int leftJoiningDot, final long startDelay) { // animate the joining fraction for the given dot ValueAnimator joining = ValueAnimator.ofFloat(0f, 1.0f); joining.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/* ww w . j a v a 2 s.c o m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { setJoiningFraction(leftJoiningDot, valueAnimator.getAnimatedFraction()); } }); joining.setDuration(animHalfDuration); joining.setStartDelay(startDelay); joining.setInterpolator(interpolator); return joining; }
From source file:com.ze.client.projecto.activity.MainActivity.java
private void animateToolbarColorResource(@ColorRes int fromColorRes, @ColorRes final int toColorRes) { @ColorInt//from ww w. j av a 2 s.c o m int fromColor = ResourcesCompat.getColor(getResources(), fromColorRes, getTheme()); @ColorInt int toColor = ResourcesCompat.getColor(getResources(), toColorRes, getTheme()); if (((ColorDrawable) mToolbar.getBackground()).getColor() == toColor) { return; } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { ValueAnimator anim = ValueAnimator.ofArgb(fromColor, toColor); anim.addUpdateListener( valueAnimator -> mToolbar.setBackgroundColor((Integer) valueAnimator.getAnimatedValue())); anim.addUpdateListener( valueAnimator -> mInfoLayout.setBackgroundColor((Integer) valueAnimator.getAnimatedValue())); @ColorInt int fromStatusColor = getWindow().getStatusBarColor(); @ColorInt int toStatusColor = ColorUtils.scrimify(toColor, true, 0.2f); ValueAnimator anim2 = ValueAnimator.ofArgb(fromStatusColor, toStatusColor); anim2.addUpdateListener( valueAnimator -> getWindow().setStatusBarColor(((Integer) valueAnimator.getAnimatedValue()))); anim.setDuration(300); anim2.setDuration(300); anim.start(); anim2.start(); } else { mToolbar.setBackgroundColor(toColor); mInfoLayout.setBackgroundColor(toColor); } }