From 69cffcd0bf8d1c74e0f819da6f3fa7fb2ef675d3 Mon Sep 17 00:00:00 2001 From: anasofiagribeiro Date: Fri, 9 Oct 2020 16:05:20 +0100 Subject: [PATCH 1/2] EcoAndroid: GZIP Compression energy pattern --- .../ukweather/weather/WeatherInformationDisplayer.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/WorldWeather/app/src/main/java/com/haringeymobile/ukweather/weather/WeatherInformationDisplayer.java b/WorldWeather/app/src/main/java/com/haringeymobile/ukweather/weather/WeatherInformationDisplayer.java index d5b5269..bf46eb7 100644 --- a/WorldWeather/app/src/main/java/com/haringeymobile/ukweather/weather/WeatherInformationDisplayer.java +++ b/WorldWeather/app/src/main/java/com/haringeymobile/ukweather/weather/WeatherInformationDisplayer.java @@ -253,7 +253,7 @@ protected Drawable doInBackground(String... args) { return new BitmapDrawable(res, iconBitmap); } } - + /** * Obtains an input stream to be decoded into a bitmap. * @@ -266,9 +266,15 @@ private InputStream getInputStream(String iconCode) { try { URL url = new URL(iconUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty("Accept-Encoding", "gzip"); connection.setDoInput(true); connection.connect(); - input = connection.getInputStream(); + InputStream input = null; + if ("gzip".equals(connection.getContentEncoding())) { + input = input; + } else { + input = connection.getInputStream(); + }; } catch (MalformedURLException e) { MiscMethods.log("MalformedURLException during SetIconDrawableTask"); return null; From c8dcd54e3878b3e9474c60ac4f7f89e5861afb31 Mon Sep 17 00:00:00 2001 From: anasofiagribeiro Date: Mon, 12 Oct 2020 09:45:19 +0100 Subject: [PATCH 2/2] EcoAndroid - GZIP Compression Energy Pattern --- .../ukweather/weather/WeatherInformationDisplayer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WorldWeather/app/src/main/java/com/haringeymobile/ukweather/weather/WeatherInformationDisplayer.java b/WorldWeather/app/src/main/java/com/haringeymobile/ukweather/weather/WeatherInformationDisplayer.java index bf46eb7..4c4392b 100644 --- a/WorldWeather/app/src/main/java/com/haringeymobile/ukweather/weather/WeatherInformationDisplayer.java +++ b/WorldWeather/app/src/main/java/com/haringeymobile/ukweather/weather/WeatherInformationDisplayer.java @@ -28,6 +28,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.util.zip.GZIPInputStream; public class WeatherInformationDisplayer { @@ -253,7 +254,7 @@ protected Drawable doInBackground(String... args) { return new BitmapDrawable(res, iconBitmap); } } - + /** * Obtains an input stream to be decoded into a bitmap. * @@ -269,12 +270,11 @@ private InputStream getInputStream(String iconCode) { connection.setRequestProperty("Accept-Encoding", "gzip"); connection.setDoInput(true); connection.connect(); - InputStream input = null; if ("gzip".equals(connection.getContentEncoding())) { - input = input; + input = new GZIPInputStream(connection.getInputStream()); } else { input = connection.getInputStream(); - }; + } } catch (MalformedURLException e) { MiscMethods.log("MalformedURLException during SetIconDrawableTask"); return null;