Search in sources :

Example 56 with ForegroundColorSpan

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

the class BiDiTestBasic method useSpans.

private void useSpans() {
    EditText urlEdit = (EditText) currentView.findViewById(R.id.edittext_url);
    Editable url = urlEdit.getText();
    if (url.length() < 1) {
        return;
    }
    String urlString = url.toString();
    int urlLength = urlString.length();
    String domainAndRegistry = "amazon.co.uk";
    int startSchemeIndex = urlString.startsWith("https") ? 5 : 0;
    int startDomainIndex = urlString.indexOf(domainAndRegistry);
    if (startDomainIndex == -1) {
        assert false;
        return;
    }
    int stopIndex = startDomainIndex + domainAndRegistry.length();
    if (startDomainIndex != 0) {
        url.setSpan(new ForegroundColorSpan(0xfff00fff), startSchemeIndex, startDomainIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    url.setSpan(new ForegroundColorSpan(0xff548aff), startDomainIndex, stopIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (stopIndex < urlString.length()) {
        url.setSpan(new ForegroundColorSpan(0xfff00fff), stopIndex, urlLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
Also used : EditText(android.widget.EditText) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Editable(android.text.Editable)

Example 57 with ForegroundColorSpan

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

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(), color) : new DrawableIcon(drawable);
    state.label = mTile.getLabel();
    if (tileState == Tile.STATE_UNAVAILABLE) {
        state.label = new SpannableStringBuilder().append(state.label, new ForegroundColorSpan(color), 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 58 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project weex-example by KalicyZhou.

the class WXTextDomObject method createSetSpanOperation.

/**
   * Create a task list which contains {@link SetSpanOperation}. The task list will be executed
   * in other method.
   * @param end the end character of the text.
   * @return a task list which contains {@link SetSpanOperation}.
   */
private List<SetSpanOperation> createSetSpanOperation(int end, int spanFlag) {
    List<SetSpanOperation> ops = new LinkedList<>();
    int start = 0;
    if (end >= start) {
        if (mTextDecoration == WXTextDecoration.UNDERLINE) {
            ops.add(new SetSpanOperation(start, end, new UnderlineSpan(), spanFlag));
        }
        if (mTextDecoration == WXTextDecoration.LINETHROUGH) {
            ops.add(new SetSpanOperation(start, end, new StrikethroughSpan(), spanFlag));
        }
        if (mIsColorSet) {
            ops.add(new SetSpanOperation(start, end, new ForegroundColorSpan(mColor), spanFlag));
        }
        if (mFontSize != UNSET) {
            ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize), spanFlag));
        }
        if (mFontStyle != UNSET || mFontWeight != UNSET || mFontFamily != null) {
            ops.add(new SetSpanOperation(start, end, new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily), spanFlag));
        }
        ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment), spanFlag));
        if (mLineHeight != UNSET) {
            ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight), spanFlag));
        }
    }
    return ops;
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) LinkedList(java.util.LinkedList) TextPaint(android.text.TextPaint) UnderlineSpan(android.text.style.UnderlineSpan) StrikethroughSpan(android.text.style.StrikethroughSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan)

Example 59 with ForegroundColorSpan

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

the class RestrictedLockUtils method removeExistingRestrictedSpans.

private static void removeExistingRestrictedSpans(SpannableStringBuilder sb) {
    final int length = sb.length();
    RestrictedLockImageSpan[] imageSpans = sb.getSpans(length - 1, length, RestrictedLockImageSpan.class);
    for (ImageSpan span : imageSpans) {
        final int start = sb.getSpanStart(span);
        final int end = sb.getSpanEnd(span);
        sb.removeSpan(span);
        sb.delete(start, end);
    }
    ForegroundColorSpan[] colorSpans = sb.getSpans(0, length, ForegroundColorSpan.class);
    for (ForegroundColorSpan span : colorSpans) {
        sb.removeSpan(span);
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) ImageSpan(android.text.style.ImageSpan)

Example 60 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project materialistic by hidroh.

the class StoryView method setPromoted.

public void setPromoted(int change) {
    SpannableString spannable = new SpannableString(String.format(Locale.US, PROMOTED, change));
    spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new ForegroundColorSpan(mPromotedColorResId), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    mRankTextView.append(spannable);
}
Also used : SpannableString(android.text.SpannableString) SuperscriptSpan(android.text.style.SuperscriptSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

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