diff --git a/res/drawable/ic_launcher_folder.png b/res/drawable/ic_launcher_folder.png
new file mode 100644
index 000000000..ed31ba580
Binary files /dev/null and b/res/drawable/ic_launcher_folder.png differ
diff --git a/res/drawable/ic_launcher_folder_small.png b/res/drawable/ic_launcher_folder_small.png
new file mode 100644
index 000000000..5df8d60f0
Binary files /dev/null and b/res/drawable/ic_launcher_folder_small.png differ
diff --git a/res/layout/file_dialog.xml b/res/layout/file_dialog.xml
new file mode 100644
index 000000000..6804ecaba
--- /dev/null
+++ b/res/layout/file_dialog.xml
@@ -0,0 +1,35 @@
+
+
+
+
+ * These specifiers extend the standard Android specifiers. + *
+ */ +public final class FileManager { + + /** + * Activity Action: Pick a file through the file manager, or let user + * specify a custom file name. Data is the current file name or file name + * suggestion. Returns a new file name as file URI in data. + * + *+ * Constant Value: "org.openintents.action.PICK_FILE" + *
+ */ + public static final String ACTION_PICK_FILE = "org.openintents.action.PICK_FILE"; + + /** + * Activity Action: Pick a directory through the file manager, or let user + * specify a custom file name. Data is the current directory name or + * directory name suggestion. Returns a new directory name as file URI in + * data. + * + *+ * Constant Value: "org.openintents.action.PICK_DIRECTORY" + *
+ */ + public static final String ACTION_PICK_DIRECTORY = "org.openintents.action.PICK_DIRECTORY"; + + /** + * The title to display. + * + *+ * This is shown in the title bar of the file manager. + *
+ * + *+ * Constant Value: "org.openintents.extra.TITLE" + *
+ */ + public static final String EXTRA_TITLE = "org.openintents.extra.TITLE"; + + /** + * The text on the button to display. + * + *+ * Depending on the use, it makes sense to set this to "Open" or "Save". + *
+ * + *+ * Constant Value: "org.openintents.extra.BUTTON_TEXT" + *
+ */ + public static final String EXTRA_BUTTON_TEXT = "org.openintents.extra.BUTTON_TEXT"; + +} diff --git a/src/org/thialfihar/android/apg/FileDialog.java b/src/org/thialfihar/android/apg/FileDialog.java index a1662bea4..c2e7ec4b3 100644 --- a/src/org/thialfihar/android/apg/FileDialog.java +++ b/src/org/thialfihar/android/apg/FileDialog.java @@ -16,34 +16,66 @@ package org.thialfihar.android.apg; +import org.openintents.intents.FileManager; + +import android.app.Activity; import android.app.AlertDialog; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.view.LayoutInflater; +import android.view.View; import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.Toast; public class FileDialog { + public static final int REQUEST_CODE_PICK_FILE_OR_DIRECTORY = 12345; + private static EditText mInput; + private static ImageButton mBrowse; + private static Activity mActivity; + private static String mFileManagerTitle; + private static String mFileManagerButton; public static interface OnClickListener { public void onCancelClick(); public void onOkClick(String filename); } - public static AlertDialog build(Context context, String title, String message, - String defaultFile, OnClickListener onClickListener) { - AlertDialog.Builder alert = new AlertDialog.Builder(context); + public static AlertDialog build(Activity activity, String title, String message, + String defaultFile, OnClickListener onClickListener, + String fileManagerTitle, String fileManagerButton) { + LayoutInflater inflater = + (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle(title); alert.setMessage(message); - final EditText input = new EditText(context); - input.setText(defaultFile); - alert.setView(input); + View view = (View) inflater.inflate(R.layout.file_dialog, null); + + mActivity = activity; + mInput = (EditText) view.findViewById(R.id.input); + mInput.setText(defaultFile); + mBrowse = (ImageButton) view.findViewById(R.id.btn_browse); + mBrowse.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + openFile(); + } + }); + mFileManagerTitle = fileManagerTitle; + mFileManagerButton = fileManagerButton; + + alert.setView(view); final OnClickListener clickListener = onClickListener; alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - clickListener.onOkClick(input.getText().toString()); + clickListener.onOkClick(mInput.getText().toString()); } }); @@ -55,4 +87,31 @@ public class FileDialog { }); return alert.create(); } + + public static void setFilename(String filename) { + if (mInput != null) { + mInput.setText(filename); + } + } + + /** + * Opens the file manager to select a file to open. + */ + private static void openFile() { + String fileName = mInput.getText().toString(); + + Intent intent = new Intent(FileManager.ACTION_PICK_FILE); + + intent.setData(Uri.parse("file://" + fileName)); + + intent.putExtra(FileManager.EXTRA_TITLE, mFileManagerTitle); + intent.putExtra(FileManager.EXTRA_BUTTON_TEXT, mFileManagerButton); + + try { + mActivity.startActivityForResult(intent, REQUEST_CODE_PICK_FILE_OR_DIRECTORY); + } catch (ActivityNotFoundException e) { + // No compatible file manager was found. + Toast.makeText(mActivity, R.string.no_filemanager_installed, Toast.LENGTH_SHORT).show(); + } + } } diff --git a/src/org/thialfihar/android/apg/MainActivity.java b/src/org/thialfihar/android/apg/MainActivity.java index 531441c1d..1c0361dec 100644 --- a/src/org/thialfihar/android/apg/MainActivity.java +++ b/src/org/thialfihar/android/apg/MainActivity.java @@ -72,6 +72,8 @@ public class MainActivity extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.main); + Apg.initialize(this); + Button encryptMessageButton = (Button) findViewById(R.id.btn_encryptMessage); Button decryptMessageButton = (Button) findViewById(R.id.btn_decryptMessage); mAccounts = (ListView) findViewById(R.id.account_list); @@ -220,9 +222,7 @@ public class MainActivity extends Activity { SpannableString info = new SpannableString("Read the warnings!\n\n" + "Changes:\n" + - " * display signed-only mails\n" + - " * verify signed-only mails\n" + - " * bug fixes, layout fixes\n" + + " * OI File Manager support\n" + "\n" + "WARNING: be careful editing your existing keys, as they " + "WILL be stripped of certificates right now.\n" + diff --git a/src/org/thialfihar/android/apg/PublicKeyListActivity.java b/src/org/thialfihar/android/apg/PublicKeyListActivity.java index 50fe7422a..1e4dc081d 100644 --- a/src/org/thialfihar/android/apg/PublicKeyListActivity.java +++ b/src/org/thialfihar/android/apg/PublicKeyListActivity.java @@ -31,10 +31,13 @@ import android.app.ExpandableListActivity; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; +import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.Menu; @@ -72,13 +75,14 @@ public class PublicKeyListActivity extends ExpandableListActivity static final int TASK_EXPORT = 2; protected int mSelectedItem = -1; - protected String mImportFilename = null; - protected String mExportFilename = null; protected int mTask = 0; private ProgressDialog mProgressDialog = null; private Thread mRunningThread = null; + private String mImportFilename = Environment.getExternalStorageDirectory() + "/pubring.gpg"; + private String mExportFilename = Environment.getExternalStorageDirectory() + "/pubexport.asc"; + private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { @@ -301,7 +305,7 @@ public class PublicKeyListActivity extends ExpandableListActivity case DIALOG_IMPORT_KEYS: { return FileDialog.build(this, "Import Keys", "Please specify which file to import from.", - Environment.getExternalStorageDirectory() + "/pubring.gpg", + mImportFilename, new FileDialog.OnClickListener() { @Override @@ -315,7 +319,9 @@ public class PublicKeyListActivity extends ExpandableListActivity public void onCancelClick() { removeDialog(DIALOG_IMPORT_KEYS); } - }); + }, + getString(R.string.filemanager_title_open), + getString(R.string.filemanager_btn_open)); } case DIALOG_EXPORT_KEY: { @@ -335,7 +341,7 @@ public class PublicKeyListActivity extends ExpandableListActivity return FileDialog.build(this, title, "Please specify which file to export to.\n" + "WARNING! File will be overwritten if it exists.", - Environment.getExternalStorageDirectory() + "/pubexport.asc", + mExportFilename, new FileDialog.OnClickListener() { @Override @@ -349,7 +355,9 @@ public class PublicKeyListActivity extends ExpandableListActivity public void onCancelClick() { removeDialog(thisDialogId); } - }); + }, + getString(R.string.filemanager_title_save), + getString(R.string.filemanager_btn_save)); } case DIALOG_IMPORTING: { @@ -621,4 +629,32 @@ public class PublicKeyListActivity extends ExpandableListActivity return view; } } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + switch (requestCode) { + case FileDialog.REQUEST_CODE_PICK_FILE_OR_DIRECTORY: { + if (resultCode == RESULT_OK && data != null) { + String filename = data.getDataString(); + if (filename != null) { + // Get rid of URI prefix: + if (filename.startsWith("file://")) { + filename = filename.substring(7); + } + // replace %20 and so on + filename = Uri.decode(filename); + + FileDialog.setFilename(filename); + } + + } + return; + } + + default: { + break; + } + } + super.onActivityResult(requestCode, resultCode, data); + } } diff --git a/src/org/thialfihar/android/apg/SecretKeyListActivity.java b/src/org/thialfihar/android/apg/SecretKeyListActivity.java index 1560546d7..794b30ea2 100644 --- a/src/org/thialfihar/android/apg/SecretKeyListActivity.java +++ b/src/org/thialfihar/android/apg/SecretKeyListActivity.java @@ -32,6 +32,7 @@ import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.Handler; @@ -81,13 +82,14 @@ public class SecretKeyListActivity extends ExpandableListActivity static final int TASK_EXPORT = 2; protected int mSelectedItem = -1; - protected String mImportFilename = null; - protected String mExportFilename = null; protected int mTask = 0; private ProgressDialog mProgressDialog = null; private Thread mRunningThread = null; + private String mImportFilename = Environment.getExternalStorageDirectory() + "/secring.gpg"; + private String mExportFilename = Environment.getExternalStorageDirectory() + "/secexport.asc"; + private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { @@ -335,7 +337,7 @@ public class SecretKeyListActivity extends ExpandableListActivity case DIALOG_IMPORT_KEYS: { return FileDialog.build(this, "Import Keys", "Please specify which file to import from.", - Environment.getExternalStorageDirectory() + "/secring.gpg", + mImportFilename, new FileDialog.OnClickListener() { @Override @@ -349,7 +351,9 @@ public class SecretKeyListActivity extends ExpandableListActivity public void onCancelClick() { removeDialog(DIALOG_IMPORT_KEYS); } - }); + }, + getString(R.string.filemanager_title_open), + getString(R.string.filemanager_btn_open)); } case DIALOG_EXPORT_KEY: { @@ -370,7 +374,7 @@ public class SecretKeyListActivity extends ExpandableListActivity "Please specify which file to export to.\n" + "WARNING! You are about to export SECRET keys.\n" + "WARNING! File will be overwritten if it exists.", - Environment.getExternalStorageDirectory() + "/secexport.asc", + mExportFilename, new FileDialog.OnClickListener() { @Override @@ -384,7 +388,9 @@ public class SecretKeyListActivity extends ExpandableListActivity public void onCancelClick() { removeDialog(thisDialogId); } - }); + }, + getString(R.string.filemanager_title_save), + getString(R.string.filemanager_btn_save)); } case DIALOG_IMPORTING: { @@ -441,6 +447,24 @@ public class SecretKeyListActivity extends ExpandableListActivity break; } + case FileDialog.REQUEST_CODE_PICK_FILE_OR_DIRECTORY: { + if (resultCode == RESULT_OK && data != null) { + String filename = data.getDataString(); + if (filename != null) { + // Get rid of URI prefix: + if (filename.startsWith("file://")) { + filename = filename.substring(7); + } + // replace %20 and so on + filename = Uri.decode(filename); + + FileDialog.setFilename(filename); + } + + } + return; + } + default: break; }