package com.lcs.cai;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;


public class MyActivity extends Activity {
	private AppTool appTool;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my);
		this.appTool = new AppTool(this);

		Log.i("lcs" , this.appTool.getAllApp().toString());
		GridView appView = (GridView) this.findViewById(R.id.appView);
		List<ResolveInfo> appList = (List<ResolveInfo>)this.appTool.getAllApp();

		appView.setAdapter(new MyAdapter( this, appList , getPackageManager() ));
		appView.setNumColumns(3);//
	//	appView.setOnItemClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.my, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}



	private class MyAdapter extends  BaseAdapter{

		private List<ResolveInfo> appList ;
		private PackageManager packageManager;
		private Context context;
		public  MyAdapter(Context  context ,List<ResolveInfo> appList  , PackageManager packageManager){
			this.appList = appList;
			this.packageManager = packageManager;
			this.context = context;
		}

		@Override
		public int getCount() {
			return this.appList.size();
		}

		@Override
		public Object getItem(int i) {
			return this.appList.get(i);
		}

		@Override
		public long getItemId(int i) {
			return 0;
		}

		@Override
		public View getView(int i, View view, ViewGroup viewGroup) {
			ImageButton btn = new ImageButton(this.context);
			ResolveInfo res = this.appList.get(i);
			btn.setImageDrawable(res.loadIcon( this.packageManager ));
			return btn;
		}
	}
}
@@ -69,20 +69,89 @@
 ntent.Co
-ntex
+mponentName;%0Aimport android.content.Context;%0Aimport android.content.Inten
 t;%0Aimpor
@@ -281,44 +281,8 @@
 og;%0A
-import android.view.LayoutInflater;%0A
 impo
@@ -390,16 +390,51 @@
 wGroup;%0A
+import android.widget.AdapterView;%0A
 import a
@@ -564,68 +564,8 @@
 ew;%0A
-import android.widget.TextView;%0A%0Aimport java.util.ArrayList;
 %0Aimp
@@ -627,16 +627,17 @@
 ctivity 
+ 
 %7B%0A%09priva
@@ -1138,18 +1138,16 @@
 (3);//%0A%09
-//
 %09appView
@@ -1170,22 +1170,302 @@
 istener(
-this);
+ new AdapterView.OnItemClickListener() %7B%0A%09%09%09@Override%0A%09%09%09public void onItemClick(AdapterView%3C?%3E adapterView, View view, int i, long l) %7B%0A%09%09%09%09Intent intent = (Intent) view.getTag();%0A%09%09%09%09startActivity(intent);%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09for( int i = 0 ; i %3C 100 ; i++ )%7B%0A%09%09%09Log.i(%22a%22,%22asd : %22 + i);%0A%09%09%7D
 %0A%09%7D%0A%0A%09@O
@@ -2047,18 +2047,16 @@
 m);%0A%09%7D%0A%0A
-%0A%0A
 %09private
@@ -2701,22 +2701,20 @@
 %09%09%09Image
-Button
+View
  btn = n
@@ -2721,22 +2721,20 @@
 ew Image
-Button
+View
 (this.co
@@ -2820,17 +2820,16 @@
 oadIcon(
- 
 this.pac
@@ -2839,18 +2839,174 @@
 eManager
- 
 )
+);%0A%0A%09%09%09Intent intent = new Intent();%0A%09%09%09intent.setComponent(new ComponentName( res.activityInfo.packageName , res.activityInfo.name ));%0A%0A%09%09%09btn.setTag(intent
 );%0A%09%09%09re

添加点击事件，可以打开应用于