Search in sources :

Example 71 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project android_frameworks_base by crdroidandroid.

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 72 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project android_frameworks_base by AOSPA.

the class HtmlToSpannedConverter method endFont.

private static void endFont(Editable text) {
    Font font = getLast(text, Font.class);
    if (font != null) {
        setSpanFromMark(text, font, new TypefaceSpan(font.mFace));
    }
    Foreground foreground = getLast(text, Foreground.class);
    if (foreground != null) {
        setSpanFromMark(text, foreground, new ForegroundColorSpan(foreground.mForegroundColor));
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) TypefaceSpan(android.text.style.TypefaceSpan)

Example 73 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project android_frameworks_base by AOSPA.

the class CustomTile method handleUpdateState.

@Override
protected void handleUpdateState(State state, Object arg) {
    int tileState = mTile.getState();
    if (mServiceManager.hasPendingBind()) {
        tileState = Tile.STATE_UNAVAILABLE;
    }
    Drawable drawable;
    boolean mHasRes = false;
    android.graphics.drawable.Icon icon = mTile.getIcon();
    try {
        drawable = icon.loadDrawable(mAppContext);
        mHasRes = icon.getType() == android.graphics.drawable.Icon.TYPE_RESOURCE;
    } catch (Exception e) {
        Log.w(TAG, "Invalid icon, forcing into unavailable state");
        tileState = Tile.STATE_UNAVAILABLE;
        drawable = mDefaultIcon.loadDrawable(mAppContext);
    }
    int color = mContext.getColor(getColor(tileState));
    drawable.setTint(color);
    state.icon = mHasRes ? new DrawableIconWithRes(drawable, icon.getResId()) : new DrawableIcon(drawable);
    state.label = mTile.getLabel();
    if (tileState == Tile.STATE_UNAVAILABLE) {
        state.label = new SpannableStringBuilder().append(state.label, new ForegroundColorSpan(mContext.getColor(R.color.qs_tile_label_tint_unavailable)), SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
    }
    if (mTile.getContentDescription() != null) {
        state.contentDescription = mTile.getContentDescription();
    } else {
        state.contentDescription = state.label;
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Drawable(android.graphics.drawable.Drawable) Icon(android.graphics.drawable.Icon) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 74 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project AgentWeb by Justson.

the class AgentWebUtils method show.

public static void show(View parent, CharSequence text, int duration, @ColorInt int textColor, @ColorInt int bgColor, CharSequence actionText, @ColorInt int actionTextColor, View.OnClickListener listener) {
    SpannableString spannableString = new SpannableString(text);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
    spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
    Snackbar snackbar = snackbarWeakReference.get();
    View view = snackbar.getView();
    view.setBackgroundColor(bgColor);
    if (actionText != null && actionText.length() > 0 && listener != null) {
        snackbar.setActionTextColor(actionTextColor);
        snackbar.setAction(actionText, listener);
    }
    snackbar.show();
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) View(android.view.View) WebView(android.webkit.WebView) Snackbar(android.support.design.widget.Snackbar)

Example 75 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project BookReader by JustWayward.

the class BookMarkAdapter method convert.

@Override
public void convert(EasyLVHolder holder, int position, BookMark item) {
    TextView tv = holder.getView(R.id.tvMarkItem);
    SpannableString spanText = new SpannableString((position + 1) + ". " + item.title + ": ");
    spanText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.light_coffee)), 0, spanText.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    tv.setText(spanText);
    if (item.desc != null) {
        tv.append(item.desc.replaceAll(" ", "").replaceAll(" ", "").replaceAll("\n", ""));
    }
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextView(android.widget.TextView)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)157 SpannableStringBuilder (android.text.SpannableStringBuilder)57 SpannableString (android.text.SpannableString)50 StyleSpan (android.text.style.StyleSpan)25 TextView (android.widget.TextView)25 ImageSpan (android.text.style.ImageSpan)23 Spannable (android.text.Spannable)22 RelativeSizeSpan (android.text.style.RelativeSizeSpan)22 View (android.view.View)22 BackgroundColorSpan (android.text.style.BackgroundColorSpan)19 TypefaceSpan (android.text.style.TypefaceSpan)16 StrikethroughSpan (android.text.style.StrikethroughSpan)14 UnderlineSpan (android.text.style.UnderlineSpan)13 Drawable (android.graphics.drawable.Drawable)12 CharacterStyle (android.text.style.CharacterStyle)11 EditText (android.widget.EditText)11 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)8 LinearLayout (android.widget.LinearLayout)8 URLSpan (android.text.style.URLSpan)7