Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,143 @@
|
||||
package net.micode.notes.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.micode.notes.R;
|
||||
|
||||
public class PasswordVerifyActivity extends Activity implements OnClickListener {
|
||||
public static final String PREFERENCE_PASSWORD_ENABLED = "net.micode.notes.password_enabled";
|
||||
public static final String PREFERENCE_PASSWORD = "net.micode.notes.password";
|
||||
|
||||
private EditText mPasswordEditText;
|
||||
private Button mVerifyButton;
|
||||
private Button mForgotPasswordButton;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_password_verify);
|
||||
|
||||
initViews();
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
mPasswordEditText = (EditText) findViewById(R.id.et_password);
|
||||
mVerifyButton = (Button) findViewById(R.id.btn_verify);
|
||||
mForgotPasswordButton = (Button) findViewById(R.id.btn_forgot_password);
|
||||
|
||||
mVerifyButton.setOnClickListener(this);
|
||||
mForgotPasswordButton.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btn_verify:
|
||||
verifyPassword();
|
||||
break;
|
||||
case R.id.btn_forgot_password:
|
||||
showForgotPasswordDialog();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyPassword() {
|
||||
String inputPassword = mPasswordEditText.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(inputPassword)) {
|
||||
Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputPassword.length() != 4) {
|
||||
Toast.makeText(this, "请输入4位数字密码", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String savedPassword = getSavedPassword(this);
|
||||
if (inputPassword.equals(savedPassword)) {
|
||||
// 密码正确,进入应用
|
||||
Intent intent = new Intent(this, NotesListActivity.class);
|
||||
intent.putExtra("PASSWORD_VERIFIED", true); // 添加验证通过标志
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} else {
|
||||
Toast.makeText(this, "密码错误,请重新输入", Toast.LENGTH_SHORT).show();
|
||||
mPasswordEditText.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
private void showForgotPasswordDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("忘记密码")
|
||||
.setMessage("确定要重置密码吗?")
|
||||
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
resetPassword();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("取消", null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void resetPassword() {
|
||||
// 重置密码
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
preferences.edit()
|
||||
.putBoolean(PREFERENCE_PASSWORD_ENABLED, false)
|
||||
.putString(PREFERENCE_PASSWORD, "")
|
||||
.apply();
|
||||
|
||||
Toast.makeText(this, "密码已重置", Toast.LENGTH_SHORT).show();
|
||||
|
||||
// 进入应用
|
||||
Intent intent = new Intent(this, NotesListActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
// 静态方法:判断密码锁是否已启用
|
||||
public static boolean isPasswordEnabled(Context context) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return preferences.getBoolean(PREFERENCE_PASSWORD_ENABLED, false);
|
||||
}
|
||||
|
||||
// 静态方法:获取保存的密码
|
||||
public static String getSavedPassword(Context context) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return preferences.getString(PREFERENCE_PASSWORD, "");
|
||||
}
|
||||
|
||||
// 静态方法:设置密码
|
||||
public static void setPassword(Context context, String password) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
preferences.edit()
|
||||
.putBoolean(PREFERENCE_PASSWORD_ENABLED, true)
|
||||
.putString(PREFERENCE_PASSWORD, password)
|
||||
.apply();
|
||||
}
|
||||
|
||||
// 静态方法:清除密码
|
||||
public static void clearPassword(Context context) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
preferences.edit()
|
||||
.putBoolean(PREFERENCE_PASSWORD_ENABLED, false)
|
||||
.putString(PREFERENCE_PASSWORD, "")
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue