Beispiel #1
0
  @Override
  protected List<AppModel> loadData(ProgressCallback callback) {
    List<AppModel> list = new ArrayList<AppModel>();
    final PackageManager pm = getActivity().getPackageManager();
    List<ApplicationInfo> la = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    for (final ApplicationInfo info : la) {
      final AppModel app = new AppModel();
      app.packageName = info.packageName;
      app.title = pm.getApplicationLabel(info).toString();
      app.iconRefreshRunnable =
          new Runnable() {
            @Override
            public void run() {
              app.icon = new WeakReference<Drawable>(pm.getApplicationIcon(info));
            }
          };
      list.add(app);
      callback.updateProgress(list.size(), la.size());
    }

    Collections.sort(
        list,
        new Comparator<AppModel>() {
          @Override
          public int compare(AppModel p1, AppModel p2) {
            return Collator.getInstance().compare(p1.title, p2.title);
          }
        });

    // Add the Global config entry
    AppModel global = new AppModel();
    global.packageName = "global";
    global.title = getString(R.string.global);
    global.icon = null;
    list.add(0, global);

    return list;
  }