List of usage examples for android.text SpannableString setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:liqui.droid.activity.Base.java
/** * Creates the breadcrumb./*from w w w . j a v a 2 s . co m*/ * * @param subTitle the sub title * @param breadCrumbHolders the bread crumb holders */ public void createBreadcrumb(String subTitle, BreadCrumbHolder... breadCrumbHolders) { if (breadCrumbHolders != null) { LinearLayout llPart = (LinearLayout) this.findViewById(R.id.ll_part); for (int i = 0; i < breadCrumbHolders.length; i++) { TextView tvBreadCrumb = new TextView(getApplication()); SpannableString part = new SpannableString(breadCrumbHolders[i].getLabel()); part.setSpan(new UnderlineSpan(), 0, part.length(), 0); tvBreadCrumb.append(part); tvBreadCrumb.setTag(breadCrumbHolders[i]); tvBreadCrumb.setBackgroundResource(R.drawable.default_link); tvBreadCrumb.setTextAppearance(getApplication(), R.style.default_text_small); tvBreadCrumb.setSingleLine(true); tvBreadCrumb.setOnClickListener(new OnClickBreadCrumb(this)); llPart.addView(tvBreadCrumb); if (i < breadCrumbHolders.length - 1) { TextView slash = new TextView(getApplication()); slash.setText(" / "); slash.setTextAppearance(getApplication(), R.style.default_text_small); llPart.addView(slash); } } } ScrollingTextView tvSubtitle = (ScrollingTextView) this.findViewById(R.id.tv_subtitle); tvSubtitle.setText(subTitle); }
From source file:com.zd.vpn.fragments.AboutFragment.java
private void createPlayBuyOptions(ArrayList<String> ownedSkus, ArrayList<String> responseList) { try {/*w w w. java2s .com*/ Vector<Pair<String, String>> gdonation = new Vector<Pair<String, String>>(); gdonation.add(new Pair<String, String>(getString(R.string.donatePlayStore), null)); HashMap<String, SkuResponse> responseMap = new HashMap<String, SkuResponse>(); for (String thisResponse : responseList) { JSONObject object = new JSONObject(thisResponse); responseMap.put(object.getString("productId"), new SkuResponse(object.getString("price"), object.getString("title"))); } for (String sku : donationSkus) if (responseMap.containsKey(sku)) gdonation.add( getSkuTitle(sku, responseMap.get(sku).title, responseMap.get(sku).price, ownedSkus)); String gmsTextString = ""; for (int i = 0; i < gdonation.size(); i++) { if (i == 1) gmsTextString += " "; else if (i > 1) gmsTextString += ", "; gmsTextString += gdonation.elementAt(i).first; } SpannableString gmsText = new SpannableString(gmsTextString); int lStart = 0; int lEnd = 0; for (Pair<String, String> item : gdonation) { lEnd = lStart + item.first.length(); if (item.second != null) { final String mSku = item.second; ClickableSpan cspan = new ClickableSpan() { @Override public void onClick(View widget) { triggerBuy(mSku); } }; gmsText.setSpan(cspan, lStart, lEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } lStart = lEnd + 2; // Account for ", " between items } if (gmsTextView != null) { gmsTextView.setText(gmsText); gmsTextView.setMovementMethod(LinkMovementMethod.getInstance()); gmsTextView.setVisibility(View.VISIBLE); } } catch (JSONException e) { VpnStatus.logException("Parsing Play Store IAP", e); } }
From source file:info.guardianproject.otr.app.im.app.MessageView.java
private CharSequence formatPresenceUpdates(String contact, int type, boolean isGroupChat, boolean scrolling) { String body;//from www . j ava 2 s .c o m Resources resources = getResources(); switch (type) { case Imps.MessageType.PRESENCE_AVAILABLE: body = resources.getString(isGroupChat ? R.string.contact_joined : R.string.contact_online, contact); break; case Imps.MessageType.PRESENCE_AWAY: body = resources.getString(R.string.contact_away, contact); break; case Imps.MessageType.PRESENCE_DND: body = resources.getString(R.string.contact_busy, contact); break; case Imps.MessageType.PRESENCE_UNAVAILABLE: body = resources.getString(isGroupChat ? R.string.contact_left : R.string.contact_offline, contact); break; default: return null; } if (scrolling) { return body; } else { SpannableString spanText = new SpannableString(body); int len = spanText.length(); spanText.setSpan(new StyleSpan(Typeface.ITALIC), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spanText.setSpan(new RelativeSizeSpan((float) 0.8), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanText; } }
From source file:com.android.mms.transaction.MessagingNotification.java
protected static CharSequence buildTickerMessage(Context context, String address, String subject, String body) { String displayAddress = Contact.get(address, true).getName(); StringBuilder buf = new StringBuilder( displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' ')); if (!TextUtils.isEmpty(subject) && !TextUtils.isEmpty(body)) { buf.append(':').append(' '); }/*from w w w .j a v a 2 s . com*/ int offset = buf.length(); if (!TextUtils.isEmpty(subject)) { subject = subject.replace('\n', ' ').replace('\r', ' '); buf.append(subject); buf.append(' '); } if (!TextUtils.isEmpty(body)) { body = body.replace('\n', ' ').replace('\r', ' '); buf.append(body); } SpannableString spanText = new SpannableString(buf.toString()); spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanText; }
From source file:com.todoroo.astrid.adapter.TaskAdapter.java
private Function<TagData, SpannableString> tagToString(final float maxLength) { return tagData -> { String tagName = tagData.getName(); tagName = tagName.substring(0, Math.min(tagName.length(), (int) maxLength)); SpannableString string = new SpannableString(SPACE + tagName + SPACE); int themeIndex = tagData.getColor(); ThemeColor color = themeIndex >= 0 ? themeCache.getThemeColor(themeIndex) : themeCache.getUntaggedColor(); string.setSpan(new BackgroundColorSpan(color.getPrimaryColor()), 0, string.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); string.setSpan(new ForegroundColorSpan(color.getActionBarTint()), 0, string.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return string; };//w w w . ja v a2 s . c o m }
From source file:com.onesignal.GenerateNotification.java
static void createSummaryNotification(Context inContext, boolean updateSummary, JSONObject gcmBundle) { if (updateSummary) setStatics(inContext);/* ww w. jav a 2 s . c om*/ String group = null; try { group = gcmBundle.getString("grp"); } catch (Throwable t) { } Random random = new Random(); PendingIntent summaryDeleteIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseDeleteIntent(0).putExtra("summary", group)); OneSignalDbHelper dbHelper = new OneSignalDbHelper(currentContext); SQLiteDatabase writableDb = dbHelper.getWritableDatabase(); 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[] whereArgs = { group }; Cursor cursor = writableDb.query(NotificationTable.TABLE_NAME, retColumn, NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + // Where String NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED + " = 0", whereArgs, null, // group by null, // filter by row groups NotificationTable._ID + " DESC" // sort order, new to old ); Notification summaryNotification; int summaryNotificationId = random.nextInt(); String firstFullData = null; Collection<SpannableString> summeryList = null; if (cursor.moveToFirst()) { SpannableString spannableString; summeryList = new ArrayList<SpannableString>(); 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); summeryList.add(spannableString); if (firstFullData == null) firstFullData = cursor .getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_FULL_DATA)); } } while (cursor.moveToNext()); if (updateSummary) { try { gcmBundle = new JSONObject(firstFullData); } catch (JSONException e) { e.printStackTrace(); } } } if (summeryList != null && (!updateSummary || summeryList.size() > 1)) { int notificationCount = summeryList.size() + (updateSummary ? 0 : 1); String summaryMessage = null; if (gcmBundle.has("grp_msg")) { try { summaryMessage = gcmBundle.getString("grp_msg").replace("$[notif_count]", "" + notificationCount); } catch (Throwable t) { } } if (summaryMessage == null) summaryMessage = notificationCount + " new messages"; JSONObject summaryDataBundle = new JSONObject(); try { summaryDataBundle.put("alert", summaryMessage); } catch (JSONException e) { e.printStackTrace(); } Intent summaryIntent = getNewBaseIntent(summaryNotificationId).putExtra("summary", group) .putExtra("onesignal_data", summaryDataBundle.toString()); PendingIntent summaryContentIntent = getNewActionPendingIntent(random.nextInt(), summaryIntent); NotificationCompat.Builder summeryBuilder = getBaseNotificationCompatBuilder(gcmBundle, !updateSummary); summeryBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent) .setContentTitle(currentContext.getPackageManager() .getApplicationLabel(currentContext.getApplicationInfo())) .setContentText(summaryMessage).setNumber(notificationCount).setOnlyAlertOnce(updateSummary) .setGroup(group).setGroupSummary(true); if (!updateSummary) summeryBuilder.setTicker(summaryMessage); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String line1Title = null; // Add the latest notification to the summary if (!updateSummary) { try { line1Title = gcmBundle.getString("title"); } catch (Throwable t) { } if (line1Title == null) line1Title = ""; else line1Title += " "; String message = ""; try { message = gcmBundle.getString("alert"); } catch (Throwable t) { } 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 : summeryList) inboxStyle.addLine(line); inboxStyle.setBigContentTitle(summaryMessage); summeryBuilder.setStyle(inboxStyle); summaryNotification = summeryBuilder.build(); } else { // There currently isn't a visible notification from this group, save the group summary notification id and post it so it looks like a normal notification. ContentValues values = new ContentValues(); values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, summaryNotificationId); values.put(NotificationTable.COLUMN_NAME_GROUP_ID, group); values.put(NotificationTable.COLUMN_NAME_IS_SUMMARY, 1); writableDb.insert(NotificationTable.TABLE_NAME, null, values); NotificationCompat.Builder notifBuilder = getBaseNotificationCompatBuilder(gcmBundle, !updateSummary); PendingIntent summaryContentIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseIntent(summaryNotificationId).putExtra("onesignal_data", gcmBundle.toString()) .putExtra("summary", group)); addNotificationActionButtons(gcmBundle, notifBuilder, summaryNotificationId, group); notifBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent) .setOnlyAlertOnce(updateSummary).setGroup(group).setGroupSummary(true); summaryNotification = notifBuilder.build(); } NotificationManagerCompat.from(currentContext).notify(summaryNotificationId, summaryNotification); cursor.close(); writableDb.close(); }
From source file:com.darly.im.ui.CCPActivityBase.java
/** * */// w w w. java 2s. c o m protected SpannableString buildActionTitle() { int dimensionPixelSize = mActionBarActivity.getResources().getDimensionPixelSize(R.dimen.BigTextSize); int mutIndex = 0; String format = "%s"; if (isMute) { format = format + " #"; mutIndex += 2; } SpannableString spannableString = EmoticonUtil.getTextFormat(mActionBarActivity, String.format(format, new Object[] { mTitleText }), dimensionPixelSize); if (isMute) { if (mMuteIcon == null) { mMuteIcon = getTitleIconTips(dimensionPixelSize, R.drawable.chat_mute_notify_title_icon); } int length = spannableString.length() - mutIndex + 1; spannableString.setSpan(mMuteIcon, length, length + 1, Spanned.SPAN_POINT_MARK); } return spannableString; }
From source file:com.android.mms.transaction.MessagingNotification.java
private static CharSequence getAttachmentTypeString(Context context, int attachmentType) { final TextAppearanceSpan notificationAttachmentSpan = new TextAppearanceSpan(context, R.style.NotificationSecondaryText); int id = 0;/*from w w w .j a v a 2 s .c o m*/ switch (attachmentType) { case WorkingMessage.AUDIO: id = R.string.attachment_audio; break; case WorkingMessage.VIDEO: id = R.string.attachment_video; break; case WorkingMessage.SLIDESHOW: id = R.string.attachment_slideshow; break; case WorkingMessage.IMAGE: id = R.string.attachment_picture; break; } if (id > 0) { final SpannableString spannableString = new SpannableString(context.getString(id)); spannableString.setSpan(notificationAttachmentSpan, 0, spannableString.length(), 0); return spannableString; } return null; }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Sets the bigtext for a notification for a single new conversation * @param context/*from w w w . j ava2 s . c o m*/ * @param subject Subject of the new message that triggered the notification * @return a {@link CharSequence} suitable for use in * {@link NotificationCompat.Builder#setContentText} */ private static CharSequence getSingleMessageLittleText(Context context, String subject) { final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText); final SpannableString spannableString = new SpannableString(subject); spannableString.setSpan(notificationSubjectSpan, 0, subject.length(), 0); return spannableString; }
From source file:com.fastbootmobile.encore.app.fragments.ListenNowFragment.java
/** * Default empty constructor//w w w . j av a 2 s .co m */ public ListenNowFragment() { mScrollListener = new ScrollStatusBarColorListener() { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (view.getChildCount() == 0 || getActivity() == null) { return; } final float heroHeight = mHeaderView.getMeasuredHeight(); final float scrollY = getScroll(view); final float toolbarBgAlpha = Math.min(1, scrollY / heroHeight); final int toolbarAlphaInteger = (((int) (toolbarBgAlpha * 255)) << 24) | 0xFFFFFF; mColorDrawable.setColor(toolbarAlphaInteger & mBackgroundColor); SpannableString spannableTitle = new SpannableString( ((MainActivity) getActivity()).getFragmentTitle()); mAlphaSpan.setAlpha(toolbarBgAlpha); ActionBar actionbar = ((AppActivity) getActivity()).getSupportActionBar(); if (actionbar != null) { actionbar.setBackgroundDrawable(mColorDrawable); spannableTitle.setSpan(mAlphaSpan, 0, spannableTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); actionbar.setTitle(spannableTitle); } mCardSearchBox.setAlpha(1.0f - toolbarBgAlpha); } }; }