Skip to content

Commit 5eca9dc

Browse files
committed
Fixed launch animation when view not attached to window
1 parent 6c67419 commit 5eca9dc

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

support/src/main/java/com/github/nikartm/support/AnimatedStripedDrawable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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();

support/src/main/java/com/github/nikartm/support/StripedProcessButton.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
public 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
}

0 commit comments

Comments
 (0)