List of usage examples for android.text SpannableStringBuilder append
public SpannableStringBuilder append(char text)
From source file:com.yangtsaosoftware.pebblemessenger.activities.SetupFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 3) { if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { myTTS = new TextToSpeech(_context, this); } else {// w w w .ja va 2s .c om SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(textInfo.getText()); ssb.append(redText(R.string.setup_tts_failed)); ssb.append('\n'); textInfo.setText(ssb); svMyview.fullScroll(View.FOCUS_DOWN); } } }
From source file:com.yangtsaosoftware.pebblemessenger.activities.SetupFragment.java
private void run_tts_test() { SpannableStringBuilder ssb = new SpannableStringBuilder(textInfo.getText()); ssb.append(_context.getString(R.string.setup_tts_test)); ssb.append('\n'); ssb.append(_context.getString(R.string.setup_tts_engine)); textInfo.setText(ssb);//w ww . j ava2 s .c o m svMyview.fullScroll(View.FOCUS_DOWN); Intent checkIntent = new Intent(); checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); getActivity().startActivityFromFragment(SetupFragment.this, checkIntent, 3); }
From source file:com.murrayc.galaxyzoo.app.ZooFragment.java
private void showAbout() { final Activity activity = getActivity(); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); // Get the layout inflater final LayoutInflater inflater = activity.getLayoutInflater(); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout final View view = inflater.inflate(R.layout.about, null); builder.setView(view);/*from w w w . jav a 2 s .c om*/ final TextView textView = (TextView) view.findViewById(R.id.textViewAbout); if (textView == null) { Log.error("showAbout: textView was null."); return; } //This voodoo makes the textviews' HTML links clickable: //See http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable/20647011#20647011 textView.setMovementMethod(LinkMovementMethod.getInstance()); final String versionText = String.format(getString(R.string.about_version_text_format), BuildConfig.VERSION_NAME); //The about dialog's text is split into multiple strings to make translation easier, //so we need to concatenate them here. //Note that we use getText(), not getString(), //so we don't lose the <a href=""> links. //Likewise, we use SpannableStringBuilder instead of StringBuilder, //because we lose the links when using StringBuilder. final SpannableStringBuilder strBuilder = new SpannableStringBuilder(); final String PARAGRAPH_BREAK = "\n\n"; strBuilder.append(versionText); strBuilder.append(PARAGRAPH_BREAK); strBuilder.append(getText(R.string.about_text1)); strBuilder.append(PARAGRAPH_BREAK); strBuilder.append(getText(R.string.about_text2)); strBuilder.append(PARAGRAPH_BREAK); strBuilder.append(getText(R.string.about_text3)); strBuilder.append(PARAGRAPH_BREAK); strBuilder.append(getText(R.string.about_text3b)); strBuilder.append(PARAGRAPH_BREAK); strBuilder.append(getText(R.string.about_text4)); strBuilder.append(PARAGRAPH_BREAK); strBuilder.append(getText(R.string.about_text5)); strBuilder.append(PARAGRAPH_BREAK); strBuilder.append(getText(R.string.about_text6)); textView.setText(strBuilder); /* We used to put the version text into a separate TextView, but when the about text in textView is too long, the scroll never reaches this far. It does work when we add it to first regular textView. */ /* final TextView textViewVersion = (TextView) view.findViewById(R.id.textViewVersion); if (textViewVersion != null) { textViewVersion.setText(versionText); } */ final AlertDialog dialog = builder.create(); dialog.setTitle(R.string.app_name); dialog.setIcon(R.mipmap.ic_launcher); dialog.show(); }
From source file:com.yangtsaosoftware.pebblemessenger.activities.SetupFragment.java
private void test_pebble_app(Context context) { BroadcastReceiver br = new BroadcastReceiver() { @Override//from ww w. j av a2s. c o m public void onReceive(Context context, Intent intent) { byte[] command = intent.getByteArrayExtra(Constants.BROADCAST_VERSION); boolean result = true; if (command == null || command[0] < Constants.PEBBLE_VERSION[0]) { result = false; } else if (command[1] < Constants.PEBBLE_VERSION[1]) { result = false; } else if (command[2] < Constants.PEBBLE_VERSION[2]) { result = false; } SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(textInfo.getText()); ssb.append(context.getString(R.string.setup_app_test)); ssb.append('\n'); ssb.append(context.getString(R.string.setup_install_pebble_app)); ssb.append((result ? greenText(R.string.setup_check_ok) : redText(R.string.setup_check_bad))); ssb.append('\n'); textInfo.setText(ssb); svMyview.fullScroll(View.FOCUS_DOWN); LocalBroadcastManager.getInstance(context).unregisterReceiver(this); } }; IntentFilter intentFilter = new IntentFilter(SetupFragment.class.getName()); LocalBroadcastManager.getInstance(context).registerReceiver(br, intentFilter); Intent inner_intent = new Intent(PebbleCenter.class.getName()); inner_intent.putExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_PEBBLE_TEST); LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent); }
From source file:com.groksolutions.grok.mobile.annotation.AnnotationListFragment.java
/** * Format annotation message body for list item display * * @param annotation The annotation to format * * @return The formatted annotation text suitable for use with {@link android.widget.TextView} *///from ww w . ja va 2s .c o m SpannableStringBuilder formatAnnotationBody(Annotation annotation) { int pos; // Format text SpannableStringBuilder text = new SpannableStringBuilder(); // <br/> My Message pos = text.length(); text.append(annotation.getMessage()); text.setSpan(new RelativeSizeSpan(1.0f), pos, text.length(), 0); text.setSpan(new StyleSpan(Typeface.NORMAL), pos, text.length(), 0); // Attach hidden annotation ID to the text. // This ID is used by the actions attached to the list text.setSpan(new android.text.Annotation("id", annotation.getId()), 0, text.length(), 0); return text; }
From source file:com.uwetrottmann.wpdisplay.ui.DisplayFragment.java
private void setText(TextView view, int labelResId, String value) { SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(getString(labelResId)); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_AppCompat_Caption), 0, builder.length(), 0);/*ww w. ja v a 2 s .c o m*/ builder.append("\n"); int lengthOld = builder.length(); builder.append(value); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_AppCompat_Display1), lengthOld, builder.length(), 0); view.setText(builder); }
From source file:com.android.messaging.datamodel.BugleNotifications.java
static CharSequence formatAttachmentTag(final String author, final String attachmentType) { final Context context = Factory.get().getApplicationContext(); final TextAppearanceSpan notificationSecondaryText = new TextAppearanceSpan(context, R.style.NotificationSecondaryText); final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); if (!TextUtils.isEmpty(author)) { final TextAppearanceSpan notificationSenderSpan = new TextAppearanceSpan(context, R.style.NotificationSenderText); spannableStringBuilder.append(author); spannableStringBuilder.setSpan(notificationSenderSpan, 0, author.length(), 0); final String separator = context.getString(R.string.notification_separator); spannableStringBuilder.append(separator); }// ww w .jav a 2 s. c om final int start = spannableStringBuilder.length(); // The default attachment type is an image, since that's what was originally // supported. When there's no content type, assume it's an image. int message = R.string.notification_picture; if (ContentType.isAudioType(attachmentType)) { message = R.string.notification_audio; } else if (ContentType.isVideoType(attachmentType)) { message = R.string.notification_video; } else if (ContentType.isVCardType(attachmentType)) { message = R.string.notification_vcard; } spannableStringBuilder.append(context.getText(message)); spannableStringBuilder.setSpan(notificationSecondaryText, start, spannableStringBuilder.length(), 0); return spannableStringBuilder; }
From source file:com.oasisfeng.nevo.decorators.StackDecorator.java
@Override public void apply(final StatusBarNotificationEvo evolved) throws RemoteException { final Collection<StatusBarNotificationEvo> history = getArchivedNotifications(evolved.getKey(), KMaxNumLines);/*www. j av a 2s . c om*/ if (history.size() <= 1) return; final INotification evolved_n = evolved.notification(); final IBundle evolved_extras = evolved_n.extras(); if (evolved_extras.containsKey(EXTRA_TEXT_LINES)) return; // Never stack already inbox-styled notification. final Calendar calendar = Calendar.getInstance(); final List<CharSequence> lines = new ArrayList<>(KMaxNumLines); long previous_when = 0; final long latest_when = evolved_n.getWhen(); for (final StatusBarNotificationEvo sbn : history) { final INotification n = sbn.notification(); final CharSequence text = n.extras().getCharSequence(NotificationCompat.EXTRA_TEXT); if (text == null) continue; final long when = n.getWhen(); if (when == latest_when || Math.abs(when - previous_when) <= KMinIntervalToShowTimestamp) lines.add(text); else { // Add time-stamp final SpannableStringBuilder line = new SpannableStringBuilder(); calendar.setTimeInMillis(when); final String time_text = String.format((Locale) null, "%1$02d:%2$02d ", calendar.get(HOUR_OF_DAY), calendar.get(MINUTE)); line.append(time_text); line.append(text); line.setSpan(new StyleSpan(Typeface.BOLD), 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); lines.add(line); } previous_when = when; } if (lines.isEmpty()) return; Collections.reverse(lines); // Latest first, since earliest lines will be trimmed by InboxStyle. final CharSequence title = evolved_extras.getCharSequence(NotificationCompat.EXTRA_TITLE); evolved_extras.putCharSequence(NotificationCompat.EXTRA_TITLE_BIG, title); evolved_extras.putCharSequenceArray(EXTRA_TEXT_LINES, lines); evolved_n.setBigContentView(buildBigContentView(evolved.getPackageName(), title, lines)); }
From source file:com.uwetrottmann.wpdisplay.ui.DisplayFragment.java
private void setTemperature(TextView view, int labelResId, double value) { SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(getString(labelResId)); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_AppCompat_Caption), 0, builder.length(), 0);/*from www .ja va 2 s . co m*/ builder.append("\n"); int lengthOld = builder.length(); builder.append(String.format(Locale.getDefault(), "%.1f", value)); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_AppCompat_Display3), lengthOld, builder.length(), 0); lengthOld = builder.length(); builder.append(getString(R.string.unit_celsius)); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_App_Unit), lengthOld, builder.length(), 0); view.setText(builder); }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void handleP(SpannableStringBuilder text, int startLength, int[] lastPTagLengthRefs) { lastPTagLengthRefs[0] = text.length(); int len = text.length() - startLength; if (len >= 1 && text.charAt(text.length() - 1) == '\n') { if (len >= 2 && text.charAt(text.length() - 2) == '\n') { lastPTagLengthRefs[1] = text.length(); return; }// w w w. j a v a2 s . co m text.append("\n"); lastPTagLengthRefs[1] = text.length(); return; } if (len != 0) { text.append("\n\n"); } lastPTagLengthRefs[1] = text.length(); }