移动开发技术实验报告Word格式文档下载.docx
- 文档编号:3658427
- 上传时间:2023-05-02
- 格式:DOCX
- 页数:26
- 大小:1.20MB
移动开发技术实验报告Word格式文档下载.docx
《移动开发技术实验报告Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《移动开发技术实验报告Word格式文档下载.docx(26页珍藏版)》请在冰点文库上搜索。
1,友好的操作界面和良好的人机互动。
2,软件的登录界面保证了信息的保密性。
3,随时对重要信息的记录并设置到时间提醒。
4,备忘录内容的修改,删除和查询。
5,也可将其用作记录本使用,代替原有的单一备忘录app。
6,系统可靠运行,安全有效。
(3)开发及运行环境
(1)开发工具:
AndroidStudio
(2)系统环境:
Windows10家庭中文版
(3)开发语言:
Java,xml
第二部分:
开发技术
(1)SharedPrefenrences技术
在用户第一次进入软件时,可以注册个人账号,包括账号和密码;
密码须二次输入同样的字符,否则无法注册成功;
账号和密码使用SharedPrefenrence技术保存。
保存用户的账号密码,属于用户的偏好参数,若使用数据库来存储这些数据,未免有些大材小用,此时SharedPreferences技术就派上用场。
SharedPreferences使用键-值的形式来存储数据。
在我们的实例中,账号为键,密码为值,具有唯一匹配性,我们只需要调用SharedPreferences的getXxx(name),就可以根据键获得对应的值。
使用起来很方便!
登录界面源码:
packagecom.example.uilayouttest.Activity;
importandroid.content.Intent;
importandroid.content.SharedPreferences;
importandroid.content.pm.ActivityInfo;
importandroid.support.v7.app.ActionBar;
importandroid.support.v7.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.text.TextUtils;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.TextView;
importandroid.widget.Toast;
importcom.example.uilayouttest.Adapter.MD5Utils;
importcom.example.uilayouttest.R;
publicclassLoginActivityextendsAppCompatActivity{
privateTextViewtv_main_title;
//标题
privateTextViewtv_back,tv_register,tv_find_psw;
//返回键,显示的注册,找回密码
privateButtonbtn_login;
//登录按钮
privateStringuserName,psw,spPsw;
//获取的用户名,密码,加密密码
privateEditTextet_user_name,et_psw;
//编辑框
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//设置此界面为竖屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
init();
ActionBaractionbar=getSupportActionBar();
if(actionbar!
=null)
actionbar.hide();
}
//获取界面控件
privatevoidinit(){
//从main_title_bar中获取的id
tv_main_title=findViewById(R.id.tv_main_title);
tv_main_title.setText("
登录"
);
tv_back=findViewById(R.id.tv_back);
//从activity_login.xml中获取的
tv_register=findViewById(R.id.tv_register);
tv_find_psw=findViewById(R.id.tv_find_psw);
btn_login=findViewById(R.id.btn_login);
et_user_name=findViewById(R.id.et_user_name);
et_psw=findViewById(R.id.et_psw);
//返回键的点击事件
tv_back.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewv){
//登录界面销毁
LoginActivity.this.finish();
});
//立即注册控件的点击事件
tv_register.setOnClickListener(newView.OnClickListener(){
//为了跳转到注册界面,并实现注册功能
Intentintent=newIntent(LoginActivity.this,RegisterActivity.class);
startActivityForResult(intent,1);
//找回密码控件的点击事件
tv_find_psw.setOnClickListener(newView.OnClickListener(){
//跳转到找回密码界面(此页面暂未创建)
//登录按钮的点击事件
btn_login.setOnClickListener(newView.OnClickListener(){
//开始登录,获取用户名和密码getText().toString().trim();
userName=et_user_name.getText().toString().trim();
psw=et_psw.getText().toString().trim();
//对当前用户输入的密码进行MD5加密再进行比对判断,MD5Utils.md5();
psw进行加密判断是否一致
Stringmd5Psw=MD5Utils.md5(psw);
//md5Psw;
spPsw为根据从SharedPreferences中用户名读取密码
//定义方法readPsw为了读取用户名,得到密码
spPsw=readPsw(userName);
//TextUtils.isEmpty
if(TextUtils.isEmpty(userName)){
Toast.makeText(LoginActivity.this,"
请输入用户名"
Toast.LENGTH_SHORT).show();
return;
}elseif(TextUtils.isEmpty(psw)){
请输入密码"
//md5Psw.equals();
判断,输入的密码加密后,是否与保存在SharedPreferences中一致
}elseif(md5Psw.equals(spPsw)){
//一致登录成功
登录成功"
//保存登录状态,在界面保存登录的用户名定义个方法saveLoginStatusboolean状态,userName用户名;
saveLoginStatus(true,userName);
//登录成功后关闭此页面进入主页
Intentdata=newIntent();
//datad.putExtra();
name,value;
data.putExtra("
isLogin"
true);
//RESULT_OK为Activity系统常量,状态码为-1
//表示此页面下的内容操作成功将data返回到上一页面,如果是用back返回过去的则不存在用setResult传递data值
setResult(RESULT_OK,data);
//销毁登录界面
//跳转到主界面,登录成功的状态传递到MainActivity中
startActivity(newIntent(LoginActivity.this,MainActivity.class));
}elseif((spPsw!
=null&
&
!
TextUtils.isEmpty(spPsw)&
md5Psw.equals(spPsw))){
输入的用户名和密码不一致"
}else{
此用户名不存在"
/**
*从SharedPreferences中根据用户名读取密码
*/
privateStringreadPsw(StringuserName){
//getSharedPreferences("
loginInfo"
MODE_PRIVATE);
//"
mode_private;
MODE_PRIVATE表示可以继续写入
SharedPreferencessp=getSharedPreferences("
MODE_PRIVATE);
//sp.getString()userName,"
"
;
returnsp.getString(userName,"
*保存登录状态和登录用户名到SharedPreferences中
privatevoidsaveLoginStatus(booleanstatus,StringuserName){
//saveLoginStatus(true,userName);
//loginInfo表示文件名SharedPreferencessp=getSharedPreferences("
//获取编辑器
SharedPreferences.Editoreditor=sp.edit();
//存入boolean类型的登录状态
editor.putBoolean("
status);
//存入登录状态时的用户名
editor.putString("
loginUserName"
userName);
//提交修改
mit();
*注册成功的数据返回至此
*@paramrequestCode请求码
*@paramresultCode结果码
*@paramdata数据
//显示数据,onActivityResult
//startActivityForResult(intent,1);
从注册界面中获取数据
//intrequestCode,intresultCode,Intentdata
//LoginActivity->
startActivityForResult->
onActivityResult();
protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){
//super.onActivityResult(requestCode,resultCode,data);
super.onActivityResult(requestCode,resultCode,data);
if(data!
=null){
//是获取注册界面回传过来的用户名
//getExtra().getString("
***"
StringuserName=data.getStringExtra("
userName"
if(!
TextUtils.isEmpty(userName)){
//设置用户名到et_user_name控件
et_user_name.setText(userName);
//et_user_name控件的setSelection()方法来设置光标位置
et_user_name.setSelection(userName.length());
}
注册界面源码如下:
importandroid.graphics.Color;
importandroid.widget.RelativeLayout;
publicclassRegisterActivityextendsAppCompatActivity{
privateTextViewtv_back;
//返回按钮
privateButtonbtn_register;
//注册按钮
//用户名,密码,再次输入的密码的控件
privateEditTextet_user_name,et_psw,et_psw_again;
//用户名,密码,再次输入的密码的控件的获取值
privateStringuserName,psw,pswAgain;
//标题布局
privateRelativeLayoutrl_title_bar;
protectedvoidonCreate(BundlesavedInstanceState){
//设置页面布局,注册界面
setContentView(R.layout.activity_register);
//ActionBaractionbar=getSupportActionBar();
//if(actionbar!
=null)
//actionbar.hide();
//从main_title_bar.xml页面布局中获取对应的UI控件
//tv_main_title.setText("
注册"
//布局根元素
rl_title_bar=findViewById(R.id.title_bar);
//rl_title_bar.setBackgroundColor(Color.TRANSPARENT);
//从activity_register.xml页面中获取对应的UI控件
btn_register=findViewById(R.id.btn_register);
et_psw_again=findViewById(R.id.et_psw_again);
Buttonbtnback=findViewById(R.id.btn_backtologin);
btnback.setOnClickListener(newView.OnClickListener(){
startActivity(newIntent(RegisterActivity.this,LoginActivity.class));
//tv_back.setOnClickListener(newView.OnClickListener(){
//@Override
//publicvoidonClick(Viewv){
////返回键
//RegisterActivity.this.finish();
//}
//});
//注册按钮
btn_register.setOnClickListener(newView.OnClickListener(){
//获取输入在相应控件中的字符串
getEditString();
//判断输入框内容
Toast.makeText(RegisterActivity.this,"
}elseif(TextUtils.isEmpty(pswAgain)){
请再次输入密码"
}elseif(!
psw.equals(pswAgain)){
输入两次的密码不一样"
*从SharedPreferences中读取输入的用户名,判断SharedPreferences中是否有此用户名
}elseif(isExistUserName(userName)){
此账户名已经存在"
注册成功"
//把账号、密码和账号标识保存到sp里面
*保存账号和密码到SharedPreferences中
saveRegisterInfo(userNa
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 移动 开发 技术 实验 报告