use of im.actor.runtime.markdown.MDRawText in project actor-platform by actorapp.
the class AndroidMarkdown method writeText.
private static void writeText(MDText[] texts, SpannableStringBuilder builder) {
for (MDText text : texts) {
if (text instanceof MDRawText) {
builder.append(((MDRawText) text).getRawText());
} else if (text instanceof MDSpan) {
MDSpan span = (MDSpan) text;
int start = builder.length();
writeText(span.getChild(), builder);
Object spanObj;
if (span.getSpanType() == MDSpan.TYPE_BOLD) {
spanObj = new StyleSpan(Typeface.BOLD);
} else {
spanObj = new StyleSpan(Typeface.ITALIC);
}
builder.setSpan(spanObj, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (text instanceof MDUrl) {
final MDUrl url = (MDUrl) text;
int start = builder.length();
builder.append(url.getUrlTitle());
builder.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
Context ctx = view.getContext();
if (url.getUrl().startsWith("send:") && view.getTag(R.id.peer) != null && view.getTag(R.id.peer) instanceof Peer) {
ActorSDK.sharedActor().getMessenger().sendMessage((Peer) view.getTag(R.id.peer), url.getUrl().replaceFirst("send:", ""));
} else {
Intent intent = buildChromeIntent().intent;
intent.setData(Uri.parse(url.getUrl()));
if (intent.resolveActivity(ctx.getPackageManager()) != null) {
ctx.startActivity(intent);
} else {
intent.setData(Uri.parse("http://" + url.getUrl()));
if (intent.resolveActivity(ctx.getPackageManager()) != null) {
ctx.startActivity(intent);
} else {
Toast.makeText(view.getContext(), "Unknown URL type", Toast.LENGTH_SHORT).show();
}
}
}
}
}, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
throw new RuntimeException("Unknown text type: " + text);
}
}
}
Aggregations