Android 仿360恶意广告拦截扫描

[java]  view plain  copy
 print ?
  1. public class GalleryMoveTest extends Activity {  
  2.     private TextView tv_hintTextView;  
  3.   
  4.     @Override  
  5.     protected void onCreate(Bundle savedInstanceState) {  
  6.         super.onCreate(savedInstanceState);  
  7.         setContentView(R.layout.gallerytest);  
  8.         tv_hintTextView = (TextView) findViewById(R.id.tv_hint);  
  9.         new AsyncTask<String, Integer, ArrayList<HashMap<String, Drawable>>>() {  
  10.   
  11.             @Override  
  12.             protected ArrayList<HashMap<String, Drawable>> doInBackground(  
  13.                     String... params) {  
  14.                 ArrayList<HashMap<String, Drawable>> appList = null;  
  15.                 appList = getAppList();  
  16.                 return appList;  
  17.             }  
  18.   
  19.             @Override  
  20.             protected void onPostExecute(  
  21.                     final ArrayList<HashMap<String, Drawable>> result) {  
  22.                 super.onPostExecute(result);  
  23.                 if (result != null) {  
  24.                     final Gallery gallery = (Gallery) findViewById(R.id.gallery1);  
  25.                     gallery.setPadding(10101010);  
  26.                     gallery.setAdapter(new ImageAdapter(GalleryMoveTest.this,  
  27.                             result));  
  28.                     final ProgressBar pBar = (ProgressBar) findViewById(R.id.pb_gallery);  
  29.                     pBar.setMax(result.size());  
  30.                     final Handler handler = new Handler() {  
  31.                         public void handleMessage(android.os.Message msg) {  
  32.                             int what = msg.what;  
  33.                             pBar.setProgress(what + 1);  
  34.                             gallery.setSelection(what);  
  35.                             tv_hintTextView.setText((what + 1) + "/"  
  36.                                     + result.size());  
  37.                             Log.i("max""max:" + result.size() + "prog "  
  38.                                     + (what + 1));  
  39.                         }  
  40.   
  41.                     };  
  42.                     new Thread(new Runnable() {  
  43.   
  44.                         private int progress = 0;  
  45.   
  46.                         @Override  
  47.                         public void run() {  
  48.                             while (progress < result.size()) {  
  49.   
  50.                                 try {  
  51.                                     Thread.sleep(500);  
  52.                                 } catch (InterruptedException e) {  
  53.                                     e.printStackTrace();  
  54.                                 }  
  55.                                 handler.sendEmptyMessage(progress++);  
  56.                             }  
  57.   
  58.                         }  
  59.                     }).start();  
  60.                 }  
  61.             }  
  62.         }.execute();  
  63.     }  
  64.   
  65.     private ArrayList<HashMap<String, Drawable>> getAppList() {  
  66.         PackageManager pManager = getPackageManager();  
  67.         List<ApplicationInfo> applications = pManager  
  68.                 .getInstalledApplications(0);  
  69.         ArrayList<HashMap<String, Drawable>> list = null;  
  70.         if (applications != null && applications.size() > 0) {  
  71.             list = new ArrayList<HashMap<String, Drawable>>();  
  72.             HashMap<String, Drawable> map = null;  
  73.             for (ApplicationInfo applicationInfo : applications) {  
  74.                 map = new HashMap<String, Drawable>();  
  75.                 String name = applicationInfo.loadLabel(pManager).toString();  
  76.                 Drawable icon = applicationInfo.loadIcon(pManager);  
  77.                 map.put(name, icon);  
  78.                 list.add(map);  
  79.             }  
  80.         }  
  81.         return list;  
  82.     }  
  83.   
  84.     public class ImageAdapter extends BaseAdapter {  
  85.         private Context mContext;  
  86.         private ArrayList<HashMap<String, Drawable>> mList;  
  87.   
  88.         public ImageAdapter(Context context,  
  89.                 ArrayList<HashMap<String, Drawable>> list) {  
  90.   
  91.             this.mContext = context;  
  92.             this.mList = list;  
  93.         }  
  94.   
  95.         @Override  
  96.         public int getCount() {  
  97.             return mList.size();  
  98.         }  
  99.   
  100.         @Override  
  101.         public Object getItem(int position) {  
  102.             return position;  
  103.         }  
  104.   
  105.         @Override  
  106.         public long getItemId(int position) {  
  107.             return position;  
  108.         }  
  109.   
  110.         @Override  
  111.         public View getView(int position, View convertView, ViewGroup parent) {  
  112.             HashMap<String, Drawable> hashMap = mList.get(position);  
  113.             Collection<Drawable> values = hashMap.values();  
  114.             ImageView imageView = null;  
  115.             for (Drawable drawable : values) {  
  116.                 imageView = new ImageView(mContext);  
  117.                 imageView.setScaleType(ScaleType.FIT_XY);  
  118.                 Gallery.LayoutParams galleryParams = new Gallery.LayoutParams(  
  119.                         100100);  
  120.                 imageView.setLayoutParams(galleryParams);  
  121.                 imageView.setImageDrawable(drawable);  
  122.             }  
  123.             return imageView;  
  124.         }  
  125.     }  
  126.   
  127. }  



转载:http://blog.csdn.net/chaoyu168/article/details/49077223

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值