From a90b748611126cd122e39ef944f4c268798419f0 Mon Sep 17 00:00:00 2001 From: Ashley Hughes Date: Sun, 2 Feb 2014 23:56:53 +0000 Subject: [PATCH] set checkboxes from key properties --- .../keychain/ui/widget/KeyEditor.java | 74 +++++++++---------- .../src/main/res/layout/edit_key_key_item.xml | 17 +++-- 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 16e868a2c..f845b53a7 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -39,9 +39,12 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.CheckBox; import android.widget.DatePicker; import android.widget.LinearLayout; import android.widget.Spinner; +import android.widget.TableLayout; +import android.widget.TableRow; import android.widget.TextView; import com.beardedhen.androidbootstrap.BootstrapButton; @@ -59,6 +62,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { TextView mCreationDate; BootstrapButton mExpiryDateButton; GregorianCalendar mExpiryDate; + CheckBox mChkCertify; + CheckBox mChkSign; + CheckBox mChkEncrypt; + CheckBox mChkAuthenticate; private int mDatePickerResultCount = 0; private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() { @@ -89,21 +96,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { mKeyId = (TextView) findViewById(R.id.keyId); mCreationDate = (TextView) findViewById(R.id.creation); mExpiryDateButton = (BootstrapButton) findViewById(R.id.expiry); - //mUsage = (Spinner) findViewById(R.id.usage); - //Choice choices[] = { - // new Choice(Id.choice.usage.sign_only, getResources().getString( - // R.string.choice_sign_only)), - // new Choice(Id.choice.usage.encrypt_only, getResources().getString( - // R.string.choice_encrypt_only)), - // new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString( - // R.string.choice_sign_and_encrypt)), }; - //ArrayAdapter adapter = new ArrayAdapter(getContext(), - // android.R.layout.simple_spinner_item, choices); - //adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - //mUsage.setAdapter(adapter); mDeleteButton = (BootstrapButton) findViewById(R.id.delete); mDeleteButton.setOnClickListener(this); + mChkCertify = (CheckBox) findViewById(R.id.chkCertify); + mChkSign = (CheckBox) findViewById(R.id.chkSign); + mChkEncrypt = (CheckBox) findViewById(R.id.chkEncrypt); + mChkAuthenticate = (CheckBox) findViewById(R.id.chkAuthenticate); setExpiryDate(null); @@ -139,8 +138,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { public void setCanEdit(boolean bCanEdit) { if (!bCanEdit) { mDeleteButton.setVisibility(View.INVISIBLE); - //mUsage.setEnabled(false); mExpiryDateButton.setEnabled(false); + mChkSign.setEnabled(false); //certify is always disabled + mChkEncrypt.setEnabled(false); + mChkAuthenticate.setEnabled(false); } } @@ -160,17 +161,26 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { Vector choices = new Vector(); boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT); boolean isDSAKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.DSA); - if (!isElGamalKey) { - //choices.add(new Choice(Id.choice.usage.sign_only, getResources().getString( - // R.string.choice_sign_only))); + if (isElGamalKey) { + mChkSign.setVisibility(View.INVISIBLE); + TableLayout table = (TableLayout)findViewById(R.id.table_keylayout); + TableRow row = (TableRow)findViewById(R.id.row_sign); + table.removeView(row); } - if (!mIsMasterKey && !isDSAKey) { - //choices.add(new Choice(Id.choice.usage.encrypt_only, getResources().getString( - // R.string.choice_encrypt_only))); + if (isDSAKey) { + mChkEncrypt.setVisibility(View.INVISIBLE); + TableLayout table = (TableLayout)findViewById(R.id.table_keylayout); + TableRow row = (TableRow)findViewById(R.id.row_encrypt); + table.removeView(row); } - if (!isElGamalKey && !isDSAKey) { - //choices.add(new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString( - // R.string.choice_sign_and_encrypt))); + if (!mIsMasterKey) { + mChkCertify.setVisibility(View.INVISIBLE); + TableLayout table = (TableLayout)findViewById(R.id.table_keylayout); + TableRow row = (TableRow)findViewById(R.id.row_certify); + table.removeView(row); + } else { + TextView mLabelUsage2= (TextView) findViewById(R.id.label_usage2); + mLabelUsage2.setVisibility(View.INVISIBLE); } ArrayAdapter adapter = new ArrayAdapter(getContext(), @@ -180,21 +190,11 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { // Set value in choice dropdown to key int selectId = 0; - if (PgpKeyHelper.isEncryptionKey(key)) { - if (PgpKeyHelper.isSigningKey(key)) { - selectId = Id.choice.usage.sign_and_encrypt; - } else { - selectId = Id.choice.usage.encrypt_only; - } - } else { - // set usage if it is predefined - if (usage != -1) { - selectId = usage; - } else { - selectId = Id.choice.usage.sign_only; - } - - } + if (key.isMasterKey()) + mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key)); + mChkSign.setChecked(PgpKeyHelper.isSigningKey(key)); + mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key)); + // TODO: use usage argument? for (int i = 0; i < choices.size(); ++i) { if (choices.get(i).getId() == selectId) { diff --git a/OpenPGP-Keychain/src/main/res/layout/edit_key_key_item.xml b/OpenPGP-Keychain/src/main/res/layout/edit_key_key_item.xml index ef913b039..499fd5aa9 100644 --- a/OpenPGP-Keychain/src/main/res/layout/edit_key_key_item.xml +++ b/OpenPGP-Keychain/src/main/res/layout/edit_key_key_item.xml @@ -11,6 +11,7 @@ android:orientation="horizontal" > - + - + + android:paddingRight="10dip" + android:text="@string/label_usage" /> - + - +