Android Open Source - mha-android Register Activity






From Project

Back to project page mha-android.

License

The source code is released under:

Copyright (c) 2011-2012 Cameron Porter, Ryan Brown http://github.com/camporter/mha-android Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated...

If you think the Android project mha-android 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.teamacra.myhomeaudio.ui;
/*from  w  w  w  .  ja  va 2s . c om*/
import com.teamacra.myhomeaudio.MHAApplication;
import com.teamacra.myhomeaudio.R;
import com.teamacra.myhomeaudio.R.id;
import com.teamacra.myhomeaudio.R.layout;
import com.teamacra.myhomeaudio.http.HttpClient;
import com.teamacra.myhomeaudio.http.StatusCode;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;

public class RegisterActivity extends Activity implements View.OnClickListener {

  private Button registerButton;

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register);

    this.registerButton = (Button) this.findViewById(R.id.registerButton);
    this.registerButton.setOnClickListener(this);
  }

  @Override
  public void onClick(View view) {
    if (view == this.registerButton) {
      String username = ((EditText) this.findViewById(R.id.registerUsernameEditText))
          .getText().toString();
      String password = ((EditText) this.findViewById(R.id.registerPasswordEditText))
          .getText().toString();

      if (username.length() > 0 && password.length() > 0) {
        new RegisterUser().execute(username, password);
      } else {
        Toast.makeText(this, "Please fill in your username and password completely!",
            Toast.LENGTH_SHORT).show();
      }

    }
  }

  private class RegisterUser extends AsyncTask<String, Void, Integer> {

    private final ProgressDialog progressDialog = new ProgressDialog(RegisterActivity.this);
    private AlertDialog completionDialog;
    MHAApplication app = (MHAApplication) RegisterActivity.this.getApplication();

    protected void onPreExecute() {
      this.progressDialog.setMessage("Registering a new account for you...");
      this.progressDialog.show();
    }

    protected Integer doInBackground(String... args) {
      String username = args[0];
      String password = args[1];

      HttpClient client = new HttpClient(app);
      return client.register(username, password);
    }

    protected void onPostExecute(final Integer statusCode) {
      AlertDialog.Builder completion = new AlertDialog.Builder(RegisterActivity.this);

      switch (statusCode) {
      case StatusCode.STATUS_OK:
        completion.setTitle("Now Registered");
        completion.setMessage("You can now log in with your username and password.");
        completion.setNeutralButton("Ok", new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface dialog, int which) {
            completionDialog.dismiss();
            
            Intent loginIntent = new Intent(RegisterActivity.this, LoginActivity.class);
            RegisterActivity.this.startActivity(loginIntent);
          }
        });
        break;
      case StatusCode.STATUS_REG_DUPLICATE:
        completion.setTitle("Duplicate Username");
        completion
            .setMessage("Your username has already been registered, please try another one.");
        completion.setNeutralButton("Ok", new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface dialog, int which) {
            completionDialog.dismiss();
          }
        });
        break;
      default:
        completion.setTitle("Registration Failed");
        completion.setMessage("An error occured while trying to register.");
        completion.setNeutralButton("Ok", new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface dialog, int which) {
            completionDialog.dismiss();
          }
        });
      }
      this.progressDialog.dismiss();
      this.completionDialog = completion.create();
      this.completionDialog.show();

    }
  }
}




Java Source Code List

com.teamacra.myhomeaudio.MHAApplication.java
com.teamacra.myhomeaudio.bluetooth.BluetoothService.java
com.teamacra.myhomeaudio.discovery.DiscoveryConstants.java
com.teamacra.myhomeaudio.discovery.DiscoveryDescription.java
com.teamacra.myhomeaudio.discovery.DiscoverySearchListener.java
com.teamacra.myhomeaudio.discovery.DiscoverySearch.java
com.teamacra.myhomeaudio.discovery.MDNSDiscovery.java
com.teamacra.myhomeaudio.http.HttpBase.java
com.teamacra.myhomeaudio.http.HttpClient.java
com.teamacra.myhomeaudio.http.HttpNode.java
com.teamacra.myhomeaudio.http.HttpSource.java
com.teamacra.myhomeaudio.http.HttpStream.java
com.teamacra.myhomeaudio.http.StatusCode.java
com.teamacra.myhomeaudio.locations.NodeSignalRange.java
com.teamacra.myhomeaudio.locations.NodeSignature.java
com.teamacra.myhomeaudio.manager.ConfigurationManager.java
com.teamacra.myhomeaudio.manager.LocationManager.java
com.teamacra.myhomeaudio.manager.NodeManager.java
com.teamacra.myhomeaudio.manager.StreamManager.java
com.teamacra.myhomeaudio.media.MediaDescriptor.java
com.teamacra.myhomeaudio.node.Node.java
com.teamacra.myhomeaudio.source.Source.java
com.teamacra.myhomeaudio.stream.StreamAction.java
com.teamacra.myhomeaudio.stream.Stream.java
com.teamacra.myhomeaudio.ui.InitialConfigActivity.java
com.teamacra.myhomeaudio.ui.LoginActivity.java
com.teamacra.myhomeaudio.ui.MyHomeAudioActivity.java
com.teamacra.myhomeaudio.ui.RegisterActivity.java
com.teamacra.myhomeaudio.ui.fragment.SongFragment.java
com.teamacra.myhomeaudio.ui.fragment.SourceFragment.java
com.teamacra.myhomeaudio.ui.fragment.TestFragment.java