use of android.view.inputmethod.InputMethodManager 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 android.view.inputmethod.InputMethodManager in project Anki-Android by Ramblurr.
the class PreviewClass method displayCardQuestion.
private void displayCardQuestion() {
// show timer, if activated in the deck's preferences
sDisplayAnswer = false;
setInterface();
String question = mCurrentCard.getQuestion(mCurrentSimpleInterface);
question = typeAnsQuestionFilter(question);
if (mPrefFixArabic) {
question = ArabicUtilities.reshapeSentence(question, true);
}
// Log.i(AnkiDroidApp.TAG, "question: '" + question + "'");
String displayString = "";
if (mCurrentSimpleInterface) {
mCardContent = convertToSimple(question);
if (mCardContent.length() == 0) {
SpannableString hint = new SpannableString(getResources().getString(R.string.simple_interface_hint, R.string.card_details_question));
hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mCardContent = hint;
}
} else {
// If the user wants to write the answer
if (typeAnswer()) {
mAnswerField.setVisibility(View.VISIBLE);
// Show soft keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(mAnswerField, InputMethodManager.SHOW_FORCED);
}
displayString = enrichWithQADiv(question, false);
if (mSpeakText) {
// ReadText.setLanguageInformation(Model.getModel(DeckManager.getMainDeck(),
// mCurrentCard.getCardModelId(), false).getId(), mCurrentCard.getCardModelId());
}
}
updateCard(displayString);
}
use of android.view.inputmethod.InputMethodManager in project Anki-Android by Ramblurr.
the class MyAccount method login.
private void login() {
// Hide soft keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(mUsername.getWindowToken(), 0);
// trim spaces, issue 1586
String username = mUsername.getText().toString().trim();
String password = mPassword.getText().toString();
if (!"".equalsIgnoreCase(username) && !"".equalsIgnoreCase(password)) {
Connection.login(loginListener, new Connection.Payload(new Object[] { username, password }));
} else {
mInvalidUserPassAlert.show();
}
}
use of android.view.inputmethod.InputMethodManager in project Anki-Android by Ramblurr.
the class MyAccount method register.
private void register() {
// Hide soft keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(mUsername.getWindowToken(), 0);
// trim spaces, issue 1586
String username = mUsername1.getText().toString().trim();
String password = mPassword1.getText().toString();
if (!"".equalsIgnoreCase(username) && !"".equalsIgnoreCase(password)) {
Connection.register(registerListener, new Connection.Payload(new Object[] { username, password }));
} else {
mInvalidUserPassAlert.show();
}
}
use of android.view.inputmethod.InputMethodManager 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