Java Code Examples for android.animation.Animator#setInterpolator()

The following examples show how to use android.animation.Animator#setInterpolator() . 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: SearchAnimator.java    From MeiZiNews with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void revealInAnimation(final Context mContext, final View view, int duration) {

    int cx = view.getWidth() - mContext.getResources().getDimensionPixelSize(R.dimen.reveal);
    int cy = view.getHeight() / 2;

    if (cx != 0 && cy != 0) {
        float finalRadius = (float) Math.hypot(cx, cy);

        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0.0f, finalRadius);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration(duration);
        view.setVisibility(View.VISIBLE);
        anim.start();
    }
}
 
Example 2
Source File: SearchAnimator.java    From MeiZiNews with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void revealOutAnimation(final Context mContext, final View view, int duration) {

    int cx = view.getWidth() - mContext.getResources().getDimensionPixelSize(R.dimen.reveal);
    int cy = view.getHeight() / 2;

    if (cx != 0 && cy != 0) {
        float initialRadius = (float) Math.hypot(cx, cy);

        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0.0f);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration(duration);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.GONE);
            }
        });
        anim.start();
    }
}
 
Example 3
Source File: ColorPicker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void setDragging(boolean value, boolean animated) {
    if (dragging == value) {
        return;
    }
    dragging = value;
    float target = dragging ? 1.0f : 0.0f;
    if (animated) {
        Animator a = ObjectAnimator.ofFloat(this, "draggingFactor", draggingFactor, target);
        a.setInterpolator(interpolator);
        int duration = 300;
        if (wasChangingWeight) {
            duration += weight * 75;
        }
        a.setDuration(duration);
        a.start();
    } else {
        setDraggingFactor(target);
    }
}
 
Example 4
Source File: SnackbarView.java    From delion with Apache License 2.0 6 votes vote down vote up
void dismiss() {
    // Disable action button during animation.
    mActionButtonView.setEnabled(false);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(mAnimationDuration);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mParent.removeOnLayoutChangeListener(mLayoutListener);
            mParent.removeView(mView);
        }
    });
    Animator moveDown = ObjectAnimator.ofFloat(mView, View.TRANSLATION_Y,
            mView.getHeight() + getLayoutParams().bottomMargin);
    moveDown.setInterpolator(new DecelerateInterpolator());
    Animator fadeOut = ObjectAnimator.ofFloat(mView, View.ALPHA, 0f);
    fadeOut.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);

    animatorSet.playTogether(fadeOut, moveDown);
    startAnimatorOnSurfaceView(animatorSet);
}
 
Example 5
Source File: BaseCircleIndicator.java    From CircleIndicator with Apache License 2.0 5 votes vote down vote up
protected Animator createAnimatorIn(Config config) {
    Animator animatorIn;
    if (config.animatorReverseResId == 0) {
        animatorIn = AnimatorInflater.loadAnimator(getContext(), config.animatorResId);
        animatorIn.setInterpolator(new ReverseInterpolator());
    } else {
        animatorIn = AnimatorInflater.loadAnimator(getContext(), config.animatorReverseResId);
    }
    return animatorIn;
}
 
Example 6
Source File: FabSheetWindow.java    From android-md-core with Apache License 2.0 5 votes vote down vote up
private Animator createSheetDismissAnimation() {
  FabInfo.Pointer target = getTargetDistance();
  int dx = vSheetContainer.getMeasuredWidth() / 2;
  int dy = vSheetContainer.getMeasuredHeight() / 2;
  int dyFab = dy + (int) (target.y - (mFabMaxBottom != null ? (float) Math.min(mFabMaxBottom, target.y) : target.y));
  float radius = (float) Math.hypot(dx, Math.max(dy, dyFab));
  Animator animator = MdCompat.createCircularReveal(vSheetContainer, dx, dyFab, radius, mFabInfo.radius);
  animator.setInterpolator(ACCELERATE);
  return animator;
}
 
Example 7
Source File: NumberRollView.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a number to display.
 * @param animate Whether it should smoothly animate to the number.
 */
public void setNumber(int number, boolean animate) {
    if (mLastRollAnimator != null) mLastRollAnimator.cancel();

    if (animate) {
        Animator rollAnimator = ObjectAnimator.ofFloat(this, NUMBER_PROPERTY, number);
        rollAnimator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        rollAnimator.start();
        mLastRollAnimator = rollAnimator;
    } else {
        setNumberRoll(number);
    }
}
 
Example 8
Source File: NumberRollView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a number to display.
 * @param animate Whether it should smoothly animate to the number.
 */
public void setNumber(int number, boolean animate) {
    if (mLastRollAnimator != null) mLastRollAnimator.cancel();

    if (animate) {
        Animator rollAnimator = ObjectAnimator.ofFloat(this, NUMBER_PROPERTY, number);
        rollAnimator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        rollAnimator.start();
        mLastRollAnimator = rollAnimator;
    } else {
        setNumberRoll(number);
    }
}
 
Example 9
Source File: SupportAnimatorLollipop.java    From PersistentSearchView with Apache License 2.0 5 votes vote down vote up
@Override
public void setInterpolator(Interpolator value) {
    Animator a = mAnimator.get();
    if(a != null) {
        a.setInterpolator(value);
    }
}
 
Example 10
Source File: WXRenderStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
void startAnimation(String ref, String animation, String callBack) {
  WXComponent component = mRegistry.get(ref);
  if (component == null || component.getRealView() == null) {
    return;
  } else {
    try {
      WXAnimationBean animationBean = WXAnimationModule.parseAnimation(animation, component.getRealView().getLayoutParams());
      if (animationBean != null) {
        Animator animator = WXAnimationModule.createAnimator(animationBean, component.getRealView());
        if (animator != null) {
          Animator.AnimatorListener animatorListener = WXAnimationModule.createAnimatorListener(mWXSDKInstance, callBack);
          Interpolator interpolator = WXAnimationModule.createTimeInterpolator(animationBean);
          if (animatorListener != null) {
            animator.addListener(animatorListener);
          }
          if (interpolator != null) {
            animator.setInterpolator(interpolator);
          }
          animator.setDuration(animationBean.duration);
          animator.start();
        }
      }
    } catch (RuntimeException e) {
      WXLogUtils.e(WXLogUtils.getStackTrace(e));
    }
  }
}
 
Example 11
Source File: FabActivity.java    From example with Apache License 2.0 5 votes vote down vote up
private void hideView(final View expandedView) {
    int cx = (btnFAB.getLeft() + btnFAB.getRight()) / 2;
    int cy = (btnFAB.getTop() + btnFAB.getBottom()) / 2;

    int initialRadius = expandedView.getWidth();

    Animator anim = ViewAnimationUtils.createCircularReveal(expandedView, cx, cy, initialRadius, 0);
    anim.setDuration(300);
    anim.setInterpolator(getLinearOutSlowInInterpolator());

    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            expandedView.setVisibility(View.INVISIBLE);
        }
    });

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            btnFAB.setVisibility(View.VISIBLE);
        }
    }, 200);

    anim.start();

}
 
Example 12
Source File: CustomAnimation3.java    From BaseRecyclerViewAdapterHelper with MIT License 5 votes vote down vote up
@NotNull
@Override
public Animator[] animators(@NotNull View view) {
    Animator alpha = ObjectAnimator.ofFloat(view, "alpha", 0, 1f);
    alpha.setDuration(450);

    Animator translationY =
            ObjectAnimator.ofFloat(view, "translationY", view.getRootView().getHeight(), 0f);
    translationY.setDuration(450);
    translationY.setInterpolator(new DecelerateInterpolator(1.2f));

    return new Animator[]{alpha, translationY};
}
 
Example 13
Source File: AnimationAction.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) {
  if (component != null) {
    if (mAnimationBean != null) {
      component.setNeedLayoutOnAnimation(mAnimationBean.needLayout);
    }
    if (component.getHostView() == null) {
      WXAnimationModule.AnimationHolder holder = new WXAnimationModule.AnimationHolder(mAnimationBean, callback);
      component.postAnimation(holder);
    } else {
      try {
        Animator animator = createAnimator(component.getHostView(), instance
            .getInstanceViewPortWidth());
        if (animator != null) {
          Animator.AnimatorListener animatorCallback = createAnimatorListener(instance, callback);
          if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && component
              .isLayerTypeEnabled() ) {
            component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
          }
          Interpolator interpolator = createTimeInterpolator();
          if (animatorCallback != null) {
            animator.addListener(animatorCallback);
          }
          if (interpolator != null) {
            animator.setInterpolator(interpolator);
          }
          animator.setDuration(mAnimationBean.duration);
          animator.start();
        }
      } catch (RuntimeException e) {
        WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
      }
    }
  }
}
 
Example 14
Source File: FooterViewHolder.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
protected Animator getEnterAnimator(List<Animator> pendingAnimatorList) {
    Animator a = ObjectAnimator.ofFloat(itemView, "alpha", 0f, 1f);
    a.setDuration(450);
    a.setInterpolator(new FastOutSlowInInterpolator());
    a.setStartDelay(pendingAnimatorList.size() * 150);
    return a;
}
 
Example 15
Source File: MotionTiming.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
public void apply(@NonNull Animator animator) {
  animator.setStartDelay(getDelay());
  animator.setDuration(getDuration());
  animator.setInterpolator(getInterpolator());
  if (animator instanceof ValueAnimator) {
    ((ValueAnimator) animator).setRepeatCount(getRepeatCount());
    ((ValueAnimator) animator).setRepeatMode(getRepeatMode());
  }
}
 
Example 16
Source File: BaseProvider.java    From Flubber with Apache License 2.0 4 votes vote down vote up
protected void setupAnimation(AnimationBody animationBody, Animator animation) {
    animation.setInterpolator(interpolatorProvider.createInterpolatorFor(animationBody));
    setupRepeating(animation, animationBody);
}
 
Example 17
Source File: AnimatorUtils.java    From Qiitanium with MIT License 4 votes vote down vote up
public static Animator of(View target, TimeInterpolator interpolator,
    PropertyValuesHolder... values) {
  Animator anim = of(target, values);
  anim.setInterpolator(interpolator);
  return anim;
}
 
Example 18
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void populateUrlClearFocusingAnimatorSet(List<Animator> animators) {
    Animator animator = ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, 0f);
    animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, TRANSLATION_X, 0);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 1);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    if (mToggleTabStackButton != null) {
        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, TRANSLATION_X, 0);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);

        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, ALPHA, 1);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);
    }

    for (int i = 0; i < mLocationBar.getChildCount(); i++) {
        View childView = mLocationBar.getChildAt(i);
        if (childView == mLocationBar.getFirstViewVisibleWhenFocused()) break;
        animator = ObjectAnimator.ofFloat(childView, ALPHA, 1);
        animator.setStartDelay(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setDuration(URL_CLEAR_FOCUS_MENU_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);
    }

    if (isLocationBarShownInNTP() && mNtpSearchBoxScrollPercent == 0f) return;

    // The call to getLayout() can return null briefly during text changes, but as it
    // is only needed for RTL calculations, we proceed if the location bar is showing
    // LTR content.
    boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
    if (!isLocationBarRtl || mUrlBar.getLayout() != null) {
        int urlBarStartScrollX = 0;
        if (isLocationBarRtl) {
            urlBarStartScrollX = (int) mUrlBar.getLayout().getPrimaryHorizontal(0);
            urlBarStartScrollX -= mUrlBar.getWidth();
        }

        // If the scroll position matches the current scroll position, do not trigger
        // this animation as it will cause visible jumps when going from cleared text
        // back to page URLs (despite it continually calling setScrollX with the same
        // number).
        if (mUrlBar.getScrollX() != urlBarStartScrollX) {
            animator = ObjectAnimator.ofInt(mUrlBar,
                    buildUrlScrollProperty(mLocationBar, isLocationBarRtl), urlBarStartScrollX);
            animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
            animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
            animators.add(animator);
        }
    }
}
 
Example 19
Source File: BaseQuickAdapter.java    From AndroidBase with Apache License 2.0 2 votes vote down vote up
/**
 * set anim to start when loading
 *
 * @param anim
 * @param index
 */
protected void startAnim(Animator anim, int index) {
    anim.setDuration(mDuration).start();
    anim.setInterpolator(mInterpolator);
}
 
Example 20
Source File: AnimationLoader.java    From MultiItem with Apache License 2.0 2 votes vote down vote up
/**
 * 开启动画
 *
 * @param anim 动画
 */
protected void startAnim(Animator anim) {
    anim.setDuration(animDuration).start();
    anim.setInterpolator(interpolator);
}