您的位置:首页 > 其它

91.手机防盗保护开启关闭

2017-03-22 02:06 141 查看
通过监听防盗保护勾选的状态,分别保存不同的sMpr值,之后根据读取的值来判断是否需要设置相关的参数
布局页面Setup4_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ldw="http://schemas.android.com/apk/res/com.ldw.safe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
style="@style/TitleStyle"
android:text="4.恭喜您设置完成"
/>
<CheckBox
android:id="@+id/cb_protect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="防盗保护没有开启"
/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/presence_invisible"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/presence_invisible"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/presence_invisible"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/presence_online"/>
</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/phone" />

<Button
style="@style/NextStyle"
android:text="设置完成"
/>

<Button
style="@style/PreviousStyle"
/>

</RelativeLayout>

</LinearLayout>

监控放到保护的开启与关闭SettupActivity.java
package com.ldw.safe.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.ldw.safe.R;

/*
* 手机防盗第四个设置向导页面
*/
public class Setup4Activity extends BaseSetupActivity {

private CheckBox cbProtect;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup4);

cbProtect = (CheckBox) findViewById(R.id.cb_protect);

//根据保存的状态保存是否开启
boolean protect = mPref.getBoolean("protect", false);
if(protect){
cbProtect.setText("防盗保护已经开启");
cbProtect.setChecked(true);
}else{
cbProtect.setText("防盗保护没有开启");
cbProtect.setChecked(false);
}

//监听checkBox,并保存checkbox状态
cbProtect.setOnCheckedChangeListener(new OnCheckedChangeListener(){

@Over
4000
ride
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(isChecked){
cbProtect.setText("防盗保护已经开启");
mPref.edit().putBoolean("protect", true).commit();
}else{
cbProtect.setText("防盗保护没有开启");
mPref.edit().putBoolean("protect", false).commit();
}

}

});
}

//显示上一页,这个需要子类去实现,跳转的页面不是固定的
public void showPrevious(){
//页面跳转
startActivity(new Intent(Setup4Activity.this, Setup3Activity.class));
//销毁当前页面
finish();
//两个界面的切换动画
overridePendingTransition(R.anim.tran_previous_in, R.anim.tran_previous_out);//进入动画和推出动画
}

//显示下一页,这个需要子类去实现,跳转的页面不是固定的
public void showNext(){
//页面跳转
startActivity(new Intent(Setup4Activity.this, LostAndFind.class));
//销毁当前页面
finish();
//更新mPref表示已经展示过设置向导,下次进来不展示更新向导
mPref.edit().putBoolean("configed", true).commit();
//两个界面的切换动画
overridePendingTransition(R.anim.tran_in, R.anim.tran_out);//进入动画和推出动画
}

}
同时在初始化进入的页面,根据防盗功能的开启和关闭初始化安全号码
LostAndFindActivity.java
package com.ldw.safe.Activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ldw.safe.R;

/*
* 手机防盗页面
*/
public class LostAndFind extends Activity {

private SharedPreferences mPref;
private TextView tvSafePhone;
private ImageView ivProtect;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//判断是否是第一次登陆,第一次登陆会进入设置向导
mPref = getSharedPreferences("config", MODE_PRIVATE);
boolean configed =  mPref.getBoolean("configed", false);
if(configed){
//进入手机放到主页面
setContentView(R.layout.activity_lostfind);
//从mPref中获取到安全号码
tvSafePhone = (TextView) findViewById(R.id.tv_safe_phone);
String phone = mPref.getString("safe_phone", "");
tvSafePhone.setText(phone);

//从mPref中获取是否是开启保护的状态,来选择后面的图片是开启还是关闭
ivProtect = (ImageView) findViewById(R.id.iv_protect);
boolean protect = mPref.getBoolean("protect", false);
if(protect){
ivProtect.setImageResource(R.drawable.lock);
}else{
ivProtect.setImageResource(R.drawable.unlock);
}

}else{
//跳转到设置向导页
startActivity(new Intent(LostAndFind.this, Setup1Activity.class));
finish();
}

}

/*
* 重新进入设置向导
*/
public void reEnter(View v){
startActivity(new Intent(LostAndFind.this, Setup1Activity.class));
finish();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: