1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
private ImageView viewer;
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.telephone_frag, container, false);
viewer = (ImageView) v.findViewById(R.id.imageTel);
Intent i = getActivity().getIntent();
donnee = i.getStringExtra(FragmentOne.MODEL);
new DownloadImage().execute();
return v;
}
public void populate(Bitmap data) {
this.viewer.setImageBitmap(data);
}
class DownloadImage extends AsyncTask<String, Void, Bitmap> {
InputStream is = null;
String result = null,result1 = null;
protected Bitmap doInBackground(String... params) {
Bitmap imageCall = null;
try {
HttpClient httpclient = new DefaultHttpClient();
nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("Designation", donnee));
HttpPost httppost = new HttpPost("http://10.0.2.2:82/AndroidWork/affiche_call.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Exception levee " + e.toString());
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
result1 = result.replace("\\","");
} catch (Exception e) {
Log.e("log_tag", "Erreur de conversion du resultat " + e.toString());
}
try {
JSONArray array = new JSONArray(result1);
for (int i = 0; i < array.length(); i++) {
JSONObject json_data = array.getJSONObject(i);
imageCall = BitmapFactory.decodeFile(json_data.getString("Detail"));
}
} catch (Exception e) {
Log.e("log_tag", "Erreur chargement bitmap " + e.toString());
}
return imageCall;
}
protected void onPostExecute(Bitmap result) {
populate(result);
}
} |
Partager