Search in sources :

Example 96 with StyleSpan

use of android.text.style.StyleSpan in project Signal-Android by WhisperSystems.

the class Util method getBoldedString.

public static CharSequence getBoldedString(String value) {
    SpannableString spanned = new SpannableString(value);
    spanned.setSpan(new StyleSpan(Typeface.BOLD), 0, spanned.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spanned;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan)

Example 97 with StyleSpan

use of android.text.style.StyleSpan 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 98 with StyleSpan

use of android.text.style.StyleSpan in project Signal-Android by WhisperSystems.

the class MessageRecord method emphasisAdded.

protected SpannableString emphasisAdded(String sequence) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new RelativeSizeSpan(0.9f), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 99 with StyleSpan

use of android.text.style.StyleSpan in project Signal-Android by WhisperSystems.

the class ThreadRecord method emphasisAdded.

private SpannableString emphasisAdded(String sequence, int start, int end) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan)

Example 100 with StyleSpan

use of android.text.style.StyleSpan in project platform_frameworks_base by android.

the class MediaProjectionPermissionActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mPackageName = getCallingPackage();
    IBinder b = ServiceManager.getService(MEDIA_PROJECTION_SERVICE);
    mService = IMediaProjectionManager.Stub.asInterface(b);
    if (mPackageName == null) {
        finish();
        return;
    }
    PackageManager packageManager = getPackageManager();
    ApplicationInfo aInfo;
    try {
        aInfo = packageManager.getApplicationInfo(mPackageName, 0);
        mUid = aInfo.uid;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "unable to look up package name", e);
        finish();
        return;
    }
    try {
        if (mService.hasProjectionPermission(mUid, mPackageName)) {
            setResult(RESULT_OK, getMediaProjectionIntent(mUid, mPackageName, false));
            finish();
            return;
        }
    } catch (RemoteException e) {
        Log.e(TAG, "Error checking projection permissions", e);
        finish();
        return;
    }
    TextPaint paint = new TextPaint();
    paint.setTextSize(42);
    String label = aInfo.loadLabel(packageManager).toString();
    // If the label contains new line characters it may push the security
    // message below the fold of the dialog. Labels shouldn't have new line
    // characters anyways, so just truncate the message the first time one
    // is seen.
    final int labelLength = label.length();
    int offset = 0;
    while (offset < labelLength) {
        final int codePoint = label.codePointAt(offset);
        final int type = Character.getType(codePoint);
        if (type == Character.LINE_SEPARATOR || type == Character.CONTROL || type == Character.PARAGRAPH_SEPARATOR) {
            label = label.substring(0, offset) + ELLIPSIS;
            break;
        }
        offset += Character.charCount(codePoint);
    }
    if (label.isEmpty()) {
        label = mPackageName;
    }
    String unsanitizedAppName = TextUtils.ellipsize(label, paint, MAX_APP_NAME_SIZE_PX, TextUtils.TruncateAt.END).toString();
    String appName = BidiFormatter.getInstance().unicodeWrap(unsanitizedAppName);
    String actionText = getString(R.string.media_projection_dialog_text, appName);
    SpannableString message = new SpannableString(actionText);
    int appNameIndex = actionText.indexOf(appName);
    if (appNameIndex >= 0) {
        message.setSpan(new StyleSpan(Typeface.BOLD), appNameIndex, appNameIndex + appName.length(), 0);
    }
    mDialog = new AlertDialog.Builder(this).setIcon(aInfo.loadIcon(packageManager)).setMessage(message).setPositiveButton(R.string.media_projection_action_text, this).setNegativeButton(android.R.string.cancel, this).setView(R.layout.remember_permission_checkbox).setOnCancelListener(this).create();
    mDialog.create();
    mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setFilterTouchesWhenObscured(true);
    ((CheckBox) mDialog.findViewById(R.id.remember)).setOnCheckedChangeListener(this);
    mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    mDialog.show();
}
Also used : SpannableString(android.text.SpannableString) IBinder(android.os.IBinder) PackageManager(android.content.pm.PackageManager) CheckBox(android.widget.CheckBox) StyleSpan(android.text.style.StyleSpan) ApplicationInfo(android.content.pm.ApplicationInfo) SpannableString(android.text.SpannableString) RemoteException(android.os.RemoteException) TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint)

Aggregations

StyleSpan (android.text.style.StyleSpan)143 SpannableString (android.text.SpannableString)56 SpannableStringBuilder (android.text.SpannableStringBuilder)34 RelativeSizeSpan (android.text.style.RelativeSizeSpan)32 ForegroundColorSpan (android.text.style.ForegroundColorSpan)25 View (android.view.View)18 TextView (android.widget.TextView)17 UnderlineSpan (android.text.style.UnderlineSpan)16 Spannable (android.text.Spannable)14 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)12 TypedArray (android.content.res.TypedArray)10 TextPaint (android.text.TextPaint)10 SubscriptSpan (android.text.style.SubscriptSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)10 Handler (android.os.Handler)9 Message (android.os.Message)9 URLSpan (android.text.style.URLSpan)8 JustifiedSpan (com.bluejamesbond.text.style.JustifiedSpan)8 ArticleBuilder (com.bluejamesbond.text.util.ArticleBuilder)8