Search in sources :

Example 71 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project Anki-Android by Ramblurr.

the class CompatV11 method setSubtitle.

@Override
public void setSubtitle(Activity activity, String title, boolean inverted) {
    ActionBar ab = activity.getActionBar();
    if (ab != null) {
        if (inverted) {
            CharacterStyle span = new ForegroundColorSpan(activity.getResources().getColor(inverted ? R.color.white : R.color.black));
            SpannableStringBuilder ssb = new SpannableStringBuilder(title);
            ssb.setSpan(span, 0, ssb.length(), 0);
            ab.setSubtitle(ssb);
        } else {
            ab.setSubtitle(title);
        }
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) ActionBar(android.app.ActionBar) CharacterStyle(android.text.style.CharacterStyle) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 72 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project Anki-Android by Ramblurr.

the class CompatV11 method setTitle.

@Override
public void setTitle(Activity activity, String title, boolean inverted) {
    ActionBar ab = activity.getActionBar();
    if (ab != null) {
        CharacterStyle span = new ForegroundColorSpan(activity.getResources().getColor(inverted ? R.color.white : R.color.black));
        SpannableStringBuilder ssb = new SpannableStringBuilder(title);
        ssb.setSpan(span, 0, ssb.length(), 0);
        ab.setTitle(ssb);
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) ActionBar(android.app.ActionBar) CharacterStyle(android.text.style.CharacterStyle) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 73 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)

Example 74 with SpannableStringBuilder

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

the class SmileyParser method getSpannableString.

/**
     * Retrieves the parsed text as a spannable string object.
     * @param context the context for fetching smiley resources.
     * @return the spannable string as CharSequence.
     */
public CharSequence getSpannableString(Context context) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    if (getPartCount() == 0) {
        return "";
    }
    // should have only one part since we parse smiley only
    Part part = getPart(0);
    ArrayList<Token> tokens = part.getTokens();
    int len = tokens.size();
    for (int i = 0; i < len; i++) {
        Token token = tokens.get(i);
        int start = builder.length();
        builder.append(token.getRawText());
        if (token.getType() == AbstractMessageParser.Token.Type.SMILEY) {
            int resid = mRes.getSmileyRes(token.getRawText());
            if (resid != -1) {
                builder.setSpan(new ImageSpan(context, resid), start, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return builder;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 75 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project Knife by mthli.

the class KnifeText method fromHtml.

public void fromHtml(String source) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(KnifeParser.fromHtml(source));
    switchToKnifeStyle(builder, 0, builder.length());
    setText(builder);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

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