Merge branch 'v2.0.0' into jlatexmath
This commit is contained in:
commit
58ba009de0
@ -225,8 +225,18 @@ public class AsyncDrawableLoader implements AsyncDrawable.Loader {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@NonNull
|
||||
public Builder schemeHandler(@NonNull String scheme, @Nullable SchemeHandler schemeHandler) {
|
||||
schemeHandlers.put(scheme, schemeHandler);
|
||||
public Builder addSchemeHandler(@NonNull SchemeHandler schemeHandler) {
|
||||
|
||||
SchemeHandler previous;
|
||||
|
||||
for (String scheme : schemeHandler.schemes()) {
|
||||
previous = schemeHandlers.put(scheme, schemeHandler);
|
||||
if (previous != null) {
|
||||
throw new IllegalStateException(String.format("Multiple scheme handlers handle " +
|
||||
"the same scheme: `%s`, %s %s", scheme, previous, schemeHandler));
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -261,33 +271,13 @@ public class AsyncDrawableLoader implements AsyncDrawable.Loader {
|
||||
|
||||
// @since 2.0.0
|
||||
// put default scheme handlers (to mimic previous behavior)
|
||||
{
|
||||
|
||||
final boolean hasHttp = schemeHandlers.containsKey("http");
|
||||
final boolean hasHttps = schemeHandlers.containsKey("https");
|
||||
|
||||
if (!hasHttp || !hasHttps) {
|
||||
|
||||
if (client == null) {
|
||||
client = new OkHttpClient();
|
||||
}
|
||||
|
||||
final NetworkSchemeHandler handler = NetworkSchemeHandler.create(client);
|
||||
if (!hasHttp) {
|
||||
schemeHandlers.put("http", handler);
|
||||
}
|
||||
if (!hasHttps) {
|
||||
schemeHandlers.put("https", handler);
|
||||
}
|
||||
}
|
||||
|
||||
if (!schemeHandlers.containsKey("file")) {
|
||||
schemeHandlers.put("file", FileSchemeHandler.createWithAssets(resources.getAssets()));
|
||||
}
|
||||
|
||||
if (!schemeHandlers.containsKey("data")) {
|
||||
schemeHandlers.put("data", DataUriSchemeHandler.create());
|
||||
if (schemeHandlers.size() == 0) {
|
||||
if (client == null) {
|
||||
client = new OkHttpClient();
|
||||
}
|
||||
addSchemeHandler(NetworkSchemeHandler.create(client));
|
||||
addSchemeHandler(FileSchemeHandler.createWithAssets(resources.getAssets()));
|
||||
addSchemeHandler(DataUriSchemeHandler.create());
|
||||
}
|
||||
|
||||
// add default media decoders if not specified
|
||||
|
@ -6,6 +6,8 @@ import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
@ -57,4 +59,10 @@ public class DataUriSchemeHandler extends SchemeHandler {
|
||||
public void cancel(@NonNull String raw) {
|
||||
// no op
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Collection<String> schemes() {
|
||||
return Collections.singleton("data");
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -98,4 +100,10 @@ public class FileSchemeHandler extends SchemeHandler {
|
||||
public void cancel(@NonNull String raw) {
|
||||
// no op
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Collection<String> schemes() {
|
||||
return Collections.singleton("file");
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.Call;
|
||||
@ -78,4 +80,10 @@ public class NetworkSchemeHandler extends SchemeHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Collection<String> schemes() {
|
||||
return Arrays.asList("http", "https");
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ -13,4 +15,7 @@ public abstract class SchemeHandler {
|
||||
public abstract ImageItem handle(@NonNull String raw, @NonNull Uri uri);
|
||||
|
||||
public abstract void cancel(@NonNull String raw);
|
||||
|
||||
@NonNull
|
||||
public abstract Collection<String> schemes();
|
||||
}
|
||||
|
@ -4,11 +4,12 @@ import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Scanner;
|
||||
|
||||
import ru.noties.jlatexmath.JLatexMathDrawable;
|
||||
@ -36,13 +37,12 @@ public class JLatexMathMedia {
|
||||
}
|
||||
}
|
||||
|
||||
public static final String SCHEME = "jlatexmath";
|
||||
|
||||
@NonNull
|
||||
public static String makeDestination(@NonNull String latex) {
|
||||
return SCHEME + "://" + latex;
|
||||
}
|
||||
|
||||
private static final String SCHEME = "jlatexmath";
|
||||
private static final String CONTENT_TYPE = "text/jlatexmath";
|
||||
|
||||
private final Config config;
|
||||
@ -67,8 +67,6 @@ public class JLatexMathMedia {
|
||||
@Override
|
||||
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
||||
|
||||
Log.e("handle", raw);
|
||||
|
||||
ImageItem item = null;
|
||||
|
||||
try {
|
||||
@ -89,6 +87,12 @@ public class JLatexMathMedia {
|
||||
public void cancel(@NonNull String raw) {
|
||||
// no op
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Collection<String> schemes() {
|
||||
return Collections.singleton(SCHEME);
|
||||
}
|
||||
}
|
||||
|
||||
static class MediaDecoderImpl extends MediaDecoder {
|
||||
@ -118,15 +122,12 @@ public class JLatexMathMedia {
|
||||
? scanner.next()
|
||||
: null;
|
||||
|
||||
Log.e("decode", latex);
|
||||
|
||||
if (latex == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// todo: change to float
|
||||
return JLatexMathDrawable.builder(latex)
|
||||
.textSize((int) config.textSize)
|
||||
.textSize(config.textSize)
|
||||
.background(config.background)
|
||||
.align(config.align)
|
||||
.fitCanvas(config.fitCanvas)
|
||||
|
@ -2,7 +2,6 @@ package ru.noties.markwon.sample.jlatexmath;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.commonmark.node.CustomBlock;
|
||||
@ -10,7 +9,6 @@ import org.commonmark.node.Node;
|
||||
import org.commonmark.parser.Parser;
|
||||
|
||||
import ru.noties.jlatexmath.JLatexMathAndroid;
|
||||
import ru.noties.jlatexmath.JLatexMathDrawable;
|
||||
import ru.noties.markwon.Markwon;
|
||||
import ru.noties.markwon.SpannableBuilder;
|
||||
import ru.noties.markwon.SpannableConfiguration;
|
||||
@ -59,7 +57,7 @@ public class MainActivity extends Activity {
|
||||
final JLatexMathMedia jLatexMathMedia = new JLatexMathMedia(config);
|
||||
|
||||
final AsyncDrawableLoader asyncDrawableLoader = AsyncDrawableLoader.builder()
|
||||
.schemeHandler(JLatexMathMedia.SCHEME, jLatexMathMedia.schemeHandler())
|
||||
.addSchemeHandler(jLatexMathMedia.schemeHandler())
|
||||
.mediaDecoders(jLatexMathMedia.mediaDecoder())
|
||||
.build();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user