package com.example.pengtuanyuan.logindemo01;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class UserInfoUtil {
public static Boolean saveUserInfo(String useName, String usePassword) {
try {
String userInfo=useName+"##"+usePassword;
String path="/data/data/com.example.pengtuanyuan.logindemo01";
File file=new File(path,"userInfo.txt");
FileOutputStream fileOutputStream=new FileOutputStream(file);
fileOutputStream.write(userInfo.getBytes());
fileOutputStream.close();
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
public static Map<String,String> getUserInfo(){
try {
String path="/data/data/com.example.pengtuanyuan.logindemo01";
File file=new File(path,"userInfo.txt");
FileInputStream fileInputStream=new FileInputStream(file);
BufferedReader bufferedReader= new BufferedReader(new InputStreamReader(fileInputStream));
String readLine =bufferedReader.readLine();
String[] split=readLine.split("##");
HashMap<String,String> hashMap=new HashMap<String,String>();
hashMap.put("useName",split[0]);
hashMap.put("usePassword",split[1]);
bufferedReader.close();
fileInputStream.close();
return hashMap;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
----------------------------------------------------
package com.example.pengtuanyuan.logindemo01;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Map;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private EditText ed_inputName;
private EditText ed_inputPassword;
private CheckBox cb_choice;
private Button bt_login;
private Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext=this;
ed_inputName = (EditText) findViewById(R.id.ed_inputName);
ed_inputPassword = (EditText) findViewById(R.id.ed_inputPassword);
cb_choice = (CheckBox) findViewById(R.id.cb_choice);
bt_login = (Button) findViewById(R.id.bt_login);
bt_login.setOnClickListener(this);
Map<String,String> map=UserInfoUtil.getUserInfo();
if (map!=null){
String userName=map.get("useName");
String password=map.get("usePassword");
ed_inputName.setText(userName);
ed_inputPassword.setText(password);
}
}
private void login(){
String useName = ed_inputName.getText().toString().trim();
String usePassword = ed_inputPassword.getText().toString().trim();
boolean isChecked=cb_choice.isChecked();
if (TextUtils.isEmpty(useName)||TextUtils.isEmpty(usePassword)){
Toast.makeText(mContext,"Name and password cannot be empty",Toast.LENGTH_SHORT).show();
return;
}
if (isChecked){
Boolean result=UserInfoUtil.saveUserInfo(useName,usePassword);
if (result){
Toast.makeText(mContext,"Name and password be saved",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(mContext,"Name and password cannot be saved",Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(mContext,"Name and password don't need to be saved",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.bt_login:
login();
break;
default:
break;
}
}
}
登陸案例——密碼回顯
最后編輯于 :
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來灾常,“玉大人霎冯,你說我怎么就攤上這事〕伲” “怎么了沈撞?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長雕什。 經(jīng)常有香客問我缠俺,道長拧廊,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任晋修,我火速辦了婚禮,結果婚禮上凰盔,老公的妹妹穿的比我還像新娘墓卦。我一直安慰自己,他們只是感情好户敬,可當我...
- 文/花漫 我一把揭開白布落剪。 她就那樣靜靜地躺著,像睡著了一般尿庐。 火紅的嫁衣襯著肌膚如雪忠怖。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼贺纲,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了褪测?” 一聲冷哼從身側響起猴誊,我...
- 正文 年R本政府宣布巴粪,位于F島的核電站通今,受9級特大地震影響粥谬,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜辫塌,卻給世界環(huán)境...
- 文/蒙蒙 一漏策、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧臼氨,春花似錦掺喻、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至持隧,卻和暖如春即硼,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背屡拨。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 【一】win10程序閃退問題瓮增,折騰了2天終于得以解決,中間各種方法都嘗試了哩俭,后面使用了某驅(qū)動更新軟件(有許多都更新...
- 1. ssh-keygen -t rsa 生成公鑰匙與私鑰匙,會生成在~/.ssh目錄下 2. 免密碼遠程ssh:...
- 最近我爹打電話給我凡资,老是覺得他很啰嗦砸捏。而且很少認真地和他說話。老是覺得他很煩隙赁,而且找不到什么話給他說的垦藏。 出門在外...
- 看美劇可以學好英語级解? 呵呵。田绑。勤哗。。掩驱。俺陋。 看了這么多年的國產(chǎn)劇我也沒有學好中文啊昙篙! 英語學習可以說是一件非常枯燥的事...