use string constants for bundle keys, first Intent for k9mail

This commit is contained in:
Thialfihar 2010-05-31 23:15:20 +00:00
parent 74ab59cd52
commit 24a53d548b
13 changed files with 152 additions and 95 deletions

View File

@ -92,6 +92,9 @@
<intent-filter> <intent-filter>
<action android:name="org.thialfihar.android.apg.intent.DECRYPT" /> <action android:name="org.thialfihar.android.apg.intent.DECRYPT" />
<action android:name="org.thialfihar.android.apg.intent.DECRYPT_FILE" /> <action android:name="org.thialfihar.android.apg.intent.DECRYPT_FILE" />
<action android:name="org.thialfihar.android.apg.intent.DECRYPT_AND_RETURN" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/*"/>
</intent-filter> </intent-filter>
</activity> </activity>

View File

@ -100,8 +100,30 @@ public class Apg {
public static final String ENCRYPT = "org.thialfihar.android.apg.intent.ENCRYPT"; public static final String ENCRYPT = "org.thialfihar.android.apg.intent.ENCRYPT";
public static final String DECRYPT_FILE = "org.thialfihar.android.apg.intent.DECRYPT_FILE"; public static final String DECRYPT_FILE = "org.thialfihar.android.apg.intent.DECRYPT_FILE";
public static final String ENCRYPT_FILE = "org.thialfihar.android.apg.intent.ENCRYPT_FILE"; public static final String ENCRYPT_FILE = "org.thialfihar.android.apg.intent.ENCRYPT_FILE";
public static final String DECRYPT_AND_RETURN = "org.thialfihar.android.apg.intent.DECRYPT_AND_RETURN";
} }
public static final String EXTRA_DATA = "data";
public static final String EXTRA_STATUS = "status";
public static final String EXTRA_ERROR = "error";
public static final String EXTRA_DECRYPTED_MESSAGE = "decryptedMessage";
public static final String EXTRA_ENCRYPTED_MESSAGE = "decryptedMessage";
public static final String EXTRA_SIGNATURE = "signature";
public static final String EXTRA_SIGNATURE_KEY_ID = "signatureKeyId";
public static final String EXTRA_SIGNATURE_USER_ID = "signatureUserId";
public static final String EXTRA_SIGNATURE_SUCCESS = "signatureSuccess";
public static final String EXTRA_SIGNATURE_UNKNOWN = "signatureUnknown";
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_MESSAGE = "message";
public static final String EXTRA_PROGRESS = "progress";
public static final String EXTRA_MAX = "max";
public static final String EXTRA_ACCOUNT = "account";
public static String VERSION = "1.0.0"; public static String VERSION = "1.0.0";
public static String FULL_VERSION = "APG v" + VERSION; public static String FULL_VERSION = "APG v" + VERSION;
@ -1410,7 +1432,7 @@ public class Apg {
if (dataChunk instanceof PGPOnePassSignatureList) { if (dataChunk instanceof PGPOnePassSignatureList) {
progress.setProgress(R.string.progress_processingSignature, currentProgress, 100); progress.setProgress(R.string.progress_processingSignature, currentProgress, 100);
returnData.putBoolean("signature", true); returnData.putBoolean(EXTRA_SIGNATURE, true);
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk; PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
for (int i = 0; i < sigList.size(); ++i) { for (int i = 0; i < sigList.size(); ++i) {
signature = sigList.get(i); signature = sigList.get(i);
@ -1428,17 +1450,17 @@ public class Apg {
if (sigKeyRing != null) { if (sigKeyRing != null) {
userId = getMainUserId(getMasterKey(sigKeyRing)); userId = getMainUserId(getMasterKey(sigKeyRing));
} }
returnData.putString("signatureUserId", userId); returnData.putString(EXTRA_SIGNATURE_USER_ID, userId);
break; break;
} }
} }
returnData.putLong("signatureKeyId", signatureKeyId); returnData.putLong(EXTRA_SIGNATURE_KEY_ID, signatureKeyId);
if (signature != null) { if (signature != null) {
signature.initVerify(signatureKey, new BouncyCastleProvider()); signature.initVerify(signatureKey, new BouncyCastleProvider());
} else { } else {
returnData.putBoolean("signatureUnknown", true); returnData.putBoolean(EXTRA_SIGNATURE_UNKNOWN, true);
} }
dataChunk = plainFact.nextObject(); dataChunk = plainFact.nextObject();
@ -1470,7 +1492,7 @@ public class Apg {
try { try {
signature.update(buffer, 0, n); signature.update(buffer, 0, n);
} catch (SignatureException e) { } catch (SignatureException e) {
returnData.putBoolean("signatureSuccess", false); returnData.putBoolean(EXTRA_SIGNATURE_SUCCESS, false);
signature = null; signature = null;
} }
} }
@ -1490,9 +1512,9 @@ public class Apg {
PGPSignatureList signatureList = (PGPSignatureList) plainFact.nextObject(); PGPSignatureList signatureList = (PGPSignatureList) plainFact.nextObject();
PGPSignature messageSignature = (PGPSignature) signatureList.get(signatureIndex); PGPSignature messageSignature = (PGPSignature) signatureList.get(signatureIndex);
if (signature.verify(messageSignature)) { if (signature.verify(messageSignature)) {
returnData.putBoolean("signatureSuccess", true); returnData.putBoolean(EXTRA_SIGNATURE_SUCCESS, true);
} else { } else {
returnData.putBoolean("signatureSuccess", false); returnData.putBoolean(EXTRA_SIGNATURE_SUCCESS, false);
} }
} }
} }
@ -1545,7 +1567,7 @@ public class Apg {
byte[] clearText = out.toByteArray(); byte[] clearText = out.toByteArray();
outStream.write(clearText); outStream.write(clearText);
returnData.putBoolean("signature", true); returnData.putBoolean(EXTRA_SIGNATURE, true);
progress.setProgress(R.string.progress_processingSignature, 60, 100); progress.setProgress(R.string.progress_processingSignature, 60, 100);
PGPObjectFactory pgpFact = new PGPObjectFactory(aIn); PGPObjectFactory pgpFact = new PGPObjectFactory(aIn);
@ -1572,15 +1594,15 @@ public class Apg {
if (sigKeyRing != null) { if (sigKeyRing != null) {
userId = getMainUserId(getMasterKey(sigKeyRing)); userId = getMainUserId(getMasterKey(sigKeyRing));
} }
returnData.putString("signatureUserId", userId); returnData.putString(EXTRA_SIGNATURE_USER_ID, userId);
break; break;
} }
} }
returnData.putLong("signatureKeyId", signatureKeyId); returnData.putLong(EXTRA_SIGNATURE_KEY_ID, signatureKeyId);
if (signature == null) { if (signature == null) {
returnData.putBoolean("signatureUnknown", true); returnData.putBoolean(EXTRA_SIGNATURE_UNKNOWN, true);
progress.setProgress(R.string.progress_done, 100, 100); progress.setProgress(R.string.progress_done, 100, 100);
return returnData; return returnData;
} }
@ -1605,7 +1627,7 @@ public class Apg {
while (lookAhead != -1); while (lookAhead != -1);
} }
returnData.putBoolean("signatureSuccess", signature.verify()); returnData.putBoolean(EXTRA_SIGNATURE_SUCCESS, signature.verify());
progress.setProgress(R.string.progress_done, 100, 100); progress.setProgress(R.string.progress_done, 100, 100);
return returnData; return returnData;

View File

@ -292,7 +292,7 @@ public class BaseActivity extends Activity
case Id.request.secret_keys: { case Id.request.secret_keys: {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras(); Bundle bundle = data.getExtras();
setSecretKeyId(bundle.getLong("selectedKeyId")); setSecretKeyId(bundle.getLong(Apg.EXTRA_KEY_ID));
} else { } else {
setSecretKeyId(Id.key.none); setSecretKeyId(Id.key.none);
} }
@ -314,9 +314,9 @@ public class BaseActivity extends Activity
public void setProgress(int progress, int max) { public void setProgress(int progress, int max) {
Message msg = new Message(); Message msg = new Message();
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putInt("type", Id.message.progress_update); data.putInt(Apg.EXTRA_STATUS, Id.message.progress_update);
data.putInt("progress", progress); data.putInt(Apg.EXTRA_PROGRESS, progress);
data.putInt("max", max); data.putInt(Apg.EXTRA_MAX, max);
msg.setData(data); msg.setData(data);
mHandler.sendMessage(msg); mHandler.sendMessage(msg);
} }
@ -324,10 +324,10 @@ public class BaseActivity extends Activity
public void setProgress(String message, int progress, int max) { public void setProgress(String message, int progress, int max) {
Message msg = new Message(); Message msg = new Message();
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putInt("type", Id.message.progress_update); data.putInt(Apg.EXTRA_STATUS, Id.message.progress_update);
data.putString("message", message); data.putString(Apg.EXTRA_MESSAGE, message);
data.putInt("progress", progress); data.putInt(Apg.EXTRA_PROGRESS, progress);
data.putInt("max", max); data.putInt(Apg.EXTRA_MAX, max);
msg.setData(data); msg.setData(data);
mHandler.sendMessage(msg); mHandler.sendMessage(msg);
} }
@ -338,16 +338,16 @@ public class BaseActivity extends Activity
return; return;
} }
int type = data.getInt("type"); int type = data.getInt(Apg.EXTRA_STATUS);
switch (type) { switch (type) {
case Id.message.progress_update: { case Id.message.progress_update: {
String message = data.getString("message"); String message = data.getString(Apg.EXTRA_MESSAGE);
if (mProgressDialog != null) { if (mProgressDialog != null) {
if (message != null) { if (message != null) {
mProgressDialog.setMessage(message); mProgressDialog.setMessage(message);
} }
mProgressDialog.setMax(data.getInt("max")); mProgressDialog.setMax(data.getInt(Apg.EXTRA_MAX));
mProgressDialog.setProgress(data.getInt("progress")); mProgressDialog.setProgress(data.getInt(Apg.EXTRA_PROGRESS));
} }
break; break;
} }

View File

@ -34,6 +34,7 @@ import org.bouncycastle2.openpgp.PGPException;
import org.bouncycastle2.util.Strings; import org.bouncycastle2.util.Strings;
import org.openintents.intents.FileManager; import org.openintents.intents.FileManager;
import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
@ -57,6 +58,8 @@ import android.widget.ViewFlipper;
public class DecryptActivity extends BaseActivity { public class DecryptActivity extends BaseActivity {
private long mSignatureKeyId = 0; private long mSignatureKeyId = 0;
private Intent mIntent;
private String mReplyTo = null; private String mReplyTo = null;
private String mSubject = null; private String mSubject = null;
private boolean mSignedOnly = false; private boolean mSignedOnly = false;
@ -158,9 +161,9 @@ public class DecryptActivity extends BaseActivity {
mSource.showNext(); mSource.showNext();
} }
Intent intent = getIntent(); mIntent = getIntent();
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_VIEW)) { if (mIntent.getAction() != null && mIntent.getAction().equals(Intent.ACTION_VIEW)) {
Uri uri = intent.getData(); Uri uri = mIntent.getData();
try { try {
InputStream attachment = getContentResolver().openInputStream(uri); InputStream attachment = getContentResolver().openInputStream(uri);
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
@ -177,8 +180,8 @@ public class DecryptActivity extends BaseActivity {
} catch (IOException e) { } catch (IOException e) {
// ignore, then // ignore, then
} }
} else if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_SEND)) { } else if (mIntent.getAction() != null && mIntent.getAction().equals(Intent.ACTION_SEND)) {
Bundle extras = intent.getExtras(); Bundle extras = mIntent.getExtras();
if (extras == null) { if (extras == null) {
extras = new Bundle(); extras = new Bundle();
} }
@ -190,12 +193,12 @@ public class DecryptActivity extends BaseActivity {
if (mSubject.startsWith("Fwd: ")) { if (mSubject.startsWith("Fwd: ")) {
mSubject = mSubject.substring(5); mSubject = mSubject.substring(5);
} }
} else if (intent.getAction() != null && intent.getAction().equals(Apg.Intent.DECRYPT)) { } else if (mIntent.getAction() != null && mIntent.getAction().equals(Apg.Intent.DECRYPT)) {
Bundle extras = intent.getExtras(); Bundle extras = mIntent.getExtras();
if (extras == null) { if (extras == null) {
extras = new Bundle(); extras = new Bundle();
} }
String data = extras.getString("data"); String data = extras.getString(Apg.EXTRA_DATA);
if (data != null) { if (data != null) {
Matcher matcher = Apg.PGP_MESSAGE.matcher(data); Matcher matcher = Apg.PGP_MESSAGE.matcher(data);
if (matcher.matches()) { if (matcher.matches()) {
@ -214,14 +217,40 @@ public class DecryptActivity extends BaseActivity {
} }
} }
} }
mReplyTo = extras.getString("replyTo"); mReplyTo = extras.getString(Apg.EXTRA_REPLY_TO);
mSubject = extras.getString("subject"); mSubject = extras.getString(Apg.EXTRA_SUBJECT);
} else if (intent.getAction() != null && intent.getAction().equals(Apg.Intent.DECRYPT_FILE)) { } else if (mIntent.getAction() != null && mIntent.getAction().equals(Apg.Intent.DECRYPT_FILE)) {
mSource.setInAnimation(null); mSource.setInAnimation(null);
mSource.setOutAnimation(null); mSource.setOutAnimation(null);
while (mSource.getCurrentView().getId() != R.id.sourceFile) { while (mSource.getCurrentView().getId() != R.id.sourceFile) {
mSource.showNext(); mSource.showNext();
} }
} else if (mIntent.getAction() != null && mIntent.getAction().equals(Apg.Intent.DECRYPT_AND_RETURN)) {
Bundle extras = mIntent.getExtras();
if (extras == null) {
extras = new Bundle();
}
String data = extras.getString(Apg.EXTRA_DATA);
if (data != null) {
Matcher matcher = Apg.PGP_MESSAGE.matcher(data);
if (matcher.matches()) {
data = matcher.group(1);
// replace non breakable spaces
data = data.replaceAll("\\xa0", " ");
mMessage.setText(data);
} else {
matcher = Apg.PGP_SIGNED_MESSAGE.matcher(data);
if (matcher.matches()) {
data = matcher.group(1);
// replace non breakable spaces
data = data.replaceAll("\\xa0", " ");
mMessage.setText(data);
mDecryptButton.setText(R.string.btn_verify);
}
}
}
mReplyTo = extras.getString(Apg.EXTRA_REPLY_TO);
mSubject = extras.getString(Apg.EXTRA_SUBJECT);
} }
if (mSource.getCurrentView().getId() == R.id.sourceMessage && if (mSource.getCurrentView().getId() == R.id.sourceMessage &&
@ -412,12 +441,11 @@ public class DecryptActivity extends BaseActivity {
String data = mMessage.getText().toString(); String data = mMessage.getText().toString();
data = data.replaceAll("(?m)^", "> "); data = data.replaceAll("(?m)^", "> ");
data = "\n\n" + data; data = "\n\n" + data;
intent.putExtra("data", data); intent.putExtra(Apg.EXTRA_DATA, data);
intent.putExtra("subject", "Re: " + mSubject); intent.putExtra(Apg.EXTRA_SUBJECT, "Re: " + mSubject);
intent.putExtra("sendTo", mReplyTo); intent.putExtra(Apg.EXTRA_SEND_TO, mReplyTo);
intent.putExtra("eyId", mSignatureKeyId); intent.putExtra(Apg.EXTRA_SIGNATURE_KEY_ID, getSecretKeyId());
intent.putExtra("signatureKeyId", getSecretKeyId()); intent.putExtra(Apg.EXTRA_ENCRYPTION_KEY_IDS, new long[] { mSignatureKeyId });
intent.putExtra("encryptionKeyIds", new long[] { mSignatureKeyId });
startActivity(intent); startActivity(intent);
} }
@ -475,9 +503,8 @@ public class DecryptActivity extends BaseActivity {
out.close(); out.close();
if (mDecryptTarget == Id.target.message) { if (mDecryptTarget == Id.target.message) {
data.putString("decryptedMessage", data.putByteArray(Apg.EXTRA_DECRYPTED_MESSAGE,
Strings.fromUTF8ByteArray(((ByteArrayOutputStream) ((ByteArrayOutputStream) out).toByteArray());
out).toByteArray()));
} }
} catch (PGPException e) { } catch (PGPException e) {
error = "" + e; error = "" + e;
@ -489,10 +516,10 @@ public class DecryptActivity extends BaseActivity {
error = "" + e; error = "" + e;
} }
data.putInt("type", Id.message.done); data.putInt(Apg.EXTRA_STATUS, Id.message.done);
if (error != null) { if (error != null) {
data.putString("error", error); data.putString(Apg.EXTRA_ERROR, error);
} }
msg.setData(data); msg.setData(data);
@ -509,19 +536,17 @@ public class DecryptActivity extends BaseActivity {
mSignatureLayout.setVisibility(View.GONE); mSignatureLayout.setVisibility(View.GONE);
mReplyButton.setVisibility(View.INVISIBLE); mReplyButton.setVisibility(View.INVISIBLE);
String error = data.getString("error"); String error = data.getString(Apg.EXTRA_ERROR);
if (error != null) { if (error != null) {
Toast.makeText(DecryptActivity.this, Toast.makeText(DecryptActivity.this,
getString(R.string.errorMessage, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT).show();
data.getString("error")),
Toast.LENGTH_SHORT).show();
return; return;
} }
Toast.makeText(this, R.string.decryptionSuccessful, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.decryptionSuccessful, Toast.LENGTH_SHORT).show();
switch (mDecryptTarget) { switch (mDecryptTarget) {
case Id.target.message: { case Id.target.message: {
String decryptedMessage = data.getString("decryptedMessage"); String decryptedMessage = Strings.fromUTF8ByteArray(data.getByteArray(Apg.EXTRA_DECRYPTED_MESSAGE));
mMessage.setText(decryptedMessage); mMessage.setText(decryptedMessage);
mReplyButton.setVisibility(View.VISIBLE); mReplyButton.setVisibility(View.VISIBLE);
break; break;
@ -541,9 +566,9 @@ public class DecryptActivity extends BaseActivity {
} }
} }
if (data.getBoolean("signature")) { if (data.getBoolean(Apg.EXTRA_SIGNATURE)) {
String userId = data.getString("signatureUserId"); String userId = data.getString(Apg.EXTRA_SIGNATURE_USER_ID);
mSignatureKeyId = data.getLong("signatureKeyId"); mSignatureKeyId = data.getLong(Apg.EXTRA_SIGNATURE_KEY_ID);
mUserIdRest.setText("id: " + Long.toHexString(mSignatureKeyId & 0xffffffffL)); mUserIdRest.setText("id: " + Long.toHexString(mSignatureKeyId & 0xffffffffL));
if (userId == null) { if (userId == null) {
userId = getResources().getString(R.string.unknownUserId); userId = getResources().getString(R.string.unknownUserId);
@ -555,15 +580,23 @@ public class DecryptActivity extends BaseActivity {
} }
mUserId.setText(userId); mUserId.setText(userId);
if (data.getBoolean("signatureSuccess")) { if (data.getBoolean(Apg.EXTRA_SIGNATURE_SUCCESS)) {
mSignatureStatusImage.setImageResource(R.drawable.overlay_ok); mSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
} else if (data.getBoolean("signatureUnknown")) { } else if (data.getBoolean(Apg.EXTRA_SIGNATURE_UNKNOWN)) {
mSignatureStatusImage.setImageResource(R.drawable.overlay_error); mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
} else { } else {
mSignatureStatusImage.setImageResource(R.drawable.overlay_error); mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
} }
mSignatureLayout.setVisibility(View.VISIBLE); mSignatureLayout.setVisibility(View.VISIBLE);
} }
if (mIntent.getAction() != null &&
mIntent.getAction().equals(Apg.Intent.DECRYPT_AND_RETURN)) {
Intent intent = new Intent();
intent.putExtras(data);
setResult(RESULT_OK, intent);
finish();
}
} }
@Override @Override

View File

@ -71,7 +71,7 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
Intent intent = getIntent(); Intent intent = getIntent();
long keyId = 0; long keyId = 0;
if (intent.getExtras() != null) { if (intent.getExtras() != null) {
keyId = intent.getExtras().getLong("keyId"); keyId = intent.getExtras().getLong(Apg.EXTRA_KEY_ID);
} }
if (keyId != 0) { if (keyId != 0) {
@ -262,10 +262,10 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
error = "" + e; error = "" + e;
} }
data.putInt("type", Id.message.done); data.putInt(Apg.EXTRA_STATUS, Id.message.done);
if (error != null) { if (error != null) {
data.putString("error", error); data.putString(Apg.EXTRA_ERROR, error);
} }
msg.setData(data); msg.setData(data);
@ -279,11 +279,10 @@ public class EditKeyActivity extends BaseActivity implements OnClickListener {
Bundle data = msg.getData(); Bundle data = msg.getData();
removeDialog(Id.dialog.saving); removeDialog(Id.dialog.saving);
String error = data.getString("error"); String error = data.getString(Apg.EXTRA_ERROR);
if (error != null) { if (error != null) {
Toast.makeText(EditKeyActivity.this, Toast.makeText(EditKeyActivity.this,
getString(R.string.errorMessage, data.getString("error")), getString(R.string.errorMessage, error), Toast.LENGTH_SHORT).show();
Toast.LENGTH_SHORT).show();
} else { } else {
Toast.makeText(EditKeyActivity.this, R.string.keySaved, Toast.LENGTH_SHORT).show(); Toast.makeText(EditKeyActivity.this, R.string.keySaved, Toast.LENGTH_SHORT).show();
setResult(RESULT_OK); setResult(RESULT_OK);

View File

@ -273,11 +273,11 @@ public class EncryptActivity extends BaseActivity {
if (extras == null) { if (extras == null) {
extras = new Bundle(); extras = new Bundle();
} }
String data = extras.getString("data"); String data = extras.getString(Apg.EXTRA_DATA);
mSendTo = extras.getString("sendTo"); mSendTo = extras.getString(Apg.EXTRA_SEND_TO);
mSubject = extras.getString("subject"); mSubject = extras.getString(Apg.EXTRA_SUBJECT);
long signatureKeyId = extras.getLong("signatureKeyId"); long signatureKeyId = extras.getLong(Apg.EXTRA_SIGNATURE_KEY_ID);
long encryptionKeyIds[] = extras.getLongArray("encryptionKeyIds"); long encryptionKeyIds[] = extras.getLongArray(Apg.EXTRA_ENCRYPTION_KEY_IDS);
if (signatureKeyId != 0) { if (signatureKeyId != 0) {
PGPSecretKeyRing keyRing = Apg.getSecretKeyRing(signatureKeyId); PGPSecretKeyRing keyRing = Apg.getSecretKeyRing(signatureKeyId);
PGPSecretKey masterKey = null; PGPSecretKey masterKey = null;
@ -582,7 +582,8 @@ public class EncryptActivity extends BaseActivity {
out.close(); out.close();
if (mEncryptTarget != Id.target.file) { if (mEncryptTarget != Id.target.file) {
data.putString("message", new String(((ByteArrayOutputStream)out).toByteArray())); data.putByteArray(Apg.EXTRA_ENCRYPTED_MESSAGE,
((ByteArrayOutputStream)out).toByteArray());
} }
} catch (IOException e) { } catch (IOException e) {
error = "" + e; error = "" + e;
@ -598,10 +599,10 @@ public class EncryptActivity extends BaseActivity {
error = "" + e; error = "" + e;
} }
data.putInt("type", Id.message.done); data.putInt(Apg.EXTRA_STATUS, Id.message.done);
if (error != null) { if (error != null) {
data.putString("error", error); data.putString(Apg.EXTRA_ERROR, error);
} }
msg.setData(data); msg.setData(data);
@ -645,7 +646,7 @@ public class EncryptActivity extends BaseActivity {
private void selectPublicKeys() { private void selectPublicKeys() {
Intent intent = new Intent(this, SelectPublicKeyListActivity.class); Intent intent = new Intent(this, SelectPublicKeyListActivity.class);
intent.putExtra("selection", mEncryptionKeyIds); intent.putExtra(Apg.EXTRA_SELECTION, mEncryptionKeyIds);
startActivityForResult(intent, Id.request.public_keys); startActivityForResult(intent, Id.request.public_keys);
} }
@ -702,7 +703,7 @@ public class EncryptActivity extends BaseActivity {
case Id.request.public_keys: { case Id.request.public_keys: {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras(); Bundle bundle = data.getExtras();
mEncryptionKeyIds = bundle.getLongArray("selection"); mEncryptionKeyIds = bundle.getLongArray(Apg.EXTRA_SELECTION);
} }
updateView(); updateView();
break; break;
@ -723,14 +724,13 @@ public class EncryptActivity extends BaseActivity {
removeDialog(Id.dialog.encrypting); removeDialog(Id.dialog.encrypting);
Bundle data = msg.getData(); Bundle data = msg.getData();
String error = data.getString("error"); String error = data.getString(Apg.EXTRA_ERROR);
if (error != null) { if (error != null) {
Toast.makeText(EncryptActivity.this, Toast.makeText(EncryptActivity.this,
getString(R.string.errorMessage, data.getString("error")), getString(R.string.errorMessage, error), Toast.LENGTH_SHORT).show();
Toast.LENGTH_SHORT).show();
return; return;
} else { } else {
String message = data.getString("message"); String message = Strings.fromUTF8ByteArray(data.getByteArray(Apg.EXTRA_ENCRYPTED_MESSAGE));
switch (mEncryptTarget) { switch (mEncryptTarget) {
case Id.target.clipboard: { case Id.target.clipboard: {
ClipboardManager clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipboardManager clip = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

View File

@ -276,13 +276,13 @@ public class KeyListActivity extends BaseActivity {
} }
if (mTask == Id.task.import_keys) { if (mTask == Id.task.import_keys) {
data.putInt("type", Id.message.import_done); data.putInt(Apg.EXTRA_STATUS, Id.message.import_done);
} else { } else {
data.putInt("type", Id.message.export_done); data.putInt(Apg.EXTRA_STATUS, Id.message.export_done);
} }
if (error != null) { if (error != null) {
data.putString("error", error); data.putString(Apg.EXTRA_ERROR, error);
} }
msg.setData(data); msg.setData(data);
@ -305,15 +305,15 @@ public class KeyListActivity extends BaseActivity {
Bundle data = msg.getData(); Bundle data = msg.getData();
if (data != null) { if (data != null) {
int type = data.getInt("type"); int type = data.getInt(Apg.EXTRA_STATUS);
switch (type) { switch (type) {
case Id.message.import_done: { case Id.message.import_done: {
removeDialog(Id.dialog.importing); removeDialog(Id.dialog.importing);
String error = data.getString("error"); String error = data.getString(Apg.EXTRA_ERROR);
if (error != null) { if (error != null) {
Toast.makeText(KeyListActivity.this, Toast.makeText(KeyListActivity.this,
getString(R.string.errorMessage, data.getString("error")), getString(R.string.errorMessage, error),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} else { } else {
int added = data.getInt("added"); int added = data.getInt("added");
@ -338,10 +338,10 @@ public class KeyListActivity extends BaseActivity {
case Id.message.export_done: { case Id.message.export_done: {
removeDialog(Id.dialog.exporting); removeDialog(Id.dialog.exporting);
String error = data.getString("error"); String error = data.getString(Apg.EXTRA_ERROR);
if (error != null) { if (error != null) {
Toast.makeText(KeyListActivity.this, Toast.makeText(KeyListActivity.this,
getString(R.string.errorMessage, data.getString("error")), getString(R.string.errorMessage, error),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} else { } else {
int exported = data.getInt("exported"); int exported = data.getInt("exported");

View File

@ -87,7 +87,7 @@ public class MailListActivity extends ListActivity {
mconversations = new Vector<Conversation>(); mconversations = new Vector<Conversation>();
mmessages = new Vector<Message>(); mmessages = new Vector<Message>();
String account = getIntent().getExtras().getString("account"); String account = getIntent().getExtras().getString(Apg.EXTRA_ACCOUNT);
// TODO: what if account is null? // TODO: what if account is null?
Uri uri = Uri.parse("content://gmail-ls/conversations/" + account); Uri uri = Uri.parse("content://gmail-ls/conversations/" + account);
Cursor cursor = Cursor cursor =
@ -153,9 +153,9 @@ public class MailListActivity extends ListActivity {
Intent intent = new Intent(MailListActivity.this, DecryptActivity.class); Intent intent = new Intent(MailListActivity.this, DecryptActivity.class);
intent.setAction(Apg.Intent.DECRYPT); intent.setAction(Apg.Intent.DECRYPT);
Message message = (Message) ((MailboxAdapter) getListAdapter()).getItem(position); Message message = (Message) ((MailboxAdapter) getListAdapter()).getItem(position);
intent.putExtra("data", message.data); intent.putExtra(Apg.EXTRA_DATA, message.data);
intent.putExtra("subject", message.subject); intent.putExtra(Apg.EXTRA_SUBJECT, message.subject);
intent.putExtra("replyTo", message.replyTo); intent.putExtra(Apg.EXTRA_REPLY_TO, message.replyTo);
startActivity(intent); startActivity(intent);
} }
}); });

View File

@ -112,7 +112,7 @@ public class MainActivity extends BaseActivity {
public void onItemClick(AdapterView<?> arg0, View view, int index, long id) { public void onItemClick(AdapterView<?> arg0, View view, int index, long id) {
String accountName = (String) mAccounts.getSelectedItem(); String accountName = (String) mAccounts.getSelectedItem();
startActivity(new Intent(MainActivity.this, MailListActivity.class) startActivity(new Intent(MainActivity.this, MailListActivity.class)
.putExtra("account", accountName)); .putExtra(Apg.EXTRA_ACCOUNT, accountName));
} }
}); });
registerForContextMenu(mAccounts); registerForContextMenu(mAccounts);

View File

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

View File

@ -38,7 +38,7 @@ public class SelectPublicKeyListActivity extends BaseActivity {
mIntent = getIntent(); mIntent = getIntent();
long selectedKeyIds[] = null; long selectedKeyIds[] = null;
if (mIntent.getExtras() != null) { if (mIntent.getExtras() != null) {
selectedKeyIds = mIntent.getExtras().getLongArray("selection"); selectedKeyIds = mIntent.getExtras().getLongArray(Apg.EXTRA_SELECTION);
} }
mList = (ListView) findViewById(R.id.list); mList = (ListView) findViewById(R.id.list);
@ -96,7 +96,7 @@ public class SelectPublicKeyListActivity extends BaseActivity {
for (int i = 0; i < vector.size(); ++i) { for (int i = 0; i < vector.size(); ++i) {
selectedKeyIds[i] = vector.get(i); selectedKeyIds[i] = vector.get(i);
} }
data.putExtra("selection", selectedKeyIds); data.putExtra(Apg.EXTRA_SELECTION, selectedKeyIds);
setResult(RESULT_OK, data); setResult(RESULT_OK, data);
finish(); finish();
} }

View File

@ -43,7 +43,7 @@ public class SelectSecretKeyListActivity extends BaseActivity {
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent data = new Intent(); Intent data = new Intent();
data.putExtra("selectedKeyId", id); data.putExtra(Apg.EXTRA_KEY_ID, id);
setResult(RESULT_OK, data); setResult(RESULT_OK, data);
finish(); finish();
} }

View File

@ -76,7 +76,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
} }
} }
String error = data.getString("error"); String error = data.getString(Apg.EXTRA_ERROR);
if (error != null) { if (error != null) {
Toast.makeText(getContext(), Toast.makeText(getContext(),
getContext().getString(R.string.errorMessage, error), getContext().getString(R.string.errorMessage, error),
@ -327,7 +327,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putBoolean("closeProgressDialog", true); data.putBoolean("closeProgressDialog", true);
if (error != null) { if (error != null) {
data.putString("error", error); data.putString(Apg.EXTRA_ERROR, error);
} else { } else {
data.putBoolean("gotNewKey", true); data.putBoolean("gotNewKey", true);
} }