Search in sources :

Example 21 with StyleSpan

use of android.text.style.StyleSpan 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 22 with StyleSpan

use of android.text.style.StyleSpan in project plaid by nickbutcher.

the class HomeActivity method setNoFiltersEmptyTextVisibility.

private void setNoFiltersEmptyTextVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noFiltersEmptyText == null) {
            // create the no filters empty text
            ViewStub stub = (ViewStub) findViewById(R.id.stub_no_filters);
            noFiltersEmptyText = (TextView) stub.inflate();
            String emptyText = getString(R.string.no_filters_selected);
            int filterPlaceholderStart = emptyText.indexOf('ࢴ');
            int altMethodStart = filterPlaceholderStart + 3;
            SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText);
            // show an image of the filter icon
            ssb.setSpan(new ImageSpan(this, R.drawable.ic_filter_small, ImageSpan.ALIGN_BASELINE), filterPlaceholderStart, filterPlaceholderStart + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            // make the alt method (swipe from right) less prominent and italic
            ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.text_secondary_light)), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            ssb.setSpan(new StyleSpan(Typeface.ITALIC), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            noFiltersEmptyText.setText(ssb);
            noFiltersEmptyText.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    drawer.openDrawer(GravityCompat.END);
                }
            });
        }
        noFiltersEmptyText.setVisibility(visibility);
    } else if (noFiltersEmptyText != null) {
        noFiltersEmptyText.setVisibility(visibility);
    }
}
Also used : ViewStub(android.view.ViewStub) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 23 with StyleSpan

use of android.text.style.StyleSpan in project plaid by nickbutcher.

the class SearchActivity method setNoResultsVisibility.

void setNoResultsVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noResults == null) {
            noResults = (TextView) ((ViewStub) findViewById(R.id.stub_no_search_results)).inflate();
            noResults.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchView.setQuery("", false);
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });
        }
        String message = String.format(getString(R.string.no_search_results), searchView.getQuery().toString());
        SpannableStringBuilder ssb = new SpannableStringBuilder(message);
        ssb.setSpan(new StyleSpan(Typeface.ITALIC), message.indexOf('“') + 1, message.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        noResults.setText(ssb);
    }
    if (noResults != null) {
        noResults.setVisibility(visibility);
    }
}
Also used : ViewStub(android.view.ViewStub) StyleSpan(android.text.style.StyleSpan) BindView(butterknife.BindView) View(android.view.View) SearchView(android.widget.SearchView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CheckedTextView(android.widget.CheckedTextView) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 24 with StyleSpan

use of android.text.style.StyleSpan in project material-calendarview by prolificinteractive.

the class OneDayDecorator method decorate.

@Override
public void decorate(DayViewFacade view) {
    view.addSpan(new StyleSpan(Typeface.BOLD));
    view.addSpan(new RelativeSizeSpan(1.4f));
}
Also used : StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 25 with StyleSpan

use of android.text.style.StyleSpan in project Conversations by siacs.

the class NotificationService method buildMultipleConversation.

private Builder buildMultipleConversation() {
    final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
    final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
    style.setBigContentTitle(notifications.size() + " " + mXmppConnectionService.getString(R.string.unread_conversations));
    final StringBuilder names = new StringBuilder();
    Conversation conversation = null;
    for (final ArrayList<Message> messages : notifications.values()) {
        if (messages.size() > 0) {
            conversation = messages.get(0).getConversation();
            final String name = conversation.getName();
            SpannableString styledString;
            if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
                int count = messages.size();
                styledString = new SpannableString(name + ": " + mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count));
                styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
                style.addLine(styledString);
            } else {
                styledString = new SpannableString(name + ": " + UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
                styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
                style.addLine(styledString);
            }
            names.append(name);
            names.append(", ");
        }
    }
    if (names.length() >= 2) {
        names.delete(names.length() - 2, names.length());
    }
    mBuilder.setContentTitle(notifications.size() + " " + mXmppConnectionService.getString(R.string.unread_conversations));
    mBuilder.setContentText(names.toString());
    mBuilder.setStyle(style);
    if (conversation != null) {
        mBuilder.setContentIntent(createContentIntent(conversation));
    }
    mBuilder.setGroupSummary(true);
    mBuilder.setGroup(CONVERSATIONS_GROUP);
    mBuilder.setDeleteIntent(createDeleteIntent(null));
    mBuilder.setSmallIcon(R.drawable.ic_notification);
    return mBuilder;
}
Also used : SpannableString(android.text.SpannableString) Message(eu.siacs.conversations.entities.Message) Builder(android.support.v4.app.NotificationCompat.Builder) StyleSpan(android.text.style.StyleSpan) NotificationCompat(android.support.v4.app.NotificationCompat) Conversation(eu.siacs.conversations.entities.Conversation) SpannableString(android.text.SpannableString)

Aggregations

StyleSpan (android.text.style.StyleSpan)143 SpannableString (android.text.SpannableString)56 SpannableStringBuilder (android.text.SpannableStringBuilder)34 RelativeSizeSpan (android.text.style.RelativeSizeSpan)32 ForegroundColorSpan (android.text.style.ForegroundColorSpan)25 View (android.view.View)18 TextView (android.widget.TextView)17 UnderlineSpan (android.text.style.UnderlineSpan)16 Spannable (android.text.Spannable)14 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)12 TypedArray (android.content.res.TypedArray)10 TextPaint (android.text.TextPaint)10 SubscriptSpan (android.text.style.SubscriptSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)10 Handler (android.os.Handler)9 Message (android.os.Message)9 URLSpan (android.text.style.URLSpan)8 JustifiedSpan (com.bluejamesbond.text.style.JustifiedSpan)8 ArticleBuilder (com.bluejamesbond.text.util.ArticleBuilder)8