extra constants moved into coresponding activities

This commit is contained in:
Dominik 2012-06-20 15:55:36 +03:00
parent c5ed6ce6f7
commit 47f88cdf4b
18 changed files with 153 additions and 130 deletions

View File

@ -21,8 +21,8 @@ import android.os.Environment;
public final class Constants {
public static final String TAG = "APG";
public static final String PACKAGE_NAME = "org.thialfihar.android.apg";
public static final String PACKAGE_NAME = "org.thialfihar.android.apg";
/*
* TODO:
@ -35,7 +35,6 @@ public final class Constants {
*/
public static final String INTENT_PREFIX = "org.thialfihar.android.apg.intent.";
public static final class path {
public static final String APP_DIR = Environment.getExternalStorageDirectory() + "/APG";
}

View File

@ -143,7 +143,7 @@ import java.util.regex.Pattern;
/**
* TODO:
*
* - Externalize the constants
* - Externalize the authority and content uri constants
*
* - Separate this file into different helpers
*
@ -155,32 +155,6 @@ public class PGPHelper {
Security.addProvider(new BouncyCastleProvider());
}
public static final String EXTRA_TEXT = "text";
public static final String EXTRA_DATA = "data";
public static final String EXTRA_ERROR = "error";
public static final String EXTRA_DECRYPTED_MESSAGE = "decryptedMessage";
public static final String EXTRA_DECRYPTED_DATA = "decryptedData";
public static final String EXTRA_ENCRYPTED_MESSAGE = "encryptedMessage";
public static final String EXTRA_ENCRYPTED_DATA = "encryptedData";
public static final String EXTRA_RESULT_URI = "resultUri";
public static final String EXTRA_SIGNATURE_DATA = "signatureData";
public static final String EXTRA_SIGNATURE_TEXT = "signatureText";
public static final String EXTRA_SIGNATURE_KEY_ID = "signatureKeyId";
public static final String EXTRA_USER_ID = "userId";
public static final String EXTRA_USER_IDS = "userIds";
public static final String EXTRA_KEY_ID = "keyId";
public static final String EXTRA_REPLY_TO = "replyTo";
public static final String EXTRA_SEND_TO = "sendTo";
public static final String EXTRA_SUBJECT = "subject";
public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds";
public static final String EXTRA_SELECTION = "selection";
public static final String EXTRA_ASCII_ARMOUR = "asciiArmour";
public static final String EXTRA_BINARY = "binary";
public static final String EXTRA_KEY_SERVERS = "keyServers";
public static final String EXTRA_EXPECTED_FINGERPRINT = "expectedFingerprint";
public static final String EXTRA_NO_PASSPHRASE = "noPassphrase";
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generateDefaultKeys";
public static final String AUTHORITY = DataProvider.AUTHORITY;
public static final Uri CONTENT_URI_SECRET_KEY_RINGS = Uri.parse("content://" + AUTHORITY

View File

@ -275,7 +275,7 @@ public class BaseActivity extends SherlockFragmentActivity implements Runnable,
case Id.request.secret_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
setSecretKeyId(bundle.getLong(PGPHelper.EXTRA_KEY_ID));
setSecretKeyId(bundle.getLong(SelectSecretKeyListActivity.EXTRA_KEY_ID));
} else {
setSecretKeyId(Id.key.none);
}

View File

@ -75,6 +75,13 @@ public class DecryptActivity extends SherlockFragmentActivity {
public static final String ACTION_DECRYPT_AND_RETURN = Constants.INTENT_PREFIX
+ "DECRYPT_AND_RETURN";
// possible extra keys
public static final String EXTRA_TEXT = "text";
public static final String EXTRA_DATA = "data";
public static final String EXTRA_REPLY_TO = "replyTo";
public static final String EXTRA_SUBJECT = "subject";
public static final String EXTRA_BINARY = "binary";
private long mSignatureKeyId = 0;
private Intent mIntent;
@ -96,9 +103,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
private ImageView mSourcePrevious = null;
private ImageView mSourceNext = null;
// private Button mDecryptButton = null;
// private Button mReplyButton = null;
private boolean mDecryptEnabled = true;
private String mDecryptString = "";
private boolean mReplyEnabled = true;
@ -117,9 +121,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
private byte[] mData = null;
private boolean mReturnBinary = false;
// private DataSource mDataSource = null;
// private DataDestination mDataDestination = null;
private long mUnknownSignatureKeyId = 0;
private long mSecretKeyId = Id.key.none;
@ -288,11 +289,11 @@ public class DecryptActivity extends SherlockFragmentActivity {
Log.d(Constants.TAG, "got extras");
}
mData = extras.getByteArray(PGPHelper.EXTRA_DATA);
mData = extras.getByteArray(EXTRA_DATA);
String textData = null;
if (mData == null) {
Log.d(Constants.TAG, "EXTRA_DATA was null");
textData = extras.getString(PGPHelper.EXTRA_TEXT);
textData = extras.getString(EXTRA_TEXT);
} else {
Log.d(Constants.TAG, "Got data from EXTRA_DATA");
}
@ -322,8 +323,8 @@ public class DecryptActivity extends SherlockFragmentActivity {
}
}
}
mReplyTo = extras.getString(PGPHelper.EXTRA_REPLY_TO);
mSubject = extras.getString(PGPHelper.EXTRA_SUBJECT);
mReplyTo = extras.getString(EXTRA_REPLY_TO);
mSubject = extras.getString(EXTRA_SUBJECT);
} else if (ACTION_DECRYPT_FILE.equals(mIntent.getAction())) {
mInputFilename = mIntent.getDataString();
if ("file".equals(mIntent.getScheme())) {
@ -343,11 +344,11 @@ public class DecryptActivity extends SherlockFragmentActivity {
extras = new Bundle();
}
mReturnBinary = extras.getBoolean(PGPHelper.EXTRA_BINARY, false);
mReturnBinary = extras.getBoolean(EXTRA_BINARY, false);
if (mContentUri == null) {
mData = extras.getByteArray(PGPHelper.EXTRA_DATA);
String data = extras.getString(PGPHelper.EXTRA_TEXT);
mData = extras.getByteArray(EXTRA_DATA);
String data = extras.getString(EXTRA_TEXT);
if (data != null) {
Matcher matcher = PGPHelper.PGP_MESSAGE.matcher(data);
if (matcher.matches()) {
@ -402,7 +403,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
if (key != null) {
Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class);
intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
intent.putExtra(PGPHelper.EXTRA_KEY_ID, mSignatureKeyId);
intent.putExtra(KeyServerQueryActivity.EXTRA_KEY_ID, mSignatureKeyId);
startActivity(intent);
}
}
@ -633,11 +634,11 @@ public class DecryptActivity extends SherlockFragmentActivity {
String data = mMessage.getText().toString();
data = data.replaceAll("(?m)^", "> ");
data = "\n\n" + data;
intent.putExtra(PGPHelper.EXTRA_TEXT, data);
intent.putExtra(PGPHelper.EXTRA_SUBJECT, "Re: " + mSubject);
intent.putExtra(PGPHelper.EXTRA_SEND_TO, mReplyTo);
intent.putExtra(PGPHelper.EXTRA_SIGNATURE_KEY_ID, getSecretKeyId());
intent.putExtra(PGPHelper.EXTRA_ENCRYPTION_KEY_IDS, new long[] { mSignatureKeyId });
intent.putExtra(EncryptActivity.EXTRA_TEXT, data);
intent.putExtra(EncryptActivity.EXTRA_SUBJECT, "Re: " + mSubject);
intent.putExtra(EncryptActivity.EXTRA_SEND_TO, mReplyTo);
intent.putExtra(EncryptActivity.EXTRA_SIGNATURE_KEY_ID, getSecretKeyId());
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, new long[] { mSignatureKeyId });
startActivity(intent);
}
@ -1044,7 +1045,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
removeDialog(Id.dialog.lookup_unknown_key);
Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class);
intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
intent.putExtra(PGPHelper.EXTRA_KEY_ID, mUnknownSignatureKeyId);
intent.putExtra(KeyServerQueryActivity.EXTRA_KEY_ID, mUnknownSignatureKeyId);
startActivityForResult(intent, Id.request.look_up_key_id);
}
});

View File

@ -69,6 +69,12 @@ public class EditKeyActivity extends SherlockFragmentActivity {
public static final String ACTION_CREATE_KEY = Constants.INTENT_PREFIX + "CREATE_KEY";
public static final String ACTION_EDIT_KEY = Constants.INTENT_PREFIX + "EDIT_KEY";
// possible extra keys
public static final String EXTRA_USER_IDS = "userIds";
public static final String EXTRA_NO_PASSPHRASE = "noPassphrase";
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generateDefaultKeys";
public static final String EXTRA_KEY_ID = "keyId";
private Intent mIntent = null;
private ActionBar mActionBar;
@ -166,14 +172,14 @@ public class EditKeyActivity extends SherlockFragmentActivity {
if (extras != null) {
// if userId is given, prefill the fields
if (extras.containsKey(PGPHelper.EXTRA_USER_IDS)) {
if (extras.containsKey(EXTRA_USER_IDS)) {
Log.d(Constants.TAG, "UserIds are given!");
mUserIds.add(extras.getString(PGPHelper.EXTRA_USER_IDS));
mUserIds.add(extras.getString(EXTRA_USER_IDS));
}
// if no passphrase is given
if (extras.containsKey(PGPHelper.EXTRA_NO_PASSPHRASE)) {
boolean noPassphrase = extras.getBoolean(PGPHelper.EXTRA_NO_PASSPHRASE);
if (extras.containsKey(EXTRA_NO_PASSPHRASE)) {
boolean noPassphrase = extras.getBoolean(EXTRA_NO_PASSPHRASE);
if (noPassphrase) {
// check "no passphrase" checkbox and remove button
mNoPassphrase.setChecked(true);
@ -182,9 +188,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
}
// generate key
if (extras.containsKey(PGPHelper.EXTRA_GENERATE_DEFAULT_KEYS)) {
boolean generateDefaultKeys = extras
.getBoolean(PGPHelper.EXTRA_GENERATE_DEFAULT_KEYS);
if (extras.containsKey(EXTRA_GENERATE_DEFAULT_KEYS)) {
boolean generateDefaultKeys = extras.getBoolean(EXTRA_GENERATE_DEFAULT_KEYS);
if (generateDefaultKeys) {
// build layout in handler after generating keys not directly in onCreate
@ -264,8 +269,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
if (extras != null) {
if (extras.containsKey(PGPHelper.EXTRA_KEY_ID)) {
long keyId = mIntent.getExtras().getLong(PGPHelper.EXTRA_KEY_ID);
if (extras.containsKey(EXTRA_KEY_ID)) {
long keyId = mIntent.getExtras().getLong(EXTRA_KEY_ID);
if (keyId != 0) {
PGPSecretKey masterKey = null;

View File

@ -76,6 +76,15 @@ public class EncryptActivity extends SherlockFragmentActivity {
public static final String ACTION_GENERATE_SIGNATURE = Constants.INTENT_PREFIX
+ "GENERATE_SIGNATURE";
// possible extra keys
public static final String EXTRA_TEXT = "text";
public static final String EXTRA_DATA = "data";
public static final String EXTRA_ASCII_ARMOUR = "asciiArmour";
public static final String EXTRA_SEND_TO = "sendTo";
public static final String EXTRA_SUBJECT = "subject";
public static final String EXTRA_SIGNATURE_KEY_ID = "signatureKeyId";
public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds";
private Intent mIntent = null;
private String mSubject = null;
private String mSendTo = null;
@ -365,21 +374,21 @@ public class EncryptActivity extends SherlockFragmentActivity {
mAsciiArmourDemand = false;
}
if (extras.containsKey(PGPHelper.EXTRA_ASCII_ARMOUR)) {
mAsciiArmourDemand = extras.getBoolean(PGPHelper.EXTRA_ASCII_ARMOUR, true);
if (extras.containsKey(EXTRA_ASCII_ARMOUR)) {
mAsciiArmourDemand = extras.getBoolean(EXTRA_ASCII_ARMOUR, true);
mOverrideAsciiArmour = true;
mAsciiArmour.setChecked(mAsciiArmourDemand);
}
mData = extras.getByteArray(PGPHelper.EXTRA_DATA);
mData = extras.getByteArray(EXTRA_DATA);
String textData = null;
if (mData == null) {
textData = extras.getString(PGPHelper.EXTRA_TEXT);
textData = extras.getString(EXTRA_TEXT);
}
mSendTo = extras.getString(PGPHelper.EXTRA_SEND_TO);
mSubject = extras.getString(PGPHelper.EXTRA_SUBJECT);
long signatureKeyId = extras.getLong(PGPHelper.EXTRA_SIGNATURE_KEY_ID);
long encryptionKeyIds[] = extras.getLongArray(PGPHelper.EXTRA_ENCRYPTION_KEY_IDS);
mSendTo = extras.getString(EXTRA_SEND_TO);
mSubject = extras.getString(EXTRA_SUBJECT);
long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
long encryptionKeyIds[] = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);
if (signatureKeyId != 0) {
PGPSecretKeyRing keyRing = PGPHelper.getSecretKeyRing(signatureKeyId);
PGPSecretKey masterKey = null;
@ -964,7 +973,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
initialKeyIds[i] = keyIds.get(i);
}
}
intent.putExtra(PGPHelper.EXTRA_SELECTION, initialKeyIds);
intent.putExtra(SelectPublicKeyListActivity.EXTRA_SELECTION, initialKeyIds);
startActivityForResult(intent, Id.request.public_keys);
}
@ -1007,7 +1016,8 @@ public class EncryptActivity extends SherlockFragmentActivity {
case Id.request.public_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
mEncryptionKeyIds = bundle.getLongArray(PGPHelper.EXTRA_SELECTION);
mEncryptionKeyIds = bundle
.getLongArray(SelectPublicKeyListActivity.EXTRA_SELECTION);
}
updateView();
break;
@ -1016,7 +1026,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
case Id.request.secret_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
setSecretKeyId(bundle.getLong(PGPHelper.EXTRA_KEY_ID));
setSecretKeyId(bundle.getLong(SelectSecretKeyListActivity.EXTRA_KEY_ID));
} else {
setSecretKeyId(Id.key.none);
}

View File

@ -43,6 +43,11 @@ public class ImportFromQRCodeActivity extends BaseActivity {
public static final String IMPORT_FROM_QR_CODE = Constants.INTENT_PREFIX
+ "IMPORT_FROM_QR_CODE";
public static final String EXTRA_KEY_ID = "keyId";
// TODO: remove when using new intentservice:
public static final String EXTRA_ERROR = "error";
private static final String TAG = "ImportFromQRCodeActivity";
private final Bundle status = new Bundle();
@ -64,12 +69,8 @@ public class ImportFromQRCodeActivity extends BaseActivity {
try {
// TODO: display some sort of spinner here while the user waits
HkpKeyServer server = new HkpKeyServer(mPreferences.getKeyServers()[0]); // TODO:
// there
// should
// be
// only
// 1
// TODO: there should be only 1
HkpKeyServer server = new HkpKeyServer(mPreferences.getKeyServers()[0]);
String encodedKey = server.get(keyId);
PGPKeyRing keyring = PGPHelper.decodeKeyRing(new ByteArrayInputStream(
@ -85,27 +86,27 @@ public class ImportFromQRCodeActivity extends BaseActivity {
int retval = PGPHelper.storeKeyRingInCache(publicKeyRing);
if (retval != Id.return_value.ok
&& retval != Id.return_value.updated) {
status.putString(PGPHelper.EXTRA_ERROR,
status.putString(EXTRA_ERROR,
"Failed to store signed key in local cache");
} else {
Intent intent = new Intent(ImportFromQRCodeActivity.this,
SignKeyActivity.class);
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyId);
intent.putExtra(EXTRA_KEY_ID, keyId);
startActivityForResult(intent, Id.request.sign_key);
}
} else {
status.putString(
PGPHelper.EXTRA_ERROR,
EXTRA_ERROR,
"Scanned fingerprint does NOT match the fingerprint of the received key. You shouldnt trust this key.");
}
}
} catch (QueryException e) {
Log.e(TAG, "Failed to query KeyServer", e);
status.putString(PGPHelper.EXTRA_ERROR, "Failed to query KeyServer");
status.putString(EXTRA_ERROR, "Failed to query KeyServer");
status.putInt(Constants.extras.STATUS, Id.message.done);
} catch (IOException e) {
Log.e(TAG, "Failed to query KeyServer", e);
status.putString(PGPHelper.EXTRA_ERROR, "Failed to query KeyServer");
status.putString(EXTRA_ERROR, "Failed to query KeyServer");
status.putInt(Constants.extras.STATUS, Id.message.done);
}
}
@ -162,7 +163,7 @@ public class ImportFromQRCodeActivity extends BaseActivity {
super.doneCallback(msg);
Bundle data = msg.getData();
String error = data.getString(PGPHelper.EXTRA_ERROR);
String error = data.getString(EXTRA_ERROR);
if (error != null) {
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
.show();

View File

@ -72,6 +72,11 @@ public class KeyListActivity extends BaseActivity {
public static final String ACTION_IMPORT = Constants.INTENT_PREFIX + "IMPORT";
public static final String EXTRA_TEXT = "text";
// TODO: remove when using new intentservice:
public static final String EXTRA_ERROR = "error";
protected ExpandableListView mList;
protected KeyListAdapter mListAdapter;
protected View mFilterLayout;
@ -146,7 +151,7 @@ public class KeyListActivity extends BaseActivity {
if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
mImportFilename = Uri.decode(intent.getDataString().replace("file://", ""));
} else {
mImportData = intent.getStringExtra(PGPHelper.EXTRA_TEXT);
mImportData = intent.getStringExtra(EXTRA_TEXT);
}
importKeys();
}
@ -373,7 +378,7 @@ public class KeyListActivity extends BaseActivity {
}
if (error != null) {
data.putString(PGPHelper.EXTRA_ERROR, error);
data.putString(EXTRA_ERROR, error);
}
msg.setData(data);
@ -401,7 +406,7 @@ public class KeyListActivity extends BaseActivity {
case Id.message.import_done: {
removeDialog(Id.dialog.importing);
String error = data.getString(PGPHelper.EXTRA_ERROR);
String error = data.getString(EXTRA_ERROR);
if (error != null) {
Toast.makeText(KeyListActivity.this, getString(R.string.errorMessage, error),
Toast.LENGTH_SHORT).show();
@ -448,7 +453,7 @@ public class KeyListActivity extends BaseActivity {
case Id.message.export_done: {
removeDialog(Id.dialog.exporting);
String error = data.getString(PGPHelper.EXTRA_ERROR);
String error = data.getString(EXTRA_ERROR);
if (error != null) {
Toast.makeText(KeyListActivity.this, getString(R.string.errorMessage, error),
Toast.LENGTH_SHORT).show();

View File

@ -47,6 +47,11 @@ public class KeyServerExportActivity extends BaseActivity {
public static final String ACTION_EXPORT_KEY_TO_SERVER = Constants.INTENT_PREFIX
+ "EXPORT_KEY_TO_SERVER";
public static final String EXTRA_KEY_ID = "keyId";
// TODO: remove when using new intentservice:
public static final String EXTRA_ERROR = "error";
private Button export;
private Spinner keyServer;
@ -103,7 +108,7 @@ public class KeyServerExportActivity extends BaseActivity {
HkpKeyServer server = new HkpKeyServer((String) keyServer.getSelectedItem());
int keyRingId = getIntent().getIntExtra(PGPHelper.EXTRA_KEY_ID, -1);
int keyRingId = getIntent().getIntExtra(EXTRA_KEY_ID, -1);
PGPKeyRing keyring = PGPHelper.getKeyRing(keyRingId);
if (keyring != null && keyring instanceof PGPPublicKeyRing) {
@ -116,7 +121,7 @@ public class KeyServerExportActivity extends BaseActivity {
data.putInt(Constants.extras.STATUS, Id.message.export_done);
if (error != null) {
data.putString(PGPHelper.EXTRA_ERROR, error);
data.putString(EXTRA_ERROR, error);
}
msg.setData(data);
@ -128,7 +133,7 @@ public class KeyServerExportActivity extends BaseActivity {
super.doneCallback(msg);
Bundle data = msg.getData();
String error = data.getString(PGPHelper.EXTRA_ERROR);
String error = data.getString(EXTRA_ERROR);
if (error != null) {
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
.show();

View File

@ -60,6 +60,12 @@ public class KeyServerQueryActivity extends BaseActivity {
public static final String ACTION_LOOK_UP_KEY_ID_AND_RETURN = Constants.INTENT_PREFIX
+ "LOOK_UP_KEY_ID_AND_RETURN";
public static final String EXTRA_KEY_ID = "keyId";
// TODO: remove when using new intentservice:
public static final String EXTRA_ERROR = "error";
public static final String EXTRA_TEXT = "text";
private ListView mList;
private EditText mQuery;
private Button mSearch;
@ -129,7 +135,7 @@ public class KeyServerQueryActivity extends BaseActivity {
Intent intent = getIntent();
if (ACTION_LOOK_UP_KEY_ID.equals(intent.getAction())
|| ACTION_LOOK_UP_KEY_ID_AND_RETURN.equals(intent.getAction())) {
long keyId = intent.getLongExtra(PGPHelper.EXTRA_KEY_ID, 0);
long keyId = intent.getLongExtra(EXTRA_KEY_ID, 0);
if (keyId != 0) {
String query = "0x" + PGPHelper.keyToHex(keyId);
mQuery.setText(query);
@ -185,7 +191,7 @@ public class KeyServerQueryActivity extends BaseActivity {
data.putInt(Constants.extras.STATUS, Id.message.done);
if (error != null) {
data.putString(PGPHelper.EXTRA_ERROR, error);
data.putString(EXTRA_ERROR, error);
}
msg.setData(data);
@ -199,7 +205,7 @@ public class KeyServerQueryActivity extends BaseActivity {
removeDialog(Id.dialog.querying);
Bundle data = msg.getData();
String error = data.getString(PGPHelper.EXTRA_ERROR);
String error = data.getString(EXTRA_ERROR);
if (error != null) {
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
.show();
@ -217,7 +223,7 @@ public class KeyServerQueryActivity extends BaseActivity {
if (ACTION_LOOK_UP_KEY_ID_AND_RETURN.equals(orgIntent.getAction())) {
if (mKeyData != null) {
Intent intent = new Intent();
intent.putExtra(PGPHelper.EXTRA_TEXT, mKeyData);
intent.putExtra(EXTRA_TEXT, mKeyData);
setResult(RESULT_OK, intent);
} else {
setResult(RESULT_CANCELED);
@ -227,7 +233,7 @@ public class KeyServerQueryActivity extends BaseActivity {
if (mKeyData != null) {
Intent intent = new Intent(this, PublicKeyListActivity.class);
intent.setAction(KeyListActivity.ACTION_IMPORT);
intent.putExtra(PGPHelper.EXTRA_TEXT, mKeyData);
intent.putExtra(KeyListActivity.EXTRA_TEXT, mKeyData);
startActivity(intent);
}
}
@ -320,7 +326,7 @@ public class KeyServerQueryActivity extends BaseActivity {
}
if (!second) {
View sep = new View(mActivity);
sep.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 1));
sep.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1));
sep.setBackgroundResource(android.R.drawable.divider_horizontal_dark);
ll.addView(sep);
}

View File

@ -151,9 +151,9 @@ public class MailListActivity extends ListActivity {
Intent intent = new Intent(MailListActivity.this, DecryptActivity.class);
intent.setAction(DecryptActivity.ACTION_DECRYPT);
Message message = (Message) ((MailboxAdapter) getListAdapter()).getItem(position);
intent.putExtra(PGPHelper.EXTRA_TEXT, message.data);
intent.putExtra(PGPHelper.EXTRA_SUBJECT, message.subject);
intent.putExtra(PGPHelper.EXTRA_REPLY_TO, message.replyTo);
intent.putExtra(DecryptActivity.EXTRA_TEXT, message.data);
intent.putExtra(DecryptActivity.EXTRA_SUBJECT, message.subject);
intent.putExtra(DecryptActivity.EXTRA_REPLY_TO, message.replyTo);
startActivity(intent);
}
});

View File

@ -195,7 +195,8 @@ public class PreferencesActivity extends SherlockPreferenceActivity {
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(PreferencesActivity.this,
PreferencesKeyServerActivity.class);
intent.putExtra(PGPHelper.EXTRA_KEY_SERVERS, mPreferences.getKeyServers());
intent.putExtra(PreferencesKeyServerActivity.EXTRA_KEY_SERVERS,
mPreferences.getKeyServers());
startActivityForResult(intent, Id.request.key_server_preference);
return false;
}
@ -209,7 +210,8 @@ public class PreferencesActivity extends SherlockPreferenceActivity {
if (resultCode == RESULT_CANCELED || data == null) {
return;
}
String servers[] = data.getStringArrayExtra(PGPHelper.EXTRA_KEY_SERVERS);
String servers[] = data
.getStringArrayExtra(PreferencesKeyServerActivity.EXTRA_KEY_SERVERS);
mPreferences.setKeyServers(servers);
mKeyServerPreference.setSummary(getResources().getString(R.string.nKeyServers,
servers.length));

View File

@ -41,6 +41,9 @@ import android.widget.TextView;
public class PreferencesKeyServerActivity extends SherlockActivity implements OnClickListener,
EditorListener {
public static final String EXTRA_KEY_SERVERS = "keyServers";
private LayoutInflater mInflater;
private ViewGroup mEditors;
private View mAdd;
@ -114,7 +117,7 @@ public class PreferencesKeyServerActivity extends SherlockActivity implements On
mAdd.setOnClickListener(this);
Intent intent = getIntent();
String servers[] = intent.getStringArrayExtra(PGPHelper.EXTRA_KEY_SERVERS);
String servers[] = intent.getStringArrayExtra(EXTRA_KEY_SERVERS);
if (servers != null) {
for (int i = 0; i < servers.length; ++i) {
KeyServerEditor view = (KeyServerEditor) mInflater.inflate(
@ -153,7 +156,7 @@ public class PreferencesKeyServerActivity extends SherlockActivity implements On
}
}
String[] dummy = new String[0];
data.putExtra(PGPHelper.EXTRA_KEY_SERVERS, servers.toArray(dummy));
data.putExtra(EXTRA_KEY_SERVERS, servers.toArray(dummy));
setResult(RESULT_OK, data);
finish();
}

View File

@ -25,6 +25,7 @@ import org.thialfihar.android.apg.helper.PGPHelper;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
@ -125,7 +126,7 @@ public class PublicKeyListActivity extends KeyListActivity {
Intent intent = new Intent(this, KeyServerQueryActivity.class);
intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID_AND_RETURN);
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyId);
intent.putExtra(KeyServerQueryActivity.EXTRA_KEY_ID, keyId);
startActivityForResult(intent, Id.request.look_up_key_id);
return true;
@ -137,7 +138,7 @@ public class PublicKeyListActivity extends KeyListActivity {
Intent intent = new Intent(this, KeyServerExportActivity.class);
intent.setAction(KeyServerExportActivity.ACTION_EXPORT_KEY_TO_SERVER);
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyRingId);
intent.putExtra(KeyServerExportActivity.EXTRA_KEY_ID, keyRingId);
startActivityForResult(intent, Id.request.export_to_server);
return true;
@ -158,7 +159,7 @@ public class PublicKeyListActivity extends KeyListActivity {
}
Intent intent = new Intent(this, SignKeyActivity.class);
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyId);
intent.putExtra(SignKeyActivity.EXTRA_KEY_ID, keyId);
startActivity(intent);
return true;
@ -175,13 +176,14 @@ public class PublicKeyListActivity extends KeyListActivity {
switch (requestCode) {
case Id.request.look_up_key_id: {
if (resultCode == RESULT_CANCELED || data == null
|| data.getStringExtra(PGPHelper.EXTRA_TEXT) == null) {
|| data.getStringExtra(KeyServerQueryActivity.EXTRA_TEXT) == null) {
return;
}
Intent intent = new Intent(this, PublicKeyListActivity.class);
intent.setAction(PublicKeyListActivity.ACTION_IMPORT);
intent.putExtra(PGPHelper.EXTRA_TEXT, data.getStringExtra(PGPHelper.EXTRA_TEXT));
intent.putExtra(PublicKeyListActivity.EXTRA_TEXT,
data.getStringExtra(KeyListActivity.EXTRA_TEXT));
handleIntent(intent);
break;
}

View File

@ -171,7 +171,7 @@ public class SecretKeyListActivity extends KeyListActivity implements OnChildCli
private void editKey() {
long keyId = ((KeyListAdapter) mList.getExpandableListAdapter()).getGroupId(mSelectedItem);
Intent intent = new Intent(EditKeyActivity.ACTION_EDIT_KEY);
intent.putExtra(PGPHelper.EXTRA_KEY_ID, keyId);
intent.putExtra(EditKeyActivity.EXTRA_KEY_ID, keyId);
startActivityForResult(intent, Id.message.edit_key);
}

View File

@ -43,6 +43,9 @@ public class SelectPublicKeyListActivity extends BaseActivity {
public static final String ACTION_SELECT_PUBLIC_KEYS = Constants.INTENT_PREFIX
+ "SELECT_PUBLIC_KEYS";
public static final String EXTRA_SELECTION = "selection";
public static final String EXTRA_USER_IDS = "userIds";
protected ListView mList;
protected SelectPublicKeyListAdapter mListAdapter;
protected View mFilterLayout;
@ -95,7 +98,7 @@ public class SelectPublicKeyListActivity extends BaseActivity {
}
long selectedKeyIds[] = null;
selectedKeyIds = intent.getLongArrayExtra(PGPHelper.EXTRA_SELECTION);
selectedKeyIds = intent.getLongArrayExtra(EXTRA_SELECTION);
if (selectedKeyIds == null) {
Vector<Long> vector = new Vector<Long>();
@ -157,8 +160,8 @@ public class SelectPublicKeyListActivity extends BaseActivity {
selectedKeyIds[i] = keys.get(i);
}
String userIdArray[] = new String[0];
data.putExtra(PGPHelper.EXTRA_SELECTION, selectedKeyIds);
data.putExtra(PGPHelper.EXTRA_USER_IDS, userIds.toArray(userIdArray));
data.putExtra(EXTRA_SELECTION, selectedKeyIds);
data.putExtra(EXTRA_USER_IDS, userIds.toArray(userIdArray));
setResult(RESULT_OK, data);
finish();
}

View File

@ -42,6 +42,9 @@ public class SelectSecretKeyListActivity extends BaseActivity {
public static final String ACTION_SELECT_SECRET_KEY = Constants.INTENT_PREFIX
+ "SELECT_SECRET_KEY";
public static final String EXTRA_USER_ID = "userId";
public static final String EXTRA_KEY_ID = "keyId";
protected ListView mList;
protected SelectSecretKeyListAdapter mListAdapter;
protected View mFilterLayout;
@ -68,8 +71,8 @@ public class SelectSecretKeyListActivity extends BaseActivity {
mList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent data = new Intent();
data.putExtra(PGPHelper.EXTRA_KEY_ID, id);
data.putExtra(PGPHelper.EXTRA_USER_ID, (String) mList.getItemAtPosition(position));
data.putExtra(EXTRA_KEY_ID, id);
data.putExtra(EXTRA_USER_ID, (String) mList.getItemAtPosition(position));
setResult(RESULT_OK, data);
finish();
}

View File

@ -60,7 +60,11 @@ import android.widget.Toast;
* signs the specified public key with the specified secret master key
*/
public class SignKeyActivity extends BaseActivity {
private static final String TAG = "SignKeyActivity";
public static final String EXTRA_KEY_ID = "keyId";
// TODO: remove when using new intentservice:
public static final String EXTRA_ERROR = "error";
private long pubKeyId = 0;
private long masterKeyId = 0;
@ -124,7 +128,7 @@ public class SignKeyActivity extends BaseActivity {
}
});
pubKeyId = getIntent().getLongExtra(PGPHelper.EXTRA_KEY_ID, 0);
pubKeyId = getIntent().getLongExtra(EXTRA_KEY_ID, 0);
if (pubKeyId == 0) {
finish(); // nothing to do if we dont know what key to sign
} else {
@ -170,7 +174,7 @@ public class SignKeyActivity extends BaseActivity {
final Bundle status = new Bundle();
Message msg = new Message();
status.putString(PGPHelper.EXTRA_ERROR, "Key has already been signed");
status.putString(EXTRA_ERROR, "Key has already been signed");
status.putInt(Constants.extras.STATUS, Id.message.done);
@ -210,7 +214,7 @@ public class SignKeyActivity extends BaseActivity {
try {
String passphrase = PGPHelper.getCachedPassPhrase(masterKeyId);
if (passphrase == null || passphrase.length() <= 0) {
status.putString(PGPHelper.EXTRA_ERROR, "Unable to obtain passphrase");
status.putString(EXTRA_ERROR, "Unable to obtain passphrase");
} else {
PGPPublicKeyRing pubring = PGPHelper.getPublicKeyRing(pubKeyId);
@ -249,27 +253,27 @@ public class SignKeyActivity extends BaseActivity {
// store the signed key in our local cache
int retval = PGPHelper.storeKeyRingInCache(pubring);
if (retval != Id.return_value.ok && retval != Id.return_value.updated) {
status.putString(PGPHelper.EXTRA_ERROR, "Failed to store signed key in local cache");
status.putString(EXTRA_ERROR, "Failed to store signed key in local cache");
}
}
} catch (PGPException e) {
Log.e(TAG, "Failed to sign key", e);
status.putString(PGPHelper.EXTRA_ERROR, "Failed to sign key");
Log.e(Constants.TAG, "Failed to sign key", e);
status.putString(EXTRA_ERROR, "Failed to sign key");
status.putInt(Constants.extras.STATUS, Id.message.done);
return;
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "Failed to sign key", e);
status.putString(PGPHelper.EXTRA_ERROR, "Failed to sign key");
Log.e(Constants.TAG, "Failed to sign key", e);
status.putString(EXTRA_ERROR, "Failed to sign key");
status.putInt(Constants.extras.STATUS, Id.message.done);
return;
} catch (NoSuchProviderException e) {
Log.e(TAG, "Failed to sign key", e);
status.putString(PGPHelper.EXTRA_ERROR, "Failed to sign key");
Log.e(Constants.TAG, "Failed to sign key", e);
status.putString(EXTRA_ERROR, "Failed to sign key");
status.putInt(Constants.extras.STATUS, Id.message.done);
return;
} catch (SignatureException e) {
Log.e(TAG, "Failed to sign key", e);
status.putString(PGPHelper.EXTRA_ERROR, "Failed to sign key");
Log.e(Constants.TAG, "Failed to sign key", e);
status.putString(EXTRA_ERROR, "Failed to sign key");
status.putInt(Constants.extras.STATUS, Id.message.done);
return;
}
@ -279,7 +283,7 @@ public class SignKeyActivity extends BaseActivity {
msg.setData(status);
sendMessage(msg);
if (status.containsKey(PGPHelper.EXTRA_ERROR)) {
if (status.containsKey(EXTRA_ERROR)) {
setResult(Id.return_value.error);
} else {
setResult(Id.return_value.ok);
@ -293,7 +297,7 @@ public class SignKeyActivity extends BaseActivity {
switch (requestCode) {
case Id.request.secret_keys: {
if (resultCode == RESULT_OK) {
masterKeyId = data.getLongExtra(PGPHelper.EXTRA_KEY_ID, 0);
masterKeyId = data.getLongExtra(EXTRA_KEY_ID, 0);
// re-enable the sign button so the user can initiate the sign process
Button sign = (Button) findViewById(R.id.sign);
@ -316,7 +320,7 @@ public class SignKeyActivity extends BaseActivity {
removeDialog(Id.dialog.signing);
Bundle data = msg.getData();
String error = data.getString(PGPHelper.EXTRA_ERROR);
String error = data.getString(EXTRA_ERROR);
if (error != null) {
Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT)
.show();