Example usage for android.text.style ImageSpan ImageSpan

List of usage examples for android.text.style ImageSpan ImageSpan

Introduction

In this page you can find the example usage for android.text.style ImageSpan ImageSpan.

Prototype

public ImageSpan(@NonNull Context context, @DrawableRes int resourceId, int verticalAlignment) 

Source Link

Document

Constructs an ImageSpan from a Context , a resource id and a vertical alignment.

Usage

From source file:net.bible.android.view.util.widget.BookmarkStyleAdapterHelper.java

/**
 * Replace first character of text with image
 *///from   ww w  .j a v  a2s. c  o m
private CharSequence addImageAtStart(String text, int drawableImage, Context context) {
    ImageSpan imageSpan = new ImageSpan(context, drawableImage, ImageSpan.ALIGN_BASELINE);
    final SpannableString spannableString = new SpannableString(text);
    spannableString.setSpan(imageSpan, 0, 1, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableString;
}

From source file:com.vuze.android.remote.adapter.SideFilterAdapter.java

@Override
public void onBindFlexibleViewHolder(SideFilterViewHolder holder, int position) {
    SideFilterInfo item = getItem(position);
    if (item.letters.equals(TorrentListFragment.LETTERS_BS)) {
        ImageSpan imageSpan = new ImageSpan(context, R.drawable.ic_backspace_white_24dp,
                DynamicDrawableSpan.ALIGN_BOTTOM);
        SpannableStringBuilder ss = new SpannableStringBuilder(",");
        ss.setSpan(imageSpan, 0, 1, 0);// w w w .  j  a v a 2  s  .  co m
        holder.tvText.setText(ss);
    } else {
        holder.tvText.setText(item.letters);

        int resID = item.letters.length() > 1 ? android.R.style.TextAppearance_Small
                : android.R.style.TextAppearance_Large;
        holder.tvText.setTextAppearance(context, resID);
        holder.tvText.setTextColor(ContextCompat.getColor(context, R.color.login_text_color));
    }
    holder.tvCount.setText(item.count > 0 ? String.valueOf(item.count) : "");
}

From source file:org.mozilla.gecko.home.ReadingListPanel.java

private void updateUiFromCursor(Cursor c) {
    // We delay setting the empty view until the cursor is actually empty.
    // This avoids image flashing.
    if ((c == null || c.getCount() == 0) && mEmptyView == null) {
        final ViewStub emptyViewStub = (ViewStub) mTopView.findViewById(R.id.home_empty_view_stub);
        mEmptyView = emptyViewStub.inflate();

        final TextView emptyHint = (TextView) mEmptyView.findViewById(R.id.home_empty_hint);
        if (HardwareUtils.isLowMemoryPlatform()) {
            emptyHint.setVisibility(View.GONE);
        } else {// w ww. ja  va2 s  .  co  m
            String readingListHint = emptyHint.getText().toString();

            // Use an ImageSpan to include the reader icon in the "Tip".
            int imageSpanIndex = readingListHint.indexOf(MATCH_STRING);
            if (imageSpanIndex != -1) {
                final ImageSpan readingListIcon = new ImageSpan(getActivity(), R.drawable.reader_cropped,
                        ImageSpan.ALIGN_BOTTOM);
                final SpannableStringBuilder hintBuilder = new SpannableStringBuilder(readingListHint);

                // Add additional spacing.
                hintBuilder.insert(imageSpanIndex + MATCH_STRING.length(), " ");
                hintBuilder.insert(imageSpanIndex, " ");

                // Add icon.
                hintBuilder.setSpan(readingListIcon, imageSpanIndex + 1,
                        imageSpanIndex + MATCH_STRING.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

                emptyHint.setText(hintBuilder, TextView.BufferType.SPANNABLE);
            }
        }

        mList.setEmptyView(mEmptyView);
    }
}

From source file:com.hannesdorfmann.home.HomeActivity.java

private void setNoFiltersVisiblity(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('\u08B4');
            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//from w  w w.j a  va  2s.  c o  m
                public void onClick(View v) {
                    drawer.openDrawer(GravityCompat.END);
                }
            });
        }
        noFiltersEmptyText.setVisibility(visibility);
    } else if (noFiltersEmptyText != null) {
        noFiltersEmptyText.setVisibility(visibility);
    }
}

From source file:us.phyxsi.gameshelf.ui.HomeActivity.java

private void setNoResultsEmptyTextVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noResultsEmptyText == null) {
            // create the no results empty text
            ViewStub stub = (ViewStub) findViewById(R.id.stub_no_results);
            noResultsEmptyText = (TextView) stub.inflate();
            String emptyText = getString(R.string.no_results_found);
            int addPlaceholderStart = emptyText.indexOf('\u08B4');
            int altMethodStart = addPlaceholderStart + 3;
            SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText);
            // show an image of the add icon
            ssb.setSpan(new ImageSpan(this, R.drawable.ic_add_small, ImageSpan.ALIGN_BASELINE),
                    addPlaceholderStart, addPlaceholderStart + 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);
            noResultsEmptyText.setText(ssb);
        }/*from  w ww.jav  a 2  s  .c om*/

        noResultsEmptyText.setVisibility(visibility);
    } else if (noResultsEmptyText != null) {
        noResultsEmptyText.setVisibility(visibility);
    }
}

From source file:com.ruesga.rview.widget.TagEditTextView.java

public void setTags(Tag[] tags) {
    // Delete any existent data
    try {/*from w  ww  .ja v  a 2  s .c  o m*/
        mTagEdit.getEditableText().clearSpans();
    } catch (Exception ex) {
        // Ignore
    }
    int count = mTagList.size() - 1;
    for (int i = count; i >= 0; i--) {
        onTagRemoveClick(mTagList.get(i));
    }
    mTagEdit.setText("");

    if (tags == null) {
        return;
    }

    // Filter invalid tags
    for (Tag tag : tags) {
        Matcher hashTagMatcher = HASH_TAG_PATTERN.matcher(tag.mTag);
        Matcher userTagMatcher = USER_TAG_PATTERN.matcher(tag.mTag);
        if (hashTagMatcher.matches() || (mSupportsUserTags && userTagMatcher.matches())) {
            mTagList.add(tag);
        }
    }

    // Build the spans
    SpannableStringBuilder builder;
    if (tags.length > 0) {
        final String text = String.format("%" + tags.length + "s", CHIP_SEPARATOR_CHAR)
                .replaceAll(CHIP_SEPARATOR_CHAR, CHIP_REPLACEMENT_CHAR);
        builder = new SpannableStringBuilder(text);
    } else {
        builder = new SpannableStringBuilder("");
    }

    int pos = 0;
    for (final Tag tag : mTagList) {
        Bitmap b = createTagChip(tag);
        tag.w = b.getWidth();
        tag.h = b.getHeight();
        ImageSpan span = new ImageSpan(getContext(), b, ImageSpan.ALIGN_BOTTOM);
        builder.setSpan(span, pos, pos + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        pos++;

        notifyTagCreated(tag);
    }
    mTagEdit.setText(builder);
    mTagEdit.setSelection(mTagEdit.getText().length());
}

From source file:io.plaidapp.ui.HomeActivity.java

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('\u08B4');
            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//from   w  w  w .j av a2s .c o  m
                public void onClick(View v) {
                    drawer.openDrawer(GravityCompat.END);
                }
            });
        }
        noFiltersEmptyText.setVisibility(visibility);
    } else if (noFiltersEmptyText != null) {
        noFiltersEmptyText.setVisibility(visibility);
    }

}