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