Search in sources :

Example 16 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project actor-platform by actorapp.

the class SearchViewHacker method setHint.

public static void setHint(SearchView searchView, String hint, int resId, int color, Resources resources) {
    AutoCompleteTextView autoComplete = (AutoCompleteTextView) findView(searchView, "mQueryTextView");
    SpannableStringBuilder stopHint = new SpannableStringBuilder("");
    stopHint.append(hint);
    autoComplete.setHint(stopHint);
    autoComplete.setHintTextColor(color);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 17 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 18 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 19 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 20 with SpannableStringBuilder

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

the class Activity method setDefaultKeyMode.

/**
     * Select the default key handling for this activity.  This controls what
     * will happen to key events that are not otherwise handled.  The default
     * mode ({@link #DEFAULT_KEYS_DISABLE}) will simply drop them on the
     * floor. Other modes allow you to launch the dialer
     * ({@link #DEFAULT_KEYS_DIALER}), execute a shortcut in your options
     * menu without requiring the menu key be held down
     * ({@link #DEFAULT_KEYS_SHORTCUT}), or launch a search ({@link #DEFAULT_KEYS_SEARCH_LOCAL} 
     * and {@link #DEFAULT_KEYS_SEARCH_GLOBAL}).
     * 
     * <p>Note that the mode selected here does not impact the default
     * handling of system keys, such as the "back" and "menu" keys, and your
     * activity and its views always get a first chance to receive and handle
     * all application keys.
     * 
     * @param mode The desired default key mode constant.
     * 
     * @see #DEFAULT_KEYS_DISABLE
     * @see #DEFAULT_KEYS_DIALER
     * @see #DEFAULT_KEYS_SHORTCUT
     * @see #DEFAULT_KEYS_SEARCH_LOCAL
     * @see #DEFAULT_KEYS_SEARCH_GLOBAL
     * @see #onKeyDown
     */
public final void setDefaultKeyMode(int mode) {
    mDefaultKeyMode = mode;
    // This list must remain in sync with the switch in onKeyDown()
    switch(mode) {
        case DEFAULT_KEYS_DISABLE:
        case DEFAULT_KEYS_SHORTCUT:
            // not used in these modes
            mDefaultKeySsb = null;
            break;
        case DEFAULT_KEYS_DIALER:
        case DEFAULT_KEYS_SEARCH_LOCAL:
        case DEFAULT_KEYS_SEARCH_GLOBAL:
            mDefaultKeySsb = new SpannableStringBuilder();
            Selection.setSelection(mDefaultKeySsb, 0);
            break;
        default:
            throw new IllegalArgumentException();
    }
}
Also used : 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