Use Timber for logging

This commit is contained in:
veyndan 2017-04-17 16:24:50 +01:00
parent 052d0c9c8e
commit d33935c70f
35 changed files with 238 additions and 259 deletions

View file

@ -14,8 +14,6 @@ public class NearbyActivity extends BaseActivity {
private LocationServiceManager locationManager;
private static final String TAG = NearbyActivity.class.getName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

View file

@ -1,7 +1,6 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -11,6 +10,8 @@ import fr.free.nrw.commons.R;
import java.util.List;
import timber.log.Timber;
public class NearbyAdapter extends ArrayAdapter<Place> {
private List<Place> placesList;
private Context context;
@ -33,7 +34,7 @@ public class NearbyAdapter extends ArrayAdapter<Place> {
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
Place place = getItem(position);
Log.v("NearbyAdapter", "" + place);
Timber.v(String.valueOf(place));
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {

View file

@ -10,7 +10,6 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -22,6 +21,7 @@ import butterknife.ButterKnife;
import butterknife.OnItemClick;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.location.LatLng;
import timber.log.Timber;
import java.util.Collections;
import java.util.Comparator;
@ -40,8 +40,6 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
private boolean isTaskRunning = false;
private static final String TAG = NearbyListFragment.class.getName();
public NearbyListFragment() {
}
@ -55,7 +53,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d(TAG, "NearbyListFragment created");
Timber.d("NearbyListFragment created");
View view = inflater.inflate(R.layout.fragment_nearby, container, false);
ButterKnife.bind(this, view);
return view;
@ -69,7 +67,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
nearbyAsyncTask = new NearbyAsyncTask(this);
nearbyAsyncTask.execute();
progressBar.setVisibility(View.VISIBLE);
Log.d(TAG, "Saved instance state is null, populating ListView");
Timber.d("Saved instance state is null, populating ListView");
} else {
progressBar.setVisibility(View.GONE);
}
@ -174,10 +172,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
double latitude = placeLatLng.latitude;
double longitude = placeLatLng.longitude;
Log.d(TAG, "Item at position "
+ position + " has coords: Lat: "
+ latitude + " Long: "
+ longitude);
Timber.d("Item at position %d has coords: Lat: %f Long: %f", position, latitude, longitude);
//Open map app at given position
Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + latitude + "," + longitude);
@ -189,7 +184,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
}
private List<Place> loadAttractionsFromLocation(LatLng curLatLng) {
Log.d(TAG, "Loading attractions near " + curLatLng);
Timber.d("Loading attractions near %s", curLatLng);
if (curLatLng == null) {
return Collections.emptyList();
}
@ -199,7 +194,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
curLatLng, Locale.getDefault().getLanguage())
: NearbyPlaces.getInstance().getFromWikiNeedsPictures();
if (curLatLng != null) {
Log.d(TAG, "Sorting places by distance...");
Timber.d("Sorting places by distance...");
final Map<Place, Double> distances = new HashMap<>();
for (Place place: places) {
distances.put(place, computeDistanceBetween(place.location, curLatLng));

View file

@ -2,7 +2,6 @@ package fr.free.nrw.commons.nearby;
import android.net.Uri;
import android.os.StrictMode;
import android.util.Log;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.location.LatLng;
@ -20,10 +19,10 @@ import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import timber.log.Timber;
public class NearbyPlaces {
private static final String TAG = NearbyPlaces.class.getName();
private static final int MIN_RESULTS = 40;
private static final double INITIAL_RADIUS = 1.0;
private static final double MAX_RADIUS = 300.0;
@ -81,7 +80,7 @@ public class NearbyPlaces {
// increase the radius gradually to find a satisfactory number of nearby places
while (radius < MAX_RADIUS) {
places = getFromWikidataQuery(curLatLng, lang, radius);
Log.d(TAG, places.size() + " results at radius: " + radius);
Timber.d("%d results at radius: %f", places.size(), radius);
if (places.size() >= MIN_RESULTS) {
break;
} else {
@ -89,10 +88,10 @@ public class NearbyPlaces {
}
}
} catch (IOException e) {
Log.d(TAG, "" + e.toString());
Timber.d(e.toString());
// errors tend to be caused by too many results (and time out)
// try a small radius next time
Log.d(TAG, "back to initial radius: " + radius);
Timber.d("back to initial radius: %f", radius);
radius = INITIAL_RADIUS;
}
return places;
@ -107,15 +106,15 @@ public class NearbyPlaces {
.replace("${LANG}", "" + lang);
query = URLEncoder.encode(query, "utf-8").replace("+", "%20");
String url = WIKIDATA_QUERY_URL.replace("${QUERY}", query);
Log.d(TAG, url);
Timber.d(url);
URLConnection conn = new URL(url).openConnection();
conn.setRequestProperty("Accept", "text/tab-separated-values");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
Log.d(TAG, "Reading from query result...");
Timber.d("Reading from query result...");
while ((line = in.readLine()) != null) {
Log.v(TAG, line);
Timber.v(line);
line = line + "\n"; // to pad columns and make fields a fixed size
if (!line.startsWith("\"Point")) {
continue;
@ -170,7 +169,7 @@ public class NearbyPlaces {
boolean firstLine = true;
String line;
Log.d(TAG, "Reading from CSV file...");
Timber.d("Reading from CSV file...");
while ((line = in.readLine()) != null) {
@ -209,7 +208,7 @@ public class NearbyPlaces {
in.close();
} catch (IOException e) {
Log.d(TAG, e.toString());
Timber.d(e.toString());
}
}
return places;