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.
MiNote/src/main/java/net/micode/notes/ui/DeleteLoginPassword.java

64 lines
2.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.util.Log;
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 DeleteLoginPassword extends Activity{
EditText password01;
Button Acknowledged;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_delete_loginpassword);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
password01=(EditText) findViewById(R.id.old_password);
Acknowledged=(Button)findViewById(R.id.Bt_Acknowledged);
Acknowledged.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text02 = password01.getText().toString();
if(text02.equals("")==true)
Toast.makeText(DeleteLoginPassword.this, "密码不能为空", Toast.LENGTH_SHORT).show();
SharedPreferences pref=getSharedPreferences("user management",MODE_PRIVATE);
String password = pref.getString("password","");
if(password.equals("")==false&&password.equals(text02)==true){
SharedPreferences.Editor editor=getSharedPreferences("user management",
MODE_PRIVATE).edit();
editor.putBoolean("user",false);//false表示已经设置登录密码
editor.putString("password","");
editor.apply();
Toast.makeText(DeleteLoginPassword.this, "已经删除登录密码", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(DeleteLoginPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
else{
Toast.makeText(DeleteLoginPassword.this, "密码错误", Toast.LENGTH_SHORT).show();
password01.setText("");//把密码框内输入过的错误密码清空
}
}
});
}
@Override
public void onBackPressed() {
Intent intent=new Intent(DeleteLoginPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}