【0069】【项目实战】-【手机安全卫士】-【9】软件管理

1.软件管理的功能

2. 布局及跳转及存储空间信息获取

【源码布局】

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6     <TextView 
 7         style="@style/TitleStyle"
 8         android:text="软件管理"/>
 9     <RelativeLayout 
10         android:padding="5dp"
11         android:layout_width="match_parent"
12         android:layout_height="wrap_content">
13         <TextView
14             android:id="@+id/tv_memory"
15             android:text="磁盘可用"
16             android:layout_width="wrap_content"
17             android:layout_height="wrap_content"/>
18         <TextView
19             android:text="sd卡可用"
20             android:layout_alignParentRight="true"
21             android:id="@+id/tv_sd_memory"
22             android:layout_width="wrap_content"
23             android:layout_height="wrap_content"/>
24     </RelativeLayout>
25     <FrameLayout 
26         android:layout_width="match_parent"
27         android:layout_height="wrap_content">
28         <ListView 
29             android:id="@+id/lv_app_list"
30             android:layout_width="match_parent"
31             android:layout_height="wrap_content">
32         </ListView>
33         <TextView 
34             android:background="#ccc"
35             android:id="@+id/tv_des"
36             android:textColor="#000"
37             android:textSize="18sp"
38             android:layout_width="match_parent"
39             android:layout_height="wrap_content"/>
40     </FrameLayout>
41     
42 </LinearLayout>

 

3. 获取应用的信息

【源码javabean】

 1 package com.itheima.mobilesafe74.db.domain;
 2 
 3 import android.graphics.drawable.Drawable;
 4 
 5 public class AppInfo {
 6 //    名称,包名,图标,(内存,sd卡),(系统,用户)
 7     public String name;
 8     public String packageName;
 9     public Drawable icon;
10     public boolean isSdCard;
11     public boolean isSystem;
12     
13     public String getName() {
14         return name;
15     }
16     public void setName(String name) {
17         this.name = name;
18     }
19     public String getPackageName() {
20         return packageName;
21     }
22     public void setPackageName(String packageName) {
23         this.packageName = packageName;
24     }
25     public Drawable getIcon() {
26         return icon;
27     }
28     public void setIcon(Drawable icon) {
29         this.icon = icon;
30     }
31     public boolean isSdCard() {
32         return isSdCard;
33     }
34     public void setSdCard(boolean isSdCard) {
35         this.isSdCard = isSdCard;
36     }
37     public boolean isSystem() {
38         return isSystem;
39     }
40     public void setSystem(boolean isSystem) {
41         this.isSystem = isSystem;
42     }
43 }

 

4. 断点调试方法

5. 应用列表展示

【信息设置的框架】

【布局】单个条目的布局

【单个条目的布局源码】

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5     <ImageView
 6         android:id="@+id/iv_icon"
 7         android:background="@drawable/ic_launcher"
 8         android:layout_width="45dp"
 9         android:layout_height="45dp"/>
10     <TextView
11         android:id="@+id/tv_name"
12         android:text="应用名称"
13         android:textSize="18sp"
14         android:layout_toRightOf="@id/iv_icon"
15         android:layout_width="wrap_content"
16         android:layout_height="wrap_content"/>
17     <TextView
18         android:id="@+id/tv_path"
19         android:textSize="18sp"
20         android:text="应用安装路径"
21         android:layout_toRightOf="@id/iv_icon"
22         android:layout_below="@id/tv_name"
23         android:layout_width="wrap_content"
24         android:layout_height="wrap_content"/>
25 </RelativeLayout>

 

【效果】出现的图片过大

【修正】

 

6.用户应用显示在顶部,系统应用显示在底部

 

 

 

7.listview多种条目类型展示

【获取的个数多加两个】

【获取的类型增加一种】本身源码默认的是1,现在需要增加1;

【3】按照索引值指定当前索引值指向的条目类型;

 

【新建灰色条目的布局文件】

【效果】用户应用和系统应用分类显示

 【Bug】出现了崩溃:在程序向下拉的时候出现了崩溃;

【效果】

8. 常驻悬浮窗的使用

【说明】即使条目在滚动,但是文件的说明框仍然不变,在悬浮着显示;

 

【源码修改】

【效果如下】

【实际的效果】

 

【滚动监听】【原理】根据不同的应用数目和系统应用的数目,来判断改变悬浮TextView的文字显示;

9. 悬浮框的弹出

9.1 popupwidow使用demo

【挂载根布局】

【源码】

【效果】

【popupWindow的回退】

【说明】如果弹出的窗体具有背景,则按下物理按键是可以进行回退消失的;

              如果弹出的窗体没有背景,则按下物理按键是可以不能回退消失的;

 

【无背景的效果】如果弹出的窗体没有背景,则按下物理按键是可以不能回退消失的;

 

 

【源码】

 1 package com.example.popupwindow;
 2 
 3 import android.os.Bundle;
 4 import android.provider.ContactsContract.CommonDataKinds.Relation;
 5 import android.app.Activity;
 6 import android.graphics.Color;
 7 import android.graphics.drawable.ColorDrawable;
 8 import android.view.Gravity;
 9 import android.view.Menu;
10 import android.view.View;
11 import android.view.View.OnClickListener;
12 import android.widget.Button;
13 import android.widget.PopupWindow;
14 import android.widget.RelativeLayout;
15 import android.widget.TextView;
16 
17 public class MainActivity extends Activity {
18 
19     private RelativeLayout rl_root;
20 
21     @Override
22     protected void onCreate(Bundle savedInstanceState) {
23         super.onCreate(savedInstanceState);
24         setContentView(R.layout.activity_main);
25         
26         Button bt_click = (Button) findViewById(R.id.bt_click);
27         rl_root = (RelativeLayout) findViewById(R.id.rl_root);
28         
29         bt_click.setOnClickListener(new OnClickListener() {
30             @Override
31             public void onClick(View v) {
32                 showPopupWindow();
33             }
34         });
35     }
36 
37     protected void showPopupWindow() {
38         //1,窗体上展示的内容
39         TextView textView = new TextView(this);
40         textView.setText("我是大魔包");
41         textView.setTextColor(Color.RED);
42         //2,挂载在popupWindow上
43         PopupWindow popupWindow = new PopupWindow(textView, 100, 100, true);
44         //3,指定popupWindow的背景(设置上背景,点击回退按钮才会有响应)
45         popupWindow.setBackgroundDrawable(new ColorDrawable(Color.GREEN));
46         //4,指定popupWindow所在位置(挂载在那个控件上,在父控件上的位置,)
47         popupWindow.showAtLocation(rl_root, Gravity.CENTER, 100, 100);
48     }
49 }

9.2 popupWindow在项目中的应用

 

【弹窗的布局源码】

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="wrap_content"
 4     android:layout_height="wrap_content"
 5     android:background="@drawable/local_popup_bg"
 6     android:orientation="horizontal" >
 7     <TextView 
 8         android:text="卸载"
 9         android:id="@+id/tv_uninstall"
10         android:drawableTop="@drawable/img1"
11         android:layout_width="wrap_content"
12         android:layout_height="wrap_content"/>
13     <TextView 
14         android:text="启动"
15         android:id="@+id/tv_start"
16         android:drawableTop="@drawable/img2"
17         android:layout_width="wrap_content"
18         android:layout_height="wrap_content"/>
19     <TextView 
20         android:text="分享"
21         android:id="@+id/tv_share"
22         android:drawableTop="@drawable/img3"
23         android:layout_width="wrap_content"
24         android:layout_height="wrap_content"/>
25 
26 </LinearLayout>

【监听的添加】

【源码】

【运行效果】在单击每个条目的时候会弹出popupWindow,点击文字listView的时候没有反应;

 

9.3 卸载&开启应用&分析功能实现

【卸载功能】系统应用无法卸载

【卸载的开启过程】

【开启应用的功能】

【分享】通过短信分享:实际的分享到第三方的平台;在智慧北京项目中讲解;

【增加窗体消失的逻辑】

【测试效果】

 

 

 【增加细节问题】在卸载应用之后需要在软件管理的界面将该应用的条目删除,需要更新条目的信息;

但是,再次进入的时候已经不存在了;

【修改】

【效果】卸载完成之后条目消失;更新了数据list信息;

 

 

posted @ 2018-02-07 13:26  OzTaking  阅读(391)  评论(0)    收藏  举报