Much more usable sign activity

This commit is contained in:
Dominik Schürmann
2014-01-18 19:54:27 +01:00
parent 47e3bd6d65
commit 46291d6b3e
5 changed files with 105 additions and 90 deletions

View File

@@ -54,32 +54,6 @@ public class SelectSecretKeyLayoutFragment extends Fragment {
mCallback = callback;
}
/**
* Inflate the layout for this fragment
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.select_secret_key_layout_fragment, container, false);
mKeyUserId = (TextView) view.findViewById(R.id.select_secret_key_user_id);
mKeyUserIdRest = (TextView) view.findViewById(R.id.select_secret_key_user_id_rest);
mSelectKeyButton = (BootstrapButton) view
.findViewById(R.id.select_secret_key_select_key_button);
mSelectKeyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
selectSecretKey();
}
});
return view;
}
private void selectSecretKey() {
Intent intent = new Intent(getActivity(), SelectSecretKeyActivity.class);
startActivityForResult(intent, REQUEST_CODE_SELECT_KEY);
}
public void selectKey(long secretKeyId) {
if (secretKeyId == Id.key.none) {
mKeyUserId.setText(R.string.api_settings_no_key);
@@ -105,6 +79,37 @@ public class SelectSecretKeyLayoutFragment extends Fragment {
}
}
public void setError(String error) {
mKeyUserId.requestFocus();
mKeyUserId.setError(error);
}
/**
* Inflate the layout for this fragment
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.select_secret_key_layout_fragment, container, false);
mKeyUserId = (TextView) view.findViewById(R.id.select_secret_key_user_id);
mKeyUserIdRest = (TextView) view.findViewById(R.id.select_secret_key_user_id_rest);
mSelectKeyButton = (BootstrapButton) view
.findViewById(R.id.select_secret_key_select_key_button);
mSelectKeyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startSelectKeyActivity();
}
});
return view;
}
private void startSelectKeyActivity() {
Intent intent = new Intent(getActivity(), SelectSecretKeyActivity.class);
startActivityForResult(intent, REQUEST_CODE_SELECT_KEY);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode & 0xFFFF) {
@@ -116,6 +121,9 @@ public class SelectSecretKeyLayoutFragment extends Fragment {
selectKey(secretKeyId);
// remove displayed errors
mKeyUserId.setError(null);
// give value back to callback
mCallback.onKeySelected(secretKeyId);
}

View File

@@ -1,4 +1,5 @@
/*
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2011 Senecaso
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +22,6 @@ import java.util.Iterator;
import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.spongycastle.openpgp.PGPSignature;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
@@ -41,7 +41,6 @@ import android.os.Messenger;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
@@ -57,9 +56,10 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
*
* signs the specified public key with the specified secret master key
*/
public class SignKeyActivity extends SherlockFragmentActivity {
public class SignKeyActivity extends SherlockFragmentActivity implements
SelectSecretKeyLayoutFragment.SelectSecretKeyCallback {
public static final String EXTRA_KEY_ID = "keyId";
public static final String EXTRA_KEY_ID = "key_id";
private long mPubKeyId = 0;
private long mMasterKeyId = 0;
@@ -67,7 +67,8 @@ public class SignKeyActivity extends SherlockFragmentActivity {
private BootstrapButton mSignButton;
private CheckBox mUploadKeyCheckbox;
private Spinner mSelectKeyserverSpinner;
private BootstrapButton mSelectKeyButton;
private SelectSecretKeyLayoutFragment mSelectKeyFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -80,6 +81,10 @@ public class SignKeyActivity extends SherlockFragmentActivity {
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
mSelectKeyFragment = (SelectSecretKeyLayoutFragment) getSupportFragmentManager()
.findFragmentById(R.id.sign_key_select_key_fragment);
mSelectKeyFragment.setCallback(this);
mSelectKeyserverSpinner = (Spinner) findViewById(R.id.sign_key_keyserver);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, Preferences.getPreferences(this)
@@ -107,26 +112,24 @@ public class SignKeyActivity extends SherlockFragmentActivity {
});
mSignButton = (BootstrapButton) findViewById(R.id.sign_key_sign_button);
mSignButton.setEnabled(false); // disabled until the user selects a key to sign with
mSignButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mPubKeyId != 0) {
initiateSigning();
if (mMasterKeyId == 0) {
mSelectKeyFragment.setError(getString(R.string.select_key_to_sign));
} else {
initiateSigning();
}
}
}
});
mPubKeyId = getIntent().getLongExtra(EXTRA_KEY_ID, 0);
if (mPubKeyId == 0) {
finish(); // nothing to do if we dont know what key to sign
} else {
// kick off the SecretKey selection activity so the user chooses which key to sign with
// first
Intent intent = new Intent(this, SelectSecretKeyActivity.class);
intent.putExtra(SelectSecretKeyActivity.EXTRA_FILTER_CERTIFY, true);
startActivityForResult(intent, Id.request.secret_keys);
Log.e(Constants.TAG, "No pub key id given!");
finish();
}
}
@@ -188,7 +191,8 @@ public class SignKeyActivity extends SherlockFragmentActivity {
startSigning();
}
} else {
Toast.makeText(this, "Key has already been signed", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.key_has_already_been_signed, Toast.LENGTH_SHORT)
.show();
setResult(RESULT_CANCELED);
finish();
@@ -226,8 +230,7 @@ public class SignKeyActivity extends SherlockFragmentActivity {
Toast.LENGTH_SHORT).show();
// check if we need to send the key to the server or not
CheckBox sendKey = (CheckBox) findViewById(R.id.sign_key_upload_checkbox);
if (sendKey.isChecked()) {
if (mUploadKeyCheckbox.isChecked()) {
/*
* upload the newly signed key to the key server
*/
@@ -295,25 +298,11 @@ public class SignKeyActivity extends SherlockFragmentActivity {
startService(intent);
}
/**
* callback from select key fragment
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case Id.request.secret_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
mMasterKeyId = bundle.getLong(SelectSecretKeyActivity.RESULT_EXTRA_MASTER_KEY_ID);
// re-enable the sign button so the user can initiate the sign process
Button sign = (Button) findViewById(R.id.sign_key_sign_button);
sign.setEnabled(true);
}
break;
}
default: {
super.onActivityResult(requestCode, resultCode, data);
}
}
public void onKeySelected(long secretKeyId) {
mMasterKeyId = secretKeyId;
}
}