aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-02-27 13:14:24 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-02-27 13:14:24 +0100
commit3ff7610d3b42c384605303d97809cad337a6d4ee (patch)
treec04e760d643165b0aace3a72b85eeca373ec879e
parent5f669fa813da02017333f571f793c0513bcf80ca (diff)
parentb0ca33da40d80149dd9861694a910a52a3d20eb4 (diff)
downloadopen-keychain-3ff7610d3b42c384605303d97809cad337a6d4ee.tar.gz
open-keychain-3ff7610d3b42c384605303d97809cad337a6d4ee.tar.bz2
open-keychain-3ff7610d3b42c384605303d97809cad337a6d4ee.zip
Merge pull request #308 from mar-v-in/issue-295
Show link to Market if no openpgp provider installed installed
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/res/values/strings.xml1
-rw-r--r--OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpListPreference.java50
2 files changed, 48 insertions, 3 deletions
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/res/values/strings.xml b/OpenPGP-Keychain-API/libraries/keychain-api-library/res/values/strings.xml
index a198d0b5e..0119831cc 100644
--- a/OpenPGP-Keychain-API/libraries/keychain-api-library/res/values/strings.xml
+++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/res/values/strings.xml
@@ -2,5 +2,6 @@
<resources>
<string name="openpgp_list_preference_none">None</string>
+ <string name="openpgp_install_openkeychain_via">Install OpenKeychain via %s</string>
</resources> \ No newline at end of file
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 034186a3a..7aea8f9fa 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
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
@@ -30,17 +31,21 @@ import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
+import org.sufficientlysecure.keychain.api.R;
import java.util.ArrayList;
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 static final String OPENKEYCHAIN_PACKAGE = "org.sufficientlysecure.keychain";
+ private static final String MARKET_INTENT_URI_BASE = "market://details?id=%s";
+ private static final Intent MARKET_INTENT = new Intent(Intent.ACTION_VIEW, Uri.parse(
+ String.format(MARKET_INTENT_URI_BASE, OPENKEYCHAIN_PACKAGE)));
+
private ArrayList<OpenPgpProviderEntry> mProviderList = new ArrayList<OpenPgpProviderEntry>();
private String mSelectedPackage;
@@ -84,6 +89,24 @@ public class OpenPgpListPreference extends DialogPreference {
}
}
+
+ // add install links if empty
+ if (mProviderList.isEmpty()) {
+ resInfo = getContext().getPackageManager().queryIntentActivities
+ (MARKET_INTENT, 0);
+ for (ResolveInfo resolveInfo : resInfo) {
+ Intent marketIntent = new Intent(MARKET_INTENT);
+ intent.setPackage(resolveInfo.activityInfo.packageName);
+ Drawable icon = resolveInfo.activityInfo.loadIcon(getContext().getPackageManager());
+ String marketName = String.valueOf(resolveInfo.activityInfo.applicationInfo
+ .loadLabel(getContext().getPackageManager()));
+ String simpleName = String.format(getContext().getString(R.string
+ .openpgp_install_openkeychain_via), marketName);
+ mProviderList.add(new OpenPgpProviderEntry(OPENKEYCHAIN_PACKAGE, simpleName,
+ icon, marketIntent));
+ }
+ }
+
// add "none"-entry
mProviderList.add(0, new OpenPgpProviderEntry("",
getContext().getString(R.string.openpgp_list_preference_none),
@@ -114,7 +137,22 @@ public class OpenPgpListPreference extends DialogPreference {
@Override
public void onClick(DialogInterface dialog, int which) {
- mSelectedPackage = mProviderList.get(which).packageName;
+ OpenPgpProviderEntry entry = mProviderList.get(which);
+
+ if (entry.intent != null) {
+ /*
+ * Intents are called as activity
+ *
+ * Current approach is to assume the user installed the app.
+ * If he does not, the selected package is not valid.
+ *
+ * However applications should always consider this could happen,
+ * as the user might remove the currently used OpenPGP app.
+ */
+ getContext().startActivity(entry.intent);
+ }
+
+ mSelectedPackage = entry.packageName;
/*
* Clicking on an item simulates the positive button click, and dismisses
@@ -190,6 +228,7 @@ public class OpenPgpListPreference extends DialogPreference {
private String packageName;
private String simpleName;
private Drawable icon;
+ private Intent intent;
public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon) {
this.packageName = packageName;
@@ -197,6 +236,11 @@ public class OpenPgpListPreference extends DialogPreference {
this.icon = icon;
}
+ public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon, Intent intent) {
+ this(packageName, simpleName, icon);
+ this.intent = intent;
+ }
+
@Override
public String toString() {
return simpleName;