package com.brink.main; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; import android.widget.ImageButton; import android.widget.Toast; public class RegisterPage extends Activity { EditText emailForm1; EditText emailForm2; EditText passwordForm1; EditText passwordForm2; ImageButton registerSubmit; ImageButton registerCancel; Boolean emailsCorrect, passwordsCorrect; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Set the content view for the user to fill out forms. setContentView(R.layout.registerpage); //Get a handle on all the difference views. emailForm1 = (EditText) findViewById(R.id.emailForm1); emailForm2 = (EditText) findViewById(R.id.emailForm2); passwordForm1 = (EditText) findViewById(R.id.passwordForm1); passwordForm2 = (EditText) findViewById(R.id.passwordForm2); registerSubmit = (ImageButton) findViewById(R.id.registerPageSubmit); registerCancel = (ImageButton) findViewById(R.id.registerPageCancel); emailForm1.setText(""); passwordForm1.setText(""); registerSubmit.setOnClickListener(new OnClickListener() { public void onClick(View v) { //Check the fields on the app to make sure they are filled out correctly if(emailForm1.getText().toString().equals(emailForm2.getText().toString())) { //Make the Error TextBox Invisible emailsCorrect = true; } else { //If emails are incorrect, have a text field existent under the description of the boxes that will //only show up if the emails dont match up. emailsCorrect = false; } if(passwordForm1.getText().toString().equals(passwordForm2.getText().toString())) { //Make the password Error TextBox invisible. passwordsCorrect = true; } else { passwordsCorrect = false; } if(emailsCorrect == false || passwordsCorrect == false) { //Toast a message telling the user to check the fields. Toast.makeText(RegisterPage.this, "Please Check All Fields" , Toast.LENGTH_LONG).show(); } if(emailsCorrect == true && passwordsCorrect == true) { Stored.UserInformation.setUsersEmail(emailForm1.getText().toString()); Stored.UserInformation.setUsersPassword(passwordForm1.getText().toString()); if(Stored.UserInformation.retrieveUsersEmail() != "" && Stored.UserInformation.retrieveUsersPassword() != "") { //Launch Async task for create user. CreateNewUserTask submitCreate = new CreateNewUserTask(); submitCreate.execute(true); } } //finish the activity finish(); } }); registerCancel.setOnClickListener(new OnClickListener() { public void onClick(View v) { Log.w("User is Cancelling the Register User Request", "Closing RegisterPage.java Activity"); finish(); } }); } public void onStart() { super.onStart(); } public void onPause() { super.onPause(); finish(); } private class CreateNewUserTask extends AsyncTask<Boolean, Void , Boolean> { Boolean emailDoesExist = false; @Override protected Boolean doInBackground(Boolean... arg0) { if(OutgoingAPI.doesEmailExist(Stored.UserInformation.retrieveUsersEmail())) { emailDoesExist = true; return false; } else { return OutgoingAPI.createUser(true); } } @Override protected void onPostExecute(Boolean result) { if(result) { //User has been created successfully make a dialog Log.w("User has been created Successfully", "CreateNewUserTask.onPostExecute"); startActivity(new Intent("com.brink.HomePage")); } else { if(emailDoesExist) { //Email exists, show a dialog that shows this. Log.w("OutgoingAPI.doesEmailExist returned a 'true'", "CreateNewUserTask.onPostExecute"); } else { //There was a problem creating the user. Log.w("OutgoingAPI.createUser had a problem creating", "CreateNewUserTask.onPostExecute"); } } } } }