Example #1
0
  /** update the level and count for the given flashcard in the database. */
  private void updateFlashcard(Flashcard fc) {
    openDB();

    _curDB.beginTransaction();
    try {
      // Delete old entry if any.
      SQLiteStatement dStmt = getCompiledStatement(SQL_DELETE_FCS);
      dStmt.bindString(1, fc.getLang1Str());
      dStmt.execute();

      // insert new state entry.
      SQLiteStatement iStmt = getCompiledStatement(SQL_INSERT_FCS);
      iStmt.bindString(1, fc.getLang1Str());
      iStmt.bindLong(2, fc.getLevel());
      iStmt.bindLong(3, fc.getRightGuessCount());
      iStmt.execute();
      _curDB.setTransactionSuccessful();
    } catch (SQLException e) {
      MsgDispatcher.sendMessageToUI(
          MsgType.MSG_SHOW_ERROR_MSG, 0, 0, "unable to update id=" + fc.getID());
    } finally {
      _curDB.endTransaction();
    }

    // this flashcard is no longer used by anyone so release it.
    fc.release();
  }
Example #2
0
  /**
   * handle a vertical or horizontal fling from within this Activity. If we have only shown the
   * first half of the current card so far, then the second half is shown to the user. Otherwise, a
   * new card is displayed.
   *
   * <p>Called by {@link AxialFlingListener} when it detects a vertical or horizontal fling.
   */
  private void handleFling(boolean isCorrectGuess) {
    if (FlashcardApp.getInstance().isShowEntireCard()) {
      // if we are already waiting for a card, ignore extra fling.
      if (_waitingForNextCard) {
        return;
      }
      _waitingForNextCard = true;

      MsgDispatcher.sendMessageToController(MsgType.MSG_GET_NEXT_FC, 0, 0, null);

      Flashcard fc = FlashcardApp.getInstance().getCurrentFlashcard();
      if (fc != null) {
        // save current fc as the previous fc. must clone it as the one
        // we send to update guess count may be released soon.
        if (_prevFlashcard != null) _prevFlashcard.release();
        _prevFlashcard = fc.clone();

        int arg1 = isCorrectGuess ? 1 : 0;
        MsgDispatcher.sendMessageToController(MsgType.MSG_FC_GUESS_RESULT, arg1, 0, fc);
      }
    } else {
      FlashcardApp.getInstance().setShowEntireCard(true);
      updateDisplay();
    }
  }