diff --git a/app/src/main/java/ru/noties/markwon/MainActivity.java b/app/src/main/java/ru/noties/markwon/MainActivity.java index 4397f6bf..943a1594 100644 --- a/app/src/main/java/ru/noties/markwon/MainActivity.java +++ b/app/src/main/java/ru/noties/markwon/MainActivity.java @@ -1,8 +1,11 @@ package ru.noties.markwon; import android.app.Activity; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.SystemClock; +import android.text.SpannableStringBuilder; +import android.text.Spanned; import android.text.method.LinkMovementMethod; import android.widget.TextView; @@ -18,6 +21,7 @@ import java.util.Scanner; import ru.noties.debug.AndroidLogDebugOutput; import ru.noties.debug.Debug; import ru.noties.markwon.renderer.*; +import ru.noties.markwon.spans.DrawableSpan; import ru.noties.markwon.spans.DrawableSpanUtils; public class MainActivity extends Activity { @@ -33,6 +37,21 @@ public class MainActivity extends Activity { final TextView textView = (TextView) findViewById(R.id.activity_main); +// final Drawable drawable = getDrawable(R.mipmap.ic_launcher); +//// drawable.setBounds(0, 0, 16, 16); +// final SpannableStringBuilder builder = new SpannableStringBuilder(); +// for (int i = 0; i < 10; i++) { +// builder.append("text here and icon: \u00a0"); +// //noinspection WrongConstant +// builder.setSpan(new DrawableSpan(drawable, i % 3), builder.length() - 1, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); +// builder.append('\n'); +// } +// textView.setText(builder); +// +// if (true) { +// return; +// } + new Thread(new Runnable() { @Override public void run() { diff --git a/library-renderer/src/main/java/ru/noties/markwon/renderer/SpannableConfiguration.java b/library-renderer/src/main/java/ru/noties/markwon/renderer/SpannableConfiguration.java index 58a0225b..aae01933 100644 --- a/library-renderer/src/main/java/ru/noties/markwon/renderer/SpannableConfiguration.java +++ b/library-renderer/src/main/java/ru/noties/markwon/renderer/SpannableConfiguration.java @@ -107,6 +107,7 @@ public class SpannableConfiguration { // todo, change to something more reliable // todo, must mention that bullet/ordered/quote must have the same margin (or maybe we can just enforce it?) + // actually it does make sense to have `blockQuote` & `list` margins (if they are different) public SpannableConfiguration build() { if (blockQuoteConfig == null) { blockQuoteConfig = new BlockQuoteSpan.Config( diff --git a/library-spans/src/main/java/ru/noties/markwon/spans/DrawableSpan.java b/library-spans/src/main/java/ru/noties/markwon/spans/DrawableSpan.java index 8c065099..5e9205dc 100644 --- a/library-spans/src/main/java/ru/noties/markwon/spans/DrawableSpan.java +++ b/library-spans/src/main/java/ru/noties/markwon/spans/DrawableSpan.java @@ -18,7 +18,7 @@ public class DrawableSpan extends ReplacementSpan { public static final int ALIGN_BOTTOM = 0; public static final int ALIGN_BASELINE = 1; - public static final int ALIGN_CENTER = 2; + public static final int ALIGN_CENTER = 2; // will only center if drawable height is less than text line height private final Drawable drawable; private final int alignment; @@ -79,7 +79,7 @@ public class DrawableSpan extends ReplacementSpan { try { final int translationY; if (ALIGN_CENTER == alignment) { - translationY = (int) (b / 2.F + .5F); + translationY = b - ((bottom - top - drawable.getBounds().height()) / 2); } else if (ALIGN_BASELINE == alignment) { translationY = b - paint.getFontMetricsInt().descent; } else {