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