Exemplo n.º 1
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {
      case CONTEXT_MENU_MARK:
        mPositionInCardsList = info.position;
        DeckTask.launchDeckTask(
            DeckTask.TASK_TYPE_MARK_CARD,
            mMarkCardHandler,
            new DeckTask.TaskData(0, mDeck, mSelectedCard));
        return true;
      case CONTEXT_MENU_SUSPEND:
        mPositionInCardsList = info.position;
        DeckTask.launchDeckTask(
            DeckTask.TASK_TYPE_SUSPEND_CARD,
            mSuspendCardHandler,
            new DeckTask.TaskData(0, mDeck, mSelectedCard));
        return true;
      case CONTEXT_MENU_DELETE:
        mPositionInCardsList = info.position;

        Dialog dialog;
        Resources res = getResources();
        StyledDialog.Builder builder = new StyledDialog.Builder(this);
        builder.setTitle(res.getString(R.string.delete_card_title));
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setMessage(
            String.format(
                res.getString(R.string.delete_card_message),
                mCards.get(mPositionInCardsList).get("question"),
                mCards.get(mPositionInCardsList).get("answer")));
        builder.setPositiveButton(
            res.getString(R.string.yes),
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                DeckTask.launchDeckTask(
                    DeckTask.TASK_TYPE_DELETE_CARD,
                    mDeleteCardHandler,
                    new DeckTask.TaskData(0, mDeck, mSelectedCard));
              }
            });
        builder.setNegativeButton(res.getString(R.string.no), null);
        dialog = builder.create();
        dialog.show();
        return true;
      case CONTEXT_MENU_DETAILS:
        Themes.htmlOkDialog(
                this,
                getResources().getString(R.string.card_browser_card_details),
                mSelectedCard.getCardDetails(this, true))
            .show();
        return true;
      default:
        return super.onContextItemSelected(item);
    }
  }
Exemplo n.º 2
0
 private void getCards() {
   DeckTask.launchDeckTask(
       DeckTask.TASK_TYPE_LOAD_CARDS,
       mLoadCardsHandler,
       new DeckTask.TaskData(
           mDeck,
           getResources().getStringArray(R.array.card_browser_order_values)[mSelectedOrder]));
 }
Exemplo n.º 3
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == EDIT_CARD && resultCode == RESULT_OK) {
      Log.i(AnkiDroidApp.TAG, "Saving card...");
      DeckTask.launchDeckTask(
          DeckTask.TASK_TYPE_UPDATE_FACT,
          mUpdateCardHandler,
          new DeckTask.TaskData(0, mDeck, mSelectedCard));
      // TODO: code to save the changes made to the current card.
    } else if (requestCode == ADD_FACT && resultCode == RESULT_OK) {
      getCards();
    }
  }
Exemplo n.º 4
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case MENU_UNDO:
       DeckTask.launchDeckTask(
           DeckTask.TASK_TYPE_UNDO, mUndoRedoHandler, new DeckTask.TaskData(0, mDeck, 0, true));
       return true;
     case MENU_REDO:
       DeckTask.launchDeckTask(
           DeckTask.TASK_TYPE_REDO, mUndoRedoHandler, new DeckTask.TaskData(0, mDeck, 0, true));
       return true;
     case MENU_ADD_FACT:
       startActivityForResult(new Intent(CardBrowser.this, FactAdder.class), ADD_FACT);
       if (Integer.valueOf(android.os.Build.VERSION.SDK) > 4) {
         ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
       }
       return true;
     case MENU_SHOW_MARKED:
       mShowOnlyMarSus = true;
       mSearchEditText.setHint(R.string.card_browser_show_marked);
       mCards.clear();
       for (int i = 0; i < mAllCards.size(); i++) {
         if ((mAllCards
                         .get(i)
                         .get("question")
                         .toLowerCase()
                         .indexOf(mSearchEditText.getText().toString().toLowerCase())
                     != -1
                 || mAllCards
                         .get(i)
                         .get("answer")
                         .toLowerCase()
                         .indexOf(mSearchEditText.getText().toString().toLowerCase())
                     != -1)
             && mAllCards.get(i).get("marSus").subSequence(0, 1).equals("1")) {
           mCards.add(mAllCards.get(i));
         }
       }
       updateList();
       return true;
     case MENU_SELECT_SUSPENDED:
       mShowOnlyMarSus = true;
       mSearchEditText.setHint(R.string.card_browser_show_suspended);
       mCards.clear();
       for (int i = 0; i < mAllCards.size(); i++) {
         if ((mAllCards
                         .get(i)
                         .get("question")
                         .toLowerCase()
                         .indexOf(mSearchEditText.getText().toString().toLowerCase())
                     != -1
                 || mAllCards
                         .get(i)
                         .get("answer")
                         .toLowerCase()
                         .indexOf(mSearchEditText.getText().toString().toLowerCase())
                     != -1)
             && mAllCards.get(i).get("marSus").subSequence(1, 2).equals("1")) {
           mCards.add(mAllCards.get(i));
         }
       }
       updateList();
       return true;
     case MENU_SELECT_TAG:
       recreateTagsDialog();
       mTagsDialog.show();
       return true;
     case MENU_CHANGE_ORDER:
       showDialog(DIALOG_ORDER);
       return true;
   }
   return false;
 }