Search in sources :

Example 1 with CHECK_DATABASE

use of com.ichi2.async.CollectionTask.TASK_TYPE.CHECK_DATABASE in project Anki-Android by Ramblurr.

the class DeckPicker method onOptionsItemSelected.

/**
 * Handles item selections
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Resources res = getResources();
    switch(item.getItemId()) {
        case MENU_HELP:
            showDialog(DIALOG_SELECT_HELP);
            return true;
        case MENU_SYNC:
            sync();
            return true;
        case MENU_ADD_NOTE:
            addNote();
            return true;
        case MENU_STATISTICS:
            showDialog(DIALOG_SELECT_STATISTICS_TYPE);
            return true;
        case MENU_CARDBROWSER:
            openCardBrowser();
            return true;
        case MENU_CREATE_DECK:
            StyledDialog.Builder builder2 = new StyledDialog.Builder(DeckPicker.this);
            builder2.setTitle(res.getString(R.string.new_deck));
            mDialogEditText = (EditText) new EditText(DeckPicker.this);
            // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter });
            builder2.setView(mDialogEditText, false, false);
            builder2.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String deckName = mDialogEditText.getText().toString().replaceAll("[\'\"\\n\\r\\[\\]\\(\\)]", "");
                    // Log.i(AnkiDroidApp.TAG, "Creating deck: " + deckName);
                    AnkiDroidApp.getCol().getDecks().id(deckName, true);
                    loadCounts();
                }
            });
            builder2.setNegativeButton(res.getString(R.string.cancel), null);
            builder2.create().show();
            return true;
        case MENU_CREATE_DYNAMIC_DECK:
            StyledDialog.Builder builder3 = new StyledDialog.Builder(DeckPicker.this);
            builder3.setTitle(res.getString(R.string.new_deck));
            mDialogEditText = (EditText) new EditText(DeckPicker.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 });
            builder3.setView(mDialogEditText, false, false);
            builder3.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    long id = AnkiDroidApp.getCol().getDecks().newDyn(mDialogEditText.getText().toString());
                    openStudyOptions(id, new Bundle());
                }
            });
            builder3.setNegativeButton(res.getString(R.string.cancel), null);
            builder3.create().show();
            return true;
        case MENU_ABOUT:
            startActivity(new Intent(DeckPicker.this, Info.class));
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.RIGHT);
            }
            return true;
        case MENU_ADD_SHARED_DECK:
            if (AnkiDroidApp.getCol() != null) {
                SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
                String hkey = preferences.getString("hkey", "");
                if (hkey.length() == 0) {
                    showDialog(DIALOG_USER_NOT_LOGGED_IN_ADD_SHARED_DECK);
                } else {
                    addSharedDeck();
                }
            }
            return true;
        case MENU_IMPORT:
            showDialog(DIALOG_IMPORT_HINT);
            return true;
        case MENU_PREFERENCES:
            startActivityForResult(new Intent(DeckPicker.this, Preferences.class), PREFERENCES_UPDATE);
            return true;
        case MENU_FEEDBACK:
            Intent i = new Intent(DeckPicker.this, Feedback.class);
            i.putExtra("request", REPORT_FEEDBACK);
            startActivityForResult(i, REPORT_FEEDBACK);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
            }
            return true;
        case CHECK_DATABASE:
            integrityCheck();
            return true;
        case StudyOptionsActivity.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 StudyOptionsActivity.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 MENU_REUPGRADE:
            restartUpgradeProcess();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) ChartBuilder(com.ichi2.charts.ChartBuilder) StyledDialog(com.ichi2.themes.StyledDialog) Intent(android.content.Intent) ActivityInfo(android.content.pm.ActivityInfo) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) Resources(android.content.res.Resources) SharedPreferences(android.content.SharedPreferences)

Aggregations

DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 ActivityInfo (android.content.pm.ActivityInfo)1 Resources (android.content.res.Resources)1 Bundle (android.os.Bundle)1 ContextMenuInfo (android.view.ContextMenu.ContextMenuInfo)1 EditText (android.widget.EditText)1 ChartBuilder (com.ichi2.charts.ChartBuilder)1 StyledDialog (com.ichi2.themes.StyledDialog)1