Image, apply bounds for result drawable if empty

This commit is contained in:
Dimitry Ivanov 2019-06-19 00:28:22 +03:00
parent a3ebae3b87
commit 5c78f1d515
8 changed files with 12 additions and 42 deletions

View File

@ -1,7 +1,6 @@
package io.noties.markwon.app;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Handler;
import android.os.SystemClock;
@ -10,8 +9,6 @@ import android.text.Spanned;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.InputStream;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@ -26,10 +23,7 @@ import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
import io.noties.markwon.ext.tables.TablePlugin;
import io.noties.markwon.ext.tasklist.TaskListPlugin;
import io.noties.markwon.html.HtmlPlugin;
import io.noties.markwon.image.ImageItem;
import io.noties.markwon.image.ImagesPlugin;
import io.noties.markwon.image.MediaDecoder;
import io.noties.markwon.image.SchemeHandler;
import io.noties.markwon.image.file.FileSchemeHandler;
import io.noties.markwon.image.network.OkHttpNetworkSchemeHandler;
import io.noties.markwon.syntax.Prism4jTheme;
@ -126,29 +120,6 @@ public class MarkdownRenderer {
builder.urlProcessor(urlProcessor);
}
})
.usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configure(@NonNull Registry registry) {
registry.require(ImagesPlugin.class, new Action<ImagesPlugin>() {
@Override
public void apply(@NonNull ImagesPlugin imagesPlugin) {
imagesPlugin.addMediaDecoder(new MediaDecoder() {
@NonNull
@Override
public Drawable decode(@Nullable String contentType, @NonNull InputStream inputStream) {
return null;
}
@NonNull
@Override
public Collection<String> supportedTypes() {
return null;
}
});
}
});
}
})
.build();
final long start = SystemClock.uptimeMillis();

View File

@ -145,9 +145,6 @@ final Markwon markwon = Markwon.builder(context)
// it's fine if it throws, async-image-loader will catch exception
final Drawable drawable = context.getDrawable(resourceId);
// it's important to apply bounds to resulting drawable
DrawableUtils.applyIntrinsicBounds(drawable);
return ImageItem.withResult(drawable);
}

View File

@ -1,3 +1,6 @@
# Migration 3.x.x -> 4.x.x
* maven group-id is changed: `io.noties.markwon` (was `ru.noties.markwon`)
* root package-name is changed: `io.noties.markwon` (was `ru.noties.markwon`)
todo

View File

@ -15,7 +15,7 @@ textView.setSpannableFactory(NoCopySpannableFactory.getInstance());
## Autolink
Do not use `autolink` XML attribute on your `TextView` as it will remove all links except autolinked ones.
Consider using [linkify plugin](/docs/v4/linkify.md) or commonmark-java [autolink extension](https://github.com/atlassian/commonmark-java)
Consider using [linkify plugin](/docs/v4/linkify/) or commonmark-java [autolink extension](https://github.com/atlassian/commonmark-java)

View File

@ -143,6 +143,12 @@ class AsyncDrawableLoaderImpl extends AsyncDrawableLoader {
final Drawable out = drawable;
// @since 4.0.0-SNAPSHOT apply intrinsic bounds (but only if they are empty)
if (out != null
&& out.getBounds().isEmpty()) {
DrawableUtils.applyIntrinsicBounds(out);
}
handler.postAtTime(new Runnable() {
@Override
public void run() {

View File

@ -50,9 +50,7 @@ public class DefaultMediaDecoder extends MediaDecoder {
throw new IllegalStateException("Exception decoding input-stream", t);
}
final Drawable drawable = new BitmapDrawable(resources, bitmap);
DrawableUtils.applyIntrinsicBounds(drawable);
return drawable;
return new BitmapDrawable(resources, bitmap);
}
@NonNull

View File

@ -65,8 +65,6 @@ public class GifMediaDecoder extends MediaDecoder {
throw new IllegalStateException("Exception creating GifDrawable", e);
}
DrawableUtils.applyIntrinsicBounds(drawable);
if (!autoPlayGif) {
drawable.pause();
}

View File

@ -16,7 +16,6 @@ import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import io.noties.markwon.image.DrawableUtils;
import io.noties.markwon.image.MediaDecoder;
/**
@ -73,9 +72,7 @@ public class SvgMediaDecoder extends MediaDecoder {
canvas.scale(density, density);
svg.renderToCanvas(canvas);
final Drawable drawable = new BitmapDrawable(resources, bitmap);
DrawableUtils.applyIntrinsicBounds(drawable);
return drawable;
return new BitmapDrawable(resources, bitmap);
}
@NonNull