aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-08-24 02:36:21 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2015-08-24 02:36:21 +0200
commita5240bebf4ca0bab13af25ccd8ae30ae413953c0 (patch)
treeaa17a2c6f1dadb111e126872fabf670a7f614063
parent989aa544b94e99703b3a75ce3c676a9b83ebb91e (diff)
downloadopenpgp-api-a5240bebf4ca0bab13af25ccd8ae30ae413953c0.tar.gz
openpgp-api-a5240bebf4ca0bab13af25ccd8ae30ae413953c0.tar.bz2
openpgp-api-a5240bebf4ca0bab13af25ccd8ae30ae413953c0.zip
Fix bugs in OpenPgpKeyPreference
-rw-r--r--openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java34
1 files changed, 21 insertions, 13 deletions
diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java
index 6343285..e4ef0a6 100644
--- a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java
+++ b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java
@@ -41,13 +41,15 @@ public class OpenPgpKeyPreference extends Preference {
public static final int REQUEST_CODE_KEY_PREFERENCE = 9999;
+ private static final int NO_KEY = 0;
+
public OpenPgpKeyPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public CharSequence getSummary() {
- return (mKeyId == 0) ? getContext().getString(R.string.openpgp_no_key_selected)
+ return (mKeyId == NO_KEY) ? getContext().getString(R.string.openpgp_no_key_selected)
: getContext().getString(R.string.openpgp_key_selected);
}
@@ -77,25 +79,27 @@ public class OpenPgpKeyPreference extends Preference {
new OpenPgpServiceConnection.OnBound() {
@Override
public void onBound(IOpenPgpService service) {
- Log.d(OpenPgpApi.TAG, "onBound!");
-
- Intent data = new Intent();
- data.setAction(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
- data.putExtra(OpenPgpApi.EXTRA_USER_ID, mDefaultUserId);
- OpenPgpApi api = new OpenPgpApi(getContext(), mServiceConnection.getService());
- api.executeApiAsync(data, null, null, new MyCallback(REQUEST_CODE_KEY_PREFERENCE));
+ getSignKeyId(new Intent());
}
@Override
public void onError(Exception e) {
- Log.e(OpenPgpApi.TAG, "exception when binding!", e);
+ Log.e(OpenPgpApi.TAG, "exception on binding!", e);
}
}
);
mServiceConnection.bindToService();
}
+ private void getSignKeyId(Intent data) {
+ data.setAction(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
+ data.putExtra(OpenPgpApi.EXTRA_USER_ID, mDefaultUserId);
+
+ OpenPgpApi api = new OpenPgpApi(getContext(), mServiceConnection.getService());
+ api.executeApiAsync(data, null, null, new MyCallback(REQUEST_CODE_KEY_PREFERENCE));
+ }
+
private class MyCallback implements OpenPgpApi.IOpenPgpCallback {
int requestCode;
@@ -107,7 +111,9 @@ public class OpenPgpKeyPreference extends Preference {
public void onReturn(Intent result) {
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS: {
- Log.e(OpenPgpApi.TAG, "RESULT_CODE_SUCCESS: Should not happen!");
+
+ long keyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, NO_KEY);
+ save(keyId);
break;
}
@@ -168,13 +174,16 @@ public class OpenPgpKeyPreference extends Preference {
// Data has changed, notify so UI can be refreshed!
notifyChanged();
+
+ // also update summary
+ setSummary(getSummary());
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
// This preference type's value type is Long, so we read the default
// value from the attributes as an Integer.
- return (long) a.getInteger(index, 0);
+ return (long) a.getInteger(index, NO_KEY);
}
@Override
@@ -274,8 +283,7 @@ public class OpenPgpKeyPreference extends Preference {
public boolean handleOnActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_KEY_PREFERENCE && resultCode == Activity.RESULT_OK) {
- long keyId = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0);
- save(keyId);
+ getSignKeyId(data);
return true;
} else {
return false;