code cleanup

This commit is contained in:
Dominik 2012-09-13 18:37:31 +02:00
parent 66cab704e7
commit a507204b9e
10 changed files with 22 additions and 149 deletions

View File

@ -263,7 +263,7 @@ public class BaseActivity extends SherlockFragmentActivity implements Runnable,
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(SelectSecretKeyListActivity.EXTRA_KEY_ID)); setSecretKeyId(bundle.getLong(SelectSecretKeyListActivity.RESULT_EXTRA_KEY_ID));
} else { } else {
setSecretKeyId(Id.key.none); setSecretKeyId(Id.key.none);
} }

View File

@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector;
import org.spongycastle.openpgp.PGPObjectFactory; import org.spongycastle.openpgp.PGPObjectFactory;
import org.spongycastle.openpgp.PGPPublicKeyRing; import org.spongycastle.openpgp.PGPPublicKeyRing;

View File

@ -994,7 +994,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
initialKeyIds[i] = keyIds.get(i); initialKeyIds[i] = keyIds.get(i);
} }
} }
intent.putExtra(SelectPublicKeyListActivity.EXTRA_SELECTION, initialKeyIds); intent.putExtra(SelectPublicKeyListActivity.RESULT_EXTRA_SELECTION, initialKeyIds);
startActivityForResult(intent, Id.request.public_keys); startActivityForResult(intent, Id.request.public_keys);
} }
@ -1038,7 +1038,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras(); Bundle bundle = data.getExtras();
mEncryptionKeyIds = bundle mEncryptionKeyIds = bundle
.getLongArray(SelectPublicKeyListActivity.EXTRA_SELECTION); .getLongArray(SelectPublicKeyListActivity.RESULT_EXTRA_SELECTION);
} }
updateView(); updateView();
break; break;
@ -1047,7 +1047,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
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(SelectSecretKeyListActivity.EXTRA_KEY_ID)); setSecretKeyId(bundle.getLong(SelectSecretKeyListActivity.RESULT_EXTRA_KEY_ID));
} else { } else {
setSecretKeyId(Id.key.none); setSecretKeyId(Id.key.none);
} }

View File

@ -19,6 +19,7 @@ package org.thialfihar.android.apg.ui;
import org.thialfihar.android.apg.Constants; import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id; import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.helper.OtherHelper;
import org.thialfihar.android.apg.service.ApgServiceHandler; import org.thialfihar.android.apg.service.ApgServiceHandler;
import org.thialfihar.android.apg.service.ApgService; import org.thialfihar.android.apg.service.ApgService;
import org.thialfihar.android.apg.R; import org.thialfihar.android.apg.R;
@ -63,16 +64,7 @@ public class ImportFromQRCodeActivity extends SherlockFragmentActivity {
mContentView = (TextView) findViewById(R.id.import_from_qr_code_content); mContentView = (TextView) findViewById(R.id.import_from_qr_code_content);
// set actionbar without home button if called from another app // set actionbar without home button if called from another app
final ActionBar actionBar = getSupportActionBar(); OtherHelper.setActionBarBackButton(this);
Log.d(Constants.TAG, "calling package (only set when using startActivityForResult)="
+ getCallingPackage());
if (getCallingPackage() != null && getCallingPackage().equals(Constants.PACKAGE_NAME)) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
} else {
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
}
// start scanning // start scanning
new IntentIntegrator(this).initiateScan(); new IntentIntegrator(this).initiateScan();

View File

@ -63,8 +63,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
public static final String EXTRA_KEY_ID = "keyId"; public static final String EXTRA_KEY_ID = "keyId";
// TODO: Change? public static final String RESULT_EXTRA_TEXT = "text";
public static final String EXTRA_TEXT = "text";
private ListView mList; private ListView mList;
private EditText mQuery; private EditText mQuery;
@ -134,8 +133,8 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
}); });
Intent intent = getIntent(); Intent intent = getIntent();
if (ACTION_LOOK_UP_KEY_ID.equals(intent.getAction()) String action = intent.getAction();
|| ACTION_LOOK_UP_KEY_ID_AND_RETURN.equals(intent.getAction())) { if (ACTION_LOOK_UP_KEY_ID.equals(action) || ACTION_LOOK_UP_KEY_ID_AND_RETURN.equals(action)) {
long keyId = intent.getLongExtra(EXTRA_KEY_ID, 0); long keyId = intent.getLongExtra(EXTRA_KEY_ID, 0);
if (keyId != 0) { if (keyId != 0) {
String query = "0x" + PGPHelper.keyToHex(keyId); String query = "0x" + PGPHelper.keyToHex(keyId);
@ -215,7 +214,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
if (ACTION_LOOK_UP_KEY_ID_AND_RETURN.equals(orgIntent.getAction())) { if (ACTION_LOOK_UP_KEY_ID_AND_RETURN.equals(orgIntent.getAction())) {
if (mKeyData != null) { if (mKeyData != null) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(EXTRA_TEXT, mKeyData); intent.putExtra(RESULT_EXTRA_TEXT, mKeyData);
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
} else { } else {
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);

View File

@ -66,10 +66,6 @@ public class PreferencesActivity extends SherlockPreferenceActivity {
mPassPhraseCacheTtl.setValue(newValue.toString()); mPassPhraseCacheTtl.setValue(newValue.toString());
mPassPhraseCacheTtl.setSummary(mPassPhraseCacheTtl.getEntry()); mPassPhraseCacheTtl.setSummary(mPassPhraseCacheTtl.getEntry());
mPreferences.setPassPhraseCacheTtl(Integer.parseInt(newValue.toString())); mPreferences.setPassPhraseCacheTtl(Integer.parseInt(newValue.toString()));
// restart cache service with new ttl
// TODO: not needed anymore!
// PassphraseCacheService.startCacheService(PreferencesActivity.this);
return false; return false;
} }
}); });

View File

@ -176,7 +176,7 @@ public class PublicKeyListActivity extends KeyListActivity {
switch (requestCode) { switch (requestCode) {
case Id.request.look_up_key_id: { case Id.request.look_up_key_id: {
if (resultCode == RESULT_CANCELED || data == null if (resultCode == RESULT_CANCELED || data == null
|| data.getStringExtra(KeyServerQueryActivity.EXTRA_TEXT) == null) { || data.getStringExtra(KeyServerQueryActivity.RESULT_EXTRA_TEXT) == null) {
return; return;
} }

View File

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

View File

@ -42,8 +42,8 @@ public class SelectSecretKeyListActivity extends SherlockFragmentActivity {
public static final String ACTION_SELECT_SECRET_KEY = Constants.INTENT_PREFIX public static final String ACTION_SELECT_SECRET_KEY = Constants.INTENT_PREFIX
+ "SELECT_SECRET_KEY"; + "SELECT_SECRET_KEY";
public static final String EXTRA_USER_ID = "userId"; public static final String RESULT_EXTRA_USER_ID = "userId";
public static final String EXTRA_KEY_ID = "keyId"; public static final String RESULT_EXTRA_KEY_ID = "keyId";
protected ListView mList; protected ListView mList;
protected SelectSecretKeyListAdapter mListAdapter; protected SelectSecretKeyListAdapter mListAdapter;
@ -71,8 +71,8 @@ public class SelectSecretKeyListActivity extends SherlockFragmentActivity {
mList.setOnItemClickListener(new OnItemClickListener() { mList.setOnItemClickListener(new OnItemClickListener() {
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(EXTRA_KEY_ID, id); data.putExtra(RESULT_EXTRA_KEY_ID, id);
data.putExtra(EXTRA_USER_ID, (String) mList.getItemAtPosition(position)); data.putExtra(RESULT_EXTRA_USER_ID, (String) mList.getItemAtPosition(position));
setResult(RESULT_OK, data); setResult(RESULT_OK, data);
finish(); finish();
} }

View File

@ -60,9 +60,6 @@ public class SignKeyActivity extends SherlockFragmentActivity {
public static final String EXTRA_KEY_ID = "keyId"; public static final String EXTRA_KEY_ID = "keyId";
// TODO: remove when using new intentservice:
public static final String EXTRA_ERROR = "error";
private long mPubKeyId = 0; private long mPubKeyId = 0;
private long mMasterKeyId = 0; private long mMasterKeyId = 0;
@ -185,33 +182,14 @@ public class SignKeyActivity extends SherlockFragmentActivity {
startSigning(); startSigning();
} }
} else { } else {
final Bundle status = new Bundle(); Toast.makeText(this, "Key has already been signed", Toast.LENGTH_SHORT).show();
// Message msg = new Message();
// status.putString(EXTRA_ERROR, "Key has already been signed"); setResult(RESULT_CANCELED);
// status.putInt(Constants.extras.STATUS, Id.message.done);
// msg.setData(status);
// sendMessage(msg);
setResult(Id.return_value.error);
finish(); finish();
} }
} }
} }
// @Override
// public long getSecretKeyId() {
// return masterKeyId;
// }
//
// @Override
// public void passPhraseCallback(long keyId, String passPhrase) {
// super.passPhraseCallback(keyId, passPhrase);
// startSigning();
// }
/** /**
* kicks off the actual signing process on a background thread * kicks off the actual signing process on a background thread
*/ */
@ -311,97 +289,6 @@ public class SignKeyActivity extends SherlockFragmentActivity {
startService(intent); startService(intent);
} }
// private void startSigning() {
// showDialog(Id.dialog.signing);
// startThread();
// }
// @Override
// public void run() {
// final Bundle status = new Bundle();
// Message msg = new Message();
//
// try {
// String passphrase = PGPMain.getCachedPassPhrase(masterKeyId);
// if (passphrase == null || passphrase.length() <= 0) {
// status.putString(EXTRA_ERROR, "Unable to obtain passphrase");
// } else {
// PGPPublicKeyRing pubring = PGPMain.getPublicKeyRing(pubKeyId);
//
// /*
// * sign the incoming key
// */
// PGPSecretKey secretKey = PGPMain.getSecretKey(masterKeyId);
// PGPPrivateKey signingKey = secretKey.extractPrivateKey(passphrase.toCharArray(),
// BouncyCastleProvider.PROVIDER_NAME);
// PGPSignatureGenerator sGen = new PGPSignatureGenerator(secretKey.getPublicKey()
// .getAlgorithm(), PGPUtil.SHA256, BouncyCastleProvider.PROVIDER_NAME);
// sGen.initSign(PGPSignature.DIRECT_KEY, signingKey);
//
// PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
//
// PGPSignatureSubpacketVector packetVector = spGen.generate();
// sGen.setHashedSubpackets(packetVector);
//
// PGPPublicKey signedKey = PGPPublicKey.addCertification(
// pubring.getPublicKey(pubKeyId), sGen.generate());
// pubring = PGPPublicKeyRing.insertPublicKey(pubring, signedKey);
//
// // check if we need to send the key to the server or not
// CheckBox sendKey = (CheckBox) findViewById(R.id.sendKey);
// if (sendKey.isChecked()) {
// Spinner keyServer = (Spinner) findViewById(R.id.keyServer);
// HkpKeyServer server = new HkpKeyServer((String) keyServer.getSelectedItem());
//
// /*
// * upload the newly signed key to the key server
// */
//
// PGPMain.uploadKeyRingToServer(server, pubring);
// }
//
// // store the signed key in our local cache
// int retval = PGPMain.storeKeyRingInCache(pubring);
// if (retval != Id.return_value.ok && retval != Id.return_value.updated) {
// status.putString(EXTRA_ERROR, "Failed to store signed key in local cache");
// }
// }
// } catch (PGPException e) {
// 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(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(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(Constants.TAG, "Failed to sign key", e);
// status.putString(EXTRA_ERROR, "Failed to sign key");
// status.putInt(Constants.extras.STATUS, Id.message.done);
// return;
// }
//
// status.putInt(Constants.extras.STATUS, Id.message.done);
//
// msg.setData(status);
// sendMessage(msg);
//
// if (status.containsKey(EXTRA_ERROR)) {
// setResult(Id.return_value.error);
// } else {
// setResult(Id.return_value.ok);
// }
//
// finish();
// }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) { switch (requestCode) {