use of com.backendless.async.callback.BackendlessCallback in project Android-SDK by Backendless.
the class PushActivity method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.push);
historyField = (TextView) findViewById(R.id.historyField);
messageField = (EditText) findViewById(R.id.messageField);
forceNotify = (CheckBox) findViewById(R.id.forceNotify);
handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
if (!(message.obj instanceof Error))
historyField.setText(message.obj + "\n" + historyField.getText());
else
MainActivity.showAlert(PushActivity.this, ((Error) message.obj).getMessage());
return true;
}
});
findViewById(R.id.sendButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String message = messageField.getText().toString();
if (message == null || message.equals(""))
return;
final ProgressDialog progressDialog = ProgressDialog.show(PushActivity.this, "", "Sending push message", true);
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setPushBroadcast(PushBroadcastMask.ALL);
PublishOptions publishOptions = new PublishOptions();
if (forceNotify.isChecked()) {
publishOptions.putHeader(PublishOptions.ANDROID_TICKER_TEXT_TAG, getString(R.string.app_name));
publishOptions.putHeader(PublishOptions.ANDROID_CONTENT_TITLE_TAG, getString(R.string.app_name));
publishOptions.putHeader(PublishOptions.ANDROID_CONTENT_TEXT_TAG, message);
}
Backendless.Messaging.publish(Defaults.CHANNEL_NAME, message, publishOptions, deliveryOptions, new BackendlessCallback<MessageStatus>() {
@Override
public void handleResponse(MessageStatus response) {
progressDialog.cancel();
messageField.setText("");
}
@Override
public void handleFault(BackendlessFault fault) {
progressDialog.cancel();
Toast.makeText(PushActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
findViewById(R.id.unregisterButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Backendless.Messaging.unregisterDevice();
setResult(RESULT_OK, new Intent());
finish();
}
});
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
use of com.backendless.async.callback.BackendlessCallback 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.async.callback.BackendlessCallback 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