From 9118a712bf9db0dc463fa9ac0b476c0bac502809 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 25 Jun 2015 10:18:22 +0200 Subject: [PATCH] Simplification du code en utilisant picasso --- Les Horaires/build.gradle | 2 + Les Horaires/proguard-rules.pro | 1 + .../shopdetail/DetailShopFragment.java | 64 ++++--------------- 3 files changed, 16 insertions(+), 51 deletions(-) diff --git a/Les Horaires/build.gradle b/Les Horaires/build.gradle index 053efb5..7a4b10d 100644 --- a/Les Horaires/build.gradle +++ b/Les Horaires/build.gradle @@ -66,4 +66,6 @@ dependencies { compile 'com.pnikosis:materialish-progress:1.5' compile 'com.wdullaer:materialdatetimepicker:1.3.0' compile 'de.cketti.library.changelog:ckchangelog:1.2.2' + + compile 'com.squareup.picasso:picasso:2.5.2' } diff --git a/Les Horaires/proguard-rules.pro b/Les Horaires/proguard-rules.pro index bef92eb..5813b23 100644 --- a/Les Horaires/proguard-rules.pro +++ b/Les Horaires/proguard-rules.pro @@ -15,3 +15,4 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} +-dontwarn com.squareup.okhttp.** diff --git a/Les Horaires/src/main/java/com/amine/horaires/shopdetail/DetailShopFragment.java b/Les Horaires/src/main/java/com/amine/horaires/shopdetail/DetailShopFragment.java index 71d5a98..2d49bf9 100644 --- a/Les Horaires/src/main/java/com/amine/horaires/shopdetail/DetailShopFragment.java +++ b/Les Horaires/src/main/java/com/amine/horaires/shopdetail/DetailShopFragment.java @@ -20,6 +20,8 @@ import com.amine.horaires.updateshop.UpdateShopActivity; import com.amine.horaires.util.Parseur; import com.amine.horaires.util.Utils; import com.melnykov.fab.FloatingActionButton; +import com.squareup.picasso.Picasso; +import com.squareup.picasso.Callback; import java.io.IOException; import java.io.InputStream; @@ -82,9 +84,18 @@ public class DetailShopFragment extends Fragment implements UpdateFav { ImageView imageResult = (ImageView) getView().findViewById(R.id.imageView); - ImageTask t = new ImageTask(imageResult); - t.execute(s.getHoraires()); + Picasso.with(imageResult.getContext()) + .load(s.getHoraires()) + .fit() + .into(imageResult, new Callback() { + @Override + public void onSuccess() { + getActivity().supportStartPostponedEnterTransition(); + } + @Override + public void onError() {} + }); TextView shopName = (TextView) getView().findViewById(R.id.shopName); TextView shopAddress = (TextView) getView().findViewById(R.id.shopAdress); TextView shopOpen = (TextView) getView().findViewById(R.id.shopOpen); @@ -165,55 +176,6 @@ public class DetailShopFragment extends Fragment implements UpdateFav { return isFav; } - public class ImageTask extends AsyncTask { - private final ImageView contenu; - - public ImageTask(ImageView contenu) { - this.contenu = contenu; - } - - @Override - protected Bitmap doInBackground(String... params) { - URL url = null; - Bitmap b = null; - HttpURLConnection conn = null; - InputStream is = null; - try { - url = new URL(params[0]); - conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("GET"); - conn.setDoInput(true); - conn.connect(); - - is = conn.getInputStream(); - b = BitmapFactory.decodeStream(is); - - is.close(); - conn.disconnect(); - - } catch (MalformedURLException e) { - Log.e("ShopDisplay", "The API doesn't respond correctly. Asked url was " + url.toString(), e); - } catch (ProtocolException e) { - Log.e("ShopDisplay", "The protocol doesn't seems to be HTTP. Url was " + url.toString(), e); - } catch (IOException e) { - Log.e("ShopDisplay", "The image seems to be corrupt. Url was " + url.toString(), e); - } finally { - // Makes sure that the InputStream is closed after the app is finished using it. - if (is != null) - try { - is.close(); - } catch (IOException e) {} - if (conn != null) - conn.disconnect(); - } - return b; - } - - protected void onPostExecute(Bitmap b) { - this.contenu.setImageBitmap(b); - } - } - private class SearchTask extends AsyncTask { @Override