| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 
 | class InitAnimation {private Button mButton;
 private String text;
 
 private int centerDrawable;
 private int backGroundDrawable;
 private BtnBgRes res;
 public ValueAnimator animator;
 
 public InitAnimation(Button button, String text, int centerDrawable, int backGroundDrawable, BtnBgRes res) {
 //要闪烁的按钮,按钮中间的文字(初始化文字),按钮中间的图标(初始化图标),背景(初始化背景),btnbgres(闪烁的多幅图片替换)
 this.text = text;
 this.mButton = button;
 this.centerDrawable = centerDrawable;
 this.backGroundDrawable = backGroundDrawable;
 this.res = res;
 }
 
 public boolean isAnimation() {
 boolean flag = false;
 if (animator != null && animator.isRunning()) {
 flag = true;
 }
 return flag;
 }
 
 public void startAnimation() {
 //        main_help.setText(res.getTextState());
 mButton.setText("");
 Drawable helpImg = getResources().getDrawable(centerDrawable);
 helpImg.setBounds(0, 50, 150, 200);
 mButton.setCompoundDrawables(null, null, null, null);
 
 if (animator != null && animator.isRunning()) {
 animator.cancel();
 }
 startDrawable = ContextCompat.getDrawable(getActivity(), res.getStartDrawable());
 endDrawable = ContextCompat.getDrawable(getActivity(), res.getEndDrawable());
 animator = ValueAnimator.ofObject(new BackgroundEvaluator(), startDrawable, endDrawable);
 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
 @Override
 public void onAnimationUpdate(ValueAnimator animation) {
 //                Log.d(TAG, "Animation:---->start");
 mButton.setBackground((Drawable) animation.getAnimatedValue());
 }
 });
 animator.setDuration(1500);   //毫秒
 animator.setRepeatCount(ValueAnimator.INFINITE);  //无限循环
 animator.start();
 //        talkState.setText(res.getTextState());
 
 }
 
 public void stopAnimation() {
 if (isAnimation()) {
 animator.cancel();
 }
 Drawable helpImg = getResources().getDrawable(centerDrawable);
 //            R.drawable.alarm
 mButton.setBackgroundResource(backGroundDrawable);
 //            R.drawable.bt_shape_red
 helpImg.setBounds(0, 50, 150, 200);
 mButton.setCompoundDrawables(null, helpImg, null, null);
 mButton.setText(text);
 //            getResources().getString(R.string.home_button_alarm_help);
 }
 }
 
 |