use of android.text.style.ClickableSpan 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);
}
}
}
use of android.text.style.ClickableSpan in project platform_frameworks_base by android.
the class TextView method onResolvePointerIcon.
@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
if (mText instanceof Spannable && mLinksClickable) {
final float x = event.getX(pointerIndex);
final float y = event.getY(pointerIndex);
final int offset = getOffsetForPosition(x, y);
final ClickableSpan[] clickables = ((Spannable) mText).getSpans(offset, offset, ClickableSpan.class);
if (clickables.length > 0) {
return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_HAND);
}
}
if (isTextSelectable() || isTextEditable()) {
return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_TEXT);
}
return super.onResolvePointerIcon(event, pointerIndex);
}
use of android.text.style.ClickableSpan in project AndroidChromium by JackyAndroid.
the class AccountChooserDialog method show.
private void show() {
View titleView = LayoutInflater.from(mContext).inflate(R.layout.account_chooser_dialog_title, null);
TextView origin = (TextView) titleView.findViewById(R.id.origin);
origin.setText(mOrigin);
TextView titleMessageText = (TextView) titleView.findViewById(R.id.title);
if (mTitleLinkStart != 0 && mTitleLinkEnd != 0) {
SpannableString spanableTitle = new SpannableString(mTitle);
spanableTitle.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
nativeOnLinkClicked(mNativeAccountChooserDialog);
mDialog.dismiss();
}
}, mTitleLinkStart, mTitleLinkEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
titleMessageText.setText(spanableTitle, TextView.BufferType.SPANNABLE);
titleMessageText.setMovementMethod(LinkMovementMethod.getInstance());
} else {
titleMessageText.setText(mTitle);
}
mAdapter = generateAccountsArrayAdapter(mContext, mCredentials);
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.AlertDialogTheme).setCustomTitle(titleView).setNegativeButton(R.string.cancel, this).setAdapter(mAdapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
mCredential = mCredentials[item];
}
});
if (!TextUtils.isEmpty(mSigninButtonText)) {
builder.setPositiveButton(mSigninButtonText, this);
}
mDialog = builder.create();
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of android.text.style.ClickableSpan in project AndroidChromium by JackyAndroid.
the class PassphraseDialogFragment method getResetText.
private SpannableString getResetText() {
final Context context = getActivity();
return SpanApplier.applySpans(context.getString(R.string.sync_passphrase_reset_instructions), new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
@Override
public void onClick(View view) {
recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
Uri syncDashboardUrl = Uri.parse(context.getText(R.string.sync_dashboard_url).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
intent.setPackage(BuildInfo.getPackageName(context));
IntentUtils.safePutBinderExtra(intent, CustomTabsIntent.EXTRA_SESSION, null);
context.startActivity(intent);
}
}));
}
use of android.text.style.ClickableSpan in project AndroidChromium by JackyAndroid.
the class PassphraseTypeDialogFragment method getResetText.
private SpannableString getResetText() {
final Context context = getActivity();
return SpanApplier.applySpans(context.getString(R.string.sync_passphrase_encryption_reset_instructions), new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
@Override
public void onClick(View view) {
Uri syncDashboardUrl = Uri.parse(context.getText(R.string.sync_dashboard_url).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
intent.setPackage(BuildInfo.getPackageName(context));
IntentUtils.safePutBinderExtra(intent, CustomTabsIntent.EXTRA_SESSION, null);
context.startActivity(intent);
}
}));
}
Aggregations