|
|
|
@ -2,45 +2,145 @@ package com.example.myapplication;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.AppComponentFactory;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
import android.widget.RadioGroup;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
public class RigsterActivity extends Activity {
|
|
|
|
|
import com.lljjcoder.citypickerview.widget.CityPicker;
|
|
|
|
|
|
|
|
|
|
public class RigsterActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
|
|
|
|
|
private EditText usernameEdit,passEdit,surePasswordEdit;
|
|
|
|
|
private TextView cityText;
|
|
|
|
|
private CityPicker cityPicker;
|
|
|
|
|
private Button regButton;
|
|
|
|
|
private RadioGroup sexGroup;
|
|
|
|
|
private String sexStr = "男";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.user_rigster);
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void init(){
|
|
|
|
|
cityText = findViewById(R.id.ri_province);
|
|
|
|
|
cityText.setOnClickListener(this);
|
|
|
|
|
usernameEdit = findViewById(R.id.rig_username);
|
|
|
|
|
passEdit = findViewById(R.id.rig_password);
|
|
|
|
|
surePasswordEdit = findViewById(R.id.re_password);
|
|
|
|
|
regButton = findViewById(R.id.re_register);
|
|
|
|
|
regButton.setOnClickListener(this);
|
|
|
|
|
sexGroup = findViewById(R.id.sex);
|
|
|
|
|
sexGroup.setOnCheckedChangeListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
switch(v.getId()){
|
|
|
|
|
case R.id.ri_province:
|
|
|
|
|
initCityPicker();
|
|
|
|
|
cityPicker.show();
|
|
|
|
|
break;
|
|
|
|
|
case R.id.re_register:
|
|
|
|
|
//注册验证方法
|
|
|
|
|
validateRegister();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// //界面组件初始化
|
|
|
|
|
// private void init(){
|
|
|
|
|
// cityText = findViewById(R.id.ri_province);
|
|
|
|
|
// cityText.setOnClickListener(this);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onClick(View v) {
|
|
|
|
|
// switch(v.getId()){
|
|
|
|
|
// case R.id.ri_province:
|
|
|
|
|
// initCityPicker();
|
|
|
|
|
// cityPicker.show();
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //初始化城市选择器
|
|
|
|
|
// private void initCityPicker() {
|
|
|
|
|
// cityPicker = new CityPicker.Builder(RigsterActivity.this)
|
|
|
|
|
// .textSize(16)
|
|
|
|
|
// .title("地址选择")
|
|
|
|
|
// .backgroundPop(0xa0000000)
|
|
|
|
|
// .title
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//初始化城市选择爱
|
|
|
|
|
//初始化城市选择器
|
|
|
|
|
private void initCityPicker() {
|
|
|
|
|
cityPicker = new CityPicker.Builder(RigsterActivity.this)
|
|
|
|
|
.textSize(16)
|
|
|
|
|
.title("地址选择")
|
|
|
|
|
.backgroundPop(0xa0000000)
|
|
|
|
|
.titleBackgroundColor("#EfB81c")
|
|
|
|
|
.titleTextColor("#000000")
|
|
|
|
|
.backgroundPop(0xa0000000)
|
|
|
|
|
.confirTextColor("#000000")
|
|
|
|
|
.cancelTextColor("#000000")
|
|
|
|
|
.province("湖南省")
|
|
|
|
|
.city("长沙市")
|
|
|
|
|
.district("雨花区")
|
|
|
|
|
.textColor(Color.parseColor("#000000"))
|
|
|
|
|
.provinceCyclic(true)
|
|
|
|
|
.cityCyclic(false)
|
|
|
|
|
.districtCyclic(false)
|
|
|
|
|
.visibleItemsCount(7)
|
|
|
|
|
.itemPadding(10)
|
|
|
|
|
.onlyShowProvinceAndCity(false).build();
|
|
|
|
|
cityPicker.setOnCityItemClickListener(new CityPicker.OnCityItemClickListener(){
|
|
|
|
|
@Override
|
|
|
|
|
public void onSelected(String...strings){
|
|
|
|
|
String province = strings[0];
|
|
|
|
|
String city = strings[1];
|
|
|
|
|
String district = strings[2];
|
|
|
|
|
cityText.setText(String.format("%s %s %s",province,city,district));
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void onCancel() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//注册验证
|
|
|
|
|
public void validateRegister(){
|
|
|
|
|
Intent intent = new Intent(RigsterActivity.this,LoginActivity.class);
|
|
|
|
|
String username = usernameEdit.getText().toString();
|
|
|
|
|
String password = passEdit.getText().toString();
|
|
|
|
|
String surePassword = surePasswordEdit.getText().toString();
|
|
|
|
|
String city = cityText.getText().toString();
|
|
|
|
|
//判断两次密码是否一致
|
|
|
|
|
if(password.equals(surePassword)){
|
|
|
|
|
if(!username.equals("") || !password.equals("")) {
|
|
|
|
|
if (!city.equals("")) {
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
|
bundle.putString("username", username);
|
|
|
|
|
bundle.putString("password", password);
|
|
|
|
|
bundle.putString("sex", sexStr);
|
|
|
|
|
bundle.putString("city", city);
|
|
|
|
|
intent.putExtras(bundle);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(RigsterActivity.this, "请选择地址",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
Toast.makeText(RigsterActivity.this,"账号或密码未填写",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
Toast.makeText(RigsterActivity.this,"两次密码输入不一致",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
Toast.makeText(RigsterActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(RadioGroup group,int checkedId){
|
|
|
|
|
// 根据用户的选择来改变性别
|
|
|
|
|
sexStr = checkedId == R.id.rig_man?"男":"女";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|