Example usage for android.text SpannableString SpannableString

List of usage examples for android.text SpannableString SpannableString

Introduction

In this page you can find the example usage for android.text SpannableString SpannableString.

Prototype

public SpannableString(CharSequence source) 

Source Link

Document

For the backward compatibility reasons, this constructor copies all spans including android.text.NoCopySpan .

Usage

From source file:com.example.sample2.MainActivity.java

private void setActionBarTitle() {
    if (getSupportActionBar() == null)
        return;// w w w.j av  a 2 s . co m
    TypefaceSpan span = new TypefaceSpan(this, "Audiowide-Regular");
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.CYAN);

    SpannableString title = new SpannableString("TextViews2");
    title.setSpan(span, 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    title.setSpan(colorSpan, 4, title.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    getSupportActionBar().setTitle(title);
}

From source file:com.justwayward.reader.view.BookContentTextView.java

public void setText(String text) {
    int startIndex = 0;
    while (true) {

        int start = text.indexOf("");
        int end = text.indexOf("");
        if (start < 0 || end < 0) {
            append(text.substring(startIndex));
            break;
        }/*w  w w. java2  s.  com*/

        append(text.substring(startIndex, start));

        SpannableString spanableInfo = new SpannableString(text.substring(start, end + 1));
        spanableInfo.setSpan(new Clickable(spanableInfo.toString()), 0, end + 1 - start,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        append(spanableInfo);
        //setMovementMethod()???
        setMovementMethod(LinkMovementMethod.getInstance());
        text = text.substring(end + 1);

        LogUtils.e(spanableInfo.toString());
    }
}

From source file:fyp.hkust.facet.activity.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getDelegate().installViewFactory();//from  w ww.  java  2s . c om
    getDelegate().onCreate(savedInstanceState);
    getDelegate().getSupportActionBar().setHomeButtonEnabled(true);
    getDelegate().getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    super.onCreate(savedInstanceState);
    // ?SharePreferences
    SpannableString s = new SpannableString(getTitle().toString());
    s.setSpan(new TypefaceSpan(SettingsActivity.this, FontManager.CUSTOM_FONT), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    getDelegate().getSupportActionBar().setTitle(s);

    getFragmentManager().beginTransaction()
            .replace(android.R.id.content, new SettingsActivity.MyPreferenceFragment()).commit();

}

From source file:com.manning.androidhacks.hack010.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//ww w .ja  va2 s  .  c om

    final TextView textView1 = (TextView) findViewById(R.id.my_text_view_html);
    textView1.setText(Html.fromHtml(getString(R.string.text1)));
    textView1.setMovementMethod(LinkMovementMethod.getInstance());

    final Spannable text2 = new SpannableString(getString(R.string.text2));
    text2.setSpan(new BackgroundColorSpan(Color.RED), 1, 4, 0);
    text2.setSpan(new ForegroundColorSpan(Color.BLUE), 5, 9, 0);

    ((TextView) findViewById(R.id.my_text_view_spannable)).setText(text2);
}

From source file:org.birthdayadapter.ui.InstallWorkaroundDialogFragment.java

/**
 * Creates dialog/*from  w  ww.ja v a  2  s  .  co  m*/
 */
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Linkify the message
    final SpannableString message = new SpannableString(getString(R.string.workaround_dialog_message));
    Linkify.addLinks(message, Linkify.ALL);

    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    alert.setTitle(R.string.workaround_dialog_title);
    alert.setMessage(message);
    alert.setCancelable(true);
    alert.setIcon(android.R.drawable.ic_dialog_info);

    alert.setNegativeButton(R.string.workaround_dialog_close_button, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dismiss();
        }
    });
    alert.setNeutralButton(R.string.workaround_dialog_dont_show_again_button, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            PreferencesHelper.setShowWorkaroundDialog(getActivity(), false);
            dismiss();
        }
    });
    alert.setPositiveButton(R.string.workaround_dialog_install_button, new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String workaroundName = "org.birthdayadapter.jb.workaround";
            try {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + workaroundName)));
            } catch (ActivityNotFoundException anfe) {
                // No Google Play installed? Weird! Try with browser!
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + workaroundName)));
            }
        }
    });
    return alert.create();
}

From source file:ru.tinkoff.acquiring.sample.ui.PaymentResultActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_payment_result);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final TextView textView = (TextView) findViewById(R.id.tv_confirm);
    Intent intent = getIntent();/*from w ww .  j  a v  a  2  s.  c om*/
    if (intent.hasExtra(EXTRA_PRICE)) {
        final Money price = (Money) intent.getSerializableExtra(EXTRA_PRICE);

        final SpannableString coloredPrice = new SpannableString(price.toString());
        coloredPrice.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorPrimary)), 0,
                coloredPrice.length(), SpannedString.SPAN_INCLUSIVE_INCLUSIVE);

        final String text = getString(R.string.payment_result_success, coloredPrice);
        textView.setText(text);
    } else {
        String cardId = intent.getStringExtra(EXTRA_CARD_ID);
        final String text = getString(R.string.attachment_result_success, cardId);
        textView.setText(text);
    }
}

From source file:com.senior.fragments.ArticleContent.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    //Obtains each 
    articleView = inflater.inflate(R.layout.articles_fragment, container, false);
    TextView title = (TextView) articleView.findViewById(R.id.title);
    progress = (ProgressBar) articleView.findViewById(R.id.progress);
    SpannableString NewTitle = new SpannableString(articleTitle);

    //Sets the options for display
    NewTitle.setSpan(new UnderlineSpan(), 0, NewTitle.length(), 0);
    title.setText(NewTitle);/* ww w  . ja va2 s.  com*/

    reloadButton = (Button) articleView.findViewById(R.id.refresh);
    reloadButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            refreshArticle();
        }
    });
    return articleView;
}

From source file:com.groupme.sdk.activity.PinEntryActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pinentry);

    TextView pinEntryInstructions = (TextView) findViewById(R.id.pin_entry_instructions);
    pinEntryInstructions/*  www  .j  ava2 s . c  o  m*/
            .setText(getString(R.string.pin_entry_instructions, getIntent().getStringExtra("phone_number")));

    mNameEntry = (EditText) findViewById(R.id.name_entry);
    mPinEntry = (EditText) findViewById(R.id.pin_entry);
    mAlternateButton = (Button) findViewById(R.id.not_number_button);

    SpannableString str = new SpannableString(getString(R.string.link_not_number));
    str.setSpan(new UnderlineSpan(), 0, str.length(), 0);
    mAlternateButton.setText(str);
}

From source file:com.dimasdanz.kendalipintu.util.CommonUtilities.java

public static void generateNotification(Context context, String message, String time, String info) {
    try {/*from   ww w.j a  v  a  2  s  . co m*/
        NotificationManager manager;
        int notificationID = 73;

        Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.ic_stat_notification);

        Notification.Builder builder = new Notification.Builder(context);
        Intent resultIntent = new Intent(context, LogActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

        stackBuilder.addParentStack(LogActivity.class);
        stackBuilder.addNextIntent(resultIntent);

        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        Spannable sb = new SpannableString(message + " " + time + "-" + info);
        sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, message.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        builder.setAutoCancel(true);
        builder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND);
        builder.setContentTitle(context.getString(R.string.notification_title));
        builder.setContentText(sb);
        builder.setTicker(context.getString(R.string.notification_ticker));
        builder.setNumber(++msgCounter);
        builder.setSmallIcon(R.drawable.ic_stat_notification);
        builder.setLargeIcon(largeIcon);
        builder.setContentIntent(resultPendingIntent);

        if (msgCounter > 1) {
            Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
            if (msgCounter > 6) {
                name[0] = new SpannableString("...");
                name[1] = name[2];
                name[2] = name[3];
                name[3] = name[4];
                name[4] = name[5];
                name[5] = sb;
            } else {
                name[msgCounter - 1] = sb;
            }

            inboxStyle.setBigContentTitle(context.getString(R.string.notification_title));
            inboxStyle.setSummaryText(
                    msgCounter + " " + context.getString(R.string.notification_title) + " Baru");

            for (int i = name.length; i > 0; i--) {
                inboxStyle.addLine(name[i - 1]);
            }

            builder.setStyle(inboxStyle);
            builder.setContentText(msgCounter + " " + context.getString(R.string.notification_title) + " Baru");
        } else {
            name[0] = sb;
        }
        manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(notificationID, builder.build());
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

}

From source file:ca.rmen.android.networkmonitor.app.about.AboutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);//from w ww.  j a v a2  s . c o m

    String versionName;
    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        versionName = packageInfo.versionName;
    } catch (NameNotFoundException e) {
        // Should never happen
        throw new AssertionError(e);
    }

    ((TextView) findViewById(R.id.txtVersion)).setText(getString(R.string.app_name) + " v" + versionName);
    TextView tvLibraries = (TextView) findViewById(R.id.about_libraries);
    SpannableString content = new SpannableString(getString(R.string.about_libraries));
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    tvLibraries.setText(content);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}