use of android.text.SpannableStringBuilder in project Etar-Calendar by Etar-Group.
the class DayView method getEventLayout.
/**
* Return the layout for a numbered event. Create it if not already existing
*/
private StaticLayout getEventLayout(StaticLayout[] layouts, int i, Event event, Paint paint, Rect r) {
if (i < 0 || i >= layouts.length) {
return null;
}
StaticLayout layout = layouts[i];
// re-layout of events at min height)
if (layout == null || r.width() != layout.getWidth()) {
SpannableStringBuilder bob = new SpannableStringBuilder();
if (event.title != null) {
// MAX - 1 since we add a space
bob.append(drawTextSanitizer(event.title.toString(), MAX_EVENT_TEXT_LEN - 1));
bob.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, bob.length(), 0);
bob.append(' ');
}
if (event.location != null) {
bob.append(drawTextSanitizer(event.location.toString(), MAX_EVENT_TEXT_LEN - bob.length()));
}
switch(event.selfAttendeeStatus) {
case Attendees.ATTENDEE_STATUS_INVITED:
paint.setColor(event.color);
break;
case Attendees.ATTENDEE_STATUS_DECLINED:
paint.setColor(mEventTextColor);
paint.setAlpha(Utils.DECLINED_EVENT_TEXT_ALPHA);
break;
// Your own events
case Attendees.ATTENDEE_STATUS_NONE:
case Attendees.ATTENDEE_STATUS_ACCEPTED:
case Attendees.ATTENDEE_STATUS_TENTATIVE:
default:
paint.setColor(mEventTextColor);
break;
}
// Leave a one pixel boundary on the left and right of the rectangle for the event
layout = new StaticLayout(bob, 0, bob.length(), new TextPaint(paint), r.width(), Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true, null, r.width());
layouts[i] = layout;
}
layout.getPaint().setAlpha(mEventsAlpha);
return layout;
}
use of android.text.SpannableStringBuilder in project Etar-Calendar by Etar-Group.
the class AlertReceiver method makeDigestNotification.
/**
* Creates an expanding digest notification for expired events.
*/
public static NotificationWrapper makeDigestNotification(Context context, ArrayList<AlertService.NotificationInfo> notificationInfos, String digestTitle, boolean expandable) {
if (notificationInfos == null || notificationInfos.size() < 1) {
return null;
}
Resources res = context.getResources();
int numEvents = notificationInfos.size();
long[] eventIds = new long[notificationInfos.size()];
long[] startMillis = new long[notificationInfos.size()];
for (int i = 0; i < notificationInfos.size(); i++) {
eventIds[i] = notificationInfos.get(i).eventId;
startMillis[i] = notificationInfos.get(i).startMillis;
}
// Create an intent triggered by clicking on the status icon that shows the alerts list.
PendingIntent pendingClickIntent = createAlertActivityIntent(context);
// Create an intent triggered by dismissing the digest notification that clears all
// expired events.
Intent deleteIntent = new Intent();
deleteIntent.setClass(context, DismissAlarmsService.class);
deleteIntent.setAction(DELETE_ALL_ACTION);
deleteIntent.putExtra(AlertUtils.EVENT_IDS_KEY, eventIds);
deleteIntent.putExtra(AlertUtils.EVENT_STARTS_KEY, startMillis);
PendingIntent pendingDeleteIntent = PendingIntent.getService(context, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (digestTitle == null || digestTitle.length() == 0) {
digestTitle = res.getString(R.string.no_title_label);
}
Notification.Builder notificationBuilder = new Notification.Builder(context);
notificationBuilder.setContentText(digestTitle);
notificationBuilder.setSmallIcon(R.drawable.stat_notify_calendar_multiple);
notificationBuilder.setContentIntent(pendingClickIntent);
notificationBuilder.setDeleteIntent(pendingDeleteIntent);
String nEventsStr = res.getQuantityString(R.plurals.Nevents, numEvents, numEvents);
notificationBuilder.setContentTitle(nEventsStr);
Notification n;
if (Utils.isJellybeanOrLater()) {
// New-style notification...
// Set to min priority to encourage the notification manager to collapse it.
notificationBuilder.setPriority(Notification.PRIORITY_MIN);
if (expandable) {
// Multiple reminders. Combine into an expanded digest notification.
Notification.InboxStyle expandedBuilder = new Notification.InboxStyle(notificationBuilder);
int i = 0;
for (AlertService.NotificationInfo info : notificationInfos) {
if (i < NOTIFICATION_DIGEST_MAX_LENGTH) {
String name = info.eventName;
if (TextUtils.isEmpty(name)) {
name = context.getResources().getString(R.string.no_title_label);
}
String timeLocation = AlertUtils.formatTimeLocation(context, info.startMillis, info.allDay, info.location);
TextAppearanceSpan primaryTextSpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText);
TextAppearanceSpan secondaryTextSpan = new TextAppearanceSpan(context, R.style.NotificationSecondaryText);
// Event title in bold.
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
stringBuilder.append(name);
stringBuilder.setSpan(primaryTextSpan, 0, stringBuilder.length(), 0);
stringBuilder.append(" ");
// Followed by time and location.
int secondaryIndex = stringBuilder.length();
stringBuilder.append(timeLocation);
stringBuilder.setSpan(secondaryTextSpan, secondaryIndex, stringBuilder.length(), 0);
expandedBuilder.addLine(stringBuilder);
i++;
} else {
break;
}
}
// If there are too many to display, add "+X missed events" for the last line.
int remaining = numEvents - i;
if (remaining > 0) {
String nMoreEventsStr = res.getQuantityString(R.plurals.N_remaining_events, remaining, remaining);
// TODO: Add highlighting and icon to this last entry once framework allows it.
expandedBuilder.setSummaryText(nMoreEventsStr);
}
// Remove the title in the expanded form (redundant with the listed items).
expandedBuilder.setBigContentTitle("");
n = expandedBuilder.build();
} else {
n = notificationBuilder.build();
}
} else {
// Old-style notification (pre-JB). We only need a standard notification (no
// buttons) but use a custom view so it is consistent with the others.
n = notificationBuilder.getNotification();
// Use custom view with buttons to provide JB-like functionality (snooze/email).
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification);
contentView.setImageViewResource(R.id.image, R.drawable.stat_notify_calendar_multiple);
contentView.setTextViewText(R.id.title, nEventsStr);
contentView.setTextViewText(R.id.text, digestTitle);
contentView.setViewVisibility(R.id.time, View.VISIBLE);
contentView.setViewVisibility(R.id.map_button, View.GONE);
contentView.setViewVisibility(R.id.call_button, View.GONE);
contentView.setViewVisibility(R.id.email_button, View.GONE);
contentView.setViewVisibility(R.id.snooze_button, View.GONE);
contentView.setViewVisibility(R.id.end_padding, View.VISIBLE);
n.contentView = contentView;
// Use timestamp to force expired digest notification to the bottom (there is no
// priority setting before JB release). This is hidden by the custom view.
n.when = 1;
}
NotificationWrapper nw = new NotificationWrapper(n);
if (AlertService.DEBUG) {
for (AlertService.NotificationInfo info : notificationInfos) {
nw.add(new NotificationWrapper(null, 0, info.eventId, info.startMillis, info.endMillis, false));
}
}
return nw;
}
use of android.text.SpannableStringBuilder in project android_frameworks_base by DirtyUnicorns.
the class NotificationBuilderTest method subst.
private static CharSequence subst(CharSequence in, char ch, CharSequence sub) {
int i = 0;
SpannableStringBuilder edit = new SpannableStringBuilder(in);
while (i < edit.length()) {
if (edit.charAt(i) == ch) {
edit.replace(i, i + 1, sub);
i += sub.length();
} else {
i++;
}
}
return edit;
}
use of android.text.SpannableStringBuilder in project android_frameworks_base by DirtyUnicorns.
the class PhoneNumberUtils method formatNumber.
/**
* Formats the given number with the given formatting type. Currently
* {@link #FORMAT_NANP} and {@link #FORMAT_JAPAN} are supported as a formating type.
*
* @param source the phone number to format
* @param defaultFormattingType The default formatting rules to apply if the number does
* not begin with +[country_code]
* @return The phone number formatted with the given formatting type.
*
* @hide
* @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
*/
@Deprecated
public static String formatNumber(String source, int defaultFormattingType) {
SpannableStringBuilder text = new SpannableStringBuilder(source);
formatNumber(text, defaultFormattingType);
return text.toString();
}
use of android.text.SpannableStringBuilder in project android_frameworks_base by DirtyUnicorns.
the class PhoneNumberUtils method formatNumber.
/**
* Breaks the given number down and formats it according to the rules
* for the country the number is from.
*
* @param source The phone number to format
* @return A locally acceptable formatting of the input, or the raw input if
* formatting rules aren't known for the number
*
* @deprecated Use link #formatNumber(String phoneNumber, String defaultCountryIso) instead
*/
@Deprecated
public static String formatNumber(String source) {
SpannableStringBuilder text = new SpannableStringBuilder(source);
formatNumber(text, getFormatTypeForLocale(Locale.getDefault()));
return text.toString();
}
Aggregations