Search in sources :

Example 1 with BackendlessCallback

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);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) Intent(android.content.Intent) PublishOptions(com.backendless.messaging.PublishOptions) ProgressDialog(android.app.ProgressDialog) TextView(android.widget.TextView) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) MessageStatus(com.backendless.messaging.MessageStatus) BackendlessCallback(com.backendless.async.callback.BackendlessCallback) BackendlessCallback(com.backendless.async.callback.BackendlessCallback) DeliveryOptions(com.backendless.messaging.DeliveryOptions)

Example 2 with BackendlessCallback

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());
        }
    });
}
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 3 with BackendlessCallback

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);
        }
    });
}
Also used : Typeface(android.graphics.Typeface) AsyncCallback(com.backendless.async.callback.AsyncCallback) Intent(android.content.Intent) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) Bitmap(android.graphics.Bitmap) BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery) BackendlessCallback(com.backendless.async.callback.BackendlessCallback) BackendlessCollection(com.backendless.BackendlessCollection)

Aggregations

View (android.view.View)3 BackendlessCallback (com.backendless.async.callback.BackendlessCallback)3 Intent (android.content.Intent)2 BackendlessCollection (com.backendless.BackendlessCollection)2 BackendlessFault (com.backendless.exceptions.BackendlessFault)2 ProgressDialog (android.app.ProgressDialog)1 Bitmap (android.graphics.Bitmap)1 Typeface (android.graphics.Typeface)1 Handler (android.os.Handler)1 Message (android.os.Message)1 ArrayAdapter (android.widget.ArrayAdapter)1 EditText (android.widget.EditText)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 BackendlessUser (com.backendless.BackendlessUser)1 AsyncCallback (com.backendless.async.callback.AsyncCallback)1 Task (com.backendless.examples.userservice.rolesdemo.Task)1 DeliveryOptions (com.backendless.messaging.DeliveryOptions)1 MessageStatus (com.backendless.messaging.MessageStatus)1 PublishOptions (com.backendless.messaging.PublishOptions)1