Supprime les stacktrace et remplace par des loggers

This commit is contained in:
Hugo 2015-06-13 14:55:35 +02:00
parent 07c4b3290a
commit e8220845f2
5 changed files with 54 additions and 43 deletions

View File

@ -9,6 +9,7 @@ import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.View; import android.view.View;
@ -163,28 +164,37 @@ public class ShopDisplay extends OptionsActivity {
@Override @Override
protected Bitmap doInBackground(String... params) { protected Bitmap doInBackground(String... params) {
URL url; URL url = null;
Bitmap b = null; Bitmap b = null;
HttpURLConnection conn = null;
InputStream is = null;
try { try {
url = new URL(params[0]); url = new URL(params[0]);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
conn.setDoInput(true); conn.setDoInput(true);
conn.connect(); conn.connect();
InputStream is = conn.getInputStream(); is = conn.getInputStream();
b = BitmapFactory.decodeStream(is); b = BitmapFactory.decodeStream(is);
is.close(); is.close();
conn.disconnect(); conn.disconnect();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Log.e("ShopDisplay", "The API doesn't respond correctly. Asked url was "+url.toString(), e);
} catch (ProtocolException e) { } catch (ProtocolException e) {
e.printStackTrace(); Log.e("ShopDisplay", "The protocol doesn't seems to be HTTP. Url was " + url.toString(), e);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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; return b;
} }
@ -201,9 +211,9 @@ public class ShopDisplay extends OptionsActivity {
HttpURLConnection conn = null; HttpURLConnection conn = null;
InputStream is = null; InputStream is = null;
String contentAsString = ""; String contentAsString = "";
URL url = null;
try { try {
URL url = params[0]; url = params[0];
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */); conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */);
@ -221,19 +231,17 @@ public class ShopDisplay extends OptionsActivity {
contentAsString = contentAsString + reader.nextLine(); contentAsString = contentAsString + reader.nextLine();
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Log.e("ShopDisplay", "The API doesn't respond correctly. Asked url was " + url.toString(), e);
} catch (ProtocolException e) { } catch (ProtocolException e) {
e.printStackTrace(); Log.e("ShopDisplay", "The protocol doesn't seems to be HTTP. Url was " + url.toString(), e);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e("ShopDisplay", "The API response is not readable. Url was " + url.toString(), e);
} finally { } finally {
// Makes sure that the InputStream is closed after the app is finished using it. // Makes sure that the InputStream is closed after the app is finished using it.
if (is != null) if (is != null)
try { try {
is.close(); is.close();
} catch (IOException e) { } catch (IOException e) {}
e.printStackTrace();
}
if (conn != null) if (conn != null)
conn.disconnect(); conn.disconnect();
} }

View File

@ -4,6 +4,7 @@ import android.content.Intent;
import android.location.Location; import android.location.Location;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -81,9 +82,9 @@ public class ShopSearch extends OptionsActivity {
HttpURLConnection conn = null; HttpURLConnection conn = null;
InputStream is = null; InputStream is = null;
String contentAsString = ""; String contentAsString = "";
URL url = null;
try { try {
URL url = params[0]; url = params[0];
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */); conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */);
@ -101,19 +102,17 @@ public class ShopSearch extends OptionsActivity {
contentAsString = contentAsString + reader.nextLine(); contentAsString = contentAsString + reader.nextLine();
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Log.e("ShopSearch", "The API doesn't respond correctly. Asked url was " + url.toString(), e);
} catch (ProtocolException e) { } catch (ProtocolException e) {
e.printStackTrace(); Log.e("ShopSearch", "The protocol doesn't seems to be HTTP. Url was " + url.toString(), e);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e("ShopSearch", "The API response is not readable. Url was " + url.toString(), e);
} finally { } finally {
// Makes sure that the InputStream is closed after the app is finished using it. // Makes sure that the InputStream is closed after the app is finished using it.
if (is != null) if (is != null)
try { try {
is.close(); is.close();
} catch (IOException e) { } catch (IOException e) {}
e.printStackTrace();
}
if (conn != null) if (conn != null)
conn.disconnect(); conn.disconnect();
} }

View File

@ -2,6 +2,7 @@ package com.amine.horaires;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
@ -93,9 +94,9 @@ public class ShopUpdate extends OptionsActivity {
HttpURLConnection conn = null; HttpURLConnection conn = null;
InputStream is = null; InputStream is = null;
String contentAsString = ""; String contentAsString = "";
URL url = null;
try { try {
URL url = params[0]; url = params[0];
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */); conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */);
@ -115,19 +116,17 @@ public class ShopUpdate extends OptionsActivity {
contentAsString = contentAsString + reader.nextLine(); contentAsString = contentAsString + reader.nextLine();
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Log.e("ShopUpdate", "The API doesn't respond correctly. Asked url was " + url.toString(), e);
} catch (ProtocolException e) { } catch (ProtocolException e) {
e.printStackTrace(); Log.e("ShopUpdate", "The protocol doesn't seems to be HTTP. Url was " + url.toString(), e);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e("ShopUpdate", "The API response is not readable. Url was " + url.toString(), e);
} finally { } finally {
// Makes sure that the InputStream is closed after the app is finished using it. // Makes sure that the InputStream is closed after the app is finished using it.
if (is != null) if (is != null)
try { try {
is.close(); is.close();
} catch (IOException e) { } catch (IOException e) {}
e.printStackTrace();
}
if (conn != null) if (conn != null)
conn.disconnect(); conn.disconnect();
} }

View File

@ -1,17 +1,16 @@
package com.amine.horaires.util; package com.amine.horaires.util;
import android.util.Log;
import com.amine.horaires.models.Shop; import com.amine.horaires.models.Shop;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
@ -215,8 +214,12 @@ public class Parseur {
saxParser.parse(is, handler); saxParser.parse(is, handler);
} catch (Exception e) { } catch (ParserConfigurationException e) {
e.printStackTrace(); Log.wtf("Parseur", "The parser configuration seems to be unexpected.", e);
} catch (IOException e) {
Log.e("Parseur", "API response seems to be unexpected.", e);
} catch (SAXException e) {
Log.e("Parseur", "Impossible to parse API response.", e);
} }
return listeMagasins; return listeMagasins;

View File

@ -1,5 +1,7 @@
package com.amine.horaires.util; package com.amine.horaires.util;
import android.util.Log;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
@ -13,10 +15,10 @@ public class Utils {
+ "&get=shops" + "&loc=" + URLEncoder.encode(location, "ISO-8859-1") + "&get=shops" + "&loc=" + URLEncoder.encode(location, "ISO-8859-1")
+ "&name=" + URLEncoder.encode(name, "ISO-8859-1")); + "&name=" + URLEncoder.encode(name, "ISO-8859-1"));
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Log.e("Utils", "URL was malformed.", e);
return null; return null;
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); Log.e("Utils", "Fail to encode the URL", e);
return null; return null;
} }
} }
@ -30,10 +32,10 @@ public class Utils {
+ "&get=shops" + "&lng=" + lng + "&lat=" + lat + "&name=" + "&get=shops" + "&lng=" + lng + "&lat=" + lat + "&name="
+ URLEncoder.encode(name, "ISO-8859-1") + "&order=distance"); + URLEncoder.encode(name, "ISO-8859-1") + "&order=distance");
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Log.e("Utils", "URL was malformed.", e);
return null; return null;
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); Log.e("Utils", "Fail to encode the URL", e);
return null; return null;
} }
} }
@ -45,7 +47,7 @@ public class Utils {
+ Configuration.key + "&h=" + Configuration.hashtag + Configuration.key + "&h=" + Configuration.hashtag
+ "&get=shop" + "&id=" + idPoi); + "&get=shop" + "&id=" + idPoi);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Log.e("Utils", "URL was malformed.", e);
return null; return null;
} }
} }
@ -57,7 +59,7 @@ public class Utils {
+ Configuration.key + "&h=" + Configuration.hashtag + Configuration.key + "&h=" + Configuration.hashtag
+ "&get=edit" + "&id=" + idPoi + periodsString); + "&get=edit" + "&id=" + idPoi + periodsString);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Log.e ("Utils", "URL was malformed.", e);
return null; return null;
} }
} }