set checkboxes from key properties

This commit is contained in:
Ashley Hughes 2014-02-02 23:56:53 +00:00
parent 212ee222c3
commit a90b748611
2 changed files with 49 additions and 42 deletions

View File

@ -39,9 +39,12 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.DatePicker; import android.widget.DatePicker;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView; import android.widget.TextView;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
@ -59,6 +62,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
TextView mCreationDate; TextView mCreationDate;
BootstrapButton mExpiryDateButton; BootstrapButton mExpiryDateButton;
GregorianCalendar mExpiryDate; GregorianCalendar mExpiryDate;
CheckBox mChkCertify;
CheckBox mChkSign;
CheckBox mChkEncrypt;
CheckBox mChkAuthenticate;
private int mDatePickerResultCount = 0; private int mDatePickerResultCount = 0;
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() { 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); mKeyId = (TextView) findViewById(R.id.keyId);
mCreationDate = (TextView) findViewById(R.id.creation); mCreationDate = (TextView) findViewById(R.id.creation);
mExpiryDateButton = (BootstrapButton) findViewById(R.id.expiry); 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<Choice> adapter = new ArrayAdapter<Choice>(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 = (BootstrapButton) findViewById(R.id.delete);
mDeleteButton.setOnClickListener(this); 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); setExpiryDate(null);
@ -139,8 +138,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
public void setCanEdit(boolean bCanEdit) { public void setCanEdit(boolean bCanEdit) {
if (!bCanEdit) { if (!bCanEdit) {
mDeleteButton.setVisibility(View.INVISIBLE); mDeleteButton.setVisibility(View.INVISIBLE);
//mUsage.setEnabled(false);
mExpiryDateButton.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<Choice> choices = new Vector<Choice>(); Vector<Choice> choices = new Vector<Choice>();
boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT); boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT);
boolean isDSAKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.DSA); boolean isDSAKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.DSA);
if (!isElGamalKey) { if (isElGamalKey) {
//choices.add(new Choice(Id.choice.usage.sign_only, getResources().getString( mChkSign.setVisibility(View.INVISIBLE);
// R.string.choice_sign_only))); TableLayout table = (TableLayout)findViewById(R.id.table_keylayout);
TableRow row = (TableRow)findViewById(R.id.row_sign);
table.removeView(row);
} }
if (!mIsMasterKey && !isDSAKey) { if (isDSAKey) {
//choices.add(new Choice(Id.choice.usage.encrypt_only, getResources().getString( mChkEncrypt.setVisibility(View.INVISIBLE);
// R.string.choice_encrypt_only))); TableLayout table = (TableLayout)findViewById(R.id.table_keylayout);
TableRow row = (TableRow)findViewById(R.id.row_encrypt);
table.removeView(row);
} }
if (!isElGamalKey && !isDSAKey) { if (!mIsMasterKey) {
//choices.add(new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString( mChkCertify.setVisibility(View.INVISIBLE);
// R.string.choice_sign_and_encrypt))); 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<Choice> adapter = new ArrayAdapter<Choice>(getContext(), ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(getContext(),
@ -180,21 +190,11 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
// Set value in choice dropdown to key // Set value in choice dropdown to key
int selectId = 0; int selectId = 0;
if (PgpKeyHelper.isEncryptionKey(key)) { if (key.isMasterKey())
if (PgpKeyHelper.isSigningKey(key)) { mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key));
selectId = Id.choice.usage.sign_and_encrypt; mChkSign.setChecked(PgpKeyHelper.isSigningKey(key));
} else { mChkEncrypt.setChecked(PgpKeyHelper.isEncryptionKey(key));
selectId = Id.choice.usage.encrypt_only; // TODO: use usage argument?
}
} else {
// set usage if it is predefined
if (usage != -1) {
selectId = usage;
} else {
selectId = Id.choice.usage.sign_only;
}
}
for (int i = 0; i < choices.size(); ++i) { for (int i = 0; i < choices.size(); ++i) {
if (choices.get(i).getId() == selectId) { if (choices.get(i).getId() == selectId) {

View File

@ -11,6 +11,7 @@
android:orientation="horizontal" > android:orientation="horizontal" >
<TableLayout <TableLayout
android:id="@+id/table_keylayout"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
@ -88,7 +89,8 @@
bootstrapbutton:bb_type="default" /> bootstrapbutton:bb_type="default" />
</TableRow> </TableRow>
<TableRow> <TableRow
android:id="@+id/row_certify">
<TextView <TextView
android:id="@+id/label_usage" android:id="@+id/label_usage"
@ -105,13 +107,16 @@
android:text="@string/flag_certify" /> android:text="@string/flag_certify" />
</TableRow> </TableRow>
<TableRow> <TableRow
android:id="@+id/row_sign">
<TextView <TextView
android:id="@+id/label_usage2"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:paddingRight="10dip" /> android:paddingRight="10dip"
android:text="@string/label_usage" />
<CheckBox <CheckBox
android:id="@+id/chkSign" android:id="@+id/chkSign"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -119,7 +124,8 @@
android:text="@string/flag_sign" /> android:text="@string/flag_sign" />
</TableRow> </TableRow>
<TableRow> <TableRow
android:id="@+id/row_encrypt">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -133,7 +139,8 @@
android:text="@string/flag_encrypt" /> android:text="@string/flag_encrypt" />
</TableRow> </TableRow>
<TableRow> <TableRow
android:id="@+id/row_authenticate">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"