編輯:關於android開發
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 M Launcher3主流程源碼淺析 背景 關於Launcher是啥的問題我想這裡就沒必要再強調了。由於一些原因迫使最近開始需要研究一下Launcher3
手把手帶你畫一個漂亮蜂窩view Android自定義view 這個效果做起來好像沒什麼意義,如果不加監聽回調 圖片就能直接替代。寫這篇博客的目的是鍛煉一下思維能力,以更
Android 中間人攻擊 0x00 Android中間人攻擊的思路就是劫持局域網中被攻擊機器和服務器間的對話。被攻擊機器和服務器表面上工作正常,實際上已經被中間人劫