package com.example.loginapp1; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import com.google.android.material.textfield.TextInputEditText; import com.vishnusivadas.advanced_httpurlconnection.PutData; 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){ final 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() { //Starting Write and Read data with URL //Creating array for parameters 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; // URL allow to insert data to the php file then to the DB in phpmyadmin. PutData putData = new PutData("https://ysjcs.net/~daniel.tang/signup.php", "POST", field, data); if (putData.startPut()) { if (putData.onComplete()) { String result = putData.getResult(); //End ProgressBar (Set visibility to GONE) progressBar.setVisibility(View.GONE); if(result.equals("Sign Up Success")){ Toast.makeText(getApplicationContext(), result,Toast.LENGTH_LONG).show(); Intent intent = new Intent(getApplicationContext(), Login.class); startActivity(intent); finish(); } else { Toast.makeText(getApplicationContext(), result,Toast.LENGTH_LONG).show(); } Log.i("PutData", result); } } //End Write and Read data with URL } }); } else { Toast.makeText(getApplicationContext(), "All fields are required", Toast.LENGTH_SHORT).show(); } } }); } }