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.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<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.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<Choice> choices = new Vector<Choice>();
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<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
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) {

View File

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