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;
		}
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值