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.
xiaomibianqian/src-function/main/java/net/micode/notes/ui/SettingPassword.java

62 lines
2.7 KiB

package net.micode.notes.ui;
import static android.content.Context.MODE_PRIVATE;
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 SettingPassword extends Activity {
EditText password;
EditText password_ack;
Button acknowledge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_loginpassword);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
password=(EditText) findViewById(R.id.password);
password_ack=(EditText) findViewById(R.id.password_ack);
acknowledge=(Button)findViewById(R.id.acknowledge);
acknowledge.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text02 = password.getText().toString();
String text03 = password_ack.getText().toString();
if(text02.equals("")==true) {
Toast.makeText(SettingPassword.this, "密码不能为空",
Toast.LENGTH_SHORT).show();
}else if (text02.equals(text03) == false) {
Toast.makeText(SettingPassword.this, "密码不匹配,请重新输入密码 ", Toast.LENGTH_SHORT).show();
password_ack.setText("");
}else if (text02.equals(text03) == true){
SharedPreferences.Editor editor=getSharedPreferences("user management",
MODE_PRIVATE).edit();
editor.putBoolean("user",true);//true 表示已经设置登录密码
editor.putString("password",text02);
editor.apply();
Log.d("RegisterLoginPassword","password is "+text02);
Toast.makeText(SettingPassword.this, "设置密码成功",
Toast.LENGTH_SHORT).show();
Intent intent=new
Intent(SettingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}
});
}
@Override
public void onBackPressed() {
Intent intent=new Intent(SettingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}