diff --git a/.classpath b/.classpath
new file mode 100644
index 000000000..6d4a0c412
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 000000000..b4ab4a1fa
--- /dev/null
+++ b/.project
@@ -0,0 +1,33 @@
+
+
+ APG 0.9.x
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 28b9a2d9d..e54d70dc1 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -14,72 +14,99 @@
limitations under the License.
-->
-
-
-
+
+
+
+
+
+
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
+
diff --git a/bin/APG 0.9.x.apk b/bin/APG 0.9.x.apk
new file mode 100644
index 000000000..5f41d9268
Binary files /dev/null and b/bin/APG 0.9.x.apk differ
diff --git a/bin/classes.dex b/bin/classes.dex
new file mode 100644
index 000000000..e6dbb2454
Binary files /dev/null and b/bin/classes.dex differ
diff --git a/bin/resources.ap_ b/bin/resources.ap_
new file mode 100644
index 000000000..3d2e3eda7
Binary files /dev/null and b/bin/resources.ap_ differ
diff --git a/res/layout/account_item.xml b/res/layout/account_item.xml
index e37000ff0..c2a75075e 100644
--- a/res/layout/account_item.xml
+++ b/res/layout/account_item.xml
@@ -24,12 +24,12 @@
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight">
-
+
diff --git a/res/layout/create_key.xml b/res/layout/create_key.xml
index 569b703f5..ab327ffeb 100644
--- a/res/layout/create_key.xml
+++ b/res/layout/create_key.xml
@@ -18,35 +18,47 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
+
+
+
+
+
+
+
+
+ android:layout_width="fill_parent"
+ android:gravity="right"
+ android:numeric="integer"/>
+
+
diff --git a/res/layout/decrypt_message.xml b/res/layout/decrypt_message.xml
index 2a0aa153d..de5b5e7fa 100644
--- a/res/layout/decrypt_message.xml
+++ b/res/layout/decrypt_message.xml
@@ -21,77 +21,79 @@
android:layout_height="fill_parent"
android:fillViewport="true">
-
+
-
+
-
+
-
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
diff --git a/res/layout/edit_key.xml b/res/layout/edit_key.xml
index 2fceeb5a3..bf994fa44 100644
--- a/res/layout/edit_key.xml
+++ b/res/layout/edit_key.xml
@@ -22,19 +22,21 @@
android:paddingTop="5dip"
android:fillViewport="true">
-
-
-
+
-
+
+
+
+
-
+
+
diff --git a/res/layout/edit_key_key_item.xml b/res/layout/edit_key_key_item.xml
index 46de4a977..78c1d1254 100644
--- a/res/layout/edit_key_key_item.xml
+++ b/res/layout/edit_key_key_item.xml
@@ -15,99 +15,129 @@
-->
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingLeft="5dip">
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:layout_width="fill_parent"
+ android:orientation="horizontal">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
diff --git a/res/layout/edit_key_section.xml b/res/layout/edit_key_section.xml
index b3a48f87e..e57b3b8df 100644
--- a/res/layout/edit_key_section.xml
+++ b/res/layout/edit_key_section.xml
@@ -15,7 +15,7 @@
-->
diff --git a/res/layout/edit_key_user_id_item.xml b/res/layout/edit_key_user_id_item.xml
index 998c436cb..40b852e3e 100644
--- a/res/layout/edit_key_user_id_item.xml
+++ b/res/layout/edit_key_user_id_item.xml
@@ -15,82 +15,99 @@
-->
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingLeft="5dip">
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:layout_width="wrap_content"
+ android:layout_marginLeft="20dip"/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
diff --git a/res/layout/encrypt_file.xml b/res/layout/encrypt_file.xml
new file mode 100644
index 000000000..8a2b9665b
--- /dev/null
+++ b/res/layout/encrypt_file.xml
@@ -0,0 +1,166 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/encrypt_message.xml b/res/layout/encrypt_message.xml
index 254552e03..3d8db4e6e 100644
--- a/res/layout/encrypt_message.xml
+++ b/res/layout/encrypt_message.xml
@@ -21,75 +21,73 @@
android:layout_height="fill_parent"
android:fillViewport="true">
-
-
+
-
+
-
+
-
+
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/layout/file_dialog.xml b/res/layout/file_dialog.xml
index 6804ecaba..c42d2636e 100644
--- a/res/layout/file_dialog.xml
+++ b/res/layout/file_dialog.xml
@@ -15,21 +15,23 @@
-->
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingLeft="5dip"
+ android:paddingRight="5dip">
+
+ android:layout_weight="1"/>
-
+ android:layout_width="wrap_content"/>
+
diff --git a/res/layout/key_list.xml b/res/layout/key_list.xml
new file mode 100644
index 000000000..f08495368
--- /dev/null
+++ b/res/layout/key_list.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
diff --git a/res/layout/key_list_child_item_master_key.xml b/res/layout/key_list_child_item_master_key.xml
index 47eba65b5..f98f94762 100644
--- a/res/layout/key_list_child_item_master_key.xml
+++ b/res/layout/key_list_child_item_master_key.xml
@@ -19,54 +19,62 @@
android:singleLine="true"
android:paddingLeft="10dip"
android:layout_marginRight="?android:attr/scrollbarSize"
- android:layout_height="?android:attr/listPreferredItemHeight" android:layout_width="fill_parent">
+ android:layout_height="?android:attr/listPreferredItemHeight"
+ android:layout_width="fill_parent">
-
+
-
+
-
+
-
+
+
-
+
-
+
-
+
+
+
-
-
-
\ No newline at end of file
diff --git a/res/layout/key_list_child_item_sub_key.xml b/res/layout/key_list_child_item_sub_key.xml
index 085d78f05..11ad90fe1 100644
--- a/res/layout/key_list_child_item_sub_key.xml
+++ b/res/layout/key_list_child_item_sub_key.xml
@@ -22,49 +22,51 @@
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="fill_parent">
-
+
-
+
-
+
+
-
+
-
+
-
+
+
+
-
-
-
\ No newline at end of file
diff --git a/res/layout/key_list_child_item_user_id.xml b/res/layout/key_list_child_item_user_id.xml
index 80cdd2867..fa2b720de 100644
--- a/res/layout/key_list_child_item_user_id.xml
+++ b/res/layout/key_list_child_item_user_id.xml
@@ -22,12 +22,12 @@
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight">
-
+
diff --git a/res/layout/key_list_group_item.xml b/res/layout/key_list_group_item.xml
index aaada82e3..c04c1d223 100644
--- a/res/layout/key_list_group_item.xml
+++ b/res/layout/key_list_group_item.xml
@@ -21,32 +21,33 @@
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight">
-
+
-
+
-
+
+
+
+
+
+
+
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout/mailbox_message_item.xml b/res/layout/mailbox_message_item.xml
index 6026909d3..131abff46 100644
--- a/res/layout/mailbox_message_item.xml
+++ b/res/layout/mailbox_message_item.xml
@@ -24,34 +24,34 @@
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="fill_parent">
-
+
-
+
-
+
-
+
+
+
-
-
\ No newline at end of file
diff --git a/res/layout/main.xml b/res/layout/main.xml
index 5418b21f6..c91abd082 100644
--- a/res/layout/main.xml
+++ b/res/layout/main.xml
@@ -22,41 +22,68 @@
android:paddingTop="5dip"
android:fillViewport="true">
-
+
-
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
\ No newline at end of file
diff --git a/res/layout/select_public_key.xml b/res/layout/select_public_key.xml
index 9a2d9f578..3c7c6534a 100644
--- a/res/layout/select_public_key.xml
+++ b/res/layout/select_public_key.xml
@@ -21,34 +21,33 @@
android:layout_height="fill_parent"
android:fillViewport="true">
-
-
+
-
+
-
+
-
-
-
+
+
+
diff --git a/res/layout/select_public_key_item.xml b/res/layout/select_public_key_item.xml
index aba0c09b9..cdc81399f 100644
--- a/res/layout/select_public_key_item.xml
+++ b/res/layout/select_public_key_item.xml
@@ -22,75 +22,76 @@
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="fill_parent">
-
+
-
+
-
+
-
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
-
-
\ No newline at end of file
diff --git a/res/layout/select_secret_key.xml b/res/layout/select_secret_key.xml
index 64967ace6..f252f56e5 100644
--- a/res/layout/select_secret_key.xml
+++ b/res/layout/select_secret_key.xml
@@ -21,10 +21,9 @@
android:layout_height="fill_parent"
android:fillViewport="true">
-
-
+
diff --git a/res/layout/select_secret_key_item.xml b/res/layout/select_secret_key_item.xml
index 0b0475c37..97a0ce5b3 100644
--- a/res/layout/select_secret_key_item.xml
+++ b/res/layout/select_secret_key_item.xml
@@ -22,67 +22,68 @@
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="fill_parent">
-
+
-
+
-
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
-
-
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 20eb5476d..f64258e0a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -23,6 +23,8 @@
Select Signature
Encrypt Message
Decrypt Message
+ Encrypt File
+ Decrypt File
Authentification
Create Key
Edit Key
@@ -31,15 +33,21 @@
Keys
Send via Email
+ Encrypt
Decrypt
Verify
Select Recipients
Reply
Encrypt Message
Decrypt Message
+ Encrypt File
+ Decrypt File
Save
Cancel
+ Symmetric
+ Asymmetric
+
About
Add GMail Account
Manage Public Keys
@@ -53,6 +61,9 @@
<unknown>
<none>
+ File:
+ Encrypt with:
+
Sign only
Encrypt only
Sign and Encrypt
diff --git a/src/org/thialfihar/android/apg/Apg.java b/src/org/thialfihar/android/apg/Apg.java
index 26a053921..fd9d29ccc 100644
--- a/src/org/thialfihar/android/apg/Apg.java
+++ b/src/org/thialfihar/android/apg/Apg.java
@@ -98,6 +98,8 @@ public class Apg {
public static class Intent {
public static final String DECRYPT = "org.thialfihar.android.apg.intent.DECRYPT";
public static final String ENCRYPT = "org.thialfihar.android.apg.intent.ENCRYPT";
+ public static final String DECRYPT_FILE = "org.thialfihar.android.apg.intent.DECRYPT_FILE";
+ public static final String ENCRYPT_FILE = "org.thialfihar.android.apg.intent.ENCRYPT_FILE";
}
public static String VERSION = "0.9.0";
@@ -121,8 +123,8 @@ public class Apg {
CompressionAlgorithmTags.BZIP2,
CompressionAlgorithmTags.ZIP };
- protected static Vector mPublicKeyRings;
- protected static Vector mSecretKeyRings;
+ protected static Vector mPublicKeyRings = new Vector();
+ protected static Vector mSecretKeyRings = new Vector();
public static Pattern PGP_MESSAGE =
Pattern.compile(".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*",
@@ -139,9 +141,6 @@ public class Apg {
protected static final int RETURN_OK = 0;
protected static final int RETURN_UPDATED = 1;
- protected static final int TYPE_PUBLIC = 0;
- protected static final int TYPE_SECRET = 1;
-
protected static HashMap mSecretKeyIdToIdMap;
protected static HashMap mSecretKeyIdToKeyRingMap;
protected static HashMap mPublicKeyIdToIdMap;
@@ -180,13 +179,12 @@ public class Apg {
}
public static void initialize(Activity context) {
- setPassPhrase(null);
if (mInitialized) {
return;
}
- loadKeyRings(context, TYPE_PUBLIC);
- loadKeyRings(context, TYPE_SECRET);
+ loadKeyRings(context, Id.type.public_key);
+ loadKeyRings(context, Id.type.secret_key);
mInitialized = true;
}
@@ -546,8 +544,8 @@ public class Apg {
saveKeyRing(context, secretKeyRing);
saveKeyRing(context, publicKeyRing);
- loadKeyRings(context, TYPE_PUBLIC);
- loadKeyRings(context, TYPE_SECRET);
+ loadKeyRings(context, Id.type.public_key);
+ loadKeyRings(context, Id.type.secret_key);
progress.setProgress("done.", 100, 100);
}
@@ -617,7 +615,7 @@ public class Apg {
Bundle returnData = new Bundle();
PGPObjectFactory objectFactors = null;
- if (type == TYPE_SECRET) {
+ if (type == Id.type.secret_key) {
progress.setProgress("importing secret keys...", 0, 100);
} else {
progress.setProgress("importing public keys...", 0, 100);
@@ -647,7 +645,7 @@ public class Apg {
PGPSecretKeyRing secretKeyRing;
int retValue;
- if (type == TYPE_SECRET) {
+ if (type == Id.type.secret_key) {
if (!(obj instanceof PGPSecretKeyRing)) {
continue;
}
@@ -729,7 +727,7 @@ public class Apg {
private static void loadKeyRings(Activity context, int type) {
Cursor cursor;
- if (type == TYPE_SECRET) {
+ if (type == Id.type.secret_key) {
mSecretKeyRings.clear();
mSecretKeyIdToIdMap.clear();
mSecretKeyIdToKeyRingMap.clear();
@@ -757,7 +755,7 @@ public class Apg {
long keyId = cursor.getLong(keyIdIndex);
try {
- if (type == TYPE_SECRET) {
+ if (type == Id.type.secret_key) {
PGPSecretKeyRing key = new PGPSecretKeyRing(keyData);
mSecretKeyRings.add(key);
mSecretKeyIdToIdMap.put(keyId, id);
@@ -775,7 +773,7 @@ public class Apg {
}
}
- if (type == TYPE_SECRET) {
+ if (type == Id.type.secret_key) {
Collections.sort(mSecretKeyRings, new SecretKeySorter());
} else {
Collections.sort(mPublicKeyRings, new PublicKeySorter());
@@ -1059,14 +1057,14 @@ public class Apg {
PGPPublicKey masterKey = getMasterKey(keyRing);
Uri uri = Uri.withAppendedPath(PublicKeys.CONTENT_URI_BY_KEY_ID, "" + masterKey.getKeyID());
context.getContentResolver().delete(uri, null, null);
- loadKeyRings(context, TYPE_PUBLIC);
+ loadKeyRings(context, Id.type.public_key);
}
public static void deleteKey(Activity context, PGPSecretKeyRing keyRing) {
PGPSecretKey masterKey = getMasterKey(keyRing);
Uri uri = Uri.withAppendedPath(SecretKeys.CONTENT_URI_BY_KEY_ID, "" + masterKey.getKeyID());
context.getContentResolver().delete(uri, null, null);
- loadKeyRings(context, TYPE_SECRET);
+ loadKeyRings(context, Id.type.secret_key);
}
public static PGPPublicKey findPublicKey(long keyId) {
diff --git a/src/org/thialfihar/android/apg/AskForSecretKeyPassPhrase.java b/src/org/thialfihar/android/apg/AskForSecretKeyPassPhrase.java
index ed1c16833..06e9c6d0a 100644
--- a/src/org/thialfihar/android/apg/AskForSecretKeyPassPhrase.java
+++ b/src/org/thialfihar/android/apg/AskForSecretKeyPassPhrase.java
@@ -35,8 +35,6 @@ import android.widget.LinearLayout;
import android.widget.Toast;
public class AskForSecretKeyPassPhrase {
- public static final int DIALOG_PASS_PHRASE = 12345;
-
public static interface PassPhraseCallbackInterface {
void passPhraseCallback(String passPhrase);
}
@@ -91,7 +89,7 @@ public class AskForSecretKeyPassPhrase {
alert.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
- activity.removeDialog(DIALOG_PASS_PHRASE);
+ activity.removeDialog(Id.dialog.pass_phrase);
String passPhrase = "" + input.getText();
try {
secretKey.extractPrivateKey(passPhrase.toCharArray(),
@@ -109,7 +107,7 @@ public class AskForSecretKeyPassPhrase {
alert.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
- activity.removeDialog(DIALOG_PASS_PHRASE);
+ activity.removeDialog(Id.dialog.pass_phrase);
}
});
diff --git a/src/org/thialfihar/android/apg/BaseActivity.java b/src/org/thialfihar/android/apg/BaseActivity.java
new file mode 100644
index 000000000..09de2ae5a
--- /dev/null
+++ b/src/org/thialfihar/android/apg/BaseActivity.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2010 Thialfihar
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.thialfihar.android.apg;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+
+public class BaseActivity extends Activity
+ implements Runnable, ProgressDialogUpdater,
+ AskForSecretKeyPassPhrase.PassPhraseCallbackInterface {
+
+ private ProgressDialog mProgressDialog = null;
+ private Thread mRunningThread = null;
+
+ private long mSecretKeyId = 0;
+
+ private Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ handlerCallback(msg);
+ }
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Apg.initialize(this);
+ }
+
+ @Override
+ protected Dialog onCreateDialog(int id) {
+
+ // in case it is a progress dialog
+ mProgressDialog = new ProgressDialog(this);
+ mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+ mProgressDialog.setCancelable(false);
+ switch (id) {
+ case Id.dialog.encrypting: {
+ mProgressDialog.setMessage("initializing...");
+ return mProgressDialog;
+ }
+
+ case Id.dialog.decrypting: {
+ mProgressDialog.setMessage("initializing...");
+ return mProgressDialog;
+ }
+
+ case Id.dialog.saving: {
+ mProgressDialog.setMessage("saving...");
+ return mProgressDialog;
+ }
+
+ case Id.dialog.importing: {
+ mProgressDialog.setMessage("importing...");
+ return mProgressDialog;
+ }
+
+ case Id.dialog.exporting: {
+ mProgressDialog.setMessage("exporting...");
+ return mProgressDialog;
+ }
+
+ default: {
+ break;
+ }
+ }
+ mProgressDialog = null;
+
+ switch (id) {
+ case Id.dialog.pass_phrase: {
+ return AskForSecretKeyPassPhrase.createDialog(this, getSecretKeyId(), this);
+ }
+
+ case Id.dialog.pass_phrases_do_not_match: {
+ AlertDialog.Builder alert = new AlertDialog.Builder(this);
+
+ alert.setIcon(android.R.drawable.ic_dialog_alert);
+ alert.setTitle("Error");
+ alert.setMessage("The pass phrases didn't match.");
+
+ alert.setPositiveButton(android.R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ removeDialog(Id.dialog.pass_phrases_do_not_match);
+ }
+ });
+ alert.setCancelable(false);
+
+ return alert.create();
+ }
+
+ case Id.dialog.no_pass_phrase: {
+ AlertDialog.Builder alert = new AlertDialog.Builder(this);
+
+ alert.setIcon(android.R.drawable.ic_dialog_alert);
+ alert.setTitle("Error");
+ alert.setMessage("Empty pass phrases are not supported.");
+
+ alert.setPositiveButton(android.R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ removeDialog(Id.dialog.no_pass_phrase);
+ }
+ });
+ alert.setCancelable(false);
+
+ return alert.create();
+ }
+
+
+ default: {
+ break;
+ }
+ }
+
+ return super.onCreateDialog(id);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ default: {
+ break;
+ }
+ }
+
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ @Override
+ public void setProgress(int progress, int max) {
+ Message msg = new Message();
+ Bundle data = new Bundle();
+ data.putInt("type", Id.message.progress_update);
+ data.putInt("progress", progress);
+ data.putInt("max", max);
+ msg.setData(data);
+ mHandler.sendMessage(msg);
+ }
+
+ @Override
+ public void setProgress(String message, int progress, int max) {
+ Message msg = new Message();
+ Bundle data = new Bundle();
+ data.putInt("type", Id.message.progress_update);
+ data.putString("message", message);
+ data.putInt("progress", progress);
+ data.putInt("max", max);
+ msg.setData(data);
+ mHandler.sendMessage(msg);
+ }
+
+ public void handlerCallback(Message msg) {
+ Bundle data = msg.getData();
+ if (data == null) {
+ return;
+ }
+
+ int type = data.getInt("type");
+ switch (type) {
+ case Id.message.progress_update: {
+ String message = data.getString("message");
+ if (mProgressDialog != null) {
+ if (message != null) {
+ mProgressDialog.setMessage(message);
+ }
+ mProgressDialog.setMax(data.getInt("max"));
+ mProgressDialog.setProgress(data.getInt("progress"));
+ }
+ break;
+ }
+
+ case Id.message.import_done: // intentionall no break
+ case Id.message.export_done: // intentionall no break
+ case Id.message.done: {
+ mProgressDialog = null;
+ doneCallback(msg);
+ break;
+ }
+ }
+ }
+
+ public void doneCallback(Message msg) {
+
+ }
+
+ public void passPhraseCallback(String passPhrase) {
+ Log.e("oink", "setting pass phrase to " + passPhrase);
+ Apg.setPassPhrase(passPhrase);
+ }
+
+ public void sendMessage(Message msg) {
+ mHandler.sendMessage(msg);
+ }
+
+ public void startThread() {
+ mRunningThread = new Thread(this);
+ mRunningThread.start();
+ }
+
+ public void run() {
+
+ }
+
+ public void setSecretKeyId(long id) {
+ mSecretKeyId = id;
+ }
+
+ public long getSecretKeyId() {
+ return mSecretKeyId;
+ }
+}
diff --git a/src/org/thialfihar/android/apg/DecryptMessageActivity.java b/src/org/thialfihar/android/apg/DecryptMessageActivity.java
index 8b7985c77..fc2c68ba4 100644
--- a/src/org/thialfihar/android/apg/DecryptMessageActivity.java
+++ b/src/org/thialfihar/android/apg/DecryptMessageActivity.java
@@ -29,13 +29,9 @@ import org.bouncycastle2.jce.provider.BouncyCastleProvider;
import org.bouncycastle2.openpgp.PGPException;
import org.bouncycastle2.util.Strings;
-import android.app.Activity;
-import android.app.Dialog;
-import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
-import android.os.Handler;
import android.os.Message;
import android.text.ClipboardManager;
import android.view.View;
@@ -47,27 +43,13 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
-public class DecryptMessageActivity extends Activity
- implements Runnable, ProgressDialogUpdater,
- AskForSecretKeyPassPhrase.PassPhraseCallbackInterface {
- static final int GET_PUCLIC_KEYS = 1;
- static final int GET_SECRET_KEY = 2;
-
- static final int DIALOG_DECRYPTING = 1;
-
- static final int MESSAGE_PROGRESS_UPDATE = 1;
- static final int MESSAGE_DONE = 2;
-
- private long mDecryptionKeyId = 0;
+public class DecryptMessageActivity extends BaseActivity {
private long mSignatureKeyId = 0;
private String mReplyTo = null;
private String mSubject = null;
private boolean mSignedOnly = false;
- private ProgressDialog mProgressDialog = null;
- private Thread mRunningThread = null;
-
private EditText mMessage = null;
private LinearLayout mSignatureLayout = null;
private ImageView mSignatureStatusImage = null;
@@ -75,90 +57,11 @@ public class DecryptMessageActivity extends Activity
private TextView mUserIdRest = null;
private Button mDecryptButton = null;
- private Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- Bundle data = msg.getData();
- if (data != null) {
- int type = data.getInt("type");
- switch (type) {
- case MESSAGE_PROGRESS_UPDATE: {
- String message = data.getString("message");
- if (mProgressDialog != null) {
- if (message != null) {
- mProgressDialog.setMessage(message);
- }
- mProgressDialog.setMax(data.getInt("max"));
- mProgressDialog.setProgress(data.getInt("progress"));
- }
- break;
- }
-
- case MESSAGE_DONE: {
- removeDialog(DIALOG_DECRYPTING);
- mProgressDialog = null;
- mSignatureKeyId = 0;
- String error = data.getString("error");
- String decryptedMessage = data.getString("decryptedMessage");
- if (error != null) {
- Toast.makeText(DecryptMessageActivity.this,
- "Error: " + data.getString("error"),
- Toast.LENGTH_SHORT).show();
- }
- mSignatureLayout.setVisibility(View.INVISIBLE);
- if (decryptedMessage != null) {
- mMessage.setText(decryptedMessage);
- mDecryptButton.setText(R.string.btn_reply);
- mDecryptButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- replyClicked();
- }
- });
-
- if (data.getBoolean("signature")) {
- String userId = data.getString("signatureUserId");
- mSignatureKeyId = data.getLong("signatureKeyId");
- mUserIdRest.setText("id: " +
- Long.toHexString(mSignatureKeyId & 0xffffffffL));
- if (userId == null) {
- userId =
- getResources()
- .getString(
- R.string.unknown_user_id);
- }
- String chunks[] = userId.split(" <", 2);
- userId = chunks[0];
- if (chunks.length > 1) {
- mUserIdRest.setText("<" + chunks[1]);
- }
- mUserId.setText(userId);
-
- if (data.getBoolean("signatureSuccess")) {
- mSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
- } else if (data.getBoolean("signatureUnknown")) {
- mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
- } else {
- mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
- }
- mSignatureLayout.setVisibility(View.VISIBLE);
- }
- }
-
- break;
- }
- }
- }
- }
- };
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.decrypt_message);
- Apg.initialize(this);
-
mMessage = (EditText) findViewById(R.id.message);
mDecryptButton = (Button) findViewById(R.id.btn_decrypt);
mSignatureLayout = (LinearLayout) findViewById(R.id.layout_signature);
@@ -232,48 +135,6 @@ public class DecryptMessageActivity extends Activity
}
}
- @Override
- protected Dialog onCreateDialog(int id) {
- switch (id) {
- case DIALOG_DECRYPTING: {
- mProgressDialog = new ProgressDialog(this);
- mProgressDialog.setMessage("initializing...");
- mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- mProgressDialog.setCancelable(false);
- return mProgressDialog;
- }
-
- case AskForSecretKeyPassPhrase.DIALOG_PASS_PHRASE: {
- return AskForSecretKeyPassPhrase.createDialog(this, mDecryptionKeyId, this);
- }
- }
-
- return super.onCreateDialog(id);
- }
-
- @Override
- public void setProgress(int progress, int max) {
- Message msg = new Message();
- Bundle data = new Bundle();
- data.putInt("type", MESSAGE_PROGRESS_UPDATE);
- data.putInt("progress", progress);
- data.putInt("max", max);
- msg.setData(data);
- mHandler.sendMessage(msg);
- }
-
- @Override
- public void setProgress(String message, int progress, int max) {
- Message msg = new Message();
- Bundle data = new Bundle();
- data.putInt("type", MESSAGE_PROGRESS_UPDATE);
- data.putString("message", message);
- data.putInt("progress", progress);
- data.putInt("max", max);
- msg.setData(data);
- mHandler.sendMessage(msg);
- }
-
private void decryptClicked() {
String error = null;
String messageData = mMessage.getText().toString();
@@ -289,8 +150,8 @@ public class DecryptMessageActivity extends Activity
ByteArrayInputStream in =
new ByteArrayInputStream(messageData.getBytes());
try {
- mDecryptionKeyId = Apg.getDecryptionKeyId(in);
- showDialog(AskForSecretKeyPassPhrase.DIALOG_PASS_PHRASE);
+ setSecretKeyId(Apg.getDecryptionKeyId(in));
+ showDialog(Id.dialog.pass_phrase);
} catch (IOException e) {
error = e.getLocalizedMessage();
} catch (Apg.GeneralException e) {
@@ -311,22 +172,23 @@ public class DecryptMessageActivity extends Activity
intent.putExtra("subject", "Re: " + mSubject);
intent.putExtra("sendTo", mReplyTo);
intent.putExtra("eyId", mSignatureKeyId);
- intent.putExtra("signatureKeyId", mDecryptionKeyId);
+ intent.putExtra("signatureKeyId", getSecretKeyId());
intent.putExtra("encryptionKeyIds", new long[] { mSignatureKeyId });
startActivity(intent);
}
+ @Override
public void passPhraseCallback(String passPhrase) {
- Apg.setPassPhrase(passPhrase);
+ super.passPhraseCallback(passPhrase);
decryptStart();
}
private void decryptStart() {
- showDialog(DIALOG_DECRYPTING);
- mRunningThread = new Thread(this);
- mRunningThread.start();
+ showDialog(Id.dialog.decrypting);
+ startThread();
}
+ @Override
public void run() {
String error = null;
Security.addProvider(new BouncyCastleProvider());
@@ -356,7 +218,7 @@ public class DecryptMessageActivity extends Activity
error = e.getMessage();
}
- data.putInt("type", MESSAGE_DONE);
+ data.putInt("type", Id.message.done);
if (error != null) {
data.putString("error", error);
@@ -365,6 +227,61 @@ public class DecryptMessageActivity extends Activity
}
msg.setData(data);
- mHandler.sendMessage(msg);
+ sendMessage(msg);
+ }
+
+ @Override
+ public void doneCallback(Message msg) {
+ super.doneCallback(msg);
+
+ Bundle data = msg.getData();
+ removeDialog(Id.dialog.decrypting);
+ mSignatureKeyId = 0;
+ String error = data.getString("error");
+ String decryptedMessage = data.getString("decryptedMessage");
+ if (error != null) {
+ Toast.makeText(DecryptMessageActivity.this,
+ "Error: " + data.getString("error"),
+ Toast.LENGTH_SHORT).show();
+ }
+ mSignatureLayout.setVisibility(View.INVISIBLE);
+ if (decryptedMessage != null) {
+ mMessage.setText(decryptedMessage);
+ mDecryptButton.setText(R.string.btn_reply);
+ mDecryptButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ replyClicked();
+ }
+ });
+
+ if (data.getBoolean("signature")) {
+ String userId = data.getString("signatureUserId");
+ mSignatureKeyId = data.getLong("signatureKeyId");
+ mUserIdRest.setText("id: " +
+ Long.toHexString(mSignatureKeyId & 0xffffffffL));
+ if (userId == null) {
+ userId =
+ getResources()
+ .getString(
+ R.string.unknown_user_id);
+ }
+ String chunks[] = userId.split(" <", 2);
+ userId = chunks[0];
+ if (chunks.length > 1) {
+ mUserIdRest.setText("<" + chunks[1]);
+ }
+ mUserId.setText(userId);
+
+ if (data.getBoolean("signatureSuccess")) {
+ mSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
+ } else if (data.getBoolean("signatureUnknown")) {
+ mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
+ } else {
+ mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
+ }
+ mSignatureLayout.setVisibility(View.VISIBLE);
+ }
+ }
}
}
diff --git a/src/org/thialfihar/android/apg/EditKeyActivity.java b/src/org/thialfihar/android/apg/EditKeyActivity.java
index b5b7045b7..6f13efabb 100644
--- a/src/org/thialfihar/android/apg/EditKeyActivity.java
+++ b/src/org/thialfihar/android/apg/EditKeyActivity.java
@@ -27,18 +27,16 @@ import org.bouncycastle2.openpgp.PGPSecretKeyRing;
import org.thialfihar.android.apg.ui.widget.SectionView;
import org.thialfihar.android.apg.utils.IterableIterator;
-import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
-import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
-import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@@ -50,17 +48,7 @@ import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
-public class EditKeyActivity extends Activity
- implements OnClickListener, ProgressDialogUpdater, Runnable {
- static final int OPTION_MENU_NEW_PASS_PHRASE = 1;
-
- static final int DIALOG_NEW_PASS_PHRASE = 1;
- static final int DIALOG_PASS_PHRASES_DO_NOT_MATCH = 2;
- static final int DIALOG_NO_PASS_PHRASE = 3;
- static final int DIALOG_SAVING = 4;
-
- static final int MESSAGE_PROGRESS_UPDATE = 1;
- static final int MESSAGE_DONE = 2;
+public class EditKeyActivity extends BaseActivity implements OnClickListener {
private PGPSecretKeyRing mKeyRing = null;
@@ -70,56 +58,8 @@ public class EditKeyActivity extends Activity
private Button mSaveButton;
private Button mDiscardButton;
- private ProgressDialog mProgressDialog = null;
- private Thread mRunningThread = null;
-
private String mNewPassPhrase = null;
- private Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- Bundle data = msg.getData();
- if (data != null) {
- int type = data.getInt("type");
- switch (type) {
- case MESSAGE_PROGRESS_UPDATE: {
- String message = data.getString("message");
- if (mProgressDialog != null) {
- if (message != null) {
- mProgressDialog.setMessage(message);
- }
- mProgressDialog.setMax(data.getInt("max"));
- mProgressDialog.setProgress(data.getInt("progress"));
- }
- break;
- }
-
- case MESSAGE_DONE: {
- removeDialog(DIALOG_SAVING);
- mProgressDialog = null;
-
- String error = data.getString("error");
- if (error != null) {
- Toast.makeText(EditKeyActivity.this,
- "Error: " + data.getString("error"),
- Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(EditKeyActivity.this, R.string.key_saved,
- Toast.LENGTH_SHORT).show();
- setResult(RESULT_OK);
- finish();
- }
- break;
- }
-
- default: {
- break;
- }
- }
- }
- }
- };
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -176,13 +116,14 @@ public class EditKeyActivity extends Activity
}
public boolean havePassPhrase() {
+ Log.e("oink", "password is " + Apg.getPassPhrase());
return (Apg.getPassPhrase() != null && !Apg.getPassPhrase().equals("")) ||
(mNewPassPhrase != null && mNewPassPhrase.equals(""));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(0, OPTION_MENU_NEW_PASS_PHRASE, 0,
+ menu.add(0, Id.menu.option.new_pass_phrase, 0,
(havePassPhrase() ? "Change Pass Phrase" : "Set Pass Phrase"))
.setIcon(android.R.drawable.ic_menu_add);
return true;
@@ -191,8 +132,8 @@ public class EditKeyActivity extends Activity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case OPTION_MENU_NEW_PASS_PHRASE: {
- showDialog(DIALOG_NEW_PASS_PHRASE);
+ case Id.menu.option.new_pass_phrase: {
+ showDialog(Id.dialog.new_pass_phrase);
return true;
}
@@ -206,15 +147,7 @@ public class EditKeyActivity extends Activity
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
- case DIALOG_SAVING: {
- mProgressDialog = new ProgressDialog(this);
- mProgressDialog.setMessage("saving...");
- mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- mProgressDialog.setCancelable(false);
- return mProgressDialog;
- }
-
- case DIALOG_NEW_PASS_PHRASE: {
+ case Id.dialog.new_pass_phrase: {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
if (havePassPhrase()) {
@@ -252,17 +185,17 @@ public class EditKeyActivity extends Activity
alert.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
- removeDialog(DIALOG_NEW_PASS_PHRASE);
+ removeDialog(Id.dialog.new_pass_phrase);
String passPhrase1 = "" + input1.getText();
String passPhrase2 = "" + input2.getText();
if (!passPhrase1.equals(passPhrase2)) {
- showDialog(DIALOG_PASS_PHRASES_DO_NOT_MATCH);
+ showDialog(Id.dialog.pass_phrases_do_not_match);
return;
}
if (passPhrase1.equals("")) {
- showDialog(DIALOG_NO_PASS_PHRASE);
+ showDialog(Id.dialog.no_pass_phrase);
return;
}
@@ -273,49 +206,13 @@ public class EditKeyActivity extends Activity
alert.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
- removeDialog(DIALOG_NEW_PASS_PHRASE);
+ removeDialog(Id.dialog.new_pass_phrase);
}
});
return alert.create();
}
- case DIALOG_PASS_PHRASES_DO_NOT_MATCH: {
- AlertDialog.Builder alert = new AlertDialog.Builder(this);
-
- alert.setIcon(android.R.drawable.ic_dialog_alert);
- alert.setTitle("Error");
- alert.setMessage("The pass phrases didn't match.");
-
- alert.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- removeDialog(DIALOG_PASS_PHRASES_DO_NOT_MATCH);
- }
- });
- alert.setCancelable(false);
-
- return alert.create();
- }
-
- case DIALOG_NO_PASS_PHRASE: {
- AlertDialog.Builder alert = new AlertDialog.Builder(this);
-
- alert.setIcon(android.R.drawable.ic_dialog_alert);
- alert.setTitle("Error");
- alert.setMessage("Empty pass phrases are not supported.");
-
- alert.setPositiveButton(android.R.string.ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- removeDialog(DIALOG_NO_PASS_PHRASE);
- }
- });
- alert.setCancelable(false);
-
- return alert.create();
- }
-
default: {
break;
}
@@ -334,16 +231,15 @@ public class EditKeyActivity extends Activity
}
private void saveClicked() {
- if ((Apg.getPassPhrase() == null || Apg.getPassPhrase().equals("")) &&
- (mNewPassPhrase == null || mNewPassPhrase.equals(""))) {
+ if (!havePassPhrase()) {
Toast.makeText(this, R.string.set_a_pass_phrase, Toast.LENGTH_SHORT).show();
return;
}
- showDialog(DIALOG_SAVING);
- mRunningThread = new Thread(this);
- mRunningThread.start();
+ showDialog(Id.dialog.saving);
+ startThread();
}
+ @Override
public void run() {
String error = null;
Bundle data = new Bundle();
@@ -368,34 +264,32 @@ public class EditKeyActivity extends Activity
error = e.getMessage();
}
- data.putInt("type", MESSAGE_DONE);
+ data.putInt("type", Id.message.done);
if (error != null) {
data.putString("error", error);
}
msg.setData(data);
- mHandler.sendMessage(msg);
+ sendMessage(msg);
}
- public void setProgress(int progress, int max) {
- Message msg = new Message();
- Bundle data = new Bundle();
- data.putInt("type", MESSAGE_PROGRESS_UPDATE);
- data.putInt("progress", progress);
- data.putInt("max", max);
- msg.setData(data);
- mHandler.sendMessage(msg);
- }
+ @Override
+ public void doneCallback(Message msg) {
+ super.doneCallback(msg);
- public void setProgress(String message, int progress, int max) {
- Message msg = new Message();
- Bundle data = new Bundle();
- data.putInt("type", MESSAGE_PROGRESS_UPDATE);
- data.putString("message", message);
- data.putInt("progress", progress);
- data.putInt("max", max);
- msg.setData(data);
- mHandler.sendMessage(msg);
+ Bundle data = msg.getData();
+ removeDialog(Id.dialog.saving);
+
+ String error = data.getString("error");
+ if (error != null) {
+ Toast.makeText(EditKeyActivity.this,
+ "Error: " + data.getString("error"),
+ Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(EditKeyActivity.this, R.string.key_saved, Toast.LENGTH_SHORT).show();
+ setResult(RESULT_OK);
+ finish();
+ }
}
}
\ No newline at end of file
diff --git a/src/org/thialfihar/android/apg/EncryptFileActivity.java b/src/org/thialfihar/android/apg/EncryptFileActivity.java
new file mode 100644
index 000000000..a9b05c687
--- /dev/null
+++ b/src/org/thialfihar/android/apg/EncryptFileActivity.java
@@ -0,0 +1,304 @@
+/*
+ * Copyright (C) 2010 Thialfihar
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.thialfihar.android.apg;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SignatureException;
+import java.util.Collections;
+import java.util.Vector;
+
+import org.bouncycastle2.bcpg.HashAlgorithmTags;
+import org.bouncycastle2.openpgp.PGPException;
+import org.bouncycastle2.openpgp.PGPPublicKeyRing;
+import org.bouncycastle2.openpgp.PGPSecretKey;
+import org.bouncycastle2.openpgp.PGPSecretKeyRing;
+import org.openintents.intents.FileManager;
+
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Message;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.ImageButton;
+import android.widget.ListView;
+import android.widget.TabHost;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.TabHost.TabSpec;
+
+public class EncryptFileActivity extends BaseActivity {
+
+ private EditText mFilename = null;
+ private ImageButton mBrowse = null;
+ private CheckBox mSign = null;
+ private TextView mMainUserId = null;
+ private TextView mMainUserIdRest = null;
+ private ListView mList;
+ private Button mEncryptButton = null;
+
+ private long mEncryptionKeyIds[] = null;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.encrypt_file);
+
+ TabHost tabHost = (TabHost) findViewById(R.id.tab_host);
+ tabHost.setup();
+
+ TabSpec ts1 = tabHost.newTabSpec("TAB_ASYMMETRIC");
+ ts1.setIndicator(getString(R.string.tab_asymmetric),
+ getResources().getDrawable(R.drawable.key));
+ ts1.setContent(R.id.tab_asymmetric);
+ tabHost.addTab(ts1);
+
+ TabSpec ts2 = tabHost.newTabSpec("TAB_SYMMETRIC");
+ ts2.setIndicator(getString(R.string.tab_symmetric),
+ getResources().getDrawable(R.drawable.encrypted));
+ ts2.setContent(R.id.tab_symmetric);
+ tabHost.addTab(ts2);
+
+ tabHost.setCurrentTab(0);
+
+ Vector keyRings =
+ (Vector) Apg.getPublicKeyRings().clone();
+ Collections.sort(keyRings, new Apg.PublicKeySorter());
+ mList = (ListView) findViewById(R.id.public_key_list);
+ mList.setAdapter(new SelectPublicKeyListAdapter(mList, keyRings));
+
+ mFilename = (EditText) findViewById(R.id.filename);
+ mBrowse = (ImageButton) findViewById(R.id.btn_browse);
+ mBrowse.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ openFile();
+ }
+ });
+
+ mEncryptButton = (Button) findViewById(R.id.btn_encrypt);
+ mSign = (CheckBox) findViewById(R.id.sign);
+ mMainUserId = (TextView) findViewById(R.id.main_user_id);
+ mMainUserIdRest = (TextView) findViewById(R.id.main_user_id_rest);
+
+ mSign.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ CheckBox checkBox = (CheckBox) v;
+ if (checkBox.isChecked()) {
+ selectSecretKey();
+ } else {
+ setSecretKeyId(0);
+ Apg.setPassPhrase(null);
+ updateView();
+ }
+ }
+ });
+
+ mEncryptButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ encryptClicked();
+ }
+ });
+
+ updateView();
+ }
+
+ private void updateView() {
+ if (getSecretKeyId() == 0) {
+ mSign.setText(R.string.sign);
+ mSign.setChecked(false);
+ mMainUserId.setText("");
+ mMainUserIdRest.setText("");
+ } else {
+ String uid = getResources().getString(R.string.unknown_user_id);
+ String uidExtra = "";
+ PGPSecretKeyRing keyRing = Apg.getSecretKeyRing(getSecretKeyId());
+ if (keyRing != null) {
+ PGPSecretKey key = Apg.getMasterKey(keyRing);
+ if (key != null) {
+ String userId = Apg.getMainUserIdSafe(this, key);
+ String chunks[] = userId.split(" <", 2);
+ uid = chunks[0];
+ if (chunks.length > 1) {
+ uidExtra = "<" + chunks[1];
+ }
+ }
+ }
+ mMainUserId.setText(uid);
+ mMainUserIdRest.setText(uidExtra);
+ mSign.setText(R.string.sign_as);
+ mSign.setChecked(true);
+ }
+ }
+
+ private void openFile() {
+ String filename = mFilename.getText().toString();
+
+ Intent intent = new Intent(FileManager.ACTION_PICK_FILE);
+
+ intent.setData(Uri.parse("file://" + filename));
+
+ intent.putExtra(FileManager.EXTRA_TITLE, "Select file to encrypt...");
+ intent.putExtra(FileManager.EXTRA_BUTTON_TEXT, "Open");
+
+ try {
+ startActivityForResult(intent, Id.request.filename);
+ } catch (ActivityNotFoundException e) {
+ // No compatible file manager was found.
+ Toast.makeText(this, R.string.no_filemanager_installed, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ private void selectSecretKey() {
+ Intent intent = new Intent(this, SelectSecretKeyListActivity.class);
+ startActivityForResult(intent, Id.request.secret_keys);
+ }
+
+ private void encryptClicked() {
+ if (getSecretKeyId() != 0 && Apg.getPassPhrase() == null) {
+ showDialog(Id.dialog.pass_phrase);
+ } else {
+ encryptStart();
+ }
+ }
+
+ @Override
+ public void passPhraseCallback(String passPhrase) {
+ super.passPhraseCallback(passPhrase);
+ encryptStart();
+ }
+
+ private void encryptStart() {
+ showDialog(Id.dialog.encrypting);
+ startThread();
+ }
+
+ @Override
+ public void run() {
+ String error = null;
+ Bundle data = new Bundle();
+ Message msg = new Message();
+
+ try {
+ InputStream in = new FileInputStream(mFilename.getText().toString());
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ if (mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0) {
+ Apg.encrypt(in, out, true, mEncryptionKeyIds, getSecretKeyId(),
+ Apg.getPassPhrase(), this);
+ data.putString("message", new String(out.toByteArray()));
+ } else {
+ Apg.signText(in, out, getSecretKeyId(),
+ Apg.getPassPhrase(), HashAlgorithmTags.SHA256, this);
+ data.putString("message", new String(out.toByteArray()));
+ }
+ } catch (IOException e) {
+ error = e.getMessage();
+ } catch (PGPException e) {
+ error = e.getMessage();
+ } catch (NoSuchProviderException e) {
+ error = e.getMessage();
+ } catch (NoSuchAlgorithmException e) {
+ error = e.getMessage();
+ } catch (SignatureException e) {
+ error = e.getMessage();
+ } catch (Apg.GeneralException e) {
+ error = e.getMessage();
+ }
+
+ data.putInt("type", Id.message.done);
+
+ if (error != null) {
+ data.putString("error", error);
+ }
+
+ msg.setData(data);
+ sendMessage(msg);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case Id.request.filename: {
+ 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);
+
+ mFilename.setText(filename);
+ }
+ }
+ return;
+ }
+
+ case Id.request.secret_keys: {
+ if (resultCode == RESULT_OK) {
+ Bundle bundle = data.getExtras();
+ long newId = bundle.getLong("selectedKeyId");
+ if (getSecretKeyId() != newId) {
+ Apg.setPassPhrase(null);
+ }
+ setSecretKeyId(newId);
+ } else {
+ setSecretKeyId(0);
+ Apg.setPassPhrase(null);
+ }
+ updateView();
+ break;
+ }
+
+ default: {
+ break;
+ }
+ }
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ @Override
+ public void doneCallback(Message msg) {
+ super.doneCallback(msg);
+ Bundle data = msg.getData();
+ removeDialog(Id.dialog.encrypting);
+
+ String error = data.getString("error");
+ if (error != null) {
+ Toast.makeText(EncryptFileActivity.this,
+ "Error: " + data.getString("error"),
+ Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(EncryptFileActivity.this,
+ "Successfully encrypted.",
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+}
diff --git a/src/org/thialfihar/android/apg/EncryptMessageActivity.java b/src/org/thialfihar/android/apg/EncryptMessageActivity.java
index b954f31a1..d89e62bd0 100644
--- a/src/org/thialfihar/android/apg/EncryptMessageActivity.java
+++ b/src/org/thialfihar/android/apg/EncryptMessageActivity.java
@@ -32,12 +32,8 @@ import org.bouncycastle2.openpgp.PGPSecretKey;
import org.bouncycastle2.openpgp.PGPSecretKeyRing;
import org.bouncycastle2.util.Strings;
-import android.app.Activity;
-import android.app.Dialog;
-import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
-import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
@@ -47,25 +43,11 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
-public class EncryptMessageActivity extends Activity
- implements Runnable, ProgressDialogUpdater,
- AskForSecretKeyPassPhrase.PassPhraseCallbackInterface {
- static final int GET_PUCLIC_KEYS = 1;
- static final int GET_SECRET_KEY = 2;
-
- static final int DIALOG_ENCRYPTING = 1;
-
- static final int MESSAGE_PROGRESS_UPDATE = 1;
- static final int MESSAGE_DONE = 2;
-
+public class EncryptMessageActivity extends BaseActivity {
private String mSubject = null;
private String mSendTo = null;
private long mEncryptionKeyIds[] = null;
- private long mSignatureKeyId = 0;
-
- private ProgressDialog mProgressDialog = null;
- private Thread mRunningThread = null;
private EditText mMessage = null;
private Button mSelectKeysButton = null;
@@ -74,92 +56,11 @@ public class EncryptMessageActivity extends Activity
private TextView mMainUserId = null;
private TextView mMainUserIdRest = null;
- private Handler mhandler = new Handler() {
- @Override
- public void handleMessage(Message mSg) {
- Bundle data = mSg.getData();
- if (data != null) {
- int type = data.getInt("type");
- switch (type) {
- case MESSAGE_PROGRESS_UPDATE: {
- String message = data.getString("message");
- if (mProgressDialog != null) {
- if (message != null) {
- mProgressDialog.setMessage(message);
- }
- mProgressDialog.setMax(data.getInt("max"));
- mProgressDialog.setProgress(data.getInt("progress"));
- }
- break;
- }
-
- case MESSAGE_DONE: {
- removeDialog(DIALOG_ENCRYPTING);
- mProgressDialog = null;
-
- String error = data.getString("error");
- if (error != null) {
- Toast.makeText(EncryptMessageActivity.this,
- "Error: " + data.getString("error"),
- Toast.LENGTH_SHORT).show();
- return;
- } else {
- String message = data.getString("message");
- Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
- emailIntent.setType("text/plain; charset=utf-8");
- emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
- if (mSubject != null) {
- emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
- mSubject);
- }
- if (mSendTo != null) {
- emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
- new String[] { mSendTo });
- }
- EncryptMessageActivity.this.
- startActivity(Intent.createChooser(emailIntent, "Send mail..."));
- }
- break;
- }
-
- default: {
- break;
- }
- }
- }
- }
- };
-
- @Override
- public void setProgress(int progress, int max) {
- Message msg = new Message();
- Bundle data = new Bundle();
- data.putInt("type", MESSAGE_PROGRESS_UPDATE);
- data.putInt("progress", progress);
- data.putInt("max", max);
- msg.setData(data);
- mhandler.sendMessage(msg);
- }
-
- @Override
- public void setProgress(String message, int progress, int max) {
- Message msg = new Message();
- Bundle data = new Bundle();
- data.putInt("type", MESSAGE_PROGRESS_UPDATE);
- data.putString("message", message);
- data.putInt("progress", progress);
- data.putInt("max", max);
- msg.setData(data);
- mhandler.sendMessage(msg);
- }
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.encrypt_message);
- Apg.initialize(this);
-
mMessage = (EditText) findViewById(R.id.message);
mSelectKeysButton = (Button) findViewById(R.id.btn_selectEncryptKeys);
mSendButton = (Button) findViewById(R.id.btn_send);
@@ -183,7 +84,7 @@ public class EncryptMessageActivity extends Activity
if (masterKey != null) {
Vector signKeys = Apg.getUsableSigningKeys(keyRing);
if (signKeys.size() > 0) {
- mSignatureKeyId = masterKey.getKeyID();
+ setSecretKeyId(masterKey.getKeyID());
}
}
}
@@ -240,7 +141,7 @@ public class EncryptMessageActivity extends Activity
if (checkBox.isChecked()) {
selectSecretKey();
} else {
- mSignatureKeyId = 0;
+ setSecretKeyId(0);
Apg.setPassPhrase(null);
updateView();
}
@@ -250,69 +151,56 @@ public class EncryptMessageActivity extends Activity
updateView();
}
- @Override
- protected Dialog onCreateDialog(int id) {
- switch (id) {
- case DIALOG_ENCRYPTING: {
- mProgressDialog = new ProgressDialog(this);
- mProgressDialog.setMessage("initializing...");
- mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- mProgressDialog.setCancelable(false);
- return mProgressDialog;
- }
-
- case AskForSecretKeyPassPhrase.DIALOG_PASS_PHRASE: {
- return AskForSecretKeyPassPhrase.createDialog(this, mSignatureKeyId, this);
- }
- }
-
- return super.onCreateDialog(id);
- }
-
private void sendClicked() {
- if (mSignatureKeyId != 0 && Apg.getPassPhrase() == null) {
- showDialog(AskForSecretKeyPassPhrase.DIALOG_PASS_PHRASE);
+ if (getSecretKeyId() != 0 && Apg.getPassPhrase() == null) {
+ showDialog(Id.dialog.pass_phrase);
} else {
encryptStart();
}
}
+ @Override
public void passPhraseCallback(String passPhrase) {
- Apg.setPassPhrase(passPhrase);
+ super.passPhraseCallback(passPhrase);
encryptStart();
}
private void encryptStart() {
- showDialog(DIALOG_ENCRYPTING);
- mRunningThread = new Thread(this);
- mRunningThread.start();
+ showDialog(Id.dialog.encrypting);
+ startThread();
}
+ @Override
public void run() {
String error = null;
Bundle data = new Bundle();
Message msg = new Message();
- String message = mMessage.getText().toString();
- // fix the message a bit, trailing spaces and newlines break stuff,
- // because GMail sends as HTML and such things fuck up the signature,
- // TODO: things like "<" and ">" also fuck up the signature
- message = message.replaceAll(" +\n", "\n");
- message = message.replaceAll("\n\n+", "\n\n");
- message = message.replaceFirst("^\n+", "");
- // make sure there'll be exactly one newline at the end
- message = message.replaceFirst("\n*$", "\n");
-
- ByteArrayInputStream in =
- new ByteArrayInputStream(Strings.toUTF8ByteArray(message));
- ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
- if (mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0) {
- Apg.encrypt(in, out, true, mEncryptionKeyIds, mSignatureKeyId,
+ boolean encryptIt = mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0;
+
+ String message = mMessage.getText().toString();
+ if (!encryptIt) {
+ // fix the message a bit, trailing spaces and newlines break stuff,
+ // because GMail sends as HTML and such things fuck up the signature,
+ // TODO: things like "<" and ">" also fuck up the signature
+ message = message.replaceAll(" +\n", "\n");
+ message = message.replaceAll("\n\n+", "\n\n");
+ message = message.replaceFirst("^\n+", "");
+ // make sure there'll be exactly one newline at the end
+ message = message.replaceFirst("\n*$", "\n");
+ }
+
+ ByteArrayInputStream in =
+ new ByteArrayInputStream(Strings.toUTF8ByteArray(message));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ if (encryptIt) {
+ Apg.encrypt(in, out, true, mEncryptionKeyIds, getSecretKeyId(),
Apg.getPassPhrase(), this);
data.putString("message", new String(out.toByteArray()));
} else {
- Apg.signText(in, out, mSignatureKeyId,
+ Apg.signText(in, out, getSecretKeyId(),
Apg.getPassPhrase(), HashAlgorithmTags.SHA256, this);
data.putString("message", new String(out.toByteArray()));
}
@@ -330,14 +218,14 @@ public class EncryptMessageActivity extends Activity
error = e.getMessage();
}
- data.putInt("type", MESSAGE_DONE);
+ data.putInt("type", Id.message.done);
if (error != null) {
data.putString("error", error);
}
msg.setData(data);
- mhandler.sendMessage(msg);
+ sendMessage(msg);
}
private void updateView() {
@@ -350,7 +238,7 @@ public class EncryptMessageActivity extends Activity
getResources().getString(R.string.n_keys_selected));
}
- if (mSignatureKeyId == 0) {
+ if (getSecretKeyId() == 0) {
mSign.setText(R.string.sign);
mSign.setChecked(false);
mMainUserId.setText("");
@@ -358,7 +246,7 @@ public class EncryptMessageActivity extends Activity
} else {
String uid = getResources().getString(R.string.unknown_user_id);
String uidExtra = "";
- PGPSecretKeyRing keyRing = Apg.getSecretKeyRing(mSignatureKeyId);
+ PGPSecretKeyRing keyRing = Apg.getSecretKeyRing(getSecretKeyId());
if (keyRing != null) {
PGPSecretKey key = Apg.getMasterKey(keyRing);
if (key != null) {
@@ -380,18 +268,18 @@ public class EncryptMessageActivity extends Activity
private void selectPublicKeys() {
Intent intent = new Intent(this, SelectPublicKeyListActivity.class);
intent.putExtra("selection", mEncryptionKeyIds);
- startActivityForResult(intent, GET_PUCLIC_KEYS);
+ startActivityForResult(intent, Id.request.public_keys);
}
private void selectSecretKey() {
Intent intent = new Intent(this, SelectSecretKeyListActivity.class);
- startActivityForResult(intent, GET_SECRET_KEY);
+ startActivityForResult(intent, Id.request.secret_keys);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
- case GET_PUCLIC_KEYS: {
+ case Id.request.public_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
mEncryptionKeyIds = bundle.getLongArray("selection");
@@ -400,26 +288,58 @@ public class EncryptMessageActivity extends Activity
break;
}
- case GET_SECRET_KEY: {
+ case Id.request.secret_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
long newId = bundle.getLong("selectedKeyId");
- if (mSignatureKeyId != newId) {
+ if (getSecretKeyId() != newId) {
Apg.setPassPhrase(null);
}
- mSignatureKeyId = newId;
+ setSecretKeyId(newId);
} else {
- mSignatureKeyId = 0;
+ setSecretKeyId(0);
Apg.setPassPhrase(null);
}
updateView();
break;
}
- default:
+ default: {
break;
+ }
}
super.onActivityResult(requestCode, resultCode, data);
}
+
+ @Override
+ public void doneCallback(Message msg) {
+ super.doneCallback(msg);
+
+ removeDialog(Id.dialog.encrypting);
+
+ Bundle data = msg.getData();
+ String error = data.getString("error");
+ if (error != null) {
+ Toast.makeText(EncryptMessageActivity.this,
+ "Error: " + data.getString("error"),
+ Toast.LENGTH_SHORT).show();
+ return;
+ } else {
+ String message = data.getString("message");
+ Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
+ emailIntent.setType("text/plain; charset=utf-8");
+ emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
+ if (mSubject != null) {
+ emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
+ mSubject);
+ }
+ if (mSendTo != null) {
+ emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
+ new String[] { mSendTo });
+ }
+ EncryptMessageActivity.this.
+ startActivity(Intent.createChooser(emailIntent, "Send mail..."));
+ }
+ }
}
\ No newline at end of file
diff --git a/src/org/thialfihar/android/apg/FileDialog.java b/src/org/thialfihar/android/apg/FileDialog.java
index c2e7ec4b3..653ca1005 100644
--- a/src/org/thialfihar/android/apg/FileDialog.java
+++ b/src/org/thialfihar/android/apg/FileDialog.java
@@ -32,8 +32,7 @@ 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 EditText mFilename;
private static ImageButton mBrowse;
private static Activity mActivity;
private static String mFileManagerTitle;
@@ -57,8 +56,8 @@ public class FileDialog {
View view = (View) inflater.inflate(R.layout.file_dialog, null);
mActivity = activity;
- mInput = (EditText) view.findViewById(R.id.input);
- mInput.setText(defaultFile);
+ mFilename = (EditText) view.findViewById(R.id.input);
+ mFilename.setText(defaultFile);
mBrowse = (ImageButton) view.findViewById(R.id.btn_browse);
mBrowse.setOnClickListener(new View.OnClickListener() {
@Override
@@ -75,7 +74,7 @@ public class FileDialog {
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
- clickListener.onOkClick(mInput.getText().toString());
+ clickListener.onOkClick(mFilename.getText().toString());
}
});
@@ -89,8 +88,8 @@ public class FileDialog {
}
public static void setFilename(String filename) {
- if (mInput != null) {
- mInput.setText(filename);
+ if (mFilename != null) {
+ mFilename.setText(filename);
}
}
@@ -98,17 +97,17 @@ public class FileDialog {
* Opens the file manager to select a file to open.
*/
private static void openFile() {
- String fileName = mInput.getText().toString();
+ String filename = mFilename.getText().toString();
Intent intent = new Intent(FileManager.ACTION_PICK_FILE);
- intent.setData(Uri.parse("file://" + fileName));
+ 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);
+ mActivity.startActivityForResult(intent, Id.request.filename);
} 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/Id.java b/src/org/thialfihar/android/apg/Id.java
new file mode 100644
index 000000000..7a57b706d
--- /dev/null
+++ b/src/org/thialfihar/android/apg/Id.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2010 Thialfihar
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.thialfihar.android.apg;
+
+public final class Id {
+ public static final class menu {
+ public static final int export = 0x21070001;
+ public static final int delete = 0x21070002;
+ public static final int edit = 0x21070003;
+
+ public static final class option {
+ public static final int new_pass_phrase = 0x21070001;
+ public static final int create = 0x21070002;
+ public static final int about = 0x21070003;
+ public static final int manage_public_keys = 0x21070004;
+ public static final int manage_secret_keys = 0x21070005;
+ public static final int import_keys = 0x21070006;
+ public static final int export_keys = 0x21070007;
+ }
+ }
+
+ public static final class message {
+ public static final int progress_update = 0x21070001;
+ public static final int done = 0x21070002;
+ public static final int import_keys = 0x21070003;
+ public static final int export_keys = 0x21070004;
+ public static final int import_done = 0x21070005;
+ public static final int export_done = 0x21070006;
+ public static final int create_key = 0x21070007;
+ public static final int edit_key = 0x21070008;
+ }
+
+ public static final class request {
+ public static final int public_keys = 0x21070001;
+ public static final int secret_keys = 0x21070002;
+ public static final int filename = 0x21070003;
+ }
+
+ public static final class dialog {
+ public static final int pass_phrase = 0x21070001;
+ public static final int encrypting = 0x21070002;
+ public static final int decrypting = 0x21070003;
+ public static final int new_pass_phrase = 0x21070004;
+ public static final int pass_phrases_do_not_match = 0x21070005;
+ public static final int no_pass_phrase = 0x21070006;
+ public static final int saving = 0x21070007;
+ public static final int delete_key = 0x21070008;
+ public static final int import_keys = 0x21070009;
+ public static final int importing = 0x2107000a;
+ public static final int export_key = 0x2107000b;
+ public static final int export_keys = 0x2107000c;
+ public static final int exporting = 0x2107000d;
+ public static final int new_account = 0x2107000e;
+ public static final int about = 0x2107000f;
+ public static final int change_log = 0x21070010;
+ }
+
+ public static final class task {
+ public static final int import_keys = 0x21070001;
+ public static final int export_keys = 0x21070002;
+ }
+
+ public static final class type {
+ public static final int public_key = 0x21070001;
+ public static final int secret_key = 0x21070002;
+ }
+}
+
diff --git a/src/org/thialfihar/android/apg/MailListActivity.java b/src/org/thialfihar/android/apg/MailListActivity.java
index ed207d4cd..c0bed5985 100644
--- a/src/org/thialfihar/android/apg/MailListActivity.java
+++ b/src/org/thialfihar/android/apg/MailListActivity.java
@@ -37,7 +37,7 @@ import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class MailListActivity extends ListActivity {
- LayoutInflater minflater = null;
+ LayoutInflater mInflater = null;
private static class Conversation {
public long id;
@@ -82,7 +82,7 @@ public class MailListActivity extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- minflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mconversations = new Vector();
mmessages = new Vector();
@@ -191,7 +191,7 @@ public class MailListActivity extends ListActivity {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- View view = minflater.inflate(R.layout.mailbox_message_item, null);
+ View view = mInflater.inflate(R.layout.mailbox_message_item, null);
Message message = (Message) getItem(position);
diff --git a/src/org/thialfihar/android/apg/MainActivity.java b/src/org/thialfihar/android/apg/MainActivity.java
index 1c0361dec..8cd9df6bf 100644
--- a/src/org/thialfihar/android/apg/MainActivity.java
+++ b/src/org/thialfihar/android/apg/MainActivity.java
@@ -51,17 +51,7 @@ import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
-public class MainActivity extends Activity {
- private static final int DIALOG_NEW_ACCOUNT = 1;
- private static final int DIALOG_ABOUT = 2;
- private static final int DIALOG_CHANGE_LOG = 3;
-
- private static final int OPTION_MENU_ADD_ACCOUNT = 1;
- private static final int OPTION_MENU_ABOUT = 2;
- private static final int OPTION_MENU_MANAGE_PUBLIC_KEYS = 3;
- private static final int OPTION_MENU_MANAGE_SECRET_KEYS = 4;
-
- private static final int MENU_DELETE_ACCOUNT = 1;
+public class MainActivity extends BaseActivity {
private static String PREF_SEEN_CHANGE_LOG = "seenChangeLogDialog" + Apg.VERSION;
@@ -72,10 +62,10 @@ 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);
+ Button encryptFileButton = (Button) findViewById(R.id.btn_encryptFile);
+ Button decryptFileButton = (Button) findViewById(R.id.btn_decryptFile);
mAccounts = (ListView) findViewById(R.id.account_list);
encryptMessageButton.setOnClickListener(new OnClickListener() {
@@ -92,6 +82,20 @@ public class MainActivity extends Activity {
}
});
+ encryptFileButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startEncryptFileActivity();
+ }
+ });
+
+ decryptFileButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startDecryptFileActivity();
+ }
+ });
+
Cursor accountCursor = managedQuery(Accounts.CONTENT_URI, null, null, null, null);
mAccounts.setAdapter(new AccountListAdapter(this, accountCursor));
@@ -113,14 +117,14 @@ public class MainActivity extends Activity {
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
if (!prefs.getBoolean(PREF_SEEN_CHANGE_LOG, false)) {
- showDialog(DIALOG_CHANGE_LOG);
+ showDialog(Id.dialog.change_log);
}
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
- case DIALOG_NEW_ACCOUNT: {
+ case Id.dialog.new_account: {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Add Account");
@@ -132,7 +136,7 @@ public class MainActivity extends Activity {
alert.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
- MainActivity.this.removeDialog(DIALOG_NEW_ACCOUNT);
+ MainActivity.this.removeDialog(Id.dialog.new_account);
String accountName = "" + input.getText();
Cursor testCursor =
@@ -165,14 +169,14 @@ public class MainActivity extends Activity {
alert.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
- MainActivity.this.removeDialog(DIALOG_NEW_ACCOUNT);
+ MainActivity.this.removeDialog(Id.dialog.new_account);
}
});
return alert.create();
}
- case DIALOG_ABOUT: {
+ case Id.dialog.about: {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("About " + Apg.FULL_VERSION);
@@ -205,14 +209,14 @@ public class MainActivity extends Activity {
alert.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
- MainActivity.this.removeDialog(DIALOG_ABOUT);
+ MainActivity.this.removeDialog(Id.dialog.about);
}
});
return alert.create();
}
- case DIALOG_CHANGE_LOG: {
+ case Id.dialog.change_log: {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Changes " + Apg.FULL_VERSION);
@@ -246,7 +250,7 @@ public class MainActivity extends Activity {
alert.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
- MainActivity.this.removeDialog(DIALOG_CHANGE_LOG);
+ MainActivity.this.removeDialog(Id.dialog.change_log);
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PREF_SEEN_CHANGE_LOG, true);
@@ -261,18 +265,19 @@ public class MainActivity extends Activity {
break;
}
}
+
return super.onCreateDialog(id);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(0, OPTION_MENU_MANAGE_PUBLIC_KEYS, 0, 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(0, OPTION_MENU_MANAGE_SECRET_KEYS, 1, 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, OPTION_MENU_ADD_ACCOUNT, 2, R.string.menu_addAccount)
+ menu.add(1, Id.menu.option.create, 2, R.string.menu_addAccount)
.setIcon(android.R.drawable.ic_menu_add);
- menu.add(1, OPTION_MENU_ABOUT, 3, R.string.menu_about)
+ menu.add(1, Id.menu.option.about, 3, R.string.menu_about)
.setIcon(android.R.drawable.ic_menu_info_details);
return true;
}
@@ -280,22 +285,22 @@ public class MainActivity extends Activity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case OPTION_MENU_ADD_ACCOUNT: {
- showDialog(DIALOG_NEW_ACCOUNT);
+ case Id.menu.option.create: {
+ showDialog(Id.dialog.new_account);
return true;
}
- case OPTION_MENU_ABOUT: {
- showDialog(DIALOG_ABOUT);
+ case Id.menu.option.about: {
+ showDialog(Id.dialog.about);
return true;
}
- case OPTION_MENU_MANAGE_PUBLIC_KEYS: {
+ case Id.menu.option.manage_public_keys: {
startPublicKeyManager();
return true;
}
- case OPTION_MENU_MANAGE_SECRET_KEYS: {
+ case Id.menu.option.manage_secret_keys: {
startSecretKeyManager();
return true;
}
@@ -314,7 +319,7 @@ public class MainActivity extends Activity {
TextView nameTextView = (TextView) v.findViewById(R.id.account_name);
if (nameTextView != null) {
menu.setHeaderTitle(nameTextView.getText());
- menu.add(0, MENU_DELETE_ACCOUNT, 0, "Delete Account");
+ menu.add(0, Id.menu.delete, 0, "Delete Account");
}
}
@@ -324,7 +329,7 @@ public class MainActivity extends Activity {
(AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
switch (menuItem.getItemId()) {
- case MENU_DELETE_ACCOUNT: {
+ case Id.menu.delete: {
Uri uri = Uri.withAppendedPath(Accounts.CONTENT_URI, "" + info.id);
this.getContentResolver().delete(uri, null, null);
return true;
@@ -342,7 +347,6 @@ public class MainActivity extends Activity {
public void startSecretKeyManager() {
startActivity(new Intent(this, SecretKeyListActivity.class));
- //startActivity(new Intent(this, EditKeyActivity.class));
}
public void startEncryptMessageActivity() {
@@ -353,6 +357,14 @@ public class MainActivity extends Activity {
startActivity(new Intent(this, DecryptMessageActivity.class));
}
+ public void startEncryptFileActivity() {
+ startActivity(new Intent(this, EncryptFileActivity.class));
+ }
+
+ public void startDecryptFileActivity() {
+ //startActivity(new Intent(this, DecryptFileActivity.class));
+ }
+
public void startMailListActivity(String account) {
startActivity(new Intent(this, MailListActivity.class).putExtra("account", account));
}
diff --git a/src/org/thialfihar/android/apg/PublicKeyListActivity.java b/src/org/thialfihar/android/apg/PublicKeyListActivity.java
index 1e4dc081d..d6a2aa577 100644
--- a/src/org/thialfihar/android/apg/PublicKeyListActivity.java
+++ b/src/org/thialfihar/android/apg/PublicKeyListActivity.java
@@ -27,17 +27,13 @@ import org.thialfihar.android.apg.utils.IterableIterator;
import android.app.AlertDialog;
import android.app.Dialog;
-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;
@@ -52,155 +48,30 @@ import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
-public class PublicKeyListActivity extends ExpandableListActivity
- implements Runnable, ProgressDialogUpdater {
- static final int MENU_DELETE = 1;
- static final int MENU_EXPORT = 2;
-
- static final int OPTION_MENU_IMPORT_KEYS = 1;
- static final int OPTION_MENU_EXPORT_KEYS = 2;
-
- static final int MESSAGE_PROGRESS_UPDATE = 1;
- static final int MESSAGE_IMPORT_DONE = 2;
- static final int MESSAGE_EXPORT_DONE = 3;
-
- static final int DIALOG_DELETE_KEY = 1;
- static final int DIALOG_IMPORT_KEYS = 2;
- static final int DIALOG_IMPORTING = 3;
- static final int DIALOG_EXPORT_KEYS = 4;
- static final int DIALOG_EXPORTING = 5;
- static final int DIALOG_EXPORT_KEY = 6;
-
- static final int TASK_IMPORT = 1;
- static final int TASK_EXPORT = 2;
+public class PublicKeyListActivity extends BaseActivity {
+ ExpandableListView mList;
protected int mSelectedItem = -1;
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) {
- Bundle data = msg.getData();
- if (data != null) {
- int type = data.getInt("type");
- switch (type) {
- case MESSAGE_PROGRESS_UPDATE: {
- String message = data.getString("message");
- if (mProgressDialog != null) {
- if (message != null) {
- mProgressDialog.setMessage(message);
- }
- mProgressDialog.setMax(data.getInt("max"));
- mProgressDialog.setProgress(data.getInt("progress"));
- }
- break;
- }
-
- case MESSAGE_IMPORT_DONE: {
- removeDialog(DIALOG_IMPORTING);
- mProgressDialog = null;
-
- String error = data.getString("error");
- if (error != null) {
- Toast.makeText(PublicKeyListActivity.this,
- "Error: " + data.getString("error"),
- Toast.LENGTH_SHORT).show();
- } else {
- int added = data.getInt("added");
- int updated = data.getInt("updated");
- String message;
- if (added > 0 && updated > 0) {
- message = "Succssfully added " + added + " keys and updated " +
- updated + " keys.";
- } else if (added > 0) {
- message = "Succssfully added " + added + " keys.";
- } else if (updated > 0) {
- message = "Succssfully updated " + updated + " keys.";
- } else {
- message = "No keys added or updated.";
- }
- Toast.makeText(PublicKeyListActivity.this, message,
- Toast.LENGTH_SHORT).show();
- }
- refreshList();
- break;
- }
-
- case MESSAGE_EXPORT_DONE: {
- removeDialog(DIALOG_EXPORTING);
- mProgressDialog = null;
-
- String error = data.getString("error");
- if (error != null) {
- Toast.makeText(PublicKeyListActivity.this,
- "Error: " + data.getString("error"),
- Toast.LENGTH_SHORT).show();
- } else {
- int exported = data.getInt("exported");
- String message;
- if (exported == 1) {
- message = "Succssfully exported 1 key.";
- } else if (exported > 0) {
- message = "Succssfully exported " + exported + " keys.";
- } else{
- message = "No keys exported.";
- }
- Toast.makeText(PublicKeyListActivity.this, message,
- Toast.LENGTH_SHORT).show();
- }
- break;
- }
-
- default: {
- break;
- }
- }
- }
- }
- };
-
- public void setProgress(int progress, int max) {
- Message msg = new Message();
- Bundle data = new Bundle();
- data.putInt("type", MESSAGE_PROGRESS_UPDATE);
- data.putInt("progress", progress);
- data.putInt("max", max);
- msg.setData(data);
- mHandler.sendMessage(msg);
- }
-
- public void setProgress(String message, int progress, int max) {
- Message msg = new Message();
- Bundle data = new Bundle();
- data.putInt("type", MESSAGE_PROGRESS_UPDATE);
- data.putString("message", message);
- data.putInt("progress", progress);
- data.putInt("max", max);
- msg.setData(data);
- mHandler.sendMessage(msg);
- }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setContentView(R.layout.key_list);
- Apg.initialize(this);
-
- setListAdapter(new PublicKeyListAdapter(this));
- registerForContextMenu(getExpandableListView());
+ mList = (ExpandableListView) findViewById(R.id.list);
+ mList.setAdapter(new PublicKeyListAdapter(this));
+ registerForContextMenu(mList);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(0, OPTION_MENU_IMPORT_KEYS, 0, "Import Keys")
+ menu.add(0, Id.menu.option.import_keys, 0, "Import Keys")
.setIcon(android.R.drawable.ic_menu_add);
- menu.add(0, OPTION_MENU_EXPORT_KEYS, 1, "Export Keys")
+ menu.add(0, Id.menu.option.export_keys, 1, "Export Keys")
.setIcon(android.R.drawable.ic_menu_save);
return true;
}
@@ -208,13 +79,13 @@ public class PublicKeyListActivity extends ExpandableListActivity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case OPTION_MENU_IMPORT_KEYS: {
- showDialog(DIALOG_IMPORT_KEYS);
+ case Id.menu.option.import_keys: {
+ showDialog(Id.dialog.import_keys);
return true;
}
- case OPTION_MENU_EXPORT_KEYS: {
- showDialog(DIALOG_EXPORT_KEYS);
+ case Id.menu.option.export_keys: {
+ showDialog(Id.dialog.export_keys);
return true;
}
@@ -237,8 +108,8 @@ public class PublicKeyListActivity extends ExpandableListActivity
PGPPublicKeyRing keyRing = Apg.getPublicKeyRings().get(groupPosition);
String userId = Apg.getMainUserIdSafe(this, Apg.getMasterKey(keyRing));
menu.setHeaderTitle(userId);
- menu.add(0, MENU_EXPORT, 0, "Export Key");
- menu.add(0, MENU_DELETE, 1, "Delete Key");
+ menu.add(0, Id.menu.export, 0, "Export Key");
+ menu.add(0, Id.menu.delete, 1, "Delete Key");
}
}
@@ -253,15 +124,15 @@ public class PublicKeyListActivity extends ExpandableListActivity
}
switch (menuItem.getItemId()) {
- case MENU_EXPORT: {
+ case Id.menu.export: {
mSelectedItem = groupPosition;
- showDialog(DIALOG_EXPORT_KEY);
+ showDialog(Id.dialog.export_key);
return true;
}
- case MENU_DELETE: {
+ case Id.menu.delete: {
mSelectedItem = groupPosition;
- showDialog(DIALOG_DELETE_KEY);
+ showDialog(Id.dialog.delete_key);
return true;
}
@@ -276,7 +147,7 @@ public class PublicKeyListActivity extends ExpandableListActivity
boolean singleKeyExport = false;
switch (id) {
- case DIALOG_DELETE_KEY: {
+ case Id.dialog.delete_key: {
PGPPublicKeyRing keyRing = Apg.getPublicKeyRings().get(mSelectedItem);
String userId = Apg.getMainUserIdSafe(this, Apg.getMasterKey(keyRing));
@@ -289,20 +160,20 @@ public class PublicKeyListActivity extends ExpandableListActivity
public void onClick(DialogInterface dialog, int id) {
deleteKey(mSelectedItem);
mSelectedItem = -1;
- removeDialog(DIALOG_DELETE_KEY);
+ removeDialog(Id.dialog.delete_key);
}
});
builder.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mSelectedItem = -1;
- removeDialog(DIALOG_DELETE_KEY);
+ removeDialog(Id.dialog.delete_key);
}
});
return builder.create();
}
- case DIALOG_IMPORT_KEYS: {
+ case Id.dialog.import_keys: {
return FileDialog.build(this, "Import Keys",
"Please specify which file to import from.",
mImportFilename,
@@ -310,33 +181,33 @@ public class PublicKeyListActivity extends ExpandableListActivity
@Override
public void onOkClick(String filename) {
- removeDialog(DIALOG_IMPORT_KEYS);
+ removeDialog(Id.dialog.import_keys);
mImportFilename = filename;
importKeys();
}
@Override
public void onCancelClick() {
- removeDialog(DIALOG_IMPORT_KEYS);
+ removeDialog(Id.dialog.import_keys);
}
},
getString(R.string.filemanager_title_open),
getString(R.string.filemanager_btn_open));
}
- case DIALOG_EXPORT_KEY: {
+ case Id.dialog.export_key: {
singleKeyExport = true;
- // break intentionally omitted, to use the DIALOG_EXPORT_KEYS dialog
+ // break intentionally omitted, to use the Id.dialog.export_keys dialog
}
- case DIALOG_EXPORT_KEYS: {
+ case Id.dialog.export_keys: {
String title = "Export Key";
if (!singleKeyExport) {
// plural "Keys"
title += "s";
}
- final int thisDialogId = (singleKeyExport ? DIALOG_EXPORT_KEY : DIALOG_EXPORT_KEYS);
+ final int thisDialogId = (singleKeyExport ? Id.dialog.export_key : Id.dialog.export_keys);
return FileDialog.build(this, title,
"Please specify which file to export to.\n" +
@@ -360,54 +231,42 @@ public class PublicKeyListActivity extends ExpandableListActivity
getString(R.string.filemanager_btn_save));
}
- case DIALOG_IMPORTING: {
- mProgressDialog = new ProgressDialog(this);
- mProgressDialog.setMessage("importing...");
- mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- mProgressDialog.setCancelable(false);
- return mProgressDialog;
- }
-
- case DIALOG_EXPORTING: {
- mProgressDialog = new ProgressDialog(this);
- mProgressDialog.setMessage("exporting...");
- mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- mProgressDialog.setCancelable(false);
- return mProgressDialog;
+ default: {
+ break;
}
}
+
return super.onCreateDialog(id);
}
public void importKeys() {
- showDialog(DIALOG_IMPORTING);
- mTask = TASK_IMPORT;
- mRunningThread = new Thread(this);
- mRunningThread.start();
+ showDialog(Id.dialog.importing);
+ mTask = Id.task.import_keys;
+ startThread();
}
public void exportKeys() {
- showDialog(DIALOG_EXPORTING);
- mTask = TASK_EXPORT;
- mRunningThread = new Thread(this);
- mRunningThread.start();
+ showDialog(Id.dialog.exporting);
+ mTask = Id.task.export_keys;
+ startThread();
}
+ @Override
public void run() {
String error = null;
Bundle data = new Bundle();
Message msg = new Message();
String filename = null;
- if (mTask == TASK_IMPORT) {
+ if (mTask == Id.task.import_keys) {
filename = mImportFilename;
} else {
filename = mExportFilename;
}
try {
- if (mTask == TASK_IMPORT) {
- data = Apg.importKeyRings(this, Apg.TYPE_PUBLIC, filename, this);
+ if (mTask == Id.task.import_keys) {
+ data = Apg.importKeyRings(this, Id.type.public_key, filename, this);
} else {
Vector