Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. package com.gokdemir.areyousafe;
  2.  
  3. import android.app.AlertDialog;
  4. import android.app.ProgressDialog;
  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.ArrayAdapter;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.Spinner;
  15. import android.widget.TextView;
  16. import android.widget.Toast;
  17.  
  18. import com.android.volley.Request;
  19. import com.android.volley.RequestQueue;
  20. import com.android.volley.Response;
  21. import com.android.volley.VolleyError;
  22. import com.android.volley.toolbox.StringRequest;
  23. import com.android.volley.toolbox.Volley;
  24.  
  25. import java.util.Arrays;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Map;
  29. import org.xmlpull.v1.XmlPullParser;
  30. import org.xmlpull.v1.XmlPullParserException;
  31. import org.xmlpull.v1.XmlPullParserFactory;
  32.  
  33. public class SignupActivity extends AppCompatActivity {
  34.  
  35. private EditText editTextEmail, editTextPassword,editTextName;
  36.  
  37. private Button buttonGoToStep2;
  38.  
  39. private boolean emailVerification, nameVerification, passwordVerification;
  40.  
  41. @Override
  42. protected void onCreate(Bundle savedInstanceState) {
  43. super.onCreate(savedInstanceState);
  44. setContentView(R.layout.activity_signup);
  45.  
  46. initializeActivityElements();
  47.  
  48.  
  49. buttonGoToStep2.setOnClickListener(new View.OnClickListener() {
  50. @Override
  51. public void onClick(View v) {
  52.  
  53. isFirstStepVerified();
  54.  
  55. }
  56. });
  57.  
  58. }
  59.  
  60. private void isFirstStepVerified() {
  61. boolean isVerified = verifyFirstStepComponents();
  62.  
  63. if(isVerified) {
  64. Intent intent = new Intent(SignupActivity.this, SignupActivity2.class);
  65. intent.putExtra("name", editTextName.getText().toString());
  66. intent.putExtra("email", editTextEmail.getText().toString());
  67. intent.putExtra("password", editTextPassword.getText().toString());
  68. startActivity(intent);
  69. }
  70. }
  71.  
  72. private void initializeActivityElements() {
  73. buttonGoToStep2 = (Button) findViewById(R.id.buttonGoToStep2);
  74.  
  75. editTextName = (EditText) findViewById(R.id.etName);
  76. editTextEmail = (EditText) findViewById(R.id.etEmail);
  77. editTextPassword = (EditText) findViewById(R.id.etPassword);
  78. }
  79.  
  80. public boolean verifyFirstStepComponents(){
  81.  
  82. verifyEmail();
  83.  
  84. verifyPassword();
  85.  
  86. verifyName();
  87.  
  88. return (emailVerification && passwordVerification && nameVerification);
  89.  
  90. }
  91.  
  92. private void verifyName() {
  93. if(!nameVerification){
  94. if(editTextName.getText().toString().trim().length() == 0){
  95. Toast.makeText(SignupActivity.this, "Please provide a name for yourself!", Toast.LENGTH_SHORT).show();
  96. }
  97. else nameVerification = true;
  98. }
  99. }
  100.  
  101. private void verifyPassword() {
  102. if(!passwordVerification) {
  103. if (editTextPassword.getText().toString().trim().length() < 10){
  104. Toast.makeText(SignupActivity.this, "Your password is too short!", Toast.LENGTH_SHORT).show();
  105. }
  106. else passwordVerification = true;
  107. }
  108. }
  109.  
  110. private void verifyEmail() {
  111. if(!emailVerification) {
  112. String email = editTextEmail.getText().toString().trim();
  113. String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
  114.  
  115. if (!email.matches(emailPattern)) Toast.makeText(SignupActivity.this, "Email information is invalid", Toast.LENGTH_SHORT).show();
  116. else emailVerification = true;
  117.  
  118. }
  119. }
  120.  
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement