You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.6 KiB
91 lines
3.6 KiB
package net.micode.notes.ui;
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.view.WindowManager;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
import android.widget.Toast;
|
|
import net.micode.notes.R;
|
|
public class DeletingPassword extends Activity {
|
|
|
|
// 声明EditText
|
|
EditText Dt_password;
|
|
//声明Button
|
|
Button Acknowledged;
|
|
|
|
// 在Activity创建时执行
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_delete_password);
|
|
//监听create活动
|
|
//设置软键盘的显示方式
|
|
getWindow().setSoftInputMode(
|
|
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
|
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
|
|
|
// 初始化EditText
|
|
Dt_password=(EditText) findViewById(R.id.thepassword);
|
|
// 初始化Button
|
|
Acknowledged=(Button)findViewById(R.id.Dt_Acknowledged);
|
|
|
|
// 设置Button的点击事件
|
|
Acknowledged.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
// 获取输入框中的密码
|
|
String text02 = Dt_password.getText().toString();
|
|
// 如果密码为空,则显示提示信息
|
|
if(text02.equals("")==true)
|
|
Toast.makeText(DeletingPassword.this, "密码不能为空",
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
// 从SharedPreferences中获取保存的密码
|
|
SharedPreferences pref=getSharedPreferences("user management",MODE_PRIVATE);
|
|
String password = pref.getString("password","");
|
|
|
|
// 如果保存的密码不为空且与输入的密码相等,则删除登录密码
|
|
if(password.equals("")==false&&password.equals(text02)==true){
|
|
// 获取SharedPreferences的编辑器
|
|
SharedPreferences.Editor editor=getSharedPreferences("user management",
|
|
MODE_PRIVATE).edit();
|
|
// 设置"user"键为false表示已设置登录密码
|
|
editor.putBoolean("user",false);
|
|
// 清空密码
|
|
editor.putString("password","");
|
|
// 应用编辑器的修改
|
|
editor.apply();
|
|
|
|
// 显示提示信息
|
|
Toast.makeText(DeletingPassword.this, "已经删除登录密码",
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
// 跳转到NotesListActivity
|
|
Intent intent=new Intent(DeletingPassword.this,NotesListActivity.class);
|
|
startActivity(intent);
|
|
finish(); // 结束当前Activity
|
|
} else {
|
|
// 显示密码错误的提示信息
|
|
Toast.makeText(DeletingPassword.this, "密码错误",
|
|
Toast.LENGTH_SHORT).show();
|
|
// 清空密码输入框
|
|
Dt_password.setText("");
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// 返回键的处理
|
|
@Override
|
|
public void onBackPressed() {
|
|
// 跳转到NotesListActivity
|
|
Intent intent=new Intent(DeletingPassword.this,NotesListActivity.class);
|
|
//开始该activity
|
|
startActivity(intent);
|
|
// 结束当前Activity
|
|
finish();
|
|
}
|
|
} |