Fix j-latex-plugin background config
This commit is contained in:
parent
5c78f1d515
commit
6ed641fa47
@ -34,6 +34,14 @@ import ru.noties.jlatexmath.JLatexMathDrawable;
|
||||
*/
|
||||
public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
||||
|
||||
/**
|
||||
* @since 4.0.0-SNAPSHOT
|
||||
*/
|
||||
public interface BackgroundProvider {
|
||||
@NonNull
|
||||
Drawable provide();
|
||||
}
|
||||
|
||||
public interface BuilderConfigure {
|
||||
void configureBuilder(@NonNull Builder builder);
|
||||
}
|
||||
@ -64,7 +72,8 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
||||
|
||||
private final float textSize;
|
||||
|
||||
private final Drawable background;
|
||||
// @since 4.0.0-SNAPSHOT
|
||||
private final BackgroundProvider backgroundProvider;
|
||||
|
||||
@JLatexMathDrawable.Align
|
||||
private final int align;
|
||||
@ -78,7 +87,7 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
||||
|
||||
Config(@NonNull Builder builder) {
|
||||
this.textSize = builder.textSize;
|
||||
this.background = builder.background;
|
||||
this.backgroundProvider = builder.backgroundProvider;
|
||||
this.align = builder.align;
|
||||
this.fitCanvas = builder.fitCanvas;
|
||||
this.padding = builder.padding;
|
||||
@ -149,7 +158,8 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
||||
|
||||
private final float textSize;
|
||||
|
||||
private Drawable background;
|
||||
// @since 4.0.0-SNAPSHOT
|
||||
private BackgroundProvider backgroundProvider;
|
||||
|
||||
@JLatexMathDrawable.Align
|
||||
private int align = JLatexMathDrawable.ALIGN_CENTER;
|
||||
@ -166,8 +176,8 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Builder background(@NonNull Drawable background) {
|
||||
this.background = background;
|
||||
public Builder backgroundProvider(@NonNull BackgroundProvider backgroundProvider) {
|
||||
this.backgroundProvider = backgroundProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -236,7 +246,7 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
||||
final JLatexMathDrawable jLatexMathDrawable =
|
||||
JLatexMathDrawable.builder(drawable.getDestination())
|
||||
.textSize(config.textSize)
|
||||
.background(config.background)
|
||||
.background(config.backgroundProvider.provide())
|
||||
.align(config.align)
|
||||
.fitCanvas(config.fitCanvas)
|
||||
.padding(config.padding)
|
||||
|
@ -1,9 +1,12 @@
|
||||
package io.noties.markwon.sample.latex;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import io.noties.markwon.Markwon;
|
||||
@ -44,9 +47,40 @@ public class LatexActivity extends Activity {
|
||||
|
||||
final Markwon markwon = Markwon.builder(this)
|
||||
// .usePlugin(ImagesPlugin.create(this))
|
||||
.usePlugin(JLatexMathPlugin.create(textView.getTextSize()))
|
||||
.usePlugin(JLatexMathPlugin.create(textView.getTextSize(), new JLatexMathPlugin.BuilderConfigure() {
|
||||
@Override
|
||||
public void configureBuilder(@NonNull JLatexMathPlugin.Builder builder) {
|
||||
builder.backgroundProvider(new JLatexMathPlugin.BackgroundProvider() {
|
||||
@NonNull
|
||||
@Override
|
||||
public Drawable provide() {
|
||||
return new ColorDrawable(0x40ff0000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}))
|
||||
.build();
|
||||
|
||||
if (true) {
|
||||
final String l = "$$\n" +
|
||||
" P(X=r)=\\frac{\\lambda^r e^{-\\lambda}}{r!}\n" +
|
||||
"$$\n" +
|
||||
"\n" +
|
||||
"$$\n" +
|
||||
" P(X<r)=P(X<r-1)\n" +
|
||||
"$$\n" +
|
||||
"\n" +
|
||||
"$$\n" +
|
||||
" P(X>r)=1-P(X<r=1)\n" +
|
||||
"$$\n" +
|
||||
"\n" +
|
||||
"$$\n" +
|
||||
" \\text{Variance} = \\lambda\n" +
|
||||
"$$";
|
||||
markwon.setMarkdown(textView, l);
|
||||
return;
|
||||
}
|
||||
|
||||
markwon.setMarkdown(textView, markdown);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user