Merge pull request #383 from sreeram-boyapati/master

Fix to passphrase dialog and Issue #207
This commit is contained in:
Dominik Schürmann 2014-03-10 23:20:07 +01:00
commit 612ad9e6b3
5 changed files with 109 additions and 39 deletions

View File

@ -24,10 +24,13 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@ -40,6 +43,7 @@ public class SelectSecretKeyLayoutFragment extends Fragment {
private TextView mKeyUserId; private TextView mKeyUserId;
private TextView mKeyUserIdRest; private TextView mKeyUserIdRest;
private TextView mKeyMasterKeyIdHex;
private BootstrapButton mSelectKeyButton; private BootstrapButton mSelectKeyButton;
private Boolean mFilterCertify; private Boolean mFilterCertify;
@ -61,26 +65,58 @@ public class SelectSecretKeyLayoutFragment extends Fragment {
public void selectKey(long secretKeyId) { public void selectKey(long secretKeyId) {
if (secretKeyId == Id.key.none) { if (secretKeyId == Id.key.none) {
mKeyUserId.setText(R.string.api_settings_no_key); mKeyMasterKeyIdHex.setText(R.string.api_settings_no_key);
mKeyUserIdRest.setText(""); mKeyUserIdRest.setText("");
mKeyUserId.setVisibility(View.GONE);
mKeyUserIdRest.setVisibility(View.GONE);
} else { } else {
String uid = getResources().getString(R.string.user_id_no_name); String uid = getResources().getString(R.string.user_id_no_name);
String uidExtra = ""; String uidExtra = "";
String masterkeyIdHex = "";
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId( PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(
getActivity(), secretKeyId); getActivity(), secretKeyId);
if (keyRing != null) { if (keyRing != null) {
PGPSecretKey key = PgpKeyHelper.getMasterKey(keyRing); PGPSecretKey key = PgpKeyHelper.getMasterKey(keyRing);
masterkeyIdHex = PgpKeyHelper.convertKeyIdToHex(secretKeyId);
if (key != null) { if (key != null) {
String userId = PgpKeyHelper.getMainUserIdSafe(getActivity(), key); String userId = PgpKeyHelper.getMainUserIdSafe(getActivity(), key);
String chunks[] = userId.split(" <", 2); /*String chunks[] = mUserId.split(" <", 2);
uid = chunks[0]; uid = chunks[0];
if (chunks.length > 1) { if (chunks.length > 1) {
uidExtra = "<" + chunks[1]; uidExtra = "<" + chunks[1];
} }*/
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
String userName, userEmail;
if (userIdSplit[0] != null) { userName = userIdSplit[0]; }
else { userName = getActivity().getResources().getString(R.string.user_id_no_name); }
if (userIdSplit[1] != null) { userEmail = userIdSplit[1]; }
else { userEmail = getActivity().getResources().getString(R.string.error_user_id_no_email); }
mKeyMasterKeyIdHex.setText(masterkeyIdHex);
mKeyUserId.setText(userName);
mKeyUserIdRest.setText(userEmail);
mKeyUserId.setVisibility(View.VISIBLE);
mKeyUserIdRest.setVisibility(View.VISIBLE);
} }
else{
mKeyMasterKeyIdHex.setText(getActivity().getResources().getString(R.string.no_key));
mKeyUserId.setVisibility(View.GONE);
mKeyUserIdRest.setVisibility(View.GONE);
}
} }
mKeyUserId.setText(uid); else{
mKeyUserIdRest.setText(uidExtra); mKeyMasterKeyIdHex.setText(getActivity().getResources().getString(R.string.no_keys_added_or_updated)+" for master id: "+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); mKeyUserId = (TextView) view.findViewById(R.id.select_secret_key_user_id);
mKeyUserIdRest = (TextView) view.findViewById(R.id.select_secret_key_user_id_rest); 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 mSelectKeyButton = (BootstrapButton) view
.findViewById(R.id.select_secret_key_select_key_button); .findViewById(R.id.select_secret_key_select_key_button);
mFilterCertify = false; mFilterCertify = false;
@ -117,6 +154,8 @@ public class SelectSecretKeyLayoutFragment extends Fragment {
startActivityForResult(intent, REQUEST_CODE_SELECT_KEY); 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 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode & 0xFFFF) { switch (requestCode & 0xFFFF) {
@ -125,7 +164,6 @@ public class SelectSecretKeyLayoutFragment extends Fragment {
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
Bundle bundle = data.getExtras(); Bundle bundle = data.getExtras();
secretKeyId = bundle.getLong(SelectSecretKeyActivity.RESULT_EXTRA_MASTER_KEY_ID); secretKeyId = bundle.getLong(SelectSecretKeyActivity.RESULT_EXTRA_MASTER_KEY_ID);
selectKey(secretKeyId); selectKey(secretKeyId);
// remove displayed errors // remove displayed errors

View File

@ -42,7 +42,15 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
protected Activity mActivity; protected Activity mActivity;
protected List<ImportKeysListEntry> data; protected List<ImportKeysListEntry> 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) { public ImportKeysAdapter(Activity activity) {
super(activity, -1); super(activity, -1);
mActivity = activity; mActivity = activity;
@ -86,16 +94,21 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
ImportKeysListEntry entry = data.get(position); ImportKeysListEntry entry = data.get(position);
ViewHolder holder;
View view = mInflater.inflate(R.layout.import_keys_list_entry, null); if(convertView == null) {
holder = new ViewHolder();
TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId); convertView = mInflater.inflate(R.layout.import_keys_list_entry, null);
TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); holder.mainUserId = (TextView) convertView.findViewById(R.id.mainUserId);
TextView keyId = (TextView) view.findViewById(R.id.keyId); holder.mainUserIdRest = (TextView) convertView.findViewById(R.id.mainUserIdRest);
TextView fingerprint = (TextView) view.findViewById(R.id.fingerprint); holder.keyId = (TextView) convertView.findViewById(R.id.keyId);
TextView algorithm = (TextView) view.findViewById(R.id.algorithm); holder.fingerprint = (TextView) convertView.findViewById(R.id.fingerprint);
TextView status = (TextView) view.findViewById(R.id.status); 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 // main user id
String userId = entry.userIds.get(0); String userId = entry.userIds.get(0);
String[] userIdSplit = PgpKeyHelper.splitUserId(userId); String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
@ -105,39 +118,39 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
// show red user id if it is a secret key // show red user id if it is a secret key
if (entry.secretKey) { if (entry.secretKey) {
userIdSplit[0] = mActivity.getString(R.string.secret_key) + " " + userIdSplit[0]; 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 { } else {
mainUserId.setText(R.string.user_id_no_name); holder.mainUserId.setText(R.string.user_id_no_name);
} }
// email // email
if (userIdSplit[1] != null) { if (userIdSplit[1] != null) {
mainUserIdRest.setText(userIdSplit[1]); holder.mainUserIdRest.setText(userIdSplit[1]);
mainUserIdRest.setVisibility(View.VISIBLE); holder.mainUserIdRest.setVisibility(View.VISIBLE);
} else { } else {
mainUserIdRest.setVisibility(View.GONE); holder.mainUserIdRest.setVisibility(View.GONE);
} }
keyId.setText(entry.hexKeyId); holder.keyId.setText(entry.hexKeyId);
if (entry.fingerPrint != null) { if (entry.fingerPrint != null) {
fingerprint.setText(mActivity.getString(R.string.fingerprint) + " " + entry.fingerPrint); holder.fingerprint.setText(mActivity.getString(R.string.fingerprint) + " " + entry.fingerPrint);
fingerprint.setVisibility(View.VISIBLE); holder.fingerprint.setVisibility(View.VISIBLE);
} else { } 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) { if (entry.revoked) {
status.setText(R.string.revoked); holder.status.setText(R.string.revoked);
} else { } 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) { if (entry.userIds.size() == 1) {
ll.setVisibility(View.GONE); ll.setVisibility(View.GONE);
} else { } else {
@ -162,10 +175,10 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
} }
} }
CheckBox cBox = (CheckBox) view.findViewById(R.id.selected); CheckBox cBox = (CheckBox) convertView.findViewById(R.id.selected);
cBox.setChecked(entry.isSelected()); cBox.setChecked(entry.isSelected());
return view; return convertView;
} }
} }

View File

@ -6,7 +6,9 @@
android:paddingRight="16dp" android:paddingRight="16dp"
android:stretchColumns="1" > android:stretchColumns="1" >
<TableRow> <TableRow
android:layout_marginBottom="5dip"
>
<TextView <TextView
android:id="@+id/passphrase_label_passphrase" android:id="@+id/passphrase_label_passphrase"
@ -24,7 +26,9 @@
android:padding="4dp" /> android:padding="4dp" />
</TableRow> </TableRow>
<TableRow> <TableRow
android:layout_marginBottom="10dip"
>
<TextView <TextView
android:id="@+id/passphrase_label_passphrase_again" android:id="@+id/passphrase_label_passphrase_again"

View File

@ -3,7 +3,7 @@
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto" xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" > android:orientation="vertical" >
<com.beardedhen.androidbootstrap.BootstrapButton <com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/select_secret_key_select_key_button" android:id="@+id/select_secret_key_select_key_button"
@ -28,28 +28,41 @@
android:paddingLeft="16dp" > android:paddingLeft="16dp" >
<!-- Has been made focusable to display error messages with setError --> <!-- Has been made focusable to display error messages with setError -->
<TextView
android:id="@+id/select_secret_key_master_key_hex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/api_settings_no_key"
/>
<TextView <TextView
android:id="@+id/select_secret_key_user_id" android:id="@+id/select_secret_key_user_id"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right" android:layout_gravity="left"
android:ellipsize="end" android:ellipsize="end"
android:focusable="true" android:focusable="true"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:singleLine="true" android:singleLine="true"
android:text="@string/api_settings_no_key" android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceMedium" /> android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView <TextView
android:id="@+id/select_secret_key_user_id_rest" android:id="@+id/select_secret_key_user_id_rest"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right" android:layout_gravity="left"
android:ellipsize="end" android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
android:text="" android:text=""
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -147,6 +147,7 @@
<string name="user_id_no_name">&lt;no name&gt;</string> <string name="user_id_no_name">&lt;no name&gt;</string>
<string name="none">&lt;none&gt;</string> <string name="none">&lt;none&gt;</string>
<string name="no_key">&lt;no key&gt;</string> <string name="no_key">&lt;no key&gt;</string>
<string name="no_email">&lt;No Email&gt;</string>
<string name="unknown_status"></string> <string name="unknown_status"></string>
<string name="can_encrypt">can encrypt</string> <string name="can_encrypt">can encrypt</string>
<string name="can_sign">can sign</string> <string name="can_sign">can sign</string>
@ -273,6 +274,7 @@
<string name="error_master_key_must_not_be_el_gamal">the master key cannot be an ElGamal key</string> <string name="error_master_key_must_not_be_el_gamal">the master key cannot be an ElGamal key</string>
<string name="error_unknown_algorithm_choice">unknown algorithm choice</string> <string name="error_unknown_algorithm_choice">unknown algorithm choice</string>
<string name="error_user_id_needs_a_name">you need to specify a name</string> <string name="error_user_id_needs_a_name">you need to specify a name</string>
<string name="error_user_id_no_email">no email found</string>
<string name="error_user_id_needs_an_email_address">you need to specify an email address</string> <string name="error_user_id_needs_an_email_address">you need to specify an email address</string>
<string name="error_key_needs_a_user_id">need at least one user id</string> <string name="error_key_needs_a_user_id">need at least one user id</string>
<string name="error_main_user_id_must_not_be_empty">main user id must not be empty</string> <string name="error_main_user_id_must_not_be_empty">main user id must not be empty</string>