Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | None | 0 0
  1. package com.yardbird.justice.yardbird;
  2.  
  3.  
  4. import android.app.AlertDialog;
  5. import android.content.DialogInterface;
  6. import android.content.Intent;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.ImageButton;
  14. import android.widget.Toast;
  15.  
  16. import com.kosalgeek.genasync12.AsyncResponse;
  17. import com.kosalgeek.genasync12.PostResponseAsyncTask;
  18.  
  19. import java.util.HashMap;
  20.  
  21. public class SignUpActivity extends AppCompatActivity {
  22. public EditText firstname, lastname, uN, pW, emailAddress, phoneNum;
  23. String LOG = "SignUpActivity";
  24.  
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_signup);
  29. firstname = (EditText) findViewById(R.id.firstname);
  30. lastname = (EditText) findViewById(R.id.lastname);
  31. uN = (EditText) findViewById(R.id.username);
  32. pW = (EditText) findViewById(R.id.password);
  33. emailAddress = (EditText) findViewById(R.id.email);
  34. phoneNum = (EditText) findViewById(R.id.mobilePhone);
  35. OnButtonClick();
  36. }
  37.  
  38. public void OnButtonClick() {
  39. Button Return = (Button) findViewById(R.id.loginReturn);
  40. Button createAccountBtn = (Button) findViewById(R.id.createAccountButton);
  41. final ImageButton username = (ImageButton) findViewById(R.id.usernameHelpButton);
  42. ImageButton password = (ImageButton) findViewById(R.id.passwordHelpButton);
  43.  
  44. //Upon being pressed, user is taken back to the login page
  45. Return.setOnClickListener(new View.OnClickListener() {
  46. @Override
  47. public void onClick(View v) {
  48. startActivity(new Intent(getApplicationContext(), LoginActivity.class));
  49. }
  50. });
  51.  
  52. //Shows a dialog box that informs the user to enter an initial username
  53. username.setOnClickListener(new View.OnClickListener() {
  54. @Override
  55. public void onClick(View v) {
  56. AlertDialog.Builder dialog = new AlertDialog.Builder(SignUpActivity.this);
  57. dialog.setMessage("1. Should be 8 characters long")
  58. .setCancelable(false)
  59. .setNegativeButton("Okay", new DialogInterface.OnClickListener() {
  60. public void onClick(DialogInterface dialog, int which) {
  61. dialog.cancel();
  62. }
  63. });
  64. AlertDialog box = dialog.create();
  65. box.setTitle("USERNAME CONDITIONS");
  66. box.show();
  67. }
  68. });
  69.  
  70. //Shows a dialog box that informs the user to enter an initial password
  71. password.setOnClickListener(new View.OnClickListener() {
  72. @Override
  73. public void onClick(View v) {
  74. AlertDialog.Builder dialog = new AlertDialog.Builder(SignUpActivity.this);
  75. dialog.setMessage("1. Should be 8 characters long")
  76. .setCancelable(false)
  77. .setNegativeButton("Okay", new DialogInterface.OnClickListener() {
  78. public void onClick(DialogInterface dialog, int which) {
  79. dialog.cancel();
  80. }
  81. });
  82. AlertDialog box = dialog.create();
  83. box.setTitle("PASSWORD CONDITIONS");
  84. box.show();
  85. }
  86. });
  87.  
  88. createAccountBtn.setOnClickListener(new View.OnClickListener() {
  89. @Override
  90. public void onClick(View v) {
  91. HashMap postData = new HashMap();
  92. postData.put("fName", firstname.getText().toString());
  93. postData.put("lName", lastname.getText().toString());
  94. postData.put("pNumber", phoneNum.getText().toString());
  95. postData.put("username", uN.getText().toString());
  96. postData.put("password", pW.getText().toString());
  97. postData.put("email", emailAddress.getText().toString());
  98. PostResponseAsyncTask taskInsert = new PostResponseAsyncTask(SignUpActivity.this, postData, new AsyncResponse() {
  99. @Override
  100. public void processFinish(String s) {
  101. if (s.contains("success")) {
  102. Log.d(LOG, s);
  103. Toast.makeText(SignUpActivity.this, "Insert Successful", Toast.LENGTH_LONG).show();
  104. Intent intent = new Intent(SignUpActivity.this, LoginActivity.class);
  105. startActivity(intent);
  106. }
  107. //If the username (or password) has under 8 characters, or the phone number length is less than 11, then an error box presents itself
  108. else if (s.contains("failed") || uN.getText().toString().length() < 8 || pW.getText().toString().length() < 8 || phoneNum.getText().toString().length() != 11) {
  109. AlertDialog.Builder dialogBox = new AlertDialog.Builder(SignUpActivity.this);
  110. dialogBox.setMessage("These reasons cause errors..."+"\n1. The username has been taken"+"\n2. The username and/or password are of the wrong length (i.e. under 8 characters)"
  111. + "\n3. The phone number is of the wrong length (i.e under 11 digits)")
  112. .setCancelable(false)
  113. .setNegativeButton("Okay", new DialogInterface.OnClickListener() {
  114. public void onClick(DialogInterface dialog, int which) {
  115. dialog.cancel();//closes the dialog box
  116. }
  117. });
  118. AlertDialog dialog = dialogBox.create();
  119. dialog.setTitle("An Error was Detected!");
  120. dialog.show();
  121. }
  122.  
  123. }
  124. });
  125. taskInsert.execute("http://collectoy.000webhostapp.com/phpfiles/register.php/");
  126. }
  127. });
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement