/config/src/com/google/marvin/config/AppListView.java

http://eyes-free.googlecode.com/ · Java · 65 lines · 49 code · 9 blank · 7 comment · 5 complexity · 4e8a1051f56cae3a5f6e9d07d3f768b3 MD5 · raw file

  1. package com.google.marvin.config;
  2. import java.util.ArrayList;
  3. import android.content.Context;
  4. import android.graphics.Canvas;
  5. import android.view.View;
  6. import android.widget.AdapterView;
  7. import android.widget.ListView;
  8. /**
  9. * A ListView for dealing with applications that can be installed.
  10. * This list will filter out already installed apps and not display them.
  11. *
  12. * @author clchen@google.com (Charles L. Chen)
  13. */
  14. public class AppListView extends ListView {
  15. private AppListAdapter appListAdapter;
  16. private ArrayList<AppDesc> appDescs;
  17. private Context ctx;
  18. public AppListView(Context context) {
  19. super(context);
  20. ctx = context;
  21. ArrayList<AppDesc> appDescs = new ArrayList<AppDesc>();
  22. AppDesc dummyApp = new AppDesc("", "", "");
  23. appDescs.add(dummyApp);
  24. appListAdapter = new AppListAdapter(ctx, appDescs);
  25. setAdapter(appListAdapter);
  26. setOnItemClickListener(new OnItemClickListener() {
  27. public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long rowId) {
  28. String packageName = appListAdapter.getPackageName((int) rowId);
  29. ctx.startActivity(Utils.getMarketIntent(packageName));
  30. }
  31. });
  32. }
  33. public void updateApps(ArrayList<AppDesc> apps) {
  34. appDescs = new ArrayList<AppDesc>();
  35. for (int i = 0; i < apps.size(); i++) {
  36. AppDesc app = apps.get(i);
  37. if (!Utils.applicationInstalled(ctx, app.getPackageName())) {
  38. appDescs.add(app);
  39. }
  40. }
  41. if (appDescs.size() < 1) {
  42. appDescs.add(new AppDesc("", ctx.getString(R.string.allAppsInstalledTitle), ctx.getString(R.string.allAppsInstalledMessage)));
  43. }
  44. }
  45. @Override
  46. protected void onDraw(Canvas canvas) {
  47. // Only try to update the adapter if there are new apps to update it with.
  48. if (appDescs != null) {
  49. appListAdapter = null;
  50. appListAdapter = new AppListAdapter(ctx, appDescs);
  51. setAdapter(appListAdapter);
  52. appDescs = null;
  53. }
  54. super.onDraw(canvas);
  55. }
  56. }