Search in sources :

Example 16 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.

the class UploadFileAsyncTask method doInBackground.

private void doInBackground(final File file, final String path) {
    final AsyncUploadMessage asyncUploadMessage = new AsyncUploadMessage(uploadCallback);
    ThreadPoolService.getPoolExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                FileOutputStreamRouter fileOutputStreamRouter = new FileOutputStreamRouter(file, new UploadCallback() {

                    public void onProgressUpdate(Integer progress) {
                        asyncUploadMessage.setCurrentProgress(progress);
                        ResponseCarrier.getInstance().deliverMessage(asyncUploadMessage);
                    }
                });
                BackendlessFile result = Backendless.Files.uploadFromStream(fileOutputStreamRouter, file.getName(), path, overwrite);
                ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<BackendlessFile>(result, responder));
            } catch (Exception e) {
                ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<BackendlessFile>(new BackendlessFault(e), responder));
            }
        }
    });
}
Also used : AsyncUploadMessage(com.backendless.async.message.AsyncUploadMessage) UploadCallback(com.backendless.async.callback.UploadCallback) AsyncMessage(com.backendless.async.message.AsyncMessage) FileOutputStreamRouter(com.backendless.files.router.FileOutputStreamRouter) BackendlessFile(com.backendless.files.BackendlessFile) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 17 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault 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));
    }
}
Also used : AsyncCallback(com.backendless.async.callback.AsyncCallback) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 18 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.

the class UserService method register.

public void register(final BackendlessUser user, final AsyncCallback<BackendlessUser> responder) {
    try {
        checkUserToBeProper(user);
        BackendlessSerializer.serializeUserProperties(user);
        Invoker.invokeAsync(USER_MANAGER_SERVER_ALIAS, "register", new Object[] { user.getProperties() }, new AsyncCallback<BackendlessUser>() {

            @Override
            public void handleResponse(BackendlessUser response) {
                response.setPassword(user.getPassword());
                user.clearProperties();
                user.putProperties(response.getProperties());
                if (responder != null)
                    responder.handleResponse(response);
            }

            @Override
            public void handleFault(BackendlessFault fault) {
                if (responder != null)
                    responder.handleFault(fault);
            }
        }, new AdaptingResponder(BackendlessUser.class, new BackendlessUserAdaptingPolicy()));
    } catch (BackendlessException e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : BackendlessException(com.backendless.exceptions.BackendlessException) AdaptingResponder(com.backendless.core.responder.AdaptingResponder) BackendlessUserAdaptingPolicy(com.backendless.core.responder.policy.BackendlessUserAdaptingPolicy) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 19 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault 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);
        }
    };
}
Also used : JSONObject(org.json.JSONObject) AsyncCallback(com.backendless.async.callback.AsyncCallback) JSONException(org.json.JSONException) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 20 with BackendlessFault

use of com.backendless.exceptions.BackendlessFault in project Android-SDK by Backendless.

the class AtomicCallback method handleResponse.

@Override
public void handleResponse(Object response) {
    Number numberResult = null;
    if (response instanceof Integer)
        numberResult = Long.valueOf(response.toString());
    else if (response instanceof Double)
        numberResult = Double.valueOf(response.toString());
    else
        realCallback.handleFault(new BackendlessFault("Result is not a number. Expecting either Integer or Double, but received " + response.getClass()));
    Class counterType = (Class) ReflectionUtil.getCallbackGenericType(realCallback);
    Number result = Counters.convertToType(numberResult, counterType);
    realCallback.handleResponse((T) result);
}
Also used : BackendlessFault(com.backendless.exceptions.BackendlessFault)

Aggregations

BackendlessFault (com.backendless.exceptions.BackendlessFault)65 AnonymousObject (weborb.reader.AnonymousObject)15 NamedObject (weborb.reader.NamedObject)15 AsyncCallback (com.backendless.async.callback.AsyncCallback)11 Intent (android.content.Intent)10 View (android.view.View)10 TextView (android.widget.TextView)6 BackendlessCollection (com.backendless.BackendlessCollection)6 List (java.util.List)6 Typeface (android.graphics.Typeface)5 BackendlessDataQuery (com.backendless.persistence.BackendlessDataQuery)5 EditText (android.widget.EditText)4 CollectionAdaptingPolicy (com.backendless.core.responder.policy.CollectionAdaptingPolicy)4 BackendlessFile (com.backendless.files.BackendlessFile)4 ArrayList (java.util.ArrayList)4 Button (android.widget.Button)3 GeoPoint (com.backendless.geo.GeoPoint)3 ProgressDialog (android.app.ProgressDialog)2 DialogInterface (android.content.DialogInterface)2 Bitmap (android.graphics.Bitmap)2