use of com.ichi2.utils.DiffEngine in project Anki-Android by Ramblurr.
the class PreviewClass method displayCardAnswer.
private void displayCardAnswer() {
// prevent answering (by e.g. gestures) before card is loaded
if (mCurrentCard == null) {
return;
}
sDisplayAnswer = true;
String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface);
answer = typeAnsAnswerFilter(answer);
String displayString = "";
if (mCurrentSimpleInterface) {
mCardContent = convertToSimple(answer);
if (mCardContent.length() == 0) {
SpannableString hint = new SpannableString(getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer));
hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mCardContent = hint;
}
} else {
Sound.stopSounds();
if (mPrefFixArabic) {
// reshape
answer = ArabicUtilities.reshapeSentence(answer, true);
}
// If the user wrote an answer
if (typeAnswer()) {
mAnswerField.setVisibility(View.GONE);
if (mCurrentCard != null) {
if (mPrefFixArabic) {
// reshape
mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true);
}
// Obtain the user answer and the correct answer
String userAnswer = mAnswerField.getText().toString();
Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect));
String correctAnswer = matcher.replaceAll("");
matcher = sBrPattern.matcher(correctAnswer);
correctAnswer = matcher.replaceAll("\n");
matcher = Sound.sSoundPattern.matcher(correctAnswer);
correctAnswer = matcher.replaceAll("");
// Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer);
// Obtain the diff and send it to updateCard
DiffEngine diff = new DiffEngine();
StringBuffer span = new StringBuffer();
span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ").append(12).append("px\">");
span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
span.append("</span>");
span.append("<br/>").append(answer);
displayString = enrichWithQADiv(span.toString(), true);
}
// Hide soft keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0);
} else {
displayString = enrichWithQADiv(answer, true);
}
}
updateCard(displayString);
}
use of com.ichi2.utils.DiffEngine in project Anki-Android by Ramblurr.
the class Reviewer method displayCardAnswer.
private void displayCardAnswer() {
Log.i(AnkiDroidApp.TAG, "displayCardAnswer");
// prevent answering (by e.g. gestures) before card is loaded
if (mCurrentCard == null) {
return;
}
sDisplayAnswer = true;
setFlipCardAnimation();
String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface);
answer = typeAnsAnswerFilter(answer);
if (mDisplayKanjiInfo) {
answer = answer + addKanjiInfo(mCurrentCard.getQuestion(mCurrentSimpleInterface));
}
String displayString = "";
if (mCurrentSimpleInterface) {
mCardContent = convertToSimple(answer);
if (mCardContent.length() == 0) {
SpannableString hint = new SpannableString(getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer));
hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mCardContent = hint;
}
} else {
Sound.stopSounds();
if (mPrefFixArabic) {
// reshape
answer = ArabicUtilities.reshapeSentence(answer, true);
}
// If the user wrote an answer
if (typeAnswer()) {
mAnswerField.setVisibility(View.GONE);
if (mCurrentCard != null) {
if (mPrefFixArabic) {
// reshape
mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true);
}
// Obtain the user answer and the correct answer
String userAnswer = mAnswerField.getText().toString();
Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect));
String correctAnswer = matcher.replaceAll("");
matcher = sBrPattern.matcher(correctAnswer);
correctAnswer = matcher.replaceAll("\n");
matcher = Sound.sSoundPattern.matcher(correctAnswer);
correctAnswer = matcher.replaceAll("");
Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer);
// Obtain the diff and send it to updateCard
DiffEngine diff = new DiffEngine();
StringBuffer span = new StringBuffer();
span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ").append(mTypeSize).append("px\">");
span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
span.append("</span>");
span.append("<br/>").append(answer);
displayString = enrichWithQADiv(span.toString(), true);
}
// Hide soft keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0);
} else {
displayString = enrichWithQADiv(answer, true);
}
}
mIsSelecting = false;
updateCard(displayString);
showEaseButtons();
// If the user want to show next question automatically
if (mPrefUseTimer) {
mTimeoutHandler.removeCallbacks(mShowQuestionTask);
mTimeoutHandler.postDelayed(mShowQuestionTask, mWaitQuestionSecond * 1000);
}
}
Aggregations