Android 仿360恶意广告拦截扫描

简介:
public class GalleryMoveTest extends Activity {
	private TextView tv_hintTextView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gallerytest);
		tv_hintTextView = (TextView) findViewById(R.id.tv_hint);
		new AsyncTask<String, Integer, ArrayList<HashMap<String, Drawable>>>() {

			@Override
			protected ArrayList<HashMap<String, Drawable>> doInBackground(
					String... params) {
				ArrayList<HashMap<String, Drawable>> appList = null;
				appList = getAppList();
				return appList;
			}

			@Override
			protected void onPostExecute(
					final ArrayList<HashMap<String, Drawable>> result) {
				super.onPostExecute(result);
				if (result != null) {
					final Gallery gallery = (Gallery) findViewById(R.id.gallery1);
					gallery.setPadding(10, 10, 10, 10);
					gallery.setAdapter(new ImageAdapter(GalleryMoveTest.this,
							result));
					final ProgressBar pBar = (ProgressBar) findViewById(R.id.pb_gallery);
					pBar.setMax(result.size());
					final Handler handler = new Handler() {
						public void handleMessage(android.os.Message msg) {
							int what = msg.what;
							pBar.setProgress(what + 1);
							gallery.setSelection(what);
							tv_hintTextView.setText((what + 1) + "/"
									+ result.size());
							Log.i("max", "max:" + result.size() + "prog "
									+ (what + 1));
						}

					};
					new Thread(new Runnable() {

						private int progress = 0;

						@Override
						public void run() {
							while (progress < result.size()) {

								try {
									Thread.sleep(500);
								} catch (InterruptedException e) {
									e.printStackTrace();
								}
								handler.sendEmptyMessage(progress++);
							}

						}
					}).start();
				}
			}
		}.execute();
	}

	private ArrayList<HashMap<String, Drawable>> getAppList() {
		PackageManager pManager = getPackageManager();
		List<ApplicationInfo> applications = pManager
				.getInstalledApplications(0);
		ArrayList<HashMap<String, Drawable>> list = null;
		if (applications != null && applications.size() > 0) {
			list = new ArrayList<HashMap<String, Drawable>>();
			HashMap<String, Drawable> map = null;
			for (ApplicationInfo applicationInfo : applications) {
				map = new HashMap<String, Drawable>();
				String name = applicationInfo.loadLabel(pManager).toString();
				Drawable icon = applicationInfo.loadIcon(pManager);
				map.put(name, icon);
				list.add(map);
			}
		}
		return list;
	}

	public class ImageAdapter extends BaseAdapter {
		private Context mContext;
		private ArrayList<HashMap<String, Drawable>> mList;

		public ImageAdapter(Context context,
				ArrayList<HashMap<String, Drawable>> list) {

			this.mContext = context;
			this.mList = list;
		}

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

		@Override
		public Object getItem(int position) {
			return position;
		}

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

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			HashMap<String, Drawable> hashMap = mList.get(position);
			Collection<Drawable> values = hashMap.values();
			ImageView imageView = null;
			for (Drawable drawable : values) {
				imageView = new ImageView(mContext);
				imageView.setScaleType(ScaleType.FIT_XY);
				Gallery.LayoutParams galleryParams = new Gallery.LayoutParams(
						100, 100);
				imageView.setLayoutParams(galleryParams);
				imageView.setImageDrawable(drawable);
			}
			return imageView;
		}
	}

}

目录
相关文章
|
9月前
|
Android开发
Android中实现获取相册中的图片扫描二维码的功能
Android中实现获取相册中的图片扫描二维码的功能
187 0
|
6天前
|
缓存 Java Android开发
Android 9.0 WiFi 扫描结果上报和获取流程
Android 9.0 WiFi 扫描结果上报和获取流程
8 0
|
7天前
|
Java Android开发
Android 对adb命令的拦截
Android 对adb命令的拦截
15 2
|
5月前
|
物联网 Android开发
Android Ble蓝牙App(七)扫描过滤
Android Ble蓝牙App(七)扫描过滤
|
5月前
|
物联网 API Android开发
Android Ble蓝牙App(一)扫描(下)
Android Ble蓝牙App(一)扫描(下)
|
5月前
|
XML 物联网 Android开发
Android Ble蓝牙App(一)扫描(上)
Android Ble蓝牙App(一)扫描(上)
|
5月前
|
物联网 Android开发
【Android App】低功耗蓝牙中扫描BLE设备的讲解及实战(附源码和演示 超详细)
【Android App】低功耗蓝牙中扫描BLE设备的讲解及实战(附源码和演示 超详细)
105 0
|
5月前
|
Android开发 网络架构
【Android App】检查手机连接WiFi信息以及扫描周围WiFi的讲解及实战(附源码和演示 超详细必看)
【Android App】检查手机连接WiFi信息以及扫描周围WiFi的讲解及实战(附源码和演示 超详细必看)
249 1
|
5月前
|
XML Java Android开发
Android Studio App开发实战项目之广告轮播(附源码 可用于大作业)
Android Studio App开发实战项目之广告轮播(附源码 可用于大作业)
75 1
|
物联网 Android开发
Android 低功耗蓝牙开发(扫描、连接)
Android 低功耗蓝牙开发(扫描、连接)
568 0
Android 低功耗蓝牙开发(扫描、连接)