From 368f0a122f242e5de75dd48c245e480a928384e1 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Mon, 26 Jul 2010 21:57:28 +0000 Subject: [PATCH] added an optional checkbox to the file dialog, can be used for instance to optionally delete files after importing them, and is used for that, also rearranged the option menu items for the main activity a little Update issue 39 Added a new string: Delete After Import --- res/layout/file_dialog.xml | 29 ++++++++++++++----- res/values/strings.xml | 1 + .../android/apg/DecryptActivity.java | 4 +-- .../android/apg/EncryptActivity.java | 4 +-- .../thialfihar/android/apg/FileDialog.java | 21 ++++++++++++-- .../android/apg/KeyListActivity.java | 13 +++++++-- .../thialfihar/android/apg/MainActivity.java | 8 ++--- 7 files changed, 60 insertions(+), 20 deletions(-) diff --git a/res/layout/file_dialog.xml b/res/layout/file_dialog.xml index c42d2636e..bc5a2a214 100644 --- a/res/layout/file_dialog.xml +++ b/res/layout/file_dialog.xml @@ -18,19 +18,32 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:orientation="horizontal" + android:orientation="vertical" android:paddingLeft="5dip" android:paddingRight="5dip"> - + android:orientation="horizontal"> - + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 8c08b7ec3..c9f35824c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -97,6 +97,7 @@ Public Key(s) Delete After Encryption Delete After Decryption + Delete After Import Encryption Algorithm Hash Algorithm Public Key diff --git a/src/org/thialfihar/android/apg/DecryptActivity.java b/src/org/thialfihar/android/apg/DecryptActivity.java index f5e35c584..a7eb31248 100644 --- a/src/org/thialfihar/android/apg/DecryptActivity.java +++ b/src/org/thialfihar/android/apg/DecryptActivity.java @@ -659,9 +659,8 @@ public class DecryptActivity extends BaseActivity { getString(R.string.specifyFileToDecryptTo), mOutputFilename, new FileDialog.OnClickListener() { - @Override - public void onOkClick(String filename) { + public void onOkClick(String filename, boolean checked) { removeDialog(Id.dialog.output_filename); mOutputFilename = filename; decryptStart(); @@ -674,6 +673,7 @@ public class DecryptActivity extends BaseActivity { }, getString(R.string.filemanager_titleSave), getString(R.string.filemanager_btnSave), + null, Id.request.output_filename); } diff --git a/src/org/thialfihar/android/apg/EncryptActivity.java b/src/org/thialfihar/android/apg/EncryptActivity.java index a42cc66c1..b3b002346 100644 --- a/src/org/thialfihar/android/apg/EncryptActivity.java +++ b/src/org/thialfihar/android/apg/EncryptActivity.java @@ -904,9 +904,8 @@ public class EncryptActivity extends BaseActivity { getString(R.string.specifyFileToEncryptTo), mOutputFilename, new FileDialog.OnClickListener() { - @Override - public void onOkClick(String filename) { + public void onOkClick(String filename, boolean checked) { removeDialog(Id.dialog.output_filename); mOutputFilename = filename; encryptStart(); @@ -919,6 +918,7 @@ public class EncryptActivity extends BaseActivity { }, getString(R.string.filemanager_titleSave), getString(R.string.filemanager_btnSave), + null, Id.request.output_filename); } diff --git a/src/org/thialfihar/android/apg/FileDialog.java b/src/org/thialfihar/android/apg/FileDialog.java index d717bb0bb..02eb80fdf 100644 --- a/src/org/thialfihar/android/apg/FileDialog.java +++ b/src/org/thialfihar/android/apg/FileDialog.java @@ -25,6 +25,7 @@ import android.content.Intent; import android.net.Uri; import android.view.LayoutInflater; import android.view.View; +import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageButton; import android.widget.Toast; @@ -32,6 +33,7 @@ import android.widget.Toast; public class FileDialog { private static EditText mFilename; private static ImageButton mBrowse; + private static CheckBox mCheckBox; private static Activity mActivity; private static String mFileManagerTitle; private static String mFileManagerButton; @@ -39,12 +41,13 @@ public class FileDialog { public static interface OnClickListener { public void onCancelClick(); - public void onOkClick(String filename); + public void onOkClick(String filename, boolean checkbox); } public static AlertDialog build(Activity activity, String title, String message, String defaultFile, OnClickListener onClickListener, String fileManagerTitle, String fileManagerButton, + String checkboxText, int requestCode) { // TODO: fileManagerTitle and fileManagerButton are deprecated, no use for them right now, // but maybe the Intent now used will someday support them again, so leaving them in @@ -70,6 +73,15 @@ public class FileDialog { mFileManagerTitle = fileManagerTitle; mFileManagerButton = fileManagerButton; mRequestCode = requestCode; + mCheckBox = (CheckBox) view.findViewById(R.id.checkbox); + if (checkboxText == null) { + mCheckBox.setEnabled(false); + mCheckBox.setVisibility(View.GONE); + } else { + mCheckBox.setEnabled(true); + mCheckBox.setVisibility(View.VISIBLE); + mCheckBox.setText(checkboxText); + } alert.setView(view); @@ -77,7 +89,12 @@ public class FileDialog { alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - clickListener.onOkClick(mFilename.getText().toString()); + boolean checked = false; + if (mCheckBox.isEnabled()) { + checked = mCheckBox.isChecked(); + } + clickListener.onOkClick(mFilename.getText().toString(), + checked); } }); diff --git a/src/org/thialfihar/android/apg/KeyListActivity.java b/src/org/thialfihar/android/apg/KeyListActivity.java index fc074e75d..6f5442502 100644 --- a/src/org/thialfihar/android/apg/KeyListActivity.java +++ b/src/org/thialfihar/android/apg/KeyListActivity.java @@ -72,6 +72,7 @@ public class KeyListActivity extends BaseActivity { protected String mExportFilename = Constants.path.app_dir + "/"; protected String mImportData; + protected boolean mDeleteAfterImport = false; protected int mKeyType = Id.type.public_key; @@ -234,8 +235,9 @@ public class KeyListActivity extends BaseActivity { new FileDialog.OnClickListener() { @Override - public void onOkClick(String filename) { + public void onOkClick(String filename, boolean checked) { removeDialog(Id.dialog.import_keys); + mDeleteAfterImport = checked; mImportFilename = filename; importKeys(); } @@ -247,6 +249,7 @@ public class KeyListActivity extends BaseActivity { }, getString(R.string.filemanager_titleOpen), getString(R.string.filemanager_btnOpen), + getString(R.string.label_deleteAfterImport), Id.request.filename); } @@ -269,7 +272,7 @@ public class KeyListActivity extends BaseActivity { mExportFilename, new FileDialog.OnClickListener() { @Override - public void onOkClick(String filename) { + public void onOkClick(String filename, boolean checked) { removeDialog(thisDialogId); mExportFilename = filename; exportKeys(); @@ -282,6 +285,7 @@ public class KeyListActivity extends BaseActivity { }, getString(R.string.filemanager_titleSave), getString(R.string.filemanager_btnSave), + null, Id.request.filename); } @@ -409,6 +413,11 @@ public class KeyListActivity extends BaseActivity { } Toast.makeText(KeyListActivity.this, message, Toast.LENGTH_SHORT).show(); + // everything went well, so now delete, if that was turned on + if (mDeleteAfterImport) { + setDeleteFile(mImportFilename); + showDialog(Id.dialog.delete_file); + } } refreshList(); break; diff --git a/src/org/thialfihar/android/apg/MainActivity.java b/src/org/thialfihar/android/apg/MainActivity.java index 6ac44b71a..81791ee1f 100644 --- a/src/org/thialfihar/android/apg/MainActivity.java +++ b/src/org/thialfihar/android/apg/MainActivity.java @@ -275,12 +275,12 @@ public class MainActivity extends BaseActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - menu.add(0, Id.menu.option.create, 0, R.string.menu_addAccount) - .setIcon(android.R.drawable.ic_menu_add); - menu.add(1, Id.menu.option.manage_public_keys, 1, R.string.menu_managePublicKeys) + menu.add(0, Id.menu.option.manage_public_keys, 0, R.string.menu_managePublicKeys) .setIcon(android.R.drawable.ic_menu_manage); - menu.add(1, Id.menu.option.manage_secret_keys, 2, R.string.menu_manageSecretKeys) + menu.add(0, Id.menu.option.manage_secret_keys, 1, R.string.menu_manageSecretKeys) .setIcon(android.R.drawable.ic_menu_manage); + menu.add(1, Id.menu.option.create, 2, R.string.menu_addAccount) + .setIcon(android.R.drawable.ic_menu_add); menu.add(2, Id.menu.option.preferences, 3, R.string.menu_preferences) .setIcon(android.R.drawable.ic_menu_preferences); menu.add(2, Id.menu.option.about, 4, R.string.menu_about)