From 7d2c3f860e4ce291a4607bee43d4a36ff0093989 Mon Sep 17 00:00:00 2001 From: Sreeram Boyapati Date: Mon, 10 Mar 2014 08:31:53 +0530 Subject: [PATCH 1/3] Fix to passphrase dialog and Issue #207 --- .../ui/SelectSecretKeyLayoutFragment.java | 50 ++++++++++++++++--- .../res/layout/passphrase_repeat_dialog.xml | 8 ++- .../select_secret_key_layout_fragment.xml | 23 +++++++-- 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectSecretKeyLayoutFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectSecretKeyLayoutFragment.java index 6bcb84f46..95a254bf2 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectSecretKeyLayoutFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectSecretKeyLayoutFragment.java @@ -24,10 +24,13 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper; +import android.Manifest; import android.app.Activity; +import android.app.ActivityOptions; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -40,6 +43,7 @@ public class SelectSecretKeyLayoutFragment extends Fragment { private TextView mKeyUserId; private TextView mKeyUserIdRest; + private TextView mKeyMasterKeyIdHex; private BootstrapButton mSelectKeyButton; private Boolean mFilterCertify; @@ -61,26 +65,58 @@ public class SelectSecretKeyLayoutFragment extends Fragment { public void selectKey(long secretKeyId) { if (secretKeyId == Id.key.none) { - mKeyUserId.setText(R.string.api_settings_no_key); + mKeyMasterKeyIdHex.setText(R.string.api_settings_no_key); mKeyUserIdRest.setText(""); + mKeyUserId.setVisibility(View.GONE); + mKeyUserIdRest.setVisibility(View.GONE); + } else { String uid = getResources().getString(R.string.user_id_no_name); String uidExtra = ""; + String masterkeyIdHex = ""; + PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId( getActivity(), secretKeyId); if (keyRing != null) { PGPSecretKey key = PgpKeyHelper.getMasterKey(keyRing); + masterkeyIdHex = PgpKeyHelper.convertKeyIdToHex(secretKeyId); + if (key != null) { String userId = PgpKeyHelper.getMainUserIdSafe(getActivity(), key); - String chunks[] = userId.split(" <", 2); + /*String chunks[] = mUserId.split(" <", 2); uid = chunks[0]; if (chunks.length > 1) { uidExtra = "<" + chunks[1]; - } + }*/ + String[] userIdSplit = PgpKeyHelper.splitUserId(userId); + String userName, userEmail; + + if (userIdSplit[0] != null) { userName = userIdSplit[0]; } + else { userName = "No Name"; } + + if (userIdSplit[1] != null) { userEmail = userIdSplit[1]; } + else { userEmail = "No Email"; } + + mKeyMasterKeyIdHex.setText(masterkeyIdHex); + mKeyUserId.setText(userName); + mKeyUserIdRest.setText(userEmail); + mKeyUserId.setVisibility(View.VISIBLE); + mKeyUserIdRest.setVisibility(View.VISIBLE); } + else{ + mKeyMasterKeyIdHex.setText("No key found for KeyRing"); + mKeyUserId.setVisibility(View.GONE); + mKeyUserIdRest.setVisibility(View.GONE); + + } + } - mKeyUserId.setText(uid); - mKeyUserIdRest.setText(uidExtra); + else{ + mKeyMasterKeyIdHex.setText("No KeyRings found for MasterId: "+secretKeyId); + mKeyUserId.setVisibility(View.GONE); + mKeyUserIdRest.setVisibility(View.GONE); + } + } } @@ -98,6 +134,7 @@ public class SelectSecretKeyLayoutFragment extends Fragment { mKeyUserId = (TextView) view.findViewById(R.id.select_secret_key_user_id); mKeyUserIdRest = (TextView) view.findViewById(R.id.select_secret_key_user_id_rest); + mKeyMasterKeyIdHex = (TextView) view.findViewById(R.id.select_secret_key_master_key_hex); mSelectKeyButton = (BootstrapButton) view .findViewById(R.id.select_secret_key_select_key_button); mFilterCertify = false; @@ -117,6 +154,8 @@ public class SelectSecretKeyLayoutFragment extends Fragment { startActivityForResult(intent, REQUEST_CODE_SELECT_KEY); } + //Select Secret Key Activity delivers the intent which was sent by it using interface to Select + // Secret Key Fragment.Intent contains Master Key Id, User Email, User Name, Master Key Id Hex. @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode & 0xFFFF) { @@ -125,7 +164,6 @@ public class SelectSecretKeyLayoutFragment extends Fragment { if (resultCode == Activity.RESULT_OK) { Bundle bundle = data.getExtras(); secretKeyId = bundle.getLong(SelectSecretKeyActivity.RESULT_EXTRA_MASTER_KEY_ID); - selectKey(secretKeyId); // remove displayed errors diff --git a/OpenPGP-Keychain/src/main/res/layout/passphrase_repeat_dialog.xml b/OpenPGP-Keychain/src/main/res/layout/passphrase_repeat_dialog.xml index 2bdd231ee..ae523762c 100644 --- a/OpenPGP-Keychain/src/main/res/layout/passphrase_repeat_dialog.xml +++ b/OpenPGP-Keychain/src/main/res/layout/passphrase_repeat_dialog.xml @@ -6,7 +6,9 @@ android:paddingRight="16dp" android:stretchColumns="1" > - + - + + android:orientation="vertical" > + + android:visibility="gone" + android:text="" + android:textAppearance="?android:attr/textAppearanceSmall" /> + + + \ No newline at end of file From b47f291d1272954a27c5d1313480dd4cc4dbfe05 Mon Sep 17 00:00:00 2001 From: Sreeram Boyapati Date: Mon, 10 Mar 2014 11:49:18 +0530 Subject: [PATCH 2/3] ViewHolder Pattern Implemented --- .../ui/adapter/ImportKeysAdapter.java | 65 +++++++++++-------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 52186b662..4f7623bce 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -42,7 +42,15 @@ public class ImportKeysAdapter extends ArrayAdapter { protected Activity mActivity; protected List data; + static class ViewHolder{ + private TextView mainUserId; + private TextView mainUserIdRest; + private TextView keyId; + private TextView fingerprint; + private TextView algorithm; + private TextView status; + } public ImportKeysAdapter(Activity activity) { super(activity, -1); mActivity = activity; @@ -86,16 +94,21 @@ public class ImportKeysAdapter extends ArrayAdapter { public View getView(int position, View convertView, ViewGroup parent) { ImportKeysListEntry entry = data.get(position); - - View view = mInflater.inflate(R.layout.import_keys_list_entry, null); - - TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId); - TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); - TextView keyId = (TextView) view.findViewById(R.id.keyId); - TextView fingerprint = (TextView) view.findViewById(R.id.fingerprint); - TextView algorithm = (TextView) view.findViewById(R.id.algorithm); - TextView status = (TextView) view.findViewById(R.id.status); - + ViewHolder holder; + if(convertView == null) { + holder = new ViewHolder(); + convertView = mInflater.inflate(R.layout.import_keys_list_entry, null); + holder.mainUserId = (TextView) convertView.findViewById(R.id.mainUserId); + holder.mainUserIdRest = (TextView) convertView.findViewById(R.id.mainUserIdRest); + holder.keyId = (TextView) convertView.findViewById(R.id.keyId); + holder.fingerprint = (TextView) convertView.findViewById(R.id.fingerprint); + holder.algorithm = (TextView) convertView.findViewById(R.id.algorithm); + holder.status = (TextView) convertView.findViewById(R.id.status); + convertView.setTag(holder); + } + else{ + holder = (ViewHolder)convertView.getTag(); + } // main user id String userId = entry.userIds.get(0); String[] userIdSplit = PgpKeyHelper.splitUserId(userId); @@ -105,39 +118,39 @@ public class ImportKeysAdapter extends ArrayAdapter { // show red user id if it is a secret key if (entry.secretKey) { userIdSplit[0] = mActivity.getString(R.string.secret_key) + " " + userIdSplit[0]; - mainUserId.setTextColor(Color.RED); + holder.mainUserId.setTextColor(Color.RED); } - mainUserId.setText(userIdSplit[0]); + holder.mainUserId.setText(userIdSplit[0]); } else { - mainUserId.setText(R.string.user_id_no_name); + holder.mainUserId.setText(R.string.user_id_no_name); } // email if (userIdSplit[1] != null) { - mainUserIdRest.setText(userIdSplit[1]); - mainUserIdRest.setVisibility(View.VISIBLE); + holder.mainUserIdRest.setText(userIdSplit[1]); + holder.mainUserIdRest.setVisibility(View.VISIBLE); } else { - mainUserIdRest.setVisibility(View.GONE); + holder.mainUserIdRest.setVisibility(View.GONE); } - keyId.setText(entry.hexKeyId); + holder.keyId.setText(entry.hexKeyId); if (entry.fingerPrint != null) { - fingerprint.setText(mActivity.getString(R.string.fingerprint) + " " + entry.fingerPrint); - fingerprint.setVisibility(View.VISIBLE); + holder.fingerprint.setText(mActivity.getString(R.string.fingerprint) + " " + entry.fingerPrint); + holder.fingerprint.setVisibility(View.VISIBLE); } else { - fingerprint.setVisibility(View.GONE); + holder.fingerprint.setVisibility(View.GONE); } - algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm); + holder.algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm); if (entry.revoked) { - status.setText(R.string.revoked); + holder.status.setText(R.string.revoked); } else { - status.setVisibility(View.GONE); + holder.status.setVisibility(View.GONE); } - LinearLayout ll = (LinearLayout) view.findViewById(R.id.list); + LinearLayout ll = (LinearLayout) convertView.findViewById(R.id.list); if (entry.userIds.size() == 1) { ll.setVisibility(View.GONE); } else { @@ -162,10 +175,10 @@ public class ImportKeysAdapter extends ArrayAdapter { } } - CheckBox cBox = (CheckBox) view.findViewById(R.id.selected); + CheckBox cBox = (CheckBox) convertView.findViewById(R.id.selected); cBox.setChecked(entry.isSelected()); - return view; + return convertView; } } From a41ee31b6c5cfbef067efb0843593a2459861b9c Mon Sep 17 00:00:00 2001 From: Sreeram Boyapati Date: Mon, 10 Mar 2014 22:37:23 +0530 Subject: [PATCH 3/3] Added string reference for Issue #207 --- .../keychain/ui/SelectSecretKeyLayoutFragment.java | 8 ++++---- OpenPGP-Keychain/src/main/res/values/strings.xml | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectSecretKeyLayoutFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectSecretKeyLayoutFragment.java index 95a254bf2..ca5d8b262 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectSecretKeyLayoutFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectSecretKeyLayoutFragment.java @@ -92,10 +92,10 @@ public class SelectSecretKeyLayoutFragment extends Fragment { String userName, userEmail; if (userIdSplit[0] != null) { userName = userIdSplit[0]; } - else { userName = "No Name"; } + else { userName = getActivity().getResources().getString(R.string.user_id_no_name); } if (userIdSplit[1] != null) { userEmail = userIdSplit[1]; } - else { userEmail = "No Email"; } + else { userEmail = getActivity().getResources().getString(R.string.error_user_id_no_email); } mKeyMasterKeyIdHex.setText(masterkeyIdHex); mKeyUserId.setText(userName); @@ -104,7 +104,7 @@ public class SelectSecretKeyLayoutFragment extends Fragment { mKeyUserIdRest.setVisibility(View.VISIBLE); } else{ - mKeyMasterKeyIdHex.setText("No key found for KeyRing"); + mKeyMasterKeyIdHex.setText(getActivity().getResources().getString(R.string.no_key)); mKeyUserId.setVisibility(View.GONE); mKeyUserIdRest.setVisibility(View.GONE); @@ -112,7 +112,7 @@ public class SelectSecretKeyLayoutFragment extends Fragment { } else{ - mKeyMasterKeyIdHex.setText("No KeyRings found for MasterId: "+secretKeyId); + mKeyMasterKeyIdHex.setText(getActivity().getResources().getString(R.string.no_keys_added_or_updated)+" for master id: "+secretKeyId); mKeyUserId.setVisibility(View.GONE); mKeyUserIdRest.setVisibility(View.GONE); } diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml index 99fc7c8a7..754d4cece 100644 --- a/OpenPGP-Keychain/src/main/res/values/strings.xml +++ b/OpenPGP-Keychain/src/main/res/values/strings.xml @@ -145,6 +145,7 @@ <no name> <none> <no key> + <No Email> can encrypt can sign @@ -271,6 +272,7 @@ the master key cannot be an ElGamal key unknown algorithm choice you need to specify a name + no email found you need to specify an email address need at least one user id main user id must not be empty