use of com.ichi2.anki.Reviewer in project AnkiChinaAndroid by ankichinateam.
the class ReadText method initializeTts.
public static String initializeTts(Context context, boolean vipSpeak, boolean showToast, ReadTextListener listener) {
// Store weak reference to Activity to prevent memory leak
mReviewer = new WeakReference<>(context);
// Create new TTS object and setup its onInit Listener
mTts = new TextToSpeech(context, status -> {
if (status == TextToSpeech.SUCCESS) {
// build list of available languages
buildAvailableLanguages(TextToSpeech.LANG_AVAILABLE);
if (availableTtsLocales.size() > 0) {
// notify the reviewer that TTS has been initialized
Timber.d("TTS initialized and available languages found");
if (listener != null) {
listener.ttsInitialized();
}
// ((AbstractFlashcardViewer) mReviewer.get()).ttsInitialized();
} else {
if (showToast) {
Toast.makeText(mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message), Toast.LENGTH_LONG).show();
}
Timber.w("TTS initialized but no available languages found");
}
mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onDone(String arg0) {
if (ReadText.sTextQueue.size() > 0) {
String[] text = ReadText.sTextQueue.remove(0);
ReadText.speak(text[0], text[1], TextToSpeech.QUEUE_FLUSH);
}
if (listener != null) {
listener.onDone();
}
}
@Override
@Deprecated
public void onError(String utteranceId) {
Timber.v("Andoid TTS failed. Check logcat for error. Indicates a problem with Android TTS engine.");
final Uri helpUrl = Uri.parse(mReviewer.get().getString(R.string.link_faq_tts));
final AnkiActivity ankiActivity = (AnkiActivity) mReviewer.get();
ankiActivity.mayOpenUrl(helpUrl);
if (showToast) {
UIUtils.showSnackbar(ankiActivity, R.string.no_tts_available_message, false, R.string.help, v -> openTtsHelpUrl(helpUrl), ankiActivity.findViewById(R.id.root_layout), new Snackbar.Callback());
}
}
@Override
public void onStart(String arg0) {
// no nothing
}
});
} else {
if (showToast) {
Toast.makeText(mReviewer.get(), mReviewer.get().getString(R.string.no_tts_available_message), Toast.LENGTH_LONG).show();
}
Timber.w("TTS not successfully initialized");
}
});
// Show toast that it's getting initialized, as it can take a while before the sound plays the first time
if (showToast) {
Toast.makeText(context, context.getString(R.string.initializing_tts), Toast.LENGTH_LONG).show();
}
return mTts.getDefaultEngine();
}
use of com.ichi2.anki.Reviewer in project AnkiChinaAndroid by ankichinateam.
the class ReviewerTest method testMultipleCards.
@Test
public synchronized void testMultipleCards() throws ConfirmModSchemaException, InterruptedException {
addNoteWithThreeCards();
Collection col = getCol();
JSONObject nw = col.getDecks().confForDid(1).getJSONObject("new");
MockTime time = getCollectionTime();
nw.put("delays", new JSONArray(new int[] { 1, 10, 60, 120 }));
waitForAsyncTasksToComplete();
Reviewer reviewer = startReviewer();
waitForAsyncTasksToComplete();
assertCounts(reviewer, 3, 0, 0);
// card 1 is shown
answerCardOrdinalAsGood(reviewer, 1);
// card get scheduler in [10, 12.5] minutes
time.addM(3);
// We wait 3 minutes to ensure card 2 is scheduled after card 1
// card 2 is shown
answerCardOrdinalAsGood(reviewer, 2);
// Same as above
time.addM(3);
// card 3 is shown
answerCardOrdinalAsGood(reviewer, 3);
undo(reviewer);
assertCurrentOrdIs(reviewer, 3);
// card 3 is shown
answerCardOrdinalAsGood(reviewer, 3);
// Anki Desktop shows "1"
assertCurrentOrdIsNot(reviewer, 3);
}
use of com.ichi2.anki.Reviewer in project AnkiChinaAndroid by ankichinateam.
the class SchedV2 method getCard.
/**
* Pop the next card from the queue. null if finished.
*/
@Nullable
public Card getCard() {
_checkDay();
// check day deal with cutoff if required. No need to do it in resets
if (!mHaveCounts) {
resetCounts(false);
}
if (!mHaveQueues) {
resetQueues(false);
}
@Nullable Card card = _getCard();
if (card != null) {
mCol.log(card);
incrReps();
// In upstream, counts are decremented when the card is
// gotten; i.e. in _getLrnCard, _getRevCard and
// _getNewCard. This can not be done anymore since we use
// those methods to pre-fetch the next card. Instead we
// decrement the counts here, when the card is returned to
// the reviewer.
decrementCounts(card);
setCurrentCard(card);
card.startTimer();
} else {
discardCurrentCard();
}
return card;
}
use of com.ichi2.anki.Reviewer in project Anki-Android by ankidroid.
the class SchedV2 method counts.
/**
* Same as counts(), but also count `card`. In practice, we use it because `card` is in the reviewer and that is the
* number we actually want.
* Overridden: left / 1000 in V1
*/
@NonNull
public Counts counts(@NonNull Card card) {
Counts counts = counts();
Queue idx = countIdx(card);
counts.changeCount(idx, 1);
return counts;
}
use of com.ichi2.anki.Reviewer in project Anki-Android by ankidroid.
the class SchedV2 method getCard.
/**
* Pop the next card from the queue. null if finished.
*/
@Nullable
public Card getCard() {
_checkDay();
if (!mHaveQueues) {
resetQueues(false);
}
@Nullable Card card = _getCard();
if (card == null && !mHaveCounts) {
// maybe we didn't refill queues because counts were not
// set. This could only occur if the only card is a buried
// sibling. So let's try to set counts and check again.
reset();
card = _getCard();
}
if (card != null) {
mCol.log(card);
incrReps();
// In upstream, counts are decremented when the card is
// gotten; i.e. in _getLrnCard, _getRevCard and
// _getNewCard. This can not be done anymore since we use
// those methods to pre-fetch the next card. Instead we
// decrement the counts here, when the card is returned to
// the reviewer.
decrementCounts(card);
setCurrentCard(card);
card.startTimer();
} else {
discardCurrentCard();
}
if (!mHaveCounts) {
// Need to reset queues once counts are reset
TaskManager.launchCollectionTask(new CollectionTask.Reset());
}
return card;
}
Aggregations