Update sample application

This commit is contained in:
Dimitry Ivanov 2020-02-26 17:18:42 +03:00
parent f61e0b7b20
commit 8da8a37178
6 changed files with 119 additions and 88 deletions

View File

@ -1,5 +1,8 @@
# Changelog
# 4.3.0-SNAPSHOT
# 4.2.2
* Fixed `AsyncDrawable` display when it has placeholder with empty bounds ([#189])
* Fixed `syntax-highlight` where code input is empty string ([#192])

View File

@ -8,7 +8,7 @@ android.enableJetifier=true
android.enableBuildCache=true
android.buildCacheDir=build/pre-dex-cache
VERSION_NAME=4.2.2
VERSION_NAME=4.3.0-SNAPSHOT
GROUP=io.noties.markwon
POM_DESCRIPTION=Markwon markdown for Android

View File

@ -1,12 +1,9 @@
package io.noties.markwon.sample.basicplugins;
import android.app.Activity;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.Layout;
import android.text.TextUtils;
import android.text.style.AlignmentSpan;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;
@ -22,56 +19,56 @@ import java.util.Collections;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.MarkwonSpansFactory;
import io.noties.markwon.MarkwonVisitor;
import io.noties.markwon.RenderProps;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.html.HtmlPlugin;
import io.noties.markwon.html.HtmlTag;
import io.noties.markwon.html.tag.SimpleTagHandler;
import io.noties.markwon.image.ImageItem;
import io.noties.markwon.image.ImagesPlugin;
import io.noties.markwon.image.SchemeHandler;
import io.noties.markwon.image.network.NetworkSchemeHandler;
import io.noties.markwon.movement.MovementMethodPlugin;
import io.noties.markwon.sample.ActivityWithMenuOptions;
import io.noties.markwon.sample.MenuOptions;
import io.noties.markwon.sample.R;
public class BasicPluginsActivity extends Activity {
public class BasicPluginsActivity extends ActivityWithMenuOptions {
private TextView textView;
@NonNull
@Override
public MenuOptions menuOptions() {
return MenuOptions.create()
.add("paragraphSpan", this::paragraphSpan)
.add("disableNode", this::disableNode)
.add("linkWithMovementMethod", this::linkWithMovementMethod)
.add("imagesPlugin", this::imagesPlugin);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_view);
textView = new TextView(this);
setContentView(textView);
textView = findViewById(R.id.text_view);
step_1();
step_2();
step_3();
step_4();
step_5();
step_6();
paragraphSpan();
//
// disableNode();
//
// customizeTheme();
//
// linkWithMovementMethod();
//
// imagesPlugin();
}
/**
* In order to apply paragraph spans a custom plugin should be created (CorePlugin will take care
* of everything else).
* <p>
* Please note that when a plugin is registered and it <em>depends</em> on CorePlugin, there is no
* need to explicitly specify it. By default all plugins that extend AbstractMarkwonPlugin do declare
* it\'s dependency on CorePlugin ({@link MarkwonPlugin#priority()}).
* <p>
* Order in which plugins are specified to the builder is of little importance as long as each
* plugin clearly states what dependencies it has
*/
private void step_1() {
private void paragraphSpan() {
final String markdown = "# Hello!\n\nA paragraph?\n\nIt should be!";
@ -91,7 +88,7 @@ public class BasicPluginsActivity extends Activity {
/**
* To disable some nodes from rendering another custom plugin can be used
*/
private void step_2() {
private void disableNode() {
final String markdown = "# Heading 1\n\n## Heading 2\n\n**other** content [here](#)";
@ -116,7 +113,7 @@ public class BasicPluginsActivity extends Activity {
/**
* To customize core theme plugin can be used again
*/
private void step_3() {
private void customizeTheme() {
final String markdown = "`A code` that is rendered differently\n\n```\nHello!\n```";
@ -145,7 +142,7 @@ public class BasicPluginsActivity extends Activity {
* <p>
* In order to customize them a custom plugin should be used
*/
private void step_4() {
private void linkWithMovementMethod() {
final String markdown = "[a link without scheme](github.com)";
@ -178,7 +175,7 @@ public class BasicPluginsActivity extends Activity {
* images handling (parsing markdown containing images, obtain an image from network
* file system or assets). Please note that
*/
private void step_5() {
private void imagesPlugin() {
final String markdown = "![image](myownscheme://en.wikipedia.org/static/images/project-logos/enwiki-2x.png)";
@ -220,29 +217,29 @@ public class BasicPluginsActivity extends Activity {
markwon.setMarkdown(textView, markdown);
}
public void step_6() {
final Markwon markwon = Markwon.builder(this)
.usePlugin(HtmlPlugin.create())
.usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configure(@NonNull Registry registry) {
registry.require(HtmlPlugin.class, plugin -> plugin.addHandler(new SimpleTagHandler() {
@Override
public Object getSpans(@NonNull MarkwonConfiguration configuration, @NonNull RenderProps renderProps, @NonNull HtmlTag tag) {
return new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
}
@NonNull
@Override
public Collection<String> supportedTags() {
return Collections.singleton("center");
}
}));
}
})
.build();
}
// public void step_6() {
//
// final Markwon markwon = Markwon.builder(this)
// .usePlugin(HtmlPlugin.create())
// .usePlugin(new AbstractMarkwonPlugin() {
// @Override
// public void configure(@NonNull Registry registry) {
// registry.require(HtmlPlugin.class, plugin -> plugin.addHandler(new SimpleTagHandler() {
// @Override
// public Object getSpans(@NonNull MarkwonConfiguration configuration, @NonNull RenderProps renderProps, @NonNull HtmlTag tag) {
// return new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
// }
//
// @NonNull
// @Override
// public Collection<String> supportedTags() {
// return Collections.singleton("center");
// }
// }));
// }
// })
// .build();
// }
// text lifecycle (after/before)
// rendering lifecycle (before/after)

View File

@ -1,36 +1,48 @@
package io.noties.markwon.sample.core;
import android.app.Activity;
import android.os.Bundle;
import android.text.Spanned;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.commonmark.node.Node;
import io.noties.markwon.Markwon;
import io.noties.markwon.core.CorePlugin;
import io.noties.markwon.sample.ActivityWithMenuOptions;
import io.noties.markwon.sample.MenuOptions;
import io.noties.markwon.sample.R;
public class CoreActivity extends Activity {
public class CoreActivity extends ActivityWithMenuOptions {
private TextView textView;
@NonNull
@Override
public MenuOptions menuOptions() {
return MenuOptions.create()
.add("simple", this::simple)
.add("toast", this::toast)
.add("alreadyParsed", this::alreadyParsed);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_view);
textView = new TextView(this);
setContentView(textView);
textView = findViewById(R.id.text_view);
step_1();
// step_1();
step_2();
simple();
step_3();
step_4();
// toast();
//
// alreadyParsed();
}
/**
@ -70,7 +82,7 @@ public class CoreActivity extends Activity {
/**
* To simply apply raw (non-parsed) markdown call {@link Markwon#setMarkdown(TextView, String)}
*/
private void step_2() {
private void simple() {
// this is raw markdown
final String markdown = "Hello **markdown**!";
@ -91,7 +103,7 @@ public class CoreActivity extends Activity {
* of invalidation. But if a Toast for example is created with a custom view
* ({@code new Toast(this).setView(...) }) and has access to a TextView everything <em>should</em> work.
*/
private void step_3() {
private void toast() {
final String markdown = "*Toast* __here__!\n\n> And a quote!";
@ -105,7 +117,7 @@ public class CoreActivity extends Activity {
/**
* To apply already parsed markdown use {@link Markwon#setParsedMarkdown(TextView, Spanned)}
*/
private void step_4() {
private void alreadyParsed() {
final String markdown = "This **is** pre-parsed [markdown](#)";

View File

@ -1,6 +1,5 @@
package io.noties.markwon.sample.customextension2;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
@ -25,34 +24,45 @@ import io.noties.markwon.core.CorePlugin;
import io.noties.markwon.core.CoreProps;
import io.noties.markwon.inlineparser.InlineProcessor;
import io.noties.markwon.inlineparser.MarkwonInlineParser;
import io.noties.markwon.sample.ActivityWithMenuOptions;
import io.noties.markwon.sample.MenuOptions;
import io.noties.markwon.sample.R;
public class CustomExtensionActivity2 extends Activity {
public class CustomExtensionActivity2 extends ActivityWithMenuOptions {
private static final String MD = "" +
"# Custom Extension 2\n" +
"\n" +
"This is an issue #1\n" +
"Done by @noties";
private TextView textView;
@NonNull
@Override
public MenuOptions menuOptions() {
return MenuOptions.create()
.add("text_added", this::text_added)
.add("inline_parsing", this::inline_parsing);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_view);
final TextView textView = findViewById(R.id.text_view);
textView = findViewById(R.id.text_view);
// let's look for github special links:
// * `#1` - an issue or a pull request
// * `@user` link to a user
final String md = "# Custom Extension 2\n" +
"\n" +
"This is an issue #1\n" +
"Done by @noties";
// inline_parsing(textView, md);
text_added(textView, md);
text_added();
}
private void text_added(@NonNull TextView textView, @NonNull String md) {
private void text_added() {
final Markwon markwon = Markwon.builder(this)
.usePlugin(new AbstractMarkwonPlugin() {
@ -64,10 +74,10 @@ public class CustomExtensionActivity2 extends Activity {
})
.build();
markwon.setMarkdown(textView, md);
markwon.setMarkdown(textView, MD);
}
private void inline_parsing(@NonNull TextView textView, @NonNull String md) {
private void inline_parsing() {
final InlineParserFactory inlineParserFactory = MarkwonInlineParser.factoryBuilder()
// include all current defaults (otherwise will be empty - contain only our inline-processors)
@ -86,7 +96,7 @@ public class CustomExtensionActivity2 extends Activity {
})
.build();
markwon.setMarkdown(textView, md);
markwon.setMarkdown(textView, MD);
}
private static class IssueInlineProcessor extends InlineProcessor {

View File

@ -1,6 +1,5 @@
package io.noties.markwon.sample.inlineparser;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
@ -26,18 +25,28 @@ import io.noties.markwon.inlineparser.BackticksInlineProcessor;
import io.noties.markwon.inlineparser.CloseBracketInlineProcessor;
import io.noties.markwon.inlineparser.MarkwonInlineParser;
import io.noties.markwon.inlineparser.OpenBracketInlineProcessor;
import io.noties.markwon.sample.ActivityWithMenuOptions;
import io.noties.markwon.sample.MenuOptions;
import io.noties.markwon.sample.R;
public class InlineParserActivity extends Activity {
public class InlineParserActivity extends ActivityWithMenuOptions {
private TextView textView;
@NonNull
@Override
public MenuOptions menuOptions() {
return MenuOptions.create()
.add("links_only", this::links_only)
.add("disable_code", this::disable_code);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_view);
this.textView = findViewById(R.id.text_view);
textView = findViewById(R.id.text_view);
// links_only();