From 52f1c930ebe98251fb9d3b34b2725087f2917f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sat, 15 Feb 2014 13:00:47 +0100 Subject: parse string util method, better help text for access screen --- .../openintents/openpgp/util/OpenPgpConstants.java | 2 ++ .../openpgp/util/OpenPgpListPreference.java | 39 +++++----------------- .../openpgp/util/OpenPgpServiceConnection.java | 5 +-- .../org/openintents/openpgp/util/OpenPgpUtils.java | 34 +++++++++++++------ 4 files changed, 37 insertions(+), 43 deletions(-) (limited to 'OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org') diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java index 229c8d42a..263b42aaa 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpConstants.java @@ -32,6 +32,8 @@ public class OpenPgpConstants { // (for encrypt method) public static final String PARAMS_USER_IDS = "user_ids"; public static final String PARAMS_KEY_IDS = "key_ids"; + // optional parameter: + public static final String PARAMS_PASSPHRASE = "passphrase"; /* Service Bundle returns */ public static final String RESULT_CODE = "result_code"; diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java index ea287a7a9..e29794e87 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java @@ -16,16 +16,11 @@ package org.openintents.openpgp.util; -import java.util.ArrayList; -import java.util.List; - import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.content.pm.ServiceInfo; import android.graphics.drawable.Drawable; import android.preference.DialogPreference; import android.util.AttributeSet; @@ -35,6 +30,9 @@ import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.TextView; +import java.util.ArrayList; +import java.util.List; + public class OpenPgpListPreference extends DialogPreference { ArrayList mProviderList = new ArrayList(); private String mSelectedPackage; @@ -42,8 +40,8 @@ public class OpenPgpListPreference extends DialogPreference { public OpenPgpListPreference(Context context, AttributeSet attrs) { super(context, attrs); - List resInfo = context.getPackageManager().queryIntentServices( - new Intent(OpenPgpConstants.SERVICE_INTENT), PackageManager.GET_META_DATA); + Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); + List resInfo = context.getPackageManager().queryIntentServices(intent, 0); if (!resInfo.isEmpty()) { for (ResolveInfo resolveInfo : resInfo) { if (resolveInfo.serviceInfo == null) @@ -54,12 +52,7 @@ public class OpenPgpListPreference extends DialogPreference { .getPackageManager())); Drawable icon = resolveInfo.serviceInfo.loadIcon(context.getPackageManager()); - // get api version - ServiceInfo si = resolveInfo.serviceInfo; - int apiVersion = si.metaData.getInt("api_version"); - - mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon, - apiVersion)); + mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon)); } } } @@ -75,10 +68,8 @@ public class OpenPgpListPreference extends DialogPreference { * @param simpleName * @param icon */ - public void addProvider(int position, String packageName, String simpleName, Drawable icon, - int apiVersion) { - mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon, - apiVersion)); + public void addProvider(int position, String packageName, String simpleName, Drawable icon) { + mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon)); } @Override @@ -99,15 +90,6 @@ public class OpenPgpListPreference extends DialogPreference { int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp10); - // disable if it has the wrong api_version - if (mProviderList.get(position).apiVersion == OpenPgpConstants.API_VERSION) { - tv.setEnabled(true); - } else { - tv.setEnabled(false); - tv.setText(tv.getText() + " (API v" + mProviderList.get(position).apiVersion - + ", needs v" + OpenPgpConstants.API_VERSION + ")"); - } - return v; } }; @@ -183,14 +165,11 @@ public class OpenPgpListPreference extends DialogPreference { private String packageName; private String simpleName; private Drawable icon; - private int apiVersion; - public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon, - int apiVersion) { + public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon) { this.packageName = packageName; this.simpleName = simpleName; this.icon = icon; - this.apiVersion = apiVersion; } @Override diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java index 780b4606b..8e8812faa 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java @@ -61,11 +61,12 @@ public class OpenPgpServiceConnection { /** * If not already bound, bind! - * + * * @return */ public boolean bindToService() { - if (mService == null && !mBound) { // if not already connected + // if not already connected + if (mService == null && !mBound) { try { Log.d(OpenPgpConstants.TAG, "not bound yet"); diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java index 6dbf76897..ffecaceba 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java @@ -17,6 +17,7 @@ package org.openintents.openpgp.util; import java.util.List; +import java.util.regex.Matcher; import java.util.regex.Pattern; import android.content.Context; @@ -24,22 +25,33 @@ import android.content.Intent; import android.content.pm.ResolveInfo; public class OpenPgpUtils { - private Context context; - public static Pattern PGP_MESSAGE = Pattern.compile( - ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); + public static final Pattern PGP_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", + Pattern.DOTALL); - public static Pattern PGP_SIGNED_MESSAGE = Pattern - .compile( - ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", - Pattern.DOTALL); + public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", + Pattern.DOTALL); - public OpenPgpUtils(Context context) { - super(); - this.context = context; + public static final int PARSE_RESULT_NO_PGP = -1; + public static final int PARSE_RESULT_MESSAGE = 0; + public static final int PARSE_RESULT_SIGNED_MESSAGE = 1; + + public static int parseMessage(String message) { + Matcher matcherSigned = PGP_SIGNED_MESSAGE.matcher(message); + Matcher matcherMessage = PGP_MESSAGE.matcher(message); + + if (matcherMessage.matches()) { + return PARSE_RESULT_MESSAGE; + } else if (matcherSigned.matches()) { + return PARSE_RESULT_SIGNED_MESSAGE; + } else { + return PARSE_RESULT_NO_PGP; + } } - public boolean isAvailable() { + public static boolean isAvailable(Context context) { Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); List resInfo = context.getPackageManager().queryIntentServices(intent, 0); if (!resInfo.isEmpty()) { -- cgit v1.2.3