Search in sources :

Example 6 with StyledDialog

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

the class Info method onCreateDialog.

@Override
protected Dialog onCreateDialog(int id) {
    StyledDialog dialog = null;
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    switch(id) {
        case DIALOG_USER_NOT_LOGGED_IN_SYNC:
            builder.setTitle(R.string.connection_error_title);
            builder.setIcon(R.drawable.ic_dialog_alert);
            builder.setMessage(R.string.no_user_password_error_message);
            builder.setNegativeButton(R.string.cancel, null);
            builder.setPositiveButton(R.string.log_in, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent myAccount = new Intent(Info.this, MyAccount.class);
                    myAccount.putExtra("notLoggedIn", true);
                    startActivityForResult(myAccount, LOG_IN_FOR_SYNC);
                    if (AnkiDroidApp.SDK_VERSION > 4) {
                        ActivityTransitionAnimation.slide(Info.this, ActivityTransitionAnimation.FADE);
                    }
                }
            });
            dialog = builder.create();
            break;
        case DIALOG_UPGRADE_ERROR:
            builder.setTitle(R.string.import_title);
            builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    setResult(RESULT_CANCELED);
                    finishWithAnimation();
                }
            });
            dialog = builder.create();
            break;
        case DIALOG_SYNC_LOG:
            builder.setTitle(R.string.sync_log_title);
            builder.setPositiveButton(R.string.ok, null);
            dialog = builder.create();
            break;
        case DIALOG_SYNC_UPGRADE_REQUIRED:
            builder.setMessage(res.getString(R.string.upgrade_required, res.getString(R.string.link_anki)));
            builder.setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    downloadCollection();
                }
            });
            builder.setNegativeButton(R.string.cancel, null);
            builder.setTitle(R.string.sync_log_title);
            dialog = builder.create();
            break;
    }
    return dialog;
}
Also used : DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) Intent(android.content.Intent) Resources(android.content.res.Resources)

Example 7 with StyledDialog

use of com.ichi2.themes.StyledDialog 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 8 with StyledDialog

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

the class StudyOptionsFragment method onPrepareDialog.

private void onPrepareDialog(int id, StyledDialog styledDialog) {
    Resources res = getResources();
    switch(id) {
        case DIALOG_CUSTOM_STUDY_DETAILS:
            styledDialog.setTitle(res.getStringArray(R.array.custom_study_options_labels)[mCustomDialogChoice]);
            switch(mCustomDialogChoice + 1) {
                case CUSTOM_STUDY_NEW:
                    if (AnkiDroidApp.colIsOpen()) {
                        Collection col = AnkiDroidApp.getCol();
                        mCustomStudyTextView1.setText(res.getString(R.string.custom_study_new_total_new, col.getSched().totalNewForCurrentDeck()));
                    }
                    mCustomStudyTextView2.setText(res.getString(R.string.custom_study_new_extend));
                    mCustomStudyEditText.setText(Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendNew", 10)));
                    styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (AnkiDroidApp.colIsOpen()) {
                                try {
                                    int n = Integer.parseInt(mCustomStudyEditText.getText().toString());
                                    AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendNew", n).commit();
                                    Collection col = AnkiDroidApp.getCol();
                                    JSONObject deck = col.getDecks().current();
                                    deck.put("extendNew", n);
                                    col.getDecks().save(deck);
                                    col.getSched().extendLimits(n, 0);
                                    resetAndUpdateValuesFromDeck();
                                    finishCongrats();
                                } catch (NumberFormatException e) {
                                    // ignore non numerical values
                                    Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false);
                                } catch (JSONException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        }
                    });
                    break;
                case CUSTOM_STUDY_REV:
                    if (AnkiDroidApp.colIsOpen()) {
                        Collection col = AnkiDroidApp.getCol();
                        mCustomStudyTextView1.setText(res.getString(R.string.custom_study_rev_total_rev, col.getSched().totalRevForCurrentDeck()));
                    }
                    mCustomStudyTextView2.setText(res.getString(R.string.custom_study_rev_extend));
                    mCustomStudyEditText.setText(Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("extendRev", 10)));
                    styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (AnkiDroidApp.colIsOpen()) {
                                try {
                                    int n = Integer.parseInt(mCustomStudyEditText.getText().toString());
                                    AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendRev", n).commit();
                                    Collection col = AnkiDroidApp.getCol();
                                    JSONObject deck = col.getDecks().current();
                                    deck.put("extendRev", n);
                                    col.getDecks().save(deck);
                                    col.getSched().extendLimits(0, n);
                                    resetAndUpdateValuesFromDeck();
                                    finishCongrats();
                                } catch (NumberFormatException e) {
                                    // ignore non numerical values
                                    Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false);
                                } catch (JSONException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        }
                    });
                    break;
                case CUSTOM_STUDY_FORGOT:
                    mCustomStudyTextView1.setText("");
                    mCustomStudyTextView2.setText(res.getString(R.string.custom_study_forgotten));
                    mCustomStudyEditText.setText(Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("forgottenDays", 2)));
                    styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            JSONArray ar = new JSONArray();
                            try {
                                int forgottenDays = Integer.parseInt(((EditText) mCustomStudyEditText).getText().toString());
                                ar.put(0, 1);
                                createFilteredDeck(ar, new Object[] { String.format(Locale.US, "rated:%d:1", forgottenDays), 9999, Sched.DYN_RANDOM }, false);
                            } catch (NumberFormatException e) {
                                // ignore non numerical values
                                Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false);
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    });
                    break;
                case CUSTOM_STUDY_AHEAD:
                    mCustomStudyTextView1.setText("");
                    mCustomStudyTextView2.setText(res.getString(R.string.custom_study_ahead));
                    mCustomStudyEditText.setText(Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("aheadDays", 1)));
                    styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                int days = Integer.parseInt(((EditText) mCustomStudyEditText).getText().toString());
                                createFilteredDeck(new JSONArray(), new Object[] { String.format(Locale.US, "prop:due<=%d", days), 9999, Sched.DYN_DUE }, true);
                            } catch (NumberFormatException e) {
                                // ignore non numerical values
                                Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false);
                            }
                        }
                    });
                    break;
                case CUSTOM_STUDY_RANDOM:
                    mCustomStudyTextView1.setText("");
                    mCustomStudyTextView2.setText(res.getString(R.string.custom_study_random));
                    mCustomStudyEditText.setText(Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("randomCards", 100)));
                    styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                int randomCards = Integer.parseInt(((EditText) mCustomStudyEditText).getText().toString());
                                createFilteredDeck(new JSONArray(), new Object[] { "", randomCards, Sched.DYN_RANDOM }, true);
                            } catch (NumberFormatException e) {
                                // ignore non numerical values
                                Themes.showThemedToast(getActivity().getBaseContext(), getResources().getString(R.string.custom_study_invalid_number), false);
                            }
                        }
                    });
                    break;
                case CUSTOM_STUDY_PREVIEW:
                    mCustomStudyTextView1.setText("");
                    mCustomStudyTextView2.setText(res.getString(R.string.custom_study_preview));
                    mCustomStudyEditText.setText(Integer.toString(AnkiDroidApp.getSharedPrefs(getActivity()).getInt("previewDays", 1)));
                    styledDialog.setButtonOnClickListener(Dialog.BUTTON_POSITIVE, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String previewDays = ((EditText) mCustomStudyEditText).getText().toString();
                            createFilteredDeck(new JSONArray(), new Object[] { "is:new added:" + previewDays, 9999, Sched.DYN_OLDEST }, false);
                        }
                    });
                    break;
            }
    }
}
Also used : EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) OnClickListener(android.content.DialogInterface.OnClickListener) JSONObject(org.json.JSONObject) Collection(com.ichi2.libanki.Collection) JSONObject(org.json.JSONObject) Resources(android.content.res.Resources)

Example 9 with StyledDialog

use of com.ichi2.themes.StyledDialog 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)

Example 10 with StyledDialog

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

the class ChartBuilder method getStatisticsDialog.

public static StyledDialog getStatisticsDialog(Context context, DialogInterface.OnClickListener listener, boolean showWholeDeckSelection) {
    StyledDialog.Builder builder = new StyledDialog.Builder(context);
    builder.setTitle(context.getString(R.string.statistics_type_title));
    builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
    // set items
    String[] items = new String[3];
    items[0] = context.getResources().getString(R.string.stats_forecast);
    items[1] = context.getResources().getString(R.string.stats_review_count);
    items[2] = context.getResources().getString(R.string.stats_review_time);
    builder.setItems(items, listener);
    // period selection
    final RadioButton[] statisticRadioButtons = new RadioButton[3];
    RadioGroup rg = new RadioGroup(context);
    rg.setOrientation(RadioGroup.HORIZONTAL);
    RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
    Resources res = context.getResources();
    String[] text = res.getStringArray(R.array.stats_period);
    int height = context.getResources().getDrawable(R.drawable.white_btn_radio).getIntrinsicHeight();
    for (int i = 0; i < statisticRadioButtons.length; i++) {
        statisticRadioButtons[i] = new RadioButton(context);
        statisticRadioButtons[i].setClickable(true);
        statisticRadioButtons[i].setText("         " + text[i]);
        statisticRadioButtons[i].setHeight(height * 2);
        statisticRadioButtons[i].setSingleLine();
        statisticRadioButtons[i].setBackgroundDrawable(null);
        statisticRadioButtons[i].setGravity(Gravity.CENTER_VERTICAL);
        rg.addView(statisticRadioButtons[i], lp);
    }
    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup arg0, int arg1) {
            int checked = arg0.getCheckedRadioButtonId();
            for (int i = 0; i < 3; i++) {
                if (arg0.getChildAt(i).getId() == checked) {
                    AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putInt("statsType", i).commit();
                    break;
                }
            }
        }
    });
    rg.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, height));
    statisticRadioButtons[Math.min(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), Stats.TYPE_LIFE)].setChecked(true);
    if (showWholeDeckSelection) {
        // collection/current deck
        final RadioButton[] statisticRadioButtons2 = new RadioButton[2];
        RadioGroup rg2 = new RadioGroup(context);
        rg2.setOrientation(RadioGroup.HORIZONTAL);
        String[] text2 = res.getStringArray(R.array.stats_range);
        for (int i = 0; i < statisticRadioButtons2.length; i++) {
            statisticRadioButtons2[i] = new RadioButton(context);
            statisticRadioButtons2[i].setClickable(true);
            statisticRadioButtons2[i].setText("         " + text2[i]);
            statisticRadioButtons2[i].setHeight(height * 2);
            statisticRadioButtons2[i].setSingleLine();
            statisticRadioButtons2[i].setBackgroundDrawable(null);
            statisticRadioButtons2[i].setGravity(Gravity.CENTER_VERTICAL);
            rg2.addView(statisticRadioButtons2[i], lp);
        }
        rg2.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup arg0, int arg1) {
                AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putBoolean("statsRange", arg0.getCheckedRadioButtonId() == arg0.getChildAt(0).getId()).commit();
            }
        });
        rg2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
        statisticRadioButtons2[AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getBoolean("statsRange", true) ? 0 : 1].setChecked(true);
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        ll.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        ll.addView(rg);
        ll.addView(rg2);
        builder.setView(ll, false, true);
    } else {
        builder.setView(rg, false, true);
    }
    return builder.create();
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) RadioGroup(android.widget.RadioGroup) StyledDialog(com.ichi2.themes.StyledDialog) RadioButton(android.widget.RadioButton) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Aggregations

StyledDialog (com.ichi2.themes.StyledDialog)14 DialogInterface (android.content.DialogInterface)12 Resources (android.content.res.Resources)10 JSONException (org.json.JSONException)7 JSONObject (org.json.JSONObject)7 OnClickListener (android.content.DialogInterface.OnClickListener)6 Intent (android.content.Intent)4 ArrayList (java.util.ArrayList)4 OnCancelListener (android.content.DialogInterface.OnCancelListener)3 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 TaskData (com.ichi2.async.DeckTask.TaskData)3 JSONArray (org.json.JSONArray)3 SuppressLint (android.annotation.SuppressLint)2 NotFoundException (android.content.res.Resources.NotFoundException)2 EditText (android.widget.EditText)2 ImageView (android.widget.ImageView)2 RadioGroup (android.widget.RadioGroup)2