Skip to content

Commit a35c785

Browse files
committed
Merge pull request square#1090 from jobi/stop-placeholder-on-error
Stop placeholder animation on errors
2 parents fbb9327 + 12667fc commit a35c785

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

picasso/src/main/java/com/squareup/picasso/ImageViewAction.java

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import android.content.Context;
1919
import android.graphics.Bitmap;
20+
import android.graphics.drawable.AnimationDrawable;
2021
import android.graphics.drawable.Drawable;
2122
import android.widget.ImageView;
2223

@@ -57,6 +58,10 @@ class ImageViewAction extends Action<ImageView> {
5758
if (target == null) {
5859
return;
5960
}
61+
Drawable placeholder = target.getDrawable();
62+
if (placeholder instanceof AnimationDrawable) {
63+
((AnimationDrawable) placeholder).stop();
64+
}
6065
if (errorResId != 0) {
6166
target.setImageResource(errorResId);
6267
} else if (errorDrawable != null) {

picasso/src/test/java/com/squareup/picasso/ImageViewActionTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.squareup.picasso;
1717

1818
import android.graphics.Bitmap;
19+
import android.graphics.drawable.AnimationDrawable;
1920
import android.graphics.drawable.Drawable;
2021
import android.widget.ImageView;
2122
import org.junit.Test;
@@ -36,6 +37,7 @@
3637
import static org.mockito.Mockito.mock;
3738
import static org.mockito.Mockito.verify;
3839
import static org.mockito.Mockito.verifyZeroInteractions;
40+
import static org.mockito.Mockito.when;
3941

4042
@RunWith(RobolectricTestRunner.class)
4143
@Config(manifest = Config.NONE)
@@ -145,4 +147,17 @@ public void clearsCallbackOnCancel() throws Exception {
145147
request.cancel();
146148
assertThat(request.callback).isNull();
147149
}
150+
151+
@Test
152+
public void stopPlaceholderAnimationOnError() throws Exception {
153+
Picasso picasso = mock(Picasso.class);
154+
AnimationDrawable placeholder = mock(AnimationDrawable.class);
155+
ImageView target = mockImageViewTarget();
156+
when(target.getDrawable()).thenReturn(placeholder);
157+
ImageViewAction request =
158+
new ImageViewAction(picasso, target, null, 0, 0, 0, null, URI_KEY_1, null,
159+
null, false);
160+
request.error();
161+
verify(placeholder).stop();
162+
}
148163
}

0 commit comments

Comments
 (0)