Search in sources :

Example 1 with StableArrayAdapter

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) {
            }
        }
    });
}
Also used : StableArrayAdapter(com.google.classysharkandroid.adapters.StableArrayAdapter) ArrayList(java.util.ArrayList) Intent(android.content.Intent) MimeTypeMap(android.webkit.MimeTypeMap) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ResolveInfo(android.content.pm.ResolveInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) AdapterView(android.widget.AdapterView) File(java.io.File)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 ResolveInfo (android.content.pm.ResolveInfo)1 View (android.view.View)1 MimeTypeMap (android.webkit.MimeTypeMap)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 StableArrayAdapter (com.google.classysharkandroid.adapters.StableArrayAdapter)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1