From b1a0f3b73954271e592caa7bdac5ffd625817588 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Thu, 28 May 2020 13:13:53 +0300 Subject: [PATCH] hasExplicitMovementMethodPlugin sample --- CHANGELOG.md | 2 +- .../markwon/sample/core/CoreActivity.java | 51 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e70a3462..0a2e0856 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ #### Added * `core` - `MovementMethodPlugin.none()`, `MovementMethodPlugin.link()` factory methods -* `core` - `CorePlugin` `hasExplicitMovementMethodPlugin` configuration method to **not** add implicit `LinkMovementMethod` on `afterSetText` +* `core` - `CorePlugin` `hasExplicitMovementMethodPlugin` configuration method to **not** add implicit `LinkMovementMethod` in `afterSetText` #### Changed * `html` - `SimpleTagHandler` visits children tags if supplied tag is block one ([#235]) diff --git a/sample/src/main/java/io/noties/markwon/sample/core/CoreActivity.java b/sample/src/main/java/io/noties/markwon/sample/core/CoreActivity.java index 7ce59464..c191a59e 100644 --- a/sample/src/main/java/io/noties/markwon/sample/core/CoreActivity.java +++ b/sample/src/main/java/io/noties/markwon/sample/core/CoreActivity.java @@ -18,6 +18,7 @@ import java.util.Set; import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.core.CorePlugin; +import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.sample.ActivityWithMenuOptions; import io.noties.markwon.sample.MenuOptions; import io.noties.markwon.sample.R; @@ -33,7 +34,10 @@ public class CoreActivity extends ActivityWithMenuOptions { .add("simple", this::simple) .add("toast", this::toast) .add("alreadyParsed", this::alreadyParsed) - .add("enabledBlockTypes", this::enabledBlockTypes); + .add("enabledBlockTypes", this::enabledBlockTypes) + .add("implicitMovementMethod", this::implicitMovementMethod) + .add("explicitMovementMethod", this::explicitMovementMethod) + .add("explicitMovementMethodPlugin", this::explicitMovementMethodPlugin); } @Override @@ -163,4 +167,49 @@ public class CoreActivity extends ActivityWithMenuOptions { markwon.setMarkdown(textView, md); } + + private void implicitMovementMethod() { + // by default a LinkMovementMethod is applied automatically, so links are clickable + + final String md = "[0 link](#) here"; + + final Markwon markwon = Markwon.create(this); + + markwon.setMarkdown(textView, md); + } + + private void explicitMovementMethod() { + // NB! as movement method is set from other methods we _explicitly_ clear it + textView.setMovementMethod(null); + + // by default Markwon will set a LinkMovementMethod on a TextView if it is missing + // to control that `hasExplicitMovementMethodPlugin` can be used + final String md = "[1 link](#) here"; + + final Markwon markwon = Markwon.builder(this) + .usePlugin(new AbstractMarkwonPlugin() { + @Override + public void configure(@NonNull Registry registry) { + // Markwon **won't** set implicit movement method + // thus making the link in markdown input not clickable + registry.require(CorePlugin.class) + .hasExplicitMovementMethodPlugin(true); + } + }) + .build(); + + markwon.setMarkdown(textView, md); + } + + private void explicitMovementMethodPlugin() { + // additionally special MovementMethodPlugin.none() can be used to control `hasExplicitMovementMethodPlugin` + + final String md = "[2 link](#) here"; + + final Markwon markwon = Markwon.builder(this) + .usePlugin(MovementMethodPlugin.none()) + .build(); + + markwon.setMarkdown(textView, md); + } }