linuxman94

sorting

Feb 20th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. private List<AppContainer> getInstalledApps() {
  2. final PackageManager pm = mContext.getPackageManager();
  3. Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
  4. mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  5. List<AppContainer> apps = new ArrayList<AppContainer>();
  6. List<ResolveInfo> packages = pm.queryIntentActivities(mainIntent, 0);
  7. for (int i = 0; i < packages.size(); i++) {
  8. ResolveInfo p = packages.get(i);
  9. ApplicationInfo appInfo = p.activityInfo.applicationInfo;
  10. AppContainer app = new AppContainer();
  11. app.appPackage = appInfo.packageName;
  12. app.appName = appInfo.name;
  13. app.icon = appInfo.loadIcon(pm);
  14. apps.add(app);
  15. }
  16.  
  17. Collections.sort(apps, new Comparator<AppContainer>() {
  18. public int compare(AppContainer app1, AppContainer app2) {
  19. return app1.appName.compareTo(app2.appName);
  20. }
  21. });
  22.  
  23. return apps;
  24. }
  25.  
  26. public List<ImageView> getAppImageViews() {
  27. List<AppContainer> appList = getInstalledApps();
  28. List<ImageView> appViews = new ArrayList<ImageView>();
  29. for (int i = 0; i < appList.size(); i++) {
  30. ImageView view = new ImageView(mContext);
  31. view.setPadding(15, 5, 15, 5); /* TODO Do not hardcode this */
  32. view.setOnTouchListener(getTouchListenerForPackage(appList.get(i).appPackage, false));
  33. view.setImageDrawable(appList.get(i).icon);
  34. view.setTag(appList.get(i).appPackage);
  35. appViews.add(view);
  36. }
  37. return appViews;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment