安卓实现密码保存和自动登录Word文件下载.docx
- 文档编号:877082
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:19
- 大小:466.46KB
安卓实现密码保存和自动登录Word文件下载.docx
《安卓实现密码保存和自动登录Word文件下载.docx》由会员分享,可在线阅读,更多相关《安卓实现密码保存和自动登录Word文件下载.docx(19页珍藏版)》请在冰点文库上搜索。
<
RelativeLayout
wrap_content"
ImageButton
id="
@+id/img_btn"
layout_alignParentRight="
true"
@drawable/quit"
/>
TextView
@+id/tv_zh"
35dip"
layout_marginLeft="
12dip"
layout_marginTop="
10dip"
gravity="
bottom"
text="
帐号:
"
textColor="
#000000"
textSize="
18sp"
/>
EditText
@+id/et_zh"
40dip"
layout_below="
@id/tv_zh"
layout_marginRight="
@+id/tv_mima"
@id/et_zh"
密码:
@+id/et_mima"
@id/tv_mima"
maxLines="
200"
password="
scrollHorizontally="
CheckBox
@+id/cb_mima"
@id/et_mima"
记住密码"
@+id/cb_auto"
@id/cb_mima"
自动登录"
Button
@+id/btn_login"
80dip"
layout_alignTop="
@id/cb_auto"
center"
登录"
/RelativeLayout>
/LinearLayout>
布局文件:
logo.xml
layout_weight="
3"
ProgressBar
@+id/pgBar"
layout_centerInParent="
@+id/tv1"
@id/pgBar"
layout_centerHorizontal="
正在登录..."
LinearLayout
1"
@+id/btn_back"
70dip"
取消"
12sp"
welcom.xml
layout_gravity="
@drawable/login_bg"
登陆成功,进入用户界面"
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);
解密后的用户名"
+username);
userName.setText(username);
}catch(Exceptione){
Toast.makeText(LoginActivity.this,"
用户名解密异常"
Toast.LENGTH_SHORT).show();
e.printStackTrace();
//TochangebodyofcatchstatementuseFile|Settings|FileTemplates.
}
Stringpassword=null;
passwordValue=sp.getString("
PASSWORD"
加密后的密码"
+passwordValue);
password=AESEncryptor.decrypt(MAK,passwordValue);
解密后的密码"
+password);
密码解密异常"
passWord.setText(password);
//判断自动登录框状态
if(sp.getBoolean("
AUTO_ISCHECK"
{
//自动登录框状态标记为选中
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);
editor.putString("
AESEncryptor.encrypt(MAK,userNameValue));
+AESEncryptor.encrypt(MAK,userNameValue));
用户名加密异常"
AESEncryptor.encrypt(MAK,passwordValue));
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实现 密码 保存 自动 登录