Added slf4j and logback for android to the classpath and initialized.

Replaced log calls for MainActivity.
master
Tomasz Półgrabia 2016-09-17 12:59:14 +02:00
parent 5347f67d74
commit bbc7666f95
3 changed files with 42 additions and 17 deletions

View File

@ -48,4 +48,10 @@ dependencies {
transitive = true; transitive = true;
} }
compile 'org.apache.commons:commons-lang3:3.4' compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'com.github.tony19:logback-android-core:1.1.1-6'
compile('com.github.tony19:logback-android-classic:1.1.1-6') {
// workaround issue #73
exclude group: 'com.google.android', module: 'android'
}
} }

View File

@ -0,0 +1,16 @@
<configuration>
<appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
<tagEncoder>
<pattern>%logger{12}</pattern>
</tagEncoder>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-20thread] %-5level %logger{36} - %msg</pattern>
</encoder>
</appender>
<logger name="pl.tpolgrabia.urbanexplorer" level="ALL"/>
<root level="INFO">
<appender-ref ref="logcat" />
</root>
</configuration>

View File

@ -14,7 +14,6 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GestureDetectorCompat; import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.*; import android.view.*;
import android.widget.Toast; import android.widget.Toast;
import com.androidquery.util.AQUtility; import com.androidquery.util.AQUtility;
@ -24,6 +23,8 @@ import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import io.fabric.sdk.android.Fabric; import io.fabric.sdk.android.Fabric;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.urbanexplorer.activities.SettingsActivity; import pl.tpolgrabia.urbanexplorer.activities.SettingsActivity;
import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListener; import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListener;
import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListenerCallback; import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListenerCallback;
@ -41,6 +42,8 @@ import pl.tpolgrabia.urbanexplorer.views.SwipeFrameLayout;
public class MainActivity extends ActionBarActivity { public class MainActivity extends ActionBarActivity {
private static final Logger lg = LoggerFactory.getLogger(MainActivity.class);
private static final int LOCATION_SETTINGS_REQUEST_ID = 1; private static final int LOCATION_SETTINGS_REQUEST_ID = 1;
private static final String CLASS_TAG = MainActivity.class.getSimpleName(); private static final String CLASS_TAG = MainActivity.class.getSimpleName();
private static final String PHOTO_BACKSTACK = "PHOTO_BACKSTACK"; private static final String PHOTO_BACKSTACK = "PHOTO_BACKSTACK";
@ -85,7 +88,7 @@ public class MainActivity extends ActionBarActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.v(CLASS_TAG, "onCreate"); lg.trace("onCreate");
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
AQUtility.setDebug(true); AQUtility.setDebug(true);
@ -115,9 +118,9 @@ public class MainActivity extends ActionBarActivity {
Fabric.with(fabric); Fabric.with(fabric);
Integer fragId = savedInstanceState != null ? savedInstanceState.getInt(FRAG_ID) : null; Integer fragId = savedInstanceState != null ? savedInstanceState.getInt(FRAG_ID) : null;
Log.v(CLASS_TAG, "Restored orig frag id: " + fragId); lg.trace("Restored orig frag id: {}", fragId);
currentFragmentId = fragId == null ? 0 : fragId; currentFragmentId = fragId == null ? 0 : fragId;
Log.v(CLASS_TAG, "Set final frag id: " + fragId); lg.trace("Set final frag id: {}", fragId);
photoInfo = savedInstanceState != null ? (PanoramioImageInfo) savedInstanceState.getSerializable(PHOTO_INFO) : null; photoInfo = savedInstanceState != null ? (PanoramioImageInfo) savedInstanceState.getSerializable(PHOTO_INFO) : null;
switchFragment(); switchFragment();
@ -163,7 +166,7 @@ public class MainActivity extends ActionBarActivity {
wikiLocationsFragment.fetchWikiLocations(); wikiLocationsFragment.fetchWikiLocations();
break; break;
default: default:
Log.w(CLASS_TAG, "Unknown current fragment ID"); lg.warn("Unknown current fragment ID");
break; break;
} }
return true; return true;
@ -200,13 +203,13 @@ public class MainActivity extends ActionBarActivity {
switch (currentFragmentId) { switch (currentFragmentId) {
case HOME_FRAGMENT_ID: case HOME_FRAGMENT_ID:
// switch to home fragment // switch to home fragment
Log.d(CLASS_TAG, "Switching to home fragment"); lg.debug("Switching to home fragment");
final HomeFragment fragment = new HomeFragment(); final HomeFragment fragment = new HomeFragment();
switchFragment(fragment, HomeFragment.TAG); switchFragment(fragment, HomeFragment.TAG);
break; break;
case WIKI_FRAGMENT_ID: case WIKI_FRAGMENT_ID:
// switch to wiki fragment // switch to wiki fragment
Log.d(CLASS_TAG, "Switching to wiki fragment"); lg.debug("Switching to wiki fragment");
switchFragment(new WikiLocationsFragment(), WikiLocationsFragment.TAG); switchFragment(new WikiLocationsFragment(), WikiLocationsFragment.TAG);
break; break;
} }
@ -217,11 +220,11 @@ public class MainActivity extends ActionBarActivity {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction ctx = fragmentManager.beginTransaction(); FragmentTransaction ctx = fragmentManager.beginTransaction();
Log.v(CLASS_TAG, "old fragment id: " + oldFragmentId + ", current fragment id: " + currentFragmentId); lg.trace("old fragment id: {}, current fragment id: {}", oldFragmentId, currentFragmentId);
if (oldFragmentId != currentFragmentId) { if (oldFragmentId != currentFragmentId) {
if (currentFragmentId < oldFragmentId) { if (currentFragmentId < oldFragmentId) {
// slide left animation // slide left animation
Log.v(CLASS_TAG, "sliding left animation"); lg.trace("sliding left animation");
ctx.setCustomAnimations( ctx.setCustomAnimations(
R.anim.slide_in_left, R.anim.slide_in_left,
R.anim.slide_out_left, R.anim.slide_out_left,
@ -229,7 +232,7 @@ public class MainActivity extends ActionBarActivity {
R.anim.slide_out_right); R.anim.slide_out_right);
} else { } else {
// slide right animation // slide right animation
Log.v(CLASS_TAG, "sliding right animation"); lg.trace("sliding right animation");
ctx.setCustomAnimations( ctx.setCustomAnimations(
R.anim.slide_in_right, R.anim.slide_in_right,
R.anim.slide_out_right, R.anim.slide_out_right,
@ -300,7 +303,7 @@ public class MainActivity extends ActionBarActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
Log.v(CLASS_TAG, "onResume"); lg.trace("onResume");
String locationProvider = LocationUtils.getDefaultLocation(this); String locationProvider = LocationUtils.getDefaultLocation(this);
if (locationProvider != null) { if (locationProvider != null) {
LocationManager locationService = (LocationManager)getSystemService(LOCATION_SERVICE); LocationManager locationService = (LocationManager)getSystemService(LOCATION_SERVICE);
@ -318,7 +321,7 @@ public class MainActivity extends ActionBarActivity {
"pref_gps_distance_freq", "pref_gps_distance_freq",
String.valueOf(AppConstants.GPS_LOCATION_DISTANCE_FREQ)); String.valueOf(AppConstants.GPS_LOCATION_DISTANCE_FREQ));
Log.d(CLASS_TAG, "Pref GPS distance update frequency " + prefDistanceUpdateFreq); lg.debug("Pref GPS distance update frequency {}", prefDistanceUpdateFreq);
return NumberUtils.safeParseFloat(prefDistanceUpdateFreq); return NumberUtils.safeParseFloat(prefDistanceUpdateFreq);
} }
@ -328,14 +331,14 @@ public class MainActivity extends ActionBarActivity {
"pref_gps_update_freq", "pref_gps_update_freq",
String.valueOf(AppConstants.GPS_LOCATION_UPDATE_FREQ)); String.valueOf(AppConstants.GPS_LOCATION_UPDATE_FREQ));
Log.d(CLASS_TAG, "Pref GPS location update frequency " + prefGpsUpdateFreq); lg.debug("Pref GPS location update frequency {}", prefGpsUpdateFreq);
return Math.round(NumberUtils.safeParseDouble(prefGpsUpdateFreq)* 60.0 * 1000.0); return Math.round(NumberUtils.safeParseDouble(prefGpsUpdateFreq)* 60.0 * 1000.0);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
Log.v(CLASS_TAG, "onPause"); lg.trace("onPause");
if (locationServicesActivated) { if (locationServicesActivated) {
LocationManager locationService = (LocationManager)getSystemService(LOCATION_SERVICE); LocationManager locationService = (LocationManager)getSystemService(LOCATION_SERVICE);
locationService.removeUpdates(locationCallback); locationService.removeUpdates(locationCallback);
@ -345,7 +348,7 @@ public class MainActivity extends ActionBarActivity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
Log.v(CLASS_TAG, "onDestroy"); lg.trace("onDestroy");
} }
@Override @Override
@ -373,7 +376,7 @@ public class MainActivity extends ActionBarActivity {
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
Log.v(CLASS_TAG, "1 Saving current fragment id: " + currentFragmentId); lg.trace("1 Saving current fragment id: {}", currentFragmentId);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putSerializable(FRAG_ID, currentFragmentId); outState.putSerializable(FRAG_ID, currentFragmentId);
outState.putSerializable(PHOTO_INFO, photoInfo); outState.putSerializable(PHOTO_INFO, photoInfo);
@ -383,7 +386,7 @@ public class MainActivity extends ActionBarActivity {
// editor.putInt(FRAG_ID, currentFragmentId); // editor.putInt(FRAG_ID, currentFragmentId);
// editor.commit(); // editor.commit();
Log.v(CLASS_TAG, "2 Saving current fragment id: " + currentFragmentId); lg.trace("2 Saving current fragment id: {}", currentFragmentId);
} }
} }