Search in sources :

Example 66 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project LuaViewSDK by alibaba.

the class UDSpannableString method add.

/**
     * 两则字符串相加,产生一个新的字符串
     *
     * @param ssb
     * @return
     */
@Override
public LuaValue add(LuaValue ssb) {
    final UDSpannableString newSpannableString = new UDSpannableString(getGlobals(), getmetatable(), null);
    SpannableStringBuilder spannableStringBuilder = getSpannableStringBuilder();
    if (spannableStringBuilder != null) {
        newSpannableString.getSpannableStringBuilder().append(spannableStringBuilder);
    }
    newSpannableString.getSpannableStringBuilder().append(ssb instanceof UDSpannableString ? ((UDSpannableString) ssb).getSpannableStringBuilder() : ssb.optjstring(""));
    return newSpannableString;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 67 with SpannableStringBuilder

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

the class Clock method getSmallTime.

public final CharSequence getSmallTime() {
    Context context = getContext();
    boolean is24 = DateFormat.is24HourFormat(context);
    LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);
    final char MAGIC1 = '';
    final char MAGIC2 = '';
    SimpleDateFormat sdf;
    String format = is24 ? d.timeFormat24 : d.timeFormat12;
    if (!format.equals(mClockFormatString)) {
        /*
             * Search for an unquoted "a" in the format string, so we can
             * add dummy characters around it to let us find it again after
             * formatting and change its size.
             */
        if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
            int a = -1;
            boolean quoted = false;
            for (int i = 0; i < format.length(); i++) {
                char c = format.charAt(i);
                if (c == '\'') {
                    quoted = !quoted;
                }
                if (!quoted && c == 'a') {
                    a = i;
                    break;
                }
            }
            if (a >= 0) {
                // Move a back so any whitespace before AM/PM is also in the alternate size.
                final int b = a;
                while (a > 0 && Character.isWhitespace(format.charAt(a - 1))) {
                    a--;
                }
                format = format.substring(0, a) + MAGIC1 + format.substring(a, b) + "a" + MAGIC2 + format.substring(b + 1);
            }
        }
        mClockFormat = sdf = new SimpleDateFormat(format);
        mClockFormatString = format;
    } else {
        sdf = mClockFormat;
    }
    String result = sdf.format(mCalendar.getTime());
    if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
        int magic1 = result.indexOf(MAGIC1);
        int magic2 = result.indexOf(MAGIC2);
        if (magic1 >= 0 && magic2 > magic1) {
            SpannableStringBuilder formatted = new SpannableStringBuilder(result);
            if (AM_PM_STYLE == AM_PM_STYLE_GONE) {
                formatted.delete(magic1, magic2 + 1);
            } else {
                if (AM_PM_STYLE == AM_PM_STYLE_SMALL) {
                    CharacterStyle style = new RelativeSizeSpan(0.7f);
                    formatted.setSpan(style, magic1, magic2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
                }
                formatted.delete(magic2, magic2 + 1);
                formatted.delete(magic1, magic1 + 1);
            }
            return formatted;
        }
    }
    return result;
}
Also used : Context(android.content.Context) LocaleData(libcore.icu.LocaleData) RelativeSizeSpan(android.text.style.RelativeSizeSpan) SimpleDateFormat(java.text.SimpleDateFormat) SpannableStringBuilder(android.text.SpannableStringBuilder) CharacterStyle(android.text.style.CharacterStyle)

Example 68 with SpannableStringBuilder

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

the class ViewPropertyAlphaActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_properties);
    getWindow().getDecorView().postDelayed(new Runnable() {

        @Override
        public void run() {
            startAnim(R.id.button);
            startAnim(R.id.textview);
            startAnim(R.id.spantext);
            startAnim(R.id.edittext);
            startAnim(R.id.selectedtext);
            startAnim(R.id.textviewbackground);
            startAnim(R.id.layout);
            startAnim(R.id.imageview);
            startAnim(myViewAlphaDefault);
            startAnim(myViewAlphaHandled);
            EditText selectedText = (EditText) findViewById(R.id.selectedtext);
            selectedText.setSelection(3, 8);
        }
    }, 2000);
    Button invalidator = (Button) findViewById(R.id.invalidateButton);
    invalidator.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            findViewById(R.id.textview).invalidate();
            findViewById(R.id.spantext).invalidate();
        }
    });
    TextView textView = (TextView) findViewById(R.id.spantext);
    if (textView != null) {
        SpannableStringBuilder text = new SpannableStringBuilder("Now this is a short text message with spans");
        text.setSpan(new BackgroundColorSpan(Color.RED), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new ForegroundColorSpan(Color.BLUE), 4, 9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new SuggestionSpan(this, new String[] { "longer" }, 3), 11, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new UnderlineSpan(), 17, 20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new ImageSpan(this, R.drawable.icon), 21, 22, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(text);
    }
    LinearLayout container = (LinearLayout) findViewById(R.id.container);
    myViewAlphaDefault = new MyView(this, false);
    myViewAlphaDefault.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
    container.addView(myViewAlphaDefault);
    myViewAlphaHandled = new MyView(this, true);
    myViewAlphaHandled.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
    container.addView(myViewAlphaHandled);
}
Also used : EditText(android.widget.EditText) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextView(android.widget.TextView) View(android.view.View) UnderlineSpan(android.text.style.UnderlineSpan) Button(android.widget.Button) TextView(android.widget.TextView) SuggestionSpan(android.text.style.SuggestionSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) BackgroundColorSpan(android.text.style.BackgroundColorSpan) LinearLayout(android.widget.LinearLayout) ImageSpan(android.text.style.ImageSpan)

Example 69 with SpannableStringBuilder

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

the class NotificationBuilderTest method subst.

private static CharSequence subst(CharSequence in, char ch, CharSequence sub) {
    int i = 0;
    SpannableStringBuilder edit = new SpannableStringBuilder(in);
    while (i < edit.length()) {
        if (edit.charAt(i) == ch) {
            edit.replace(i, i + 1, sub);
            i += sub.length();
        } else {
            i++;
        }
    }
    return edit;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 70 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project HoloEverywhere by Prototik.

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)

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