use of com.google.classysharkandroid.adapters.StableArrayAdapter in project android-classyshark by google.
the class MainActivity method onStart.
@Override
public void onStart() {
super.onStart();
final ArrayList<AppListNode> apps = new ArrayList<>();
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
for (Object object : pkgAppsList) {
ResolveInfo info = (ResolveInfo) object;
File file = new File(info.activityInfo.applicationInfo.publicSourceDir);
AppListNode aln = new AppListNode();
aln.name = info.activityInfo.applicationInfo.processName.toString();
aln.file = file;
apps.add(aln);
}
Collections.sort(apps);
final StableArrayAdapter adapter = new StableArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, convert(apps));
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MimeTypeMap myMime = MimeTypeMap.getSingleton();
Intent newIntent = new Intent(MainActivity.this, ClassesListActivity.class);
String mimeType = myMime.getMimeTypeFromExtension("apk");
newIntent.setDataAndType(Uri.fromFile(apps.get(position).file), mimeType);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.putExtra(APP_NAME, apps.get(position).name);
try {
startActivity(newIntent);
} catch (ActivityNotFoundException e) {
}
}
});
}
Aggregations