use of android.text.SpannableString in project AndroidChromium by JackyAndroid.
the class UpdatePasswordInfoBar method createContent.
@Override
public void createContent(InfoBarLayout layout) {
super.createContent(layout);
if (mTitleLinkRangeStart != 0 && mTitleLinkRangeEnd != 0) {
SpannableString title = new SpannableString(mTitle);
title.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
onLinkClicked();
}
}, mTitleLinkRangeStart, mTitleLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
layout.setMessage(title);
}
InfoBarControlLayout controlLayout = layout.addControlLayout();
if (mUsernames.length > 1) {
InfoBarArrayAdapter<String> usernamesAdapter = new InfoBarArrayAdapter<String>(getContext(), mUsernames);
mUsernamesSpinner = controlLayout.addSpinner(R.id.password_infobar_accounts_spinner, usernamesAdapter);
} else {
controlLayout.addDescription(mUsernames[0]);
}
}
use of android.text.SpannableString in project zxing by zxing.
the class SupplementalInfoRetriever method append.
final void append(String itemID, String source, String[] newTexts, String linkURL) {
StringBuilder newTextCombined = new StringBuilder();
if (source != null) {
newTextCombined.append(source).append(' ');
}
int linkStart = newTextCombined.length();
boolean first = true;
for (String newText : newTexts) {
if (first) {
newTextCombined.append(newText);
first = false;
} else {
newTextCombined.append(" [");
newTextCombined.append(newText);
newTextCombined.append(']');
}
}
int linkEnd = newTextCombined.length();
String newText = newTextCombined.toString();
Spannable content = new SpannableString(newText + "\n\n");
if (linkURL != null) {
// Lower-case these as it should always be OK to lower-case these schemes.
if (linkURL.startsWith("HTTP://")) {
linkURL = "http" + linkURL.substring(4);
} else if (linkURL.startsWith("HTTPS://")) {
linkURL = "https" + linkURL.substring(5);
}
content.setSpan(new URLSpan(linkURL), linkStart, linkEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
newContents.add(content);
newHistories.add(new String[] { itemID, newText });
}
use of android.text.SpannableString in project BarcodeEye by BarcodeEye.
the class SupplementalInfoRetriever method append.
final void append(String itemID, String source, String[] newTexts, String linkURL) {
StringBuilder newTextCombined = new StringBuilder();
if (source != null) {
newTextCombined.append(source).append(' ');
}
int linkStart = newTextCombined.length();
boolean first = true;
for (String newText : newTexts) {
if (first) {
newTextCombined.append(newText);
first = false;
} else {
newTextCombined.append(" [");
newTextCombined.append(newText);
newTextCombined.append(']');
}
}
int linkEnd = newTextCombined.length();
String newText = newTextCombined.toString();
Spannable content = new SpannableString(newText + "\n\n");
if (linkURL != null) {
// Lower-case these as it should always be OK to lower-case these schemes.
if (linkURL.startsWith("HTTP://")) {
linkURL = "http" + linkURL.substring(4);
} else if (linkURL.startsWith("HTTPS://")) {
linkURL = "https" + linkURL.substring(5);
}
content.setSpan(new URLSpan(linkURL), linkStart, linkEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
newContents.add(content);
}
use of android.text.SpannableString in project android_frameworks_base by DirtyUnicorns.
the class LinkifyBenchmark method setUp.
@BeforeExperiment
protected void setUp() throws Exception {
int copyAmount = Integer.parseInt(mParamCopyAmount);
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < copyAmount; i++) {
strBuilder.append(mParamBasicText);
}
mTestSpannable = new SpannableString(strBuilder.toString());
}
use of android.text.SpannableString in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotification method createSummaryNotification.
// This summary notification will be visible instead of the normal one on pre-Android 7.0 devices.
static void createSummaryNotification(NotificationGenerationJob notifJob, OneSignalNotificationBuilder notifBuilder) {
boolean updateSummary = notifJob.restoring;
JSONObject gcmBundle = notifJob.jsonPayload;
String group = gcmBundle.optString("grp", null);
Random random = new Random();
PendingIntent summaryDeleteIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseDeleteIntent(0).putExtra("summary", group));
Notification summaryNotification;
Integer summaryNotificationId = null;
String firstFullData = null;
Collection<SpannableString> summaryList = null;
OneSignalDbHelper dbHelper = OneSignalDbHelper.getInstance(currentContext);
Cursor cursor = null;
try {
SQLiteDatabase readableDb = dbHelper.getReadableDbWithRetries();
String[] retColumn = { NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, NotificationTable.COLUMN_NAME_FULL_DATA, NotificationTable.COLUMN_NAME_IS_SUMMARY, NotificationTable.COLUMN_NAME_TITLE, NotificationTable.COLUMN_NAME_MESSAGE };
String whereStr = // Where String
NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED + " = 0";
String[] whereArgs = { group };
// Make sure to omit any old existing matching android ids in-case we are replacing it.
if (!updateSummary && notifJob.getAndroidId() != -1)
whereStr += " AND " + NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID + " <> " + notifJob.getAndroidId();
cursor = readableDb.query(NotificationTable.TABLE_NAME, retColumn, whereStr, whereArgs, // group by
null, // filter by row groups
null, // sort order, new to old
NotificationTable._ID + " DESC");
if (cursor.moveToFirst()) {
SpannableString spannableString;
summaryList = new ArrayList<>();
do {
if (cursor.getInt(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_IS_SUMMARY)) == 1)
summaryNotificationId = cursor.getInt(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID));
else {
String title = cursor.getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_TITLE));
if (title == null)
title = "";
else
title += " ";
// Html.fromHtml("<strong>" + line1Title + "</strong> " + gcmBundle.getString("alert"));
String msg = cursor.getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_MESSAGE));
spannableString = new SpannableString(title + msg);
if (title.length() > 0)
spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, title.length(), 0);
summaryList.add(spannableString);
if (firstFullData == null)
firstFullData = cursor.getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_FULL_DATA));
}
} while (cursor.moveToNext());
if (updateSummary && firstFullData != null) {
try {
gcmBundle = new JSONObject(firstFullData);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
} finally {
if (cursor != null && !cursor.isClosed())
cursor.close();
}
if (summaryNotificationId == null) {
summaryNotificationId = random.nextInt();
createSummaryIdDatabaseEntry(dbHelper, group, summaryNotificationId);
}
PendingIntent summaryContentIntent = getNewActionPendingIntent(random.nextInt(), createBaseSummaryIntent(summaryNotificationId, gcmBundle, group));
// 2 or more notifications with a group received, group them together as a single notification.
if (summaryList != null && ((updateSummary && summaryList.size() > 1) || (!updateSummary && summaryList.size() > 0))) {
int notificationCount = summaryList.size() + (updateSummary ? 0 : 1);
String summaryMessage = gcmBundle.optString("grp_msg", null);
if (summaryMessage == null)
summaryMessage = notificationCount + " new messages";
else
summaryMessage = summaryMessage.replace("$[notif_count]", "" + notificationCount);
NotificationCompat.Builder summaryBuilder = getBaseOneSignalNotificationBuilder(notifJob).compatBuilder;
if (updateSummary)
removeNotifyOptions(summaryBuilder);
// The summary is designed to fit all notifications.
// Default small and large icons are used instead of the payload options to enforce this.
summaryBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent).setContentTitle(currentContext.getPackageManager().getApplicationLabel(currentContext.getApplicationInfo())).setContentText(summaryMessage).setNumber(notificationCount).setSmallIcon(getDefaultSmallIconId()).setLargeIcon(getDefaultLargeIcon()).setOnlyAlertOnce(updateSummary).setGroup(group).setGroupSummary(true);
if (!updateSummary)
summaryBuilder.setTicker(summaryMessage);
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
// Add the latest notification to the summary
if (!updateSummary) {
String line1Title = gcmBundle.optString("title", null);
if (line1Title == null)
line1Title = "";
else
line1Title += " ";
String message = gcmBundle.optString("alert");
SpannableString spannableString = new SpannableString(line1Title + message);
if (line1Title.length() > 0)
spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, line1Title.length(), 0);
inboxStyle.addLine(spannableString);
}
for (SpannableString line : summaryList) inboxStyle.addLine(line);
inboxStyle.setBigContentTitle(summaryMessage);
summaryBuilder.setStyle(inboxStyle);
summaryNotification = summaryBuilder.build();
} else {
// First notification with this group key, post like a normal notification.
NotificationCompat.Builder summaryBuilder = notifBuilder.compatBuilder;
// We are re-using the notifBuilder from the normal notification so if a developer as an
// extender setup all the settings will carry over.
// Note: However their buttons will not carry over as we need to be setup with this new summaryNotificationId.
summaryBuilder.mActions.clear();
addNotificationActionButtons(gcmBundle, summaryBuilder, summaryNotificationId, group);
summaryBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent).setOnlyAlertOnce(updateSummary).setGroup(group).setGroupSummary(true);
summaryNotification = summaryBuilder.build();
addXiaomiSettings(notifBuilder, summaryNotification);
}
NotificationManagerCompat.from(currentContext).notify(summaryNotificationId, summaryNotification);
}
Aggregations