|
|
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.Message;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
@ -16,8 +17,12 @@ import com.example.logistics.manager.userManager;
|
|
|
|
|
import com.example.logistics.entity.User;
|
|
|
|
|
|
|
|
|
|
public class SignUpUI extends Activity {
|
|
|
|
|
|
|
|
|
|
private String TAG = "SignUpUI";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.activity_sign_up);
|
|
|
|
|
|
|
|
|
@ -28,16 +33,20 @@ public class SignUpUI extends Activity {
|
|
|
|
|
new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
Log.d(TAG, "SignUp:onClick");
|
|
|
|
|
register(v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 返回登录按钮监听器
|
|
|
|
|
backLoginButton.setOnClickListener(
|
|
|
|
|
new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
// 跳转到登录界面
|
|
|
|
|
Log.d(TAG, "BackLogin:onClick");
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(SignUpUI.this, LoginUI.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
@ -47,6 +56,9 @@ public class SignUpUI extends Activity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void register(View view){
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "register");
|
|
|
|
|
|
|
|
|
|
EditText userName = (EditText) this.findViewById(R.id.UserNameEdit);
|
|
|
|
|
EditText passWord = (EditText) this.findViewById(R.id.PassWordEdit);
|
|
|
|
|
EditText passWordAgain = (EditText) this.findViewById(R.id.PassWordAgainEdit);
|
|
|
|
@ -58,16 +70,33 @@ public class SignUpUI extends Activity {
|
|
|
|
|
String strPhoneNumber = phone.getText().toString().trim();
|
|
|
|
|
|
|
|
|
|
if (strUserName.length() > 10) {
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "username out of length");
|
|
|
|
|
Toast.makeText(SignUpUI.this, "用户名长度必须小于10!", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
} else if (strUserName.length() == 0) {
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "username is none");
|
|
|
|
|
Toast.makeText(SignUpUI.this, "用户名不能为空!", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
} else if (strPassWord.length() > 16) {
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "password out of length");
|
|
|
|
|
Toast.makeText(SignUpUI.this, "密码长度必须小于16!", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
} else if (strPassWord.length() == 0) {
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "password is none");
|
|
|
|
|
Toast.makeText(SignUpUI.this, "密码不能为空!", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
} else if (!strPassWord.equals(strPassWordAgain)) {
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "password is not same");
|
|
|
|
|
Toast.makeText(SignUpUI.this, "两次密码输入不一致!", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "register success");
|
|
|
|
|
Toast.makeText(SignUpUI.this, "注册成功!", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
User user = new User();
|
|
|
|
@ -78,17 +107,27 @@ public class SignUpUI extends Activity {
|
|
|
|
|
new Thread(){
|
|
|
|
|
@Override
|
|
|
|
|
public void run(){
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "register thread");
|
|
|
|
|
int msg = 0;
|
|
|
|
|
userManager userManager = new userManager();
|
|
|
|
|
|
|
|
|
|
User uu = userManager.findUser(user.getUserName());
|
|
|
|
|
|
|
|
|
|
if(uu != null){
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "have this account");
|
|
|
|
|
msg = 1; //have this account
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "have no this account");
|
|
|
|
|
boolean flag = userManager.register(user);
|
|
|
|
|
if(flag){
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "register success");
|
|
|
|
|
msg = 2;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hand.sendEmptyMessage(msg);
|
|
|
|
@ -100,14 +139,24 @@ public class SignUpUI extends Activity {
|
|
|
|
|
@SuppressLint("HandlerLeak")
|
|
|
|
|
final Handler hand = new Handler(){
|
|
|
|
|
public void handleMessage(Message msg){
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "msg is:" + msg.toString());
|
|
|
|
|
|
|
|
|
|
if(msg.what == 0){
|
|
|
|
|
|
|
|
|
|
Toast.makeText(getApplicationContext(), "注册失败", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
}else if(msg.what == 1){
|
|
|
|
|
|
|
|
|
|
Toast.makeText(getApplicationContext(), "该账号已存在,请换一个注册", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
}else if(msg.what == 2){
|
|
|
|
|
|
|
|
|
|
Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(SignUpUI.this, LoginUI.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|