Search in sources :

Example 1 with TextArg

use of com.zhan_dui.dictionary.datacenter.DictionaryParseInfomation.TextArg 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)

Aggregations

SpannableString (android.text.SpannableString)1 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)1 CharacterStyle (android.text.style.CharacterStyle)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 TextView (android.widget.TextView)1 EchoViews (com.zhan_dui.dictionary.datacenter.DictionaryParseInfomation.EchoViews)1 TextArg (com.zhan_dui.dictionary.datacenter.DictionaryParseInfomation.TextArg)1 ArrayList (java.util.ArrayList)1