diff options
Diffstat (limited to 'OpenPGP-Keychain/src/org/sufficientlysecure')
15 files changed, 94 insertions, 96 deletions
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/KeychainApplication.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/KeychainApplication.java index dbe9f6394..e63c44760 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/KeychainApplication.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/KeychainApplication.java @@ -28,7 +28,7 @@ public class KeychainApplication extends Application { static { // Define Java Security Provider to be Bouncy Castle - Security.addProvider(new BouncyCastleProvider()); + Security.insertProviderAt(new BouncyCastleProvider(), 1); } @Override diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/PgpMain.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/PgpMain.java index 142dfec01..d236f9faa 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/PgpMain.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/PgpMain.java @@ -132,7 +132,8 @@ public class PgpMain { } // Not BC due to the use of Spongy Castle for Android - public static final String BOUNCY_CASTLE_PROVIDER_NAME = "SC"; + public static final String SC = BouncyCastleProvider.PROVIDER_NAME; + public static final String BOUNCY_CASTLE_PROVIDER_NAME = SC; private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[] { SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192, @@ -323,8 +324,9 @@ public class PgpMain { } PGPSecretKeyRing newKeyRing = PGPSecretKeyRing.copyWithNewPassword(keyRing, - oldPassPhrase.toCharArray(), newPassPhrase.toCharArray(), keyRing.getSecretKey().getKeyEncryptionAlgorithm(), - new SecureRandom(), BOUNCY_CASTLE_PROVIDER_NAME); + new JcePBESecretKeyDecryptorBuilder( + new JcaPGPDigestCalculatorProviderBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build()).setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(oldPassPhrase.toCharArray()), + new JcePBESecretKeyEncryptorBuilder(keyRing.getSecretKey().getKeyEncryptionAlgorithm()).build(newPassPhrase.toCharArray())); updateProgress(progress, R.string.progress_savingKeyRing, 50, 100); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 711cdae24..bf685d725 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -65,27 +65,26 @@ public class KeychainIntentService extends IntentService implements ProgressDial /* extras that can be given by intent */ public static final String EXTRA_MESSENGER = "messenger"; - public static final String EXTRA_ACTION = "action"; public static final String EXTRA_DATA = "data"; /* possible EXTRA_ACTIONs */ - public static final int ACTION_ENCRYPT_SIGN = 10; + public static final String ACTION_ENCRYPT_SIGN = Constants.INTENT_PREFIX + "ENCRYPT_SIGN"; - public static final int ACTION_DECRYPT_VERIFY = 20; + public static final String ACTION_DECRYPT_VERIFY = Constants.INTENT_PREFIX + "DECRYPT_VERIFY"; - public static final int ACTION_SAVE_KEYRING = 30; - public static final int ACTION_GENERATE_KEY = 31; - public static final int ACTION_GENERATE_DEFAULT_RSA_KEYS = 32; + public static final String ACTION_SAVE_KEYRING = Constants.INTENT_PREFIX + "SAVE_KEYRING"; + public static final String ACTION_GENERATE_KEY = Constants.INTENT_PREFIX + "GENERATE_KEY"; + public static final String ACTION_GENERATE_DEFAULT_RSA_KEYS = Constants.INTENT_PREFIX + "GENERATE_DEFAULT_RSA_KEYS"; - public static final int ACTION_DELETE_FILE_SECURELY = 40; + public static final String ACTION_DELETE_FILE_SECURELY = Constants.INTENT_PREFIX + "DELETE_FILE_SECURELY"; - public static final int ACTION_IMPORT_KEYRING = 50; - public static final int ACTION_EXPORT_KEYRING = 51; + public static final String ACTION_IMPORT_KEYRING = Constants.INTENT_PREFIX + "IMPORT_KEYRING"; + public static final String ACTION_EXPORT_KEYRING = Constants.INTENT_PREFIX + "EXPORT_KEYRING"; - public static final int ACTION_UPLOAD_KEYRING = 60; - public static final int ACTION_QUERY_KEYRING = 61; + public static final String ACTION_UPLOAD_KEYRING = Constants.INTENT_PREFIX + "UPLOAD_KEYRING"; + public static final String ACTION_QUERY_KEYRING = Constants.INTENT_PREFIX + "QUERY_KEYRING"; - public static final int ACTION_SIGN_KEYRING = 70; + public static final String ACTION_SIGN_KEYRING = Constants.INTENT_PREFIX + "SIGN_KEYRING"; /* keys for data bundle */ @@ -216,8 +215,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial return; } - if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || extras - .containsKey(EXTRA_ACTION))) { + if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || + (intent.getAction() == null))) { Log.e(Constants.TAG, "Extra bundle must contain a messenger, a data bundle, and an action!"); return; @@ -228,12 +227,10 @@ public class KeychainIntentService extends IntentService implements ProgressDial OtherHelper.logDebugBundle(data, "EXTRA_DATA"); - int action = extras.getInt(EXTRA_ACTION); - + String action = intent.getAction(); + // execute action from extra bundle - switch (action) { - case ACTION_ENCRYPT_SIGN: - + if( ACTION_ENCRYPT_SIGN.equals(action)) { try { /* Input */ int target = data.getInt(TARGET); @@ -382,10 +379,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_DECRYPT_VERIFY: + } + else if(ACTION_DECRYPT_VERIFY.equals(action)) { try { /* Input */ int target = data.getInt(TARGET); @@ -514,11 +509,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_SAVE_KEYRING: - + } + else if(ACTION_SAVE_KEYRING.equals(action)) { try { /* Input */ String oldPassPhrase = data.getString(SAVE_KEYRING_CURRENT_PASSPHRASE); @@ -554,11 +546,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_GENERATE_KEY: - + } + else if(ACTION_GENERATE_KEY.equals(action)) { try { /* Input */ int algorithm = data.getInt(GENERATE_KEY_ALGORITHM); @@ -585,10 +574,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_GENERATE_DEFAULT_RSA_KEYS: + } + else if(ACTION_GENERATE_DEFAULT_RSA_KEYS.equals(action)) { // generate one RSA 2048 key for signing and one subkey for encrypting! try { /* Input */ @@ -614,10 +601,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_DELETE_FILE_SECURELY: + } + else if(ACTION_DELETE_FILE_SECURELY.equals(action)) { try { /* Input */ String deleteFile = data.getString(DELETE_FILE); @@ -638,10 +623,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_IMPORT_KEYRING: + } + else if(ACTION_IMPORT_KEYRING.equals(action)) { try { /* Input */ @@ -688,10 +671,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_EXPORT_KEYRING: + } + else if(ACTION_EXPORT_KEYRING.equals(action)) { try { /* Input */ @@ -739,10 +720,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_UPLOAD_KEYRING: + } + else if(ACTION_UPLOAD_KEYRING.equals(action)) { try { /* Input */ @@ -766,10 +745,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_QUERY_KEYRING: + } + else if(ACTION_QUERY_KEYRING.equals(action)) { try { /* Input */ @@ -797,10 +774,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - case ACTION_SIGN_KEYRING: + } + else if(ACTION_SIGN_KEYRING.equals(action)) { try { /* Input */ @@ -824,13 +799,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial } catch (Exception e) { sendErrorToHandler(e); } - - break; - - default: - break; } - } private void sendErrorToHandler(Exception e) { diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/DecryptActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/DecryptActivity.java index ed81c2aa8..8b617b92b 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/DecryptActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/DecryptActivity.java @@ -758,7 +758,7 @@ public class DecryptActivity extends SherlockFragmentActivity { // fill values for this action Bundle data = new Bundle(); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_DECRYPT_VERIFY); + intent.setAction(KeychainIntentService.ACTION_DECRYPT_VERIFY); // choose action based on input: decrypt stream, file or bytes if (mContentUri != null) { diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index bc4467967..b710e69cf 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -238,8 +238,7 @@ public class EditKeyActivity extends SherlockFragmentActivity { // Send all information needed to service generate keys in other thread Intent serviceIntent = new Intent(this, KeychainIntentService.class); - serviceIntent.putExtra(KeychainIntentService.EXTRA_ACTION, - KeychainIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS); + serviceIntent.setAction(KeychainIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS); // fill values for this action Bundle data = new Bundle(); @@ -438,8 +437,7 @@ public class EditKeyActivity extends SherlockFragmentActivity { // Send all information needed to service to edit key in other thread Intent intent = new Intent(this, KeychainIntentService.class); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, - KeychainIntentService.ACTION_SAVE_KEYRING); + intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING); // fill values for this action Bundle data = new Bundle(); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EncryptActivity.java index c6b2d196a..e38044526 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EncryptActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EncryptActivity.java @@ -693,7 +693,7 @@ public class EncryptActivity extends SherlockFragmentActivity { signOnly = (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0); } - intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_ENCRYPT_SIGN); + intent.setAction(KeychainIntentService.ACTION_ENCRYPT_SIGN); // choose default settings, target and data bundle by target if (mStreamAndReturnUri != null) { @@ -778,7 +778,11 @@ public class EncryptActivity extends SherlockFragmentActivity { Log.d(Constants.TAG, "output: " + output); Intent emailIntent = new Intent(Intent.ACTION_SEND); - emailIntent.setType("text/plain; charset=utf-8"); + + //Type is set to text/plain so that encrypted messages can + //be sent with Whatsapp, Hangouts, SMS etc... + emailIntent.setType("text/plain"); + emailIntent.putExtra(Intent.EXTRA_TEXT, output); if (mSubject != null) { emailIntent.putExtra(Intent.EXTRA_SUBJECT, mSubject); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index cd5a12df0..cb186ba16 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -321,7 +321,7 @@ public class ImportKeysActivity extends SherlockFragmentActivity { // Send all information needed to service to import key in other thread Intent intent = new Intent(this, KeychainIntentService.class); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_IMPORT_KEYRING); + intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING); // fill values for this action Bundle data = new Bundle(); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListActivity.java index a128263c1..d96308a40 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -259,7 +259,7 @@ public class KeyListActivity extends SherlockFragmentActivity { // Send all information needed to service to export key in other thread Intent intent = new Intent(this, KeychainIntentService.class); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_EXPORT_KEYRING); + intent.setAction(KeychainIntentService.ACTION_EXPORT_KEYRING); // fill values for this action Bundle data = new Bundle(); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java index 648b09ef7..d04cdcaad 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java @@ -116,7 +116,7 @@ public class KeyListPublicFragment extends KeyListFragment implements case Id.menu.exportToServer: Intent uploadIntent = new Intent(mKeyListActivity, KeyServerUploadActivity.class); uploadIntent.setAction(KeyServerUploadActivity.ACTION_EXPORT_KEY_TO_SERVER); - uploadIntent.putExtra(KeyServerUploadActivity.EXTRA_KEYRING_ROW_ID, keyRingRowId); + uploadIntent.putExtra(KeyServerUploadActivity.EXTRA_KEYRING_ROW_ID, (int)keyRingRowId); startActivityForResult(uploadIntent, Id.request.export_to_server); return true; diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java index df8b7b374..b409698b0 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerQueryActivity.java @@ -168,7 +168,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity { // Send all information needed to service to query keys in other thread Intent intent = new Intent(this, KeychainIntentService.class); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_QUERY_KEYRING); + intent.setAction(KeychainIntentService.ACTION_QUERY_KEYRING); // fill values for this action Bundle data = new Bundle(); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerUploadActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerUploadActivity.java index 657044f2b..31486937d 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerUploadActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyServerUploadActivity.java @@ -104,7 +104,7 @@ public class KeyServerUploadActivity extends SherlockFragmentActivity { // Send all information needed to service to upload key in other thread Intent intent = new Intent(this, KeychainIntentService.class); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_UPLOAD_KEYRING); + intent.setAction(KeychainIntentService.ACTION_UPLOAD_KEYRING); // fill values for this action Bundle data = new Bundle(); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/SignKeyActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/SignKeyActivity.java index 06d59b9a2..e8f989dff 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/SignKeyActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/SignKeyActivity.java @@ -199,8 +199,7 @@ public class SignKeyActivity extends SherlockFragmentActivity { // Send all information needed to service to sign key in other thread Intent intent = new Intent(this, KeychainIntentService.class); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, - KeychainIntentService.ACTION_SIGN_KEYRING); + intent.setAction(KeychainIntentService.ACTION_SIGN_KEYRING); // fill values for this action Bundle data = new Bundle(); @@ -251,8 +250,7 @@ public class SignKeyActivity extends SherlockFragmentActivity { // Send all information needed to service to upload key in other thread Intent intent = new Intent(this, KeychainIntentService.class); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, - KeychainIntentService.ACTION_UPLOAD_KEYRING); + intent.setAction(KeychainIntentService.ACTION_UPLOAD_KEYRING); // fill values for this action Bundle data = new Bundle(); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java index defc3bc6c..303193c9a 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/dialog/DeleteFileDialogFragment.java @@ -76,7 +76,7 @@ public class DeleteFileDialogFragment extends DialogFragment { // fill values for this action Bundle data = new Bundle(); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_DELETE_FILE_SECURELY); + intent.setAction(KeychainIntentService.ACTION_DELETE_FILE_SECURELY); data.putString(KeychainIntentService.DELETE_FILE, deleteFile); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index e9a5674cd..45c106eb9 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -59,10 +59,14 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { Button mExpiryDateButton; GregorianCalendar mExpiryDate; + private int mDatePickerResultCount = 0; private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { - GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth); - setExpiryDate(date); + if(mDatePickerResultCount++ == 0) // Note: Ignore results after the first one - android sends multiples. + { + GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth); + setExpiryDate(date); + } } }; @@ -111,11 +115,15 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { DatePickerDialog dialog = new DatePickerDialog(getContext(), mExpiryDateSetListener, date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH)); + mDatePickerResultCount = 0; dialog.setCancelable(true); dialog.setButton(Dialog.BUTTON_NEGATIVE, getContext() .getString(R.string.btn_noDate), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { - setExpiryDate(null); + if(mDatePickerResultCount++ == 0) // Note: Ignore results after the first one - android sends multiples. + { + setExpiryDate(null); + } } }); dialog.show(); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/SectionView.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/SectionView.java index 6d94889cf..997352769 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/SectionView.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/widget/SectionView.java @@ -43,6 +43,8 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ImageView; @@ -186,14 +188,32 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor } } - final EditText keySize = (EditText) view.findViewById(R.id.create_key_size); - + final Spinner keySize = (Spinner) view.findViewById(R.id.create_key_size); + ArrayAdapter<CharSequence> keySizeAdapter = ArrayAdapter.createFromResource(getContext(), R.array.key_size_spinner_values, android.R.layout.simple_spinner_item); + keySizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + keySize.setAdapter(keySizeAdapter); + keySize.setSelection(2); // Default to 2048 for the key length dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface di, int id) { di.dismiss(); try { - mNewKeySize = Integer.parseInt("" + keySize.getText()); + int nKeyIndex = keySize.getSelectedItemPosition(); + switch(nKeyIndex) + { + case 0: + mNewKeySize = 512; + break; + case 1: + mNewKeySize = 1024; + break; + case 2: + mNewKeySize = 2048; + break; + case 3: + mNewKeySize = 4096; + break; + } } catch (NumberFormatException e) { mNewKeySize = 0; } @@ -269,8 +289,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor // Send all information needed to service to edit key in other thread Intent intent = new Intent(mActivity, KeychainIntentService.class); - intent.putExtra(KeychainIntentService.EXTRA_ACTION, - KeychainIntentService.ACTION_GENERATE_KEY); + intent.setAction(KeychainIntentService.ACTION_GENERATE_KEY); // fill values for this action Bundle data = new Bundle(); |