Example #1
0
  /** Prepare the page for the actual registration in the database. */
  public void prepareForRegistration() {
    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
      // Internet Connection is not present
      alert.showAlertDialog(
          "Internet Connection Error", "Please connect to working Internet connection", false);
      // stop executing code by return
      return;
    }

    // Check if GCM configuration is set
    if (SERVER_URL == null
        || SENDER_ID == null
        || SERVER_URL.length() == 0
        || SENDER_ID.length() == 0) {
      // GCM sernder id / server url is missing
      alert.showAlertDialog(
          "Configuration Error!", "Please set your Server URL and GCM Sender ID", false);
      // stop executing code by return
      return;
    }

    txtName = (EditText) findViewById(R.id.txtName);
    txtEmail = (EditText) findViewById(R.id.txtEmail);
    btnRegister = (Button) findViewById(R.id.btnRegister);

    /*
     * Click event on Register button
     */
    btnRegister.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View arg0) {

            name = txtName.getText().toString();
            email = txtEmail.getText().toString();

            // Check if user filled the form
            if (name.trim().length() > 0 && email.trim().length() > 0) {

              register(name, email);

            } else {
              // user didn't fill data; show alert message
              alert.showAlertDialog("Registration Error!", "Please enter your details", false);
            }
          }
        });
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
      // Internet Connection is not present
      alert.showAlertDialog(
          RegisterActivity.this,
          "Internet Connection Error",
          "Please connect to working Internet connection",
          false);
      // stop executing code by return
      return;
    }

    // Check if GCM configuration is set
    if (SERVER_URL == null
        || SENDER_ID == null
        || SERVER_URL.length() == 0
        || SENDER_ID.length() == 0) {
      // GCM sernder id / server url is missing
      alert.showAlertDialog(
          RegisterActivity.this,
          "Configuration Error!",
          "Please set your Server URL and GCM Sender ID",
          false);
      // stop executing code by return
      return;
    }

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);

    String reg_id = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (!reg_id.equals("")) {
      Intent i = new Intent(getApplicationContext(), MainActivity.class);
      startActivity(i);
      finish();
    }

    txtName = (EditText) findViewById(R.id.txtName);
    txtEmail = (EditText) findViewById(R.id.txtEmail);
    btnRegister = (Button) findViewById(R.id.btnRegister);

    /*
     * Click event on Register button
     * */
    btnRegister.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View arg0) {
            // Read EditText dat
            String name = txtName.getText().toString();
            String email = txtEmail.getText().toString();

            // Check if user filled the form
            if (name.trim().length() > 0 && email.trim().length() > 0) {
              // Launch Main Activity
              Intent i = new Intent(getApplicationContext(), MainActivity.class);

              // Registering user on our server
              // Sending registraiton details to MainActivity
              i.putExtra("name", name);
              i.putExtra("email", email);
              startActivity(i);
              finish();
            } else {
              // user doen't filled that data
              // ask him to fill the form
              alert.showAlertDialog(
                  RegisterActivity.this, "Registration Error!", "Please enter your details", false);
            }
          }
        });
  }