List of usage examples for android.animation ValueAnimator addUpdateListener
public void addUpdateListener(AnimatorUpdateListener listener)
From source file:xyz.klinker.android.article.view.ElasticDragDismissFrameLayout.java
@Override public void onStopNestedScroll(View child) { if (enabled) { if (Math.abs(totalDrag) >= dragDismissDistance) { dispatchDismissCallback();// ww w . j a va 2 s . c o 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(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { draggingBackground.top = (float) valueAnimator.getAnimatedValue(); invalidate(); } }); } else if (draggingDown) { animator = ValueAnimator.ofFloat(draggingBackground.bottom, draggingBackground.top); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator 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.ze.client.projecto.activity.MainActivity.java
private void animateToolbarColorResource(@ColorRes int fromColorRes, @ColorRes final int toColorRes) { @ColorInt/* w w w . j a v a2 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); } }
From source file:com.telenav.nodeflow.NodeFlowLayout.java
/** * perform a fade in animation for showing node content * * @param node active node/*from w w w.ja va 2s .co m*/ */ private void fadeIn(final Node<?> node) { ValueAnimator animator = ValueAnimator.ofFloat(1); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { for (int i = getChildCount() - (node.hasChildren() ? node.getChildCount() : 1); i < getChildCount(); ++i) { getChildAt(i).setAlpha(((Float) animation.getAnimatedValue())); } } }); animator.setDuration(duration); animator.setInterpolator(new FastOutSlowInInterpolator()); animator.start(); }
From source file:com.telenav.nodeflow.NodeFlowLayout.java
/** * perform a fade out animation for hiding node content * * @param node active node//from w w w . ja v a2 s. co m */ private void fadeOut(final Node<?> node) { ValueAnimator animator = ValueAnimator.ofFloat(1, 0); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { for (int i = 1; i < getChildCount(); ++i) { getChildAt(i).setAlpha(((Float) animation.getAnimatedValue())); } } }); animator.addListener(new CustomAnimationListener() { @Override public void onAnimationEnd(Animator animator) { animateDrillOut(node); } }); animator.setDuration(duration / 2); animator.setInterpolator(new FastOutSlowInInterpolator()); animator.start(); }
From source file:net.margaritov.preference.colorpicker.ColorPickerDialog.java
private ValueAnimator createColorTransitionAnimator(float start, float end) { ValueAnimator animator = ValueAnimator.ofFloat(start, end); animator.setDuration(500);//from ww w . j ava 2s . c o m animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float position = animation.getAnimatedFraction(); if (mIsPanelButtons) { int[] blended = new int[8]; for (int i = 0; i < mPanelViewButtons.length; i++) { blended[i] = blendColors(mPanelViewButtons[i].getColor(), mPaletteColors[mPalette][i], position); mPanelViewButtons[i].setColor(blended[i]); } } else { int blended = blendColors(mNewColor.getColor(), mNewColorValue, position); mNewColor.setColor(blended); } } }); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (!mIsPanelButtons) { mIsPanelButtons = true; } } }); return animator; }
From source file:com.bitants.wally.fragments.ImageZoomFragment.java
private void animateOut() { ValueAnimator animWidth = ValueAnimator.ofInt(zoomableImageView.getMeasuredWidth(), rect.right); animWidth.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w . java2 s . c om public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams(); layoutParams.width = val; zoomableImageView.setLayoutParams(layoutParams); } }); animWidth.setDuration(500); animWidth.start(); ValueAnimator animHeight = ValueAnimator.ofInt(zoomableImageView.getMeasuredHeight(), rect.bottom); animHeight.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams(); layoutParams.height = val; zoomableImageView.setLayoutParams(layoutParams); } }); animHeight.setDuration(500); animHeight.start(); if (statusBarHeightCorrection > 0) { zoomableImageView.animate().y(-statusBarHeightCorrection).setDuration(300).start(); } zoomableImageView.animate().alpha(0.0f).setDuration(500).start(); }
From source file:com.telenav.nodeflow.NodeFlowLayout.java
/** * perform opening animation for the specified node * * @param node node to be animated// w ww . j ava 2s. c o m */ private void animateDrillIn(final Node<?> node) { final int index = activeNode.getIndex() + (activeNode.getDepth() > 1 ? 1 : 0); ValueAnimator animator = ValueAnimator.ofFloat(1); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { for (int i = 0; i < getChildCount(); ++i) { if (i < index) { getChildAt(i).setTranslationY( headerHeight * i - ((Float) animation.getAnimatedValue()) * headerHeight * index); } else if (i > index) { getChildAt(i).setTranslationY(headerHeight * i + ((Float) animation.getAnimatedValue()) * (getHeight() - headerHeight * index)); } else { getChildAt(i).setTranslationY( headerHeight * i - ((Float) animation.getAnimatedValue()) * headerHeight * index); // move active item } } } }); animator.addListener(new CustomAnimationListener() { @Override public void onAnimationEnd(Animator animator) { updateViews(node, true); } }); animator.setDuration(duration); animator.setInterpolator(new FastOutSlowInInterpolator()); animator.start(); animateDrillAlpha(index + 1, getChildCount(), 0); }
From source file:com.example.administrator.iclub21.view.SlideSwitch.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public void moveToDest(final boolean toRight) { ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left); toDestAnim.setDuration(500);//from w w w .j a v a 2 s . co m toDestAnim.setInterpolator(new AccelerateDecelerateInterpolator()); toDestAnim.start(); toDestAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { frontRect_left = (Integer) animation.getAnimatedValue(); alpha = (int) (255 * (float) frontRect_left / (float) max_left); invalidateView(); } }); toDestAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (toRight) { isOpen = true; if (listener != null) listener.open(); frontRect_left_begin = max_left; } else { isOpen = false; if (listener != null) listener.close(); frontRect_left_begin = min_left; } } }); }
From source file:com.fruit.widget.SlideSwitch.java
public void moveToDest(final boolean toRight) { ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left); toDestAnim.setDuration(duration);// w w w . j a v a 2 s.c om toDestAnim.setInterpolator(new AccelerateDecelerateInterpolator()); toDestAnim.start(); toDestAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { frontRect_left = (Integer) animation.getAnimatedValue(); alpha = (int) (255 * (float) frontRect_left / (float) max_left); invalidateView(); } }); toDestAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (toRight) { isOpen = true; if (listener != null) listener.open(); frontRect_left_begin = max_left; } else { isOpen = false; if (listener != null) listener.close(); frontRect_left_begin = min_left; } } }); }
From source file:com.bitants.wally.fragments.ImageZoomFragment.java
private void animateIn(final Dialog dialog) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomableImageView.getLayoutParams(); params.width = rect.right;//from w w w . j a v a 2 s . c om params.height = rect.bottom; zoomableImageView.setLayoutParams(params); zoomableImageView.setX(rect.left); zoomableImageView.setY(rect.top - statusBarHeightCorrection); zoomableImageView.setAlpha(0.0f); zoomableImageView.setImageBitmap(bitmap); WindowManager win = getActivity().getWindowManager(); Display d = win.getDefaultDisplay(); int displayWidth = d.getWidth(); // Width of the actual device int displayHeight = d.getHeight() + statusBarHeightCorrection; ValueAnimator animWidth = ValueAnimator.ofInt(rect.right, displayWidth); animWidth.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams(); layoutParams.width = val; zoomableImageView.setLayoutParams(layoutParams); } }); animWidth.setDuration(500); animWidth.setInterpolator(new LinearOutSlowInInterpolator()); animWidth.start(); ValueAnimator animHeight = ValueAnimator.ofInt(rect.bottom, displayHeight); animHeight.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams(); layoutParams.height = val; zoomableImageView.setLayoutParams(layoutParams); } }); animHeight.setDuration(500); animHeight.setInterpolator(new LinearOutSlowInInterpolator()); animHeight.start(); if (statusBarHeightCorrection > 0) { zoomableImageView.animate().y(0.0f).setDuration(300).start(); } ValueAnimator animDim = ValueAnimator.ofFloat(0.0f, 0.5f); animDim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); layoutParams.copyFrom(dialog.getWindow().getAttributes()); layoutParams.dimAmount = (Float) valueAnimator.getAnimatedValue(); dialog.getWindow().setAttributes(layoutParams); } }); animDim.setDuration(300); animDim.setStartDelay(300); animDim.start(); zoomableImageView.animate().alpha(1.0f).setDuration(300).start(); }