|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 青玄 于 2015-1-6 18:21 编辑
手机防盗模块
首先是实现滑屏操作的类:
<p>package com.cbd.safemobile;</p><p>import com.example.safemobile_test.R;</p><p>import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;</p><p>public abstract class BaseSetupWizardActivity extends Activity {
//定义共享存储偏号
protected SharedPreferences ps;
//定义手势识别器
protected GestureDetector mGestureDetector;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ps=getSharedPreferences("config", Context.MODE_PRIVATE);
mGestureDetector=new GestureDetector(new GestureDetector.SimpleOnGestureListener(){
//手指在屏幕上做手势时,调用该方法
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
if(Math.abs(e1.getRawY() - e2.getRawY())>200)
{
Log.i("BaseSetupWizardActivity","垂直方向移动过大,动作不合法");
return true;
}
if(Math.abs(velocityX)<50)
{
Log.i("BaseSetupWizardActivity","滑动的太慢,动作不合法");
return true;
}
if(e2.getRawX()-e1.getRawX()>200)
{
//showPre();
pre(null);
return true;
}
if(e1.getRawX()-e2.getRawX()>200)
{
//showNext();
next(null);
return true;
}
return super.onFling(e1, e2, velocityX, velocityY);
}
});
setupView();
findView();
}
//当手指在屏幕上触摸的时候调用的方法.
@Override
public boolean onTouchEvent(MotionEvent event) {
//3.让手势识别器生效
mGestureDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}
public abstract void setupView();
public abstract void findView();
public abstract void showNext();
public abstract void showPre();
public void next(View v)
{
showNext();
overridePendingTransition(R.anim.tran_in_next, R.anim.tran_out_next);
}
public void pre(View v)
{
showPre();
overridePendingTransition(R.anim.tran_in</p><p>
_pre, R.anim.tran_out_pre);
}
}
</p><p> </p>
首先近来的时候先设置密码,然后就进入第一个设置页面:
package com.example.safemobile_test;
import com.cbd.pagechange.BaseActivity;
import com.cbd.safemobile.BaseSetupWizardActivity;
import com.example.safemobile_test.activity.TheftFirstActivity;
import com.example.safemobile_test.activity.TheftSetUpOkActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
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;
public class TheftPhone extends BaseSetupWizardActivity {
private AlertDialog dialog ;
private SharedPreferences sp;
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// // TODO Auto-generated method stub
// super.onCreate(savedInstanceState);
//
//
// }
public void showSetPasswordDialog()
{
AlertDialog.Builder builder = new Builder(this);
View view = View.inflate(this, R.layout.layout_first_dialog, null);
dialog = builder.create();
dialog.setView(view, 0, 0, 0, 0);
dialog.show();
final EditText inputpassword = (EditText) view.findViewById(R.id.et_first_entry_pwd);
final EditText reinputPassword = (EditText) view.findViewById(R.id.et_first_entry_pwd_confirm);
Button onclick_ok = (Button) view.findViewById(R.id.bt_first_entry_ok);
Button onclick_cancel = (Button) view.findViewById(R.id.bt_first_entry_cancle);
onclick_ok.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String getInputPass = inputpassword.getText().toString();
String getreinputPass = reinputPassword.getText().toString();
if((getInputPass.equals(getreinputPass)) && (getInputPass != null && getreinputPass!=null)
&&!("".equals(getreinputPass) && "".equals(getInputPass)))
{
Toast.makeText(getApplicationContext(), "密码已经设置", Toast.LENGTH_SHORT).show();
Editor editor = sp.edit();
editor.putString("password", getInputPass);
editor.putBoolean("ispassword", true);
editor.commit();
showGetpasswordDialog();
dialog.dismiss();
TheftPhone.this.finish();
}else
{
Toast.makeText(getApplicationContext(), "密码不匹配或不能为空", Toast.LENGTH_SHORT).show();
}
}
});
onclick_cancel.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "取消", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
}
public void showGetpasswordDialog()
{
AlertDialog.Builder builder=new Builder(this);
View view=View.inflate(this, R.layout.layout_normal_dialog, null);
dialog=builder.create();
dialog.setView(view,0,0,0,0);
dialog.show();
Button bt_normal_entry_ok=(Button) view.findViewById(R.id.bt_normal_entry_ok);
Button bt_normal_entry_cancle=(Button) view.findViewById(R.id.bt_normal_entry_cancle);
final EditText et_normal_entry_pwd=(EditText) view.findViewById(R.id.et_normal_entry_pwd);
bt_normal_entry_ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String text=et_normal_entry_pwd.getText().toString().trim();
if(text.equals(sp.getString("password", ""))){
if(ps.getBoolean("isLock_state", true))
{
Intent intent = new Intent(getApplicationContext(), TheftSetUpOkActivity.class);
startActivity(intent);
}else
{
Toast.makeText(getApplicationContext(), "ps为:" +ps.getBoolean("isLock_state", true) ,
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), TheftFirstActivity.class);
startActivity(intent);
}
dialog.dismiss();
TheftPhone.this.finish();
}
}
});
bt_normal_entry_cancle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
});
}
@Override
public void setupView() {
// TODO Auto-generated method stub
sp = getSharedPreferences("config", Context.MODE_PRIVATE);
if(!sp.getBoolean("ispassword", false))
{
this.showSetPasswordDialog();
}else
{
this.showGetpasswordDialog();
}
}
@Override
public void findView() {
// TODO Auto-generated method stub
}
@Override
public void showNext() {
// TODO Auto-generated method stub
}
@Override
public void showPre() {
// TODO Auto-generated method stub
}
}
接下来就可以往下设置了:
|
-
评分
-
查看全部评分
|