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.
68 lines
2.4 KiB
68 lines
2.4 KiB
/*gaoheng*/
|
|
package net.micode.notes.ui;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.os.Bundle;
|
|
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 LoginActivity extends Activity {
|
|
|
|
EditText lg_password;
|
|
Button lg_login;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
SharedPreferences pref = getSharedPreferences("user management", MODE_PRIVATE);
|
|
boolean userBoolean = pref.getBoolean("user", false); // 获取用户是否设置了密码
|
|
|
|
if (!userBoolean) { // userBoolean = false 时(没有设置密码),直接跳转到便签主界面
|
|
Intent intent = new Intent(LoginActivity.this, NotesListActivity.class);
|
|
startActivity(intent);
|
|
finish();
|
|
}
|
|
|
|
setContentView(R.layout.activity_login);
|
|
|
|
getWindow().setSoftInputMode(
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
lg_password = (EditText) findViewById(R.id.lg_password);
|
|
lg_login = (Button) findViewById(R.id.login);
|
|
lg_login.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
SharedPreferences pref = getSharedPreferences("user management", MODE_PRIVATE);
|
|
String password = pref.getString("password", "");
|
|
|
|
if (!password.equals("") && password.equals(lg_password.getText().toString())) {
|
|
Intent intent = new Intent(LoginActivity.this, NotesListActivity.class);
|
|
startActivity(intent);
|
|
finish();
|
|
} else {
|
|
Toast.makeText(LoginActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
|
|
/*
|
|
用来重新登录或者忘记密码的时候更改
|
|
SharedPreferences.Editor editor = null;
|
|
editor.putString("password", "1234567");
|
|
editor.apply();
|
|
*/
|
|
lg_password.setText(""); // 把密码框内输入过的错误密码清空
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|