Search in sources :

Example 6 with AbsoluteSizeSpan

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;
}
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 7 with AbsoluteSizeSpan

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;
}
Also used : SpannableString(android.text.SpannableString) LayoutParams(android.view.ViewGroup.LayoutParams) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) SpannableString(android.text.SpannableString) EchoViews(com.zhan_dui.dictionary.datacenter.DictionaryParseInfomation.EchoViews) TextArg(com.zhan_dui.dictionary.datacenter.DictionaryParseInfomation.TextArg) CharacterStyle(android.text.style.CharacterStyle) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan)

Example 8 with AbsoluteSizeSpan

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;
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) Spanned(android.text.Spanned) SpannableStringBuilder(android.text.SpannableStringBuilder) CharacterStyle(android.text.style.CharacterStyle) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan)

Example 9 with AbsoluteSizeSpan

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;
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) Spanned(android.text.Spanned) SpannableStringBuilder(android.text.SpannableStringBuilder) CharacterStyle(android.text.style.CharacterStyle) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan)

Example 10 with AbsoluteSizeSpan

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));
}
Also used : SpannableString(android.text.SpannableString) SpannedString(android.text.SpannedString) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan)

Aggregations

AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)18 CharacterStyle (android.text.style.CharacterStyle)12 ForegroundColorSpan (android.text.style.ForegroundColorSpan)10 RelativeSizeSpan (android.text.style.RelativeSizeSpan)10 StrikethroughSpan (android.text.style.StrikethroughSpan)8 SpannableStringBuilder (android.text.SpannableStringBuilder)7 StyleSpan (android.text.style.StyleSpan)7 URLSpan (android.text.style.URLSpan)7 UnderlineSpan (android.text.style.UnderlineSpan)7 BackgroundColorSpan (android.text.style.BackgroundColorSpan)6 SubscriptSpan (android.text.style.SubscriptSpan)6 SuperscriptSpan (android.text.style.SuperscriptSpan)6 TypefaceSpan (android.text.style.TypefaceSpan)6 Application (android.app.Application)5 SpannableString (android.text.SpannableString)5 Spanned (android.text.Spanned)5 ImageSpan (android.text.style.ImageSpan)5 TextAppearanceSpan (android.text.style.TextAppearanceSpan)5 TextPaint (android.text.TextPaint)2 TextView (android.widget.TextView)2