code cleanup

This commit is contained in:
Dominik 2012-04-25 19:09:24 +02:00
parent b63fe462a4
commit 7b61ad24d7
4 changed files with 33 additions and 35 deletions

View File

@ -33,19 +33,17 @@ public class ApgHandler extends Handler {
public static final int MESSAGE_UPDATE_PROGRESS = 3;
// possible data keys for messages
public static final String ERROR = "error";
public static final String PROGRESS = "progress";
public static final String PROGRESS_MAX = "max";
public static final String MESSAGE = "message";
public static final String MESSAGE_ID = "message_id";
// generate key results
public static final String NEW_KEY = "new_key";
public static final String NEW_KEY2 = "new_key2";
public static final String DATA_ERROR = "error";
public static final String DATA_PROGRESS = "progress";
public static final String DATA_PROGRESS_MAX = "max";
public static final String DATA_MESSAGE = "message";
public static final String DATA_MESSAGE_ID = "message_id";
// possible data keys as result from service
public static final String RESULT_NEW_KEY = "new_key";
public static final String RESULT_NEW_KEY2 = "new_key2";
Activity mActivity;
ProgressDialogFragment mProgressDialogFragment;
public ApgHandler(Activity activity) {
@ -64,35 +62,35 @@ public class ApgHandler extends Handler {
switch (message.arg1) {
case MESSAGE_OKAY:
mProgressDialogFragment.dismiss();
break;
case MESSAGE_EXCEPTION:
mProgressDialogFragment.dismiss();
if (data.containsKey(ERROR)) {
// show error from service
if (data.containsKey(DATA_ERROR)) {
Toast.makeText(mActivity,
mActivity.getString(R.string.errorMessage, data.getString(ERROR)),
mActivity.getString(R.string.errorMessage, data.getString(DATA_ERROR)),
Toast.LENGTH_SHORT).show();
}
break;
case MESSAGE_UPDATE_PROGRESS:
if (data.containsKey(PROGRESS) && data.containsKey(PROGRESS_MAX)) {
if (data.containsKey(MESSAGE)) {
mProgressDialogFragment.setProgress(data.getString(MESSAGE),
data.getInt(PROGRESS), data.getInt(PROGRESS_MAX));
} else if (data.containsKey(MESSAGE_ID)) {
mProgressDialogFragment.setProgress(data.getInt(MESSAGE_ID),
data.getInt(PROGRESS), data.getInt(PROGRESS_MAX));
if (data.containsKey(DATA_PROGRESS) && data.containsKey(DATA_PROGRESS_MAX)) {
// update progress from service
if (data.containsKey(DATA_MESSAGE)) {
mProgressDialogFragment.setProgress(data.getString(DATA_MESSAGE),
data.getInt(DATA_PROGRESS), data.getInt(DATA_PROGRESS_MAX));
} else if (data.containsKey(DATA_MESSAGE_ID)) {
mProgressDialogFragment.setProgress(data.getInt(DATA_MESSAGE_ID),
data.getInt(DATA_PROGRESS), data.getInt(DATA_PROGRESS_MAX));
} else {
mProgressDialogFragment.setProgress(data.getInt(PROGRESS),
data.getInt(PROGRESS_MAX));
mProgressDialogFragment.setProgress(data.getInt(DATA_PROGRESS),
data.getInt(DATA_PROGRESS_MAX));
}
}
break;

View File

@ -155,7 +155,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
// Output
Bundle resultData = new Bundle();
resultData.putByteArray(ApgHandler.NEW_KEY,
resultData.putByteArray(ApgHandler.RESULT_NEW_KEY,
Utils.PGPSecretKeyRingToBytes(newKeyRing));
sendMessageToHandler(ApgHandler.MESSAGE_OKAY, null, resultData);
} catch (Exception e) {
@ -178,9 +178,9 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
// Output
Bundle resultData = new Bundle();
resultData.putByteArray(ApgHandler.NEW_KEY,
resultData.putByteArray(ApgHandler.RESULT_NEW_KEY,
Utils.PGPSecretKeyRingToBytes(masterKeyRing));
resultData.putByteArray(ApgHandler.NEW_KEY2,
resultData.putByteArray(ApgHandler.RESULT_NEW_KEY2,
Utils.PGPSecretKeyRingToBytes(subKeyRing));
sendMessageToHandler(ApgHandler.MESSAGE_OKAY, null, resultData);
} catch (Exception e) {
@ -200,7 +200,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
e.printStackTrace();
Bundle data = new Bundle();
data.putString(ApgHandler.ERROR, e.getMessage());
data.putString(ApgHandler.DATA_ERROR, e.getMessage());
sendMessageToHandler(ApgHandler.MESSAGE_EXCEPTION, null, data);
}
@ -235,10 +235,10 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
Bundle data = new Bundle();
if (message != null) {
data.putString(ApgHandler.MESSAGE, message);
data.putString(ApgHandler.DATA_MESSAGE, message);
}
data.putInt(ApgHandler.PROGRESS, progress);
data.putInt(ApgHandler.PROGRESS_MAX, max);
data.putInt(ApgHandler.DATA_PROGRESS, progress);
data.putInt(ApgHandler.DATA_PROGRESS_MAX, max);
sendMessageToHandler(ApgHandler.MESSAGE_UPDATE_PROGRESS, null, data);
}

View File

@ -61,7 +61,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import java.util.Iterator;
import java.util.Vector;
public class EditKeyActivity extends SherlockFragmentActivity { // extends BaseActivity {
public class EditKeyActivity extends SherlockFragmentActivity {
private Intent mIntent = null;
private ActionBar mActionBar;
@ -207,10 +207,10 @@ public class EditKeyActivity extends SherlockFragmentActivity { // extends BaseA
Bundle data = message.getData();
PGPSecretKeyRing masterKeyRing = Utils
.BytesToPGPSecretKeyRing(data
.getByteArray(ApgHandler.NEW_KEY));
.getByteArray(ApgHandler.RESULT_NEW_KEY));
PGPSecretKeyRing subKeyRing = Utils
.BytesToPGPSecretKeyRing(data
.getByteArray(ApgHandler.NEW_KEY2));
.getByteArray(ApgHandler.RESULT_NEW_KEY2));
// add master key
Iterator<PGPSecretKey> masterIt = masterKeyRing.getSecretKeys();

View File

@ -285,7 +285,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
// get new key from data bundle returned from service
Bundle data = message.getData();
PGPSecretKeyRing newKeyRing = Utils.BytesToPGPSecretKeyRing(data
.getByteArray(ApgHandler.NEW_KEY));
.getByteArray(ApgHandler.RESULT_NEW_KEY));
boolean isMasterKey = (mEditors.getChildCount() == 0);