From 1a33f4d886ce45596dd7f6dfc3356fe32ec71c1c Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 12 Apr 2012 15:23:00 +0200 Subject: intent to create a new key --- .../src/org/apg/integration/ApgIntentHelper.java | 68 +++++++++++++++++++--- .../src/org/apg/integration/Constants.java | 3 + 2 files changed, 63 insertions(+), 8 deletions(-) (limited to 'org_apg_integration_lib/src') diff --git a/org_apg_integration_lib/src/org/apg/integration/ApgIntentHelper.java b/org_apg_integration_lib/src/org/apg/integration/ApgIntentHelper.java index 506ec7a5c..a03e74d2b 100644 --- a/org_apg_integration_lib/src/org/apg/integration/ApgIntentHelper.java +++ b/org_apg_integration_lib/src/org/apg/integration/ApgIntentHelper.java @@ -36,11 +36,59 @@ public class ApgIntentHelper { } /** - * Select the signature key. + * Opens APG activity to create new key * - * @param activity - * @param pgpData - * @return success or failure + * @param userIds + * value to specify prefilled values for user that should be created + * @return true when user presses save, false when user presses cancel + */ + public boolean createNewKey(String userIds) { + Intent intent = new Intent(Constants.Intent.EDIT_KEY); + if (userIds != null) { + intent.putExtra(Constants.EXTRA_USER_IDS, userIds); + } + intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION); + try { + activity.startActivityForResult(intent, Constants.CREATE_NEW_KEY); + return true; + } catch (ActivityNotFoundException e) { + activityNotFound(); + return false; + } + } + + /** + * Opens APG activity to create new key + * + * @return true when user presses save, false when user presses cancel + */ + public boolean createNewKey() { + return createNewKey(null); + } + + /** + * Opens APG activity to edit already existing key based on keyId + * + * @param keyId + * @return true when user presses save, false when user presses cancel + */ + public boolean editKey(long keyId) { + Intent intent = new Intent(Constants.Intent.EDIT_KEY); + intent.putExtra(Constants.EXTRA_KEY_ID, keyId); + intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION); + try { + activity.startActivityForResult(intent, Constants.CREATE_NEW_KEY); + return true; + } catch (ActivityNotFoundException e) { + activityNotFound(); + return false; + } + } + + /** + * Opens APG activity to select the signature key. + * + * @return true when user presses okay, false when user presses cancel */ public boolean selectSecretKey() { Intent intent = new Intent(Constants.Intent.SELECT_SECRET_KEY); @@ -55,12 +103,16 @@ public class ApgIntentHelper { } /** - * Start the encrypt activity. + * Encrypts the given data by opening APGs encrypt activity. If encryptionKeys are given it + * encrypts immediately and goes back to your program after that * - * @param activity * @param data - * @param pgpData - * @return success or failure + * String that contains the message to be encrypted + * @param encryptionKeyIds + * long[] that holds the ids of the encryption keys + * @param signatureKeyId + * id of the signature key + * @return */ public boolean encrypt(String data, long[] encryptionKeyIds, long signatureKeyId) { Intent intent = new Intent(Constants.Intent.ENCRYPT_AND_RETURN); diff --git a/org_apg_integration_lib/src/org/apg/integration/Constants.java b/org_apg_integration_lib/src/org/apg/integration/Constants.java index 017f88478..b5a92919e 100644 --- a/org_apg_integration_lib/src/org/apg/integration/Constants.java +++ b/org_apg_integration_lib/src/org/apg/integration/Constants.java @@ -49,6 +49,7 @@ public class Constants { + ".intent.SELECT_PUBLIC_KEYS"; public static final String SELECT_SECRET_KEY = APG_PACKAGE_NAME + ".intent.SELECT_SECRET_KEY"; + public static final String EDIT_KEY = APG_PACKAGE_NAME + ".intent.EDIT_KEY"; } public static final String EXTRA_TEXT = "text"; @@ -62,6 +63,7 @@ public class Constants { public static final String EXTRA_SIGNATURE_SUCCESS = "signatureSuccess"; public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown"; public static final String EXTRA_USER_ID = "userId"; + public static final String EXTRA_USER_IDS = "userIds"; public static final String EXTRA_KEY_ID = "keyId"; public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds"; public static final String EXTRA_SELECTION = "selection"; @@ -74,6 +76,7 @@ public class Constants { public static final int ENCRYPT_MESSAGE = 0x21070002; public static final int SELECT_PUBLIC_KEYS = 0x21070003; public static final int SELECT_SECRET_KEY = 0x21070004; + public static final int CREATE_NEW_KEY = 0x21070005; // public static Pattern PGP_MESSAGE = Pattern.compile( // ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); -- cgit v1.2.3