Android mobile guard 16-mobile anti-virus, android16 --

Source: Internet
Author: User

Android mobile guard 16-mobile anti-virus, android16 --

1. Specify that the animation is always rotated.

rotateAnimation.setRepeatCount(RotateAnimation.INFINITE);

Android: repeatCount repeated times. The default value is 0. It must be an int value. The value-1 indicates that the repeatCount is not stopped.

 

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, displays the name of the application being scanned 17 ScanInfo info = (ScanInfo) msg. obj; 18 TV _name.setText (info. name); 19 // 2, add a TextView 20 TextView textView = new TextView (getApplicationContext (); 21 if (info. isVirus) {22 // is the textView of virus 23. setTextColor (Color. RED); 24 textView. setText ("detected virus:" + info. name); 25} else {26 // not a virus 27 textView. setTextColor (Color. BLACK); 28 textView. setText ("Scan security:" + info. name); 29} 30 ll_add_text.addView (textView, 0); 31 break; 32 case SCAN_FINISH: 33 TV _name.setText ("Scan completed "); 34 // stop the actually executed rotation animation 35 iv_scanning.clearAnimation (); 36 // notify the user to uninstall the application containing the virus 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 // source code 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 // obtain the md5 code 70 List of all viruses in the database <String> virusList = VirusDao. getVirusList (); 71 // obtain the md5 code of all application signature files on the mobile phone 72 // 1. get PackageManager object 73 PackageManager pm = getPackageManager (); 74 // 2. obtain all application signature files (PackageManager. GET_SIGNATURES: Signature file of the installed application +) 75 // PackageManager. GET_UNINSTALLED_PACKAGES: the application that has been uninstalled. The residual file 76 List <PackageInfo> packageInfoList = pm. getInstalledPackages (77 PackageManager. GET_SIGNATURES + PackageManager. GET_UNINSTALLED_PACKAGES); 78 // create a collection of record viruses 79 80 mVirusScanInfoList = new ArrayList <ScanInfo> (); 81 82 // record the collection of all applications 83 List <ScanInfo> scanInfoList = new ArrayList <ScanInfo> (); 84 85 // set the maximum value of the progress bar 86 pb_bar.setMax (packageInfoList. size (); 87 88 // 3. traverse the application set 89 for (PackageInfo packageInfo: packageInfoList) {90 ScanInfo scanInfo = new ScanInfo (); 91 // obtain the array 92 Signature [] signatures = packageInfo. signatures; 93 // obtain the first digit of the Signature file array, and then perform md5. Compare the md5 value with the md5 value in the database 94 signature = signatures [0]; 95 String string = Signature. toCharsString (); 96 // 32-Bit String, hexadecimal character (0-f) 97 String encoder = Md5Util. encoder (string); 98 // 4, check whether the application is virus 99 if (virusList. contains (encoder) {100 // 5. record the virus 101 scanInfo. isVirus = true; 102 mVirusScanInfoList. add (scanInfo); 103} else {104 scanInfo. isVirus = false; 105} 106/6, maintenance object package name, and application name 107 scanInfo. packageName = packageInfo. packageName; 108 scanInfo. name = packageInfo. applicationInfo. loadLabel (pm ). toString (); 109 scanInfoList. add (scanInfo); 110 // 7. during the scanning process, you must update the progress bar 111 index ++; 112 pb_bar.setProgress (index); 113 114 115 try {Thread. sleep (50 + new Random (). nextInt (100); 116} catch (InterruptedException e) {117 e. printStackTrace (); 118} 119 120 // 8. send a Message to the main thread to update the UI (1: name of the top scan application 2: add view to the linear layout during the scan) 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 // specify that the animation is always rotated 146 // rotateAnimation. setRepeatMode (RotateAnimation. INFINITE); 147 rotateAnimation. setRepeatCount (RotateAnimation. INFINITE); 148 // keep the animation in the 149 rotateAnimation state after it is executed. setFillAfter (true); 150 // always execute animation 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 maid = (LinearLayout) findViewById (R. id. ll_add_text); 159} 160}
AnitVirusActivity

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.