Search in sources :

Example 26 with SpannableStringBuilder

use of android.text.SpannableStringBuilder 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 27 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project WordPress-Android by wordpress-mobile.

the class HtmlStyleTextWatcherTest method testAddingListTagsFromFormatBar.

@Test
public void testAddingListTagsFromFormatBar() {
    // -- Test adding a list tag to an empty document
    mContent = new SpannableStringBuilder("<ul>\n\t<li>");
    mWatcher.onTextChanged(mContent, 0, 0, 10);
    mWatcher.afterTextChanged(mContent);
    assertEquals(0, mSpanRange.getOpeningTagLoc());
    assertEquals(10, mSpanRange.getClosingTagLoc());
    // -- Test adding a closing list tag
    mContent = new SpannableStringBuilder(//5
    "<ul>\n" + //20
    "\t<li>list item</li>\n" + //22
    "\t<li>another list item</li>\n" + "</ul>");
    // Added "</li>\n</ul>"
    mWatcher.onTextChanged(mContent, 47, 0, 11);
    mWatcher.afterTextChanged(mContent);
    assertEquals(47, mSpanRange.getOpeningTagLoc());
    assertEquals(58, mSpanRange.getClosingTagLoc());
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) Test(org.junit.Test)

Example 28 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project XobotOS by xamarin.

the class DigitsKeyListener method filter.

@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
    CharSequence out = super.filter(source, start, end, dest, dstart, dend);
    if (mSign == false && mDecimal == false) {
        return out;
    }
    if (out != null) {
        source = out;
        start = 0;
        end = out.length();
    }
    int sign = -1;
    int decimal = -1;
    int dlen = dest.length();
    for (int i = 0; i < dstart; i++) {
        char c = dest.charAt(i);
        if (c == '-') {
            sign = i;
        } else if (c == '.') {
            decimal = i;
        }
    }
    for (int i = dend; i < dlen; i++) {
        char c = dest.charAt(i);
        if (c == '-') {
            // Nothing can be inserted in front of a '-'.
            return "";
        } else if (c == '.') {
            decimal = i;
        }
    }
    /*
         * If it does, we must strip them out from the source.
         * In addition, '-' must be the very first character,
         * and nothing can be inserted before an existing '-'.
         * Go in reverse order so the offsets are stable.
         */
    SpannableStringBuilder stripped = null;
    for (int i = end - 1; i >= start; i--) {
        char c = source.charAt(i);
        boolean strip = false;
        if (c == '-') {
            if (i != start || dstart != 0) {
                strip = true;
            } else if (sign >= 0) {
                strip = true;
            } else {
                sign = i;
            }
        } else if (c == '.') {
            if (decimal >= 0) {
                strip = true;
            } else {
                decimal = i;
            }
        }
        if (strip) {
            if (end == start + 1) {
                // Only one character, and it was stripped.
                return "";
            }
            if (stripped == null) {
                stripped = new SpannableStringBuilder(source, start, end);
            }
            stripped.delete(i - start, i + 1 - start);
        }
    }
    if (stripped != null) {
        return stripped;
    } else if (out != null) {
        return out;
    } else {
        return null;
    }
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 29 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project XobotOS by xamarin.

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 30 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project android_frameworks_base by ResurrectionRemix.

the class TextView method onSaveInstanceState.

@Override
public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    // Save state if we are forced to
    final boolean freezesText = getFreezesText();
    boolean hasSelection = false;
    int start = -1;
    int end = -1;
    if (mText != null) {
        start = getSelectionStart();
        end = getSelectionEnd();
        if (start >= 0 || end >= 0) {
            // Or save state if there is a selection
            hasSelection = true;
        }
    }
    if (freezesText || hasSelection) {
        SavedState ss = new SavedState(superState);
        if (freezesText) {
            if (mText instanceof Spanned) {
                final Spannable sp = new SpannableStringBuilder(mText);
                if (mEditor != null) {
                    removeMisspelledSpans(sp);
                    sp.removeSpan(mEditor.mSuggestionRangeSpan);
                }
                ss.text = sp;
            } else {
                ss.text = mText.toString();
            }
        }
        if (hasSelection) {
            // XXX Should also save the current scroll position!
            ss.selStart = start;
            ss.selEnd = end;
        }
        if (isFocused() && start >= 0 && end >= 0) {
            ss.frozenWithFocus = true;
        }
        ss.error = getError();
        if (mEditor != null) {
            ss.editorState = mEditor.saveInstanceState();
        }
        return ss;
    }
    return superState;
}
Also used : Parcelable(android.os.Parcelable) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)705 TextView (android.widget.TextView)114 ForegroundColorSpan (android.text.style.ForegroundColorSpan)112 View (android.view.View)100 StyleSpan (android.text.style.StyleSpan)85 ImageSpan (android.text.style.ImageSpan)77 Test (org.junit.Test)65 SpannableString (android.text.SpannableString)55 Drawable (android.graphics.drawable.Drawable)44 TextPaint (android.text.TextPaint)43 Intent (android.content.Intent)42 Spanned (android.text.Spanned)38 RelativeSizeSpan (android.text.style.RelativeSizeSpan)38 Paint (android.graphics.Paint)34 Spannable (android.text.Spannable)33 ImageView (android.widget.ImageView)31 ArrayList (java.util.ArrayList)28 Typeface (android.graphics.Typeface)26 Context (android.content.Context)25 SuppressLint (android.annotation.SuppressLint)24