Skip to content

Commit

Permalink
Loading Imaged using Octet stream completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan Khanna committed Jun 24, 2014
1 parent 8708f0d commit 8862392
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.PopupMenu;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
Expand All @@ -38,17 +37,13 @@
import com.mifos.utils.Constants;
import com.mifos.utils.SafeUIBlockingUtility;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -522,6 +517,7 @@ public void updateMenu() {

}

//TODO Ask Vishwas which way to use Binary or Data URI
public class ImageLoadingAsyncTask extends AsyncTask<Integer, Void, Void> {

Bitmap bmp;
Expand All @@ -532,36 +528,59 @@ protected Void doInBackground(Integer... integers) {
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(Constants.applicationContext);
String authToken = pref.getString(User.AUTHENTICATION_KEY, "NA");

HttpClient httpClient = new DefaultHttpClient();

String url = "https://demo.openmf.org/mifosng-provider/api/v1/clients/"+
integers[0] + "/images";
HttpGet imageFetchingRequest = new HttpGet(url);
//TODO: Remove default tenant dependency & static URL dependency
imageFetchingRequest.addHeader("X-Mifos-Platform-TenantId","default");
imageFetchingRequest.addHeader(API.HEADER_AUTHORIZATION,authToken);

try {
HttpResponse response = httpClient.execute(imageFetchingRequest);

BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
// HttpClient httpClient = new DefaultHttpClient();
// HttpGet imageFetchingRequest = new HttpGet(url);
// //TODO: Remove default tenant dependency & static URL dependency
// imageFetchingRequest.addHeader("X-Mifos-Platform-TenantId","default");
// imageFetchingRequest.addHeader(API.HEADER_AUTHORIZATION,authToken);
//
// try {
// HttpResponse response = httpClient.execute(imageFetchingRequest);
//
// BufferedReader rd = new BufferedReader(
// new InputStreamReader(response.getEntity().getContent()));
//
// StringBuffer result = new StringBuffer();
// String line = "";
// while ((line = rd.readLine()) != null) {
// result.append(line);
// }
//
// String[] imageDataAndInfoSplitString = result.toString().split(",");
// byte[] bytes = Base64.decode(imageDataAndInfoSplitString[1].getBytes(),Base64.DEFAULT);
// bmp = BitmapFactory.decodeByteArray(bytes,0,bytes.length);
//
// } catch (IOException e) {
// e.printStackTrace();
// }
try{

HttpURLConnection httpURLConnection = (HttpURLConnection) (new URL(url)).openConnection();

httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("X-Mifos-Platform-TenantId", "default");
httpURLConnection.setRequestProperty(API.HEADER_AUTHORIZATION,authToken);
httpURLConnection.setRequestProperty("Accept", "application/octet-stream");
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
Log.i("Connected", "True");
InputStream inputStream = httpURLConnection.getInputStream();

bmp = BitmapFactory.decodeStream(inputStream);

httpURLConnection.disconnect();
Log.i("Connected", "False");

}catch (MalformedURLException e) {

}catch (IOException ioe) {

StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}

String[] imageDataAndInfoSplitString = result.toString().split(",");
byte[] bytes = Base64.decode(imageDataAndInfoSplitString[1].getBytes(),Base64.DEFAULT);
bmp = BitmapFactory.decodeByteArray(bytes,0,bytes.length);

} catch (IOException e) {
e.printStackTrace();
}


return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ public class DataTableDataFragment extends Fragment {
SafeUIBlockingUtility safeUIBlockingUtility;




public static DataTableDataFragment newInstance(DataTable dataTable, int entityId) {

DataTableDataFragment fragment = new DataTableDataFragment();
fragment.dataTable = dataTable;
fragment.entityId = entityId;
return fragment;
}

public DataTableDataFragment() {
// Required empty public constructor
}
Expand All @@ -77,9 +76,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Override
public void success(JsonArray jsonElements, Response response) {

if(jsonElements!=null)
{
rootView = DataTableUIBuilder.getDataTableLayout(dataTable, jsonElements, (LinearLayout)rootView, getActivity());
if (jsonElements != null) {
rootView = DataTableUIBuilder.getDataTableLayout(dataTable, jsonElements, (LinearLayout) rootView, getActivity());
}
}

Expand Down

0 comments on commit 8862392

Please sign in to comment.