Search in sources :

Example 91 with SpannableString

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]);
    }
}
Also used : SpannableString(android.text.SpannableString) InfoBarArrayAdapter(org.chromium.chrome.browser.infobar.InfoBarControlLayout.InfoBarArrayAdapter) SpannableString(android.text.SpannableString) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View)

Example 92 with SpannableString

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 });
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) Spannable(android.text.Spannable)

Example 93 with SpannableString

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);
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) Spannable(android.text.Spannable)

Example 94 with SpannableString

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());
}
Also used : SpannableString(android.text.SpannableString) BeforeExperiment(com.google.caliper.BeforeExperiment)

Example 95 with SpannableString

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);
}
Also used : JSONException(org.json.JSONException) SpannableString(android.text.SpannableString) OSUtils.getResourceString(com.onesignal.OSUtils.getResourceString) Cursor(android.database.Cursor) Notification(android.app.Notification) BigInteger(java.math.BigInteger) SpannableString(android.text.SpannableString) JSONObject(org.json.JSONObject) Random(java.util.Random) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) StyleSpan(android.text.style.StyleSpan) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Aggregations

SpannableString (android.text.SpannableString)325 TextView (android.widget.TextView)61 Spannable (android.text.Spannable)60 View (android.view.View)57 StyleSpan (android.text.style.StyleSpan)53 ForegroundColorSpan (android.text.style.ForegroundColorSpan)47 TextPaint (android.text.TextPaint)25 Spanned (android.text.Spanned)24 TextAppearanceSpan (android.text.style.TextAppearanceSpan)21 Paint (android.graphics.Paint)20 RelativeSizeSpan (android.text.style.RelativeSizeSpan)19 ImageView (android.widget.ImageView)19 Bundle (android.os.Bundle)17 TypedValue (android.util.TypedValue)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)16 Intent (android.content.Intent)15 SpannableStringBuilder (android.text.SpannableStringBuilder)15 ClickableSpan (android.text.style.ClickableSpan)14 URLSpan (android.text.style.URLSpan)13 LayoutInflater (android.view.LayoutInflater)13