[安卓]手机管家(二十一)杀毒UI及SlidingDrawer(抽屉效果)
2015-06-28 08:51
387 查看
关于布局
扫描的圈圈是两张图叠加在一块的,需要帧布局
进度条的属性 用到style
注意,随着扫描的越来越多,listview应该在scroll里面,否则屏幕满了动不了
图标要转起来,这里要用到动画
接下来来扫描程序
走起,挂了,因为在子线程刷了UI (addView)
则handler是必须的,addview应该在handler里
跟新进度条,在扫描前加一个最大值
扫描的同时更新
至于怎么杀毒,在获取applicationInfo时,通过某些算法来实现,比如查看签名什么的
另外关于流量统计:
用到UID,以及trafficStats类
在布局上,有一种类似于抽屉的框架 SlidingDrawer
关键是必须有子控件 ID上要注意
扫描的圈圈是两张图叠加在一块的,需要帧布局
进度条的属性 用到style
注意,随着扫描的越来越多,listview应该在scroll里面,否则屏幕满了动不了
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="fill_parent" android:layout_height="60dp" android:text="手机杀毒" android:background="#00FF00" android:gravity="center" android:textSize="25sp"/> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/iv_antivirus_rador"> <ImageView android:layout_margin="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_scanner_malware"/> <ImageView android:id="@+id/iv_antivirus_scan" android:layout_margin="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/act_scanning_03"/> </FrameLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="70dp" android:layout_toRightOf="@id/iv_antivirus_rador" android:orientation="vertical" android:gravity="center_vertical"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/tv_antivirus_scan" android:text="正在扫描.." android:layout_gravity="center"/> <ProgressBar android:id="@+id/pb_antivirus_progress" android:progressDrawable="@drawable/progress_horizontal" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </LinearLayout> </RelativeLayout> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/ll_antivirus_packagename" android:orientation="vertical"> </LinearLayout> </ScrollView> </LinearLayout>
图标要转起来,这里要用到动画
public class AntiVirusActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_antivirus); //圆圈转动 ImageView iv_antivirus_scan = (ImageView) findViewById(R.id.iv_antivirus_scan); RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(10000); rotateAnimation.setRepeatCount(100); iv_antivirus_scan.setAnimation(rotateAnimation); rotateAnimation.start(); }
接下来来扫描程序
public class AntiVirusActivity extends Activity { private LinearLayout ll; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_antivirus); //3.1 返回的app的list显示出来,在这个list里 ll = (LinearLayout) findViewById(R.id.ll_antivirus_packagename); //1.圆圈转动 ImageView iv_antivirus_scan = (ImageView) findViewById(R.id.iv_antivirus_scan); RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(10000); rotateAnimation.setRepeatCount(100); iv_antivirus_scan.setAnimation(rotateAnimation); rotateAnimation.start(); //不能放在主线程,否则进去的时候会有个黑屏,主线程被阻塞 new Thread(){ public void run() { scanapps(); }; }.start(); } //2.扫描并显示 private void scanapps() { PackageManager pm = getPackageManager(); //3.2 获得所有安装的程序,并且返回一个list List<ApplicationInfo> ia = pm.getInstalledApplications(0); for(ApplicationInfo applicationInfo : ia){ //3.3 需要通过textview来将包名加进list TextView tv = new TextView(this); tv.setText(applicationInfo.packageName); ll.addView(tv); //4 睡一会,否则速度太快,用户看不到查杀过程 try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
走起,挂了,因为在子线程刷了UI (addView)
则handler是必须的,addview应该在handler里
public class AntiVirusActivity extends Activity { private LinearLayout ll; private RotateAnimation rotateAnimation; private TextView tv_antivirus_scan; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_antivirus); //3.1 返回的app的list显示出来,在这个list里 ll = (LinearLayout) findViewById(R.id.ll_antivirus_packagename); //1.圆圈转动 ImageView iv_antivirus_scan = (ImageView) findViewById(R.id.iv_antivirus_scan); rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(10000); rotateAnimation.setRepeatCount(100); iv_antivirus_scan.setAnimation(rotateAnimation); rotateAnimation.start(); //不能放在主线程,否则进去的时候会有个黑屏,主线程被阻塞 new Thread(){ public void run() { scanapps(); }; }.start(); } //2.扫描并显示 private void scanapps() { PackageManager pm = getPackageManager(); //3.2 获得所有安装的程序,并且返回一个list List<ApplicationInfo> ia = pm.getInstalledApplications(0); for(ApplicationInfo applicationInfo : ia){ //获得包名 String packagename = applicationInfo.packageName; //发消息 Message msg = myHandler.obtainMessage(); msg.obj = packagename; msg.what = 0; myHandler.sendMessage(msg); //4 睡一会,否则速度太快,用户看不到查杀过程 try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //扫完发的消息,无需带数据,通知即可 Message msg = myHandler.obtainMessage(); msg.what=1; myHandler.sendMessage(msg); } Handler myHandler = new Handler(){ public void handleMessage(android.os.Message msg) { if (msg.what==0) { String packagename = (String) msg.obj; //3.3 需要通过textview来将包名加进list TextView tv = new TextView(AntiVirusActivity.this); tv.setText(packagename); //将新的显示放在第一位 ll.addView(tv,0); } else if (msg.what ==1) { rotateAnimation.cancel(); tv_antivirus_scan.setText("扫描完成"); } }; }; }
跟新进度条,在扫描前加一个最大值
//5.1 找到进度条 pb = (ProgressBar) findViewById(R.id.pb_antivirus_progress);
//3.2 获得所有安装的程序,并且返回一个list List<ApplicationInfo> ia = pm.getInstalledApplications(0); //5.2 进度条的最大值 pb.setMax(ia.size());
扫描的同时更新
//3.3 需要通过textview来将包名加进list TextView tv = new TextView(AntiVirusActivity.this); tv.setText(packagename); //将新的显示放在第一位 ll.addView(tv,0); //5.3 进度条更新 pb.setProgress(count++);
至于怎么杀毒,在获取applicationInfo时,通过某些算法来实现,比如查看签名什么的
另外关于流量统计:
用到UID,以及trafficStats类
在布局上,有一种类似于抽屉的框架 SlidingDrawer
关键是必须有子控件 ID上要注意
<TextView android:layout_width="fill_parent" android:layout_height="60dp" android:text="流量统计" android:background="#00FF00" android:gravity="center" android:textSize="25sp"/> <SlidingDrawer android:layout_width="fill_parent" android:layout_height="fill_parent" android:handle="@+id/drawerhalder" android:content="@+id/drawercontent" android:orientation="horizontal"> <ImageView android:id="@id/drawerhalder" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/img3" /> <LinearLayout android:id="@id/drawercontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#00FF00"> </LinearLayout> </SlidingDrawer>
相关文章推荐
- UIAlertView自动弹框创建步骤
- UI控件设置圆角
- UITextView弹簧效果属性
- 创建UIImageView方式的区别
- [iOS8][Segue转场]转场返回无法绑定的解决办法
- 【Leetcode】Combination Sum III #216
- Google interview question: quickSort-like questions
- Google interview question: mergeSort-like questions
- Arduino MPU6050学习资料总结
- 探究requestDisallowInterceptTouchEvent失效的原因
- iOS开发——CoreBluetooth蓝牙开发(三)
- c#中使用easyUI的DataGrid组件
- 重装操作系统后,要重新配置Android开发环境。配置成功后,添加原本项目时却出现了错误! Android requires compiler compliance level 5.0 or 6.0.
- 3. 导入新的一个android项目报错,详情见下面: Android requires compiler compliance level 5.0 or 6.0. Found'1.4' instea
- 使用NGUI的UIListener 和UIEvent Trigger 中的 OnDouble-Click 出现问题
- UIViewAlertForUnsatisfiableConstraints to catch this in the debugger
- [leetcode] 95.Unique Binary Search Trees II
- 2299 Poj Ultra-QuickSort(归并排序求逆序数)
- STL 笔记(三) 容器适配器 stack、queue、priority_queue
- STL 笔记(一) 顺序容器 vector、list、deque常用函数