-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignUp.java
108 lines (97 loc) · 4.91 KB
/
SignUp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.example.fda;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Patterns;
import com.google.android.material.textfield.TextInputEditText;
public class SignUp extends AppCompatActivity {
TextInputEditText textInputEditTextFullname,
textInputEditTextUsername,
textInputEditTextPassword,
textInputEditTextEmail;
Button buttonSignUp;
TextView textViewLogin;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
textInputEditTextFullname = findViewById(R.id.fullname);
textInputEditTextUsername = findViewById(R.id.username);
textInputEditTextPassword = findViewById(R.id.password);
textInputEditTextEmail = findViewById(R.id.email);
buttonSignUp = findViewById(R.id.buttonSignUp);
textViewLogin = findViewById(R.id.loginText);
progressBar = findViewById(R.id.progress);
textViewLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Login.class);
startActivity(intent);
finish();
}
});
buttonSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String fullname, username, password, email;
fullname = String.valueOf(textInputEditTextFullname.getText());
username = String.valueOf(textInputEditTextUsername.getText());
password = String.valueOf(textInputEditTextPassword.getText());
email = String.valueOf(textInputEditTextEmail.getText());
if (!fullname.equals("") && !username.equals("") &&
!password.equals("") && !email.equals("")) {
//Start ProgressBar first (Set visibility VISIBLE)
progressBar.setVisibility(View.VISIBLE);
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
String[] field = new String[4];
field[0] = "fullname";
field[1] = "username";
field[2] = "password";
field[3] = "email";
//Creating array for data
String[] data = new String[4];
data[0] = fullname;
data[1] = username;
data[2] = password;
data[3] = email;
if (!email.isEmpty() && Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
PutData putData = new PutData("http://192.168.0.109:80/LoginRegister/signup.php", "POST", field, data);
if (putData.startPut()) {
if (putData.onComplete()) {
progressBar.setVisibility(View.GONE);
String result = putData.getResult();
if (result.equals("Sign Up Success")) {
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), Login.class);
startActivity(intent);
finish();
} else {
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
}
}
}
} else {
progressBar.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(), "Enter valid Email address !", Toast.LENGTH_SHORT).show();
}
}
});
}
else{
Toast.makeText(getApplicationContext(),"All Fields are required",Toast.LENGTH_SHORT).show();
}
}
});
}
}