diff options
| author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-03-02 02:17:20 +0100 | 
|---|---|---|
| committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-03-02 02:17:20 +0100 | 
| commit | 8c6017e8905af7744cb44636908abc67d4b989b3 (patch) | |
| tree | 5310eea30f8fce9cbc89f6944e3ef7ffc58e63ea | |
| parent | 4a13f70a88d64591eb878ea2a9ff70b062c7cc52 (diff) | |
| download | open-keychain-8c6017e8905af7744cb44636908abc67d4b989b3.tar.gz open-keychain-8c6017e8905af7744cb44636908abc67d4b989b3.tar.bz2 open-keychain-8c6017e8905af7744cb44636908abc67d4b989b3.zip | |
fixes for OpenPgpListPreference
| -rw-r--r-- | OpenPGP-Keychain-API/libraries/keychain-api-library/src/org/openintents/openpgp/util/OpenPgpListPreference.java | 51 | 
1 files changed, 30 insertions, 21 deletions
| 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 5920f7080..ecc2b8ec1 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 @@ -46,7 +46,9 @@ public class OpenPgpListPreference extends DialogPreference {      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 ArrayList<OpenPgpProviderEntry> mLegacyList = new ArrayList<OpenPgpProviderEntry>(); +    private ArrayList<OpenPgpProviderEntry> mList = new ArrayList<OpenPgpProviderEntry>(); +      private String mSelectedPackage;      public OpenPgpListPreference(Context context, AttributeSet attrs) { @@ -64,15 +66,24 @@ public class OpenPgpListPreference extends DialogPreference {       * @param simpleName       * @param icon       */ -    public void addProvider(int position, String packageName, String simpleName, Drawable icon) { -        mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon)); +    public void addLegacyProvider(int position, String packageName, String simpleName, Drawable icon) { +        mLegacyList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon));      }      @Override      protected void onPrepareDialogBuilder(Builder builder) { - -        // get providers -        mProviderList.clear(); +        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()) { @@ -85,12 +96,12 @@ public class OpenPgpListPreference extends DialogPreference {                          .getPackageManager()));                  Drawable icon = resolveInfo.serviceInfo.loadIcon(getContext().getPackageManager()); -                mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon)); +                providerList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));              }          } -        // add install links if empty -        if (mProviderList.isEmpty()) { +        if (providerList.isEmpty()) { +            // add install links if provider list is empty              resInfo = getContext().getPackageManager().queryIntentActivities                      (MARKET_INTENT, 0);              for (ResolveInfo resolveInfo : resInfo) { @@ -101,26 +112,24 @@ public class OpenPgpListPreference extends DialogPreference {                          .loadLabel(getContext().getPackageManager()));                  String simpleName = String.format(getContext().getString(R.string                          .openpgp_install_openkeychain_via), marketName); -                mProviderList.add(new OpenPgpProviderEntry(OPENKEYCHAIN_PACKAGE, simpleName, +                mList.add(new OpenPgpProviderEntry(OPENKEYCHAIN_PACKAGE, simpleName,                          icon, marketIntent));              } +        } else { +            // add provider +            mList.addAll(providerList);          } -        // add "none"-entry -        mProviderList.add(0, new OpenPgpProviderEntry("", -                getContext().getString(R.string.openpgp_list_preference_none), -                getContext().getResources().getDrawable(R.drawable.ic_action_cancel_launchersize))); -          // Init ArrayAdapter with OpenPGP Providers          ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getContext(), -                android.R.layout.select_dialog_singlechoice, android.R.id.text1, mProviderList) { +                android.R.layout.select_dialog_singlechoice, android.R.id.text1, mList) {              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(mProviderList.get(position).icon, null, +                tv.setCompoundDrawablesWithIntrinsicBounds(mList.get(position).icon, null,                          null, null);                  // Add margin between image and text (support various screen densities) @@ -136,7 +145,7 @@ public class OpenPgpListPreference extends DialogPreference {                      @Override                      public void onClick(DialogInterface dialog, int which) { -                        OpenPgpProviderEntry entry = mProviderList.get(which); +                        OpenPgpProviderEntry entry = mList.get(which);                          if (entry.intent != null) {                              /* @@ -181,9 +190,9 @@ public class OpenPgpListPreference extends DialogPreference {      }      private int getIndexOfProviderList(String packageName) { -        for (OpenPgpProviderEntry app : mProviderList) { +        for (OpenPgpProviderEntry app : mList) {              if (app.packageName.equals(packageName)) { -                return mProviderList.indexOf(app); +                return mList.indexOf(app);              }          } @@ -214,7 +223,7 @@ public class OpenPgpListPreference extends DialogPreference {      }      public String getEntryByValue(String packageName) { -        for (OpenPgpProviderEntry app : mProviderList) { +        for (OpenPgpProviderEntry app : mList) {              if (app.packageName.equals(packageName)) {                  return app.simpleName;              } | 
