List of usage examples for android.text SpannableStringBuilder length
public int length()
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?"); }/* w w w .j a v a 2s. co 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: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 w w . jav a 2 s .c om*/ 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:com.github.michalbednarski.intentslab.browser.RegisteredReceiverFetcher.java
@Override Object getEntries(Context context) { try {//ww w . ja v a 2s . c o m final Categorizer<RegisteredReceiverInfo> categorizer = new ProcessCategorizer(); (new RegisteredReceiversParser(mExcludeProtected) { @Override protected void onReceiverFound(RegisteredReceiverInfo receiverInfo) { categorizer.add(receiverInfo); } }).parse(context); return categorizer.getResult(); } catch (SecurityException e) { // Create message about error SpannableStringBuilder ssb = new SpannableStringBuilder( context.getString(R.string.registered_receivers_denied)); ssb.append("\n"); int commandStart = ssb.length(); if (ComponentFetcher.DEVELOPMENT_PERMISSIONS_SUPPORTED) { ssb.append("pm grant ").append(context.getPackageName()).append(" android.permission.DUMP"); } else { ssb.append(RemoteEntryPoint.getScriptFile(context).getAbsolutePath()); } int commandEnd = ssb.length(); ssb.setSpan(new StyleSpan(Typeface.BOLD), commandStart, commandEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return new CustomError(ssb); } catch (Throwable e) { e.printStackTrace(); return new CustomError(Utils.describeException(e)); } }
From source file:com.github.michalbednarski.intentslab.providerlab.proxy.LogViewerFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { setListAdapter(new CursorAdapter(getActivity(), data, false) { @Override// w w w. j a v a2s . c o m public View newView(Context context, Cursor cursor, ViewGroup parent) { return ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(android.R.layout.simple_list_item_2, parent, false); } @Override public void bindView(View view, Context context, Cursor cursor) { // First row: method and app name final String appName = getActivity().getPackageManager().getNameForUid(cursor.getInt(3)); final String methodName = methodIdToName(cursor.getInt(1)); ((TextView) view.findViewById(android.R.id.text1)).setText(methodName + "() by " + appName); // Second row: uri and exception final String uri = cursor.getString(2); String exception = cursor.getString(4); SpannableStringBuilder text2 = new SpannableStringBuilder(uri); if (exception != null) { text2.append("\n"); final int start = text2.length(); text2.append(exception); final int end = text2.length(); text2.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { // TODO: result / empty result warning } ((TextView) view.findViewById(android.R.id.text2)).setText(text2); } }); }
From source file:io.github.hidroh.materialistic.widget.StoryView.java
private Spannable decorateUpdated() { SpannableStringBuilder sb = new SpannableStringBuilder("*"); sb.setSpan(new AsteriskSpan(getContext()), sb.length() - 1, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return sb;/*from www . jav a 2 s .c o m*/ }
From source file:org.kontalk.ui.view.TextContentView.java
@Override public void bind(long databaseId, TextComponent component, Pattern highlight) { mComponent = component;//from w w w . jav a 2 s . c o m SpannableStringBuilder formattedMessage = formatMessage(highlight); setTextStyle(this); // linkify! if (formattedMessage.length() < MAX_AFFORDABLE_SIZE) Linkify.addLinks(formattedMessage, Linkify.ALL); /* * workaround for bugs: * http://code.google.com/p/android/issues/detail?id=17343 * http://code.google.com/p/android/issues/detail?id=22493 * applies from Honeycomb to JB 4.2.2 afaik */ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB && android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) // from http://stackoverflow.com/a/12303155/1045199 formattedMessage.append("\u200b"); // was: \u2060 setText(formattedMessage); }
From source file:com.android.mail.browse.SubjectAndFolderView.java
public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) { mVisibleFolders = true;//from ww w. j a v a2 s . co m final BidiFormatter bidiFormatter = getBidiFormatter(); final String wrappedSubject = mSubject == null ? "" : bidiFormatter.unicodeWrap(mSubject); final SpannableStringBuilder sb = new SpannableStringBuilder(wrappedSubject); sb.append('\u0020'); final Settings settings = account.settings; final int start = sb.length(); if (settings.importanceMarkersEnabled && conv.isImportant()) { sb.append(".\u0020"); sb.setSpan(new ReplacementSpan() { @Override public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { return mImportanceMarkerDrawable.getIntrinsicWidth(); } @Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int baseline, int bottom, Paint paint) { canvas.save(); final int transY = baseline + mChipVerticalOffset - mImportanceMarkerDrawable.getIntrinsicHeight(); canvas.translate(x, transY); mImportanceMarkerDrawable.draw(canvas); canvas.restore(); } }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */); mFolderDisplayer.constructFolderChips(sb); final int end = sb.length(); sb.setSpan(new ChangeLabelsSpan(callbacks), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); setText(sb); setMovementMethod(LinkMovementMethod.getInstance()); }
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} */// w ww .ja v a2 s. 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.groksolutions.grok.mobile.annotation.AnnotationListFragment.java
/** * Format annotation message footer for list item display * * @param annotation/* w w w. ja v a 2 s.com*/ * @param showDate * @return */ SpannableStringBuilder formatAnnotationFooter(Annotation annotation, boolean showDate) { int pos, rightPos; Date created = new Date(annotation.getCreated()); // Format text SpannableStringBuilder text = new SpannableStringBuilder(); // <div align="right"> rightPos = pos = text.length(); //<small>6/30/14 3:25 PM - </small> // Show date if different annotation or if created date changed if (showDate) { text.append(_dateFormat.format(created)).append(" "); } text.append(_timeFormat.format(created)).append(" - "); text.setSpan(new RelativeSizeSpan(0.5f), pos, text.length(), 0); // User pos = text.length(); text.append(annotation.getUser()); text.setSpan(new RelativeSizeSpan(1.0f), pos, text.length(), 0); // </div align="right"> text.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), rightPos, 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: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 . java2 s . c om 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); }