android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
gravity="center"
android:
text="登陆成功,进入用户界面"
android:
textColor="#000000"
android:
textSize="20sp"/>
java代码:
LoginActivity.java
packagecom.wang.activity;
importandroid.app.Activity;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.content.SharedPreferences;
importandroid.content.SharedPreferences.Editor;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.view.Window;
importandroid.widget.Button;
importandroid.widget.CheckBox;
importandroid.widget.CompoundButton;
importandroid.widget.CompoundButton.OnCheckedChangeListener;
importandroid.widget.EditText;
importandroid.widget.ImageButton;
importandroid.widget.Toast;
publicclassLoginActivityextendsActivity{
privateEditTextuserName,passWord;
privateCheckBoxrem_pw,auto_login;
privateButtonbtn_login;
privateImageButtonbtnQuit;
privateStringuserNameValue,passwordValue;
privateSharedPreferencessp;
privatefinalStringMAK="innoview";
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
//去掉TitleBar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.login);
//获取shareprefrence里面的数据
sp=this.getSharedPreferences("userInfo",Context.MODE_WORLD_READABLE);
userName=(EditText)findViewById(R.id.et_zh);
passWord=(EditText)findViewById(R.id.et_mima);
rem_pw=(CheckBox)findViewById(R.id.cb_mima);
auto_login=(CheckBox)findViewById(R.id.cb_auto);
btn_login=(Button)findViewById(R.id.btn_login);
btnQuit=(ImageButton)findViewById(R.id.img_btn);
//判断记住密码框状态
if(sp.getBoolean("ISCHECK",false))
{
//记住密码框状态标记为选中
rem_pw.setChecked(true);
try{
userNameValue=sp.getString("USER_NAME","");
System.out.println("<<<<<<<<<<<<"+"加密后的用户名"+userNameValue);
Stringusername=AESEncryptor.decrypt(MAK,userNameValue);
System.out.println("<<<<<<<<<<<<"+"解密后的用户名"+username);
userName.setText(username);
}catch(Exceptione){
Toast.makeText(LoginActivity.this,"用户名解密异常",Toast.LENGTH_SHORT).show();
e.printStackTrace(); //TochangebodyofcatchstatementuseFile|Settings|FileTemplates.
}
Stringpassword=null;
try{
passwordValue=sp.getString("PASSWORD","");
System.out.println("<<<<<<<<<<<<"+"加密后的密码"+passwordValue);
password=AESEncryptor.decrypt(MAK,passwordValue);
System.out.println("<<<<<<<<<<<<"+"解密后的密码"+password);
}catch(Exceptione){
Toast.makeText(LoginActivity.this,"密码解密异常",Toast.LENGTH_SHORT).show();
e.printStackTrace(); //TochangebodyofcatchstatementuseFile|Settings|FileTemplates.
}
passWord.setText(password);
//判断自动登录框状态
if(sp.getBoolean("AUTO_ISCHECK",false))
{
//自动登录框状态标记为选中
auto_login.setChecked(true);
Intentintent=newIntent(LoginActivity.this,LogoActivity.class);
LoginActivity.this.startActivity(intent);
}
}
//用户名:
login秘密:
123456
btn_login.setOnClickListener(newOnClickListener(){
publicvoidonClick(Viewv){
userNameValue=userName.getText().toString();
passwordValue=passWord.getText().toString();
if(userNameValue.equals("login")&&passwordValue.equals("123456"))
{
Toast.makeText(LoginActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();
//如果记住密码框未选中状态
if(rem_pw.isChecked())
{
Editoreditor=sp.edit();
// AESEncryptor.encrypt(userNameValue);
try{
editor.putString("USER_NAME",AESEncryptor.encrypt(MAK,userNameValue));
System.out.println("<<<<<<<<"+"加密后的用户名"+AESEncryptor.encrypt(MAK,userNameValue));
}catch(Exceptione){
Toast.makeText(LoginActivity.this,"用户名加密异常",Toast.LENGTH_SHORT).show();
e.printStackTrace(); //TochangebodyofcatchstatementuseFile|Settings|FileTemplates.
}
try{
editor.putString("PASSWORD",AESEncryptor.encrypt(MAK,passwordValue));