Android Open Source - ExpertAndroid Signup Activity






From Project

Back to project page ExpertAndroid.

License

The source code is released under:

MIT License

If you think the Android project ExpertAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.androidbook.parse;
// w  ww. j  a  v  a 2 s  .c o m
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
/*
 * What shoudl happen here?
 * 
 * This is a sign up activity.
 * 
 * 1. enter sign up info
 * 2. validate fields
 * 3. succeed
 * 4. fail
 * 
 * Failure
 * *********
 * 1. validate field level edits
 * 2. if account already exists offer to login/reset password
 * 
 * Success
 * *********
 * 1. Transfer to activity successful sign up
 * 
 */
public class SignupActivity 
extends FormActivity 
{
  ProgressDialog pd;
  private static String tag = "SignupActivity"; 
  
  //Form Fields
  EditText userid;
  EditText password1;
  EditText password2;
  EditText email;
  
  public SignupActivity()
  {
    super(tag);
  }
  
  /** Called when the activity is first created. */
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.signup);
  }
  
  //from form fields
  @Override
  protected void initializeFormFields() 
  {
    this.reportBack("form initialized");
    userid = (EditText)findViewById(R.id.userid);
    password1 = (EditText)findViewById(R.id.password1);
    password2 = (EditText)findViewById(R.id.password2);
    email = (EditText)findViewById(R.id.email);
    
    //Setup the validators
    addValidator(new Field(userid));
    addValidator(new Field(password1));
    addValidator(new Field(password2));
    addValidator(new Field(email));
    addValidator(new PasswordFieldRule(password1,password2));
  }
  
  private boolean validateFields()
  {
    return validateForm();
  }

  private String getUserId()
  {
    return getStringValue(R.id.userid);
  }
  private String getUserEmail()
  {
    return getStringValue(R.id.email);
  }
  private String getPassword1()
  {
    return getStringValue(R.id.password1);
  }
  private String getPassword2()
  {
    return getStringValue(R.id.password2);
  }
  
  private TextView getTextView(int controlId)
  {
    TextView tv = (TextView)findViewById(controlId);
    if (tv == null)
    {
      throw new RuntimeException("Sorry Can't find the control id");
    }
    //view available
    return tv;
  }
  private String getStringValue(int controlId)
  {
    TextView tv = (TextView)findViewById(controlId);
    if (tv == null)
    {
      throw new RuntimeException("Sorry Can't find the control id");
    }
    //view available
    return tv.getText().toString();
  }

  public void signupButtonClick(View v)
  {
    if (validateFields() == false)
    {
      reportTransient("Make sure all fields have valid values");
      return;
    }
    //everything is good
    String userid = getUserId();
    String password = getPassword1();
    String email = getUserEmail();
    reportTransient("Going to sign up now");
    signup(userid, email, password);
  }
  
  private void signup(String userid, String email, String password)
  {
    ParseUser user = new ParseUser();
    user.setUsername(userid);
    user.setPassword(password);
    user.setEmail(email);

    //Show the progress dialog
    turnOnProgressDialog("Signup", "Please wait while we sign you up");
    
    //Go for signup with a callback
    user.signUpInBackground(new SignUpCallback() {
      public void done(ParseException e) {
      turnOffProgressDialog();
        if (e == null) {
          // Hooray! Let them use the app now.
          signupSuccessful();
        } else {
          // Sign up didn't succeed. Look at the ParseException
          // to figure out what went wrong
          signupFailed(e);
        }
      }
    });    
    return;
  }//signup-method
  
  private void signupSuccessful()
  {
    //Go to signup successful page 
    //finish
    gotoActivity(SignupSuccessActivity.class);
    finish();
  }
  private void signupFailed(ParseException x)
  {
    //stay on the page
    //Put an error message for the exception
    String message = x.getMessage();
    alert("Signup", "Failed:" + message);
  }
}//eof-class





Java Source Code List

com.androidbook.notebad.NoteEditor.java
com.androidbook.notebad.NotePadProvider.java
com.androidbook.notebad.NotePad.java
com.androidbook.notebad.NotesList.java
com.androidbook.notebad.TitleEditor.java
com.androidbook.parse.BaseActivity.java
com.androidbook.parse.BaseListActivity.java
com.androidbook.parse.CreateAMeaningActivity.java
com.androidbook.parse.CreateAWordActivity.java
com.androidbook.parse.Field.java
com.androidbook.parse.FormActivity.java
com.androidbook.parse.IReportBack.java
com.androidbook.parse.IValidator.java
com.androidbook.parse.IValueValidator.java
com.androidbook.parse.LoginActivity.java
com.androidbook.parse.ParseApplication.java
com.androidbook.parse.ParseObjectWrapperOld1.java
com.androidbook.parse.ParseObjectWrapper.java
com.androidbook.parse.ParseStarterProjectActivity.java
com.androidbook.parse.PasswordFieldRule.java
com.androidbook.parse.PasswordResetActivity.java
com.androidbook.parse.PasswordResetSuccessActivity.java
com.androidbook.parse.SignupActivity.java
com.androidbook.parse.SignupSuccessActivity.java
com.androidbook.parse.StringUtils.java
com.androidbook.parse.UserListActivity.java
com.androidbook.parse.WelcomeActivity.java
com.androidbook.parse.WordListActivity.java
com.androidbook.parse.WordListAdapter.java
com.androidbook.parse.WordMeaningListAdapter.java
com.androidbook.parse.WordMeaning.java
com.androidbook.parse.WordMeaningsListActivity.java
com.androidbook.parse.Word.java
com.iuriio.demos.expertandroid.ch10search.MainActivity.java
com.iuriio.demos.expertandroid.ch10search.SearchActivity.java
com.iuriio.demos.expertandroid.ch11searchprovider.MainActivity.java
com.iuriio.demos.expertandroid.ch11searchprovider.SearchActivity.java
com.iuriio.demos.expertandroid.ch11searchprovider.SimpleSuggestionProvider.java
com.iuriio.demos.expertandroid.ch11searchprovider.SuggestUrlProvider.java
com.iuriio.demos.expertandroid.ch13parsesimple.BaseActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.LoginActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.MainActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.ParseApp.java
com.iuriio.demos.expertandroid.ch13parsesimple.ParseObjectWrapper.java
com.iuriio.demos.expertandroid.ch13parsesimple.ParseStarterProjectActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.PasswordResetSuccessActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.ResetPasswordActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.SignupActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.StringUtils.java
com.iuriio.demos.expertandroid.ch13parsesimple.WordListActivity.java
com.iuriio.demos.expertandroid.ch13parsesimple.Word.java
com.iuriio.demos.expertandroid.ch1circleview.AbstractBaseView.java
com.iuriio.demos.expertandroid.ch1circleview.CircleView.java
com.iuriio.demos.expertandroid.ch1circleview.MainActivity.java
com.iuriio.demos.expertandroid.ch2durationcontrol.DatePickerFragment.java
com.iuriio.demos.expertandroid.ch2durationcontrol.DurationControl.java
com.iuriio.demos.expertandroid.ch2durationcontrol.MainActivity.java
com.iuriio.demos.expertandroid.ch3flowlayout.FlowLayout.java
com.iuriio.demos.expertandroid.ch3flowlayout.MainActivity.java
com.iuriio.demos.expertandroid.ch4gsonserialization.ChildObject.java
com.iuriio.demos.expertandroid.ch4gsonserialization.MainActivity.java
com.iuriio.demos.expertandroid.ch4gsonserialization.MainObject.java
com.iuriio.demos.expertandroid.ch6forms.BaseActivity.java
com.iuriio.demos.expertandroid.ch6forms.Field.java
com.iuriio.demos.expertandroid.ch6forms.FormActivity.java
com.iuriio.demos.expertandroid.ch6forms.IValidator.java
com.iuriio.demos.expertandroid.ch6forms.IValueValidator.java
com.iuriio.demos.expertandroid.ch6forms.MainActivity.java
com.iuriio.demos.expertandroid.ch6forms.PasswordFieldRule.java
com.iuriio.demos.expertandroid.ch6forms.StringUtils.java
com.iuriio.demos.expertandroid.ch6forms.WelcomeActivity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.AbstractRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.AnimatedSimpleTriangleRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20AbstractRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20ControlledAnimatedTexturedCubeRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20SimpleTriangleRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.ES20SingleTextureAbstractRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.FrustumDimensions.java
com.iuriio.demos.expertandroid.ch9openglexperiments.MainActivity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.MyApplication.java
com.iuriio.demos.expertandroid.ch9openglexperiments.OpenGLES10Activity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.OpenGLES20Activity.java
com.iuriio.demos.expertandroid.ch9openglexperiments.PolygonRenderer.java
com.iuriio.demos.expertandroid.ch9openglexperiments.RegularPolygon.java
com.iuriio.demos.expertandroid.ch9openglexperiments.Shape.java
com.iuriio.demos.expertandroid.ch9openglexperiments.SimpleTriangleRenderer.java
converters.FieldTransporter.java
converters.IFieldTransport.java
converters.IntegerFieldTransport.java
converters.ParseObjectEssentials.java
converters.StringFieldTransport.java
converters.User.java
converters.ValueField.java