下面列出了怎么用android.view.animation.CycleInterpolator的API类实例代码及写法,或者点击链接到github查看源代码。
private void invalidateField(final EditText editText){
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.colorHeader), getResources().getColor(R.color.brightRed));
colorAnimation.setDuration(200);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
editText.setTextColor((int) animation.getAnimatedValue());
}
});
Animation invalidShake = AnimationUtils.loadAnimation(this, R.anim.invalid_shake);
invalidShake.setInterpolator(new CycleInterpolator(7F));
colorAnimation.start();
editText.startAnimation(invalidShake);
}
private void invalidateField(final EditText editText){
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.colorHeader), getResources().getColor(R.color.invalidRed));
colorAnimation.setDuration(200);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
editText.getBackground().setColorFilter((int) animation.getAnimatedValue(), PorterDuff.Mode.SRC_ATOP);
editText.setTextColor((int) animation.getAnimatedValue());
}
});
Animation invalidShake = AnimationUtils.loadAnimation(getActivity(), R.anim.invalid_shake);
invalidShake.setInterpolator(new CycleInterpolator(7F));
colorAnimation.start();
editText.startAnimation(invalidShake);
}
private void invalidateField(final EditText editText){
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.colorHeader), getResources().getColor(R.color.invalidRed));
colorAnimation.setDuration(200);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
editText.getBackground().setColorFilter((int) animation.getAnimatedValue(), PorterDuff.Mode.SRC_ATOP);
editText.setTextColor((int) animation.getAnimatedValue());
}
});
Animation invalidShake = AnimationUtils.loadAnimation(this, R.anim.invalid_shake);
invalidShake.setInterpolator(new CycleInterpolator(7F));
colorAnimation.start();
editText.startAnimation(invalidShake);
}
private void invalidateField(final EditText editText){
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.colorHeader), getResources().getColor(R.color.invalidRed));
colorAnimation.setDuration(200);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
editText.getBackground().setColorFilter((int) animation.getAnimatedValue(), PorterDuff.Mode.SRC_ATOP);
editText.setTextColor((int) animation.getAnimatedValue());
}
});
Animation invalidShake = AnimationUtils.loadAnimation(getActivity(), R.anim.invalid_shake);
invalidShake.setInterpolator(new CycleInterpolator(7F));
colorAnimation.start();
editText.startAnimation(invalidShake);
}
private void invalidateField(final EditText editText){
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.colorHeader), getResources().getColor(R.color.brightRed));
colorAnimation.setDuration(200);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
editText.setTextColor((int) animation.getAnimatedValue());
}
});
Animation invalidShake = AnimationUtils.loadAnimation(getActivity(), R.anim.invalid_shake);
invalidShake.setInterpolator(new CycleInterpolator(7F));
colorAnimation.start();
editText.startAnimation(invalidShake);
}
/**
* According to the different status display text message
* @param resId
* @param isError
*/
private void showErrorHint(String resId,boolean isError){
if(resId == null){
drawpatterTv.setVisibility(View.INVISIBLE);
}else{
drawpatterTv.setVisibility(View.VISIBLE);
drawpatterTv.setText(resId);
if(isError){
drawpatterTv.setTextColor(mActivity.getResources().getColor(R.color.color_ff6c5a));
Animation animationInto = AnimationUtils.loadAnimation(mActivity,R.anim.text_shake);
animationInto.setInterpolator(new CycleInterpolator(5));
drawpatterTv.setAnimation(animationInto);
}else{
drawpatterTv.setTextColor(mActivity.getResources().getColor(R.color.color_161A21));
}
}
}
private void initInterpolations() {
ArrayList<Class> interpolatorList = new ArrayList<Class>() {{
add(FastOutSlowInInterpolator.class);
add(BounceInterpolator.class);
add(LinearInterpolator.class);
add(DecelerateInterpolator.class);
add(CycleInterpolator.class);
add(AnticipateInterpolator.class);
add(AccelerateDecelerateInterpolator.class);
add(AccelerateInterpolator.class);
add(AnticipateOvershootInterpolator.class);
add(FastOutLinearInInterpolator.class);
add(LinearOutSlowInInterpolator.class);
add(OvershootInterpolator.class);
}};
try {
interpolatorSelector = (Interpolator) interpolatorList.get(animateSelector).newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* This animation will make a pulse effect to the inner circle
*
* @return Animation
*/
private Animator preparePulseAnimation() {
AnimatorSet animation = new AnimatorSet();
Animator firstBounce = ObjectAnimator.ofFloat(drawable, CircularProgressDrawable.CIRCLE_SCALE_PROPERTY,
drawable.getCircleScale(), 0.88f);
firstBounce.setDuration(300);
firstBounce.setInterpolator(new CycleInterpolator(1));
Animator secondBounce = ObjectAnimator.ofFloat(drawable, CircularProgressDrawable.CIRCLE_SCALE_PROPERTY,
0.75f, 0.83f);
secondBounce.setDuration(300);
secondBounce.setInterpolator(new CycleInterpolator(1));
Animator thirdBounce = ObjectAnimator.ofFloat(drawable, CircularProgressDrawable.CIRCLE_SCALE_PROPERTY,
0.75f, 0.80f);
thirdBounce.setDuration(300);
thirdBounce.setInterpolator(new CycleInterpolator(1));
animation.playSequentially(firstBounce, secondBounce, thirdBounce);
return animation;
}
/**
* @param shouldResetTextColor if true make sure you end the previous animation before starting this one.
*/
public static ObjectAnimator getShakeAnimation(final TextView textView, final boolean shouldResetTextColor) {
final int textColor = textView.getCurrentTextColor();
textView.setTextColor(Color.RED);
ObjectAnimator shakeAnim = ObjectAnimator.ofFloat(textView, "translationX", -16);
shakeAnim.setDuration(SHAKE_DURATION);
shakeAnim.setInterpolator(new CycleInterpolator(2.0f));
shakeAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator anim) {
if (shouldResetTextColor) {
textView.setTextColor(textColor);
}
}
});
return shakeAnim;
}
public static Interpolator parse(Integer type, Float cycles) {
if (type != null) {
switch (type) {
case 0:
return new AccelerateDecelerateInterpolator();
case 1:
return new AccelerateInterpolator();
case 2:
return new AnticipateInterpolator();
case 3:
return new AnticipateOvershootInterpolator();
case 4:
return new BounceInterpolator();
case 5:
return new CycleInterpolator((cycles != null && cycles > 0) ? cycles : 1f);
case 6:
return new DecelerateInterpolator();
case 7:
return new LinearInterpolator();
case 8:
return new OvershootInterpolator();
default:
return new LinearInterpolator();
}
} else {
return new LinearInterpolator();
}
}
public static Animation shakeAnimation(int counts)
{
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(1000);
return translateAnimation;
}
/**
* 晃动动画
*
* @param counts 半秒钟晃动多少下
* @return
*/
public static Animation shakeAnimation(int counts) {
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(500);
return translateAnimation;
}
/**
* 晃动动画
* @param counts 1秒钟晃动多少下
* @return
*/
public static Animation shakeAnimation(int counts){
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(1000);
return translateAnimation;
}
/**
* 晃动动画
*
* @param counts 1秒钟晃动多少下
* @return
*/
public static Animation shakeAnimation(int counts) {
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(800);
return translateAnimation;
}
/**
* 晃动动画
* @param counts 半秒钟晃动多少下
* @return
*/
public static Animation shakeAnimation(int counts) {
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(500);
return translateAnimation;
}
@Override
public void initView() {
mActivity = this;
toolbarTop.setTitleImg(R.mipmap.logo_black_middle);
UserBean userBean = SharedPreferenceUtil.getInstance().getUser();
idGestureLockViewGroup.setAnswer(userBean.getPriKey(),userBean.getSalt());
idGestureLockViewGroup.setOnGestureLockViewListener(new GestureLockViewGroup.OnGestureLockViewListener() {
@Override
public void onBlockSelected(int cId) {
}
@Override
public void onGestureEvent(boolean matched) {
if (matched) {
goinHome(idGestureLockViewGroup.getPriKey());
} else {
hintTv.setText(getString(R.string.Set_Password_incorrect_you_have_chance,idGestureLockViewGroup.getUnMatchExceedBoundary()));
Animation animationInto = AnimationUtils.loadAnimation(mActivity,R.anim.text_shake);
animationInto.setInterpolator(new CycleInterpolator(5));
hintTv.setAnimation(animationInto);
}
}
@Override
public void onUnmatchedExceedBoundary() {
SharedPreferenceUtil.getInstance().remove(SharedPreferenceUtil.USER_INFO);
ActivityUtil.next(mActivity, LoginForPhoneActivity.class);
finish();
}
});
}
/**
* Apply the error animations which will move key left to right and after right to left for two times.
*/
private ValueAnimator playErrorAnimation() {
ValueAnimator goLeftAnimator = ValueAnimator.ofInt(0, 10);
goLeftAnimator.setInterpolator(new CycleInterpolator(2));
goLeftAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mBounds.left += (int) animation.getAnimatedValue();
mBounds.right += (int) animation.getAnimatedValue();
getRootView().invalidate();
}
});
return goLeftAnimator;
}
/**
* Public constructor.
*/
private SquareKey(@NonNull SquareKey.Builder builder,
@NonNull final String keyTitle,
@NonNull final Rect bound) {
super(builder, keyTitle, bound);
mBuilder = builder;
//Set the keyboard paint
mKeyPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mKeyPaint.setStyle(Paint.Style.STROKE);
mKeyPaint.setColor(builder.mKeyStrokeColor);
mKeyPaint.setTextSize(builder.mKeyTextSize);
mKeyPaint.setStrokeWidth(builder.mKeyStrokeWidth);
//Set the keyboard text paint
mKeyTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mKeyTextPaint.setColor(builder.mKeyTextColor);
mKeyTextPaint.setTextSize(builder.mKeyTextSize);
mKeyTextPaint.setFakeBoldText(true);
mKeyTextPaint.setTextAlign(Paint.Align.CENTER);
//Ripple paint
mRipplePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRipplePaint.setStyle(Paint.Style.STROKE);
mRipplePaint.setColor(Utils.makeColorDark(builder.mKeyStrokeColor));
mRipplePaint.setStrokeWidth(builder.mKeyStrokeWidth);
//Error animator
mErrorAnimator = ValueAnimator.ofInt(0, 10);
mErrorAnimator.setInterpolator(new CycleInterpolator(2));
mErrorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
getBounds().left += (int) animation.getAnimatedValue();
getBounds().right += (int) animation.getAnimatedValue();
getPasscodeView().invalidate();
}
});
}
/**
* Public constructor.
*/
private RectKey(@NonNull RectKey.Builder builder,
@NonNull final String keyTitle,
@NonNull final Rect bound) {
super(builder, keyTitle, bound);
mBuilder = builder;
//Set the keyboard paint
mKeyPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mKeyPaint.setStyle(Paint.Style.STROKE);
mKeyPaint.setColor(builder.mKeyStrokeColor);
mKeyPaint.setTextSize(builder.mKeyTextSize);
mKeyPaint.setStrokeWidth(builder.mKeyStrokeWidth);
//Set the keyboard text paint
mKeyTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mKeyTextPaint.setColor(builder.mKeyTextColor);
mKeyTextPaint.setTextSize(builder.mKeyTextSize);
mKeyTextPaint.setFakeBoldText(true);
mKeyTextPaint.setTextAlign(Paint.Align.CENTER);
//Ripple paint
mRipplePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRipplePaint.setStyle(Paint.Style.STROKE);
mRipplePaint.setColor(Utils.makeColorDark(builder.mKeyStrokeColor));
mRipplePaint.setStrokeWidth(builder.mKeyStrokeWidth);
//Error animator
mErrorAnimator = ValueAnimator.ofInt(0, 10);
mErrorAnimator.setInterpolator(new CycleInterpolator(2));
mErrorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
getBounds().left += (int) animation.getAnimatedValue();
getBounds().right += (int) animation.getAnimatedValue();
getPasscodeView().invalidate();
}
});
}
/**
* 晃动动画
* @param counts 1秒钟晃动多少下
* @return
*/
public static Animation shakeAnimation(int counts){
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(1000);
return translateAnimation;
}
/**
* �����
* @param counts 1���ӻζ�������
* @return
*/
public static Animation shakeAnimation(int counts){
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(1000);
return translateAnimation;
}
private void startAnimation() {
ObjectAnimator animator = ObjectAnimator.ofFloat(ivSplashIcon, "translationY", 0, -(ivSplashIcon.getHeight() >> 1));
animator.setDuration(800);
animator.setRepeatCount(ObjectAnimator.INFINITE);
animator.setRepeatMode(ObjectAnimator.RESTART);
animator.setInterpolator(new CycleInterpolator(0.5f));
animator.start();
}
/**
* 晃动动画
*
* @param counts 1秒钟晃动多少下
* @return
*/
public static Animation shakeAnimation(int counts) {
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(1000);
return translateAnimation;
}
private void failureAnim() {
float currentX = this.getTranslationX();
ObjectAnimator tansXAnim = ObjectAnimator.ofFloat(this, "translationX",currentX+20);
tansXAnim.setDuration(1000);
tansXAnim.setInterpolator(new CycleInterpolator(3));
tansXAnim.start();
}
@Override
public void setAnimation(View view) {
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", -10, 10);
animator.setInterpolator(new CycleInterpolator(5));
animatorSet.playTogether(animator);
/**
* <pre>
* 另一种shake实现
* ObjectAnimator.ofFloat(view, "translationX", 0, 25, -25, 25, -25, 15, -15, 6, -6, 0);
* </pre>
*/
}
/**
* 抖动动动画
* counts 1秒钟晃动多少下
*/
public static Animation shakeAnimation(int counts){
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(1000);
return translateAnimation;
}
/**
* Show animation indicated invalid pincode
*/
public void setError() {
ValueAnimator goLeftAnimator = ValueAnimator.ofInt(0, 5);
goLeftAnimator.setInterpolator(new CycleInterpolator(2));
goLeftAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override public void onAnimationUpdate(ValueAnimator animation) {
rect.left += (int) animation.getAnimatedValue();
rect.right += (int) animation.getAnimatedValue();
view.invalidate();
}
});
goLeftAnimator.start();
}
/**
* 晃动动画
* @param counts 半秒钟晃动多少下
* @return
*/
public static Animation shakeAnimation(int counts){
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(500);
return translateAnimation;
}
/**
* 晃动动画
*
* @param counts 1秒钟晃动多少下
* @return
*/
public static Animation shakeAnimation(int counts) {
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(1000);
return translateAnimation;
}
private void startRotationAnimation() {
if (!mHasCenterIcon) {
return;
}
mIconAnimator = ObjectAnimator.ofFloat(mCenterIv, "rotation", 0f, 15f);
mIconAnimator.setRepeatCount(Animation.INFINITE);
mIconAnimator.setInterpolator(new CycleInterpolator(1));
mIconAnimator.setDuration(2000);
mIconAnimator.start();
}