File tree Expand file tree Collapse file tree
support/src/main/java/com/github/nikartm/support Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -168,6 +168,7 @@ protected void start() {
168168 return ;
169169 }
170170 running = true ;
171+ initAnimator ();
171172 animator .start ();
172173 setShowStripes (true );
173174 invalidateSelf ();
Original file line number Diff line number Diff line change 1616public class StripedProcessButton extends AppCompatButton implements Animatable {
1717
1818 private AnimatedStripedDrawable stripedDrawable ;
19+ private State state ;
1920
2021 private long startAnimDuration = Constants .NO_INIT ;
2122 private long stopAnimDuration = Constants .NO_INIT ;
@@ -48,6 +49,21 @@ private void initAttrs(AttributeSet attrs) {
4849 protected void onAttachedToWindow () {
4950 super .onAttachedToWindow ();
5051 defaultText = getText () != null ? getText ().toString () : "" ;
52+ launchAnimationWithDelay ();
53+ }
54+
55+ // Launch animation with delay when view attached to window
56+ private void launchAnimationWithDelay () {
57+ switch (state ) {
58+ case START :
59+ start ();
60+ break ;
61+ case STOP :
62+ stop ();
63+ break ;
64+ default :
65+ break ;
66+ }
5167 }
5268
5369 @ Override
@@ -59,6 +75,7 @@ protected void onDraw(Canvas canvas) {
5975
6076 @ Override
6177 public void start () {
78+ state = State .START ;
6279 if (isRunning () || !isAttachedToWindow ()) {
6380 return ;
6481 }
@@ -69,6 +86,7 @@ public void start() {
6986
7087 @ Override
7188 public void stop () {
89+ state = State .STOP ;
7290 if (!isRunning () || !isAttachedToWindow ()) {
7391 return ;
7492 }
@@ -153,4 +171,11 @@ public StripedProcessButton setButtonAnimation(boolean buttonAnimation) {
153171 return this ;
154172 }
155173
174+ /**
175+ * State of launch methods with delay
176+ */
177+ private enum State {
178+ START , STOP
179+ }
180+
156181}
You can’t perform that action at this time.
0 commit comments