// External methods public static void fetchImage(final Campaign campaign, final APIResponseHandler responseHandler) { if (campaign.imageBMP == null) { APIClient.getFromRaw( campaign.imageURL, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] bytes) { campaign.imageBMP = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); if (responseHandler != null) { responseHandler.onCompletion(campaign.imageBMP, null); } } @Override public void onFailure( int statusCode, Header[] headers, byte[] bytes, Throwable throwable) { if (responseHandler != null) { responseHandler.onCompletion((Bitmap) null, throwable); } } }); } else { responseHandler.onCompletion(campaign.imageBMP, null); } }
// Static methods public static void fetchAllCampaigns(final APIResponseHandler responseHandler) { APIClient.get( Constants.ENDPOINT_FEATURED_CAMPAIGNS, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONArray responseArray) { super.onSuccess(statusCode, headers, responseArray); final Campaign[] campaigns = new Campaign[responseArray.length()]; for (int i = 0; i < responseArray.length(); ++i) { JSONObject responseObject; Campaign campaign; responseObject = JSONProcessor.jsonObjectFromArray(responseArray, i); campaign = campaignFromJSONObject(responseObject); campaigns[i] = campaign; } responseHandler.onCompletion(campaigns, null); } @Override public void onFailure( int statusCode, Header[] headers, String responseString, Throwable throwable) { super.onFailure(statusCode, headers, responseString, throwable); responseHandler.onCompletion((Campaign[]) null, throwable); } }); }