Search in sources :

Example 36 with ClickableSpan

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);
        }
    }
}
Also used : Context(android.content.Context) AndroidContext(im.actor.runtime.android.AndroidContext) ActorContext(im.actor.runtime.actors.ActorContext) MDRawText(im.actor.runtime.markdown.MDRawText) MDUrl(im.actor.runtime.markdown.MDUrl) Peer(im.actor.core.entity.Peer) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) MDSpan(im.actor.runtime.markdown.MDSpan) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) MDText(im.actor.runtime.markdown.MDText) StyleSpan(android.text.style.StyleSpan)

Example 37 with ClickableSpan

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);
}
Also used : ClickableSpan(android.text.style.ClickableSpan) Spannable(android.text.Spannable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 38 with ClickableSpan

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();
}
Also used : SpannableString(android.text.SpannableString) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) ClickableSpan(android.text.style.ClickableSpan)

Example 39 with ClickableSpan

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);
        }
    }));
}
Also used : Context(android.content.Context) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri)

Example 40 with ClickableSpan

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);
        }
    }));
}
Also used : Context(android.content.Context) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView) Uri(android.net.Uri)

Aggregations

ClickableSpan (android.text.style.ClickableSpan)66 View (android.view.View)29 Layout (android.text.Layout)20 TextPaint (android.text.TextPaint)19 TextView (android.widget.TextView)19 SpannableString (android.text.SpannableString)15 Spannable (android.text.Spannable)14 Paint (android.graphics.Paint)13 SpannableStringBuilder (android.text.SpannableStringBuilder)11 Intent (android.content.Intent)7 InputMethodManager (android.view.inputmethod.InputMethodManager)7 Context (android.content.Context)5 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)4 StyleSpan (android.text.style.StyleSpan)4 SuppressLint (android.annotation.SuppressLint)3 DialogInterface (android.content.DialogInterface)3 AlertDialog (android.support.v7.app.AlertDialog)3 ImageView (android.widget.ImageView)3 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)3 PendingIntent (android.app.PendingIntent)2