Search in sources :

Example 46 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project AndroidTraining by mixi-inc.

the class SearchView method getDecoratedHint.

private CharSequence getDecoratedHint(CharSequence hintText) {
    // If the field is always expanded, then don't add the search icon to the hint
    if (!mIconifiedByDefault)
        return hintText;
    // for the icon
    SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
    ssb.append(hintText);
    Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId());
    int textSize = (int) (mQueryTextView.getTextSize() * 1.25);
    searchIcon.setBounds(0, 0, textSize, textSize);
    ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ssb;
}
Also used : Drawable(android.graphics.drawable.Drawable) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 47 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project k-9 by k9mail.

the class MessageListAdapter method bindView.

@Override
public void bindView(View view, Context context, Cursor cursor) {
    Account account = fragment.getAccountFromCursor(cursor);
    String fromList = cursor.getString(SENDER_LIST_COLUMN);
    String toList = cursor.getString(TO_LIST_COLUMN);
    String ccList = cursor.getString(CC_LIST_COLUMN);
    Address[] fromAddrs = Address.unpack(fromList);
    Address[] toAddrs = Address.unpack(toList);
    Address[] ccAddrs = Address.unpack(ccList);
    boolean fromMe = fragment.messageHelper.toMe(account, fromAddrs);
    boolean toMe = fragment.messageHelper.toMe(account, toAddrs);
    boolean ccMe = fragment.messageHelper.toMe(account, ccAddrs);
    CharSequence displayName = fragment.messageHelper.getDisplayName(account, fromAddrs, toAddrs);
    CharSequence displayDate = DateUtils.getRelativeTimeSpanString(context, cursor.getLong(DATE_COLUMN));
    Address counterpartyAddress = fetchCounterPartyAddress(fromMe, toAddrs, ccAddrs, fromAddrs);
    int threadCount = (fragment.showingThreadedList) ? cursor.getInt(THREAD_COUNT_COLUMN) : 0;
    String subject = MlfUtils.buildSubject(cursor.getString(SUBJECT_COLUMN), fragment.getString(R.string.general_no_subject), threadCount);
    boolean read = (cursor.getInt(READ_COLUMN) == 1);
    boolean flagged = (cursor.getInt(FLAGGED_COLUMN) == 1);
    boolean answered = (cursor.getInt(ANSWERED_COLUMN) == 1);
    boolean forwarded = (cursor.getInt(FORWARDED_COLUMN) == 1);
    boolean hasAttachments = (cursor.getInt(ATTACHMENT_COUNT_COLUMN) > 0);
    MessageViewHolder holder = (MessageViewHolder) view.getTag();
    int maybeBoldTypeface = (read) ? Typeface.NORMAL : Typeface.BOLD;
    long uniqueId = cursor.getLong(fragment.uniqueIdColumn);
    boolean selected = fragment.selected.contains(uniqueId);
    holder.chip.setBackgroundColor(account.getChipColor());
    if (fragment.checkboxes) {
        holder.selected.setChecked(selected);
    }
    if (fragment.stars) {
        holder.flagged.setChecked(flagged);
    }
    holder.position = cursor.getPosition();
    if (holder.contactBadge != null) {
        updateContactBadge(holder, counterpartyAddress);
    }
    setBackgroundColor(view, selected, read);
    if (fragment.activeMessage != null) {
        changeBackgroundColorIfActiveMessage(cursor, account, view);
    }
    updateWithThreadCount(holder, threadCount);
    CharSequence beforePreviewText = (fragment.senderAboveSubject) ? subject : displayName;
    String sigil = recipientSigil(toMe, ccMe);
    SpannableStringBuilder messageStringBuilder = new SpannableStringBuilder(sigil).append(beforePreviewText);
    if (fragment.previewLines > 0) {
        String preview = getPreview(cursor);
        messageStringBuilder.append(" ").append(preview);
    }
    holder.preview.setText(messageStringBuilder, TextView.BufferType.SPANNABLE);
    formatPreviewText(holder.preview, beforePreviewText, sigil);
    Drawable statusHolder = buildStatusHolder(forwarded, answered);
    if (holder.from != null) {
        holder.from.setTypeface(Typeface.create(holder.from.getTypeface(), maybeBoldTypeface));
        if (fragment.senderAboveSubject) {
            holder.from.setCompoundDrawablesWithIntrinsicBounds(// left
            statusHolder, // top
            null, // right
            hasAttachments ? mAttachmentIcon : null, // bottom
            null);
            holder.from.setText(displayName);
        } else {
            holder.from.setText(new SpannableStringBuilder(sigil).append(displayName));
        }
    }
    if (holder.subject != null) {
        if (!fragment.senderAboveSubject) {
            holder.subject.setCompoundDrawablesWithIntrinsicBounds(// left
            statusHolder, // top
            null, // right
            hasAttachments ? mAttachmentIcon : null, // bottom
            null);
        }
        holder.subject.setTypeface(Typeface.create(holder.subject.getTypeface(), maybeBoldTypeface));
        holder.subject.setText(subject);
    }
    holder.date.setText(displayDate);
}
Also used : Account(com.fsck.k9.Account) Address(com.fsck.k9.mail.Address) Drawable(android.graphics.drawable.Drawable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 48 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project qksms by moezbhatti.

the class SearchAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(SearchViewHolder holder, int position) {
    SearchData data = getItem(position);
    holder.mData = data;
    holder.mClickListener = mItemClickListener;
    holder.root.setOnClickListener(holder);
    holder.root.setOnLongClickListener(holder);
    if (data.contact != null) {
        Drawable avatarDrawable = data.contact.getAvatar(mContext, null);
        holder.avatar.setImageDrawable(avatarDrawable);
        holder.avatar.setContactName(data.contact.getName());
        holder.name.setText(data.contact.getName());
    } else {
        holder.avatar.setImageDrawable(null);
        holder.avatar.setContactName(null);
        holder.name.setText(null);
    }
    holder.date.setText(DateFormatter.getConversationTimestamp(mContext, data.date));
    if (mQuery != null) {
        // We need to make the search string bold within the full message
        // Get all of the start positions of the query within the messages
        ArrayList<Integer> indices = new ArrayList<>();
        int index = data.body.toLowerCase().indexOf(mQuery.toLowerCase());
        while (index >= 0) {
            indices.add(index);
            index = data.body.toLowerCase().indexOf(mQuery.toLowerCase(), index + 1);
        }
        // Make all instances of the search query bold
        SpannableStringBuilder sb = new SpannableStringBuilder(data.body);
        for (int i : indices) {
            StyleSpan span = new StyleSpan(Typeface.BOLD);
            sb.setSpan(span, i, i + mQuery.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        }
        holder.snippet.setText(sb);
    }
}
Also used : StyleSpan(android.text.style.StyleSpan) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 49 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project Signal-Android by WhisperSystems.

the class RecipientsEditor method populate.

public void populate(Recipients list) {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    for (Recipient c : list.getRecipientsList()) {
        if (sb.length() != 0) {
            sb.append(", ");
        }
        sb.append(contactToToken(c));
    }
    setText(sb);
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 50 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project Signal-Android by WhisperSystems.

the class AbstractNotificationBuilder method getStyledMessage.

protected CharSequence getStyledMessage(@NonNull Recipient recipient, @Nullable CharSequence message) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(Util.getBoldedString(recipient.toShortString()));
    builder.append(": ");
    builder.append(message == null ? "" : message);
    return builder;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)336 ForegroundColorSpan (android.text.style.ForegroundColorSpan)56 ImageSpan (android.text.style.ImageSpan)53 TextView (android.widget.TextView)40 View (android.view.View)38 StyleSpan (android.text.style.StyleSpan)35 Spanned (android.text.Spanned)28 Drawable (android.graphics.drawable.Drawable)27 Spannable (android.text.Spannable)25 SpannableString (android.text.SpannableString)21 Test (org.junit.Test)21 CharacterStyle (android.text.style.CharacterStyle)18 TextPaint (android.text.TextPaint)17 RelativeSizeSpan (android.text.style.RelativeSizeSpan)17 Paint (android.graphics.Paint)16 Context (android.content.Context)15 TextAppearanceSpan (android.text.style.TextAppearanceSpan)15 ImageView (android.widget.ImageView)15 Intent (android.content.Intent)13 Editable (android.text.Editable)13