Replaced old logcat logging with slf4j for util classes.
parent
3986119b62
commit
4f24cab000
|
@ -4,6 +4,8 @@ import android.location.Location;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -12,12 +14,13 @@ import java.util.List;
|
||||||
* Created by tpolgrabia on 28.08.16.
|
* Created by tpolgrabia on 28.08.16.
|
||||||
*/
|
*/
|
||||||
public class StandardLocationListener implements LocationListener {
|
public class StandardLocationListener implements LocationListener {
|
||||||
|
private static final Logger lg = LoggerFactory.getLogger(StandardLocationListener.class);
|
||||||
private static final String CLASS_TAG = StandardLocationListener.class.getSimpleName();
|
private static final String CLASS_TAG = StandardLocationListener.class.getSimpleName();
|
||||||
private List<StandardLocationListenerCallback> locationChangedCallbacks = new ArrayList<>();
|
private List<StandardLocationListenerCallback> locationChangedCallbacks = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
Log.i(CLASS_TAG, "Location provider changed: " + location);
|
lg.info("Location provider changed: {}", location);
|
||||||
for (StandardLocationListenerCallback callback : locationChangedCallbacks) {
|
for (StandardLocationListenerCallback callback : locationChangedCallbacks) {
|
||||||
callback.callback(location);
|
callback.callback(location);
|
||||||
}
|
}
|
||||||
|
@ -25,17 +28,17 @@ public class StandardLocationListener implements LocationListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
// Log.i(CLASS_TAG, "Location provider status changed")
|
lg.debug("Location provider status changed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String provider) {
|
public void onProviderEnabled(String provider) {
|
||||||
Log.i(CLASS_TAG, "Provider " + provider + " enabled");
|
lg.info("Provider {} enabled", provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String provider) {
|
public void onProviderDisabled(String provider) {
|
||||||
Log.i(CLASS_TAG, "Provider " + provider + " disabled");
|
lg.info("Provider {} disabled", provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCallback(StandardLocationListenerCallback callback) {
|
public void addCallback(StandardLocationListenerCallback callback) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package pl.tpolgrabia.urbanexplorer.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by tpolgrabia on 28.08.16.
|
* Created by tpolgrabia on 28.08.16.
|
||||||
|
|
|
@ -3,8 +3,9 @@ package pl.tpolgrabia.urbanexplorer.utils;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
|
||||||
import com.androidquery.AQuery;
|
import com.androidquery.AQuery;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import pl.tpolgrabia.urbanexplorer.AppConstants;
|
import pl.tpolgrabia.urbanexplorer.AppConstants;
|
||||||
|
|
||||||
import java.net.Authenticator;
|
import java.net.Authenticator;
|
||||||
|
@ -14,15 +15,15 @@ import java.net.PasswordAuthentication;
|
||||||
* Created by Tomasz Półgrabia <tomasz.polgrabia@unicredit.eu> (c310702) on 15.09.2016.
|
* Created by Tomasz Półgrabia <tomasz.polgrabia@unicredit.eu> (c310702) on 15.09.2016.
|
||||||
*/
|
*/
|
||||||
public class NetUtils {
|
public class NetUtils {
|
||||||
private static final String CLASS_TAG = NetUtils.class.getSimpleName();
|
private static final Logger lg = LoggerFactory.getLogger(NetUtils.class);
|
||||||
|
|
||||||
public static AQuery createProxyAQueryInstance(Context ctx) {
|
public static AQuery createProxyAQueryInstance(Context ctx) {
|
||||||
final AQuery aq = new AQuery(ctx);
|
final AQuery aq = new AQuery(ctx);
|
||||||
try {
|
try {
|
||||||
Log.v(CLASS_TAG, "Creating aquery proxy instance");
|
lg.trace("Creating aquery proxy instance");
|
||||||
SharedPreferences sharedPrefs = getDefaultSharedPreferences(ctx);
|
SharedPreferences sharedPrefs = getDefaultSharedPreferences(ctx);
|
||||||
boolean enabled = isProxyEnabled(ctx);
|
boolean enabled = isProxyEnabled(ctx);
|
||||||
Log.v(CLASS_TAG, "Proxy is enabled: " + enabled);
|
lg.trace("Proxy is enabled: {}", enabled);
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return aq;
|
return aq;
|
||||||
}
|
}
|
||||||
|
@ -33,26 +34,27 @@ public class NetUtils {
|
||||||
String httpProxyPort = sharedPrefs.getString(AppConstants.PREF_HTTP_PROXY_PORT_KEY,
|
String httpProxyPort = sharedPrefs.getString(AppConstants.PREF_HTTP_PROXY_PORT_KEY,
|
||||||
AppConstants.DEF_HTTP_PROXY_PORT);
|
AppConstants.DEF_HTTP_PROXY_PORT);
|
||||||
|
|
||||||
Log.v(CLASS_TAG, "Proxy is enabled, host: " + httpProxyHost + ", port: " + httpProxyPort);
|
lg.trace("Proxy is enabled, host: {}, port: {}", httpProxyHost, httpProxyPort);
|
||||||
|
|
||||||
|
|
||||||
if (httpProxyHost == null) {
|
if (httpProxyHost == null) {
|
||||||
return aq;
|
return aq;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.v(CLASS_TAG, "Proxy host: " + httpProxyHost + ", proxy port: " + httpProxyPort);
|
lg.trace("Proxy host: {}, proxy port: {}",
|
||||||
|
httpProxyHost, httpProxyPort);
|
||||||
aq.proxy(httpProxyHost, Integer.parseInt(httpProxyPort));
|
aq.proxy(httpProxyHost, Integer.parseInt(httpProxyPort));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.w(CLASS_TAG, "Invalid proxy auth number format", e);
|
lg.warn("Invalid proxy auth number format", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return aq;
|
return aq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setGlobalProxyAuth(Context ctx) {
|
public static void setGlobalProxyAuth(Context ctx) {
|
||||||
Log.v(CLASS_TAG, "Setting proxy auth");
|
lg.trace("Setting proxy auth");
|
||||||
if (isProxyEnabled(ctx)) {
|
if (isProxyEnabled(ctx)) {
|
||||||
Log.v(CLASS_TAG, "Setting custom proxy auth");
|
lg.trace("Setting custom proxy auth");
|
||||||
SharedPreferences sharedPrefs = getDefaultSharedPreferences(ctx);
|
SharedPreferences sharedPrefs = getDefaultSharedPreferences(ctx);
|
||||||
final String httpProxyUser = sharedPrefs.getString(AppConstants.PREF_HTTP_PROXY_USER_KEY,
|
final String httpProxyUser = sharedPrefs.getString(AppConstants.PREF_HTTP_PROXY_USER_KEY,
|
||||||
AppConstants.DEF_HTTP_PROXY_USER);
|
AppConstants.DEF_HTTP_PROXY_USER);
|
||||||
|
@ -63,7 +65,7 @@ public class NetUtils {
|
||||||
setGlobalProxyAuth(httpProxyUser, httpProxyPass);
|
setGlobalProxyAuth(httpProxyUser, httpProxyPass);
|
||||||
} else {
|
} else {
|
||||||
Authenticator.setDefault(null);
|
Authenticator.setDefault(null);
|
||||||
Log.v(CLASS_TAG, "Setting empty proxy auth");
|
lg.trace("Setting empty proxy auth");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,11 +74,11 @@ public class NetUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setGlobalProxyAuth(final String httpProxyUser, final String httpProxyPass) {
|
private static void setGlobalProxyAuth(final String httpProxyUser, final String httpProxyPass) {
|
||||||
Log.v(CLASS_TAG, "Proxy user: " + httpProxyUser + ", proxy pass: " + httpProxyPass);
|
lg.trace("Proxy user: {}, proxy pass {}", httpProxyUser);
|
||||||
Authenticator.setDefault(new Authenticator() {
|
Authenticator.setDefault(new Authenticator() {
|
||||||
@Override
|
@Override
|
||||||
protected PasswordAuthentication getPasswordAuthentication() {
|
protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
Log.v(CLASS_TAG, "Proxy auth try");
|
lg.trace("Proxy auth try");
|
||||||
return new PasswordAuthentication(httpProxyUser,httpProxyPass.toCharArray());
|
return new PasswordAuthentication(httpProxyUser,httpProxyPass.toCharArray());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package pl.tpolgrabia.urbanexplorer.utils;
|
package pl.tpolgrabia.urbanexplorer.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
|
||||||
import com.androidquery.AQuery;
|
import com.androidquery.AQuery;
|
||||||
import com.androidquery.callback.AjaxCallback;
|
import com.androidquery.callback.AjaxCallback;
|
||||||
import com.androidquery.callback.AjaxStatus;
|
import com.androidquery.callback.AjaxStatus;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseCallback;
|
import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseCallback;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseStatus;
|
import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseStatus;
|
||||||
import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioImageInfo;
|
import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioImageInfo;
|
||||||
|
@ -24,6 +25,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class PanoramioUtils {
|
public class PanoramioUtils {
|
||||||
|
|
||||||
|
private static final Logger lg = LoggerFactory.getLogger(PanoramioUtils.class);
|
||||||
private static final String CLASS_TAG = PanoramioUtils.class.getSimpleName();
|
private static final String CLASS_TAG = PanoramioUtils.class.getSimpleName();
|
||||||
|
|
||||||
private static final String LOCATIONS_LIST_IMAGE_SIZE = "medium";
|
private static final String LOCATIONS_LIST_IMAGE_SIZE = "medium";
|
||||||
|
@ -50,15 +52,15 @@ public class PanoramioUtils {
|
||||||
"&size=" + LOCATIONS_LIST_IMAGE_SIZE +
|
"&size=" + LOCATIONS_LIST_IMAGE_SIZE +
|
||||||
"&order=" + LOCATIONS_ORDER +
|
"&order=" + LOCATIONS_ORDER +
|
||||||
"&mapfilter=true";
|
"&mapfilter=true";
|
||||||
Log.d(CLASS_TAG, "Query: " + aqQuery);
|
lg.debug("Query URL: {}", aqQuery);
|
||||||
aq.ajax(aqQuery,
|
aq.ajax(aqQuery,
|
||||||
JSONObject.class,
|
JSONObject.class,
|
||||||
new AjaxCallback<JSONObject>() {
|
new AjaxCallback<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void callback(String url, JSONObject object, AjaxStatus status) {
|
public void callback(String url, JSONObject object, AjaxStatus status) {
|
||||||
try {
|
try {
|
||||||
Log.d(CLASS_TAG, "Query code: " + status.getCode()
|
lg.debug("Query code: {}, error: {}, message: {}, object: {}",
|
||||||
+ ", error: " + status.getError() + ", message: " + status.getMessage());
|
status.getCode(), status.getError(), status.getMessage(), object);
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +69,7 @@ public class PanoramioUtils {
|
||||||
try {
|
try {
|
||||||
photosInfos = PanoramioUtils.fetchPanoramioImagesFromResponse(object.getJSONArray("photos"));
|
photosInfos = PanoramioUtils.fetchPanoramioImagesFromResponse(object.getJSONArray("photos"));
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
Log.w(CLASS_TAG, "Parse exception", e);
|
lg.warn("Parse exception", e);
|
||||||
photosInfos = new ArrayList<>();
|
photosInfos = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +79,7 @@ public class PanoramioUtils {
|
||||||
photosCount);
|
photosCount);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.w(CLASS_TAG, "Json not supported format", e);
|
lg.warn("Json not supported format", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package pl.tpolgrabia.urbanexplorer.utils;
|
package pl.tpolgrabia.urbanexplorer.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import com.androidquery.AQuery;
|
import com.androidquery.AQuery;
|
||||||
import com.androidquery.callback.AjaxCallback;
|
import com.androidquery.callback.AjaxCallback;
|
||||||
|
@ -10,6 +9,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.WikiResponseCallback;
|
import pl.tpolgrabia.urbanexplorer.callbacks.WikiResponseCallback;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.WikiStatus;
|
import pl.tpolgrabia.urbanexplorer.callbacks.WikiStatus;
|
||||||
import pl.tpolgrabia.urbanexplorer.dto.wiki.app.WikiAppObject;
|
import pl.tpolgrabia.urbanexplorer.dto.wiki.app.WikiAppObject;
|
||||||
|
@ -27,6 +28,7 @@ import java.util.*;
|
||||||
* Created by tpolgrabia on 28.08.16.
|
* Created by tpolgrabia on 28.08.16.
|
||||||
*/
|
*/
|
||||||
public class WikiUtils {
|
public class WikiUtils {
|
||||||
|
private static final Logger lg = LoggerFactory.getLogger(WikiUtils.class);
|
||||||
private static final String CLASS_TAG = WikiUtils.class.getSimpleName();
|
private static final String CLASS_TAG = WikiUtils.class.getSimpleName();
|
||||||
private static final String WIKI_FORMAT = "json";
|
private static final String WIKI_FORMAT = "json";
|
||||||
private static final long WIKI_MIN_RADIUS = 10L;
|
private static final long WIKI_MIN_RADIUS = 10L;
|
||||||
|
@ -68,7 +70,7 @@ public class WikiUtils {
|
||||||
try {
|
try {
|
||||||
callback.callback(WikiStatus.SUCCESS, fetchWikiResponse(object));
|
callback.callback(WikiStatus.SUCCESS, fetchWikiResponse(object));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(CLASS_TAG, "JSon error: " + object.toString(), e);
|
lg.error("JSon error: {}", object, e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callback.callback(WikiStatus.NETWORK_ERROR, null);
|
callback.callback(WikiStatus.NETWORK_ERROR, null);
|
||||||
|
@ -162,10 +164,7 @@ public class WikiUtils {
|
||||||
Long limit,
|
Long limit,
|
||||||
final WikiGeoResponseCallback callback) {
|
final WikiGeoResponseCallback callback) {
|
||||||
|
|
||||||
Log.d(CLASS_TAG, "Latitude: " + latitude +
|
lg.debug("Latitude: {}, longitude: {}, radius: {}, limit: {}", latitude, longitude, radius, limit);
|
||||||
", longitude: " + longitude +
|
|
||||||
", radius: " + radius +
|
|
||||||
", limit: " + limit);
|
|
||||||
|
|
||||||
if (radius == null) {
|
if (radius == null) {
|
||||||
radius = WIKI_STD_RADIUS;
|
radius = WIKI_STD_RADIUS;
|
||||||
|
@ -185,19 +184,19 @@ public class WikiUtils {
|
||||||
"&format=json", JSONObject.class, new AjaxCallback<JSONObject>() {
|
"&format=json", JSONObject.class, new AjaxCallback<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void callback(String url, JSONObject object, AjaxStatus status) {
|
public void callback(String url, JSONObject object, AjaxStatus status) {
|
||||||
Log.v(CLASS_TAG, "Finished waiting for " + url
|
lg.trace("Finished waiting for {} with status {}:{} and response: {}",
|
||||||
+ " with status " + status.getCode() + ":" + status.getMessage()
|
url, status.getCode(), status.getMessage(), object);
|
||||||
+ " and response: " + object);
|
|
||||||
if (status.getCode() == 200) {
|
if (status.getCode() == 200) {
|
||||||
try {
|
try {
|
||||||
callback.callback(WikiStatus.SUCCESS, fetchWikiGeoResponse(object));
|
callback.callback(WikiStatus.SUCCESS, fetchWikiGeoResponse(object));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Log.e(CLASS_TAG, "General error during fetching", t);
|
lg.error("General error during fetching", t);
|
||||||
callback.callback(WikiStatus.GENERAL_ERROR, null);
|
callback.callback(WikiStatus.GENERAL_ERROR, null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(CLASS_TAG, "Couldn't fetch wiki metadata " + object
|
lg.error("Couldn't fetch wiki metadata {}, status: {}:{} from url: {}",
|
||||||
+ ", status: " + status.getCode() + ": " + status.getMessage() + " from url: " + url);
|
object, status.getCode(), status.getMessage(), url);
|
||||||
callback.callback(WikiStatus.NETWORK_ERROR, null);
|
callback.callback(WikiStatus.NETWORK_ERROR, null);
|
||||||
}
|
}
|
||||||
super.callback(url, object, status);
|
super.callback(url, object, status);
|
||||||
|
@ -243,16 +242,14 @@ public class WikiUtils {
|
||||||
final Long limit,
|
final Long limit,
|
||||||
final WikiAppResponseCallback callback) {
|
final WikiAppResponseCallback callback) {
|
||||||
|
|
||||||
Log.d(CLASS_TAG, "Latitude: " + latitude
|
lg.debug("Latitude: {}, longitude: {}, radius: {}, limit: {}",
|
||||||
+ ", longitude: " + longitude
|
latitude, longitude, radius, limit);
|
||||||
+ ", radius: " + radius
|
|
||||||
+ ", limit: " + limit);
|
|
||||||
|
|
||||||
fetchGeoSearchWikiMetadata(ctx, latitude, longitude, radius, limit, new WikiGeoResponseCallback() {
|
fetchGeoSearchWikiMetadata(ctx, latitude, longitude, radius, limit, new WikiGeoResponseCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void callback(WikiStatus status, WikiGeoResponse response) {
|
public void callback(WikiStatus status, WikiGeoResponse response) {
|
||||||
|
|
||||||
Log.v(CLASS_TAG, "Fetching finished with status: " + status + " and values: " + response);
|
lg.trace("Fetching finished with status: {} and values: {}", status, response);
|
||||||
|
|
||||||
if (status != WikiStatus.SUCCESS) {
|
if (status != WikiStatus.SUCCESS) {
|
||||||
Toast.makeText(ctx, "Sorry, couldn't fetch wiki metadata", Toast.LENGTH_SHORT).show();
|
Toast.makeText(ctx, "Sorry, couldn't fetch wiki metadata", Toast.LENGTH_SHORT).show();
|
||||||
|
@ -330,7 +327,7 @@ public class WikiUtils {
|
||||||
try {
|
try {
|
||||||
callback.callback(WikiStatus.SUCCESS, fetchWikiResponse(object));
|
callback.callback(WikiStatus.SUCCESS, fetchWikiResponse(object));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
Log.e(CLASS_TAG, "General error", t);
|
lg.error("General error", t);
|
||||||
callback.callback(WikiStatus.GENERAL_ERROR, null);
|
callback.callback(WikiStatus.GENERAL_ERROR, null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue