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; public static final int MESSAGE_UPDATE_PROGRESS = 3;
// possible data keys for messages // possible data keys for messages
public static final String ERROR = "error"; public static final String DATA_ERROR = "error";
public static final String PROGRESS = "progress"; public static final String DATA_PROGRESS = "progress";
public static final String PROGRESS_MAX = "max"; public static final String DATA_PROGRESS_MAX = "max";
public static final String MESSAGE = "message"; public static final String DATA_MESSAGE = "message";
public static final String MESSAGE_ID = "message_id"; public static final String DATA_MESSAGE_ID = "message_id";
// generate key results
public static final String NEW_KEY = "new_key";
public static final String NEW_KEY2 = "new_key2";
// 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; Activity mActivity;
ProgressDialogFragment mProgressDialogFragment; ProgressDialogFragment mProgressDialogFragment;
public ApgHandler(Activity activity) { public ApgHandler(Activity activity) {
@@ -70,29 +68,29 @@ public class ApgHandler extends Handler {
case MESSAGE_EXCEPTION: case MESSAGE_EXCEPTION:
mProgressDialogFragment.dismiss(); mProgressDialogFragment.dismiss();
if (data.containsKey(ERROR)) { // show error from service
if (data.containsKey(DATA_ERROR)) {
Toast.makeText(mActivity, Toast.makeText(mActivity,
mActivity.getString(R.string.errorMessage, data.getString(ERROR)), mActivity.getString(R.string.errorMessage, data.getString(DATA_ERROR)),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
break; break;
case MESSAGE_UPDATE_PROGRESS: case MESSAGE_UPDATE_PROGRESS:
if (data.containsKey(PROGRESS) && data.containsKey(PROGRESS_MAX)) { if (data.containsKey(DATA_PROGRESS) && data.containsKey(DATA_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));
// 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 { } else {
mProgressDialogFragment.setProgress(data.getInt(PROGRESS), mProgressDialogFragment.setProgress(data.getInt(DATA_PROGRESS),
data.getInt(PROGRESS_MAX)); data.getInt(DATA_PROGRESS_MAX));
} }
} }
break; break;

View File

@@ -155,7 +155,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
// Output // Output
Bundle resultData = new Bundle(); Bundle resultData = new Bundle();
resultData.putByteArray(ApgHandler.NEW_KEY, resultData.putByteArray(ApgHandler.RESULT_NEW_KEY,
Utils.PGPSecretKeyRingToBytes(newKeyRing)); Utils.PGPSecretKeyRingToBytes(newKeyRing));
sendMessageToHandler(ApgHandler.MESSAGE_OKAY, null, resultData); sendMessageToHandler(ApgHandler.MESSAGE_OKAY, null, resultData);
} catch (Exception e) { } catch (Exception e) {
@@ -178,9 +178,9 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
// Output // Output
Bundle resultData = new Bundle(); Bundle resultData = new Bundle();
resultData.putByteArray(ApgHandler.NEW_KEY, resultData.putByteArray(ApgHandler.RESULT_NEW_KEY,
Utils.PGPSecretKeyRingToBytes(masterKeyRing)); Utils.PGPSecretKeyRingToBytes(masterKeyRing));
resultData.putByteArray(ApgHandler.NEW_KEY2, resultData.putByteArray(ApgHandler.RESULT_NEW_KEY2,
Utils.PGPSecretKeyRingToBytes(subKeyRing)); Utils.PGPSecretKeyRingToBytes(subKeyRing));
sendMessageToHandler(ApgHandler.MESSAGE_OKAY, null, resultData); sendMessageToHandler(ApgHandler.MESSAGE_OKAY, null, resultData);
} catch (Exception e) { } catch (Exception e) {
@@ -200,7 +200,7 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
e.printStackTrace(); e.printStackTrace();
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putString(ApgHandler.ERROR, e.getMessage()); data.putString(ApgHandler.DATA_ERROR, e.getMessage());
sendMessageToHandler(ApgHandler.MESSAGE_EXCEPTION, null, data); sendMessageToHandler(ApgHandler.MESSAGE_EXCEPTION, null, data);
} }
@@ -235,10 +235,10 @@ public class ApgService extends IntentService implements ProgressDialogUpdater {
Bundle data = new Bundle(); Bundle data = new Bundle();
if (message != null) { if (message != null) {
data.putString(ApgHandler.MESSAGE, message); data.putString(ApgHandler.DATA_MESSAGE, message);
} }
data.putInt(ApgHandler.PROGRESS, progress); data.putInt(ApgHandler.DATA_PROGRESS, progress);
data.putInt(ApgHandler.PROGRESS_MAX, max); data.putInt(ApgHandler.DATA_PROGRESS_MAX, max);
sendMessageToHandler(ApgHandler.MESSAGE_UPDATE_PROGRESS, null, data); 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.Iterator;
import java.util.Vector; import java.util.Vector;
public class EditKeyActivity extends SherlockFragmentActivity { // extends BaseActivity { public class EditKeyActivity extends SherlockFragmentActivity {
private Intent mIntent = null; private Intent mIntent = null;
private ActionBar mActionBar; private ActionBar mActionBar;
@@ -207,10 +207,10 @@ public class EditKeyActivity extends SherlockFragmentActivity { // extends BaseA
Bundle data = message.getData(); Bundle data = message.getData();
PGPSecretKeyRing masterKeyRing = Utils PGPSecretKeyRing masterKeyRing = Utils
.BytesToPGPSecretKeyRing(data .BytesToPGPSecretKeyRing(data
.getByteArray(ApgHandler.NEW_KEY)); .getByteArray(ApgHandler.RESULT_NEW_KEY));
PGPSecretKeyRing subKeyRing = Utils PGPSecretKeyRing subKeyRing = Utils
.BytesToPGPSecretKeyRing(data .BytesToPGPSecretKeyRing(data
.getByteArray(ApgHandler.NEW_KEY2)); .getByteArray(ApgHandler.RESULT_NEW_KEY2));
// add master key // add master key
Iterator<PGPSecretKey> masterIt = masterKeyRing.getSecretKeys(); 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 // get new key from data bundle returned from service
Bundle data = message.getData(); Bundle data = message.getData();
PGPSecretKeyRing newKeyRing = Utils.BytesToPGPSecretKeyRing(data PGPSecretKeyRing newKeyRing = Utils.BytesToPGPSecretKeyRing(data
.getByteArray(ApgHandler.NEW_KEY)); .getByteArray(ApgHandler.RESULT_NEW_KEY));
boolean isMasterKey = (mEditors.getChildCount() == 0); boolean isMasterKey = (mEditors.getChildCount() == 0);