Initial commit
This commit is contained in:
parent
61373eeef4
commit
6f2b709a1f
@ -22,7 +22,7 @@ import com.youxuegu.utils.UtilsHelper;
|
|||||||
public class RegisterActivity extends AppCompatActivity {
|
public class RegisterActivity extends AppCompatActivity {
|
||||||
|
|
||||||
//标题栏与返回按钮
|
//标题栏与返回按钮
|
||||||
private TextView tv_mian_title, tv_back;
|
private TextView tv_main_title, tv_back;
|
||||||
//标题栏布局
|
//标题栏布局
|
||||||
private RelativeLayout rl_title_bar;
|
private RelativeLayout rl_title_bar;
|
||||||
//注册按钮
|
//注册按钮
|
||||||
@ -35,32 +35,33 @@ public class RegisterActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_register);
|
setContentView(R.layout.activity_register);
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
tv_mian_title = findViewById(R.id.tv_main_title);
|
tv_main_title = findViewById(R.id.tv_main_title);
|
||||||
tv_mian_title.setText("注册");
|
//设置注册界面标题为“注册”
|
||||||
|
tv_main_title.setText("注册");
|
||||||
tv_back = findViewById(R.id.tv_back);
|
tv_back = findViewById(R.id.tv_back);
|
||||||
rl_title_bar = findViewById(R.id.title_bar);
|
rl_title_bar = findViewById(R.id.title_bar);
|
||||||
//设置标题栏的背景颜色为透明
|
//设置标题栏背景颜色为透明
|
||||||
rl_title_bar.setBackgroundColor(Color.TRANSPARENT);
|
rl_title_bar.setBackgroundColor(Color.TRANSPARENT);
|
||||||
btn_register = findViewById(R.id.btn_register);
|
btn_register = findViewById(R.id.btn_register);
|
||||||
et_user_name = findViewById(R.id.et_user_name);
|
et_user_name = findViewById(R.id.et_user_name);
|
||||||
et_psw = findViewById(R.id.et_psw);
|
et_psw = findViewById(R.id.et_psw);
|
||||||
et_psw_again = findViewById(R.id.et_psw_again);
|
et_psw_again = findViewById(R.id.et_psw_again);
|
||||||
|
//“返回”按钮的点击事件
|
||||||
//返回按钮的点击事件
|
|
||||||
tv_back.setOnClickListener(new View.OnClickListener() {
|
tv_back.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View v) {
|
||||||
RegisterActivity.this.finish();
|
RegisterActivity.this.finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//注册按钮的点击事件
|
//“注册”按钮的点击事件
|
||||||
btn_register.setOnClickListener(new View.OnClickListener() {
|
btn_register.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View v) {
|
||||||
getEditString();
|
getEditString();//获取界面控件中输入的注册信息
|
||||||
if (TextUtils.isEmpty(userName)) {
|
if (TextUtils.isEmpty(userName)) {
|
||||||
Toast.makeText(RegisterActivity.this, "请输入用户名", Toast.LENGTH_SHORT).show();
|
Toast.makeText(RegisterActivity.this, "请输入用户名", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
@ -70,21 +71,18 @@ public class RegisterActivity extends AppCompatActivity {
|
|||||||
} else if (TextUtils.isEmpty(pswAgain)) {
|
} else if (TextUtils.isEmpty(pswAgain)) {
|
||||||
Toast.makeText(RegisterActivity.this, "请再次输入密码", Toast.LENGTH_SHORT).show();
|
Toast.makeText(RegisterActivity.this, "请再次输入密码", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}else if (psw.equals(pswAgain)) {
|
} else if (!psw.equals(pswAgain)) {
|
||||||
Toast.makeText(RegisterActivity.this, "输入两次密码不一致", Toast.LENGTH_SHORT).show();
|
Toast.makeText(RegisterActivity.this, "输入两次的密码不一致", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}else if (psw.equals(pswAgain)) {
|
} else if (UtilsHelper.isExistUserName(RegisterActivity.this, userName)) {
|
||||||
Toast.makeText(RegisterActivity.this, "输入两次密码不一致", Toast.LENGTH_SHORT).show();
|
Toast.makeText(RegisterActivity.this, "此用户名已经存在", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}else if (UtilsHelper.isExistUserName(RegisterActivity.this,userName)) {
|
} else {
|
||||||
Toast.makeText(RegisterActivity.this, "此用户名已存在", Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}else {
|
|
||||||
Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
|
Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
|
||||||
//把用户名和密码保存到SharedPreferences文件中
|
//把用户名和密码保存到SharedPreferences文件中
|
||||||
UtilsHelper.saveUserInfo(RegisterActivity.this, userName, psw);
|
UtilsHelper.saveUserInfo(RegisterActivity.this, userName, psw);
|
||||||
//注册成功后把用户名传递到LoginActivity中
|
//注册成功后把用户名传递到LoginActivity中
|
||||||
Intent data =new Intent();
|
Intent data = new Intent();
|
||||||
data.putExtra("userName", userName);
|
data.putExtra("userName", userName);
|
||||||
setResult(RESULT_OK, data);
|
setResult(RESULT_OK, data);
|
||||||
RegisterActivity.this.finish();
|
RegisterActivity.this.finish();
|
||||||
@ -99,10 +97,9 @@ public class RegisterActivity extends AppCompatActivity {
|
|||||||
private void getEditString() {
|
private void getEditString() {
|
||||||
//获取注册界面中输入的用户名信息
|
//获取注册界面中输入的用户名信息
|
||||||
userName = et_user_name.getText().toString().trim();
|
userName = et_user_name.getText().toString().trim();
|
||||||
//获取注册界面中输入的密码信息
|
//获取注册界面输入的密码信息
|
||||||
psw = et_psw.getText().toString().trim();
|
psw = et_psw.getText().toString().trim();
|
||||||
//获取注册界面中输入的二次密码信息
|
//获取注册界面输入的再次输入密码信息
|
||||||
pswAgain = et_psw_again.getText().toString().trim();
|
pswAgain = et_psw_again.getText().toString().trim();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -10,16 +10,12 @@ import android.text.TextUtils;
|
|||||||
public class UtilsHelper {
|
public class UtilsHelper {
|
||||||
/**
|
/**
|
||||||
* 判断SharedPreferences文件中是否存在要保存的用户名
|
* 判断SharedPreferences文件中是否存在要保存的用户名
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @param userName
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static boolean isExistUserName(Context context, String userName) {
|
public static boolean isExistUserName(Context context, String userName) {
|
||||||
boolean has_userName = false;
|
boolean has_userName = false;
|
||||||
SharedPreferences sp = context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
|
SharedPreferences sp = context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
|
||||||
String spPsw = sp.getString(userName, "");
|
String spPsw = sp.getString(userName, "");
|
||||||
if (TextUtils.isEmpty(spPsw)) {
|
if (!TextUtils.isEmpty(spPsw)) {
|
||||||
has_userName = true;
|
has_userName = true;
|
||||||
}
|
}
|
||||||
return has_userName;
|
return has_userName;
|
||||||
@ -34,7 +30,6 @@ public class UtilsHelper {
|
|||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
//将用户名和密码封装到编辑器对象editor中
|
//将用户名和密码封装到编辑器对象editor中
|
||||||
editor.putString(userName, md5Psw);
|
editor.putString(userName, md5Psw);
|
||||||
//提交保存信息
|
editor.commit();//提交保存信息
|
||||||
editor.commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user