List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
From source file:com.tct.mail.browse.ConversationItemView.java
private void createSnippet() { final String snippet = mHeader.conversation.getSnippet(); /// TCT: add for search term highlight // process subject and snippet respectively @{ SpannableStringBuilder snippetToHighlight = new SpannableStringBuilder(snippet); boolean hasFilter = (mSearchParams != null && !TextUtils.isEmpty(mSearchParams.mFilter)); if (hasFilter) { boolean fieldMatchedSnippet = (mSearchParams != null && (SearchParams.SEARCH_FIELD_BODY.equals(mSearchParams.mField) || SearchParams.SEARCH_FIELD_ALL.equals(mSearchParams.mField))); /// TCT: Only highlight un-empty snippet if (fieldMatchedSnippet && !TextUtils.isEmpty(snippet)) { CharSequence snippetChars = TextUtilities.highlightTermsInText(snippet, mSearchParams.mFilter); snippetToHighlight.replace(0, snippet.length(), snippetChars); }/* w w w . j a va 2 s . com*/ } /// @} final Spannable displayedStringBuilder = new SpannableString(snippetToHighlight); // measure the width of the folders which overlap the snippet view final int folderWidth = mHeader.folderDisplayer.measureFolders(mCoordinates); // size the snippet view by subtracting the folder width from the maximum snippet width final int snippetWidth = mCoordinates.maxSnippetWidth - folderWidth; final int snippetHeight = mCoordinates.snippetHeight; mSnippetTextView.setLayoutParams(new ViewGroup.LayoutParams(snippetWidth, snippetHeight)); mSnippetTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mCoordinates.snippetFontSize); layoutViewExactly(mSnippetTextView, snippetWidth, snippetHeight); mSnippetTextView.setText(displayedStringBuilder); }
From source file:mobi.omegacentauri.ptimer.PTimerEditActivity.java
void showServerPrompt(final boolean userInitiated) { final SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); final SpannableString message = new SpannableString(getResources().getText(R.string.server_prompt)); Linkify.addLinks(message, Linkify.ALL); final AlertDialog dialog = new AlertDialog.Builder(PTimerEditActivity.this).setTitle(R.string.server_title) .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); if (userInitiated) { finish();//from w w w . j a v a 2 s .c om } else { sendStatsToServerAndFinish(); } } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { int allowServerCheckIndex = prefs.getInt(PREF_STATS_SERVER_CHECK, 2); int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0); SharedPreferences.Editor prefsEditor = prefs.edit(); if (userInitiated) { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, successCount + 2); } else { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, allowServerCheckIndex * 2); } prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_NO); if (userInitiated) { // If the user initiated, err on the safe side and disable // sending crash reports too. There's no way to turn them // back on now aside from clearing data from this app, but // it doesn't matter, we don't need error reports from every // user ever. prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); } prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.SpeechEd.SpeechEdEditActivity.java
void showServerPrompt(final boolean userInitiated) { final SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); final SpannableString message = new SpannableString(getResources().getText(R.string.server_prompt)); Linkify.addLinks(message, Linkify.ALL); final AlertDialog dialog = new AlertDialog.Builder(SpeechEdEditActivity.this) .setTitle(R.string.server_title).setMessage(message) .setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); if (userInitiated) { finish();// w ww .j a v a 2 s .c o m } else { sendStatsToServerAndFinish(); } } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { int allowServerCheckIndex = prefs.getInt(PREF_STATS_SERVER_CHECK, 2); int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0); SharedPreferences.Editor prefsEditor = prefs.edit(); if (userInitiated) { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, successCount + 2); } else { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, allowServerCheckIndex * 2); } prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_NO); if (userInitiated) { // If the user initiated, err on the safe side and disable // sending crash reports too. There's no way to turn them // back on now aside from clearing data from this app, but // it doesn't matter, we don't need error reports from every // user ever. prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); } prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
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 a2s .c o m 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.Beat.RingdroidEditActivity.java
void showServerPrompt(final boolean userInitiated) { final SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); final SpannableString message = new SpannableString(getResources().getText(R.string.server_prompt)); Linkify.addLinks(message, Linkify.ALL); final AlertDialog dialog = new AlertDialog.Builder(RingdroidEditActivity.this) .setTitle(R.string.server_title).setMessage(message) .setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); if (userInitiated) { finish();//from w w w . ja v a 2 s .c o m } else { sendStatsToServerAndFinish(); } } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { int allowServerCheckIndex = prefs.getInt(PREF_STATS_SERVER_CHECK, 2); int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0); SharedPreferences.Editor prefsEditor = prefs.edit(); if (userInitiated) { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, successCount + 2); } else { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, allowServerCheckIndex * 2); } prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_NO); if (userInitiated) { // If the user initiated, err on the safe side and disable // sending crash reports too. There's no way to turn them // back on now aside from clearing data from this app, but // it doesn't matter, we don't need error reports from every // user ever. prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); } prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.android.ex.chips.RecipientEditTextView.java
private CharSequence createChip(final RecipientEntry entry, final boolean pressed) { final String displayText = createAddressText(entry); if (TextUtils.isEmpty(displayText)) return null; SpannableString chipText = null;//from ww w . ja v a 2 s.c om // Always leave a blank space at the end of a chip. final int textLength = displayText.length() - 1; chipText = new SpannableString(displayText); if (!mNoChips) try { final DrawableRecipientChip chip = constructChipSpan(entry, pressed, false /* * leave space for contact * icon */); chipText.setSpan(chip, 0, textLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); chip.setOriginalText(chipText.toString()); } catch (final NullPointerException e) { Log.e(TAG, e.getMessage(), e); return null; } return chipText; }
From source file:com.ichi2.anki.AbstractFlashcardViewer.java
protected void updateScreenCounts() { if (mCurrentCard == null) { return;//from w w w . j av a2s .co m } try { String[] title = getCol().getDecks().get(mCurrentCard.getDid()).getString("name").split("::"); getSupportActionBar().setTitle(title[title.length - 1]); } catch (JSONException e) { throw new RuntimeException(e); } int[] counts = mSched.counts(mCurrentCard); int eta = mSched.eta(counts, false); getSupportActionBar() .setSubtitle(getResources().getQuantityString(R.plurals.reviewer_window_title, eta, eta)); SpannableString newCount = new SpannableString(String.valueOf(counts[0])); SpannableString lrnCount = new SpannableString(String.valueOf(counts[1])); SpannableString revCount = new SpannableString(String.valueOf(counts[2])); if (mPrefHideDueCount) { revCount = new SpannableString("???"); } switch (mSched.countIdx(mCurrentCard)) { case Card.TYPE_NEW: newCount.setSpan(new UnderlineSpan(), 0, newCount.length(), 0); break; case Card.TYPE_LRN: lrnCount.setSpan(new UnderlineSpan(), 0, lrnCount.length(), 0); break; case Card.TYPE_REV: revCount.setSpan(new UnderlineSpan(), 0, revCount.length(), 0); break; } mTextBarNew.setText(newCount); mTextBarLearn.setText(lrnCount); mTextBarReview.setText(revCount); }
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 . ja v a2 s.c o m * @param senders Sender of the new message that triggered the notification. * @param subject Subject of the new message that triggered the notification * @param snippet Snippet of the new message that triggered the notification * @return a {@link CharSequence} suitable for use in * {@link android.support.v4.app.NotificationCompat.BigTextStyle} */ private static CharSequence getSingleMessageInboxLine(Context context, String senders, String subject, String snippet) { // TODO(cwren) finish this step toward commmon code with getSingleMessageBigText final String subjectSnippet = !TextUtils.isEmpty(subject) ? subject : snippet; final TextAppearanceSpan notificationPrimarySpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText); if (TextUtils.isEmpty(senders)) { // If the senders are empty, just use the subject/snippet. return subjectSnippet; } else if (TextUtils.isEmpty(subjectSnippet)) { // If the subject/snippet is empty, just use the senders. final SpannableString spannableString = new SpannableString(senders); spannableString.setSpan(notificationPrimarySpan, 0, senders.length(), 0); return spannableString; } else { final String formatString = context.getResources() .getString(R.string.multiple_new_message_notification_item); final TextAppearanceSpan notificationSecondarySpan = new TextAppearanceSpan(context, R.style.NotificationSecondaryText); // senders is already individually unicode wrapped so it does not need to be done here final String instantiatedString = String.format(formatString, senders, sBidiFormatter.unicodeWrap(subjectSnippet)); final SpannableString spannableString = new SpannableString(instantiatedString); final boolean isOrderReversed = formatString.indexOf("%2$s") < formatString.indexOf("%1$s"); final int primaryOffset = (isOrderReversed ? instantiatedString.lastIndexOf(senders) : instantiatedString.indexOf(senders)); final int secondaryOffset = (isOrderReversed ? instantiatedString.lastIndexOf(subjectSnippet) : instantiatedString.indexOf(subjectSnippet)); spannableString.setSpan(notificationPrimarySpan, primaryOffset, primaryOffset + senders.length(), 0); spannableString.setSpan(notificationSecondarySpan, secondaryOffset, secondaryOffset + subjectSnippet.length(), 0); return spannableString; } }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Handles the manual selection of suggestions from the suggestion bar * @param index the position of the suggestion in the suggestion list *//*from ww w .ja v a 2 s .c o m*/ public void pickSuggestionManually(int index) { if (mCompletionOn && mCompletions != null && index >= 0 && index < mCompletions.length) { CompletionInfo ci = mCompletions[index]; ic.commitCompletion(ci); if (mCandidateView != null) { mCandidateView.clear(); } updateShiftKeyState(getCurrentInputEditorInfo()); } else if (mComposing.length() >= 0) { String picked; if (!replacemode) picked = suggestions.get(index) + " "; else picked = suggestions.get(index); //Log.i("Suggestion picked 2", picked); //ic.commitText(picked, picked.length()); getCurrentInputEditorInfo(); //colour the text according to user preferences SpannableString text = new SpannableString(picked); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (sharedPrefs.getBoolean("suggestion_highlight", false)) text.setSpan(new BackgroundColorSpan(suggestion), 0, picked.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); currentSession.nSuggestionsPicked++; if (replacemode) { replacemode = false; //remove from list of autocorrected words. //Log.i("PickSuggestion", "Removed "+autocorrected_words.remove(text.toString())); //find the current word extr = ic.getExtractedText(new ExtractedTextRequest(), 0); WordDetails w = findWord(extr.selectionStart, extr.text); //Log.i("FindWord", w.word+", "+w.wordStart+" - "+w.wordEnd); ic.setComposingRegion(w.wordStart, w.wordEnd); text.setSpan(null, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); /* //clear any spans BackgroundColorSpan[] spans=(new SpannableString(extr.text.toString())).getSpans(w.wordStart, w.wordEnd, BackgroundColorSpan.class); for(int i=0; i<spans.length; i++){ text.removeSpan(spans[i]); }*/ //commit the update ic.commitText(text, 1); } else ic.commitText(text, picked.length()); coreEngine.resetCoreString(); coreEngine.insertText(picked); mComposing.setLength(0); updateCandidates(); } }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Sets the bigtext for a notification for a single new conversation * @param context//from ww w . j a v a 2 s. co 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; }