@Override
 protected void onPrepareDialog(int id, Dialog dialog) {
   Resources res = getResources();
   StyledDialog ad = (StyledDialog) dialog;
   switch (id) {
     case DIALOG_CONTEXT_MENU:
       HashMap<String, String> card = mCards.get(mPositionInCardsList);
       int flags = Integer.parseInt(card.get("flags"));
       if (flags == 2 || flags == 3) {
         ad.changeListItem(CONTEXT_MENU_MARK, res.getString(R.string.card_browser_unmark_card));
         Log.i(AnkiDroidApp.TAG, "Selected Card is currently marked");
       } else {
         ad.changeListItem(CONTEXT_MENU_MARK, res.getString(R.string.card_browser_mark_card));
       }
       if (flags == 1 || flags == 3) {
         ad.changeListItem(
             CONTEXT_MENU_SUSPEND, res.getString(R.string.card_browser_unsuspend_card));
         Log.i(AnkiDroidApp.TAG, "Selected Card is currently suspended");
       } else {
         ad.changeListItem(
             CONTEXT_MENU_SUSPEND, res.getString(R.string.card_browser_suspend_card));
       }
       ad.setTitle(card.get("sfld"));
       break;
     case DIALOG_TAGS:
       mSelectedTags.clear();
       ad.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);
               }
             }
           });
       break;
   }
 }
 @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;
 }
Example #3
0
 public static boolean lookUp(String text) {
   if (!mIsDictionaryAvailable) {
     return false;
   }
   // clear text from leading and closing dots, commas, brackets etc.
   text =
       text.trim()
           .replaceAll("[,;:\\s\\(\\[\\)\\]\\.]*$", "")
           .replaceAll("^[,;:\\s\\(\\[\\)\\]\\.]*", "");
   switch (mDictionary) {
     case DICTIONARY_NONE:
       return false;
     case DICTIONARY_AEDICT:
       Intent aedictSearchIntent = new Intent(mDictionaryAction);
       aedictSearchIntent.putExtra("kanjis", text);
       mContext.startActivity(aedictSearchIntent);
       return true;
     case DICTIONARY_LEO_WEB:
     case DICTIONARY_LEO_APP:
       mLookupText = text;
       // localisation is needless here since leo.org translates only into or out of German
       final CharSequence[] itemValues = {"en", "fr", "es", "it", "ch", "ru"};
       String language = getLanguage(MetaDB.LANGUAGES_QA_UNDEFINED);
       if (language.length() > 0) {
         for (int i = 0; i < itemValues.length; i++) {
           if (language.equals(itemValues[i])) {
             lookupLeo(language, mLookupText);
             mLookupText = "";
             return true;
           }
         }
       }
       final String[] items = {
         "Englisch", "Französisch", "Spanisch", "Italienisch", "Chinesisch", "Russisch"
       };
       StyledDialog.Builder builder = new StyledDialog.Builder(mContext);
       builder.setTitle("\"" + mLookupText + "\" nachschlagen");
       builder.setItems(
           items,
           new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int item) {
               String language = itemValues[item].toString();
               storeLanguage(language, MetaDB.LANGUAGES_QA_UNDEFINED);
               lookupLeo(language, mLookupText);
               mLookupText = "";
             }
           });
       StyledDialog alert = builder.create();
       alert.show();
       return true;
     case DICTIONARY_COLORDICT:
       Intent colordictSearchIntent = new Intent(mDictionaryAction);
       colordictSearchIntent.putExtra("EXTRA_QUERY", text);
       mContext.startActivity(colordictSearchIntent);
       return true;
     case DICTIONARY_FORA:
       Intent foraSearchIntent = new Intent(mDictionaryAction);
       foraSearchIntent.putExtra("HEADWORD", text.trim());
       mContext.startActivity(foraSearchIntent);
       return true;
     case DICTIONARY_NCIKU_WEB:
       Intent ncikuWebIntent =
           new Intent(mDictionaryAction, Uri.parse("http://m.nciku.com/en/entry/?query=" + text));
       mContext.startActivity(ncikuWebIntent);
       return true;
     case DICTIONARY_EIJIRO_WEB:
       Intent eijiroWebIntent =
           new Intent(mDictionaryAction, Uri.parse("http://eow.alc.co.jp/" + text));
       mContext.startActivity(eijiroWebIntent);
       return true;
   }
   return false;
 }
Example #4
0
 @Override
 public void onDisconnected() {
   if (mNoConnectionAlert != null) {
     mNoConnectionAlert.show();
   }
 }