Example usage for android.text SpannableStringBuilder append

List of usage examples for android.text SpannableStringBuilder append

Introduction

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

Prototype

public SpannableStringBuilder append(char text) 

Source Link

Usage

From source file:es.usc.citius.servando.calendula.activities.ReminderNotification.java

private static void styleForSchedule(Context context, NotificationCompat.InboxStyle style, Schedule schedule) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    final Medicine med = schedule.medicine();
    final SpannableStringBuilder SpItem = new SpannableStringBuilder();
    SpItem.append(med.name());
    SpItem.append("   " + schedule.dose() + " " + med.presentation().units(context.getResources()));
    style.addLine(SpItem);//  w ww  .j  a v  a  2 s .  co  m

    String delayMinutesStr = prefs.getString("alarm_repeat_frequency", "15");
    int delayMinutes = (int) Long.parseLong(delayMinutesStr);

    if (delayMinutes > 0) {
        String repeatTime = DateTime.now().plusMinutes((int) delayMinutes).toString("kk:mm");
        style.setSummaryText(context.getString(R.string.notification_repeat_message, repeatTime));
    } else {
        style.setSummaryText(med.name() + "(" + context.getString(R.string.every) + " "
                + schedule.rule().interval() + " " + context.getString(R.string.hours) + ")");
    }
}

From source file:org.fdroid.enigtext.notifications.MessageNotifier.java

private static void sendSingleThreadNotification(Context context, MasterSecret masterSecret,
        NotificationState notificationState, boolean signal) {
    List<NotificationItem> notifications = notificationState.getNotifications();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    Recipient recipient = notifications.get(0).getIndividualRecipient();

    builder.setSmallIcon(R.drawable.icon_notification);
    builder.setLargeIcon(recipient.getContactPhoto());
    builder.setContentTitle(recipient.toShortString());
    builder.setContentText(notifications.get(0).getText());
    builder.setContentIntent(notifications.get(0).getPendingIntent(context));

    if (masterSecret != null) {
        builder.addAction(R.drawable.check, context.getString(R.string.MessageNotifier_mark_as_read),
                notificationState.getMarkAsReadIntent(context, masterSecret));
    }/*from   w w  w .j a  va  2s .c o m*/

    SpannableStringBuilder content = new SpannableStringBuilder();

    for (NotificationItem item : notifications) {
        content.append(item.getBigStyleSummary());
        content.append('\n');
    }

    builder.setStyle(new BigTextStyle().bigText(content));

    setNotificationAlarms(context, builder, signal);

    if (signal) {
        builder.setTicker(notifications.get(0).getTickerText());
    }

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID,
            builder.build());
}

From source file:es.usc.citius.servando.calendula.activities.ReminderNotification.java

private static void styleForRoutine(Context ctx, NotificationCompat.InboxStyle style, Routine r,
        List<ScheduleItem> doses) {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);

    for (ScheduleItem scheduleItem : doses) {
        //TODO: Use DecimalFormat
        // DecimalFormat timeFormatter = new DecimalFormat("#");
        //String dfDose = timeFormatter.format(scheduleItem.dose());

        final SpannableStringBuilder SpItem = new SpannableStringBuilder();
        final Medicine med = scheduleItem.schedule().medicine();
        SpItem.append(med.name());
        SpItem.append(":  " + scheduleItem.dose() + " " + med.presentation().units(ctx.getResources()));
        style.addLine(SpItem);/*from   w  w  w.j  av a  2 s .  c  o  m*/
    }
    String delayMinutesStr = prefs.getString("alarm_repeat_frequency", "15");
    int delayMinutes = (int) Long.parseLong(delayMinutesStr);

    if (delayMinutes > 0) {
        String repeatTime = DateTime.now().plusMinutes(delayMinutes).toString("HH:mm");
        style.setSummaryText(ctx.getResources().getString(R.string.notification_repeat_message, repeatTime));
    } else {
        style.setSummaryText(doses.size() + " meds to take at " + r.name());
    }

}

From source file:org.thoughtcrime.securesms.notifications.MessageNotifier.java

private static void sendSingleThreadNotification(Context context, MasterSecret masterSecret,
        NotificationState notificationState, boolean signal) {
    if (notificationState.getNotifications().isEmpty()) {
        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(NOTIFICATION_ID);
        return;//from   w w w.  j  a v  a2  s .  c om
    }

    List<NotificationItem> notifications = notificationState.getNotifications();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    Recipient recipient = notifications.get(0).getIndividualRecipient();

    builder.setSmallIcon(R.drawable.icon_notification);
    builder.setLargeIcon(recipient.getContactPhoto());
    builder.setContentTitle(recipient.toShortString());
    builder.setContentText(notifications.get(0).getText());
    builder.setContentIntent(notifications.get(0).getPendingIntent(context));
    builder.setContentInfo(String.valueOf(notificationState.getMessageCount()));

    if (masterSecret != null) {
        builder.addAction(R.drawable.check, context.getString(R.string.MessageNotifier_mark_as_read),
                notificationState.getMarkAsReadIntent(context, masterSecret));
    }

    SpannableStringBuilder content = new SpannableStringBuilder();

    for (NotificationItem item : notifications) {
        content.append(item.getBigStyleSummary());
        content.append('\n');
    }

    builder.setStyle(new BigTextStyle().bigText(content));

    setNotificationAlarms(context, builder, signal);

    if (signal) {
        builder.setTicker(notifications.get(0).getTickerText());
    }

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID,
            builder.build());
}

From source file:com.securecomcode.text.notifications.MessageNotifier.java

private static void sendSingleThreadNotification(Context context, MasterSecret masterSecret,
        NotificationState notificationState, boolean signal) {
    if (notificationState.getNotifications().isEmpty()) {
        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(NOTIFICATION_ID);
        return;//from www . j a  v  a2  s. c o  m
    }

    List<NotificationItem> notifications = notificationState.getNotifications();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    Recipient recipient = notifications.get(0).getIndividualRecipient();

    builder.setSmallIcon(R.drawable.icon_notification);
    builder.setLargeIcon(recipient.getContactPhoto());
    builder.setContentTitle(recipient.toShortString());
    builder.setContentText(notifications.get(0).getText());
    builder.setContentIntent(notifications.get(0).getPendingIntent(context));
    builder.setContentInfo(String.valueOf(notificationState.getMessageCount()));
    builder.setNumber(notificationState.getMessageCount());

    if (masterSecret != null) {
        builder.addAction(R.drawable.check, context.getString(R.string.MessageNotifier_mark_as_read),
                notificationState.getMarkAsReadIntent(context, masterSecret));
    }

    SpannableStringBuilder content = new SpannableStringBuilder();

    for (NotificationItem item : notifications) {
        content.append(item.getBigStyleSummary());
        content.append('\n');
    }

    builder.setStyle(new BigTextStyle().bigText(content));

    setNotificationAlarms(context, builder, signal);

    if (signal) {
        builder.setTicker(notifications.get(0).getTickerText());
    }

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID,
            builder.build());
}

From source file:Main.java

public static void showChangelog(final Context context, final String title, final String appname,
        final int resChanges, final int resNotes) {
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    final String v0 = p.getString(PREFS_LAST_RUN, "");
    String v1 = null;//from ww  w .  j av a2  s.c  o  m
    try {
        v1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "package not found: " + context.getPackageName(), e);
    }
    p.edit().putString(PREFS_LAST_RUN, v1).commit();
    if (v0.length() == 0) {
        Log.d(TAG, "first boot, skip changelog");
        // return;
    }
    if (v0.equals(v1)) {
        Log.d(TAG, "no changes");
        return;
    }

    String[] changes = context.getResources().getStringArray(resChanges);
    String[] notes = resNotes > 0 ? context.getResources().getStringArray(resNotes) : null;

    final SpannableStringBuilder sb = new SpannableStringBuilder();
    for (String s : notes) {
        SpannableString ss = new SpannableString(s + "\n");
        int j = s.indexOf(":");
        if (j > 0) {
            if (!TextUtils.isEmpty(s)) {
                ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        sb.append(ss);
        sb.append("\n");
    }
    if (notes != null && notes.length > 0) {
        sb.append("\n");
    }
    for (String s : changes) {
        s = appname + " " + s.replaceFirst(": ", ":\n* ").replaceAll(", ", "\n* ") + "\n";
        SpannableString ss = new SpannableString(s);
        int j = s.indexOf(":");
        if (j > 0) {
            ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        sb.append(ss);
        sb.append("\n");
    }
    sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    changes = null;
    notes = null;

    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(title);
    b.setMessage(sb);
    b.setCancelable(true);
    b.setPositiveButton(android.R.string.ok, null);
    b.show();
}

From source file:de.ub0r.android.lib.DonationHelper.java

/**
 * Show "donate" dialog.//from  w w  w  .  ja  va  2 s  .  co  m
 * 
 * @param context
 *            {@link Context}
 * @param title
 *            title
 * @param btnDonate
 *            button text for donate
 * @param btnNoads
 *            button text for "i did a donation"
 * @param messages
 *            messages for dialog body
 */
public static void showDonationDialog(final Activity context, final String title, final String btnDonate,
        final String btnNoads, final String[] messages) {
    final Intent marketIntent = Market.getInstallAppIntent(context, DONATOR_PACKAGE, null);

    String btnTitle = String.format(btnDonate, "Play Store");

    SpannableStringBuilder sb = new SpannableStringBuilder();
    for (String m : messages) {
        sb.append(m);
        sb.append("\n");
    }
    sb.delete(sb.length() - 1, sb.length());
    sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(title);
    b.setMessage(sb);
    b.setCancelable(true);
    b.setPositiveButton(btnTitle, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            try {
                context.startActivity(marketIntent);
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "activity not found", e);
                Toast.makeText(context, "activity not found", Toast.LENGTH_LONG).show();
            }
        }
    });
    b.setNeutralButton(btnNoads, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            try {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
                        "http://code.google.com/p/ub0rapps/downloads/list?" + "can=3&q=Product%3DDonator")));
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "activity not found", e);
                Toast.makeText(context, "activity not found", Toast.LENGTH_LONG).show();
            }
        }
    });
    b.show();
}

From source file:com.google.android.apps.iosched.util.UIUtils.java

public static void updateTimeAndLivestreamBlockUI(final Context context, long blockStart, long blockEnd,
        boolean hasLivestream, View backgroundView, TextView titleView, TextView subtitleView,
        CharSequence subtitle) {/* w  w w  .  ja va2s  .  com*/
    long currentTimeMillis = getCurrentTime(context);

    boolean past = (currentTimeMillis > blockEnd && currentTimeMillis < CONFERENCE_END_MILLIS);
    boolean present = (blockStart <= currentTimeMillis && currentTimeMillis <= blockEnd);

    final Resources res = context.getResources();
    if (backgroundView != null) {
        backgroundView.setBackgroundColor(past ? res.getColor(R.color.past_background_color) : 0);
    }

    if (titleView != null) {
        titleView.setTypeface(Typeface.SANS_SERIF, past ? Typeface.NORMAL : Typeface.BOLD);
    }

    if (subtitleView != null) {
        boolean empty = true;
        SpannableStringBuilder sb = new SpannableStringBuilder(); // TODO: recycle
        if (subtitle != null) {
            sb.append(subtitle);
            empty = false;
        }

        if (present) {
            if (sNowPlayingText == null) {
                sNowPlayingText = Html.fromHtml(context.getString(R.string.now_playing_badge));
            }
            if (!empty) {
                sb.append("  ");
            }
            sb.append(sNowPlayingText);

            if (hasLivestream) {
                if (sLivestreamNowText == null) {
                    sLivestreamNowText = Html
                            .fromHtml("&nbsp;&nbsp;" + context.getString(R.string.live_now_badge));
                }
                sb.append(sLivestreamNowText);
            }
        } else if (hasLivestream) {
            if (sLivestreamAvailableText == null) {
                sLivestreamAvailableText = Html.fromHtml(context.getString(R.string.live_available_badge));
            }
            if (!empty) {
                sb.append("  ");
            }
            sb.append(sLivestreamAvailableText);
        }

        subtitleView.setText(sb);
    }
}

From source file:com.android.mail.browse.SendersView.java

private static void appendMessageInfo(SpannableStringBuilder sb, CharSequence text, Object span,
        boolean appendSplitToken, boolean convRead) {
    int startIndex = sb.length();
    if (appendSplitToken) {
        sb.append(sSendersSplitToken);
        sb.setSpan(CharacterStyle.wrap(convRead ? sMessageInfoReadStyleSpan : sMessageInfoUnreadStyleSpan),
                startIndex, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }//from   w  ww  .j  a va2s. co  m

    startIndex = sb.length();
    sb.append(text);
    sb.setSpan(span, startIndex, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:Main.java

/**
 * Returns the bulleted list based on the given {@code lines}.
 * If one of lines starts with {@link BulletListUtil#BAD_FIRST_SYMBOLS}, then such symbol is
 * removed from there (sometimes bad lines are received from the Food2Work).
 * Also if line consists of the upper case words, then this line is used like a header and is
 * underlined./*w  w w . j a  v a  2 s  .  com*/
 *
 * @param leadingMargin In pixels, the space between the left edge of the bullet and the left
 *                         edge of the text
 * @param lines List of strings. Each string will be a separate item in the bulleted list
 * @return The bulleted list based on the given {@code lines}
 */
public static CharSequence makeBulletList(List<String> lines, int leadingMargin) {
    List<Spanned> spanned = new ArrayList<>(lines.size());
    for (String line : lines) {
        if (!line.trim().isEmpty()) {
            Spanned spannedLine = Html.fromHtml(removeBadFirstCharacters(line.trim()));
            spanned.add(spannedLine);
        }
    }

    SpannableStringBuilder sb = new SpannableStringBuilder();
    for (int i = 0; i < spanned.size(); i++) {
        CharSequence line = spanned.get(i) + (i < spanned.size() - 1 ? "\n" : "");
        boolean underlineNeeded = isUpperCase(line);
        Spannable spannable = new SpannableString(line);
        if (underlineNeeded) {
            spannable.setSpan(new UnderlineSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        } else {
            spannable.setSpan(new BulletSpan(leadingMargin), 0, spannable.length(),
                    Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        }
        sb.append(spannable);
    }
    return sb;
}