Search in sources :

Example 26 with InputMethodManager

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);
}
Also used : SpannableString(android.text.SpannableString) DiffEngine(com.ichi2.utils.DiffEngine) Matcher(java.util.regex.Matcher) StyleSpan(android.text.style.StyleSpan) InputMethodManager(android.view.inputmethod.InputMethodManager) SpannedString(android.text.SpannedString) SpannableString(android.text.SpannableString)

Example 27 with InputMethodManager

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);
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) InputMethodManager(android.view.inputmethod.InputMethodManager) SpannedString(android.text.SpannedString) SpannableString(android.text.SpannableString)

Example 28 with InputMethodManager

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();
    }
}
Also used : Payload(com.ichi2.async.Connection.Payload) Connection(com.ichi2.async.Connection) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 29 with InputMethodManager

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();
    }
}
Also used : Payload(com.ichi2.async.Connection.Payload) Connection(com.ichi2.async.Connection) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 30 with InputMethodManager

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);
    }
}
Also used : SpannableString(android.text.SpannableString) DiffEngine(com.ichi2.utils.DiffEngine) Matcher(java.util.regex.Matcher) StyleSpan(android.text.style.StyleSpan) InputMethodManager(android.view.inputmethod.InputMethodManager) SpannedString(android.text.SpannedString) SpannableString(android.text.SpannableString)

Aggregations

InputMethodManager (android.view.inputmethod.InputMethodManager)601 View (android.view.View)113 TextView (android.widget.TextView)61 Paint (android.graphics.Paint)43 Spannable (android.text.Spannable)34 Editable (android.text.Editable)32 EditText (android.widget.EditText)30 Intent (android.content.Intent)29 ImageView (android.widget.ImageView)29 RemoteException (android.os.RemoteException)23 TextPaint (android.text.TextPaint)21 KeyEvent (android.view.KeyEvent)20 Point (android.graphics.Point)18 InputMethodInfo (android.view.inputmethod.InputMethodInfo)18 AdapterView (android.widget.AdapterView)17 Button (android.widget.Button)17 RemoteView (android.widget.RemoteViews.RemoteView)16 Resources (android.content.res.Resources)15 ListView (android.widget.ListView)15 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)14