1.目标效果

旋转动画+病毒查杀效果

2.xml布局文件

(1)activity_kill_virus.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".KillVirusActivity"> <TextView
style="@style/TitleStyle"
android:text="手机杀毒" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"> <RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"> <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_scanner_malware" /> <ImageView
android:id="@+id/ivKV_scaning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/act_scanning_03" />
</RelativeLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/tvKV_scaning"
android:text="扫描过程"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <!--自定义进度条图片(3种类型)-->
<ProgressBar
android:id="@+id/pbKV_bar"
android:progressDrawable="@drawable/progress_bg"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout> <!--ScrollView只有一个直接子节点-->
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/ll_add_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"> </LinearLayout>
</ScrollView>
</LinearLayout>

(2)自定义样式的进度条

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--进度条为0,使用的图片-->
<item android:id="@android:id/background" android:drawable="@drawable/security_progress_bg"/>
<!--进度条为0-100%之间,使用的图片-->
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/security_progress"/>
<!--进度条为100%时,使用的图片-->
<item android:id="@android:id/progress" android:drawable="@drawable/security_progress"/>
</layer-list>

3.java后台

package com.example.administrator.test62360safeguard;

import android.annotation.SuppressLint;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView; import com.example.administrator.test62360safeguard.Utils.MD5Util;
import com.example.administrator.test62360safeguard.engine.VirusDao; import java.util.ArrayList;
import java.util.List;
import java.util.Random; public class KillVirusActivity extends AppCompatActivity {
ImageView ivKV_scaning;
TextView tvKV_scaning;
ProgressBar pbKV_bar;
LinearLayout ll_add_textview;
protected static final int SCANING = 100;
protected static final int SCAN_FINISH = 101;
private List<ScanResultInfoBean> virusScanInfoList;
private int index = 0; @SuppressLint("HandlerLeak")
private Handler handler = new Handler(){
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case SCANING:
//1,显示正在扫描应用的名称
ScanResultInfoBean info = (ScanResultInfoBean)msg.obj;
tvKV_scaning.setText(info.name);
//2,在线性布局中添加一个正在扫描应用的TextView
TextView textView = new TextView(getApplicationContext());
if(info.isVirus){
//是病毒
textView.setTextColor(Color.RED);
textView.setText("发现病毒:"+info.name);
}else{
//不是病毒
textView.setTextColor(Color.BLACK);
textView.setText("扫描安全:"+info.name);
}
ll_add_textview.addView(textView, 0); //参数2:设置为0,使得控件放在LinearLayout的顶部
break;
case SCAN_FINISH:
tvKV_scaning.setText("扫描完成");
//停止真正执行的旋转动画
ivKV_scaning.clearAnimation();
break;
}
}
}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_kill_virus); initUI();
initAnimation();
checkVirus();
} /**
* 病毒扫描过程
*/
private void checkVirus() {
//耗时操作,开启一个线程
new Thread(){
public void run() {
//1.获取数据库中所有的病毒的md5码
List<String> virusList = VirusDao.getVirusList();
//获取手机上面的所有应用程序签名文件的md5码
//2.1获取包管理者对象
PackageManager pm = getPackageManager();
//2.2获取所有应用程序签名文件(PackageManager.GET_SIGNATURES 已安装应用的签名文件+)
//PackageManager.GET_UNINSTALLED_PACKAGES 卸载完了的应用,残余的文件
List<PackageInfo> packageInfoList = pm.getInstalledPackages(
PackageManager.GET_SIGNATURES + PackageManager.GET_UNINSTALLED_PACKAGES); //2.3创建记录病毒的集合
virusScanInfoList = new ArrayList<>(); //设置进度条的最大值
pbKV_bar.setMax(packageInfoList.size()); //3.遍历应用集合
for (PackageInfo packageInfo : packageInfoList) {
//获取签名文件的数组
Signature[] signatures = packageInfo.signatures;
//获取签名文件数组的第一位,然后进行md5,将此md5和数据库中的md5比对
Signature signature = signatures[0];
String string = signature.toCharsString();
//32位字符串,16进制字符(0-f)
String encoder = MD5Util.encoder(string);
//创建内部类ScanResultInfoBean的javabean用来存储一个应用经过扫描后的某些属性
ScanResultInfoBean scanResultInfoBean = new ScanResultInfoBean(); //4,比对应用是否为病毒
if(virusList.contains(encoder)){
//5.记录病毒
scanResultInfoBean.isVirus = true;
virusScanInfoList.add(scanResultInfoBean);
}else{
scanResultInfoBean.isVirus = false;
}
//6,维护对象的包名,以及应用名称
scanResultInfoBean.packageName = packageInfo.packageName;
scanResultInfoBean.name = packageInfo.applicationInfo.loadLabel(pm).toString(); //7.在扫描的过程中,需要更新进度条
index++;
pbKV_bar.setProgress(index); //给当前的子线程设置一段睡眠时间,模拟病毒扫描过程(即让扫描过程不要太快,达到肉眼可见的效果)
try {
Thread.sleep(50+new Random().nextInt(100));
} catch (InterruptedException e) {
e.printStackTrace();
} //8.在子线程中发送消息,告知主线程更新UI(1:顶部扫描应用的名称2:扫描过程中往线性布局中添加view)
Message msg = Message.obtain();
msg.what = SCANING;
msg.obj = scanResultInfoBean;
handler.sendMessage(msg);
}
Message msg = Message.obtain();
msg.what = SCAN_FINISH;
handler.sendMessage(msg);
}
}.start();
} /**
* 此javabean用来记录扫描结果中需要存储的应用相关信息
* isVirus 应用是否为病毒
* packageName 包名
* name 应用名称
*/
class ScanResultInfoBean{
public boolean isVirus;
public String packageName;
public String name;
} private void initAnimation() {
//参数1,2设置旋转的角度
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(1000);
//设置动画一直旋转
rotateAnimation.setRepeatMode(Animation.INFINITE);
//保存动画执行结束后的状态
rotateAnimation.setFillAfter(true);
//开始执行动画
ivKV_scaning.startAnimation(rotateAnimation);
} private void initUI() {
ivKV_scaning=findViewById(R.id.ivKV_scaning);
tvKV_scaning=findViewById(R.id.tvKV_scaning);
pbKV_bar=findViewById(R.id.pbKV_bar);
ll_add_textview=findViewById(R.id.ll_add_textview);
}
}

4.效果图

028 Android 旋转动画+病毒查杀效果+自定义样式的ProgressBar的更多相关文章

  1. android146 360 病毒查杀

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  2. Android旋转动画

    Android旋转动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...

  3. Linux服务器感染kerberods病毒 | 挖矿病毒查杀及分析 | (curl -fsSL lsd.systemten.org||wget -q -O- lsd.systemten.org)|sh)

    概要: 一.症状及表现 二.查杀方法 三.病毒分析 四.安全防护 五.参考文章 一.症状及表现 1.CPU使用率异常,top命令显示CPU统计数数据均为0,利用busybox 查看CPU占用率之后,发 ...

  4. 浅谈Android手机木马手工查杀

    这篇文章主要是浅谈,所以会从简单方面开始讲起. 关于手机木马查杀,有些人会说安装手机杀毒软件不就解决了吗? 其实不然.因为手机和PC不一样,手机反木马技术没有PC端那么强. 就算你把目前市面上的所有手 ...

  5. Linux十字病毒查杀处理

    之前处理过一次十字病毒,但未好好整理处理过程,现在转载一篇来自51cto的文章. 转自:http://blog.51cto.com/ixdba/2163018 十字符病毒,杀不死的小强,一次云服务器沦 ...

  6. android旋转动画的两种实现方式

    在android开发,我们会常常使用到旋转动画,普通情况下旋转动画有两种实现方式,一种是直接通过java代码去实现,第二种是通过配置文件实现动画.以下是两种动画的基本是用法: 纯Java代码实现: / ...

  7. android旋转动画和平移动画具体解释,补充说一下假设制作gif动画放到csdn博客上

    先上效果图: 我这里用的是GifCam来制作的gif动画,能够在http://download.csdn.net/detail/baidu_nod/7628461下载, 制作过程是先起一个模拟器,然后 ...

  8. 【转】Android 旋转动画,停止和持续旋转

    旋转180度后停止 RotateAnimation rotate; rotate =new RotateAnimation(0f,180f,Animation.RELATIVE_TO_SELF, 0. ...

  9. Virus:病毒查杀

    简介 小伙伴们,大家好,今天分享一次Linux系统杀毒的经历,还有个人的一些总结,希望对大家有用. 这次遇到的是一个挖矿的病毒,在挖一种叫门罗币(XMR)的数字货币,行情走势请看 https://ww ...

随机推荐

  1. 批量转换word为pdf

    自己写的一个小工具,用于批量转换word为pdf,使用方式: 将完整代码拷贝到文档中,并修改名称为words2pdfs.py将该文件拷贝到需要转换的文档目录下在终端中输入python words2pd ...

  2. 实验五 遇到的问题:openssl: error while loading shared libraries: libssl.so.1.1

    遇到的问题 命令行:linux@ubuntu64-vm:~/exp/exp5$ openssl enc -aes-128-cbc -in test_aes.txt -out out.txt -pass ...

  3. * resolve_conffiles: Existing conffile /etc/config/dhcp is different from the conffile in the new package. The new conffile will be placed at /etc/config/dhcp-opkg.

    * resolve_conffiles: Existing conffile /etc/config/dhcp is different from the conffile in the new pa ...

  4. Postman使用方法示例

  5. Microservices in action: java(spring) and .net

    Manning | Homehttps://www.manning.com/ What is a Microservice? | Manninghttps://freecontent.manning. ...

  6. c++ 标准 字符串转换为时间 时间大小比较 判断有效期 简洁办法

    c# php delphi java 等各种语言 对字符串转换为日期 然后与当前日期进行比较 是非常容易的 因为有现成的函数可用 标准 c++ 硬是找不到 合适的代码可用 于是 百度了很多 没百出个结 ...

  7. 文章后面的QA或FAQ

    QA:question&answer FAQ: Frequently Asked Questions的缩写,中文意思就是“经常问到的问题”

  8. nginx: [warn] conflicting server name "aaa.bbbb.com" on 0.0.0.0:80, ignored

    date: 2019-08-12  16:52:44 author: headsen chen notice :个人原创 故障现象: openresty -t nginx: [warn] confli ...

  9. Flutter Container容器组件、Text文本组件详解

    import 'package:flutter/material.dart'; void main(){ runApp(MyApp()); } class MyApp extends Stateles ...

  10. openresty开发系列25--openresty中使用json模块

    openresty开发系列25--openresty中使用json模块 web开发过程中,经常用的数据结构为json,openresty中封装了json模块,我们看如何使用 一)如何引入cjson模块 ...