use of android.text.SpannableStringBuilder in project Meizhi by drakeet.
the class GankListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Gank gank = mGankList.get(position);
if (position == 0) {
showCategory(holder);
} else {
boolean theCategoryOfLastEqualsToThis = mGankList.get(position - 1).type.equals(mGankList.get(position).type);
if (!theCategoryOfLastEqualsToThis) {
showCategory(holder);
} else {
hideCategory(holder);
}
}
holder.category.setText(gank.type);
SpannableStringBuilder builder = new SpannableStringBuilder(gank.desc).append(StringStyles.format(holder.gank.getContext(), " (via. " + gank.who + ")", R.style.ViaTextAppearance));
CharSequence gankText = builder.subSequence(0, builder.length());
holder.gank.setText(gankText);
showItemAnim(holder.gank, position);
}
use of android.text.SpannableStringBuilder in project cw-omnibus by commonsguy.
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;
}
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;
}
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);
}
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);
}
}
Aggregations