diff --git a/markwon-image/src/main/java/io/noties/markwon/image/AsyncDrawableLoaderBuilder.java b/markwon-image/src/main/java/io/noties/markwon/image/AsyncDrawableLoaderBuilder.java index 731aa449..704ebffb 100644 --- a/markwon-image/src/main/java/io/noties/markwon/image/AsyncDrawableLoaderBuilder.java +++ b/markwon-image/src/main/java/io/noties/markwon/image/AsyncDrawableLoaderBuilder.java @@ -10,8 +10,10 @@ import java.util.concurrent.Executors; import io.noties.markwon.image.data.DataUriSchemeHandler; import io.noties.markwon.image.gif.GifMediaDecoder; +import io.noties.markwon.image.gif.GifSupport; import io.noties.markwon.image.network.NetworkSchemeHandler; import io.noties.markwon.image.svg.SvgMediaDecoder; +import io.noties.markwon.image.svg.SvgSupport; class AsyncDrawableLoaderBuilder { @@ -33,11 +35,11 @@ class AsyncDrawableLoaderBuilder { addSchemeHandler(NetworkSchemeHandler.create()); // add SVG and GIF, but only if they are present in the class-path - if (SvgMediaDecoder.available()) { + if (SvgSupport.hasSvgSupport()) { addMediaDecoder(SvgMediaDecoder.create()); } - if (GifMediaDecoder.available()) { + if (GifSupport.hasGifSupport()) { addMediaDecoder(GifMediaDecoder.create()); } 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 335cbb71..923fc113 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 @@ -1,6 +1,7 @@ package io.noties.markwon.image.gif; import android.graphics.drawable.Drawable; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -37,21 +38,13 @@ public class GifMediaDecoder extends MediaDecoder { return new GifMediaDecoder(autoPlayGif); } - /** - * @return boolean indicating if GIF dependency is satisfied - * @since 4.0.0-SNAPSHOT - */ - public static boolean available() { - return Holder.HAS_GIF; - } - private final boolean autoPlayGif; protected GifMediaDecoder(boolean autoPlayGif) { this.autoPlayGif = autoPlayGif; // @since 4.0.0-SNAPSHOT - Holder.validate(); + validate(); } @NonNull @@ -104,28 +97,11 @@ public class GifMediaDecoder extends MediaDecoder { return outputStream.toByteArray(); } - // @since 4.0.0-SNAPSHOT - private static class Holder { - - private static final boolean HAS_GIF; - - static { - boolean result = true; - try { - pl.droidsonroids.gif.GifDrawable.class.getName(); - } catch (Throwable t) { - result = false; - t.printStackTrace(); - } - HAS_GIF = result; - } - - static void validate() { - if (!HAS_GIF) { - throw new IllegalStateException("`pl.droidsonroids.gif:android-gif-drawable:*` " + - "dependency is missing, please add to your project explicitly if you " + - "wish to use GIF media decoder"); - } + private static void validate() { + if (!GifSupport.hasGifSupport()) { + throw new IllegalStateException("`pl.droidsonroids.gif:android-gif-drawable:*` " + + "dependency is missing, please add to your project explicitly if you " + + "wish to use GIF media decoder"); } } } diff --git a/markwon-image/src/main/java/io/noties/markwon/image/gif/GifSupport.java b/markwon-image/src/main/java/io/noties/markwon/image/gif/GifSupport.java new file mode 100644 index 00000000..3e996d45 --- /dev/null +++ b/markwon-image/src/main/java/io/noties/markwon/image/gif/GifSupport.java @@ -0,0 +1,28 @@ +package io.noties.markwon.image.gif; + +/** + * @since 4.0.0-SNAPSHOT + */ +public abstract class GifSupport { + + private static boolean HAS_GIF; + + static { + boolean result; + try { + pl.droidsonroids.gif.GifDrawable.class.getName(); + result = true; + } catch (Throwable t) { + t.printStackTrace(); + result = false; + } + HAS_GIF = result; + } + + public static boolean hasGifSupport() { + return HAS_GIF; + } + + private GifSupport() { + } +} 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 9e58d1e7..eb4cb74c 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 @@ -5,6 +5,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -39,14 +40,6 @@ public class SvgMediaDecoder extends MediaDecoder { return new SvgMediaDecoder(resources); } - /** - * @return boolean indicating if SVG dependency is satisfied - * @since 4.0.0-SNAPSHOT - */ - public static boolean available() { - return Holder.HAS_SVG; - } - private final Resources resources; @SuppressWarnings("WeakerAccess") @@ -54,7 +47,7 @@ public class SvgMediaDecoder extends MediaDecoder { this.resources = resources; // @since 4.0.0-SNAPSHOT - Holder.validate(); + validate(); } @NonNull @@ -91,27 +84,10 @@ public class SvgMediaDecoder extends MediaDecoder { return Collections.singleton(CONTENT_TYPE); } - // @since 4.0.0-SNAPSHOT - private static class Holder { - - private static final boolean HAS_SVG; - - static { - boolean result = true; - try { - com.caverock.androidsvg.SVG.class.getName(); - } catch (Throwable t) { - result = false; - t.printStackTrace(); - } - HAS_SVG = result; - } - - static void validate() { - if (!HAS_SVG) { - throw new IllegalStateException("`com.caverock:androidsvg:*` dependency is missing, " + - "please add to your project explicitly if you wish to use SVG media decoder"); - } + private static void validate() { + if (!SvgSupport.hasSvgSupport()) { + throw new IllegalStateException("`com.caverock:androidsvg:*` dependency is missing, " + + "please add to your project explicitly if you wish to use SVG media decoder"); } } } diff --git a/markwon-image/src/main/java/io/noties/markwon/image/svg/SvgSupport.java b/markwon-image/src/main/java/io/noties/markwon/image/svg/SvgSupport.java new file mode 100644 index 00000000..7ed0ce46 --- /dev/null +++ b/markwon-image/src/main/java/io/noties/markwon/image/svg/SvgSupport.java @@ -0,0 +1,28 @@ +package io.noties.markwon.image.svg; + +/** + * @since 4.0.0-SNAPSHOT + */ +public abstract class SvgSupport { + + private static final boolean HAS_SVG; + + static { + boolean result; + try { + com.caverock.androidsvg.SVG.class.getName(); + result = true; + } catch (Throwable t) { + t.printStackTrace(); + result = false; + } + HAS_SVG = result; + } + + public static boolean hasSvgSupport() { + return HAS_SVG; + } + + private SvgSupport() { + } +}