系统的功能模块大致分为两部分,分别是主界面和设置界面。而主界面又分为i选择模式和勾选应用两部分,设置界面又可细分为防火墙开关,日志开关,保存规则,退出,帮助和更多六部分。
运行环境要求:
- 操作系统: Android手机基于Linux操作系统
- 支持环境: Android2.3以上版本
- 开发环境: Eclipse3.5 ADT0.95
1.编写布局文件
(1)首先编写主界面文件main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android: layout_width="fill_parent" android: layout_height="fill_parent"
xmlns:android=“http://schemas.android.com/apk/res/android”
android:orientation="vertical" android:duplicateParentState="false">
<View android:layout_width="fill_width" android:layout_height="1sp"
android:background="#FFFFFFFF" />
<LinearLayout android:layout_width="fill_parent" android: layout_height="wrap_content" android: padding="8sp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/label_mode"
android:text="Mode:" android:textSize="20sp" android:clickable="true"></TextView>
</LinearLayout>
<View android:layout_width="fill_parent" android:layout_height="1sp" android:background="#FFFFFFFF"> />
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="3sp">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/img_wifi"
android:src="@drawable/eth_wifi" android:clickable="false"
android:layout_alignParentLeft="true" android:paddingLeft="3sp"
android:paddingRight="10sp"></ImageView>
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/img_3g"
android:src="@drawable/eth_g" android:clickable="false"
android:layout_toRightOf="@id/img_wifi"></ImageView>
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/img_download"
android:src="@drawable/download" android:clickable="false"
android:layout_alignParentRight="true" android:paddingLeft="22sp"></ImageView>
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/img_upload" android:layout_toLeftOf="@id/img_download"
android:src="@drawable/upload" android:clickable="false"></ImageView>
</RelativeLayout>
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listview"></ListView>
</LinearLayout>
上述代码将整个主界面划分为了如下两个部分。
- 上部分:显示模式和网络类型,其中模式分为黑名单模式和白名单模式两种。
- 下部分:列表显示某种模式下的所有网络服务,并且在每种服务前面显示一个复选框按钮,通过按钮可以设置某种服务启用还是禁用。
下部分的列表功能是通过文件listitem.xml实现的,具体代码如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/itemcheck_wifi" android:layout_alignParentLeft="true"></CheckBox>
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/itemcheck_3g" android:layout_toRightOf="@id/itemcheck_wifi"></CheckBox>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/app_text" android:layout_toRightOf="@id/itemcheck_3g" android:text="uid:packages"
android:layout_centerVertical="true" android:paddingRight="80sp"></TextView>
<TextView android:layout_height="wrap_content" android:id="@+id/download" android: layout_width="wrap_content"
android: layout_alignParentRight="true" android: layout_centerVertical="true" android: paddingLeft="15sp"></TextView>
<TextView android: layout_height="wrap_content" android:id="@+id/upload" android:layout_width="wrap_content"
android: layout_toLeftOf="@id/download" android:layout_centerVertical="true"></TextView>
</RelativeLayout>
(2)编写帮助界面布局文件help_dialog.xml
<?xml version="1.0" encoding="utf-8" ?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ScrollView ximns: android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_height="fill_parent" android:layout_width="fill_parent"
android:text="@string/help_dialog_text" android:padding="6dip" />
</ScrollView>
</FrameLayout>
界面部分已经完成,下一篇博客将为大家奉上主程序文件。
未完待续。。。。。。。。