博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 仿360恶意广告拦截扫描
阅读量:6670 次
发布时间:2019-06-25

本文共 3174 字,大约阅读时间需要 10 分钟。

[java]   
 
  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

你可能感兴趣的文章
当区块链遇上人工智能,这次变革的意义到底有多重大?
查看>>
Linux下安装python
查看>>
Go基础系列:读取标准输入(一)
查看>>
CAD打印文字不显示怎么办
查看>>
js正则表达式全文关键字搜索并高亮
查看>>
Java代理模式
查看>>
PHP协程入门详解
查看>>
Java_Reflect_1
查看>>
HTML中的<table>标签及其子元素标签,JS中DOM对<table>的操作
查看>>
在linux中执行wget命令提示 -bash: wget: command not found 解决方法
查看>>
MobPush推送证书制作
查看>>
springmvc源码解析之配置加载ContextLoadListener
查看>>
SVN就是这么简单
查看>>
网站安全防护工作
查看>>
Java gc中能聊的那些事
查看>>
如何判断一个以太坊地址是不是合约?
查看>>
逆袭!? 期待下一个“BCH”出现
查看>>
Linux 终端下全能系统监控工具 dstat
查看>>
自动化运维工具Ansible的安装(资源)
查看>>
Oracle-如何收集统计信息
查看>>