save selected provider in list preference

This commit is contained in:
Dominik Schürmann 2014-02-15 18:44:13 +01:00
parent a659e97a64
commit 884aaf7e7a
5 changed files with 31 additions and 24 deletions

View File

@ -16,9 +16,6 @@
package org.sufficientlysecure.keychain.demo;
import org.sufficientlysecure.keychain.demo.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
@ -27,10 +24,7 @@ import android.preference.PreferenceActivity;
import android.widget.Toast;
public class BaseActivity extends PreferenceActivity {
private Activity mActivity;
private Preference mIntentDemo;
private Preference mContentProviderDemo;
private Preference mCryptoProvider;
/**
@ -40,14 +34,11 @@ public class BaseActivity extends PreferenceActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivity = this;
// load preferences from xml
addPreferencesFromResource(R.xml.base_preference);
// find preferences
mIntentDemo = (Preference) findPreference("intent_demo");
mContentProviderDemo = (Preference) findPreference("content_provider_demo");
mCryptoProvider = (Preference) findPreference("openpgp_provider_demo");
mIntentDemo.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@ -63,12 +54,11 @@ public class BaseActivity extends PreferenceActivity {
mCryptoProvider.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(mActivity, OpenPgpProviderActivity.class));
startActivity(new Intent(BaseActivity.this, OpenPgpProviderActivity.class));
return false;
}
});
}
}

View File

@ -35,7 +35,6 @@ import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
import org.openintents.openpgp.IOpenPgpService;
import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.util.OpenPgpApi;
import org.openintents.openpgp.util.OpenPgpConstants;
@ -49,8 +48,6 @@ import java.util.ArrayList;
import java.util.List;
public class OpenPgpProviderActivity extends Activity {
Activity mActivity;
EditText mMessage;
EditText mCiphertext;
EditText mEncryptUserIds;
@ -59,7 +56,7 @@ public class OpenPgpProviderActivity extends Activity {
Button mSignAndEncrypt;
Button mDecryptAndVerify;
private OpenPgpServiceConnection mCryptoServiceConnection;
OpenPgpServiceConnection mCryptoServiceConnection;
public static final int REQUEST_CODE_SIGN = 9910;
public static final int REQUEST_CODE_ENCRYPT = 9911;
@ -71,16 +68,14 @@ public class OpenPgpProviderActivity extends Activity {
super.onCreate(icicle);
setContentView(R.layout.openpgp_provider);
mActivity = this;
mMessage = (EditText) findViewById(R.id.crypto_provider_demo_message);
mCiphertext = (EditText) findViewById(R.id.crypto_provider_demo_ciphertext);
mEncryptUserIds = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id);
mSign = (Button) findViewById(R.id.crypto_provider_demo_sign);
mEncrypt = (Button) findViewById(R.id.crypto_provider_demo_encrypt);
mSignAndEncrypt = (Button) findViewById(R.id.crypto_provider_demo_sign_and_encrypt);
mDecryptAndVerify = (Button) findViewById(R.id.crypto_provider_demo_decrypt_and_verify);
mSign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -110,11 +105,11 @@ public class OpenPgpProviderActivity extends Activity {
}
private void handleError(final OpenPgpError error) {
mActivity.runOnUiThread(new Runnable() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mActivity,
Toast.makeText(OpenPgpProviderActivity.this,
"onError id:" + error.getErrorId() + "\n\n" + error.getMessage(),
Toast.LENGTH_LONG).show();
Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());

View File

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Intent" >
<PreferenceCategory android:title="OpenKeychain Intents">
<Preference
android:key="intent_demo"
android:title="Intent Demo" />
</PreferenceCategory>
<PreferenceCategory android:title="OpenPGP Provider" >
<PreferenceCategory android:title="OpenPGP Provider API">
<org.openintents.openpgp.util.OpenPgpListPreference
android:key="openpgp_provider_list"
android:title="Select OpenPGP Provider!" />
<Preference
android:key="openpgp_provider_demo"
android:title="OpenPGP Provider" />
android:title="OpenPGP Provider Demo" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -21,6 +21,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
@ -161,6 +162,16 @@ public class OpenPgpListPreference extends DialogPreference {
return getEntryByValue(mSelectedPackage);
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return a.getString(index);
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
setValue(restoreValue ? getPersistedString(mSelectedPackage) : (String) defaultValue);
}
public String getEntryByValue(String packageName) {
for (OpenPgpProviderEntry app : mProviderList) {
if (app.packageName.equals(packageName)) {

View File

@ -21,6 +21,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
@ -161,6 +162,16 @@ public class OpenPgpListPreference extends DialogPreference {
return getEntryByValue(mSelectedPackage);
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return a.getString(index);
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
setValue(restoreValue ? getPersistedString(mSelectedPackage) : (String) defaultValue);
}
public String getEntryByValue(String packageName) {
for (OpenPgpProviderEntry app : mProviderList) {
if (app.packageName.equals(packageName)) {