码迷,mamicode.com
首页 > 移动开发 > 详细

Android 手机卫士16--手机杀毒

时间:2016-10-22 16:57:42      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:最大   应用   停止   char   更新ui   dom   uninstall   pack   tco   

技术分享

1.指定动画一直旋转

rotateAnimation.setRepeatCount(RotateAnimation.INFINITE);

android:repeatCount 重复的次数,默认为0,必须是int,可以为-1表示不停止  

 

技术分享
  1 public class AnitVirusActivity extends Activity {
  2     protected static final int SCANING = 100;
  3 
  4     protected static final int SCAN_FINISH = 101;
  5     
  6     private ImageView iv_scanning;
  7     private TextView tv_name;
  8     private ProgressBar pb_bar;
  9     private LinearLayout ll_add_text;
 10     private int index = 0;
 11     private List<ScanInfo> mVirusScanInfoList;
 12     private Handler mHandler = new Handler(){
 13         public void handleMessage(android.os.Message msg) {
 14             switch (msg.what) {
 15             case SCANING:
 16                 //1,显示正在扫描应用的名称
 17                 ScanInfo info = (ScanInfo)msg.obj;
 18                 tv_name.setText(info.name);
 19                 //2,在线性布局中添加一个正在扫描应用的TextView
 20                 TextView textView = new TextView(getApplicationContext());
 21                 if(info.isVirus){
 22                     //是病毒
 23                     textView.setTextColor(Color.RED);
 24                     textView.setText("发现病毒:"+info.name);
 25                 }else{
 26                     //不是病毒
 27                     textView.setTextColor(Color.BLACK);
 28                     textView.setText("扫描安全:"+info.name);
 29                 }
 30                 ll_add_text.addView(textView, 0);
 31                 break;
 32             case SCAN_FINISH:
 33                 tv_name.setText("扫描完成");
 34                 //停止真正执行的旋转动画
 35                 iv_scanning.clearAnimation();
 36                 //告知用户卸载包含了病毒的应用
 37                 unInstallVirus();
 38                 break;
 39             }
 40         };
 41     };
 42 
 43     
 44 
 45     @Override
 46     protected void onCreate(Bundle savedInstanceState) {
 47         super.onCreate(savedInstanceState);
 48         setContentView(R.layout.activity_anit_virus);
 49         
 50         initUI();
 51         initAnimation();
 52         checkVirus();
 53     }
 54 
 55     protected void unInstallVirus() {
 56         for(ScanInfo scanInfo:mVirusScanInfoList){
 57             String packageName = scanInfo.packageName;
 58             //源码
 59             Intent intent = new Intent("android.intent.action.DELETE");
 60             intent.addCategory("android.intent.category.DEFAULT");
 61             intent.setData(Uri.parse("package:"+packageName));
 62             startActivity(intent);
 63         }
 64     }
 65 
 66     private void checkVirus() {
 67         new Thread(){
 68             public void run() {
 69                 //获取数据库中所有的病毒的md5码
 70                 List<String> virusList = VirusDao.getVirusList();
 71                 //获取手机上面的所有应用程序签名文件的md5码
 72                 //1.获取包管理者对象
 73                 PackageManager pm = getPackageManager();
 74                 //2.获取所有应用程序签名文件(PackageManager.GET_SIGNATURES 已安装应用的签名文件+)
 75                 //PackageManager.GET_UNINSTALLED_PACKAGES    卸载完了的应用,残余的文件
 76                 List<PackageInfo> packageInfoList = pm.getInstalledPackages(
 77                         PackageManager.GET_SIGNATURES + PackageManager.GET_UNINSTALLED_PACKAGES);
 78                 //创建记录病毒的集合
 79                 
 80                 mVirusScanInfoList = new ArrayList<ScanInfo>();
 81                 
 82                 //记录所有应用的集合
 83                 List<ScanInfo> scanInfoList = new ArrayList<ScanInfo>();
 84                 
 85                 //设置进度条的最大值
 86                 pb_bar.setMax(packageInfoList.size());
 87                 
 88                 //3.遍历应用集合
 89                 for (PackageInfo packageInfo : packageInfoList) {
 90                     ScanInfo scanInfo = new ScanInfo();
 91                     //获取签名文件的数组
 92                     Signature[] signatures = packageInfo.signatures;
 93                     //获取签名文件数组的第一位,然后进行md5,将此md5和数据库中的md5比对
 94                     Signature signature = signatures[0];
 95                     String string = signature.toCharsString();
 96                     //32位字符串,16进制字符(0-f)
 97                     String encoder = Md5Util.encoder(string);
 98                     //4,比对应用是否为病毒
 99                     if(virusList.contains(encoder)){
100                         //5.记录病毒
101                         scanInfo.isVirus = true;
102                         mVirusScanInfoList.add(scanInfo);
103                     }else{
104                         scanInfo.isVirus = false;
105                     }
106                     //6,维护对象的包名,以及应用名称
107                     scanInfo.packageName = packageInfo.packageName;
108                     scanInfo.name = packageInfo.applicationInfo.loadLabel(pm).toString();
109                     scanInfoList.add(scanInfo);
110                     //7.在扫描的过程中,需要更新进度条
111                     index++;
112                     pb_bar.setProgress(index);
113 
114                     try {
115                         Thread.sleep(50+new Random().nextInt(100));
116                     } catch (InterruptedException e) {
117                         e.printStackTrace();
118                     }
119                     
120                     //8.在子线程中发送消息,告知主线程更新UI(1:顶部扫描应用的名称2:扫描过程中往线性布局中添加view)
121                     Message msg = Message.obtain();
122                     msg.what = SCANING;
123                     msg.obj = scanInfo;
124                     mHandler.sendMessage(msg);
125                 }
126                 Message msg = Message.obtain();
127                 msg.what = SCAN_FINISH;
128                 mHandler.sendMessage(msg);
129             };
130         }.start();
131     }
132     
133     class ScanInfo{
134         public boolean isVirus;
135         public String packageName;
136         public String name;
137     }
138 
139     private void initAnimation() {
140         RotateAnimation rotateAnimation = new RotateAnimation(
141                 0, 360, 
142                 Animation.RELATIVE_TO_SELF, 0.5f,
143                 Animation.RELATIVE_TO_SELF, 0.5f);
144         rotateAnimation.setDuration(1000);
145         //指定动画一直旋转
146 //        rotateAnimation.setRepeatMode(RotateAnimation.INFINITE);
147         rotateAnimation.setRepeatCount(RotateAnimation.INFINITE);
148         //保持动画执行结束后的状态
149         rotateAnimation.setFillAfter(true);
150         //一直执行动画
151         iv_scanning.startAnimation(rotateAnimation);
152     }
153 
154     private void initUI() {
155         iv_scanning = (ImageView) findViewById(R.id.iv_scanning);
156         tv_name = (TextView) findViewById(R.id.tv_name);
157         pb_bar = (ProgressBar) findViewById(R.id.pb_bar);
158         ll_add_text = (LinearLayout) findViewById(R.id.ll_add_text);
159     }
160 }
AnitVirusActivity

 

Android 手机卫士16--手机杀毒

标签:最大   应用   停止   char   更新ui   dom   uninstall   pack   tco   

原文地址:http://www.cnblogs.com/ganchuanpu/p/5987641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!