From 5c78f1d51541f4eeaae2a0d5f20e0e635922213a Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Wed, 19 Jun 2019 00:28:22 +0300 Subject: [PATCH] Image, apply bounds for result drawable if empty --- .../noties/markwon/app/MarkdownRenderer.java | 29 ------------------- docs/docs/v4/image/README.md | 3 -- docs/docs/v4/migration-3-4.md | 3 ++ docs/docs/v4/recipes.md | 2 +- .../image/AsyncDrawableLoaderImpl.java | 6 ++++ .../markwon/image/DefaultMediaDecoder.java | 4 +-- .../markwon/image/gif/GifMediaDecoder.java | 2 -- .../markwon/image/svg/SvgMediaDecoder.java | 5 +--- 8 files changed, 12 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/io/noties/markwon/app/MarkdownRenderer.java b/app/src/main/java/io/noties/markwon/app/MarkdownRenderer.java index 67585f85..9bcb8e0f 100644 --- a/app/src/main/java/io/noties/markwon/app/MarkdownRenderer.java +++ b/app/src/main/java/io/noties/markwon/app/MarkdownRenderer.java @@ -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() { - @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 supportedTypes() { - return null; - } - }); - } - }); - } - }) .build(); final long start = SystemClock.uptimeMillis(); diff --git a/docs/docs/v4/image/README.md b/docs/docs/v4/image/README.md index b618f999..bee67c00 100644 --- a/docs/docs/v4/image/README.md +++ b/docs/docs/v4/image/README.md @@ -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); } diff --git a/docs/docs/v4/migration-3-4.md b/docs/docs/v4/migration-3-4.md index 5537e1e2..f36cf75a 100644 --- a/docs/docs/v4/migration-3-4.md +++ b/docs/docs/v4/migration-3-4.md @@ -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 \ No newline at end of file diff --git a/docs/docs/v4/recipes.md b/docs/docs/v4/recipes.md index 46e9d86c..c9aad1cb 100644 --- a/docs/docs/v4/recipes.md +++ b/docs/docs/v4/recipes.md @@ -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) diff --git a/markwon-image/src/main/java/io/noties/markwon/image/AsyncDrawableLoaderImpl.java b/markwon-image/src/main/java/io/noties/markwon/image/AsyncDrawableLoaderImpl.java index 52afc7a3..a88a69e1 100644 --- a/markwon-image/src/main/java/io/noties/markwon/image/AsyncDrawableLoaderImpl.java +++ b/markwon-image/src/main/java/io/noties/markwon/image/AsyncDrawableLoaderImpl.java @@ -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() { diff --git a/markwon-image/src/main/java/io/noties/markwon/image/DefaultMediaDecoder.java b/markwon-image/src/main/java/io/noties/markwon/image/DefaultMediaDecoder.java index bdf81e05..0fc18824 100644 --- a/markwon-image/src/main/java/io/noties/markwon/image/DefaultMediaDecoder.java +++ b/markwon-image/src/main/java/io/noties/markwon/image/DefaultMediaDecoder.java @@ -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 diff --git a/markwon-image/src/main/java/io/noties/markwon/image/gif/GifMediaDecoder.java b/markwon-image/src/main/java/io/noties/markwon/image/gif/GifMediaDecoder.java index 923fc113..479815f4 100644 --- a/markwon-image/src/main/java/io/noties/markwon/image/gif/GifMediaDecoder.java +++ b/markwon-image/src/main/java/io/noties/markwon/image/gif/GifMediaDecoder.java @@ -65,8 +65,6 @@ public class GifMediaDecoder extends MediaDecoder { throw new IllegalStateException("Exception creating GifDrawable", e); } - DrawableUtils.applyIntrinsicBounds(drawable); - if (!autoPlayGif) { drawable.pause(); } diff --git a/markwon-image/src/main/java/io/noties/markwon/image/svg/SvgMediaDecoder.java b/markwon-image/src/main/java/io/noties/markwon/image/svg/SvgMediaDecoder.java index eb4cb74c..848cc82e 100644 --- a/markwon-image/src/main/java/io/noties/markwon/image/svg/SvgMediaDecoder.java +++ b/markwon-image/src/main/java/io/noties/markwon/image/svg/SvgMediaDecoder.java @@ -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