use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by ankidroid.
the class ContentProviderTest method testAnswerCard.
/**
* Test giving the answer for a reviewed card
*/
@Test
public void testAnswerCard() {
Collection col = getCol();
Card card = getFirstCardFromScheduler(col);
long cardId = card.getId();
// the card starts out being new
assertEquals("card is initial new", Consts.CARD_TYPE_NEW, card.getQueue());
ContentResolver cr = getContentResolver();
Uri reviewInfoUri = FlashCardsContract.ReviewInfo.CONTENT_URI;
ContentValues values = new ContentValues();
long noteId = card.note().getId();
int cardOrd = card.getOrd();
int earlyGraduatingEase = (schedVersion == 1) ? AbstractFlashcardViewer.EASE_3 : AbstractFlashcardViewer.EASE_4;
// 5 seconds
long timeTaken = 5000;
values.put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId);
values.put(FlashCardsContract.ReviewInfo.CARD_ORD, cardOrd);
values.put(FlashCardsContract.ReviewInfo.EASE, earlyGraduatingEase);
values.put(FlashCardsContract.ReviewInfo.TIME_TAKEN, timeTaken);
int updateCount = cr.update(reviewInfoUri, values, null, null);
assertEquals("Check if update returns 1", 1, updateCount);
try {
Thread.currentThread().wait(500);
} catch (Exception e) {
/* do nothing */
}
col.reset();
Card newCard = col.getSched().getCard();
if (newCard != null) {
if (newCard.note().getId() == card.note().getId() && newCard.getOrd() == card.getOrd()) {
fail("Next scheduled card has not changed");
}
}
// lookup the card after update, ensure it's not new anymore
Card cardAfterReview = col.getCard(cardId);
assertEquals("card is now type rev", Card.TYPE_REV, cardAfterReview.getQueue());
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER 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);
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by Ramblurr.
the class Reviewer method onCreate.
// ----------------------------------------------------------------------------
// ANDROID METHODS
// ----------------------------------------------------------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
Themes.applyTheme(this);
super.onCreate(savedInstanceState);
// Remove the status bar and title bar
if (mPrefFullscreenReview) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Do not hide the title bar in Honeycomb, since it contains the action bar.
if (AnkiDroidApp.SDK_VERSION <= 11) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
}
mChangeBorderStyle = Themes.getTheme() == Themes.THEME_ANDROID_LIGHT || Themes.getTheme() == Themes.THEME_ANDROID_DARK;
// The hardware buttons should control the music volume while reviewing.
setVolumeControlStream(AudioManager.STREAM_MUSIC);
Collection col = AnkiDroidApp.getCol();
if (col == null) {
reloadCollection(savedInstanceState);
return;
} else {
mSched = col.getSched();
mCollectionFilename = col.getPath();
mBaseUrl = Utils.getBaseUrl(col.getMedia().getDir());
restorePreferences();
setFullScreen(mPrefFullscreenReview);
registerExternalStorageListener();
if (mNightMode) {
mCurrentBackgroundColor = Themes.getNightModeCardBackground(this);
} else {
mCurrentBackgroundColor = Color.WHITE;
}
mUseQuickUpdate = shouldUseQuickUpdate();
initLayout(R.layout.flashcard);
try {
String[] title = mSched.getCol().getDecks().current().getString("name").split("::");
AnkiDroidApp.getCompat().setTitle(this, title[title.length - 1], mInvertedColors);
} catch (JSONException e) {
throw new RuntimeException(e);
}
AnkiDroidApp.getCompat().setSubtitle(this, "", mInvertedColors);
if (mPrefTextSelection) {
clipboardSetText("");
}
// Load the template for the card
try {
mCardTemplate = Utils.convertStreamToString(getAssets().open("card_template.html"));
} catch (IOException e) {
e.printStackTrace();
}
// Initialize text-to-speech. This is an asynchronous operation.
if (mSpeakText) {
ReadText.initializeTts(this);
}
// Get last whiteboard state
if (mPrefWhiteboard && mCurrentCard != null && MetaDB.getWhiteboardState(this, mCurrentCard.getDid()) == 1) {
mShowWhiteboard = true;
mWhiteboard.setVisibility(View.VISIBLE);
}
// Load the first card and start reviewing. Uses the answer card
// task to load a card, but since we send null
// as the card to answer, no card will be answered.
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler, new DeckTask.TaskData(mSched, null, 0));
// Since we aren't actually answering a card, decrement the rep count
mSched.setReps(mSched.getReps() - 1);
}
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project Anki-Android by Ramblurr.
the class Reviewer method displayCardAnswer.
private void 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);
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);
}
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project AnkiChinaAndroid by ankichinateam.
the class Reviewer method onCollectionLoaded.
@Override
protected void onCollectionLoaded(Collection col) {
super.onCollectionLoaded(col);
// Load the first card and start reviewing. Uses the answer card
// task to load a card, but since we send null
// as the card to answer, no card will be answered.
mPrefWhiteboard = MetaDB.getWhiteboardState(this, getParentDid());
if (mPrefWhiteboard) {
// DEFECT: Slight inefficiency here, as we set the database using these methods
boolean whiteboardVisibility = MetaDB.getWhiteboardVisibility(this, getParentDid());
setWhiteboardEnabledState(true);
setWhiteboardVisibility(whiteboardVisibility);
}
// Reset schedule in case card was previously loaded
col.getSched().deferReset();
getCol().startTimebox();
CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(false), new TaskData(null, 0));
disableDrawerSwipeOnConflicts();
// Add a weak reference to current activity so that scheduler can talk to to Activity
mSched.setContext(new WeakReference<Activity>(this));
// Set full screen/immersive mode if needed
if (mPrefFullscreenReview) {
CompatHelper.getCompat().setFullScreen(this);
}
}
Aggregations