Skip to content

Commit 5ac4ec7

Browse files
authored
Merge pull request #210 from Lee20170303/master
#35 #146 第二次作业
2 parents f2e9fac + 37150f7 commit 5ac4ec7

File tree

4 files changed

+189
-0
lines changed

4 files changed

+189
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package edu.hzuapps.androidlabs.homeworks.net1414080903235;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
/**
10+
* Created by Administrator on 2017/4/14.
11+
*/
12+
//实现登录功能:登录时保存用户数据到data.xml文件里面去
13+
public class Net1414080903235Utils {
14+
public static boolean saveUserInfo(Context context,String number,String password){
15+
SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE);
16+
SharedPreferences.Editor edit=sp.edit();
17+
edit.putString("username",number);
18+
edit.putString("pwd",password);
19+
edit.commit();
20+
return true;
21+
}
22+
public static Map<String,String> getUserInfo(Context context){
23+
SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE);
24+
String number=sp.getString("number",null);
25+
String password=sp.getString("password",null);
26+
Map<String,String> userMap=new HashMap<>();//这里可以通过number找到对应的password
27+
userMap.put("number",number);
28+
userMap.put("password",password);
29+
return userMap;
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package edu.hzuapps.androidlabs.homeworks.net1414080903235;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.text.TextUtils;
6+
import android.util.Log;
7+
import android.view.View;
8+
import android.widget.EditText;
9+
import android.widget.Toast;
10+
11+
import java.util.Map;
12+
13+
import Utils.Net1414080903235Utils;
14+
15+
public class Net1414080903235_SignInActivity extends Activity implements View.OnClickListener {
16+
private EditText etNumber;
17+
private EditText etPassword;
18+
public void onCreate(Bundle savedInstanceState) {
19+
super.onCreate(savedInstanceState);
20+
setContentView(R.layout.activity_net1414080903235__signin);
21+
initView();
22+
Map<String, String> userInfo = Net1414080903235Utils.getUserInfo(this);
23+
if (userInfo != null) {
24+
etNumber.setText(userInfo.get("number"));
25+
etPassword.setText(userInfo.get("password"));
26+
}
27+
}
28+
29+
private void initView(){
30+
etNumber=(EditText) findViewById(R.id.et_number);
31+
etPassword=(EditText) findViewById(R.id.et_password);
32+
findViewById(R.id.btn_login).setOnClickListener(this);
33+
}
34+
35+
@Override
36+
public void onClick(View v) {
37+
String number=etNumber.getText().toString().trim();
38+
String password=etPassword.getText().toString();
39+
if(TextUtils.isEmpty(number)){
40+
Toast.makeText(this,"请输入账号",Toast.LENGTH_SHORT).show();
41+
return;
42+
}
43+
if(TextUtils.isEmpty(password)){
44+
Toast.makeText(this,"请输入密码",Toast.LENGTH_SHORT).show();
45+
return;
46+
}
47+
Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
48+
Log.i("MainActivity","记住密码:"+number+","+password);
49+
boolean isSaveSuccess=Net1414080903235Utils.saveUserInfo(this,number,password);
50+
if(isSaveSuccess){
51+
Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show();
52+
}
53+
else{
54+
Toast.makeText(this, "失败", Toast.LENGTH_SHORT).show();
55+
}
56+
}
57+
}
58+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="#E6E6E6"
6+
android:orientation="vertical">
7+
8+
<ImageView
9+
android:id="@+id/iv_head"
10+
android:layout_width="50dp"
11+
android:layout_height="50dp"
12+
android:src="@drawable/sodoku"
13+
android:layout_alignParentRight="true"
14+
android:layout_alignParentEnd="true"
15+
android:layout_alignParentLeft="true"
16+
android:layout_alignParentStart="true"
17+
android:layout_alignParentTop="true"
18+
android:layout_above="@+id/layout" />
19+
20+
<LinearLayout
21+
android:id="@+id/layout"
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content"
24+
android:background="#ffffff"
25+
android:orientation="vertical"
26+
android:layout_above="@+id/btn_login"
27+
android:layout_alignParentLeft="true"
28+
android:layout_alignParentStart="true"
29+
android:layout_marginBottom="59dp">
30+
<RelativeLayout
31+
android:id="@+id/r1_username"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:layout_margin="10dp">
35+
<TextView
36+
android:id="@+id/tv_name"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"
39+
android:layout_centerVertical="true"
40+
android:text="账号"/>
41+
<EditText
42+
android:id="@+id/et_number"
43+
android:layout_width="match_parent"
44+
android:layout_height="wrap_content"
45+
android:layout_marginLeft="5dp"
46+
android:layout_toRightOf="@+id/tv_name"
47+
android:background="@null"/>
48+
</RelativeLayout>
49+
<View
50+
android:layout_width="match_parent"
51+
android:layout_height="2dp"
52+
android:background="#E6E6E6"/>
53+
<RelativeLayout
54+
android:id="@+id/r1_userpsw"
55+
android:layout_width="match_parent"
56+
android:layout_height="wrap_content"
57+
android:layout_margin="10dp">
58+
<TextView
59+
android:id="@+id/tv_psw"
60+
android:layout_width="wrap_content"
61+
android:layout_height="wrap_content"
62+
android:layout_centerVertical="true"
63+
android:text="密码"/>
64+
<EditText
65+
android:id="@+id/et_password"
66+
android:layout_width="match_parent"
67+
android:layout_height="wrap_content"
68+
android:inputType="textPassword"
69+
android:background="@null"
70+
android:layout_alignTop="@+id/tv_psw"
71+
android:layout_alignParentLeft="true"
72+
android:layout_alignParentStart="true" />
73+
</RelativeLayout>
74+
75+
</LinearLayout>
76+
<Button
77+
android:id="@+id/btn_login"
78+
android:layout_width="match_parent"
79+
android:layout_height="wrap_content"
80+
android:background="#3C8DC4"
81+
android:text="登录"
82+
android:textColor="#ffffff"
83+
android:layout_marginBottom="177dp"
84+
android:layout_alignParentBottom="true"
85+
android:layout_alignParentLeft="true"
86+
android:layout_alignParentStart="true" />
87+
</RelativeLayout>
88+
89+

sh.exe.stackdump

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Stack trace:
2+
Frame Function Args
3+
00180308010 0018005CE1E (0018022B830, 0018021DC39, 00180308010, 000FFFFB9F0)
4+
00180308010 00180046609 (00000000002, 00000000003, 00000000002, 000C0000000)
5+
00180308010 00180046642 (00000000002, 00180308320, 00180308010, 00000000008)
6+
00180308010 001800574A2 (00000000000, 000FFFFCC35, 000FFFFCC53, 0018021C3F0)
7+
000FFFFCCB0 00180057550 (645C655C725C635C, 695C745C6E5C655C, 6D5C2D5C6C5C615C, 675C615C6E5C615C)
8+
000FFFFCCB0 00180046DD5 (00000000000, 00000000000, 00000000000, 00000000000)
9+
00000000000 00180045873 (00000000000, 00000000000, 00000000000, 00000000000)
10+
000FFFFFFF0 00180045924 (00000000000, 00000000000, 00000000000, 00000000000)
11+
End of stack trace

0 commit comments

Comments
 (0)