Skip to content

Commit

Permalink
Merge pull request #210 from Lee20170303/master
Browse files Browse the repository at this point in the history
#35 #146 第二次作业
  • Loading branch information
zengsn authored Apr 28, 2017
2 parents f2e9fac + 37150f7 commit 5ac4ec7
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903235;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashMap;
import java.util.Map;

/**
* Created by Administrator on 2017/4/14.
*/
//实现登录功能:登录时保存用户数据到data.xml文件里面去
public class Net1414080903235Utils {
public static boolean saveUserInfo(Context context,String number,String password){
SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE);
SharedPreferences.Editor edit=sp.edit();
edit.putString("username",number);
edit.putString("pwd",password);
edit.commit();
return true;
}
public static Map<String,String> getUserInfo(Context context){
SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE);
String number=sp.getString("number",null);
String password=sp.getString("password",null);
Map<String,String> userMap=new HashMap<>();//这里可以通过number找到对应的password
userMap.put("number",number);
userMap.put("password",password);
return userMap;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903235;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Map;

import Utils.Net1414080903235Utils;

public class Net1414080903235_SignInActivity extends Activity implements View.OnClickListener {
private EditText etNumber;
private EditText etPassword;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903235__signin);
initView();
Map<String, String> userInfo = Net1414080903235Utils.getUserInfo(this);
if (userInfo != null) {
etNumber.setText(userInfo.get("number"));
etPassword.setText(userInfo.get("password"));
}
}

private void initView(){
etNumber=(EditText) findViewById(R.id.et_number);
etPassword=(EditText) findViewById(R.id.et_password);
findViewById(R.id.btn_login).setOnClickListener(this);
}

@Override
public void onClick(View v) {
String number=etNumber.getText().toString().trim();
String password=etPassword.getText().toString();
if(TextUtils.isEmpty(number)){
Toast.makeText(this,"请输入账号",Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this,"请输入密码",Toast.LENGTH_SHORT).show();
return;
}
Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
Log.i("MainActivity","记住密码:"+number+","+password);
boolean isSaveSuccess=Net1414080903235Utils.saveUserInfo(this,number,password);
if(isSaveSuccess){
Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(this, "失败", Toast.LENGTH_SHORT).show();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6E6E6"
android:orientation="vertical">

<ImageView
android:id="@+id/iv_head"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/sodoku"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_above="@+id/layout" />

<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
android:layout_above="@+id/btn_login"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="59dp">
<RelativeLayout
android:id="@+id/r1_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="账号"/>
<EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/tv_name"
android:background="@null"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#E6E6E6"/>
<RelativeLayout
android:id="@+id/r1_userpsw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:id="@+id/tv_psw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="密码"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:background="@null"
android:layout_alignTop="@+id/tv_psw"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

</LinearLayout>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3C8DC4"
android:text="登录"
android:textColor="#ffffff"
android:layout_marginBottom="177dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>


11 changes: 11 additions & 0 deletions sh.exe.stackdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Stack trace:
Frame Function Args
00180308010 0018005CE1E (0018022B830, 0018021DC39, 00180308010, 000FFFFB9F0)
00180308010 00180046609 (00000000002, 00000000003, 00000000002, 000C0000000)
00180308010 00180046642 (00000000002, 00180308320, 00180308010, 00000000008)
00180308010 001800574A2 (00000000000, 000FFFFCC35, 000FFFFCC53, 0018021C3F0)
000FFFFCCB0 00180057550 (645C655C725C635C, 695C745C6E5C655C, 6D5C2D5C6C5C615C, 675C615C6E5C615C)
000FFFFCCB0 00180046DD5 (00000000000, 00000000000, 00000000000, 00000000000)
00000000000 00180045873 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0 00180045924 (00000000000, 00000000000, 00000000000, 00000000000)
End of stack trace

0 comments on commit 5ac4ec7

Please sign in to comment.