aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshley Hughes <spirit.returned@gmail.com>2015-02-01 23:12:48 +0000
committerAshley Hughes <spirit.returned@gmail.com>2015-02-01 23:12:48 +0000
commit16f31c27714e86717f79fc9863e7b4793e3aad96 (patch)
tree53d9379f83f707440a33e33d17ec1d46e2aa13a6
parentc866dc22bcfa004ec2c46bc86c08694e76d1058d (diff)
downloadopenpgp-api-16f31c27714e86717f79fc9863e7b4793e3aad96.tar.gz
openpgp-api-16f31c27714e86717f79fc9863e7b4793e3aad96.tar.bz2
openpgp-api-16f31c27714e86717f79fc9863e7b4793e3aad96.zip
initialise provider list in constructor
-rw-r--r--src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java103
1 files changed, 55 insertions, 48 deletions
diff --git a/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java b/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
index 31ba97c..e3c8e2e 100644
--- a/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
+++ b/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
@@ -60,6 +60,7 @@ public class OpenPgpListPreference extends DialogPreference {
public OpenPgpListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
+ populateExistingProviderList();
}
public OpenPgpListPreference(Context context) {
@@ -79,55 +80,8 @@ public class OpenPgpListPreference extends DialogPreference {
@Override
protected void onPrepareDialogBuilder(Builder builder) {
- mList.clear();
-
- // add "none"-entry
- mList.add(0, new OpenPgpProviderEntry("",
- getContext().getString(R.string.openpgp_list_preference_none),
- getContext().getResources().getDrawable(R.drawable.ic_action_cancel_launchersize)));
-
- // add all additional (legacy) providers
- mList.addAll(mLegacyList);
-
- // search for OpenPGP providers...
- ArrayList<OpenPgpProviderEntry> providerList = new ArrayList<OpenPgpProviderEntry>();
- Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT);
- List<ResolveInfo> resInfo = getContext().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(getContext()
- .getPackageManager()));
- Drawable icon = resolveInfo.serviceInfo.loadIcon(getContext().getPackageManager());
-
- if (!PROVIDER_BLACKLIST.contains(packageName)) {
- providerList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
- }
- }
- }
- if (providerList.isEmpty()) {
- // add install links if provider list is empty
- resInfo = getContext().getPackageManager().queryIntentActivities
- (MARKET_INTENT, 0);
- for (ResolveInfo resolveInfo : resInfo) {
- Intent marketIntent = new Intent(MARKET_INTENT);
- marketIntent.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);
- mList.add(new OpenPgpProviderEntry(OPENKEYCHAIN_PACKAGE, simpleName,
- icon, marketIntent));
- }
- } else {
- // add provider
- mList.addAll(providerList);
- }
+ populateExistingProviderList();
// Init ArrayAdapter with OpenPGP Providers
ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getContext(),
@@ -241,6 +195,59 @@ public class OpenPgpListPreference extends DialogPreference {
return null;
}
+ private void populateExistingProviderList()
+ {
+ mList.clear();
+
+ // add "none"-entry
+ mList.add(0, new OpenPgpProviderEntry("",
+ getContext().getString(R.string.openpgp_list_preference_none),
+ getContext().getResources().getDrawable(R.drawable.ic_action_cancel_launchersize)));
+
+ // add all additional (legacy) providers
+ mList.addAll(mLegacyList);
+
+ // search for OpenPGP providers...
+ ArrayList<OpenPgpProviderEntry> providerList = new ArrayList<OpenPgpProviderEntry>();
+ Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT);
+ List<ResolveInfo> resInfo = getContext().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(getContext()
+ .getPackageManager()));
+ Drawable icon = resolveInfo.serviceInfo.loadIcon(getContext().getPackageManager());
+
+ if (!PROVIDER_BLACKLIST.contains(packageName)) {
+ providerList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
+ }
+ }
+ }
+
+ if (providerList.isEmpty()) {
+ // add install links if provider list is empty
+ resInfo = getContext().getPackageManager().queryIntentActivities
+ (MARKET_INTENT, 0);
+ for (ResolveInfo resolveInfo : resInfo) {
+ Intent marketIntent = new Intent(MARKET_INTENT);
+ marketIntent.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);
+ mList.add(new OpenPgpProviderEntry(OPENKEYCHAIN_PACKAGE, simpleName,
+ icon, marketIntent));
+ }
+ } else {
+ // add provider
+ mList.addAll(providerList);
+ }
+ }
+
private static class OpenPgpProviderEntry {
private String packageName;
private String simpleName;