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.
ghnb/gaoheng/SettingPassword.java

70 lines
3.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*gaoheng*/
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 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) {
SharedPreferences pref=getSharedPreferences("user management",MODE_PRIVATE);
boolean User_boolean = pref.getBoolean("user",false);//获取用户是否设置了密码
if(User_boolean) //User_boolean = false 时, 没有设置密码) 直接跳转到便签主界面
{
Toast.makeText(SettingPassword.this, "已经设置过密码",
Toast.LENGTH_SHORT).show();
}
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();
}
}