Android Open Source - android-ribbit-design Sign Up Activity






From Project

Back to project page android-ribbit-design.

License

The source code is released under:

MIT License

If you think the Android project android-ribbit-design 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.teamtreehouse.ribbit.ui;
/*  w  ww  . j  av  a2  s .  co m*/
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
import com.teamtreehouse.ribbit.R;
import com.teamtreehouse.ribbit.RibbitApplication;

public class SignUpActivity extends Activity {
  
  protected EditText mUsername;
  protected EditText mPassword;
  protected EditText mEmail;
  protected Button mSignUpButton;
  protected Button mCancelButton;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_sign_up);
    
    ActionBar actionBar = getActionBar();
    actionBar.hide();
    
    mUsername = (EditText)findViewById(R.id.usernameField);
    mPassword = (EditText)findViewById(R.id.passwordField);
    mEmail = (EditText)findViewById(R.id.emailField);
    
    mCancelButton = (Button)findViewById(R.id.cancelButton);
    mCancelButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        finish();
      }
    });
    
    
    mSignUpButton = (Button)findViewById(R.id.signupButton);
    mSignUpButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        String username = mUsername.getText().toString();
        String password = mPassword.getText().toString();
        String email = mEmail.getText().toString();
        
        username = username.trim();
        password = password.trim();
        email = email.trim();
        
        if (username.isEmpty() || password.isEmpty() || email.isEmpty()) {
          AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
          builder.setMessage(R.string.signup_error_message)
            .setTitle(R.string.signup_error_title)
            .setPositiveButton(android.R.string.ok, null);
          AlertDialog dialog = builder.create();
          dialog.show();
        }
        else {
          // create the new user!
          setProgressBarIndeterminateVisibility(true);
          
          ParseUser newUser = new ParseUser();
          newUser.setUsername(username);
          newUser.setPassword(password);
          newUser.setEmail(email);
          newUser.signUpInBackground(new SignUpCallback() {
            @Override
            public void done(ParseException e) {
              setProgressBarIndeterminateVisibility(false);
              
              if (e == null) {
                // Success!
                RibbitApplication.updateParseInstallation(
                    ParseUser.getCurrentUser());
                
                Intent intent = new Intent(SignUpActivity.this, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
              }
              else {
                AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
                builder.setMessage(e.getMessage())
                  .setTitle(R.string.signup_error_title)
                  .setPositiveButton(android.R.string.ok, null);
                AlertDialog dialog = builder.create();
                dialog.show();
              }
            }
          });
        }
      }
    });
  }
}




Java Source Code List

com.teamtreehouse.ribbit.RibbitApplication.java
com.teamtreehouse.ribbit.adapters.MessageAdapter.java
com.teamtreehouse.ribbit.adapters.SectionsPagerAdapter.java
com.teamtreehouse.ribbit.adapters.UserAdapter.java
com.teamtreehouse.ribbit.ui.EditFriendsActivity.java
com.teamtreehouse.ribbit.ui.FriendsFragment.java
com.teamtreehouse.ribbit.ui.InboxFragment.java
com.teamtreehouse.ribbit.ui.LoginActivity.java
com.teamtreehouse.ribbit.ui.MainActivity.java
com.teamtreehouse.ribbit.ui.RecipientsActivity.java
com.teamtreehouse.ribbit.ui.SignUpActivity.java
com.teamtreehouse.ribbit.ui.ViewImageActivity.java
com.teamtreehouse.ribbit.utils.FileHelper.java
com.teamtreehouse.ribbit.utils.ImageResizer.java
com.teamtreehouse.ribbit.utils.MD5Util.java
com.teamtreehouse.ribbit.utils.ParseConstants.java