aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain-API
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-02-15 18:51:58 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-02-15 18:51:58 +0100
commitea361f4bf50fca2dea96e83a186fff7bb01bccd7 (patch)
treefdc6dd5114d9891bcebb48cacb31d50f50001e12 /OpenPGP-Keychain-API
parent884aaf7e7ac24a54f54c4e714121869346b7a623 (diff)
downloadopen-keychain-ea361f4bf50fca2dea96e83a186fff7bb01bccd7.tar.gz
open-keychain-ea361f4bf50fca2dea96e83a186fff7bb01bccd7.tar.bz2
open-keychain-ea361f4bf50fca2dea96e83a186fff7bb01bccd7.zip
select provider with preference
Diffstat (limited to 'OpenPGP-Keychain-API')
-rw-r--r--OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java96
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpListPreference.java4
2 files changed, 18 insertions, 82 deletions
diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
index 7b1aecae9..33a94de61 100644
--- a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
+++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java
@@ -22,9 +22,12 @@ import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
+import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -101,7 +104,17 @@ public class OpenPgpProviderActivity extends Activity {
}
});
- selectCryptoProvider();
+ SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
+ String providerPackageName = settings.getString("openpgp_provider_list", "");
+ if (TextUtils.isEmpty(providerPackageName)) {
+ Toast.makeText(this, "No OpenPGP Provider selected!", Toast.LENGTH_LONG).show();
+ finish();
+ } else {
+ // bind to service
+ mCryptoServiceConnection = new OpenPgpServiceConnection(
+ OpenPgpProviderActivity.this, providerPackageName);
+ mCryptoServiceConnection.bindToService();
+ }
}
private void handleError(final OpenPgpError error) {
@@ -283,85 +296,4 @@ public class OpenPgpProviderActivity extends Activity {
}
}
- private void selectCryptoProvider() {
- Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT);
-
- final ArrayList<OpenPgpProviderElement> providerList = new ArrayList<OpenPgpProviderElement>();
-
- List<ResolveInfo> resInfo = getPackageManager().queryIntentServices(intent, 0);
- if (!resInfo.isEmpty()) {
- for (ResolveInfo resolveInfo : resInfo) {
- if (resolveInfo.serviceInfo == null)
- continue;
-
- String packageName = resolveInfo.serviceInfo.packageName;
- String simpleName = String.valueOf(resolveInfo.serviceInfo
- .loadLabel(getPackageManager()));
- Drawable icon = resolveInfo.serviceInfo.loadIcon(getPackageManager());
- providerList.add(new OpenPgpProviderElement(packageName, simpleName, icon));
- }
- }
-
- AlertDialog.Builder alert = new AlertDialog.Builder(this);
- alert.setTitle("Select OpenPGP Provider!");
- alert.setCancelable(false);
-
- if (!providerList.isEmpty()) {
- // add "disable OpenPGP provider"
- providerList.add(0, new OpenPgpProviderElement(null, "Disable OpenPGP Provider",
- getResources().getDrawable(android.R.drawable.ic_menu_close_clear_cancel)));
-
- // Init ArrayAdapter with OpenPGP Providers
- ListAdapter adapter = new ArrayAdapter<OpenPgpProviderElement>(this,
- android.R.layout.select_dialog_item, android.R.id.text1, providerList) {
- public View getView(int position, View convertView, ViewGroup parent) {
- // User super class to create the View
- View v = super.getView(position, convertView, parent);
- TextView tv = (TextView) v.findViewById(android.R.id.text1);
-
- // Put the image on the TextView
- tv.setCompoundDrawablesWithIntrinsicBounds(providerList.get(position).icon,
- null, null, null);
-
- // Add margin between image and text (support various screen densities)
- int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
- tv.setCompoundDrawablePadding(dp5);
-
- return v;
- }
- };
-
- alert.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() {
-
- public void onClick(DialogInterface dialog, int position) {
- String packageName = providerList.get(position).packageName;
-
- if (packageName == null) {
- dialog.cancel();
- finish();
- }
-
- // bind to service
- mCryptoServiceConnection = new OpenPgpServiceConnection(
- OpenPgpProviderActivity.this, packageName);
- mCryptoServiceConnection.bindToService();
-
- dialog.dismiss();
- }
- });
- } else {
- alert.setMessage("No OpenPGP Provider installed!");
- }
-
- alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
-
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- finish();
- }
- });
-
- AlertDialog ad = alert.create();
- ad.show();
- }
}
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpListPreference.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpListPreference.java
index f1f326fca..034186a3a 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpListPreference.java
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpListPreference.java
@@ -36,6 +36,10 @@ import java.util.List;
import org.sufficientlysecure.keychain.api.R;
+/**
+ * Does not extend ListPreference, but is very similar to it!
+ * http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/4.4_r1/android/preference/ListPreference.java/?v=source
+ */
public class OpenPgpListPreference extends DialogPreference {
private ArrayList<OpenPgpProviderEntry> mProviderList = new ArrayList<OpenPgpProviderEntry>();
private String mSelectedPackage;