use of android.text.style.AbsoluteSizeSpan 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.AbsoluteSizeSpan in project little-bear-dictionary by daimajia.
the class QueryProcessor method processOneItem.
/**
* 对每一个单词条目生成textview
*
* @param context
* @param cursor
* @param dictionaryParseInfomation
* @param index
* @return
*/
private TextView processOneItem(Context context, Cursor cursor, DictionaryParseInfomation dictionaryParseInfomation, int index) {
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
TextView textView = new TextView(context);
for (EchoViews echoView : dictionaryParseInfomation.echoViews) {
textView.setLayoutParams(layoutParams);
textView.setPadding(DisplayUtils.dip2px(context, echoView.view_padding_left), DisplayUtils.dip2px(context, echoView.view_padding_top), DisplayUtils.dip2px(context, echoView.view_padding_right), DisplayUtils.dip2px(context, echoView.view_padding_bottom));
ArrayList<SpannableString> contents = new ArrayList<SpannableString>();
CharacterStyle colorCharacterStyle = null, sizeCharacterStyle = null;
for (TextArg textArg : echoView.sprintfArgs) {
String content = cursor.getString(cursor.getColumnIndex(textArg.argContent)) + " ";
SpannableString partString = dealAction(textArg, content);
colorCharacterStyle = null;
sizeCharacterStyle = null;
if (mIsGlobal) {
colorCharacterStyle = new ForegroundColorSpan(mGlobalColor);
sizeCharacterStyle = new AbsoluteSizeSpan(mGlobalSize);
}
if (mIsIndividual) {
if (mIsIndividualProperty && textArg.type.equalsIgnoreCase("property")) {
colorCharacterStyle = new ForegroundColorSpan(mPropertyColor);
sizeCharacterStyle = new AbsoluteSizeSpan(mPropertySize);
} else if (mIsIndividualEnglish && textArg.type.equalsIgnoreCase("english")) {
colorCharacterStyle = new ForegroundColorSpan(mEnglishColor);
sizeCharacterStyle = new AbsoluteSizeSpan(mEnglishSize);
} else if (mIsIndividualChinese && textArg.type.equalsIgnoreCase("chinese")) {
colorCharacterStyle = new ForegroundColorSpan(mChineseColor);
sizeCharacterStyle = new AbsoluteSizeSpan(mChineseSize);
} else if (mIsIndividualExample && textArg.type.equalsIgnoreCase("example")) {
colorCharacterStyle = new ForegroundColorSpan(mExampleColor);
sizeCharacterStyle = new AbsoluteSizeSpan(mExampleSize);
}
}
if (colorCharacterStyle == null || sizeCharacterStyle == null) {
if (mIsGlobal) {
colorCharacterStyle = new ForegroundColorSpan(mGlobalColor);
sizeCharacterStyle = new AbsoluteSizeSpan(mGlobalSize);
} else {
// theme style
}
}
partString.setSpan(colorCharacterStyle, 0, partString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
partString.setSpan(sizeCharacterStyle, 0, partString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
contents.add(partString);
}
CharSequence resultContent = TextUtils.concat(contents.toArray(new SpannableString[0]));
SpannableString IndexSpannableString = new SpannableString(index + ".");
if (mIsIndividual && mIsIndividualTermNum) {
colorCharacterStyle = new ForegroundColorSpan(mTermNumColor);
sizeCharacterStyle = new AbsoluteSizeSpan(mTermNumSize);
} else if (mIsGlobal) {
colorCharacterStyle = new ForegroundColorSpan(mGlobalColor);
sizeCharacterStyle = new AbsoluteSizeSpan(mGlobalSize);
} else {
// Theme style
}
IndexSpannableString.setSpan(colorCharacterStyle, 0, IndexSpannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
IndexSpannableString.setSpan(sizeCharacterStyle, 0, IndexSpannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
resultContent = TextUtils.concat(IndexSpannableString, resultContent);
textView.setText(resultContent);
}
return textView;
}
use of android.text.style.AbsoluteSizeSpan in project android_frameworks_base by DirtyUnicorns.
the class Notification method removeTextSizeSpans.
private static CharSequence removeTextSizeSpans(CharSequence charSequence) {
if (charSequence instanceof Spanned) {
Spanned ss = (Spanned) charSequence;
Object[] spans = ss.getSpans(0, ss.length(), Object.class);
SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString());
for (Object span : spans) {
Object resultSpan = span;
if (resultSpan instanceof CharacterStyle) {
resultSpan = ((CharacterStyle) span).getUnderlying();
}
if (resultSpan instanceof TextAppearanceSpan) {
TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan;
resultSpan = new TextAppearanceSpan(originalSpan.getFamily(), originalSpan.getTextStyle(), -1, originalSpan.getTextColor(), originalSpan.getLinkTextColor());
} else if (resultSpan instanceof RelativeSizeSpan || resultSpan instanceof AbsoluteSizeSpan) {
continue;
} else {
resultSpan = span;
}
builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span));
}
return builder;
}
return charSequence;
}
use of android.text.style.AbsoluteSizeSpan in project android_frameworks_base by AOSPA.
the class Notification method removeTextSizeSpans.
private static CharSequence removeTextSizeSpans(CharSequence charSequence) {
if (charSequence instanceof Spanned) {
Spanned ss = (Spanned) charSequence;
Object[] spans = ss.getSpans(0, ss.length(), Object.class);
SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString());
for (Object span : spans) {
Object resultSpan = span;
if (resultSpan instanceof CharacterStyle) {
resultSpan = ((CharacterStyle) span).getUnderlying();
}
if (resultSpan instanceof TextAppearanceSpan) {
TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan;
resultSpan = new TextAppearanceSpan(originalSpan.getFamily(), originalSpan.getTextStyle(), -1, originalSpan.getTextColor(), originalSpan.getLinkTextColor());
} else if (resultSpan instanceof RelativeSizeSpan || resultSpan instanceof AbsoluteSizeSpan) {
continue;
} else {
resultSpan = span;
}
builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span));
}
return builder;
}
return charSequence;
}
use of android.text.style.AbsoluteSizeSpan in project MVPArms by JessYanCoding.
the class UiUtils method setViewHintSize.
/**
* 设置hint大小
*
* @param size
* @param v
* @param res
*/
public static void setViewHintSize(int size, TextView v, int res) {
SpannableString ss = new SpannableString(getResources().getString(res));
// 新建一个属性对象,设置文字的大小
AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true);
// 附加属性到文本
ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// 设置hint
// 一定要进行转换,否则属性会消失
v.setHint(new SpannedString(ss));
}
Aggregations