Search in sources :

Example 11 with ANSWER

use of com.ichi2.anki.CardBrowser.Column.ANSWER in project AnkiChinaAndroid by ankichinateam.

the class SchedTest method test_new_v1.

public void test_new_v1() throws Exception {
    Collection col = getColV1();
    col.reset();
    assertEquals(0, col.getSched().newDue());
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    col.reset();
    assertEquals(1, col.getSched().counts()[0]);
    // fetch it
    Card c = col.getSched().getCard();
    assertNotNull(c);
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    assertEquals(CARD_TYPE_NEW, c.getType());
    // if we answer it, it should become a learn card
    long t = col.getTime().intTime();
    col.getSched().answerCard(c, 1);
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    assertEquals(CARD_TYPE_LRN, c.getType());
    assertThat(c.getDue(), is(greaterThanOrEqualTo(t)));
// disabled for now, as the learn fudging makes this randomly fail
// // the default order should ensure siblings are not seen together, and
// // should show all cards
// Model m = col.getModels().current(); Models mm = col.getModels()
// JSONObject t = mm.newTemplate("Reverse")
// t['qfmt'] = "{{Back}}"
// t['afmt'] = "{{Front}}"
// mm.addTemplateModChanged(m, t)
// mm.save(m)
// note = col.newNote()
// note['Front'] = u"2"; note['Back'] = u"2"
// col.addNote(note)
// note = col.newNote()
// note['Front'] = u"3"; note['Back'] = u"3"
// col.addNote(note)
// col.reset()
// qs = ("2", "3", "2", "3")
// for (int n = 0; n < 4; n++) {
// c = col.getSched().getCard()
// assertTrue(qs[n] in c.q())
// col.getSched().answerCard(c, 2)
// }
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card)

Example 12 with ANSWER

use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.

the class SchedTest method test_new_v1.

public void test_new_v1() throws Exception {
    Collection col = getColV1();
    col.reset();
    assertEquals(0, col.getSched().newCount());
    // add a note
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    col.reset();
    assertEquals(1, col.getSched().counts().getNew());
    // fetch it
    Card c = getCard();
    assertNotNull(c);
    assertEquals(QUEUE_TYPE_NEW, c.getQueue());
    assertEquals(CARD_TYPE_NEW, c.getType());
    // if we answer it, it should become a learn card
    long t = col.getTime().intTime();
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(QUEUE_TYPE_LRN, c.getQueue());
    assertEquals(CARD_TYPE_LRN, c.getType());
    assertThat(c.getDue(), is(greaterThanOrEqualTo(t)));
// disabled for now, as the learn fudging makes this randomly fail
// // the default order should ensure siblings are not seen together, and
// // should show all cards
// Model m = col.getModels().current(); Models mm = col.getModels()
// JSONObject t = mm.newTemplate("Reverse")
// t['qfmt'] = "{{Back}}"
// t['afmt'] = "{{Front}}"
// mm.addTemplateModChanged(m, t)
// mm.save(m)
// note = col.newNote()
// note['Front'] = u"2"; note['Back'] = u"2"
// col.addNote(note)
// note = col.newNote()
// note['Front'] = u"3"; note['Back'] = u"3"
// col.addNote(note)
// col.reset()
// qs = ("2", "3", "2", "3")
// for (int n = 0; n < 4; n++) {
// c = getCard()
// assertTrue(qs[n] in c.q())
// col.getSched().answerCard(c, 2)
// }
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card)

Example 13 with ANSWER

use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.

the class SchedV2Test method test_counts_idxV2.

@Test
public void test_counts_idxV2() throws Exception {
    Collection col = getColV2();
    Note note = col.newNote();
    note.setItem("Front", "one");
    note.setItem("Back", "two");
    col.addNote(note);
    col.reset();
    assertEquals(new Counts(1, 0, 0), col.getSched().counts());
    Card c = getCard();
    // counter's been decremented but idx indicates 1
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    assertEquals(NEW, col.getSched().countIdx(c));
    // answer to move to learn queue
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
    // fetching again will decrement the count
    c = getCard();
    assertEquals(new Counts(0, 0, 0), col.getSched().counts());
    assertEquals(LRN, col.getSched().countIdx(c));
    // answering should add it back again
    col.getSched().answerCard(c, BUTTON_ONE);
    assertEquals(new Counts(0, 1, 0), col.getSched().counts());
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 14 with ANSWER

use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.

the class AbstractFlashcardViewer method answerCard.

protected void answerCard(@Consts.BUTTON_TYPE int ease) {
    if (mInAnswer) {
        return;
    }
    mIsSelecting = false;
    int buttonNumber = getCol().getSched().answerButtons(mCurrentCard);
    // Detect invalid ease for current card (e.g. by using keyboard shortcut or gesture).
    if (buttonNumber < ease) {
        return;
    }
    // Temporarily sets the answer indicator dots appearing below the toolbar
    mPreviousAnswerIndicator.displayAnswerIndicator(ease, buttonNumber);
    mSoundPlayer.stopSounds();
    mCurrentEase = ease;
    new SchedulerService.AnswerAndGetCard(mCurrentCard, mCurrentEase).runWithHandler(answerCardHandler(true));
}
Also used : SchedulerService(com.ichi2.anki.servicelayer.SchedulerService) SuppressLint(android.annotation.SuppressLint)

Example 15 with ANSWER

use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.

the class AbstractFlashcardViewer method displayCardQuestion.

protected void displayCardQuestion(boolean reload) {
    Timber.d("displayCardQuestion()");
    sDisplayAnswer = false;
    mBackButtonPressedToReturn = false;
    setInterface();
    mTypeAnswer.setInput("");
    mTypeAnswer.updateInfo(mCurrentCard, getResources());
    if (!mCurrentCard.isEmpty() && mTypeAnswer.validForEditText()) {
        // Show text entry based on if the user wants to write the answer
        mAnswerField.setVisibility(View.VISIBLE);
        LanguageHintService.applyLanguageHint(mAnswerField, mTypeAnswer.getLanguageHint());
    } else {
        mAnswerField.setVisibility(View.GONE);
    }
    CardHtml content = mHtmlGenerator.generateHtml(mCurrentCard, reload, Side.FRONT);
    updateCard(content);
    hideEaseButtons();
    mAutomaticAnswer.onDisplayQuestion();
    // If Card-based TTS is enabled, we "automatic display" after the TTS has finished as we don't know the duration
    if (!mTTS.isEnabled()) {
        mAutomaticAnswer.scheduleAutomaticDisplayAnswer(mUseTimerDynamicMS);
    }
    Timber.i("AbstractFlashcardViewer:: Question successfully shown for card id %d", mCurrentCard.getId());
}
Also used : CardHtml(com.ichi2.anki.cardviewer.CardHtml)

Aggregations

Test (org.junit.Test)29 Collection (com.ichi2.libanki.Collection)20 Note (com.ichi2.libanki.Note)20 Card (com.ichi2.libanki.Card)17 RobolectricTest (com.ichi2.anki.RobolectricTest)16 View (android.view.View)9 Intent (android.content.Intent)8 JSONArray (com.ichi2.utils.JSONArray)8 JSONObject (com.ichi2.utils.JSONObject)8 Model (com.ichi2.libanki.Model)7 Bundle (android.os.Bundle)6 WebView (android.webkit.WebView)6 SuppressLint (android.annotation.SuppressLint)5 SharedPreferences (android.content.SharedPreferences)5 TextView (android.widget.TextView)5 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)5 Matcher (java.util.regex.Matcher)5 InputMethodManager (android.view.inputmethod.InputMethodManager)4 Context (android.content.Context)3 Uri (android.net.Uri)3