我们有4个手机防盗的界面,第一个是显示功能,第二个是输入自己的手机号码,这个手机号码可以用来判断是否被换卡,当换卡的时候我们可以报警等,第三个界面是输入用户设置的安全号码,这个号码可以用于当手机丢失的时候软件后台检测手机号码并且检测号码里面的内容,进行操作。
第一个设置界面:
简单的布局,显示有什么功能即可。布局代码如下:
<?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"
android:background="@drawable/bigwhite_4">
<TextView
android:background="#FFFF00"
style="@style/text_title"
android:gravity="center_horizontal"
android:text="1.欢迎使用设置向导"
/>
<ImageView
style="@style/divide_style"
/>
<TextView
style="@style/text_content_style"
android:text="您的手机卫士具有以下功能:"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
style="@style/start_style"
/>
<TextView
android:layout_marginTop="1dp"
style="@style/text_content_style"
android:text="SIM卡变更报警"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
style="@style/start_style"
/>
<TextView
android:layout_marginTop="1dp"
style="@style/text_content_style"
android:text="手机定位追踪"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
style="@style/start_style"
/>
<TextView
android:layout_marginTop="1dp"
style="@style/text_content_style"
android:text="手机数据远程销毁"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
style="@style/start_style"
/>
<TextView
android:layout_marginTop="1dp"
style="@style/text_content_style"
android:text="手机远程锁屏"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
>
<ImageView
android:layout_marginTop="1dp"
style="@style/statu_on_style"
/>
<ImageView
style="@style/statu_off_style"
/>
<ImageView
style="@style/statu_off_style"
/>
<ImageView
style="@style/statu_off_style"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
>
<Button
style="@style/button_next_style"
android:layout_marginTop="250dp"
/>
</LinearLayout>
</LinearLayout>
在这里学到最多的就是封装样式,将我们需要的进行样式的封装,可以提高代码的复用性。在这里,无论是分割线的样式封装还是星星图标的样式封装,都给了封装便于使用。
对应的Activity,同样是一个继承Activity的界面,然后在主清单进行注册,然后再设置加载界面。
剩下的几个设置界面就不多说,现在我们主要来看看界面的按钮我们必须增加点击事件,当每一个下一步的时候,我们就要进行我们数据的存储,首先我们先看第二个布局文件中有自己的手机号码,在这个点击下一步的时候,我们可以将手机卡的序列号取出,并进行保存在SharedPerferences中。
思路如下:
1、得到一个手机管理器,通过上下文获取
TelephoneManger tm=(TelephoneManger )getSystemService(TELEPHONY_SERVICE);
得到一个sim序列号
String Sim=tm.getSimSerialNumber();
//使用SharedPerferences进行存储在本地文件夹
Editor editor=sp.edit();
editor.putString(“simSerialNumber”, simSerialNumber);
editor.commit();
总体代码如下:
package developer.yupeibiao.mobilesafe.ui;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Toast;
import developer.yupeibiao.mobilesafe.R;
public class SetGuide2Activity extends Activity {
//得到手机管理者
private TelephonyManager tm;
private SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setguide2);
//得到sharedprefrene
sp=getSharedPreferences("config_test", Context.MODE_PRIVATE);
//得到手机服务管理者
tm =(TelephonyManager) getSystemService(TELEPHONY_SERVICE);
}
/**
* 下一步按钮操作
* */
public void next(View view){
//获取手机的SIM卡序列号
String simSerialNumber=tm.getSimSerialNumber();
//进行序列号的保存
Editor editor=sp.edit();
editor.putString("simSerialNumber", simSerialNumber);
editor.commit();
Intent intent=new Intent(this,SetGuide3Activity.class);
startActivity(intent);
finish();
}
/**
* 上一步按钮操作
* */
public void previous(View view){
Intent intent=new Intent(this,SetGuideActivity.class);
startActivity(intent);
finish();
}
}
在第三个获得得到设置的安全号码的时候,我们也同样进行相同的操作保存。
这样,四个界面的设置的保存也就完成了。
接下来是手机防盗相关功能的实现了,下面一个章节会讲解。