diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-02-17 20:35:59 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-02-17 20:35:59 +0100 |
commit | 286b27522ef48a729bf55dfe7ab415caaac84238 (patch) | |
tree | 871caa15a1df5a0d9063be5cd48c4157aad7b47e | |
parent | 439c7a66f2bf22b822b6db219fee0334a3da9a60 (diff) | |
download | open-keychain-286b27522ef48a729bf55dfe7ab415caaac84238.tar.gz open-keychain-286b27522ef48a729bf55dfe7ab415caaac84238.tar.bz2 open-keychain-286b27522ef48a729bf55dfe7ab415caaac84238.zip |
Cleanup of API demo
3 files changed, 44 insertions, 43 deletions
diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/Constants.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/Constants.java index 03e76254c..acff12f47 100644 --- a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/Constants.java +++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/Constants.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de> + * Copyright (C) 2013-2014 Dominik Schürmann <dominik@dominikschuermann.de> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,5 @@ package org.sufficientlysecure.keychain.demo; public final class Constants { - - public static final boolean DEBUG = BuildConfig.DEBUG; - public static final String TAG = "Keychain"; - } diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/IntentActivity.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/IntentActivity.java index ad1b55df0..27fe09099 100644 --- a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/IntentActivity.java +++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/IntentActivity.java @@ -33,8 +33,15 @@ import org.sufficientlysecure.keychain.api.OpenKeychainIntents; import java.io.UnsupportedEncodingException; public class IntentActivity extends PreferenceActivity { + private Preference mEncrypt; + private Preference mEncryptUri; + private Preference mDecrypt; + private Preference mImportKey; + private Preference mImportKeyFromKeyserver; + private Preference mImportKeyFromQrCode; + private Preference mOpenpgp4fpr; - private static final int SELECT_PHOTO = 100; + private static final int REQUEST_CODE_SELECT_PHOTO = 100; /** * Called when the activity is first created. @@ -47,24 +54,16 @@ public class IntentActivity extends PreferenceActivity { addPreferencesFromResource(R.xml.intent_preference); // find preferences - Preference encrypt = (Preference) findPreference("ENCRYPT"); - Preference encryptUri = (Preference) findPreference("ENCRYPT_URI"); - Preference decrypt = (Preference) findPreference("DECRYPT"); - Preference import_key = (Preference) findPreference("IMPORT_KEY"); - Preference import_key_from_keyserver = (Preference) findPreference("IMPORT_KEY_FROM_KEYSERVER"); - Preference import_key_from_qr_code = (Preference) findPreference("IMPORT_KEY_FROM_QR_CODE"); - Preference openpgp4fpr = (Preference) findPreference("openpgp4fpr"); - - // To prevent Android Studio from complaining... - assert encrypt != null; - assert encryptUri != null; - assert decrypt != null; - assert import_key != null; - assert import_key_from_keyserver != null; - assert import_key_from_qr_code != null; - assert openpgp4fpr != null; - - encrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() { + mEncrypt = (Preference) findPreference("ENCRYPT"); + mEncryptUri = (Preference) findPreference("ENCRYPT_URI"); + mDecrypt = (Preference) findPreference("DECRYPT"); + mImportKey = (Preference) findPreference("IMPORT_KEY"); + mImportKeyFromKeyserver = (Preference) findPreference("IMPORT_KEY_FROM_KEYSERVER"); + mImportKeyFromQrCode = (Preference) findPreference("IMPORT_KEY_FROM_QR_CODE"); + mOpenpgp4fpr = (Preference) findPreference("mOpenpgp4fpr"); + + + mEncrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { try { @@ -79,18 +78,18 @@ public class IntentActivity extends PreferenceActivity { } }); - encryptUri.setOnPreferenceClickListener(new OnPreferenceClickListener() { + mEncryptUri.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); - startActivityForResult(photoPickerIntent, SELECT_PHOTO); + startActivityForResult(photoPickerIntent, REQUEST_CODE_SELECT_PHOTO); return false; } }); - decrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() { + mDecrypt.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { try { @@ -105,7 +104,7 @@ public class IntentActivity extends PreferenceActivity { } }); - import_key.setOnPreferenceClickListener(new OnPreferenceClickListener() { + mImportKey.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { try { @@ -126,7 +125,7 @@ public class IntentActivity extends PreferenceActivity { } }); - import_key_from_keyserver.setOnPreferenceClickListener(new OnPreferenceClickListener() { + mImportKeyFromKeyserver.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { try { @@ -141,7 +140,7 @@ public class IntentActivity extends PreferenceActivity { } }); - import_key_from_qr_code.setOnPreferenceClickListener(new OnPreferenceClickListener() { + mImportKeyFromQrCode.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { try { @@ -155,12 +154,12 @@ public class IntentActivity extends PreferenceActivity { } }); - openpgp4fpr.setOnPreferenceClickListener(new OnPreferenceClickListener() { + mOpenpgp4fpr.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { try { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282")); + intent.setData(Uri.parse("mOpenpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282")); startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(IntentActivity.this, "Activity not found!", Toast.LENGTH_LONG).show(); @@ -177,7 +176,7 @@ public class IntentActivity extends PreferenceActivity { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); switch (requestCode) { - case SELECT_PHOTO: + case REQUEST_CODE_SELECT_PHOTO: if (resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java index d14703f2d..ef40ee5ac 100644 --- a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java +++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java @@ -41,15 +41,15 @@ import java.io.InputStream; import java.io.UnsupportedEncodingException; public class OpenPgpProviderActivity extends Activity { - EditText mMessage; - EditText mCiphertext; - EditText mEncryptUserIds; - Button mSign; - Button mEncrypt; - Button mSignAndEncrypt; - Button mDecryptAndVerify; + private EditText mMessage; + private EditText mCiphertext; + private EditText mEncryptUserIds; + private Button mSign; + private Button mEncrypt; + private Button mSignAndEncrypt; + private Button mDecryptAndVerify; - OpenPgpServiceConnection mServiceConnection; + private OpenPgpServiceConnection mServiceConnection; public static final int REQUEST_CODE_SIGN = 9910; public static final int REQUEST_CODE_ENCRYPT = 9911; @@ -138,7 +138,7 @@ public class OpenPgpProviderActivity extends Activity { } is = new ByteArrayInputStream(inputStr.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + Log.e(Constants.TAG, "UnsupportedEncodingException", e); } return is; @@ -237,11 +237,17 @@ public class OpenPgpProviderActivity extends Activity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - Log.d(Constants.TAG, "onActivityResult resultCode: " + resultCode); // try again after user interaction if (resultCode == RESULT_OK) { + /* + * The params originally given to the pgp method are are again + * returned here to be used when calling again after user interaction. + * + * They also contain results from the user interaction which happened, + * for example selected key ids. + */ Bundle params = data.getBundleExtra(OpenPgpConstants.PI_RESULT_PARAMS); switch (requestCode) { |