use of com.zhan_dui.dictionary.datacenter.DictionaryParseInfomation.EchoViews 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;
}
Aggregations