public class LockAppActivity extends Activity{
EditText pass1, pass2;
Button back, next;
SharedPreferences prefs;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lockapp);
pass1 = (EditText) findViewById(R.id.edit1);
pass2 = (EditText) findViewById(R.id.edit2);
back = (Button) findViewById(R.id.back);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v1) {
Intent setIntent = new Intent(Intent.ACTION_MAIN);
setIntent.addCategory(Intent.CATEGORY_HOME);
setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(setIntent);
}
});
next = (Button) findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
String password1 = "";
String password2 = "";
public void onClick(View v){
password1 = pass1.getText().toString();
password2 = pass2.getText().toString();
if (!password1.equals("")){
if (password1.length() >= 15){
Pattern pattern = Pattern.compile("[[0-9]&&[a-z]&&[A-Z]]");
Matcher matcher = pattern.matcher(password1);
if(matcher.matches()){
if (password1.equals(password2)){
//SavePreferences("Password", password1);
Intent intent = new Intent(LockAppActivity.this, PhoneNumActivity.class);
startActivity(intent);
}
else{
pass1.setText("");
pass2.setText("");
Toast.makeText(LockAppActivity.this,"Not equal",Toast.LENGTH_LONG).show();
}
}
else{
pass1.setText("");
pass2.setText("");
Toast.makeText(LockAppActivity.this,"Not matched",Toast.LENGTH_LONG).show();
}
}
else{
pass1.setText("");
pass2.setText("");
Toast.makeText(LockAppActivity.this,"Length",Toast.LENGTH_LONG).show();
}
}
else{
pass1.setText("");
pass2.setText("");
Toast.makeText(LockAppActivity.this,"Nothing",Toast.LENGTH_LONG).show();
}
}
});
}
private void SavePreferences(String key, String value){
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}
}
我在进入有效密码时面临问题,但是,我pop着一位名叫“不匹配”的传闻,以及我如何在口中挽救这一密码,而新密码进入时,会更新和推翻旧密码。