Example usage for android.content.res Resources getString

List of usage examples for android.content.res Resources getString

Introduction

In this page you can find the example usage for android.content.res Resources getString.

Prototype

@NonNull
public String getString(@StringRes int id) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.nit.vicky.DeckPicker.java

@Override
protected Dialog onCreateDialog(int id) {
    StyledDialog dialog;/*from   w  w  w. j  a  v a 2s.c o m*/
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);

    switch (id) {
    case DIALOG_OK:
        builder.setPositiveButton(R.string.ok, null);
        dialog = builder.create();
        break;

    case DIALOG_NO_SDCARD:
        builder.setMessage("The SD card could not be read. Please, turn off USB storage.");
        builder.setPositiveButton(R.string.ok, null);
        dialog = builder.create();
        break;

    case DIALOG_SELECT_HELP:
        builder.setTitle(res.getString(R.string.help_title));
        builder.setItems(new String[] { res.getString(R.string.help_tutorial),
                res.getString(R.string.help_online), res.getString(R.string.help_faq) },
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        if (arg1 == 0) {
                            createTutorialDeck();
                        } else {
                            if (Utils.isIntentAvailable(DeckPicker.this, "android.intent.action.VIEW")) {
                                Intent intent = new Intent("android.intent.action.VIEW",
                                        Uri.parse(getResources().getString(
                                                arg1 == 0 ? R.string.link_help : R.string.link_faq)));
                                startActivity(intent);
                            } else {
                                startActivity(new Intent(DeckPicker.this, Info.class));
                            }
                        }
                    }

                });
        dialog = builder.create();
        break;

    case DIALOG_CONNECTION_ERROR:
        builder.setTitle(res.getString(R.string.connection_error_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setMessage(res.getString(R.string.connection_error_message));
        builder.setPositiveButton(res.getString(R.string.retry), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sync();
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        dialog = builder.create();
        break;

    case DIALOG_SYNC_CONFLICT_RESOLUTION:
        builder.setTitle(res.getString(R.string.sync_conflict_title));
        builder.setIcon(android.R.drawable.ic_input_get);
        builder.setMessage(res.getString(R.string.sync_conflict_message));
        builder.setPositiveButton(res.getString(R.string.sync_conflict_local), mSyncConflictResolutionListener);
        builder.setNeutralButton(res.getString(R.string.sync_conflict_remote), mSyncConflictResolutionListener);
        builder.setNegativeButton(res.getString(R.string.sync_conflict_cancel),
                mSyncConflictResolutionListener);
        builder.setCancelable(true);
        dialog = builder.create();
        break;

    case DIALOG_LOAD_FAILED:
        builder.setMessage(res.getString(R.string.open_collection_failed_message,
                BackupManager.BROKEN_DECKS_SUFFIX, res.getString(R.string.repair_deck)));
        builder.setTitle(R.string.open_collection_failed_title);
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.error_handling_options),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        showDialog(DIALOG_ERROR_HANDLING);
                    }
                });
        builder.setNegativeButton(res.getString(R.string.close), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finishWithAnimation();
            }
        });
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                finishWithAnimation();
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_DB_ERROR:
        builder.setMessage(R.string.answering_error_message);
        builder.setTitle(R.string.answering_error_title);
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.error_handling_options),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        showDialog(DIALOG_ERROR_HANDLING);
                    }
                });
        builder.setNeutralButton(res.getString(R.string.answering_error_report),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent i = new Intent(DeckPicker.this, Feedback.class);
                        i.putExtra("request", RESULT_DB_ERROR);
                        dialog.dismiss();
                        startActivityForResult(i, REPORT_ERROR);
                        if (AnkiDroidApp.SDK_VERSION > 4) {
                            ActivityTransitionAnimation.slide(DeckPicker.this,
                                    ActivityTransitionAnimation.RIGHT);
                        }
                    }
                });
        builder.setNegativeButton(res.getString(R.string.close), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (!AnkiDroidApp.colIsOpen()) {
                    finishWithAnimation();
                }
            }
        });
        builder.setCancelable(true);
        dialog = builder.create();
        break;

    case DIALOG_ERROR_HANDLING:
        builder.setTitle(res.getString(R.string.error_handling_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setSingleChoiceItems(new String[] { "1" }, 0, null);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (mLoadFailed) {
                    // dialog has been called because collection could not be opened
                    showDialog(DIALOG_LOAD_FAILED);
                } else {
                    // dialog has been called because a db error happened
                    showDialog(DIALOG_DB_ERROR);
                }
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mLoadFailed) {
                    // dialog has been called because collection could not be opened
                    showDialog(DIALOG_LOAD_FAILED);
                } else {
                    // dialog has been called because a db error happened
                    showDialog(DIALOG_DB_ERROR);
                }
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_USER_NOT_LOGGED_IN_ADD_SHARED_DECK:
        builder.setTitle(res.getString(R.string.connection_error_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setMessage(res.getString(R.string.no_user_password_error_message));
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        builder.setPositiveButton(res.getString(R.string.log_in), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent myAccount = new Intent(DeckPicker.this, MyAccount.class);
                myAccount.putExtra("notLoggedIn", true);
                startActivityForResult(myAccount, LOG_IN_FOR_SHARED_DECK);
                if (AnkiDroidApp.SDK_VERSION > 4) {
                    ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.FADE);
                }
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_USER_NOT_LOGGED_IN_SYNC:
        builder.setTitle(res.getString(R.string.connection_error_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setMessage(res.getString(R.string.no_user_password_error_message));
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        builder.setPositiveButton(res.getString(R.string.log_in), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent myAccount = new Intent(DeckPicker.this, MyAccount.class);
                myAccount.putExtra("notLoggedIn", true);
                startActivityForResult(myAccount, LOG_IN_FOR_SYNC);
                if (AnkiDroidApp.SDK_VERSION > 4) {
                    ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.FADE);
                }
            }
        });
        dialog = builder.create();
        break;

    // case DIALOG_USER_NOT_LOGGED_IN_DOWNLOAD:
    // if (id == DIALOG_USER_NOT_LOGGED_IN_SYNC) {
    // } else {
    // builder.setPositiveButton(res.getString(R.string.log_in),
    // new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    // Intent myAccount = new Intent(DeckPicker.this,
    // MyAccount.class);
    // myAccount.putExtra("notLoggedIn", true);
    // startActivityForResult(myAccount, LOG_IN_FOR_DOWNLOAD);
    // if (UIUtils.getApiLevel() > 4) {
    // ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.LEFT);
    // }
    // }
    // });
    // }
    // builder.setNegativeButton(res.getString(R.string.cancel), null);
    // dialog = builder.create();
    // break;

    case DIALOG_NO_CONNECTION:
        builder.setTitle(res.getString(R.string.connection_error_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setMessage(res.getString(R.string.connection_needed));
        builder.setPositiveButton(res.getString(R.string.ok), null);
        dialog = builder.create();
        break;

    case DIALOG_DELETE_DECK:
        if (!AnkiDroidApp.colIsOpen() || mDeckList == null) {
            return null;
        }
        // Message is set in onPrepareDialog
        builder.setTitle(res.getString(R.string.delete_deck_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.yes), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DELETE_DECK, new DeckTask.TaskListener() {
                    @Override
                    public void onPreExecute() {
                        mProgressDialog = StyledProgressDialog.show(DeckPicker.this, "",
                                getResources().getString(R.string.delete_deck), true);
                    }

                    @Override
                    public void onPostExecute(TaskData result) {
                        if (result == null) {
                            return;
                        }
                        Object[] res = result.getObjArray();
                        updateDecksList((TreeSet<Object[]>) res[0], (Integer) res[1], (Integer) res[2]);
                        if (mFragmented) {
                            selectDeck(AnkiDroidApp.getCol().getDecks().selected());
                        }
                        if (mProgressDialog.isShowing()) {
                            try {
                                mProgressDialog.dismiss();
                            } catch (Exception e) {
                                Log.e(AnkiDroidApp.TAG,
                                        "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
                            }
                        }
                    }

                    @Override
                    public void onProgressUpdate(TaskData... values) {
                    }
                }, new TaskData(AnkiDroidApp.getCol(), mCurrentDid));
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        dialog = builder.create();
        break;

    case DIALOG_SELECT_STATISTICS_TYPE:
        dialog = ChartBuilder.getStatisticsDialog(this, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean muh = mFragmented
                        ? AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getBoolean(
                                "statsRange", true)
                        : true;
                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_LOAD_STATISTICS, mLoadStatisticsHandler,
                        new DeckTask.TaskData(AnkiDroidApp.getCol(), which,
                                mFragmented
                                        ? AnkiDroidApp
                                                .getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext())
                                                .getBoolean("statsRange", true)
                                        : true));
            }
        }, mFragmented);
        break;

    case DIALOG_CONTEXT_MENU:
        String[] entries = new String[3];
        // entries[CONTEXT_MENU_DECK_SUMMARY] =
        // "XXXsum";//res.getStringArray(R.array.statistics_type_labels)[0];
        // entries[CONTEXT_MENU_CUSTOM_DICTIONARY] =
        // res.getString(R.string.contextmenu_deckpicker_set_custom_dictionary);
        // entries[CONTEXT_MENU_RESET_LANGUAGE] =
        // res.getString(R.string.contextmenu_deckpicker_reset_language_assignments);
        entries[CONTEXT_MENU_COLLAPSE_DECK] = res.getString(R.string.contextmenu_deckpicker_collapse_deck);
        entries[CONTEXT_MENU_RENAME_DECK] = res.getString(R.string.contextmenu_deckpicker_rename_deck);
        entries[CONTEXT_MENU_DELETE_DECK] = res.getString(R.string.contextmenu_deckpicker_delete_deck);
        builder.setTitle("Context Menu");
        builder.setIcon(R.drawable.ic_menu_manage);
        builder.setItems(entries, mContextMenuListener);
        dialog = builder.create();
        break;

    case DIALOG_REPAIR_COLLECTION:
        builder.setTitle(res.getString(R.string.backup_repair_deck));
        builder.setMessage(res.getString(R.string.repair_deck_dialog, BackupManager.BROKEN_DECKS_SUFFIX));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.yes), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_REPAIR_DECK, mRepairDeckHandler,
                        new DeckTask.TaskData(AnkiDroidApp.getCol(), AnkiDroidApp.getCollectionPath()));
            }
        });
        builder.setNegativeButton(res.getString(R.string.no), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        builder.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface arg0) {
                showDialog(DIALOG_ERROR_HANDLING);
            }

        });
        dialog = builder.create();
        break;

    case DIALOG_SYNC_SANITY_ERROR:
        builder.setPositiveButton(getString(R.string.sync_sanity_local), mSyncSanityFailListener);
        builder.setNeutralButton(getString(R.string.sync_sanity_remote), mSyncSanityFailListener);
        builder.setNegativeButton(res.getString(R.string.sync_conflict_cancel), mSyncSanityFailListener);
        builder.setTitle(res.getString(R.string.sync_log_title));
        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(res.getString(R.string.retry), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sync("download", mSyncMediaUsn);
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mLoadFailed) {
                    // dialog has been called because collection could not be opened
                    showDialog(DIALOG_LOAD_FAILED);
                } else {
                    // dialog has been called because a db error happened
                    showDialog(DIALOG_DB_ERROR);
                }
            }
        });
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                if (mLoadFailed) {
                    // dialog has been called because collection could not be opened
                    showDialog(DIALOG_LOAD_FAILED);
                } else {
                    // dialog has been called because a db error happened
                    showDialog(DIALOG_DB_ERROR);
                }
            }
        });
        builder.setTitle(res.getString(R.string.sync_log_title));
        dialog = builder.create();
        break;

    case DIALOG_SYNC_LOG:
        builder.setTitle(res.getString(R.string.sync_log_title));
        builder.setPositiveButton(res.getString(R.string.ok), null);
        dialog = builder.create();
        break;

    case DIALOG_BACKUP_NO_SPACE_LEFT:
        builder.setTitle(res.getString(R.string.attention));
        builder.setMessage(res.getString(R.string.backup_deck_no_space_left));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                loadCollection();
            }
        });
        // builder.setNegativeButton(res.getString(R.string.dont_show_again), new
        // DialogInterface.OnClickListener() {
        // @Override
        // public void onClick(DialogInterface arg0, int arg1) {
        // PrefSettings.getSharedPrefs(getBaseContext()).edit().putBoolean("dontShowLowMemory", true).commit();
        // }
        // });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                loadCollection();
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_SD_CARD_NOT_MOUNTED:
        if (mNotMountedDialog == null || !mNotMountedDialog.isShowing()) {
            mNotMountedDialog = StyledOpenCollectionDialog.show(DeckPicker.this,
                    getResources().getString(R.string.sd_card_not_mounted), new OnCancelListener() {

                        @Override
                        public void onCancel(DialogInterface arg0) {
                            finishWithAnimation();
                        }
                    }, new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            startActivityForResult(new Intent(DeckPicker.this, Preferences.class),
                                    PREFERENCES_UPDATE);
                        }
                    });
        }
        dialog = null;
        break;

    case DIALOG_IMPORT:
        builder.setTitle(res.getString(R.string.import_title));
        builder.setMessage(res.getString(R.string.import_message, mImportPath));
        builder.setPositiveButton(res.getString(R.string.import_message_add),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                                new TaskData(AnkiDroidApp.getCol(), mImportPath, false));
                        mImportPath = null;
                    }
                });
        builder.setNeutralButton(res.getString(R.string.import_message_replace),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                                new TaskData(AnkiDroidApp.getCol(), mImportPath, true));
                        mImportPath = null;
                    }
                });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        builder.setCancelable(true);
        dialog = builder.create();
        break;

    case DIALOG_IMPORT_SELECT:
        builder.setTitle(res.getString(R.string.import_title));
        dialog = builder.create();
        break;

    case DIALOG_IMPORT_HINT:
        builder.setTitle(res.getString(R.string.import_title));
        builder.setMessage(res.getString(R.string.import_hint, AnkiDroidApp.getCurrentAnkiDroidDirectory()));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                showDialog(DIALOG_IMPORT_SELECT);
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        dialog = builder.create();
        break;

    case DIALOG_IMPORT_LOG:
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setTitle(res.getString(R.string.import_title));
        builder.setPositiveButton(res.getString(R.string.ok), null);
        dialog = builder.create();
        break;

    case DIALOG_NO_SPACE_LEFT:
        builder.setTitle(res.getString(R.string.attention));
        builder.setMessage(res.getString(R.string.sd_space_warning, BackupManager.MIN_FREE_SPACE));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finishWithAnimation();
            }
        });
        // builder.setNegativeButton(res.getString(R.string.dont_show_again), new
        // DialogInterface.OnClickListener() {
        // @Override
        // public void onClick(DialogInterface arg0, int arg1) {
        // PrefSettings.getSharedPrefs(getBaseContext()).edit().putBoolean("dontShowLowMemory", true).commit();
        // }
        // });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                finishWithAnimation();
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_RESTORE_BACKUP:
        File[] files = BackupManager.getBackups(new File(AnkiDroidApp.getCollectionPath()));
        mBackups = new File[files.length];
        for (int i = 0; i < files.length; i++) {
            mBackups[i] = files[files.length - 1 - i];
        }
        if (mBackups.length == 0) {
            builder.setTitle(getResources().getString(R.string.backup_restore));
            builder.setMessage(res.getString(R.string.backup_restore_no_backups));
            builder.setPositiveButton(res.getString(R.string.ok), new Dialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    showDialog(DIALOG_ERROR_HANDLING);
                }
            });
            builder.setCancelable(true).setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface arg0) {
                    showDialog(DIALOG_ERROR_HANDLING);
                }
            });
        } else {
            String[] dates = new String[mBackups.length];
            for (int i = 0; i < mBackups.length; i++) {
                dates[i] = mBackups[i].getName().replaceAll(".*-(\\d{4}-\\d{2}-\\d{2})-(\\d{2})-(\\d{2}).anki2",
                        "$1 ($2:$3 h)");
            }
            builder.setTitle(res.getString(R.string.backup_restore_select_title));
            builder.setIcon(android.R.drawable.ic_input_get);
            builder.setSingleChoiceItems(dates, dates.length, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    DeckTask.launchDeckTask(DeckTask.TASK_TYPE_RESTORE_DECK, mRestoreDeckHandler,
                            new DeckTask.TaskData(new Object[] { AnkiDroidApp.getCol(),
                                    AnkiDroidApp.getCollectionPath(), mBackups[which].getPath() }));
                }
            });
            builder.setCancelable(true).setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface arg0) {
                    showDialog(DIALOG_ERROR_HANDLING);
                }
            });
        }
        dialog = builder.create();
        break;

    case DIALOG_NEW_COLLECTION:
        builder.setTitle(res.getString(R.string.backup_new_collection));
        builder.setMessage(res.getString(R.string.backup_del_collection_question));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                AnkiDroidApp.closeCollection(false);
                String path = AnkiDroidApp.getCollectionPath();
                AnkiDatabaseManager.closeDatabase(path);
                if (BackupManager.moveDatabaseToBrokenFolder(path, false)) {
                    loadCollection();
                } else {
                    showDialog(DIALOG_ERROR_HANDLING);
                }
            }
        });
        builder.setNegativeButton(res.getString(R.string.no), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_FULL_SYNC_FROM_SERVER:
        builder.setTitle(res.getString(R.string.backup_full_sync_from_server));
        builder.setMessage(res.getString(R.string.backup_full_sync_from_server_question));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sync("download", mSyncMediaUsn);
            }
        });
        builder.setNegativeButton(res.getString(R.string.no), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        dialog = builder.create();
        break;

    default:
        dialog = null;
    }
    if (dialog != null) {
        dialog.setOwnerActivity(this);
    }
    return dialog;
}

From source file:com.ichi2.anki2.Reviewer.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    Resources res = getResources();
    MenuItem item = menu.findItem(MENU_MARK);
    if (mCurrentCard != null && mCurrentCard.note().hasTag("marked")) {
        item.setTitle(R.string.menu_unmark_card);
        item.setIcon(R.drawable.ic_menu_marked);
    } else {/* ww w . java2 s  . c o  m*/
        item.setTitle(R.string.menu_mark_card);
        item.setIcon(R.drawable.ic_menu_mark);
    }
    item = menu.findItem(MENU_UNDO);
    if (AnkiDroidApp.colIsOpen() && AnkiDroidApp.getCol().undoAvailable()) {
        item.setEnabled(true);
        item.setIcon(R.drawable.ic_menu_revert);
    } else {
        item.setEnabled(false);
        item.setIcon(R.drawable.ic_menu_revert_disabled);
    }
    item = menu.findItem(MENU_SEARCH);
    if (item != null) {
        item.setTitle(clipboardHasText() ? Lookup.getSearchStringTitle() : res.getString(R.string.menu_select));
    }
    return true;
}

From source file:com.hichinaschool.flashcards.anki.DeckPicker.java

@Override
protected Dialog onCreateDialog(int id) {
    StyledDialog dialog;/*from  w ww. jav a  2s  .c om*/
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);

    switch (id) {
    case DIALOG_OK:
        builder.setPositiveButton(R.string.ok, null);
        dialog = builder.create();
        break;

    case DIALOG_NO_SDCARD:
        builder.setMessage("The SD card could not be read. Please, turn off USB storage.");
        builder.setPositiveButton(R.string.ok, null);
        dialog = builder.create();
        break;

    case DIALOG_SELECT_HELP:
        builder.setTitle(res.getString(R.string.help_title));
        builder.setItems(new String[] { res.getString(R.string.help_tutorial),
                res.getString(R.string.help_online), res.getString(R.string.help_faq) },
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        if (arg1 == 0) {
                            createTutorialDeck();
                        } else {
                            if (Utils.isIntentAvailable(DeckPicker.this, "android.intent.action.VIEW")) {
                                Intent intent = new Intent("android.intent.action.VIEW",
                                        Uri.parse(getResources().getString(
                                                arg1 == 0 ? R.string.link_help : R.string.link_faq)));
                                startActivity(intent);
                            } else {
                                startActivity(new Intent(DeckPicker.this, Info.class));
                            }
                        }
                    }

                });
        dialog = builder.create();
        break;

    case DIALOG_CONNECTION_ERROR:
        builder.setTitle(res.getString(R.string.connection_error_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setMessage(res.getString(R.string.connection_error_message));
        builder.setPositiveButton(res.getString(R.string.retry), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sync();
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        dialog = builder.create();
        break;

    case DIALOG_SYNC_CONFLICT_RESOLUTION:
        builder.setTitle(res.getString(R.string.sync_conflict_title));
        builder.setIcon(android.R.drawable.ic_input_get);
        builder.setMessage(res.getString(R.string.sync_conflict_message));
        builder.setPositiveButton(res.getString(R.string.sync_conflict_local), mSyncConflictResolutionListener);
        builder.setNeutralButton(res.getString(R.string.sync_conflict_remote), mSyncConflictResolutionListener);
        builder.setNegativeButton(res.getString(R.string.sync_conflict_cancel),
                mSyncConflictResolutionListener);
        builder.setCancelable(true);
        dialog = builder.create();
        break;

    case DIALOG_LOAD_FAILED:
        builder.setMessage(res.getString(R.string.open_collection_failed_message,
                BackupManager.BROKEN_DECKS_SUFFIX, res.getString(R.string.repair_deck)));
        builder.setTitle(R.string.open_collection_failed_title);
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.error_handling_options),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        showDialog(DIALOG_ERROR_HANDLING);
                    }
                });
        builder.setNegativeButton(res.getString(R.string.close), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finishWithAnimation();
            }
        });
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                finishWithAnimation();
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_DB_ERROR:
        builder.setMessage(R.string.answering_error_message);
        builder.setTitle(R.string.answering_error_title);
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.error_handling_options),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        showDialog(DIALOG_ERROR_HANDLING);
                    }
                });
        builder.setNeutralButton(res.getString(R.string.answering_error_report),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent i = new Intent(DeckPicker.this, Feedback.class);
                        i.putExtra("request", RESULT_DB_ERROR);
                        dialog.dismiss();
                        startActivityForResult(i, REPORT_ERROR);
                        if (AnkiDroidApp.SDK_VERSION > 4) {
                            ActivityTransitionAnimation.slide(DeckPicker.this,
                                    ActivityTransitionAnimation.RIGHT);
                        }
                    }
                });
        builder.setNegativeButton(res.getString(R.string.close), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (!AnkiDroidApp.colIsOpen()) {
                    finishWithAnimation();
                }
            }
        });
        builder.setCancelable(true);
        dialog = builder.create();
        break;

    case DIALOG_ERROR_HANDLING:
        builder.setTitle(res.getString(R.string.error_handling_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setSingleChoiceItems(new String[] { "1" }, 0, null);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (mLoadFailed) {
                    // dialog has been called because collection could not be opened
                    showDialog(DIALOG_LOAD_FAILED);
                } else {
                    // dialog has been called because a db error happened
                    showDialog(DIALOG_DB_ERROR);
                }
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mLoadFailed) {
                    // dialog has been called because collection could not be opened
                    showDialog(DIALOG_LOAD_FAILED);
                } else {
                    // dialog has been called because a db error happened
                    showDialog(DIALOG_DB_ERROR);
                }
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_USER_NOT_LOGGED_IN_ADD_SHARED_DECK:
        builder.setTitle(res.getString(R.string.connection_error_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setMessage(res.getString(R.string.no_user_password_error_message));
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        builder.setPositiveButton(res.getString(R.string.log_in), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent myAccount = new Intent(DeckPicker.this, MyAccount.class);
                myAccount.putExtra("notLoggedIn", true);
                startActivityForResult(myAccount, LOG_IN_FOR_SHARED_DECK);
                if (AnkiDroidApp.SDK_VERSION > 4) {
                    ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.FADE);
                }
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_USER_NOT_LOGGED_IN_SYNC:
        builder.setTitle(res.getString(R.string.connection_error_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setMessage(res.getString(R.string.no_user_password_error_message));
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        builder.setPositiveButton(res.getString(R.string.log_in), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent myAccount = new Intent(DeckPicker.this, MyAccount.class);
                myAccount.putExtra("notLoggedIn", true);
                startActivityForResult(myAccount, LOG_IN_FOR_SYNC);
                if (AnkiDroidApp.SDK_VERSION > 4) {
                    ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.FADE);
                }
            }
        });
        dialog = builder.create();
        break;

    // case DIALOG_USER_NOT_LOGGED_IN_DOWNLOAD:
    // if (id == DIALOG_USER_NOT_LOGGED_IN_SYNC) {
    // } else {
    // builder.setPositiveButton(res.getString(R.string.log_in),
    // new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    // Intent myAccount = new Intent(DeckPicker.this,
    // MyAccount.class);
    // myAccount.putExtra("notLoggedIn", true);
    // startActivityForResult(myAccount, LOG_IN_FOR_DOWNLOAD);
    // if (UIUtils.getApiLevel() > 4) {
    // ActivityTransitionAnimation.slide(DeckPicker.this, ActivityTransitionAnimation.LEFT);
    // }
    // }
    // });
    // }
    // builder.setNegativeButton(res.getString(R.string.cancel), null);
    // dialog = builder.create();
    // break;

    case DIALOG_NO_CONNECTION:
        builder.setTitle(res.getString(R.string.connection_error_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setMessage(res.getString(R.string.connection_needed));
        builder.setPositiveButton(res.getString(R.string.ok), null);
        dialog = builder.create();
        break;

    case DIALOG_DELETE_DECK:
        if (!AnkiDroidApp.colIsOpen() || mDeckList == null) {
            return null;
        }
        // Message is set in onPrepareDialog
        builder.setTitle(res.getString(R.string.delete_deck_title));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.yes), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DELETE_DECK, new DeckTask.TaskListener() {
                    @Override
                    public void onPreExecute() {
                        mProgressDialog = StyledProgressDialog.show(DeckPicker.this, "",
                                getResources().getString(R.string.delete_deck), true);
                    }

                    @Override
                    public void onPostExecute(TaskData result) {
                        if (result == null) {
                            return;
                        }
                        Object[] res = result.getObjArray();
                        updateDecksList((TreeSet<Object[]>) res[0], (Integer) res[1], (Integer) res[2]);
                        if (mFragmented) {
                            selectDeck(AnkiDroidApp.getCol().getDecks().selected());
                        }
                        if (mProgressDialog.isShowing()) {
                            try {
                                mProgressDialog.dismiss();
                            } catch (Exception e) {
                                Log.e(AnkiDroidApp.TAG,
                                        "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
                            }
                        }
                    }

                    @Override
                    public void onProgressUpdate(TaskData... values) {
                    }
                }, new TaskData(AnkiDroidApp.getCol(), mCurrentDid));
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        dialog = builder.create();
        break;

    case DIALOG_SELECT_STATISTICS_TYPE:
        dialog = ChartBuilder.getStatisticsDialog(this, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean muh = mFragmented
                        ? AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getBoolean(
                                "statsRange", true)
                        : true;
                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_LOAD_STATISTICS, mLoadStatisticsHandler,
                        new DeckTask.TaskData(AnkiDroidApp.getCol(), which,
                                mFragmented
                                        ? AnkiDroidApp
                                                .getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext())
                                                .getBoolean("statsRange", true)
                                        : true));
            }
        }, mFragmented);
        break;

    case DIALOG_CONTEXT_MENU:
        String[] entries = new String[1];
        // entries[CONTEXT_MENU_DECK_SUMMARY] =
        // "XXXsum";//res.getStringArray(R.array.statistics_type_labels)[0];
        // entries[CONTEXT_MENU_CUSTOM_DICTIONARY] =
        // res.getString(R.string.contextmenu_deckpicker_set_custom_dictionary);
        // entries[CONTEXT_MENU_RESET_LANGUAGE] =
        // res.getString(R.string.contextmenu_deckpicker_reset_language_assignments);
        //                entries[CONTEXT_MENU_COLLAPSE_DECK] = res.getString(R.string.contextmenu_deckpicker_collapse_deck);
        //                entries[CONTEXT_MENU_RENAME_DECK] = res.getString(R.string.contextmenu_deckpicker_rename_deck);
        entries[CONTEXT_MENU_DELETE_DECK] = res.getString(R.string.contextmenu_deckpicker_delete_deck);
        builder.setTitle("Context Menu");
        builder.setIcon(R.drawable.ic_menu_manage);
        builder.setItems(entries, mContextMenuListener);
        dialog = builder.create();
        break;

    case DIALOG_REPAIR_COLLECTION:
        builder.setTitle(res.getString(R.string.backup_repair_deck));
        builder.setMessage(res.getString(R.string.repair_deck_dialog, BackupManager.BROKEN_DECKS_SUFFIX));
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setPositiveButton(res.getString(R.string.yes), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_REPAIR_DECK, mRepairDeckHandler,
                        new DeckTask.TaskData(AnkiDroidApp.getCol(), AnkiDroidApp.getCollectionPath()));
            }
        });
        builder.setNegativeButton(res.getString(R.string.no), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        builder.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface arg0) {
                showDialog(DIALOG_ERROR_HANDLING);
            }

        });
        dialog = builder.create();
        break;

    case DIALOG_SYNC_SANITY_ERROR:
        builder.setPositiveButton(getString(R.string.sync_sanity_local), mSyncSanityFailListener);
        builder.setNeutralButton(getString(R.string.sync_sanity_remote), mSyncSanityFailListener);
        builder.setNegativeButton(res.getString(R.string.sync_conflict_cancel), mSyncSanityFailListener);
        builder.setTitle(res.getString(R.string.sync_log_title));
        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(res.getString(R.string.retry), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sync("download", mSyncMediaUsn);
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mLoadFailed) {
                    // dialog has been called because collection could not be opened
                    showDialog(DIALOG_LOAD_FAILED);
                } else {
                    // dialog has been called because a db error happened
                    showDialog(DIALOG_DB_ERROR);
                }
            }
        });
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                if (mLoadFailed) {
                    // dialog has been called because collection could not be opened
                    showDialog(DIALOG_LOAD_FAILED);
                } else {
                    // dialog has been called because a db error happened
                    showDialog(DIALOG_DB_ERROR);
                }
            }
        });
        builder.setTitle(res.getString(R.string.sync_log_title));
        dialog = builder.create();
        break;

    case DIALOG_SYNC_LOG:
        builder.setTitle(res.getString(R.string.sync_log_title));
        builder.setPositiveButton(res.getString(R.string.ok), null);
        dialog = builder.create();
        break;

    case DIALOG_BACKUP_NO_SPACE_LEFT:
        builder.setTitle(res.getString(R.string.attention));
        builder.setMessage(res.getString(R.string.backup_deck_no_space_left));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                loadCollection();
            }
        });
        // builder.setNegativeButton(res.getString(R.string.dont_show_again), new
        // DialogInterface.OnClickListener() {
        // @Override
        // public void onClick(DialogInterface arg0, int arg1) {
        // PrefSettings.getSharedPrefs(getBaseContext()).edit().putBoolean("dontShowLowMemory", true).commit();
        // }
        // });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                loadCollection();
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_SD_CARD_NOT_MOUNTED:
        if (mNotMountedDialog == null || !mNotMountedDialog.isShowing()) {
            mNotMountedDialog = StyledOpenCollectionDialog.show(DeckPicker.this,
                    getResources().getString(R.string.sd_card_not_mounted), new OnCancelListener() {

                        @Override
                        public void onCancel(DialogInterface arg0) {
                            finishWithAnimation();
                        }
                    }, new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            startActivityForResult(new Intent(DeckPicker.this, Preferences.class),
                                    PREFERENCES_UPDATE);
                        }
                    });
        }
        dialog = null;
        break;

    case DIALOG_IMPORT:
        builder.setTitle(res.getString(R.string.import_title));
        builder.setMessage(res.getString(R.string.import_message, mImportPath));
        builder.setPositiveButton(res.getString(R.string.import_message_add),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                                new TaskData(AnkiDroidApp.getCol(), mImportPath, false));
                        mImportPath = null;
                    }
                });
        builder.setNeutralButton(res.getString(R.string.import_message_replace),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Resources res = getResources();
                        StyledDialog.Builder builder = new StyledDialog.Builder(DeckPicker.this);
                        builder.setTitle(res.getString(R.string.import_title));
                        builder.setMessage(res.getString(R.string.import_message_replace_confirm, mImportPath));
                        builder.setPositiveButton(res.getString(R.string.yes),
                                new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT_REPLACE,
                                                mImportReplaceListener,
                                                new TaskData(AnkiDroidApp.getCol(), mImportPath));
                                        mImportPath = null;
                                    }

                                });
                        builder.setNegativeButton(res.getString(R.string.no), null);
                        builder.show();
                    }
                });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        builder.setCancelable(true);
        dialog = builder.create();
        break;

    case DIALOG_IMPORT_SELECT:
        builder.setTitle(res.getString(R.string.import_title));
        dialog = builder.create();
        break;

    case DIALOG_IMPORT_HINT:
        builder.setTitle(res.getString(R.string.import_title));
        builder.setMessage(res.getString(R.string.import_hint, AnkiDroidApp.getCurrentAnkiDroidDirectory()));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                showDialog(DIALOG_IMPORT_SELECT);
            }
        });
        builder.setNegativeButton(res.getString(R.string.cancel), null);
        dialog = builder.create();
        break;

    case DIALOG_IMPORT_LOG:
        builder.setIcon(R.drawable.ic_dialog_alert);
        builder.setTitle(res.getString(R.string.import_title));
        builder.setPositiveButton(res.getString(R.string.ok), null);
        dialog = builder.create();
        break;

    case DIALOG_NO_SPACE_LEFT:
        builder.setTitle(res.getString(R.string.attention));
        builder.setMessage(res.getString(R.string.sd_space_warning, BackupManager.MIN_FREE_SPACE));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finishWithAnimation();
            }
        });
        // builder.setNegativeButton(res.getString(R.string.dont_show_again), new
        // DialogInterface.OnClickListener() {
        // @Override
        // public void onClick(DialogInterface arg0, int arg1) {
        // PrefSettings.getSharedPrefs(getBaseContext()).edit().putBoolean("dontShowLowMemory", true).commit();
        // }
        // });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                finishWithAnimation();
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_RESTORE_BACKUP:
        File[] files = BackupManager.getBackups(new File(AnkiDroidApp.getCollectionPath()));
        mBackups = new File[files.length];
        for (int i = 0; i < files.length; i++) {
            mBackups[i] = files[files.length - 1 - i];
        }
        if (mBackups.length == 0) {
            builder.setTitle(getResources().getString(R.string.backup_restore));
            builder.setMessage(res.getString(R.string.backup_restore_no_backups));
            builder.setPositiveButton(res.getString(R.string.ok), new Dialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    showDialog(DIALOG_ERROR_HANDLING);
                }
            });
            builder.setCancelable(true).setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface arg0) {
                    showDialog(DIALOG_ERROR_HANDLING);
                }
            });
        } else {
            String[] dates = new String[mBackups.length];
            for (int i = 0; i < mBackups.length; i++) {
                dates[i] = mBackups[i].getName().replaceAll(".*-(\\d{4}-\\d{2}-\\d{2})-(\\d{2})-(\\d{2}).anki2",
                        "$1 ($2:$3 h)");
            }
            builder.setTitle(res.getString(R.string.backup_restore_select_title));
            builder.setIcon(android.R.drawable.ic_input_get);
            builder.setSingleChoiceItems(dates, dates.length, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    DeckTask.launchDeckTask(DeckTask.TASK_TYPE_RESTORE_DECK, mRestoreDeckHandler,
                            new DeckTask.TaskData(new Object[] { AnkiDroidApp.getCol(),
                                    AnkiDroidApp.getCollectionPath(), mBackups[which].getPath() }));
                }
            });
            builder.setCancelable(true).setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface arg0) {
                    showDialog(DIALOG_ERROR_HANDLING);
                }
            });
        }
        dialog = builder.create();
        break;

    case DIALOG_NEW_COLLECTION:
        builder.setTitle(res.getString(R.string.backup_new_collection));
        builder.setMessage(res.getString(R.string.backup_del_collection_question));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                AnkiDroidApp.closeCollection(false);
                String path = AnkiDroidApp.getCollectionPath();
                AnkiDatabaseManager.closeDatabase(path);
                if (BackupManager.moveDatabaseToBrokenFolder(path, false)) {
                    loadCollection();
                } else {
                    showDialog(DIALOG_ERROR_HANDLING);
                }
            }
        });
        builder.setNegativeButton(res.getString(R.string.no), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        dialog = builder.create();
        break;

    case DIALOG_FULL_SYNC_FROM_SERVER:
        builder.setTitle(res.getString(R.string.backup_full_sync_from_server));
        builder.setMessage(res.getString(R.string.backup_full_sync_from_server_question));
        builder.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sync("download", mSyncMediaUsn);
            }
        });
        builder.setNegativeButton(res.getString(R.string.no), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface arg0) {
                showDialog(DIALOG_ERROR_HANDLING);
            }
        });
        dialog = builder.create();
        break;

    default:
        dialog = null;
    }
    if (dialog != null) {
        dialog.setOwnerActivity(this);
    }
    return dialog;
}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final Resources res = getResources();

    if (item.getItemId() == R.id.menu_favorites_toggle) {
        onCheckedChanged(mIsStarred);//from w ww.j  a  v a2 s . c  o  m

        mIsStarred = (mIsStarred ? false : true); // Toggle value
        getSherlockActivity().invalidateOptionsMenu();
        return true;
    } else if (item.getItemId() == R.id.menu_map) {
        final Intent intent = new Intent(getActivity(), MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra(Const.INTENT_EXTRA_GEO_LAT, mGeoLat);
        intent.putExtra(Const.INTENT_EXTRA_GEO_LNG, mGeoLng);
        intent.putExtra(Const.INTENT_EXTRA_POST_ID, mIdPost);

        startActivity(intent);

        return true;
    } else if (item.getItemId() == R.id.menu_reminder) {
        parkingApp.showToastText(R.string.toast_todo_reminder, Toast.LENGTH_LONG);

        return true;
    } else if (item.getItemId() == R.id.menu_directions) {

        if ((Double.compare(mGeoLat, Double.MIN_VALUE) != 0)
                && (Double.compare(mGeoLng, Double.MIN_VALUE) != 0)) {
            /**
             * Get directions using Intents.
             */

            try {
                final Uri uriNavigation = Uri
                        .parse(String.format(Const.URI_INTENT_NAVIGATION, mGeoLat, mGeoLng));
                final Intent intent = new Intent(Intent.ACTION_VIEW, uriNavigation);
                startActivity(intent);

            } catch (Exception e) {
                e.printStackTrace();

                String sAddr = "";
                Location userLocation = parkingApp.getLocation();
                if (userLocation != null) {
                    sAddr = Double.toString(userLocation.getLatitude()) + ","
                            + Double.toString(userLocation.getLongitude());
                }

                final String urlGmaps = String.format(Const.URL_GMAPS_DIRECTIONS, sAddr,
                        mGeoLat + "," + mGeoLng);

                final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlGmaps));
                startActivity(intent);
            }
        }
        return true;
    } else if (item.getItemId() == R.id.menu_streetview) {

        if ((Double.compare(mGeoLat, Double.MIN_VALUE) != 0)
                && (Double.compare(mGeoLng, Double.MIN_VALUE) != 0)) {

            try {
                final Uri uriStreetView = Uri
                        .parse(String.format(Const.URI_INTENT_STREETVIEW, mGeoLat, mGeoLng));
                final Intent intent = new Intent(Intent.ACTION_VIEW, uriStreetView);
                startActivity(intent);
            } catch (NullPointerException e) {
                e.printStackTrace();
                return false;
            } catch (Exception e) {
                parkingApp.showToastText(R.string.toast_streetview_error, Toast.LENGTH_LONG);
                e.printStackTrace();

                final Uri uriInstallStreetView = Uri.parse(Const.URI_INSTALL_STREETVIEW);
                final Intent intent = new Intent(Intent.ACTION_VIEW, uriInstallStreetView);
                startActivity(intent);

                return false;
            }
        }
        return true;
    }

    else if (item.getItemId() == R.id.menu_share) {

        final GregorianCalendar parkingCalendar = parkingApp.getParkingCalendar();

        final int dayOfWeek = (parkingCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ? 7
                : parkingCalendar.get(Calendar.DAY_OF_WEEK) - 1);
        final double parkingHour = parkingCalendar.get(Calendar.HOUR_OF_DAY)
                + Math.round(parkingCalendar.get(Calendar.MINUTE) / 0.6) / 100.00d;

        // final int duration = parkingApp.getParkingDuration();

        final String url = String.format(res.getString(R.string.url_share_post_id), mIdPost, dayOfWeek,
                parkingHour, parkingApp.getParkingDuration());
        final String subject = String.format(res.getString(R.string.details_share_title), url);
        final String desc = String.format(res.getString(R.string.details_share_subtitle), mShareDesc);

        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        // EXTRA_SUBJECT is not used to allow sharing with SMS instead of
        // MMS
        // intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, subject + Const.LINE_SEPARATOR + desc);

        startActivity(intent);
        return true;
    }

    return (activityHelper.onOptionsItemSelected(item) || super.onOptionsItemSelected(item));
}

From source file:com.androzic.vnspeech.MapFragment.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Resources resources = getResources();
    if (getString(R.string.pref_wakelock).equals(key)) {
        keepScreenOn = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_wakelock));
        map.setKeepScreenOn(keepScreenOn);
    } else if (getString(R.string.pref_showdistance_int).equals(key)) {
        showDistance = Integer.parseInt(sharedPreferences.getString(key, getString(R.string.def_showdistance)));
    } else if (getString(R.string.pref_hidemapinfo).equals(key)) {
        mapInfoHideDelay = Integer.parseInt(sharedPreferences.getString(key, "2147483647"));
    } else if (getString(R.string.pref_hidesatinfo).equals(key)) {
        satInfoHideDelay = Integer.parseInt(sharedPreferences.getString(key, "2147483647"));
    } else if (getString(R.string.pref_hidenavinfo).equals(key)) {
        navInfoHideDelay = Integer.parseInt(sharedPreferences.getString(key, "2147483647"));
    } else if (getString(R.string.pref_maprenderinterval).equals(key)) {
        updatePeriod = sharedPreferences.getInt(key, resources.getInteger(R.integer.def_maprenderinterval))
                * 100;//from   ww  w. j  a va2s  . c  om
    } else if (getString(R.string.pref_mapfollowonloc).equals(key)) {
        followOnLocation = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapfollowonloc));
    } else if (getString(R.string.pref_mapdiminterval).equals(key)) {
        dimInterval = sharedPreferences.getInt(key, resources.getInteger(R.integer.def_mapdiminterval)) * 1000;
    } else if (getString(R.string.pref_mapdimvalue).equals(key)) {
        dimValue = sharedPreferences.getInt(key, resources.getInteger(R.integer.def_mapdimvalue));
    } else if (getString(R.string.pref_mapdim).equals(key)) {
        autoDim = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapdim));
        dimScreen();
    } else if (getString(R.string.pref_unfollowontap).equals(key)) {
        map.setStrictUnfollow(
                !sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_unfollowontap)));
    } else if (getString(R.string.pref_lookahead).equals(key)) {
        map.setLookAhead(sharedPreferences.getInt(key, resources.getInteger(R.integer.def_lookahead)));
    } else if (getString(R.string.pref_mapbest).equals(key)) {
        map.setBestMapEnabled(sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapbest)));
    } else if (getString(R.string.pref_mapbestinterval).equals(key)) {
        map.setBestMapInterval(
                sharedPreferences.getInt(key, resources.getInteger(R.integer.def_mapbestinterval)) * 1000);
    } else if (getString(R.string.pref_mapforcezoom).equals(key)) {
        forceZoomMap = Integer.parseInt(sharedPreferences.getString(key, "1"));
    } else if (getString(R.string.pref_maprotation).equals(key)) {
        int rotation = Integer
                .parseInt(sharedPreferences.getString(key, resources.getString(R.string.def_maprotation)));
        map.setMapRotation(rotation);
    } else if (getString(R.string.pref_scalebarbg).equals(key)) {
        map.setDrawScaleBarBackground(
                sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_scalebarbg)));
    } else if (getString(R.string.pref_scalebarcolor).equals(key)) {
        map.setScaleBarColor(sharedPreferences.getInt(key, resources.getColor(R.color.scalebar)));
    } else if (getString(R.string.pref_scalebarbgcolor).equals(key)) {
        map.setScaleBarBackgroundColor(sharedPreferences.getInt(key, resources.getColor(R.color.scalebarbg)));
    } else if (getString(R.string.pref_hidemapcross).equals(key)) {
        int delay = Integer.parseInt(sharedPreferences.getString(key, "5"));
        map.setCrossCursorHideDelay(delay);
    } else if (getString(R.string.pref_mapcrosscolor).equals(key)) {
        map.setCrossColor(sharedPreferences.getInt(key, resources.getColor(R.color.mapcross)));
    } else if (getString(R.string.pref_cursorvector).equals(key)
            || getString(R.string.pref_cursorvectormlpr).equals(key)) {
        map.setCursorVector(
                Integer.parseInt(sharedPreferences.getString(getString(R.string.pref_cursorvector),
                        getString(R.string.def_cursorvector))),
                sharedPreferences.getInt(getString(R.string.pref_cursorvectormlpr),
                        resources.getInteger(R.integer.def_cursorvectormlpr)));
    } else if (getString(R.string.pref_cursorcolor).equals(key)) {
        map.setCursorColor(sharedPreferences.getInt(key, resources.getColor(R.color.cursor)));
    } else if (getString(R.string.pref_navigation_proximity).equals(key)) {
        map.setProximity(Integer
                .parseInt(sharedPreferences.getString(key, getString(R.string.def_navigation_proximity))));
    } else if (getString(R.string.pref_unitspeed).equals(key)) {
        speedUnit.setText(StringFormatter.speedAbbr);
    } else if (getString(R.string.pref_unitelevation).equals(key)) {
        elevationUnit.setText(StringFormatter.elevationAbbr);
    } else if (getString(R.string.pref_unitangle).equals(key)) {
        trackUnit.setText(StringFormatter.angleAbbr);
        bearingUnit.setText(StringFormatter.angleAbbr);
        turnUnit.setText(StringFormatter.angleAbbr);
    }
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private void handleAddAttachmentError(final int error, final int mediaTypeStringId) {
    if (error == WorkingMessage.OK) {
        return;/*from   w  w  w  .ja  v  a2 s .  c o  m*/
    }
    Log.d(TAG, "handleAddAttachmentError: " + error);

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Resources res = getResources();
            String mediaType = res.getString(mediaTypeStringId);
            String title, message;

            switch (error) {
            case WorkingMessage.UNKNOWN_ERROR:
                message = res.getString(R.string.failed_to_add_media, mediaType);
                Toast.makeText(ComposeMessageActivity.this, message, Toast.LENGTH_SHORT).show();
                return;
            case WorkingMessage.UNSUPPORTED_TYPE:
                title = res.getString(R.string.unsupported_media_format, mediaType);
                message = res.getString(R.string.select_different_media, mediaType);
                break;
            case WorkingMessage.MESSAGE_SIZE_EXCEEDED:
                title = res.getString(R.string.exceed_message_size_limitation, mediaType);
                message = res.getString(R.string.failed_to_add_media, mediaType);
                break;
            case WorkingMessage.IMAGE_TOO_LARGE:
                title = res.getString(R.string.failed_to_resize_image);
                message = res.getString(R.string.resize_image_error_information);
                break;
            default:
                throw new IllegalArgumentException("unknown error " + error);
            }

            MessageUtils.showErrorDialog(ComposeMessageActivity.this, title, message);
        }
    });
}

From source file:com.nit.vicky.Reviewer.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Resources res = getResources();

    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card,
            R.drawable.ic_menu_mark);/*w ww .  j  av  a2 s.  c  o  m*/
    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo,
            R.drawable.ic_menu_revert_disabled);
    UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card,
            R.drawable.ic_menu_edit);

    if (mPrefWhiteboard) {
        if (mShowWhiteboard) {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.hide_whiteboard, R.drawable.ic_menu_compose);
        } else {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.show_whiteboard, R.drawable.ic_menu_compose);
        }
        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE,
                R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist);
    }

    SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note);
    removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_CARD, Menu.NONE, R.string.menu_bury_card);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_NOTE, Menu.NONE, R.string.menu_bury_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note);
    if (mPrefTextSelection) {
        MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select));
        item.setIcon(R.drawable.ic_menu_search);
        item.setEnabled(Lookup.isAvailable());
    }
    return true;
}

From source file:au.com.infiniterecursion.vidiom.utils.PublishingUtils.java

public Thread videoUploadToFacebook(final Activity activity, final Handler handler, final Facebook mFacebook,
        final String path, final String title, final String description, final String emailAddress,
        final long sdrecord_id) {

    // Make the progress bar view visible.
    ((VidiomActivity) activity).startedUploading(PublishingUtils.TYPE_FB);
    final Resources res = activity.getResources();

    Thread t = new Thread(new Runnable() {
        public void run() {
            // Do background task.
            // Track errors
            boolean failed = false;

            Log.i(TAG, "Upload starting");
            // Initialising REST API video.upload parameters
            Bundle params = new Bundle();

            params.putString("method", "facebook.video.upload");
            params.putString("format", "json");
            params.putString("title", title);
            params.putString("description", description);
            params.putString("call_id", String.valueOf(System.currentTimeMillis()));
            params.putString("v", "1.0");
            params.putString("oauth_token", mFacebook.getAccessToken());

            // Reading input file
            try {
                File videoFile = new File(path);
                byte[] data = null;
                try {

                    // XXX
                    // SPLIT THIS INTO 5K chunks!!
                    // XXX

                    data = new byte[(int) videoFile.length()];
                } catch (OutOfMemoryError e) {
                    failed = true;//from   www. j  a  va2 s.  c om
                }
                if (data != null) {
                    InputStream is = new FileInputStream(videoFile);
                    is.read(data);
                    params.putByteArray(videoFile.getName(), data);
                }
            } catch (Exception ex) {
                Log.e(TAG, "Cannot read video file :", ex);
            }

            // Sending POST request to Facebook
            String response = null;
            String url = "https://api-video.facebook.com/restserver.php";

            try {
                if (!failed) {
                    response = Util.openUrl(url, "POST", params);
                }
                // SessionEvents.onUploadComplete(response);
            } catch (FileNotFoundException e) {
                // SessionEvents.onFileNotFoundException(e);
                failed = true;
                e.printStackTrace();
            } catch (MalformedURLException e) {
                // SessionEvents.onMalformedURLException(e);
                failed = true;
                e.printStackTrace();
            } catch (IOException e) {
                // SessionEvents.onIOException(e);
                failed = true;
                e.printStackTrace();
            } catch (OutOfMemoryError e) {
                failed = true;
                e.printStackTrace();
            }

            if (failed) {
                // Use the handler to execute a Runnable on the
                // main thread in order to have access to the
                // UI elements.

                mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FB);

                handler.postDelayed(new Runnable() {
                    public void run() {
                        // Update UI

                        // Indicate back to calling activity the result!
                        // update uploadInProgress state also.

                        ((VidiomActivity) activity).finishedUploading(false);
                        ((VidiomActivity) activity)
                                .createNotification(res.getString(R.string.upload_to_facebook_failed_));
                    }
                }, 0);

                return;
            }

            Log.i(TAG, "Uploading to facebook complete. Response is " + response);

            // response is JSON
            JSONObject fb_response = null;
            // decode, and grab URL
            try {
                fb_response = (JSONObject) new JSONTokener(response).nextValue();
            } catch (JSONException e) {
                //
                e.printStackTrace();
                fb_response = null;
            }
            String hosted_url = "facebook.com";

            if (fb_response != null) {

                try {
                    hosted_url = fb_response.getString("link");
                    Log.i(TAG, "Facebook hosted url is : " + hosted_url);
                } catch (JSONException e) {
                    //
                    e.printStackTrace();
                    hosted_url = null;
                }

                if (hosted_url != null) {
                    // Log record of this URL in POSTs table
                    dbutils.creatHostDetailRecordwithNewVideoUploaded(sdrecord_id, url, hosted_url, "");

                    mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FB);

                    // Use the handler to execute a Runnable on the
                    // main thread in order to have access to the
                    // UI elements.
                    handler.postDelayed(new Runnable() {

                        public void run() {
                            // Update UI

                            // Indicate back to calling activity the result!
                            // update uploadInProgress state also.

                            ((VidiomActivity) activity).finishedUploading(true);
                            ((VidiomActivity) activity)
                                    .createNotification(res.getString(R.string.upload_to_facebook_succeeded_));

                        }
                    }, 0);
                }

            } else {

                // an error -- fb_response is NULL.
                mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FB);

                handler.postDelayed(new Runnable() {
                    public void run() {
                        // Update UI

                        // Indicate back to calling activity the result!
                        // update uploadInProgress state also.

                        ((VidiomActivity) activity).finishedUploading(false);
                        ((VidiomActivity) activity)
                                .createNotification(res.getString(R.string.upload_to_facebook_failed_));
                    }
                }, 0);

            }

            if (emailAddress != null && fb_response != null && hosted_url != null) {

                // EmailSender through IR controlled gmail system.
                SSLEmailSender sender = new SSLEmailSender(
                        activity.getString(R.string.automatic_email_username),
                        activity.getString(R.string.automatic_email_password)); // consider
                // this
                // public
                // knowledge.
                try {
                    sender.sendMail(activity.getString(R.string.vidiom_automatic_email), // subject.getText().toString(),
                            activity.getString(R.string.url_of_hosted_video_is_) + " " + hosted_url, // body.getText().toString(),
                            activity.getString(R.string.automatic_email_from), // from.getText().toString(),
                            emailAddress // to.getText().toString()
                    );
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }

        }
    });

    t.start();

    return t;

}

From source file:com.ichi2.anki2.CardBrowser.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);//ww w  .  j  av  a 2  s  . c  o  m
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "sfld", "deck", "flags" },
            new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent editCard = new Intent(CardBrowser.this, CardEditor.class);
            editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

From source file:cgeo.geocaching.cgBase.java

public static boolean runNavigation(Activity activity, Resources res, cgSettings settings,
        final Geopoint coords, final Geopoint coordsNow) {
    if (activity == null) {
        return false;
    }/* ww  w .  jav  a2  s.  co  m*/
    if (settings == null) {
        return false;
    }

    // Google Navigation
    if (settings.useGNavigation == 1) {
        try {
            activity.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("google.navigation:ll=" + coords.getLatitude() + "," + coords.getLongitude())));

            return true;
        } catch (Exception e) {
            // nothing
        }
    }

    // Google Maps Directions
    try {
        if (coordsNow != null) {
            activity.startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://maps.google.com/maps?f=d&saddr=" + coordsNow.getLatitude() + ","
                            + coordsNow.getLongitude() + "&daddr=" + coords.getLatitude() + ","
                            + coords.getLongitude())));
        } else {
            activity.startActivity(
                    new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?f=d&daddr="
                            + coords.getLatitude() + "," + coords.getLongitude())));
        }

        return true;
    } catch (Exception e) {
        // nothing
    }

    Log.i(cgSettings.tag, "cgBase.runNavigation: No navigation application available.");

    if (res != null) {
        ActivityMixin.showToast(activity, res.getString(R.string.err_navigation_no));
    }

    return false;
}