Search in sources :

Example 6 with Builder

use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.

the class Lookup method lookUp.

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_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;
}
Also used : DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) Intent(android.content.Intent)

Example 7 with Builder

use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.

the class Reviewer method showDeleteNoteDialog.

private void showDeleteNoteDialog() {
    Dialog dialog;
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    builder.setTitle(res.getString(R.string.delete_card_title));
    builder.setIcon(R.drawable.ic_dialog_alert);
    builder.setMessage(String.format(res.getString(R.string.delete_note_message), Utils.stripHTML(mCurrentCard.getQuestion(true))));
    builder.setPositiveButton(res.getString(R.string.yes), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            setNextCardAnimation(false);
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData(mSched, mCurrentCard, 3));
        }
    });
    builder.setNegativeButton(res.getString(R.string.no), null);
    dialog = builder.create();
    dialog.show();
}
Also used : DialogInterface(android.content.DialogInterface) Dialog(android.app.Dialog) ProgressDialog(android.app.ProgressDialog) StyledDialog(com.ichi2.themes.StyledDialog) StyledOpenCollectionDialog(com.ichi2.themes.StyledOpenCollectionDialog) StyledProgressDialog(com.ichi2.themes.StyledProgressDialog) StyledDialog(com.ichi2.themes.StyledDialog) Resources(android.content.res.Resources)

Example 8 with Builder

use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.

the class StudyOptionsActivity method onOptionsItemSelected.

/** Handles item selections */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Resources res = this.getResources();
    switch(item.getItemId()) {
        case android.R.id.home:
            closeStudyOptions();
            return true;
        case MENU_PREFERENCES:
            startActivityForResult(new Intent(this, Preferences.class), StudyOptionsFragment.PREFERENCES_UPDATE);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE);
            }
            return true;
        case MENU_ROTATE:
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            } else {
                this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
            return true;
        case MENU_NIGHT:
            SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this);
            if (preferences.getBoolean("invertedColors", false)) {
                preferences.edit().putBoolean("invertedColors", false).commit();
                item.setIcon(R.drawable.ic_menu_night);
            } else {
                preferences.edit().putBoolean("invertedColors", true).commit();
                item.setIcon(R.drawable.ic_menu_night_checked);
            }
            return true;
        case DeckPicker.MENU_CREATE_DYNAMIC_DECK:
            StyledDialog.Builder builder = new StyledDialog.Builder(StudyOptionsActivity.this);
            builder.setTitle(res.getString(R.string.new_deck));
            mDialogEditText = new EditText(StudyOptionsActivity.this);
            ArrayList<String> names = AnkiDroidApp.getCol().getDecks().allNames();
            int n = 1;
            String cramDeckName = "Cram 1";
            while (names.contains(cramDeckName)) {
                n++;
                cramDeckName = "Cram " + n;
            }
            mDialogEditText.setText(cramDeckName);
            // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter });
            builder.setView(mDialogEditText, false, false);
            builder.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    long id;
                    Bundle initialConfig = new Bundle();
                    try {
                        initialConfig.putString("searchSuffix", "'deck:" + AnkiDroidApp.getCol().getDecks().current().getString("name") + "'");
                        id = AnkiDroidApp.getCol().getDecks().newDyn(mDialogEditText.getText().toString());
                        AnkiDroidApp.getCol().getDecks().get(id);
                    } catch (JSONException e) {
                        throw new RuntimeException(e);
                    }
                    loadContent(false, initialConfig);
                }
            });
            builder.setNegativeButton(res.getString(R.string.cancel), null);
            builder.create().show();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : EditText(android.widget.EditText) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) StyledDialog(com.ichi2.themes.StyledDialog) JSONException(org.json.JSONException) Intent(android.content.Intent) Resources(android.content.res.Resources) SharedPreferences(android.content.SharedPreferences)

Example 9 with Builder

use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.

the class StudyOptionsFragment method createFilteredDeck.

private void createFilteredDeck(JSONArray delays, Object[] terms, Boolean resched) {
    JSONObject dyn;
    if (AnkiDroidApp.colIsOpen()) {
        Collection col = AnkiDroidApp.getCol();
        try {
            String deckName = col.getDecks().current().getString("name");
            String customStudyDeck = getResources().getString(R.string.custom_study_deck_name);
            JSONObject cur = col.getDecks().byName(customStudyDeck);
            if (cur != null) {
                if (cur.getInt("dyn") != 1) {
                    StyledDialog.Builder builder = new StyledDialog.Builder(getActivity());
                    builder.setMessage(R.string.custom_study_deck_exists);
                    builder.setNegativeButton(getResources().getString(R.string.cancel), new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        //
                        }
                    });
                    builder.create().show();
                    return;
                } else {
                    // safe to empty
                    col.getSched().emptyDyn(cur.getLong("id"));
                    // reuse; don't delete as it may have children
                    dyn = cur;
                    col.getDecks().select(cur.getLong("id"));
                }
            } else {
                long did = col.getDecks().newDyn(customStudyDeck);
                dyn = col.getDecks().get(did);
            }
            // and then set various options
            dyn.put("delays", delays);
            JSONArray ar = dyn.getJSONArray("terms");
            ar.getJSONArray(0).put(0, new StringBuilder("deck:\"").append(deckName).append("\" ").append(terms[0]).toString());
            ar.getJSONArray(0).put(1, terms[1]);
            ar.getJSONArray(0).put(2, terms[2]);
            dyn.put("resched", resched);
            if (mFragmented) {
                Bundle config = new Bundle();
                config.putString("searchSuffix", "'deck:" + dyn.getString("name") + "'");
                initAllContentViews(getLayoutInflater(config));
                finishCongrats();
            } else {
                // Load a new fragment with the filtered deck view. The config passed is null, so it uses the
                // current deck. The deck we just created is internally set as the current deck.
                ((StudyOptionsActivity) getActivity()).loadContent(false, null);
            }
            // Initial rebuild
            mProgressDialog = StyledProgressDialog.show(getActivity(), "", getResources().getString(R.string.rebuild_custom_study_deck), true);
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_REBUILD_CRAM, mRebuildCustomStudyListener, new DeckTask.TaskData(AnkiDroidApp.getCol(), AnkiDroidApp.getCol().getDecks().selected(), mFragmented));
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) ChartBuilder(com.ichi2.charts.ChartBuilder) StyledDialog(com.ichi2.themes.StyledDialog) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) TaskData(com.ichi2.async.DeckTask.TaskData) DeckTask(com.ichi2.async.DeckTask) JSONObject(org.json.JSONObject) Collection(com.ichi2.libanki.Collection) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 10 with Builder

use of com.ichi2.themes.StyledDialog.Builder in project Anki-Android by Ramblurr.

the class MultimediaCardEditorActivity method showDeckSelectDialog.

private Dialog showDeckSelectDialog() {
    StyledDialog dialog = null;
    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    ArrayList<CharSequence> dialogDeckItems = new ArrayList<CharSequence>();
    // Use this array to know which ID is associated with each
    // Item(name)
    final ArrayList<Long> dialogDeckIds = new ArrayList<Long>();
    ArrayList<JSONObject> decks = mCol.getDecks().all();
    Collections.sort(decks, new JSONNameComparator());
    builder.setTitle(R.string.deck);
    for (JSONObject d : decks) {
        try {
            if (d.getInt("dyn") == 0) {
                dialogDeckItems.add(d.getString("name"));
                dialogDeckIds.add(d.getLong("id"));
            }
        } catch (JSONException e) {
            Log.e("Multimedia Editor", e.getMessage());
        }
    }
    // Convert to Array
    String[] items = new String[dialogDeckItems.size()];
    dialogDeckItems.toArray(items);
    builder.setItems(items, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int item) {
            long newId = dialogDeckIds.get(item);
            if (mCurrentDid != newId) {
                if (mAddNote) {
                    try {
                        // TODO: remove from dynamic deck (see CardEditor.java in v2.1)
                        // TODO: mEditorNote.setDid(newId);
                        mEditorNote.model().put("did", newId);
                        mCol.getModels().setChanged();
                    } catch (JSONException e) {
                        Log.e("Multimedia Editor", e.getMessage());
                    }
                }
                mCurrentDid = newId;
                createEditorUI(mNote);
            }
        }
    });
    dialog = builder.create();
    return dialog;
}
Also used : JSONNameComparator(com.ichi2.utils.JSONNameComparator) DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) SuppressLint(android.annotation.SuppressLint) JSONObject(org.json.JSONObject)

Aggregations

StyledDialog (com.ichi2.themes.StyledDialog)18 DialogInterface (android.content.DialogInterface)17 Resources (android.content.res.Resources)12 Intent (android.content.Intent)8 JSONException (org.json.JSONException)7 JSONObject (org.json.JSONObject)6 OnClickListener (android.content.DialogInterface.OnClickListener)5 ArrayList (java.util.ArrayList)5 View (android.view.View)4 TextView (android.widget.TextView)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 DeckTask (com.ichi2.async.DeckTask)3 SuppressLint (android.annotation.SuppressLint)2 Dialog (android.app.Dialog)2 OnCancelListener (android.content.DialogInterface.OnCancelListener)2 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2 OnClickListener (android.view.View.OnClickListener)2 EditText (android.widget.EditText)2