Search in sources :

Example 11 with BackendlessUser

use of com.backendless.BackendlessUser in project Android-SDK by Backendless.

the class BackendlessUtils method register.

private static void register(String userId, String password, final AsyncCallback<Boolean> callback) {
    BackendlessUser backendlessUser = new BackendlessUser();
    backendlessUser.setProperty(Defaults.IDENTITY, userId);
    backendlessUser.setPassword(password);
    Backendless.UserService.register(backendlessUser, new BackendlessCallback<BackendlessUser>() {

        @Override
        public void handleResponse(BackendlessUser user) {
            callback.handleResponse(true);
        }
    });
}
Also used : BackendlessUser(com.backendless.BackendlessUser)

Example 12 with BackendlessUser

use of com.backendless.BackendlessUser in project Android-SDK by Backendless.

the class RegisterActivity method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register);
    final EditText nameField = (EditText) findViewById(R.id.nameField);
    final EditText passwordField = (EditText) findViewById(R.id.passwordField);
    final EditText verifyPasswordField = (EditText) findViewById(R.id.verifyPasswordField);
    final EditText emailField = (EditText) findViewById(R.id.emailField);
    final RadioGroup genderRadio = (RadioGroup) findViewById(R.id.genderRadio);
    final Calendar dateOfBirth = Calendar.getInstance();
    final EditText dateOfBirthField = (EditText) findViewById(R.id.dateOfBirthField);
    dateOfBirthField.setText(SIMPLE_DATE_FORMAT.format(dateOfBirth.getTime()));
    findViewById(R.id.dateOfBirthField).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new DatePickerDialog(RegisterActivity.this, new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                    dateOfBirth.set(Calendar.YEAR, year);
                    dateOfBirth.set(Calendar.MONTH, monthOfYear);
                    dateOfBirth.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                    dateOfBirthField.setText(SIMPLE_DATE_FORMAT.format(dateOfBirth.getTime()));
                }
            }, dateOfBirth.get(Calendar.YEAR), dateOfBirth.get(Calendar.MONTH), dateOfBirth.get(Calendar.DAY_OF_MONTH)).show();
        }
    });
    findViewById(R.id.registerButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String name = nameField.getText().toString();
            if (name == null || name.equals("")) {
                showToast("Name cannot be empty");
                return;
            }
            String password = passwordField.getText().toString();
            if (password == null || password.equals("")) {
                showToast("Password cannot be empty");
                return;
            }
            String verifyPassword = verifyPasswordField.getText().toString();
            if (!password.equals(verifyPassword)) {
                showToast("Passwords does not match");
                return;
            }
            String email = emailField.getText().toString();
            if (email == null || email.equals("")) {
                showToast("Email cannot be empty");
                return;
            }
            Gender gender = null;
            switch(genderRadio.getCheckedRadioButtonId()) {
                case -1:
                    showToast("Please select your gender");
                    return;
                case R.id.genderMale:
                    gender = Gender.MALE;
                    break;
                case R.id.genderFemale:
                    gender = Gender.FEMALE;
            }
            BackendlessUser user = new BackendlessUser();
            user.setPassword(password);
            user.setEmail(email);
            user.setProperty(NAME_KEY, name);
            user.setProperty(GENDER_KEY, gender);
            user.setProperty(DATE_OF_BIRTH_KEY, dateOfBirth.getTime());
            user.setProperty(LOGIN_KEY, email);
            Backendless.UserService.register(user, new DefaultCallback<BackendlessUser>(RegisterActivity.this) {

                @Override
                public void handleResponse(BackendlessUser response) {
                    super.handleResponse(response);
                    startActivity(new Intent(getBaseContext(), RegisteredActivity.class));
                    finish();
                }
            });
        }
    });
}
Also used : EditText(android.widget.EditText) BackendlessUser(com.backendless.BackendlessUser) RadioGroup(android.widget.RadioGroup) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) Intent(android.content.Intent) View(android.view.View) DatePicker(android.widget.DatePicker)

Aggregations

BackendlessUser (com.backendless.BackendlessUser)12 View (android.view.View)8 EditText (android.widget.EditText)5 Intent (android.content.Intent)4 Button (android.widget.Button)3 TextView (android.widget.TextView)3 AsyncCallback (com.backendless.async.callback.AsyncCallback)3 BackendlessFault (com.backendless.exceptions.BackendlessFault)3 Typeface (android.graphics.Typeface)2 DatePickerDialog (android.app.DatePickerDialog)1 ArrayAdapter (android.widget.ArrayAdapter)1 DatePicker (android.widget.DatePicker)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 RadioGroup (android.widget.RadioGroup)1 BackendlessCollection (com.backendless.BackendlessCollection)1 BackendlessCallback (com.backendless.async.callback.BackendlessCallback)1 ResponseAsyncCallback (com.backendless.examples.endless.matchmaker.controllers.shared.ResponseAsyncCallback)1 Gender (com.backendless.examples.endless.matchmaker.models.local.Gender)1 Task (com.backendless.examples.userservice.rolesdemo.Task)1