Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.dv.sharer.mobile.controllers; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.util.Log; import com.dv.common.json.BaseModel; import com.dv.common.json.ITransferable; import com.dv.common.webservices.rest.core.client.IRestClient; import com.dv.common.webservices.rest.core.client.IRestClientModel; import com.dv.common.webservices.rest.core.client.IUploadDownload; import com.dv.common.webservices.rest.core.request.search.Search; import com.dv.common.webservices.rest.core.request.search.SearchEntity; import com.dv.common.webservices.rest.core.response.Response; import com.dv.common.webservices.rest.core.response.RetreiveMultiple; import com.dv.model.pojo.Image; import com.dv.model.pojo.Shareable; import com.dv.sharer.utils.Configs; import com.dv.sharer.mobile.rest.AndroidRestClient; import com.dv.sharer.mobile.rest.IAndroidRestClient; import com.dv.sharer.mobile.rest.impl.ImageAndroidRestClient; import com.dv.sharer.restclients.ImageRestClient; import com.dv.sharer.restclients.ShareableRestClient; import com.dv.sharer.restclients.delegate.ImageDelegate; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import javax.ws.rs.client.Entity; import javax.ws.rs.client.Invocation; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import org.apache.commons.codec.binary.Base64; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; /** * * @author PP76575 */ public class ImageController { private static final String TAG = ImageController.class.getName(); IRestClient imareRestClient; ImageAndroidRestClient restClient; ImageDelegate imageDelegate; public ImageController() { imareRestClient = new ImageRestClient(Configs.REST_URL, true); restClient = new ImageAndroidRestClient(imareRestClient, true); imageDelegate = new ImageDelegate(restClient); } public List<Image> getImagesForShareable(Integer shareableId) { Search search = new Search(); SearchEntity searchEntity = new SearchEntity(); searchEntity.setFieldName("shareableId"); searchEntity.setSearchValue(shareableId); searchEntity.setOperation(SearchEntity.Operation.EQUALS); search.setBaseSearchEntity(searchEntity); List<Image> retVal = new ArrayList<Image>(); try { RetreiveMultiple response = restClient.search(search); for (Integer id : response.getIds()) { Image image = (Image) imageDelegate.retrieve(id); retVal.add(image); } } catch (Exception e) { Log.e(TAG, "Could not get shareables for user", e); return null; } return retVal; } public Bitmap convertImageToBitmap(Image image) { byte[] imageData = image.getData(); Bitmap bmp = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); return bmp; } }