List of usage examples for android.text SpannableStringBuilder length
public int length()
From source file:com.silentcircle.contacts.vcard.ManageVCardActivity.java
private Dialog getVCardFileSelectDialog(boolean multipleSelect) { final int size = mAllVCardFileList.size(); final VCardSelectedListener listener = new VCardSelectedListener(multipleSelect); final AlertDialog.Builder builder = new AlertDialog.Builder(this) .setTitle(R.string.select_vcard_title_remove).setPositiveButton(android.R.string.ok, listener) .setOnCancelListener(mCancelListener).setNegativeButton(android.R.string.cancel, mCancelListener); CharSequence[] items = new CharSequence[size]; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < size; i++) { VCardFile vcardFile = mAllVCardFileList.get(i); SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); stringBuilder.append(vcardFile.getName()); stringBuilder.append('\n'); int indexToBeSpanned = stringBuilder.length(); // Smaller date text looks better, since each file name becomes easier to read. // The value set to RelativeSizeSpan is arbitrary. You can change it to any other // value (but the value bigger than 1.0f would not make nice appearance :) stringBuilder.append("(" + dateFormat.format(new Date(vcardFile.getLastModified())) + ")"); stringBuilder.setSpan(new RelativeSizeSpan(0.7f), indexToBeSpanned, stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); items[i] = stringBuilder;/*w ww .j av a2s. c o m*/ } if (multipleSelect) { builder.setMultiChoiceItems(items, (boolean[]) null, listener); } else { builder.setSingleChoiceItems(items, 0, listener); } return builder.create(); }
From source file:com.chen.mail.browse.SendersView.java
public static SpannableStringBuilder createMessageInfo(Context context, Conversation conv, final boolean resourceCachingRequired) { SpannableStringBuilder messageInfo = new SpannableStringBuilder(); try {//www . ja va2 s . c o m ConversationInfo conversationInfo = conv.conversationInfo; int sendingStatus = conv.sendingState; boolean hasSenders = false; // This covers the case where the sender is "me" and this is a draft // message, which means this will only run once most of the time. for (MessageInfo m : conversationInfo.messageInfos) { if (!TextUtils.isEmpty(m.sender)) { hasSenders = true; break; } } getSenderResources(context, resourceCachingRequired); if (conversationInfo != null) { int count = conversationInfo.messageCount; int draftCount = conversationInfo.draftCount; boolean showSending = sendingStatus == UIProvider.ConversationSendingState.SENDING; if (count > 1) { messageInfo.append(count + ""); } messageInfo.setSpan( CharacterStyle.wrap(conv.read ? sMessageInfoReadStyleSpan : sMessageInfoUnreadStyleSpan), 0, messageInfo.length(), 0); if (draftCount > 0) { // If we are showing a message count or any draft text and there // is at least 1 sender, prepend the sending state text with a // comma. if (hasSenders || count > 1) { messageInfo.append(sSendersSplitToken); } SpannableStringBuilder draftString = new SpannableStringBuilder(); if (draftCount == 1) { draftString.append(sDraftSingularString); } else { draftString.append(sDraftPluralString + String.format(sDraftCountFormatString, draftCount)); } draftString.setSpan(CharacterStyle.wrap(sDraftsStyleSpan), 0, draftString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); messageInfo.append(draftString); } if (showSending) { // If we are showing a message count or any draft text, prepend // the sending state text with a comma. if (count > 1 || draftCount > 0) { messageInfo.append(sSendersSplitToken); } SpannableStringBuilder sending = new SpannableStringBuilder(); sending.append(sSendingString); sending.setSpan(sSendingStyleSpan, 0, sending.length(), 0); messageInfo.append(sending); } // Prepend a space if we are showing other message info text. if (count > 1 || (draftCount > 0 && hasSenders) || showSending) { messageInfo.insert(0, sMessageCountSpacerString); } } } finally { if (!resourceCachingRequired) { clearResourceCache(); } } return messageInfo; }
From source file:app.abhijit.iter.MainActivity.java
private void setupGettingStartedHint() { TextView gettingStartedHint = (TextView) findViewById(R.id.hint_getting_started); int lineHeight = gettingStartedHint.getLineHeight(); Drawable hamburgerIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_hamburger, null); hamburgerIcon.setBounds(0, 0, lineHeight, lineHeight); SpannableStringBuilder hintText = new SpannableStringBuilder(); hintText.append(getResources().getString(R.string.hint_getting_started_1)).append(" "); hintText.setSpan(new ImageSpan(hamburgerIcon), hintText.length() - 1, hintText.length(), 0); hintText.append(getResources().getString(R.string.hint_getting_started_2)); gettingStartedHint.setText(hintText); }
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); }//from w w w. j a v a2 s. co m 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: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 ww w. j ava2 s . c om*/ 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.gh4a.activities.IssueActivity.java
private void fillData() { // set details inside listview header ImageView ivGravatar = (ImageView) mListHeaderView.findViewById(R.id.iv_gravatar); AvatarHandler.assignAvatar(ivGravatar, mIssue.getUser()); ivGravatar.setOnClickListener(this); TextView tvState = (TextView) mHeader.findViewById(R.id.tv_state); boolean closed = Constants.Issue.STATE_CLOSED.equals(mIssue.getState()); int stateTextResId = closed ? R.string.closed : R.string.open; int stateColorAttributeId = closed ? R.attr.colorIssueClosed : R.attr.colorIssueOpen; tvState.setText(getString(stateTextResId).toUpperCase(Locale.getDefault())); transitionHeaderToColor(stateColorAttributeId, closed ? R.attr.colorIssueClosedDark : R.attr.colorIssueOpenDark); UiUtils.trySetListOverscrollColor(mRecyclerView, UiUtils.resolveColor(this, stateColorAttributeId)); TextView tvExtra = (TextView) mListHeaderView.findViewById(R.id.tv_extra); tvExtra.setText(ApiHelpers.getUserLogin(this, mIssue.getUser())); TextView tvTimestamp = (TextView) mListHeaderView.findViewById(R.id.tv_timestamp); tvTimestamp.setText(StringUtils.formatRelativeTime(this, mIssue.getCreatedAt(), true)); TextView tvTitle = (TextView) mHeader.findViewById(R.id.tv_title); tvTitle.setText(mIssue.getTitle());/*ww w. ja v a2 s . c om*/ String body = mIssue.getBodyHtml(); TextView descriptionView = (TextView) mListHeaderView.findViewById(R.id.tv_desc); if (!StringUtils.isBlank(body)) { body = HtmlUtils.format(body).toString(); mImageGetter.bind(descriptionView, body, mIssue.getNumber()); } descriptionView.setMovementMethod(UiUtils.CHECKING_LINK_METHOD); View milestoneGroup = mListHeaderView.findViewById(R.id.milestone_container); if (mIssue.getMilestone() != null) { TextView tvMilestone = (TextView) mListHeaderView.findViewById(R.id.tv_milestone); tvMilestone.setText(mIssue.getMilestone().getTitle()); milestoneGroup.setVisibility(View.VISIBLE); } else { milestoneGroup.setVisibility(View.GONE); } View assigneeGroup = mListHeaderView.findViewById(R.id.assignee_container); if (mIssue.getAssignee() != null) { TextView tvAssignee = (TextView) mListHeaderView.findViewById(R.id.tv_assignee); tvAssignee.setText(mIssue.getAssignee().getLogin()); ImageView ivAssignee = (ImageView) mListHeaderView.findViewById(R.id.iv_assignee); AvatarHandler.assignAvatar(ivAssignee, mIssue.getAssignee()); ivAssignee.setOnClickListener(this); assigneeGroup.setVisibility(View.VISIBLE); } else { assigneeGroup.setVisibility(View.GONE); } List<Label> labels = mIssue.getLabels(); View labelGroup = mListHeaderView.findViewById(R.id.label_container); if (labels != null && !labels.isEmpty()) { TextView labelView = (TextView) mListHeaderView.findViewById(R.id.labels); SpannableStringBuilder builder = new SpannableStringBuilder(); for (Label label : labels) { int pos = builder.length(); IssueLabelSpan span = new IssueLabelSpan(this, label, true); builder.append(label.getName()); builder.setSpan(span, pos, pos + label.getName().length(), 0); } labelView.setText(builder); labelGroup.setVisibility(View.VISIBLE); } else { labelGroup.setVisibility(View.GONE); } TextView tvPull = (TextView) mListHeaderView.findViewById(R.id.tv_pull); if (mIssue.getPullRequest() != null && mIssue.getPullRequest().getDiffUrl() != null) { tvPull.setVisibility(View.VISIBLE); tvPull.setOnClickListener(this); } else { tvPull.setVisibility(View.GONE); } mHeader.setVisibility(View.VISIBLE); updateFabVisibility(); updateCommentLockState(); }
From source file:com.mybitcoin.wallet.ui.TransactionsListFragment.java
@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); /*if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto));*/ setEmptyText(emptyText);/* w w w.j a v a 2 s . c o m*/ }
From source file:com.gh4a.fragment.PullRequestFragment.java
private void fillLabels(List<Label> labels) { View labelGroup = mListHeaderView.findViewById(R.id.label_container); if (labels != null && !labels.isEmpty()) { TextView labelView = (TextView) mListHeaderView.findViewById(R.id.labels); SpannableStringBuilder builder = new SpannableStringBuilder(); for (Label label : labels) { int pos = builder.length(); IssueLabelSpan span = new IssueLabelSpan(getActivity(), label, true); builder.append(label.getName()); builder.setSpan(span, pos, pos + label.getName().length(), 0); }//from w ww.j ava 2s.c om labelView.setText(builder); labelGroup.setVisibility(View.VISIBLE); } else { labelGroup.setVisibility(View.GONE); } }
From source file:cc.mintcoin.wallet.ui.TransactionsListFragment.java
@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto)); setEmptyText(emptyText);//from w w w . j av a 2 s . c o m }
From source file:biz.wiz.android.wallet.ui.TransactionsListFragment.java
@Override public void onLoadFinished(final Loader<List<Transaction>> loader, final List<Transaction> transactions) { adapter.replace(transactions);/*from ww w .j a v a 2s . c o m*/ final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto)); setEmptyText(emptyText); setEmptyText("wallet bip32 seed is " + wallet.getKeyChainSeed().getMnemonicCode()); }