Search in sources :

Example 1 with BackendlessUser

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

the class LoginWithFacebookSDKActivity method initUIBehaviour.

private void initUIBehaviour() {
    callbackManager = configureFacebookSDKLogin();
    fbLogoutBackendlessButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isLoggedInBackendless)
                logoutFromBackendless();
            if (isLoggedInFacebook)
                logoutFromFacebook();
        }
    });
    if (AccessToken.getCurrentAccessToken() != null) {
        isLoggedInFacebook = true;
        fbAccessToken = AccessToken.getCurrentAccessToken().getToken();
    }
    BackendlessUser user = Backendless.UserService.CurrentUser();
    if (user != null) {
        isLoggedInBackendless = true;
        backendlessUserInfo.setTextColor(getColor(android.R.color.black));
        backendlessUserInfo.setText("Current user: " + user.getEmail());
        loginFacebookButton.setVisibility(View.INVISIBLE);
        fbLogoutBackendlessButton.setVisibility(View.VISIBLE);
    }
}
Also used : BackendlessUser(com.backendless.BackendlessUser) View(android.view.View)

Example 2 with BackendlessUser

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

the class LoginWithGooglePlusSDKActivity method initUIBehaviour.

private void initUIBehaviour() {
    configureGooglePlusSDK();
    if (mGoogleApiClient.isConnected()) {
        OptionalPendingResult pendingResult = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
        if (pendingResult.isDone())
            handleSignInResult((GoogleSignInResult) pendingResult.get());
    }
    gpLogoutBackendlessButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isLoggedInBackendless)
                logoutFromBackendless();
            if (isLoggedInGoogle)
                logoutFromGoogle();
        }
    });
    BackendlessUser user = Backendless.UserService.CurrentUser();
    if (user != null) {
        isLoggedInBackendless = true;
        backendlessUserInfo.setTextColor(getColor(android.R.color.black));
        backendlessUserInfo.setText("Current user: " + user.getEmail());
        loginGooglePlusButton.setVisibility(View.INVISIBLE);
        gpLogoutBackendlessButton.setVisibility(View.VISIBLE);
    }
}
Also used : BackendlessUser(com.backendless.BackendlessUser) OptionalPendingResult(com.google.android.gms.common.api.OptionalPendingResult) View(android.view.View) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult)

Example 3 with BackendlessUser

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

the class TasksListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.acitivity_taskslist);
    final EditText newTask = (EditText) findViewById(R.id.task);
    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_task);
    final ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(adapter);
    findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (TextUtils.isEmpty(newTask.getText())) {
                newTask.setError("Task cannot be empty");
                newTask.requestFocus();
                return;
            }
            String taskName = newTask.getText().toString();
            BackendlessUser currentUser = Backendless.UserService.CurrentUser();
            String userId = (String) currentUser.getProperty(Defaults.IDENTITY);
            Task task = new Task(taskName, userId);
            BackendlessUtils.saveTask(task, listView, new BackendlessCallback<Task>() {

                @Override
                public void handleResponse(Task task) {
                    adapter.add(task.getMessage());
                }
            });
            newTask.setText("");
            listView.requestFocus();
        }
    });
    BackendlessUtils.initTasks(new BackendlessCallback<Collection<Task>>() {

        @Override
        public void handleResponse(Collection<Task> taskBackendlessCollection) {
            for (Task task : taskBackendlessCollection.getCurrentPage()) adapter.add(task.getMessage());
        }
    });
}
Also used : EditText(android.widget.EditText) BackendlessUser(com.backendless.BackendlessUser) Task(com.backendless.examples.userservice.rolesdemo.Task) View(android.view.View) ListView(android.widget.ListView) ListView(android.widget.ListView) BackendlessCallback(com.backendless.async.callback.BackendlessCallback) BackendlessCollection(com.backendless.BackendlessCollection) ArrayAdapter(android.widget.ArrayAdapter)

Example 4 with BackendlessUser

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

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    if (Defaults.APPLICATION_ID.equals("") || Defaults.SECRET_KEY.equals("") || Defaults.VERSION.equals("")) {
        showAlert(this, "Missing application ID and secret key arguments. Login to Backendless Console, select your app and get the ID and key from the Manage > App Settings screen. Copy/paste the values into the Backendless.initApp call");
        return;
    }
    Backendless.initApp(this, Defaults.APPLICATION_ID, Defaults.SECRET_KEY, Defaults.VERSION);
    final EditText emailField = (EditText) findViewById(R.id.emailField);
    final EditText passwordField = (EditText) findViewById(R.id.passwordField);
    findViewById(R.id.loginButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Backendless.UserService.login(emailField.getText().toString(), passwordField.getText().toString(), new DefaultCallback<BackendlessUser>(MainActivity.this) {

                public void handleResponse(BackendlessUser backendlessUser) {
                    super.handleResponse(backendlessUser);
                    startActivity(new Intent(getBaseContext(), LoggedInActivity.class));
                }
            });
        }
    });
    findViewById(R.id.registerButton).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            startActivity(new Intent(getBaseContext(), RegisterActivity.class));
        }
    });
}
Also used : EditText(android.widget.EditText) BackendlessUser(com.backendless.BackendlessUser) Intent(android.content.Intent) View(android.view.View)

Example 5 with BackendlessUser

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

the class ProfileActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.profile);
    TextView nameField = (TextView) findViewById(R.id.nameField);
    TextView genderField = (TextView) findViewById(R.id.genderField);
    TextView ageField = (TextView) findViewById(R.id.ageField);
    ImageView avatarImage = (ImageView) findViewById(R.id.avatarImage);
    ImageView genderImage = (ImageView) findViewById(R.id.genderImage);
    BackendlessUser currentUser = Backendless.UserService.CurrentUser();
    // Checking CurrentUser
    if (currentUser == null) {
        Lifecycle.runLoginActivity(ProfileActivity.this);
        finish();
    } else {
        nameField.setText((String) currentUser.getProperty(Defaults.NAME_PROPERTY));
        Gender userGender = Gender.valueOf((String) currentUser.getProperty(Defaults.GENDER_PROPERTY));
        genderField.setText(userGender.toString());
        if (userGender == Gender.male) {
            avatarImage.setImageDrawable(getResources().getDrawable(R.drawable.avatar_default_male));
            genderImage.setImageDrawable(getResources().getDrawable(R.drawable.icon_male));
        } else {
            avatarImage.setImageDrawable(getResources().getDrawable(R.drawable.avatar_default_female));
            genderImage.setImageDrawable(getResources().getDrawable(R.drawable.icon_female));
        }
        Date birthDate = (Date) currentUser.getProperty(Defaults.BIRTH_DATE_PROPERTY);
        ageField.setText(String.valueOf(SimpleMath.getAgeFromDate(birthDate)));
    }
    findViewById(R.id.findButton).setOnClickListener(findMatchesListener);
    findViewById(R.id.editFoodPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.FOOD));
    findViewById(R.id.editMusicPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.MUSIC));
    findViewById(R.id.editHobbiesPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.HOBBIES));
    findViewById(R.id.editTravelPreferenceButton).setOnClickListener(getEditPreferencesListener(PreferenceTheme.TRAVEL));
    Button button_logout = (Button) findViewById(R.id.buttonLogOut);
    button_logout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            progressDialog = UIFactory.getDefaultProgressDialog(ProfileActivity.this);
            Backendless.UserService.logout(new AsyncCallback<Void>() {

                @Override
                public void handleResponse(Void aVoid) {
                    Lifecycle.runLoginActivity(ProfileActivity.this);
                    finish();
                    progressDialog.cancel();
                }

                @Override
                public void handleFault(BackendlessFault backendlessFault) {
                    progressDialog.cancel();
                    Toast.makeText(ProfileActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
                }
            });
        }
    });
}
Also used : BackendlessUser(com.backendless.BackendlessUser) Button(android.widget.Button) ResponseAsyncCallback(com.backendless.examples.endless.matchmaker.controllers.shared.ResponseAsyncCallback) AsyncCallback(com.backendless.async.callback.AsyncCallback) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Gender(com.backendless.examples.endless.matchmaker.models.local.Gender) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date) BackendlessFault(com.backendless.exceptions.BackendlessFault)

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