手机卫士07-设置向导
今天,我们要做的就是给我们的手机防盗这个功能添加一个设置向导的功能啦,指导用户进行一些设置,废话不多说,直接上图,看看我们要做的效果

UI不是很好看,各位可以自己修改一下哈
好啦,我们今天主要是把这两个界面写出来,还有把一些逻辑代码写一下
其实这主要就是两个xml文件啦
setup_guide1.xml
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:andro
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:background="@drawable/title_background"
-
android:orientation="vertical" >
-
-
<TextView
-
-
android:text="@string/guide1"/>
-
-
<TextView
-
/>
-
-
<TextView
-
-
android:text="@string/guide1_content"/>
-
-
<TextView
-
-
android:text="@string/guide1_item1"/>
-
-
<TextView
-
-
android:text="@string/guide1_item2"/>
-
-
<TextView
-
-
android:text="@string/guide1_item3"/>
-
-
<TextView
-
-
android:text="@string/guide1_item4"/>
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="wrap_content"
-
android:layout_marginTop="8dip"
-
android:gravity="center_horizontal"
-
android:orientation="horizontal">
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_online"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
</LinearLayout>
-
-
<RelativeLayout
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:gravity="center_horizontal|center_vertical">
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:gravity="center_horizontal|center_vertical">
-
-
<ImageView
-
android:layout_width="150dip"
-
android:layout_height="150dip"
-
android:src="@drawable/widget01"
-
android:contentDescription="@string/hello_world"/>
-
-
</LinearLayout>
-
-
<Button
-
android:
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="@string/next"
-
android:drawableRight="@drawable/next"
-
android:layout_alignParentBottom="true"
-
android:layout_alignParentRight="true"/>
-
-
</RelativeLayout>
-
-
</LinearLayout>
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:andro
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:background="@drawable/title_background"
-
android:orientation="vertical" >
-
-
<TextView
-
-
android:text="@string/guide2"/>
-
-
<TextView
-
/>
-
-
<TextView
-
-
android:text="@string/guide2_content"/>
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="wrap_content"
-
android:orientation="horizontal">
-
-
<Button
-
android:
-
android:layout_width="240dip"
-
android:layout_height="wrap_content"
-
android:layout_marginTop="8dip"
-
android:text="@string/guide2_item1"/>
-
-
<CheckBox
-
android:
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="@string/guide2_item2"/>
-
-
</LinearLayout>
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="wrap_content"
-
android:layout_marginTop="20dip"
-
android:gravity="center_horizontal"
-
android:orientation="horizontal">
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_online"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
</LinearLayout>
-
-
<RelativeLayout
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:gravity="center_horizontal|center_vertical">
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:gravity="center_horizontal|center_vertical">
-
-
<ImageView
-
android:layout_width="150dip"
-
android:layout_height="150dip"
-
android:src="@drawable/guide2"
-
android:contentDescription="@string/hello_world"/>
-
-
</LinearLayout>
-
-
<Button
-
android:
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="@string/perviout"
-
android:drawableRight="@drawable/previous"
-
android:layout_alignParentBottom="true"
-
android:layout_alignParentLeft="true"/>
-
-
<Button
-
android:
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="@string/next"
-
android:drawableRight="@drawable/next"
-
android:layout_alignParentBottom="true"
-
android:layout_alignParentRight="true"/>
-
-
</RelativeLayout>
-
-
</LinearLayout>
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:andro
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:background="@drawable/title_background"
-
android:orientation="vertical" >
-
-
<TextView
-
-
android:text="@string/guide1"/>
-
-
<TextView
-
/>
-
-
<TextView
-
-
android:text="@string/guide1_content"/>
-
-
<TextView
-
-
android:text="@string/guide1_item1"/>
-
-
<TextView
-
-
android:text="@string/guide1_item2"/>
-
-
<TextView
-
-
android:text="@string/guide1_item3"/>
-
-
<TextView
-
-
android:text="@string/guide1_item4"/>
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="wrap_content"
-
android:layout_marginTop="8dip"
-
android:gravity="center_horizontal"
-
android:orientation="horizontal">
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_online"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
</LinearLayout>
-
-
<RelativeLayout
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:gravity="center_horizontal|center_vertical">
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:gravity="center_horizontal|center_vertical">
-
-
<ImageView
-
android:layout_width="150dip"
-
android:layout_height="150dip"
-
android:src="@drawable/widget01"
-
android:contentDescription="@string/hello_world"/>
-
-
</LinearLayout>
-
-
<Button
-
android:
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="@string/next"
-
android:drawableRight="@drawable/next"
-
android:layout_alignParentBottom="true"
-
android:layout_alignParentRight="true"/>
-
-
</RelativeLayout>
-
-
</LinearLayout>
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout xmlns:andro
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:background="@drawable/title_background"
-
android:orientation="vertical" >
-
-
<TextView
-
-
android:text="@string/guide4"/>
-
-
<TextView
-
/>
-
-
<TextView
-
-
android:text="@string/guide4_content"/>
-
-
<CheckBox
-
android:
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:textColor="@android:color/white"
-
android:text="@string/guide4_item1"/>
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="wrap_content"
-
android:layout_marginTop="8dip"
-
android:gravity="center_horizontal"
-
android:orientation="horizontal">
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_invisible"
-
android:contentDescription="@string/hello_world"/>
-
-
<ImageView
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:src="@android:drawable/presence_online"
-
android:contentDescription="@string/hello_world"/>
-
-
</LinearLayout>
-
-
<RelativeLayout
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:gravity="center_horizontal|center_vertical">
-
-
<LinearLayout
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:gravity="center_horizontal|center_vertical">
-
-
<ImageView
-
android:layout_width="150dip"
-
android:layout_height="150dip"
-
android:src="@drawable/guide4"
-
android:contentDescription="@string/hello_world"/>
-
-
</LinearLayout>
-
-
<Button
-
android:
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="@string/perviout"
-
android:drawableRight="@drawable/previous"
-
android:layout_alignParentBottom="true"
-
android:layout_alignParentLeft="true"/>
-
-
<Button
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:text="@string/finish"
-
android:drawableRight="@drawable/next"
-
android:layout_alignParentBottom="true"
-
android:layout_alignParentRight="true"/>
-
-
</RelativeLayout>
-
-
</LinearLayout>
-
package com.xiaobin.security.ui;
-
-
import android.app.Activity;
-
import android.app.Dialog;
-
import android.content.Context;
-
import android.content.Intent;
-
import android.content.SharedPreferences;
-
import android.content.SharedPreferences.Editor;
-
import android.os.Bundle;
-
import android.view.View;
-
import android.view.View.OnClickListener;
-
import android.widget.Button;
-
import android.widget.EditText;
-
import android.widget.Toast;
-
-
import com.xiaobin.security.R;
-
import com.xiaobin.security.utils.MD5Encoder;
-
-
public class LostProtectedActivity extends Activity implements OnClickListener
-
{
-
private SharedPreferences sp;
-
private Dialog dialog;
-
private EditText password;
-
private EditText confirmPassword;
-
-
@Override
-
protected void onCreate(Bundle savedInstanceState)
-
{
-
super.onCreate(savedInstanceState);
-
-
sp = getSharedPreferences("cofig", Context.MODE_PRIVATE);
-
-
if(isSetPassword())
-
{
-
showLoginDialog();
-
}
-
else
-
{
-
showFirstDialog();
-
}
-
}
-
-
private void showLoginDialog()
-
{
-
dialog = new Dialog(this, R.style.MyDialog);
-
View view = View.inflate(this, R.layout.login_dialog, null);
-
password = (EditText) view.findViewById(R.id.et_protected_password);
-
Button yes = (Button) view.findViewById(R.id.bt_protected_login_yes);
-
Button cancel = (Button) view.findViewById(R.id.bt_protected_login_no);
-
yes.setOnClickListener(this);
-
cancel.setOnClickListener(this);
-
dialog.setContentView(view);
-
dialog.setCancelable(false);
-
dialog.show();
-
}
-
-
private void showFirstDialog()
-
{
-
dialog = new Dialog(this, R.style.MyDialog);
-
//dialog.setContentView(R.layout.first_dialog);
-
View view = View.inflate(this, R.layout.first_dialog, null);//这种填充布局的方式比较方便,峭用拿到一个LayoutInflate对象
-
password = (EditText) view.findViewById(R.id.et_protected_first_password);
-
confirmPassword = (EditText) view.findViewById(R.id.et_protected_confirm_password);
-
Button yes = (Button) view.findViewById(R.id.bt_protected_first_yes);
-
Button cancel = (Button) view.findViewById(R.id.bt_protected_first_no);
-
yes.setOnClickListener(this);
-
cancel.setOnClickListener(this);
-
dialog.setContentView(view);
-
dialog.setCancelable(false);
-
dialog.show();
-
}
-
-
private boolean isSetPassword()
-
{
-
String pwd = sp.getString("password", "");
-
if(pwd.equals("") || pwd == null)
-
{
-
return false;
-
}
-
return true;
-
}
-
-
private boolean isSetupGuide()
-
{
-
return sp.getBoolean("setupGuide", false);
-
}
-
-
@Override
-
public void onClick(View v)
-
{
-
switch(v.getId())
-
{
-
case R.id.bt_protected_first_yes :
-
String fp = password.getText().toString().trim();
-
String cp = confirmPassword.getText().toString().trim();
-
if(fp.equals("") || cp.equals(""))
-
{
-
Toast.makeText(this, "密码不能为空", Toast.LENGTH_SHORT).show();
-
return;
-
}
-
else
-
{
-
if(fp.equals(cp))
-
{
-
Editor editor = sp.edit();
-
editor.putString("password", MD5Encoder.encode(fp));
-
editor.commit();
-
dialog.dismiss();
-
-
if(!isSetupGuide())
-
{
-
finish();
-
Intent intent = new Intent(this, SetupGuide1Activity.class);
-
startActivity(intent);
-
}
-
}
-
else
-
{
-
Toast.makeText(this, "两次密码不相同", Toast.LENGTH_SHORT).show();
-
return;
-
}
-
}
-
dialog.dismiss();
-
break;
-
-
case R.id.bt_protected_first_no :
-
dialog.dismiss();
-
finish();
-
break;
-
-
case R.id.bt_protected_login_yes :
-
String pwd = password.getText().toString().toString();
-
if(pwd.equals(""))
-
{
-
Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
-
}
-
else
-
{
-
String str = sp.getString("password", "");
-
if(MD5Encoder.encode(pwd).equals(str))
-
{
-
if(!isSetupGuide())
-
{
-
finish();
-
Intent intent = new Intent(this, SetupGuide1Activity.class);
-
startActivity(intent);
-
}
-
dialog.dismiss();
-
}
-
else
-
{
-
Toast.makeText(this, "密码错误", Toast.LENGTH_SHORT).show();
-
}
-
}
-
break;
-
-
case R.id.bt_protected_login_no :
-
dialog.dismiss();
-
finish();
-
break;
-
-
default :
-
break;
-
}
-
}
-
-
}
-
package com.xiaobin.security.ui;
-
-
import android.app.Activity;
-
import android.content.Intent;
-
import android.os.Bundle;
-
import android.view.View;
-
import android.view.View.OnClickListener;
-
import android.widget.Button;
-
-
import com.xiaobin.security.R;
-
-
public class SetupGuide1Activity extends Activity implements OnClickListener
-
{
-
private Button next;
-
-
@Override
-
protected void onCreate(Bundle savedInstanceState)
-
{
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.setup_guide1);
-
-
next = (Button) findViewById(R.id.bt_guide_next);
-
next.setOnClickListener(this);
-
}
-
-
@Override
-
public void onClick(View v)
-
{
-
switch(v.getId())
-
{
-
case R.id.bt_guide_next :
-
Intent intent = new Intent(this, SetupGuide2Activity.class);
-
finish();
-
startActivity(intent);
-
//这个是定义activity切换时的动画效果的
-
overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
-
break;
-
-
default :
-
break;
-
}
-
}
-
-
}
-
<?xml version="1.0" encoding="utf-8"?>
-
<alpha xmlns:andro
-
android:fromAlpha="0.0"
-
android:toAlpha="1.0"
-
android:duration="300" >
-
-
-
</alpha>
-
package com.xiaobin.security.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.view.View.OnClickListener;
-
import android.widget.Button;
-
import android.widget.CheckBox;
-
import android.widget.CompoundButton;
-
import android.widget.CompoundButton.OnCheckedChangeListener;
-
-
import com.xiaobin.security.R;
-
-
public class SetupGuide2Activity extends Activity implements OnClickListener
-
{
-
private Button bt_bind;
-
private Button bt_next;
-
private Button bt_perviout;
-
private CheckBox cb_bind;
-
private SharedPreferences sp;
-
-
@Override
-
protected void onCreate(Bundle savedInstanceState)
-
{
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.setup_guide2);
-
-
sp = getSharedPreferences("config", Context.MODE_PRIVATE);
-
-
bt_bind = (Button) findViewById(R.id.bt_guide_bind);
-
bt_next = (Button) findViewById(R.id.bt_guide_next);
-
bt_perviout = (Button) findViewById(R.id.bt_guide_pervious);
-
bt_bind.setOnClickListener(this);
-
bt_next.setOnClickListener(this);
-
bt_perviout.setOnClickListener(this);
-
-
cb_bind = (CheckBox) findViewById(R.id.cb_guide_check);
-
//初始化CheckBox状态
-
String sim = sp.getString("simSerial", null);
-
if(sim != null)
-
{
-
cb_bind.setText("已经绑定");
-
cb_bind.setChecked(true);
-
}
-
else
-
{
-
cb_bind.setText("没有绑定");
-
cb_bind.setChecked(false);
-
}
-
cb_bind.setOnCheckedChangeListener(new OnCheckedChangeListener()
-
{
-
@Override
-
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
-
{
-
//那个解除绑定的我还没做的呢,各位可以自己去完成,就是把那个SharedPreferences里面的值设置一下就行啦
-
if(isChecked)
-
{
-
cb_bind.setText("已经绑定");
-
setSimInfo();
-
}
-
else
-
{
-
cb_bind.setText("没有绑定");
-
}
-
}
-
});
-
}
-
-
@Override
-
public void onClick(View v)
-
{
-
switch(v.getId())
-
{
-
case R.id.bt_guide_bind :
-
setSimInfo();
-
cb_bind.setText("已经绑定");
-
cb_bind.setChecked(true);
-
break;
-
-
case R.id.bt_guide_next :
-
Intent intent = new Intent(this, SetupGuide3Activity.class);
-
finish();
-
startActivity(intent);
-
//这个是定义activity切换时的动画效果的
-
overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
-
break;
-
case R.id.bt_guide_pervious :
-
-
Intent i = new Intent(this, SetupGuide1Activity.class);
-
finish();
-
startActivity(i);
-
//这个是定义activity切换时的动画效果的
-
overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
-
break;
-
-
default :
-
break;
-
}
-
}
-
-
private void setSimInfo()
-
{
-
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-
String simSerial = telephonyManager.getSimSerialNumber();//拿到sim卡的序列号,是唯一的
-
Editor editor = sp.edit();
-
editor.putString("simSerial", simSerial);
-
editor.commit();
-
}
-
-
}

最后更新:2017-04-03 14:54:25