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

View File

@ -4,6 +4,7 @@ import android.content.Intent;
import android.location.Location;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -81,9 +82,9 @@ public class ShopSearch extends OptionsActivity {
HttpURLConnection conn = null;
InputStream is = null;
String contentAsString = "";
URL url = null;
try {
URL url = params[0];
url = params[0];
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
@ -101,19 +102,17 @@ public class ShopSearch extends OptionsActivity {
contentAsString = contentAsString + reader.nextLine();
}
} catch (MalformedURLException e) {
e.printStackTrace();
Log.e("ShopSearch", "The API doesn't respond correctly. Asked url was " + url.toString(), 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) {
e.printStackTrace();
Log.e("ShopSearch", "The API response is not readable. 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) {
e.printStackTrace();
}
} catch (IOException e) {}
if (conn != null)
conn.disconnect();
}

View File

@ -2,6 +2,7 @@ package com.amine.horaires;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
@ -93,9 +94,9 @@ public class ShopUpdate extends OptionsActivity {
HttpURLConnection conn = null;
InputStream is = null;
String contentAsString = "";
URL url = null;
try {
URL url = params[0];
url = params[0];
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
@ -115,19 +116,17 @@ public class ShopUpdate extends OptionsActivity {
contentAsString = contentAsString + reader.nextLine();
}
} catch (MalformedURLException e) {
e.printStackTrace();
Log.e("ShopUpdate", "The API doesn't respond correctly. Asked url was " + url.toString(), 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) {
e.printStackTrace();
Log.e("ShopUpdate", "The API response is not readable. 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) {
e.printStackTrace();
}
} catch (IOException e) {}
if (conn != null)
conn.disconnect();
}

View File

@ -1,17 +1,16 @@
package com.amine.horaires.util;
import android.util.Log;
import com.amine.horaires.models.Shop;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.*;
import java.util.ArrayList;
/**
@ -215,8 +214,12 @@ public class Parseur {
saxParser.parse(is, handler);
} catch (Exception e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
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;

View File

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