Search in sources :

Example 6 with BackendlessDataQuery

use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.

the class BrowseActivity method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse);
    padding = (int) getResources().getDimension(R.dimen.micro_padding);
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int screenWidth = displayMetrics.widthPixels;
    itemWidth = (screenWidth - (2 * (int) getResources().getDimension(R.dimen.default_margin))) / 3;
    GridView gridView = (GridView) findViewById(R.id.gridView);
    imageAdapter = new ImageAdapter(this);
    gridView.setAdapter(imageAdapter);
    Toast.makeText(BrowseActivity.this, "Downloading images...", Toast.LENGTH_SHORT).show();
    BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery();
    backendlessDataQuery.setQueryOptions(new QueryOptions(100, 0, "uploaded"));
    Backendless.Persistence.of(ImageEntity.class).find(backendlessDataQuery, new AsyncCallback<Collection<ImageEntity>>() {

        @Override
        public void handleResponse(final Collection<ImageEntity> response) {
            Toast.makeText(BrowseActivity.this, "Will add " + response.getCurrentPage().size() + " images", Toast.LENGTH_SHORT).show();
            new Thread() {

                @Override
                public void run() {
                    List<ImageEntity> imageEntities = response.getCurrentPage();
                    for (ImageEntity imageEntity : imageEntities) {
                        Message message = new Message();
                        try {
                            URL url = new URL(imageEntity.getUrl());
                            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                            connection.setDoInput(true);
                            connection.connect();
                            InputStream input = connection.getInputStream();
                            message.obj = BitmapFactory.decodeStream(input);
                        } catch (Exception e) {
                            message.obj = e;
                        }
                        imagesHandler.sendMessage(message);
                    }
                }
            }.start();
        }

        @Override
        public void handleFault(BackendlessFault fault) {
            Toast.makeText(BrowseActivity.this, "Make some upload first", Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : Message(android.os.Message) InputStream(java.io.InputStream) DisplayMetrics(android.util.DisplayMetrics) QueryOptions(com.backendless.persistence.QueryOptions) URL(java.net.URL) BackendlessFault(com.backendless.exceptions.BackendlessFault) HttpURLConnection(java.net.HttpURLConnection) BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery) BackendlessCollection(com.backendless.BackendlessCollection) GridView(android.widget.GridView)

Example 7 with BackendlessDataQuery

use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.

the class Persistence method getView.

public List<Map<String, Object>> getView(String viewName, DataQueryBuilder queryBuilder) {
    if (queryBuilder == null)
        throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
    BackendlessDataQuery dataQuery = queryBuilder.build();
    Object[] args = new Object[] { viewName, dataQuery };
    return Invoker.invokeSync(PERSISTENCE_MANAGER_SERVER_ALIAS, "callStoredView", args);
}
Also used : BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery)

Example 8 with BackendlessDataQuery

use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.

the class Persistence method find.

public <E> void find(Class<E> entity, DataQueryBuilder queryBuilder, AsyncCallback<List<E>> responder) {
    if (entity == null)
        throw new IllegalArgumentException(ExceptionMessage.NULL_ENTITY);
    if (queryBuilder == null)
        throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
    BackendlessDataQuery dataQuery = queryBuilder.build();
    try {
        Object[] args = new Object[] { BackendlessSerializer.getSimpleName(entity), dataQuery };
        Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "find", args, responder, ResponderHelper.getCollectionAdaptingResponder(entity));
    } catch (Throwable e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 9 with BackendlessDataQuery

use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.

the class Persistence method loadRelations.

public <T> void loadRelations(String parentType, String objectId, LoadRelationsQueryBuilder queryBuilder, Class<T> relatedType, final AsyncCallback<List<T>> responder) {
    StringUtils.checkEmpty(objectId, ExceptionMessage.NULL_ENTITY);
    if (queryBuilder == null)
        throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
    BackendlessDataQuery dataQuery = queryBuilder.build();
    String relationName = dataQuery.getQueryOptions().getRelated().iterator().next();
    int pageSize = dataQuery.getPageSize();
    int offset = dataQuery.getOffset();
    try {
        Object[] args = new Object[] { parentType, objectId, relationName, pageSize, offset };
        Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "loadRelations", args, responder, ResponderHelper.getCollectionAdaptingResponder(relatedType));
    } catch (Throwable e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 10 with BackendlessDataQuery

use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.

the class Persistence method getObjectCount.

<E> void getObjectCount(final Class<E> entity, DataQueryBuilder queryBuilder, AsyncCallback<Integer> responder) {
    if (queryBuilder == null)
        throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
    BackendlessDataQuery dataQuery = queryBuilder.build();
    try {
        Object[] args = new Object[] { BackendlessSerializer.getSimpleName(entity), dataQuery };
        Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "count", args, responder);
    } catch (Throwable e) {
        if (responder != null)
            responder.handleFault(new BackendlessFault(e));
    }
}
Also used : BackendlessDataQuery(com.backendless.persistence.BackendlessDataQuery) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Aggregations

BackendlessDataQuery (com.backendless.persistence.BackendlessDataQuery)10 BackendlessFault (com.backendless.exceptions.BackendlessFault)6 BackendlessCollection (com.backendless.BackendlessCollection)3 AsyncCallback (com.backendless.async.callback.AsyncCallback)2 QueryOptions (com.backendless.persistence.QueryOptions)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Typeface (android.graphics.Typeface)1 Message (android.os.Message)1 DisplayMetrics (android.util.DisplayMetrics)1 View (android.view.View)1 CheckBox (android.widget.CheckBox)1 GridView (android.widget.GridView)1 TextView (android.widget.TextView)1 BackendlessCallback (com.backendless.async.callback.BackendlessCallback)1 ResponseAsyncCallback (com.backendless.examples.endless.matchmaker.controllers.shared.ResponseAsyncCallback)1 PreferencesDefaults (com.backendless.examples.endless.matchmaker.models.persistent.PreferencesDefaults)1 UserPreferences (com.backendless.examples.endless.matchmaker.models.persistent.UserPreferences)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1