List of usage examples for android.animation ValueAnimator getDuration
@Override public long getDuration()
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 ww . j av a 2 s . c o m*/ 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.roughike.bottombar.BottomBarTab.java
void updateWidth(float endWidth, boolean animated) { if (!animated) { getLayoutParams().width = (int) endWidth; if (!isActive && badge != null) { badge.adjustPositionAndSize(this); badge.show();/*from w w w. j a v a2 s. com*/ } return; } float start = getWidth(); ValueAnimator animator = ValueAnimator.ofFloat(start, endWidth); animator.setDuration(150); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { ViewGroup.LayoutParams params = getLayoutParams(); if (params == null) return; params.width = Math.round((float) animator.getAnimatedValue()); setLayoutParams(params); } }); // Workaround to avoid using faulty onAnimationEnd() listener postDelayed(new Runnable() { @Override public void run() { if (!isActive && badge != null) { clearAnimation(); badge.adjustPositionAndSize(BottomBarTab.this); badge.show(); } } }, animator.getDuration()); animator.start(); }