use of com.backendless.async.callback.AsyncCallback in project Android-SDK by Backendless.
the class ChatActivity method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chat);
final String name = getIntent().getStringExtra(Defaults.NAME_TAG);
final EditText historyField = (EditText) findViewById(R.id.historyField);
final EditText messageField = (EditText) findViewById(R.id.messageField);
Backendless.initApp(this, Defaults.APPLICATION_ID, Defaults.SECRET_KEY, Defaults.VERSION);
Backendless.Messaging.subscribe(Defaults.CHANNEL_NAME, new AsyncCallback<List<Message>>() {
@Override
public void handleResponse(List<Message> response) {
for (Message message : response) historyField.setText(message.getPublisherId() + ": " + message.getData() + "\n" + historyField.getText());
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(ChatActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();
}
}, new AsyncCallback<Subscription>() {
@Override
public void handleResponse(Subscription response) {
subscription = response;
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(ChatActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();
}
});
messageField.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.getAction() == KeyEvent.ACTION_UP) {
String message = messageField.getText().toString();
if (message == null || message.equals(""))
return true;
final ProgressDialog progressDialog = ProgressDialog.show(ChatActivity.this, "", "Sending", true);
Backendless.Messaging.publish(Defaults.CHANNEL_NAME, message, new PublishOptions(name), new AsyncCallback<MessageStatus>() {
@Override
public void handleResponse(MessageStatus response) {
progressDialog.cancel();
messageField.setText("");
}
@Override
public void handleFault(BackendlessFault fault) {
progressDialog.cancel();
Toast.makeText(ChatActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();
}
});
return true;
}
return false;
}
});
}
use of com.backendless.async.callback.AsyncCallback in project Android-SDK by Backendless.
the class Persistence method remove.
protected <E> void remove(final E 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) {
FootprintsManager.getInstance().Inner.removeFootprintForObject(BackendlessSerializer.serializeToMap(entity), entity);
if (responder == null)
return;
responder.handleResponse(((Number) response).longValue());
}
@Override
public void handleFault(BackendlessFault fault) {
if (responder != null)
responder.handleFault(fault);
}
};
Map<String, Object> entityMap = BackendlessSerializer.serializeToMap(entity);
FootprintsManager.getInstance().Inner.putMissingPropsToEntityMap(entity, entityMap);
Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "remove", new Object[] { BackendlessSerializer.getSimpleName(entity.getClass()), entityMap }, 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 UserService method getUserRoles.
public void getUserRoles(final AsyncCallback<List<String>> responder) {
try {
AsyncCallback<String[]> callback = new AsyncCallback<String[]>() {
@Override
public void handleResponse(String[] response) {
if (responder != null)
responder.handleResponse(Arrays.asList(response));
}
@Override
public void handleFault(BackendlessFault fault) {
if (responder != null)
responder.handleFault(fault);
}
};
Invoker.invokeAsync(USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] {}, callback);
} 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 UserServiceAndroidExtra method getSocialDialogResponder.
private AsyncCallback<JSONObject> getSocialDialogResponder(final AsyncCallback<BackendlessUser> responder) {
return new AsyncCallback<JSONObject>() {
@Override
public void handleResponse(JSONObject response) {
try {
BackendlessUser result = new BackendlessUser();
Iterator keys = response.keys();
while (keys.hasNext()) {
String key = String.valueOf(keys.next());
result.setProperty(key, JSONObjectConverter.fromJson(response.get(key)));
}
if (responder != null)
responder.handleResponse(result);
} catch (Exception e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
@Override
public void handleFault(BackendlessFault fault) {
if (responder != null)
responder.handleFault(fault);
}
};
}
use of com.backendless.async.callback.AsyncCallback in project Android-SDK by Backendless.
the class EditPreferencesActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editpreference);
progressDialog = UIFactory.getDefaultProgressDialog(this);
TextView preferenceName = (TextView) findViewById(R.id.preferenceName);
preferencesContainer = (LinearLayout) findViewById(R.id.preferencesContainer);
preferenceTheme = PreferenceTheme.valueOf(getIntent().getStringExtra(Lifecycle.PREFERENCE_TYPE_TAG));
preferenceStore = Backendless.Persistence.of(UserPreferences.class);
// Naming the page
preferenceName.setText(preferenceTheme.getPreference());
((TextView) findViewById(R.id.preferenceLabel)).setText(getString(R.string.textfield_preferences_label_base) + " " + preferenceTheme.getPreference().toLowerCase() + ":");
// Getting preference structure
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery("theme = '" + preferenceTheme.getPreference() + "'");
QueryOptions queryOptions = new QueryOptions();
queryOptions.setPageSize(50);
queryOptions.addSortByOption("name");
backendlessDataQuery.setQueryOptions(queryOptions);
Backendless.Persistence.of(PreferencesDefaults.class).find(backendlessDataQuery, new AsyncCallback<Collection<PreferencesDefaults>>() {
@Override
public void handleResponse(Collection<PreferencesDefaults> preferencesDefaultsBackendlessCollection) {
// Creating a map with predefined checkboxes
List<PreferencesDefaults> preferencesDefaults = preferencesDefaultsBackendlessCollection.getCurrentPage();
for (PreferencesDefaults preference : preferencesDefaults) {
CheckBox checkBox = UIFactory.getPreferenceCheckbox(EditPreferencesActivity.this, preference);
checkBox.setOnClickListener(getCheckboxListener(checkBox));
preferencesContainer.addView(checkBox);
preferenceNameToCheckboxMap.put(preference.getName(), checkBox);
}
// Getting preferences, which should be enabled for current user
String whereClause = "email = '" + Backendless.UserService.CurrentUser().getEmail() + "'";
whereClause += " and theme = '" + preferenceTheme.getPreference() + "'";
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery();
backendlessDataQuery.setWhereClause(whereClause);
backendlessDataQuery.setQueryOptions(new QueryOptions(50, 0));
Backendless.Persistence.of(UserPreferences.class).find(backendlessDataQuery, new AsyncCallback<Collection<UserPreferences>>() {
@Override
public void handleResponse(Collection<UserPreferences> userPreferencesBackendlessCollection) {
List<UserPreferences> userPreferences = userPreferencesBackendlessCollection.getCurrentPage();
for (UserPreferences userPreference : userPreferences) {
CheckBox checkBox = preferenceNameToCheckboxMap.get(userPreference.getPreference());
preferenceNameToPreferenceMap.put(userPreference.getPreference(), userPreference);
checkBox.setChecked(true);
}
progressDialog.cancel();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(EditPreferencesActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(EditPreferencesActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
Aggregations