List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder
public SpannableStringBuilder()
From source file:com.googlecode.eyesfree.brailleback.NodeBrailler.java
/** * Formats {@code node} and its descendants, appending the result * to {@code sb}.//from ww w . j a va 2 s . com */ private void formatSubtree(AccessibilityNodeInfoCompat node, Editable result) { if (!node.isVisibleToUser()) { return; } BrailleRule rule = mRuleRepository.find(node); SpannableStringBuilder subtreeResult = new SpannableStringBuilder(); rule.format(subtreeResult, mContext, node); if (rule.includeChildren(node, mContext)) { int childCount = node.getChildCount(); for (int i = 0; i < childCount; ++i) { AccessibilityNodeInfoCompat child = node.getChild(i); if (child == null) { continue; } formatSubtree(child, subtreeResult); child.recycle(); } } if (!TextUtils.isEmpty(subtreeResult)) { // If the node is accessibility focused, add the focus span // here to cover the node and its formatted children. // This is a fallback in case the formatting rule hasn't set // focus by itself. if (node.isAccessibilityFocused() && subtreeResult.getSpans(0, subtreeResult.length(), DisplaySpans.FocusSpan.class).length == 0) { DisplaySpans.addFocus(subtreeResult, 0, subtreeResult.length()); } addNodeSpanForUncovered(node, subtreeResult); StringUtils.appendWithSpaces(result, subtreeResult); } }
From source file:org.mariotaku.twidere.view.NameView.java
public void updateText(@Nullable BidiFormatter formatter) { final SpannableStringBuilder sb = new SpannableStringBuilder(); final String primaryText = mNameFirst ? mName : mScreenName; final String secondaryText = mNameFirst ? mScreenName : mName; if (primaryText != null) { int start = sb.length(); if (formatter != null && !isInEditMode()) { sb.append(formatter.unicodeWrap(primaryText)); } else {//w ww. j av a 2s. co m sb.append(primaryText); } int end = sb.length(); sb.setSpan(mPrimaryTextColor, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sb.setSpan(mPrimaryTextStyle, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sb.setSpan(mPrimaryTextSize, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } sb.append(mTwoLine ? '\n' : ' '); if (secondaryText != null) { int start = sb.length(); if (formatter != null && !isInEditMode()) { sb.append(formatter.unicodeWrap(secondaryText)); } else { sb.append(secondaryText); } int end = sb.length(); sb.setSpan(mSecondaryTextColor, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sb.setSpan(mSecondaryTextStyle, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sb.setSpan(mSecondaryTextSize, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } setText(sb); }
From source file:com.oasisfeng.nevo.decorators.whatsapp.WhatsAppDecorator.java
@Override public void apply(final StatusBarNotificationEvo evolving) throws RemoteException { final INotification n = evolving.notification(); final IBundle extras = n.extras(); final CharSequence who, group, message; @SuppressWarnings("unchecked") final List<CharSequence> lines = extras.getCharSequenceArray(EXTRA_TEXT_LINES); final boolean has_lines = lines != null && !lines.isEmpty(); final CharSequence title = extras.getCharSequence(EXTRA_TITLE); final CharSequence last = has_lines ? lines.get(lines.size() - 1) : extras.getCharSequence(EXTRA_TEXT); final CharSequence[] last_parts = extract(title, last); who = last_parts[0];//from w ww.j av a2s . c o m group = last_parts[1]; message = last_parts[2]; if (group != null) evolving.setTag(".Group"); else if (who != null) evolving.setTag(".Direct"); else return; // Nothing to do for other messages. final CharSequence new_title = group != null ? group : who; evolving.setId(new_title.toString().hashCode()); if (n.getColor() == 0) n.setColor(DEFAULT_COLOR); // Fix the missing color in some notifications if (!has_lines) return; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) n.removeFlags(Notification.FLAG_GROUP_SUMMARY); else extras.remove("android.support.isGroupSummary"); extras.putCharSequence(EXTRA_TITLE, new_title); extras.putCharSequence(EXTRA_TITLE_BIG, new_title); extras.putCharSequence(EXTRA_TEXT, group != null ? who + ": " + message : message); final List<CharSequence> new_lines = new ArrayList<>(lines.size()); for (final CharSequence line : lines) { final CharSequence[] parts = extract(title, line); if (group != null) { // Group chat, keep messages within the same group. if (!group.equals(parts[1])) continue; final SpannableStringBuilder new_line = new SpannableStringBuilder(); new_line.append(parts[0]).setSpan(new StyleSpan(BOLD), 0, new_line.length(), SPAN_EXCLUSIVE_EXCLUSIVE); new_lines.add(new_line.append(": ").append(parts[2])); } else if (who.equals(parts[0]) && parts[1] == null) new_lines.add(parts[2]); // Direct chat, keep messages from the same person (excluding group chat) } extras.putCharSequenceArray(EXTRA_TEXT_LINES, new_lines); extras.remove(EXTRA_SUMMARY_TEXT); extras.putString(EXTRA_REBUILD_STYLE, STYLE_INBOX); if (new_lines.size() > 1) n.setNumber(new_lines.size()); }
From source file:fi.iki.murgo.irssinotifier.InitialSettingsActivity.java
private void checkLicense() { LicenseCheckingTask task = new LicenseCheckingTask(this, "", getString(R.string.verifying_license)); task.setCallback(new Callback<LicenseCheckingTask.LicenseCheckingMessage>() { public void doStuff(LicenseCheckingTask.LicenseCheckingMessage result) { switch (result.licenseCheckingStatus) { case Allow: whatNext(3);//from w ww . ja va 2 s. c o m break; case Disallow: preferences.setLicenseCount(0); MessageBox.Show(InitialSettingsActivity.this, getString(R.string.not_licensed_title), getString(R.string.not_licensed), errorCallback); break; case Error: MessageBox.Show(InitialSettingsActivity.this, getText(R.string.licensing_error_title), new SpannableStringBuilder().append(getText(R.string.license_error)) .append(result.errorMessage), errorCallback); break; } } }); task.execute(); }
From source file:com.android.screenspeak.speechrules.NodeSpeechRuleProcessor.java
/** * Returns the best description for the subtree rooted at * {@code announcedNode}./*from ww w . jav a 2s . c o m*/ * * @param announcedNode The root node of the subtree to describe. * @param event The source event, may be {@code null} when called with * non-source nodes. * @param source The event's source node. * @return The best description for a node. */ public CharSequence getDescriptionForTree(AccessibilityNodeInfoCompat announcedNode, AccessibilityEvent event, AccessibilityNodeInfoCompat source) { if (announcedNode == null) { return null; } final SpannableStringBuilder builder = new SpannableStringBuilder(); Set<AccessibilityNodeInfoCompat> visitedNodes = new HashSet<>(); appendDescriptionForTree(announcedNode, builder, event, source, visitedNodes); AccessibilityNodeInfoUtils.recycleNodes(visitedNodes); formatTextWithLabel(announcedNode, builder); appendRootMetadataToBuilder(announcedNode, builder); return builder; }
From source file:com.yelinaung.karrency.app.ui.HomeActivity.java
private void firstTimeTask() { if (SharePrefUtils.getInstance(getApplicationContext()).isFirstTime()) { lastSync.setVisibility(View.GONE); } else {/*from www .j av a2s .com*/ String time = SharePrefUtils.getInstance(getApplicationContext()).getTime(); SpannableStringBuilder lastSyncTime = new SpannableStringBuilder(); lastSyncTime.append(Html.fromHtml(getString(R.string.sync_time, time))); lastSync.setText(lastSyncTime); } }
From source file:com.google.android.marvin.mytalkback.speechrules.NodeSpeechRuleProcessor.java
/** * Returns the best description for the subtree rooted at * {@code announcedNode}./* w ww . ja v a 2 s . c o m*/ * * @param announcedNode The root node of the subtree to describe. * @param event The source event, may be {@code null} when called with * non-source nodes. * @param source The event's source node. * @return The best description for a node. */ public CharSequence getDescriptionForTree(AccessibilityNodeInfoCompat announcedNode, AccessibilityEvent event, AccessibilityNodeInfoCompat source) { if (announcedNode == null) { return null; } final SpannableStringBuilder builder = new SpannableStringBuilder(); appendDescriptionForTree(announcedNode, builder, event, source); formatTextWithLabel(announcedNode, builder); appendRootMetadataToBuilder(announcedNode, builder); return builder; }
From source file:com.woodblockwithoutco.beretainedexample.MainActivity.java
protected CharSequence[] getItems() { //filling list with entries like "fieldName 0xfieldHash" String[] fieldNames = new String[] { "mIntArray", "mObject", "mMap", }; String[] fieldHashcodes = new String[] { "0x" + Integer.toHexString(System.identityHashCode(mIntArray)), "0x" + Integer.toHexString(System.identityHashCode(mObject)), "0x" + Integer.toHexString(System.identityHashCode(mMap)) }; if (fieldHashcodes.length != fieldNames.length) { throw new IllegalStateException("Did you forget to add something?"); }/*from w ww. j a v a2s . c o m*/ int length = fieldHashcodes.length; CharSequence[] items = new CharSequence[length]; for (int i = 0; i < length; i++) { SpannableStringBuilder description = new SpannableStringBuilder(); description.append(fieldNames[i]); description.setSpan(new TypefaceSpan("bold"), 0, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); description.append(" ").append(fieldHashcodes[i]); items[i] = description; } return items; }
From source file:net.kourlas.voipms_sms.adapters.ConversationsRecyclerViewAdapter.java
@Override public void onBindViewHolder(ConversationViewHolder conversationViewHolder, int position) { Message message = messages.get(position); ViewSwitcher viewSwitcher = conversationViewHolder.getViewSwitcher(); viewSwitcher.setDisplayedChild(isItemChecked(position) ? 1 : 0); QuickContactBadge contactBadge = conversationViewHolder.getContactBadge(); contactBadge.assignContactFromPhone(message.getContact(), true); String photoUri = Utils.getContactPhotoUri(applicationContext, message.getContact()); if (photoUri != null) { contactBadge.setImageURI(Uri.parse(photoUri)); } else {//from w w w .jav a 2 s. c o m contactBadge.setImageToDefault(); } TextView contactTextView = conversationViewHolder.getContactTextView(); String contactName = Utils.getContactName(applicationContext, message.getContact()); SpannableStringBuilder contactTextBuilder = new SpannableStringBuilder(); if (contactName != null) { contactTextBuilder.append(contactName); } else { contactTextBuilder.append(Utils.getFormattedPhoneNumber(message.getContact())); } if (!filterConstraint.equals("")) { int index = contactTextBuilder.toString().toLowerCase().indexOf(filterConstraint.toLowerCase()); if (index != -1) { contactTextBuilder.setSpan( new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)), index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); } } contactTextView.setText(contactTextBuilder); final TextView messageTextView = conversationViewHolder.getMessageTextView(); SpannableStringBuilder messageTextBuilder = new SpannableStringBuilder(); int index = message.getText().toLowerCase().indexOf(filterConstraint.toLowerCase()); if (!filterConstraint.equals("") && index != -1) { int nonMessageOffset = index; if (message.getType() == Message.Type.OUTGOING) { messageTextBuilder.insert(0, applicationContext.getString(R.string.conversations_message_you) + " "); nonMessageOffset += 5; } int substringOffset = index - 20; if (substringOffset > 0) { messageTextBuilder.append("..."); nonMessageOffset += 3; while (message.getText().charAt(substringOffset) != ' ' && substringOffset < index - 1) { substringOffset += 1; } substringOffset += 1; } else { substringOffset = 0; } messageTextBuilder.append(message.getText().substring(substringOffset)); messageTextBuilder.setSpan( new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)), nonMessageOffset - substringOffset, nonMessageOffset - substringOffset + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); } else { if (message.getType() == Message.Type.OUTGOING) { messageTextBuilder.append(applicationContext.getString(R.string.conversations_message_you)); messageTextBuilder.append(" "); } messageTextBuilder.append(message.getText()); } messageTextView.setText(messageTextBuilder); if (message.isUnread()) { contactTextView.setTypeface(null, Typeface.BOLD); messageTextView.setTypeface(null, Typeface.BOLD); } else { contactTextView.setTypeface(null, Typeface.NORMAL); messageTextView.setTypeface(null, Typeface.NORMAL); } // Set date line TextView dateTextView = conversationViewHolder.getDateTextView(); if (message.isDraft()) { SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder(); dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_draft)); dateTextBuilder.setSpan(new StyleSpan(Typeface.ITALIC), 0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); dateTextView.setText(dateTextBuilder); } else if (!message.isDelivered()) { if (!message.isDeliveryInProgress()) { SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder(); dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_not_sent)); dateTextBuilder.setSpan( new ForegroundColorSpan( ContextCompat.getColor(applicationContext, android.R.color.holo_red_dark)), 0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); dateTextView.setText(dateTextBuilder); } else { dateTextView.setText(applicationContext.getString(R.string.conversations_message_sending)); } } else { dateTextView.setText(Utils.getFormattedDate(applicationContext, message.getDate(), true)); } }
From source file:com.yangtsaosoftware.pebblemessenger.activities.SetupFragment.java
private void run_basic_test() { SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(_context.getString(R.string.setup_basic_test)); ssb.append('\n'); ssb.append(_context.getString(R.string.setup_test_pebble_title)); ssb.append(test_Pebble_state(_context)); ssb.append('\n'); ssb.append(_context.getString(R.string.setup_test_pebble_firmware)); ssb.append(test_PebbleFirmware_state(_context)); ssb.append('\n'); ssb.append(_context.getString(R.string.setup_accessibility_service_title)); // ssb.append(test_AccessService_state(_context)); ssb.append('\n'); ssb.append(_context.getString(R.string.setup_watch_list)); ssb.append(test_WatchList_state(_context)); ssb.append('\n'); ssb.append(_context.getString(R.string.setup_font_base_status)); ssb.append(test_FontBase_state(_context)); ssb.append('\n'); textInfo.setText(ssb);//from w w w. j av a 2s . c o m svMyview.fullScroll(View.FOCUS_DOWN); }