use of android.text.SpannableStringBuilder in project plaid by nickbutcher.
the class SearchActivity method setNoResultsVisibility.
void setNoResultsVisibility(int visibility) {
if (visibility == View.VISIBLE) {
if (noResults == null) {
noResults = (TextView) ((ViewStub) findViewById(R.id.stub_no_search_results)).inflate();
noResults.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.setQuery("", false);
searchView.requestFocus();
ImeUtils.showIme(searchView);
}
});
}
String message = String.format(getString(R.string.no_search_results), searchView.getQuery().toString());
SpannableStringBuilder ssb = new SpannableStringBuilder(message);
ssb.setSpan(new StyleSpan(Typeface.ITALIC), message.indexOf('“') + 1, message.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
noResults.setText(ssb);
}
if (noResults != null) {
noResults.setVisibility(visibility);
}
}
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 WordPress-Android by wordpress-mobile.
the class HtmlStyleTextWatcherTest method testAddingListTagsFromFormatBar.
@Test
public void testAddingListTagsFromFormatBar() {
// -- Test adding a list tag to an empty document
mContent = new SpannableStringBuilder("<ul>\n\t<li>");
mWatcher.onTextChanged(mContent, 0, 0, 10);
mWatcher.afterTextChanged(mContent);
assertEquals(0, mSpanRange.getOpeningTagLoc());
assertEquals(10, mSpanRange.getClosingTagLoc());
// -- Test adding a closing list tag
mContent = new SpannableStringBuilder(//5
"<ul>\n" + //20
"\t<li>list item</li>\n" + //22
"\t<li>another list item</li>\n" + "</ul>");
// Added "</li>\n</ul>"
mWatcher.onTextChanged(mContent, 47, 0, 11);
mWatcher.afterTextChanged(mContent);
assertEquals(47, mSpanRange.getOpeningTagLoc());
assertEquals(58, mSpanRange.getClosingTagLoc());
}
use of android.text.SpannableStringBuilder in project XobotOS by xamarin.
the class DigitsKeyListener method filter.
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
CharSequence out = super.filter(source, start, end, dest, dstart, dend);
if (mSign == false && mDecimal == false) {
return out;
}
if (out != null) {
source = out;
start = 0;
end = out.length();
}
int sign = -1;
int decimal = -1;
int dlen = dest.length();
for (int i = 0; i < dstart; i++) {
char c = dest.charAt(i);
if (c == '-') {
sign = i;
} else if (c == '.') {
decimal = i;
}
}
for (int i = dend; i < dlen; i++) {
char c = dest.charAt(i);
if (c == '-') {
// Nothing can be inserted in front of a '-'.
return "";
} else if (c == '.') {
decimal = i;
}
}
/*
* If it does, we must strip them out from the source.
* In addition, '-' must be the very first character,
* and nothing can be inserted before an existing '-'.
* Go in reverse order so the offsets are stable.
*/
SpannableStringBuilder stripped = null;
for (int i = end - 1; i >= start; i--) {
char c = source.charAt(i);
boolean strip = false;
if (c == '-') {
if (i != start || dstart != 0) {
strip = true;
} else if (sign >= 0) {
strip = true;
} else {
sign = i;
}
} else if (c == '.') {
if (decimal >= 0) {
strip = true;
} else {
decimal = i;
}
}
if (strip) {
if (end == start + 1) {
// Only one character, and it was stripped.
return "";
}
if (stripped == null) {
stripped = new SpannableStringBuilder(source, start, end);
}
stripped.delete(i - start, i + 1 - start);
}
}
if (stripped != null) {
return stripped;
} else if (out != null) {
return out;
} else {
return null;
}
}
use of android.text.SpannableStringBuilder in project XobotOS by xamarin.
the class SearchView method getDecoratedHint.
private CharSequence getDecoratedHint(CharSequence hintText) {
// If the field is always expanded, then don't add the search icon to the hint
if (!mIconifiedByDefault)
return hintText;
// for the icon
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
ssb.append(hintText);
Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId());
int textSize = (int) (mQueryTextView.getTextSize() * 1.25);
searchIcon.setBounds(0, 0, textSize, textSize);
ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return ssb;
}
Aggregations