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();
}
});
}
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);
}
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));
}
}
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));
}
}
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));
}
}
Aggregations