use of com.backendless.async.callback.AsyncCallback 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();
}
});
}
});
}
use of com.backendless.async.callback.AsyncCallback in project Android-SDK by Backendless.
the class MapDrivenDataStore method remove.
@Override
public void remove(Map entity, final AsyncCallback<Long> responder) {
try {
if (entity == null)
throw new IllegalArgumentException(ExceptionMessage.NULL_ENTITY);
AsyncCallback<Object> removalCallback = new AsyncCallback<Object>() {
@Override
public void handleResponse(Object response) {
responder.handleResponse(((Number) response).longValue());
}
@Override
public void handleFault(BackendlessFault fault) {
if (responder != null)
responder.handleFault(fault);
}
};
Object[] args = new Object[] { tableName, entity };
Invoker.invokeAsync(Persistence.PERSISTENCE_MANAGER_SERVER_ALIAS, "remove", args, removalCallback);
} catch (Throwable e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
use of com.backendless.async.callback.AsyncCallback in project Android-SDK by Backendless.
the class ReflectionUtil method getCallbackGenericType.
public static <T> Type getCallbackGenericType(AsyncCallback<T> callback) {
Type[] genericInterfaces = callback.getClass().getGenericInterfaces();
Type asyncCallbackInterface = null;
for (Type genericInterface : genericInterfaces) {
if (!(genericInterface instanceof ParameterizedType))
continue;
Type rawType = ((ParameterizedType) genericInterface).getRawType();
if (rawType instanceof Class && AsyncCallback.class.isAssignableFrom((Class) rawType)) {
asyncCallbackInterface = genericInterface;
break;
}
}
return ((ParameterizedType) asyncCallbackInterface).getActualTypeArguments()[0];
}
use of com.backendless.async.callback.AsyncCallback in project Android-SDK by Backendless.
the class LoginActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_login);
Backendless.initApp(LoginActivity.this, Default.APP_ID, Default.SECRET_KEY, Default.VERSION);
TextView textEmail = (TextView) findViewById(R.id.textEmail);
TextView textPass = (TextView) findViewById(R.id.textPass);
TextView textPiar = (TextView) findViewById(R.id.textPiar);
TextView textOr = (TextView) findViewById(R.id.textOr);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
textEmail.setTypeface(typeface);
textPass.setTypeface(typeface);
textPiar.setTypeface(typeface);
textOr.setTypeface(typeface);
final Button loginBtn = (Button) findViewById(R.id.loginBtn);
loginBtn.setTypeface(typeface);
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText editEmailText = (EditText) findViewById(R.id.emailEdit);
EditText editPasswordText = (EditText) findViewById(R.id.passwordEdit);
final String messageMail = editEmailText.getText().toString();
final String messagePassword = editPasswordText.getText().toString();
if (TextUtils.isEmpty(messageMail) || TextUtils.isEmpty(messagePassword)) {
String alertMessage = "Please, fill in empty fields!";
Toast.makeText(LoginActivity.this, alertMessage, Toast.LENGTH_LONG).show();
return;
}
progressDialog = ProgressDialog.show(LoginActivity.this, "", "Loading", true);
Backendless.UserService.login(messageMail, messagePassword, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser backendlessUser) {
progressDialog.cancel();
Intent intent = new Intent(LoginActivity.this, EndlessTaggingActivity.class);
intent.putExtra(Default.EXTRA_EMAIL, messageMail);
intent.putExtra(Default.EXTRA_PASSWORD, messagePassword);
startActivity(intent);
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(LoginActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
Button goRegistrationBtn = (Button) findViewById(R.id.goRegistrationBtn);
goRegistrationBtn.setTypeface(typeface);
goRegistrationBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(LoginActivity.this, RegistrationActivity.class);
startActivity(intent);
finish();
}
});
Button facebookBtn = (Button) findViewById(R.id.facebookBtn);
facebookBtn.setTypeface(typeface);
facebookBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Backendless.UserService.loginWithFacebook(LoginActivity.this, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
Intent intent = new Intent(LoginActivity.this, EndlessTaggingActivity.class);
startActivity(intent);
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(LoginActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
Button twitterBtn = (Button) findViewById(R.id.twitterBtn);
twitterBtn.setTypeface(typeface);
twitterBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Backendless.UserService.loginWithTwitter(LoginActivity.this, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
Intent intent = new Intent(LoginActivity.this, EndlessTaggingActivity.class);
startActivity(intent);
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(LoginActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
}
use of com.backendless.async.callback.AsyncCallback in project Android-SDK by Backendless.
the class PointCommentsActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_point_comments);
photoBtn = (Button) findViewById(R.id.photoBtn);
photoBtn.setVisibility(View.INVISIBLE);
final TextView textViewComment = (TextView) findViewById(R.id.textViewComment);
TextView textPointComments = (TextView) findViewById(R.id.textPointComments);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
textPointComments.setTypeface(typeface);
textViewComment.setTypeface(typeface);
textViewComment.setVisibility(View.INVISIBLE);
final EditText editComment = (EditText) findViewById(R.id.editComment);
editComment.setVisibility(View.INVISIBLE);
photoBtn.setTypeface(typeface);
Intent intent = getIntent();
geoPointId = intent.getStringExtra(Default.GEO_POINT_ID);
userName = (String) Backendless.UserService.CurrentUser().getProperty("name");
if (userName == null)
userName = Backendless.UserService.CurrentUser().getEmail();
Bitmap bitmap = intent.getParcelableExtra(Default.SEND_BITMAP);
imageView = (ImageView) findViewById(R.id.photoView);
imageView.setImageBitmap(bitmap);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
final Button commentsBtn = (Button) findViewById(R.id.commentsBtn);
commentsBtn.setTypeface(typeface);
commentsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageView.setVisibility(View.INVISIBLE);
commentsBtn.setEnabled(false);
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery();
backendlessDataQuery.addProperty("name");
backendlessDataQuery.addProperty("message");
backendlessDataQuery.setWhereClause("geoPointId=" + "'" + geoPointId + "'");
progressDialog = ProgressDialog.show(PointCommentsActivity.this, "", "Loading", true);
Backendless.Persistence.of(Comment.class).find(backendlessDataQuery, new AsyncCallback<Collection<Comment>>() {
@Override
public void handleResponse(Collection<Comment> response) {
Collection<Comment> comments = response;
for (int i = 0; i < comments.getCurrentPage().size(); i++) {
Comment comment = comments.getCurrentPage().get(i);
String userName = comment.getName();
commentsPoint.add(userName + " : " + comment.getMessage());
}
lvMain = (ListView) findViewById(R.id.commentList);
lvMain.setVisibility(View.VISIBLE);
adapter = new ArrayAdapter<String>(PointCommentsActivity.this, android.R.layout.simple_list_item_1, commentsPoint);
lvMain.setAdapter(adapter);
progressDialog.cancel();
textViewComment.setVisibility(View.VISIBLE);
editComment.setVisibility(View.VISIBLE);
addCommentBtn.setVisibility(View.VISIBLE);
commentsBtn.setVisibility(View.INVISIBLE);
photoBtn.setVisibility(View.VISIBLE);
}
@Override
public void handleFault(BackendlessFault fault) {
progressDialog.cancel();
Toast.makeText(PointCommentsActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
textViewComment.setVisibility(View.VISIBLE);
editComment.setVisibility(View.VISIBLE);
addCommentBtn.setVisibility(View.VISIBLE);
commentsBtn.setVisibility(View.INVISIBLE);
photoBtn.setVisibility(View.VISIBLE);
}
});
}
});
addCommentBtn = (Button) findViewById(R.id.addCommentBtn);
addCommentBtn.setTypeface(typeface);
addCommentBtn.setVisibility(View.INVISIBLE);
addCommentBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String commentName = editComment.getText().toString();
if (TextUtils.isEmpty(commentName)) {
String alertMessage = "Please, fill in empty field!";
Toast.makeText(PointCommentsActivity.this, alertMessage, Toast.LENGTH_LONG).show();
return;
}
progressDialog = ProgressDialog.show(PointCommentsActivity.this, "", "Loading", true);
Comment commentPoint = new Comment(userName, commentName, geoPointId);
Backendless.Persistence.save(commentPoint, new BackendlessCallback<Comment>() {
@Override
public void handleResponse(Comment commentPoint) {
Intent categoryIntent = getIntent();
String name = categoryIntent.getStringExtra(Default.SEARCH_CATEGORY_NAME);
Intent intent = new Intent();
intent.putExtra(Default.SEARCH_CATEGORY_NAME, name);
setResult(Default.ADD_NEW_COMMENT, intent);
progressDialog.cancel();
finish();
Toast.makeText(PointCommentsActivity.this, "A new comment was successfully added", Toast.LENGTH_LONG).show();
}
});
}
});
photoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.clear();
lvMain.setAdapter(adapter);
lvMain.setVisibility(View.INVISIBLE);
textViewComment.setVisibility(View.INVISIBLE);
editComment.setVisibility(View.INVISIBLE);
addCommentBtn.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);
photoBtn.setVisibility(View.INVISIBLE);
commentsBtn.setVisibility(View.VISIBLE);
commentsBtn.setEnabled(true);
}
});
}
Aggregations