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));
}
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;
}
}
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);
}
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);
}
}
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;
}
Aggregations