33import android .animation .AnimatorSet ;
44import android .animation .ObjectAnimator ;
55import android .animation .ValueAnimator ;
6+ import android .annotation .TargetApi ;
67import android .content .Context ;
78import android .content .res .TypedArray ;
89import android .graphics .Bitmap ;
1516import android .graphics .Point ;
1617import android .graphics .RectF ;
1718import android .graphics .Shader ;
19+ import android .os .Build ;
1820import android .text .TextUtils ;
1921import android .util .AttributeSet ;
2022import android .view .View ;
@@ -688,12 +690,44 @@ public void setCenterTitleStrokeColor(int centerTitleStrokeColor) {
688690 mCenterTitleStrokePaint .setColor (centerTitleStrokeColor );
689691 }
690692
691- private void startAnimation () {
693+ public void startAnimation () {
692694 if (mAnimatorSet != null ) {
693695 mAnimatorSet .start ();
694696 }
695697 }
696698
699+ public void endAnimation () {
700+ if (mAnimatorSet != null ) {
701+ mAnimatorSet .end ();
702+ }
703+ }
704+
705+ public void cancelAnimation () {
706+ if (mAnimatorSet != null ) {
707+ mAnimatorSet .cancel ();
708+ }
709+ }
710+
711+ @ TargetApi (Build .VERSION_CODES .KITKAT )
712+ @ SuppressWarnings ("deprecation" )
713+ public void pauseAnimation () {
714+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .KITKAT ) {
715+ if (mAnimatorSet != null ) {
716+ mAnimatorSet .pause ();
717+ }
718+ }
719+ }
720+
721+ @ TargetApi (Build .VERSION_CODES .KITKAT )
722+ @ SuppressWarnings ("deprecation" )
723+ public void resumeAnimation () {
724+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .KITKAT ) {
725+ if (mAnimatorSet != null ) {
726+ mAnimatorSet .resume ();
727+ }
728+ }
729+ }
730+
697731 private void initAnimation () {
698732 // Wave waves infinitely.
699733 ObjectAnimator waveShiftAnim = ObjectAnimator .ofFloat (this , "waveShiftRatio" , 0f , 1f );
@@ -705,12 +739,6 @@ private void initAnimation() {
705739 mAnimatorSet .play (waveShiftAnim );
706740 }
707741
708- private void cancel () {
709- if (mAnimatorSet != null ) {
710- mAnimatorSet .end ();
711- }
712- }
713-
714742 @ Override
715743 protected void onAttachedToWindow () {
716744 startAnimation ();
@@ -719,7 +747,7 @@ protected void onAttachedToWindow() {
719747
720748 @ Override
721749 protected void onDetachedFromWindow () {
722- cancel ();
750+ cancelAnimation ();
723751 super .onDetachedFromWindow ();
724752 }
725753
0 commit comments