Skip to content

Commit 2b5f9b0

Browse files
authored
Merge pull request #111 from penfeizhou/feature/zpf
Add nomeasure option
2 parents f7ff4d1 + 898a1f5 commit 2b5f9b0

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

app/src/main/java/com/github/penfeizhou/animation/demo/APNGTestActivity.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,17 @@ protected void onCreate(Bundle savedInstanceState) {
2222
setContentView(R.layout.activity_apnglib);
2323
LinearLayout linearLayout = findViewById(R.id.layout);
2424
String[] urls = new String[]{
25-
"file:///android_asset/apng_detail_guide.png",
26-
"https://misc.aotu.io/ONE-SUNDAY/SteamEngine.png",
27-
"https://isparta.github.io/compare-webp/image/gif_webp/webp/2.webp",
28-
"file:///android_asset/1.gif",
29-
"file:///android_asset/2.gif",
30-
"file:///android_asset/3.gif",
31-
"file:///android_asset/4.gif",
32-
"file:///android_asset/5.gif",
33-
"file:///android_asset/1.webp",
34-
"file:///android_asset/2.webp",
35-
"https://misc.aotu.io/ONE-SUNDAY/world_cup_2014_42.webp",
36-
"https://misc.aotu.io/ONE-SUNDAY/BladeRunner.webp",
37-
"https://misc.aotu.io/ONE-SUNDAY/SteamEngine.webp",
38-
"https://misc.aotu.io/ONE-SUNDAY/SteamEngine_lossy.webp",
39-
"https://ezgif.com/images/format-demo/butterfly-small.webp",
40-
};
25+
"https://misc.aotu.io/ONE-SUNDAY/SteamEngine.png"};
4126
for (String url : urls) {
4227
ImageView imageView = new ImageView(this);
43-
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
28+
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(500, 500);
4429
layoutParams.bottomMargin = 50;
4530
layoutParams.topMargin = 50;
4631
linearLayout.addView(imageView, layoutParams);
4732
GlideApp.with(imageView)
4833
.load(url)
34+
.set(AnimationDecoderOption.NO_ANIMATION_BOUNDS_MEASURE, true)
4935
.into(imageView);
5036
}
51-
// FileLoader fileLoader = new FileLoader("/data/data/com.github.pengfeizhou.animation.demo/cache/image_manager_disk_cache/b6dd68d837b8d1e8f24edb0a0df5213b7accebb16c22c8202e95363f7227740e.0");
52-
//
53-
// ImageView imageView = new ImageView(this);
54-
// LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
55-
// layoutParams.bottomMargin = 50;
56-
// layoutParams.topMargin = 50;
57-
// linearLayout.addView(imageView, layoutParams);
58-
// imageView.setImageDrawable(new APNGDrawable(fileLoader));
59-
6037
}
6138
}

frameanimation/src/main/java/com/github/penfeizhou/animation/FrameAnimationDrawable.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public void run() {
7474

7575
private final Set<WeakReference<Callback>> obtainedCallbacks = new HashSet<>();
7676

77+
private boolean noMeasure = false;
78+
7779
public FrameAnimationDrawable(Decoder frameSeqDecoder) {
7880
paint.setAntiAlias(true);
7981
this.frameSeqDecoder = frameSeqDecoder;
@@ -88,6 +90,10 @@ public void setAutoPlay(boolean autoPlay) {
8890
this.autoPlay = autoPlay;
8991
}
9092

93+
public void setNoMeasure(boolean noMeasure) {
94+
this.noMeasure = noMeasure;
95+
}
96+
9197
protected abstract Decoder createFrameSeqDecoder(Loader streamLoader, FrameSeqDecoder.RenderListener listener);
9298

9399
/**
@@ -240,6 +246,9 @@ public boolean setVisible(boolean visible, boolean restart) {
240246

241247
@Override
242248
public int getIntrinsicWidth() {
249+
if (noMeasure) {
250+
return -1;
251+
}
243252
try {
244253
return frameSeqDecoder.getBounds().width();
245254
} catch (Exception exception) {
@@ -249,6 +258,9 @@ public int getIntrinsicWidth() {
249258

250259
@Override
251260
public int getIntrinsicHeight() {
261+
if (noMeasure) {
262+
return -1;
263+
}
252264
try {
253265
return frameSeqDecoder.getBounds().height();
254266
} catch (Exception exception) {

plugin_glide/src/main/java/com/github/penfeizhou/animation/glide/AnimationDecoderOption.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public final class AnimationDecoderOption {
2828
public static final Option<Boolean> DISABLE_ANIMATION_APNG_DECODER = Option.memory(
2929
"com.github.penfeizhou.animation.glide.AnimationDecoderOption.DISABLE_ANIMATION_APNG_DECODER", false);
3030

31+
/**
32+
* If set to {@code true}, call {@link com.github.penfeizhou.animation.FrameAnimationDrawable#setNoMeasure(boolean)}
33+
* Defaults to {@code false}.
34+
*/
35+
public static final Option<Boolean> NO_ANIMATION_BOUNDS_MEASURE = Option.memory(
36+
"com.github.penfeizhou.animation.glide.AnimationDecoderOption.DISABLE_ANIMATION_BOUNDS_MEASURE", false);
37+
3138

3239
private AnimationDecoderOption() {
3340
}

plugin_glide/src/main/java/com/github/penfeizhou/animation/glide/FrameDrawableTranscoder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ class FrameDrawableTranscoder implements ResourceTranscoder<FrameSeqDecoder, Dra
2929
@Override
3030
public Resource<Drawable> transcode(@NonNull Resource<FrameSeqDecoder> toTranscode, @NonNull Options options) {
3131
FrameSeqDecoder frameSeqDecoder = toTranscode.get();
32+
boolean noMeasure = options.get(AnimationDecoderOption.NO_ANIMATION_BOUNDS_MEASURE);
3233
if (frameSeqDecoder instanceof APNGDecoder) {
3334
final APNGDrawable apngDrawable = new APNGDrawable((APNGDecoder) frameSeqDecoder);
3435
apngDrawable.setAutoPlay(false);
36+
apngDrawable.setNoMeasure(noMeasure);
3537
return new DrawableResource<Drawable>(apngDrawable) {
3638
@NonNull
3739
@Override
@@ -57,6 +59,7 @@ public void initialize() {
5759
} else if (frameSeqDecoder instanceof WebPDecoder) {
5860
final WebPDrawable webPDrawable = new WebPDrawable((WebPDecoder) frameSeqDecoder);
5961
webPDrawable.setAutoPlay(false);
62+
webPDrawable.setNoMeasure(noMeasure);
6063
return new DrawableResource<Drawable>(webPDrawable) {
6164
@NonNull
6265
@Override
@@ -81,6 +84,7 @@ public void initialize() {
8184
} else if (frameSeqDecoder instanceof GifDecoder) {
8285
final GifDrawable gifDrawable = new GifDrawable((GifDecoder) frameSeqDecoder);
8386
gifDrawable.setAutoPlay(false);
87+
gifDrawable.setNoMeasure(noMeasure);
8488
return new DrawableResource<Drawable>(gifDrawable) {
8589
@NonNull
8690
@Override

0 commit comments

Comments
 (0)