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);
}
}
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;
}
}
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;
}
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);
}
}
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);
}
Aggregations