From a48aa2bcaa1ae814e71bd5a36611c7066adf0122 Mon Sep 17 00:00:00 2001 From: bcbarnes-gmx Date: Mon, 22 Jul 2013 11:11:41 -0500 Subject: [PATCH] Change key bit length control into a dropdown --- OpenPGP-Keychain/res/layout/create_key.xml | 6 ++--- OpenPGP-Keychain/res/values/arrays.xml | 7 ++++- OpenPGP-Keychain/res/values/strings.xml | 7 ++++- .../keychain/ui/widget/SectionView.java | 26 ++++++++++++++++--- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/OpenPGP-Keychain/res/layout/create_key.xml b/OpenPGP-Keychain/res/layout/create_key.xml index 8858e8d80..8014dbefc 100644 --- a/OpenPGP-Keychain/res/layout/create_key.xml +++ b/OpenPGP-Keychain/res/layout/create_key.xml @@ -58,14 +58,12 @@ android:padding="4dp" android:text="@string/label_keySize" /> - + android:padding="4dp" /> diff --git a/OpenPGP-Keychain/res/values/arrays.xml b/OpenPGP-Keychain/res/values/arrays.xml index 05320c609..950a70821 100644 --- a/OpenPGP-Keychain/res/values/arrays.xml +++ b/OpenPGP-Keychain/res/values/arrays.xml @@ -43,5 +43,10 @@ 14400 28800 - + + @string/key_size_512 + @string/key_size_1024 + @string/key_size_2048 + @string/key_size_4096 + \ No newline at end of file diff --git a/OpenPGP-Keychain/res/values/strings.xml b/OpenPGP-Keychain/res/values/strings.xml index d02cceff8..a0787a63a 100644 --- a/OpenPGP-Keychain/res/values/strings.xml +++ b/OpenPGP-Keychain/res/values/strings.xml @@ -324,11 +324,16 @@ Filter: \"%s\" Share keyring with… + + 512 + 1024 + 2048 + 4096 + fast slow very slow - 2048 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..6992cc232 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 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; }