@ -0,0 +1,204 @@
|
||||
package com.example.PersonalCenter.Login_Register;
|
||||
|
||||
import android.media.Image;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.dd.CircularProgressButton;
|
||||
import com.example.Util.ConditionCode;
|
||||
import com.example.Util.RequestBody.user;
|
||||
import com.example.Util.ReturnData;
|
||||
import com.example.Util.ToolTip;
|
||||
import com.example.Util.User;
|
||||
import com.example.Util.cmkgWebServicePost;
|
||||
import com.example.Util.publicStringUtil;
|
||||
import com.example.cmknowledgegraph.R;
|
||||
import com.hanks.library.AnimateCheckBox;
|
||||
import com.itheima.wheelpicker.WheelPicker;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
private EditText phonenumberRegister;
|
||||
private EditText usernameRegister;
|
||||
private EditText passwordRegister;
|
||||
private TextView RegisterButton;
|
||||
private ImageView boycheckimg;
|
||||
private ImageView girlcheckimg;
|
||||
private AnimateCheckBox boycheck;
|
||||
private AnimateCheckBox girlcheck;
|
||||
private WheelPicker wheelPicker;
|
||||
|
||||
|
||||
|
||||
private final RegisterHandler registerHandler = new RegisterHandler(this);
|
||||
public static class RegisterHandler extends Handler{
|
||||
private final WeakReference<RegisterActivity> weakReference;
|
||||
RegisterHandler(RegisterActivity registerActivity){
|
||||
this.weakReference = new WeakReference<RegisterActivity>(registerActivity);
|
||||
}
|
||||
@Override
|
||||
public void handleMessage(@NonNull Message msg) {
|
||||
super.handleMessage(msg);
|
||||
RegisterActivity registerActivity = (RegisterActivity) weakReference.get();
|
||||
Bundle bundle = msg.getData();
|
||||
|
||||
ReturnData returnData = (ReturnData) bundle.getSerializable("msg");
|
||||
|
||||
if(returnData!=null && returnData.getCode()!=null){
|
||||
int code = returnData.getCode();
|
||||
if(code == ConditionCode.registersucess){
|
||||
try {
|
||||
Thread.sleep(700);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ToolTip.FadeCenter(weakReference.get(),"注册成功!");
|
||||
weakReference.get().finish();
|
||||
}else {
|
||||
ToolTip.FlyTocenter(weakReference.get(),returnData.getMsg());
|
||||
}
|
||||
}else ToolTip.FlyTocenter(weakReference.get(),"服务器出了点小问题");
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.activity_register);
|
||||
initView();
|
||||
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
//获取各个控件
|
||||
RegisterButton = findViewById(R.id.main_btn_register_but);
|
||||
boycheck = findViewById(R.id.boycheck);
|
||||
boycheckimg = findViewById(R.id.boycheckimg);
|
||||
girlcheck = findViewById(R.id.girlcheck);
|
||||
girlcheckimg = findViewById(R.id.girlcheckimg);
|
||||
phonenumberRegister = findViewById(R.id.phonenumber_edit_register);
|
||||
usernameRegister = findViewById(R.id.username_edit_register);
|
||||
passwordRegister = findViewById(R.id.password_edit_register);
|
||||
|
||||
//给控件设置监听器
|
||||
boycheck.setOnClickListener(this);
|
||||
boycheckimg.setOnClickListener(this);
|
||||
girlcheckimg.setOnClickListener(this);
|
||||
girlcheck.setOnClickListener(this);
|
||||
RegisterButton.setOnClickListener(this);
|
||||
List<String> agewhellList = new ArrayList<String>();
|
||||
for(int i=0;i<120;i++) agewhellList.add(i+"");
|
||||
|
||||
|
||||
|
||||
// wheelPicker.run();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
switch (id){
|
||||
case R.id.boycheck:
|
||||
case R.id.boycheckimg:
|
||||
if(!girlcheck.isChecked()){
|
||||
if(boycheck.isChecked()) boycheck.setChecked(false); else boycheck.setChecked(true);
|
||||
}
|
||||
break;
|
||||
case R.id.girlcheck:
|
||||
case R.id.girlcheckimg:
|
||||
if(!boycheck.isChecked()) {
|
||||
if(girlcheck.isChecked()) girlcheck.setChecked(false); else girlcheck.setChecked(true);
|
||||
}
|
||||
break;
|
||||
case R.id.main_btn_register_but:
|
||||
Log.i("haha","你要注册了");
|
||||
checkInfo();
|
||||
|
||||
}
|
||||
}
|
||||
public void checkInfo(){
|
||||
// 先检查手机号
|
||||
String phonenumber = phonenumberRegister.getText().toString();
|
||||
|
||||
if(phonenumber == null || phonenumber.length()!=11 || !phonenumber.matches("[0-9]+")){
|
||||
ToolTip.FadeCenter(this,"请输入正确的手机号");
|
||||
|
||||
}else{
|
||||
String username = usernameRegister.getText().toString();
|
||||
if(username == null){
|
||||
ToolTip.FadeCenter(this,"请输入用户名");
|
||||
}else if(username.length()>14) ToolTip.FadeCenter(this,"用户名过长");
|
||||
else {
|
||||
String password = passwordRegister.getText().toString();
|
||||
if(password == null){
|
||||
ToolTip.FadeCenter(this,"请输入密码");
|
||||
}else if(password.length()<6) ToolTip.FadeCenter(this, "密码至少为6位");
|
||||
else if(password.length()>14) ToolTip.FadeCenter(this," 密码最多14位");
|
||||
else {
|
||||
if(boycheck.isChecked()){
|
||||
user user = new user(phonenumber,username,password,0,0,"");
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Message m = new Message();
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
ReturnData returnData = cmkgWebServicePost.execuHttpPost(user.toString(), publicStringUtil.registerURL);
|
||||
Log.i("returndata",""+returnData);
|
||||
bundle.putSerializable("msg", returnData);
|
||||
m.setData(bundle);
|
||||
registerHandler.sendMessage(m);
|
||||
|
||||
}
|
||||
}).start();
|
||||
}else if(girlcheck.isChecked()){
|
||||
String args = "phonenumber="+phonenumber+"&username="+username+"&password="+password
|
||||
+"®ion="+""+"&age=0"+"&sex=0";
|
||||
cmkgWebServicePost.execuHttpPost(args, publicStringUtil.registerURL);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Message message = new Message();
|
||||
Bundle bundle = new Bundle();
|
||||
ReturnData returnData = cmkgWebServicePost.execuHttpPost(args,publicStringUtil.registerURL);
|
||||
bundle.putSerializable("msg", returnData);
|
||||
message.setData(bundle);
|
||||
registerHandler.sendMessage(message);
|
||||
}
|
||||
}).start();
|
||||
}else{
|
||||
ToolTip.FadeCenter(this,"请选择性别");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.example.Util.RequestBody;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class user {
|
||||
protected user(){}
|
||||
private String phonenumber;
|
||||
private String username;
|
||||
private String password;
|
||||
private Integer age;
|
||||
private Integer sex;
|
||||
private String region;
|
||||
|
||||
public user(String phonenumber, String username, String password, Integer age, Integer sex, String region) {
|
||||
this.phonenumber = phonenumber;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.age = age;
|
||||
this.sex = sex;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String getPhonenumber() {
|
||||
return phonenumber;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public Integer getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("phonenumber",phonenumber);
|
||||
jsonObject.put("username",username);
|
||||
jsonObject.put("password",password);
|
||||
jsonObject.put("sex",sex);
|
||||
jsonObject.put("age",age);
|
||||
jsonObject.put("region",region);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setPhonenumber(String phonenumber) {
|
||||
this.phonenumber = phonenumber;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public void setSex(Integer sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.example.Util;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.example.cmknowledgegraph.R;
|
||||
import com.github.johnpersano.supertoasts.library.Style;
|
||||
import com.github.johnpersano.supertoasts.library.SuperActivityToast;
|
||||
import com.github.johnpersano.supertoasts.library.utils.PaletteUtils;
|
||||
|
||||
/*
|
||||
*
|
||||
* 用于发出提示框
|
||||
* */
|
||||
public class ToolTip {
|
||||
|
||||
public static void FadeCenter(Context context,String info){
|
||||
SuperActivityToast.create(context, new Style(), Style.TYPE_STANDARD)
|
||||
.setButtonText("UNDO")
|
||||
.setButtonIconResource(R.drawable.back)
|
||||
.setProgressBarColor(Color.WHITE)
|
||||
.setText(info)
|
||||
.setDuration(Style.DURATION_LONG)
|
||||
.setFrame(Style.FRAME_KITKAT)
|
||||
.setColor(PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_RED))
|
||||
.setAnimations(Style.ANIMATIONS_SCALE).show();
|
||||
}
|
||||
public static void FlyTocenter(Context context, String info){
|
||||
SuperActivityToast.create(context, new Style(), Style.TYPE_STANDARD)
|
||||
.setButtonText("UNDO")
|
||||
.setButtonIconResource(R.drawable.back)
|
||||
.setProgressBarColor(Color.WHITE)
|
||||
.setText(info)
|
||||
.setDuration(Style.DURATION_MEDIUM)
|
||||
.setFrame(Style.FRAME_KITKAT)
|
||||
.setColor(PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_BROWN))
|
||||
.setAnimations(Style.ANIMATIONS_FLY).show();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.example.Util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class cmkgWebServicePost {
|
||||
public static ReturnData execuHttpPost(String args,String address){
|
||||
HttpURLConnection connection = null;
|
||||
InputStream in = null;
|
||||
String path = publicStringUtil.cmkgTomcatURL+address;
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(path);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setReadTimeout(8000);
|
||||
connection.setUseCaches(false);
|
||||
connection.setRequestProperty("Content-Type","raw");
|
||||
connection.connect();
|
||||
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
|
||||
// String data = URLEncoder.encode(args, "UTF-8");
|
||||
Log.i("data",""+args);
|
||||
// "username="+ URLEncoder.encode(username,"UTF-8")+"&phonenumber="+URLEncoder.encode(phonenumber,"UTF-8")+"&password="+URLEncoder.encode(password,"UTF-8");
|
||||
out.writeBytes(args);
|
||||
out.flush();
|
||||
out.close();
|
||||
// int resultCode = connection.getResponseCode();
|
||||
// Log.i("HTTP",resultCode+"");
|
||||
// if(HttpURLConnection.HTTP_OK == resultCode){
|
||||
in = connection.getInputStream();
|
||||
|
||||
return parseInfo(in);
|
||||
// }
|
||||
// return null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(connection != null){
|
||||
connection.disconnect();
|
||||
}
|
||||
if(in != null){
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static ReturnData parseInfo(InputStream inputStream){
|
||||
BufferedReader reader = null;
|
||||
String line = "";
|
||||
StringBuilder response = new StringBuilder();
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
try {
|
||||
while((line = reader.readLine())!=null){
|
||||
Log.d("RegisterActivity",line);
|
||||
response.append(line);
|
||||
}
|
||||
Log.d("RegisterActivity","response.toSring:"+response.toString());
|
||||
|
||||
JSONObject jsonObject = null;
|
||||
ReturnData returnData = null;
|
||||
try {
|
||||
jsonObject = new JSONObject(response.toString());
|
||||
int code = jsonObject.getInt("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
String data = jsonObject.getString("data");
|
||||
returnData = new ReturnData(code,msg,data);
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return returnData;
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(reader != null){
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 401 B |
After Width: | Height: | Size: 353 B |
After Width: | Height: | Size: 821 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.7 KiB |
@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--这个是登录或者注册的编辑区-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="20dip"
|
||||
android:background="@drawable/radius_drawable_bg"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dip" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/phonenumber_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_call_filled" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/phonenumber_edit_register"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:background="#00000000"
|
||||
android:hint="请输入手机号"
|
||||
android:textColor="@color/cyan"
|
||||
android:padding="5dip"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10px"
|
||||
android:layout_marginBottom="5dip"
|
||||
android:layout_marginTop="5dip"
|
||||
android:background="#eeeeee" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/username_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_profile" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/username_edit_register"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:background="#00000000"
|
||||
android:hint="请输入用户名"
|
||||
android:padding="5dip"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/cyan"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10px"
|
||||
android:layout_marginBottom="5dip"
|
||||
android:layout_marginTop="5dip"
|
||||
android:background="#eeeeee" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/password_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_lockopen" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password_edit_register"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:background="#00000000"
|
||||
android:hint="密码"
|
||||
android:inputType="textPassword"
|
||||
android:padding="5dip"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/cyan"/>
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10px"
|
||||
android:layout_marginBottom="5dip"
|
||||
android:layout_marginTop="5dip"
|
||||
android:background="#eeeeee" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -1,3 +1,4 @@
|
||||
<resources>
|
||||
<!-- <string name="app_name">CMKnowledgeGraph</string>-->
|
||||
<!-- <string name="Sign"-->
|
||||
</resources>
|
||||
|