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);
}
}
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);
}
}
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());
}
});
}
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));
}
});
}
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();
}
});
}
});
}
Aggregations