@Override
        public void onClick(DialogInterface dialog, int which) {
          switch (which) {
            case CONTEXT_MENU_MARK:
              DeckTask.launchDeckTask(
                  DeckTask.TASK_TYPE_MARK_CARD,
                  mUpdateCardHandler,
                  new DeckTask.TaskData(
                      mCol.getSched(),
                      mCol.getCard(Long.parseLong(mCards.get(mPositionInCardsList).get("id"))),
                      0));
              return;

            case CONTEXT_MENU_SUSPEND:
              DeckTask.launchDeckTask(
                  DeckTask.TASK_TYPE_DISMISS_NOTE,
                  mSuspendCardHandler,
                  new DeckTask.TaskData(
                      mCol.getSched(),
                      mCol.getCard(Long.parseLong(mCards.get(mPositionInCardsList).get("id"))),
                      1));
              return;

            case CONTEXT_MENU_DELETE:
              Resources res = getResources();
              StyledDialog.Builder builder = new StyledDialog.Builder(CardBrowser.this);
              builder.setTitle(res.getString(R.string.delete_card_title));
              builder.setIcon(android.R.drawable.ic_dialog_alert);
              builder.setMessage(
                  res.getString(
                      R.string.delete_card_message, mCards.get(mPositionInCardsList).get("sfld")));
              builder.setPositiveButton(
                  res.getString(R.string.yes),
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      Card card =
                          mCol.getCard(Long.parseLong(mCards.get(mPositionInCardsList).get("id")));
                      deleteNote(card);
                      DeckTask.launchDeckTask(
                          DeckTask.TASK_TYPE_DISMISS_NOTE,
                          mDeleteNoteHandler,
                          new DeckTask.TaskData(mCol.getSched(), card, 3));
                    }
                  });
              builder.setNegativeButton(res.getString(R.string.no), null);
              builder.create().show();
              return;

            case CONTEXT_MENU_DETAILS:
              Card tempCard =
                  mCol.getCard(Long.parseLong(mCards.get(mPositionInCardsList).get("id")));
              Themes.htmlOkDialog(
                      CardBrowser.this,
                      getResources().getString(R.string.card_browser_card_details),
                      tempCard.getCardDetails(CardBrowser.this))
                  .show();
              return;
          }
        }
  @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);
    }
  }
  private void recreateTagsDialog() {
    Resources res = getResources();
    if (allTags == null) {
      String[] oldTags = AnkiDroidApp.deck().allTags_();
      Log.i(AnkiDroidApp.TAG, "all tags: " + Arrays.toString(oldTags));
      allTags = new String[oldTags.length];
      for (int i = 0; i < oldTags.length; i++) {
        allTags[i] = oldTags[i];
      }
    }
    mSelectedTags.clear();

    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    builder.setTitle(R.string.studyoptions_limit_select_tags);
    builder.setMultiChoiceItems(
        allTags,
        new boolean[0],
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            String tag = allTags[which];
            if (mSelectedTags.contains(tag)) {
              Log.i(AnkiDroidApp.TAG, "unchecked tag: " + tag);
              mSelectedTags.remove(tag);
            } else {
              Log.i(AnkiDroidApp.TAG, "checked tag: " + tag);
              mSelectedTags.add(tag);
            }
          }
        });
    builder.setPositiveButton(
        res.getString(R.string.select),
        new OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            updateCardsList();
          }
        });
    builder.setNegativeButton(
        res.getString(R.string.cancel),
        new OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            mSelectedTags.clear();
          }
        });
    builder.setOnCancelListener(
        new OnCancelListener() {

          @Override
          public void onCancel(DialogInterface dialog) {
            mSelectedTags.clear();
          }
        });
    mTagsDialog = builder.create();
  }
  @Override
  protected Dialog onCreateDialog(int id) {
    StyledDialog dialog = null;
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);

    switch (id) {
      case DIALOG_ORDER:
        builder.setTitle(res.getString(R.string.card_browser_change_display_order_title));
        builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
        builder.setSingleChoiceItems(
            getResources().getStringArray(R.array.card_browser_order_labels),
            mOrder,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface arg0, int which) {
                if (which != mOrder) {
                  mOrder = which;
                  AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext())
                      .edit()
                      .putInt("cardBrowserOrder", mOrder)
                      .commit();
                  if (mOrder != CARD_ORDER_NONE) {
                    DeckTask.launchDeckTask(
                        DeckTask.TASK_TYPE_UPDATE_CARD_BROWSER_LIST,
                        mSortCardsHandler,
                        new DeckTask.TaskData(mAllCards, new HashMapCompare()));
                  }
                }
              }
            });
        dialog = builder.create();
        break;

      case DIALOG_CONTEXT_MENU:
        String[] entries = new String[4];
        @SuppressWarnings("unused")
        MenuItem item;
        entries[CONTEXT_MENU_MARK] = res.getString(R.string.card_browser_mark_card);
        entries[CONTEXT_MENU_SUSPEND] = res.getString(R.string.card_browser_suspend_card);
        entries[CONTEXT_MENU_DELETE] = res.getString(R.string.card_browser_delete_card);
        entries[CONTEXT_MENU_DETAILS] = res.getString(R.string.card_browser_card_details);
        builder.setTitle("contextmenu");
        builder.setIcon(R.drawable.ic_menu_manage);
        builder.setItems(entries, mContextMenuListener);
        dialog = builder.create();
        break;

      case DIALOG_TAGS:
        allTags = mCol.getTags().all();
        builder.setTitle(R.string.studyoptions_limit_select_tags);
        builder.setMultiChoiceItems(
            allTags,
            new boolean[allTags.length],
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                String tag = allTags[which];
                if (mSelectedTags.contains(tag)) {
                  Log.i(AnkiDroidApp.TAG, "unchecked tag: " + tag);
                  mSelectedTags.remove(tag);
                } else {
                  Log.i(AnkiDroidApp.TAG, "checked tag: " + tag);
                  mSelectedTags.add(tag);
                }
              }
            });
        builder.setPositiveButton(
            res.getString(R.string.select),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                mSearchEditText.setText("");
                mTimerHandler.removeCallbacks(updateList);
                String tags = mSelectedTags.toString();
                mSearchEditText.setHint(
                    getResources()
                        .getString(
                            R.string.card_browser_tags_shown,
                            tags.substring(1, tags.length() - 1)));
                DeckTask.launchDeckTask(
                    DeckTask.TASK_TYPE_UPDATE_CARD_BROWSER_LIST,
                    new DeckTask.TaskListener() {
                      @Override
                      public void onPreExecute() {
                        mProgressDialog =
                            StyledProgressDialog.show(
                                CardBrowser.this,
                                "",
                                getResources().getString(R.string.card_browser_filtering_cards),
                                true);
                      }

                      @Override
                      public void onProgressUpdate(DeckTask.TaskData... values) {}

                      @Override
                      public void onPostExecute(DeckTask.TaskData result) {
                        updateList();
                        if (mProgressDialog != null && mProgressDialog.isShowing()) {
                          mProgressDialog.dismiss();
                        }
                      }
                    },
                    new DeckTask.TaskData(mAllCards),
                    new DeckTask.TaskData(mCards),
                    new DeckTask.TaskData(new Object[] {mSelectedTags}));
              }
            });
        builder.setNegativeButton(
            res.getString(R.string.cancel),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                mSelectedTags.clear();
              }
            });
        builder.setOnCancelListener(
            new OnCancelListener() {

              @Override
              public void onCancel(DialogInterface dialog) {
                mSelectedTags.clear();
              }
            });
        dialog = builder.create();
        break;
        //		case DIALOG_RELOAD_CARDS:
        //			builder.setTitle(res.getString(R.string.pref_cache_cardbrowser));
        //			builder.setMessage(res.getString(R.string.pref_cache_cardbrowser_reload));
        //			builder.setPositiveButton(res.getString(R.string.yes), new OnClickListener() {
        //
        //				@Override
        //				public void onClick(DialogInterface arg0, int arg1) {
        //					DeckTask.launchDeckTask(DeckTask.TASK_TYPE_LOAD_CARDS,
        //							mLoadCardsHandler,
        //							new DeckTask.TaskData(mDeck, LOAD_CHUNK));
        //					}
        //
        //			});
        //			builder.setNegativeButton(res.getString(R.string.no), new OnClickListener() {
        //
        //				@Override
        //				public void onClick(DialogInterface arg0, int arg1) {
        //					mAllCards.addAll(sAllCardsCache);
        //					mCards.addAll(mAllCards);
        //					updateList();
        //				}
        //
        //			});
        //			builder.setCancelable(true);
        //			builder.setOnCancelListener(new OnCancelListener() {
        //
        //				@Override
        //				public void onCancel(DialogInterface arg0) {
        //					mAllCards.addAll(sAllCardsCache);
        //					mCards.addAll(mAllCards);
        //					updateList();
        //				}
        //
        //			});
        //			dialog = builder.create();
        //			break;
      case DIALOG_FIELD:
        builder.setTitle(res.getString(R.string.card_browser_field_title));
        builder.setIcon(android.R.drawable.ic_menu_sort_by_size);

        HashMap<String, String> card = mAllCards.get(0);

        String[][] items = mCol.getCard(Long.parseLong(card.get("id"))).note().items();

        mFields = new String[items.length + 1];
        mFields[0] = "SFLD";

        for (int i = 0; i < items.length; i++) {
          mFields[i + 1] = items[i][0];
        }

        builder.setSingleChoiceItems(
            mFields,
            0,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface arg0, int which) {
                if (which != mField) {
                  mField = which;
                  AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext())
                      .edit()
                      .putInt("cardBrowserField", mField)
                      .commit();
                  getCards();
                }
              }
            });
        dialog = builder.create();
        break;
    }
    return dialog;
  }
示例#5
0
  @Override
  protected Dialog onCreateDialog(int id) {
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    switch (id) {
      case DIALOG_BACKUP:
        builder.setTitle(res.getString(R.string.backup_manager_title));
        builder.setCancelable(false);
        builder.setMessage(res.getString(R.string.pref_backup_warning));
        builder.setPositiveButton(
            res.getString(R.string.yes),
            new OnClickListener() {

              @Override
              public void onClick(DialogInterface arg0, int arg1) {
                lockCheckAction = true;
                useBackupPreference.setChecked(false);
                dialogMessage = getResources().getString(R.string.backup_delete);
                DeckTask.launchDeckTask(
                    DeckTask.TASK_TYPE_DELETE_BACKUPS,
                    mDeckOperationHandler,
                    (DeckTask.TaskData[]) null);
              }
            });
        builder.setNegativeButton(res.getString(R.string.no), null);
        break;
      case DIALOG_ASYNC:
        builder.setTitle(res.getString(R.string.async_mode));
        builder.setCancelable(false);
        builder.setMessage(res.getString(R.string.async_mode_message));
        builder.setPositiveButton(
            res.getString(R.string.yes),
            new OnClickListener() {

              @Override
              public void onClick(DialogInterface arg0, int arg1) {
                lockCheckAction = true;
                asyncModePreference.setChecked(true);
              }
            });
        builder.setNegativeButton(res.getString(R.string.no), null);
        break;
      case DIALOG_WRITE_ANSWERS:
        builder.setTitle(res.getString(R.string.write_answers));
        builder.setCancelable(false);
        builder.setMessage(res.getString(R.string.write_answers_message));
        builder.setNegativeButton(res.getString(R.string.ok), null);
        break;
      case DIALOG_HEBREW_FONT:
        builder.setTitle(res.getString(R.string.fix_hebrew_text));
        builder.setCancelable(false);
        builder.setMessage(
            res.getString(
                R.string.fix_hebrew_instructions, AnkiDroidApp.getCurrentAnkiDroidDirectory()));
        builder.setNegativeButton(R.string.cancel, null);
        builder.setPositiveButton(
            res.getString(R.string.fix_hebrew_download_font),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                Intent intent =
                    new Intent(
                        "android.intent.action.VIEW",
                        Uri.parse(getResources().getString(R.string.link_hebrew_font)));
                startActivity(intent);
              }
            });
        break;
    }
    return builder.create();
  }