|
|
|
|
@ -806,12 +806,32 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
View focused = mEditTextList.getChildAt(index);
|
|
|
|
|
focused.findViewById(R.id.et_edit_text).requestFocus();
|
|
|
|
|
} else {
|
|
|
|
|
// 普通模式下,直接显示翻译结果
|
|
|
|
|
mNoteEditor.setText(result);
|
|
|
|
|
// scroll to first translation: find first occurrence of "[翻译失败]" or second line
|
|
|
|
|
int idx = result.indexOf('\n');
|
|
|
|
|
if (idx >= 0 && idx + 1 < result.length()) {
|
|
|
|
|
mNoteEditor.setSelection(idx + 1);
|
|
|
|
|
// 普通模式下,直接显示翻译结果
|
|
|
|
|
SpannableString spannable = new SpannableString(result);
|
|
|
|
|
// 分析文本结构:原文和翻译交替出现
|
|
|
|
|
// 格式:原文1\n翻译1\n原文2\n翻译2\n...
|
|
|
|
|
String[] lines = result.split("\n");
|
|
|
|
|
int currentPosition = 0;
|
|
|
|
|
boolean isTranslation = false;
|
|
|
|
|
|
|
|
|
|
for (String line : lines) {
|
|
|
|
|
if (!TextUtils.isEmpty(line)) {
|
|
|
|
|
if (isTranslation) {
|
|
|
|
|
// 设置翻译结果为浅灰色
|
|
|
|
|
int start = currentPosition;
|
|
|
|
|
int end = currentPosition + line.length();
|
|
|
|
|
spannable.setSpan(new ForegroundColorSpan(Color.parseColor("#999999")), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
}
|
|
|
|
|
isTranslation = !isTranslation;
|
|
|
|
|
}
|
|
|
|
|
currentPosition += line.length() + 1; // +1 for newline
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mNoteEditor.setText(spannable);
|
|
|
|
|
// scroll to first translation
|
|
|
|
|
int firstTranslationIdx = result.indexOf('\n');
|
|
|
|
|
if (firstTranslationIdx >= 0 && firstTranslationIdx + 1 < result.length()) {
|
|
|
|
|
mNoteEditor.setSelection(firstTranslationIdx + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|