private void addPluginPreferences(PreferenceScreen screen) {
    Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> resolveInfoList =
        pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA);
    int length = resolveInfoList.size();
    LinkedHashMap<String, ArrayList<Preference>> categoryPreferences =
        new LinkedHashMap<String, ArrayList<Preference>>();

    // Loop through a list of all packages (including plugins, addons)
    // that have a settings action
    for (int i = 0; i < length; i++) {
      ResolveInfo resolveInfo = resolveInfoList.get(i);
      Intent intent = new Intent(AstridApiConstants.ACTION_SETTINGS);
      intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);

      if (MilkPreferences.class.getName().equals(resolveInfo.activityInfo.name)
          && !MilkUtilities.INSTANCE.isLoggedIn()) continue;

      Preference preference = new Preference(this);
      preference.setTitle(resolveInfo.activityInfo.loadLabel(pm));
      preference.setIntent(intent);

      String category = MetadataHelper.resolveActivityCategoryName(resolveInfo, pm);

      if (!categoryPreferences.containsKey(category))
        categoryPreferences.put(category, new ArrayList<Preference>());
      ArrayList<Preference> arrayList = categoryPreferences.get(category);
      arrayList.add(preference);
    }

    for (Entry<String, ArrayList<Preference>> entry : categoryPreferences.entrySet()) {
      Preference header = new Preference(this);
      header.setLayoutResource(android.R.layout.preference_category);
      header.setTitle(entry.getKey());
      screen.addPreference(header);

      for (Preference preference : entry.getValue()) screen.addPreference(preference);
    }
  }
示例#2
0
  private void addPluginPreferences(PreferenceScreen screen) {
    Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> resolveInfoList =
        pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA);
    int length = resolveInfoList.size();
    LinkedHashMap<String, ArrayList<Preference>> categoryPreferences =
        new LinkedHashMap<String, ArrayList<Preference>>();

    // Loop through a list of all packages (including plugins, addons)
    // that have a settings action
    String labsTitle = getString(R.string.EPr_labs_header);
    for (int i = 0; i < length; i++) {
      ResolveInfo resolveInfo = resolveInfoList.get(i);
      final Intent intent = new Intent(AstridApiConstants.ACTION_SETTINGS);
      intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);

      if (MilkPreferences.class.getName().equals(resolveInfo.activityInfo.name)
          && !MilkUtilities.INSTANCE.isLoggedIn()) continue;

      if (GtasksPreferences.class.getName().equals(resolveInfo.activityInfo.name)
          && AmazonMarketStrategy.isKindleFire()) continue;

      if (ProducteevPreferences.class.getName().equals(resolveInfo.activityInfo.name)
          && !Preferences.getBoolean(R.string.p_third_party_addons, false)
          && !ProducteevUtilities.INSTANCE.isLoggedIn()) continue;

      Preference preference = new Preference(this);
      preference.setTitle(resolveInfo.activityInfo.loadLabel(pm));
      if (labsTitle.equals(preference.getTitle())) preference.setSummary(R.string.EPr_labs_desc);
      try {
        Class<?> intentComponent = Class.forName(intent.getComponent().getClassName());
        if (intentComponent.getSuperclass().equals(SyncProviderPreferences.class))
          intentComponent = SyncProviderPreferences.class;
        if (PREFERENCE_REQUEST_CODES.containsKey(intentComponent)) {
          final int code = PREFERENCE_REQUEST_CODES.get(intentComponent);
          preference.setOnPreferenceClickListener(
              new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference pref) {
                  startActivityForResult(intent, code);
                  return true;
                }
              });
        } else {
          preference.setIntent(intent);
        }
      } catch (ClassNotFoundException e) {
        preference.setIntent(intent);
      }

      String category = MetadataHelper.resolveActivityCategoryName(resolveInfo, pm);

      if (!categoryPreferences.containsKey(category))
        categoryPreferences.put(category, new ArrayList<Preference>());
      ArrayList<Preference> arrayList = categoryPreferences.get(category);
      arrayList.add(preference);
    }

    for (Entry<String, ArrayList<Preference>> entry : categoryPreferences.entrySet()) {
      Preference header = new Preference(this);
      header.setLayoutResource(android.R.layout.preference_category);
      header.setTitle(entry.getKey());
      screen.addPreference(header);

      for (Preference preference : entry.getValue()) screen.addPreference(preference);
    }
  }