}
}
@Override
public Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DIALOG_DELETE_SECRET: {
// NOTE: the assumption at this point is that position is valid,
// otherwise we would never get here because of the check done
// in onOptionsItemSelected().
DialogInterface.OnClickListener listener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (DialogInterface.BUTTON1 == which) {
deleteSecret(cmenuPosition);
}
}
};
// NOTE: the message part of this dialog is dynamic, so its value is
// set in onPrepareDialog() below. However, its important to set it
// to something here, even the empty string, so that the setMessage()
// call done later actually has an effect.
dialog = new AlertDialog.Builder(this)
.setTitle(R.string.list_menu_delete)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(EMPTY_STRING)
.setPositiveButton(R.string.login_reset_password_pos, listener)
.setNegativeButton(R.string.login_reset_password_neg, null)
.create();
break;
}
case DIALOG_CONFIRM_RESTORE: {
final RestoreDialogState state = new RestoreDialogState();
DialogInterface.OnClickListener itemListener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
state.selected = which;
dialog.dismiss();
SecurityUtils.CipherInfo info = SecurityUtils.getCipherInfo();
if (restoreSecrets(state.getSelectedRestorePoint(), info))
showToast(R.string.restore_succeeded);
}
};
dialog = new AlertDialog.Builder(this)
.setTitle(R.string.dialog_restore_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setSingleChoiceItems(state.getRestoreChoices(),
state.selected,
itemListener)
.create();
break;
}
case DIALOG_IMPORT_SUCCESS: {
DialogInterface.OnClickListener listener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (DialogInterface.BUTTON1 == which) {
deleteImportedFile();
}
importedFile = null;
}
};
dialog = new AlertDialog.Builder(this)
.setTitle(R.string.list_menu_import)
.setIcon(android.R.drawable.ic_dialog_info)
.setMessage(EMPTY_STRING)
.setPositiveButton(R.string.login_reset_password_pos, listener)
.setNegativeButton(R.string.login_reset_password_neg, null)
.create();
break;
}
case DIALOG_CHANGE_PASSWORD: {
DialogInterface.OnClickListener listener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogi, int which) {
AlertDialog dialog = (AlertDialog) dialogi;
TextView password1 = (TextView) dialog.findViewById(
R.id.password);
TextView password2 = (TextView) dialog.findViewById(
R.id.password_validation);
String password = password1.getText().toString();
String p2 = password2.getText().toString();
if (!password.equals(p2) || password.length() == 0) {
showToast(R.string.invalid_password);
return;
}
SeekBar bar = (SeekBar) dialog.findViewById(R.id.cipher_strength);
byte[] salt = SecurityUtils.getSalt();
int rounds = bar.getProgress() + PROGRESS_ROUNDS_OFFSET;
SecurityUtils.CipherInfo info = SecurityUtils.createCiphers(
password, salt, rounds);
if (null != info) {
SecurityUtils.saveCiphers(info);
showToast(R.string.password_changed);
} else {
showToast(R.string.error_reset_password);
}
}
};
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.change_password, getListView(),
false);
dialog = new AlertDialog.Builder(this)
.setTitle(R.string.list_menu_change_password)
.setIcon(android.R.drawable.ic_dialog_info)
.setView(view)
.setPositiveButton(R.string.list_menu_change_password, listener)
.create();
final Dialog dialogFinal = dialog;
SeekBar bar = (SeekBar) view.findViewById(R.id.cipher_strength);
bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,