Search in sources :

Example 1 with EASE

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

the class AbstractFlashcardViewer method answerCard.

protected void answerCard(@Consts.BUTTON_TYPE int ease) {
    if (mInAnswer) {
        return;
    }
    mIsSelecting = false;
    hideLookupButton();
    int buttonNumber = getCol().getSched().answerButtons(mCurrentCard);
    // Detect invalid ease for current card (e.g. by using keyboard shortcut or gesture).
    if (buttonNumber < ease) {
        return;
    }
    // Set the dots appearing below the toolbar
    switch(ease) {
        case EASE_1:
            mChosenAnswer.setText("\u2022");
            mChosenAnswer.setTextColor(ContextCompat.getColor(this, R.color.material_red_500));
            break;
        case EASE_2:
            mChosenAnswer.setText("\u2022\u2022");
            mChosenAnswer.setTextColor(ContextCompat.getColor(this, buttonNumber == Consts.BUTTON_FOUR ? R.color.material_blue_grey_600 : R.color.material_green_500));
            break;
        case EASE_3:
            mChosenAnswer.setText("\u2022\u2022\u2022");
            mChosenAnswer.setTextColor(ContextCompat.getColor(this, buttonNumber == Consts.BUTTON_FOUR ? R.color.material_green_500 : R.color.material_light_blue_500));
            break;
        case EASE_4:
            mChosenAnswer.setText("\u2022\u2022\u2022\u2022");
            mChosenAnswer.setTextColor(ContextCompat.getColor(this, R.color.material_light_blue_500));
            break;
        default:
            Timber.w("Unknown easy type %s", ease);
            break;
    }
    // remove chosen answer hint after a while
    mTimerHandler.removeCallbacks(removeChosenAnswerText);
    mTimerHandler.postDelayed(removeChosenAnswerText, mShowChosenAnswerLength);
    mSoundPlayer.stopSounds();
    stopOnlineSpeaking();
    mCurrentEase = ease;
    CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(true), new TaskData(mCurrentCard, mCurrentEase));
}
Also used : SuppressLint(android.annotation.SuppressLint) TaskData(com.ichi2.async.TaskData)

Example 2 with EASE

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

the class CardContentProvider method answerCard.

private void answerCard(Collection col, AbstractSched sched, Card cardToAnswer, @Consts.BUTTON_TYPE int ease, long timeTaken) {
    try {
        DB db = col.getDb();
        db.getDatabase().beginTransaction();
        try {
            if (cardToAnswer != null) {
                if (timeTaken != -1) {
                    cardToAnswer.setTimerStarted(col.getTime().intTime() - timeTaken / 1000);
                }
                sched.answerCard(cardToAnswer, ease);
            }
            db.getDatabase().setTransactionSuccessful();
        } finally {
            db.getDatabase().endTransaction();
        }
    } catch (RuntimeException e) {
        Timber.e(e, "answerCard - RuntimeException on answering card");
        AnkiDroidApp.sendExceptionReport(e, "doInBackgroundAnswerCard");
        return;
    }
}
Also used : DB(com.ichi2.libanki.DB)

Example 3 with EASE

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

the class CollectionTask method doInBackgroundAnswerCard.

private TaskData doInBackgroundAnswerCard(TaskData param) {
    Collection col = getCol();
    AbstractSched sched = col.getSched();
    Card oldCard = param.getCard();
    @Consts.BUTTON_TYPE int ease = param.getInt();
    Card newCard = null;
    Timber.i(oldCard != null ? "Answering card" : "Obtaining card");
    try {
        DB db = col.getDb();
        db.getDatabase().beginTransaction();
        try {
            if (oldCard != null) {
                Timber.i("Answering card %d", oldCard.getId());
                sched.answerCard(oldCard, ease);
            }
            newCard = sched.getCard();
            if (newCard != null) {
                // render cards before locking database
                newCard._getQA(true);
            }
            publishProgress(new TaskData(newCard));
            db.getDatabase().setTransactionSuccessful();
        } finally {
            db.getDatabase().endTransaction();
        }
    } catch (RuntimeException e) {
        Timber.e(e, "doInBackgroundAnswerCard - RuntimeException on answering card");
        AnkiDroidApp.sendExceptionReport(e, "doInBackgroundAnswerCard");
        return new TaskData(false);
    }
    return new TaskData(true);
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Collection(com.ichi2.libanki.Collection) DB(com.ichi2.libanki.DB) Card(com.ichi2.libanki.Card)

Example 4 with EASE

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

the class Sched method _updateRevIvl.

@Override
protected void _updateRevIvl(@NonNull Card card, @Consts.BUTTON_TYPE int ease) {
    try {
        int idealIvl = _nextRevIvl(card, ease);
        JSONObject conf = _revConf(card);
        card.setIvl(Math.min(Math.max(_adjRevIvl(card, idealIvl), card.getIvl() + 1), conf.getInt("maxIvl")));
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}
Also used : JSONObject(com.ichi2.utils.JSONObject) JSONException(com.ichi2.utils.JSONException)

Example 5 with EASE

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

the class SchedV2 method _nextRevIvl.

/**
 * Interval management ******************************************************
 * *****************************************
 */
/**
 * Next interval for CARD, given EASE.
 */
protected int _nextRevIvl(@NonNull Card card, @Consts.BUTTON_TYPE int ease, boolean fuzz) {
    long delay = _daysLate(card);
    JSONObject conf = _revConf(card);
    double fct = card.getFactor() / 1000.0;
    double hardFactor = conf.optDouble("hardFactor", 1.2);
    int hardMin;
    if (hardFactor > 1) {
        hardMin = card.getIvl();
    } else {
        hardMin = 0;
    }
    int ivl2 = _constrainedIvl(card.getIvl() * hardFactor, conf, hardMin, fuzz);
    if (ease == Consts.BUTTON_TWO) {
        return ivl2;
    }
    int ivl3 = _constrainedIvl((card.getIvl() + delay / 2) * fct, conf, ivl2, fuzz);
    if (ease == Consts.BUTTON_THREE) {
        return ivl3;
    }
    int ivl4 = _constrainedIvl(((card.getIvl() + delay) * fct * conf.getDouble("ease4")), conf, ivl3, fuzz);
    return ivl4;
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Aggregations

JSONObject (com.ichi2.utils.JSONObject)16 RobolectricTest (com.ichi2.anki.RobolectricTest)9 Test (org.junit.Test)9 Card (com.ichi2.libanki.Card)8 Collection (com.ichi2.libanki.Collection)7 Note (com.ichi2.libanki.Note)6 DeckConfig (com.ichi2.libanki.DeckConfig)4 JSONArray (com.ichi2.utils.JSONArray)4 JSONException (com.ichi2.utils.JSONException)4 WebView (android.webkit.WebView)3 DB (com.ichi2.libanki.DB)3 Config (org.robolectric.annotation.Config)3 SuppressLint (android.annotation.SuppressLint)2 NonNull (androidx.annotation.NonNull)2 Model (com.ichi2.libanki.Model)2 Map (java.util.Map)2 Set (java.util.Set)2 MimeTypeMap (android.webkit.MimeTypeMap)1 AnkiDb (com.ichi2.anki.AnkiDb)1 SchedulerService (com.ichi2.anki.servicelayer.SchedulerService)1