Search in sources :

Example 1 with MDSection

use of im.actor.runtime.markdown.MDSection in project actor-platform by actorapp.

the class AndroidMarkdown method processText.

private static Spannable processText(String markdown, int mode) {
    MDDocument doc = new MarkdownParser(mode).processDocument(markdown);
    SpannableStringBuilder builder = new SpannableStringBuilder();
    boolean isFirst = true;
    for (MDSection s : doc.getSections()) {
        if (isFirst) {
            isFirst = false;
        } else {
            builder.append("\n");
        }
        if (s.getType() == MDSection.TYPE_CODE) {
            int start = builder.length();
            builder.append("View Source Code");
            final String text = s.getCode().getCode();
            builder.setSpan(new RelativeSizeSpan(1.1f), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(Color.RED), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.setSpan(new ClickableSpan() {

                @Override
                public void onClick(View view) {
                    AndroidContext.getContext().startActivity(new Intent(AndroidContext.getContext(), CodePreviewActivity.class).putExtra("source_code", text).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                }
            }, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (s.getType() == MDSection.TYPE_TEXT) {
            writeText(s.getText(), builder);
        } else {
            throw new RuntimeException("Unknown section type: " + s.getType());
        }
    }
    return builder;
}
Also used : MDSection(im.actor.runtime.markdown.MDSection) ForegroundColorSpan(android.text.style.ForegroundColorSpan) MDDocument(im.actor.runtime.markdown.MDDocument) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RelativeSizeSpan(android.text.style.RelativeSizeSpan) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) MarkdownParser(im.actor.runtime.markdown.MarkdownParser) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ClickableSpan (android.text.style.ClickableSpan)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 RelativeSizeSpan (android.text.style.RelativeSizeSpan)1 View (android.view.View)1 MDDocument (im.actor.runtime.markdown.MDDocument)1 MDSection (im.actor.runtime.markdown.MDSection)1 MarkdownParser (im.actor.runtime.markdown.MarkdownParser)1