Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gokdemir.areyousafe;
- import android.app.AlertDialog;
- import android.app.ProgressDialog;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Spinner;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.android.volley.Request;
- import com.android.volley.RequestQueue;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.toolbox.StringRequest;
- import com.android.volley.toolbox.Volley;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.xmlpull.v1.XmlPullParser;
- import org.xmlpull.v1.XmlPullParserException;
- import org.xmlpull.v1.XmlPullParserFactory;
- public class SignupActivity extends AppCompatActivity {
- private EditText editTextEmail, editTextPassword,editTextName;
- private Button buttonGoToStep2;
- private boolean emailVerification, nameVerification, passwordVerification;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_signup);
- initializeActivityElements();
- buttonGoToStep2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- isFirstStepVerified();
- }
- });
- }
- private void isFirstStepVerified() {
- boolean isVerified = verifyFirstStepComponents();
- if(isVerified) {
- Intent intent = new Intent(SignupActivity.this, SignupActivity2.class);
- intent.putExtra("name", editTextName.getText().toString());
- intent.putExtra("email", editTextEmail.getText().toString());
- intent.putExtra("password", editTextPassword.getText().toString());
- startActivity(intent);
- }
- }
- private void initializeActivityElements() {
- buttonGoToStep2 = (Button) findViewById(R.id.buttonGoToStep2);
- editTextName = (EditText) findViewById(R.id.etName);
- editTextEmail = (EditText) findViewById(R.id.etEmail);
- editTextPassword = (EditText) findViewById(R.id.etPassword);
- }
- public boolean verifyFirstStepComponents(){
- verifyEmail();
- verifyPassword();
- verifyName();
- return (emailVerification && passwordVerification && nameVerification);
- }
- private void verifyName() {
- if(!nameVerification){
- if(editTextName.getText().toString().trim().length() == 0){
- Toast.makeText(SignupActivity.this, "Please provide a name for yourself!", Toast.LENGTH_SHORT).show();
- }
- else nameVerification = true;
- }
- }
- private void verifyPassword() {
- if(!passwordVerification) {
- if (editTextPassword.getText().toString().trim().length() < 10){
- Toast.makeText(SignupActivity.this, "Your password is too short!", Toast.LENGTH_SHORT).show();
- }
- else passwordVerification = true;
- }
- }
- private void verifyEmail() {
- if(!emailVerification) {
- String email = editTextEmail.getText().toString().trim();
- String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
- if (!email.matches(emailPattern)) Toast.makeText(SignupActivity.this, "Email information is invalid", Toast.LENGTH_SHORT).show();
- else emailVerification = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement