Skip to content

Instantly share code, notes, and snippets.

@benoitjadinon
Last active April 18, 2016 10:20
Show Gist options
  • Save benoitjadinon/197ea8ac1fb96dd8d063 to your computer and use it in GitHub Desktop.
Save benoitjadinon/197ea8ac1fb96dd8d063 to your computer and use it in GitHub Desktop.
prints the lifecycle of the class it is injected into
import android.app.Activity;
import android.util.Log;
import com.google.inject.Inject;
import roboguice.activity.event.*;
import roboguice.context.event.*;
import roboguice.event.Observes;
import roboguice.inject.ContextSingleton;
/**
* Created by Benoit Jadinon on 10/09/15.
*
* RoboGuice Injection that will log the lifecycle of the class it is injected into
*
* USAGE :
@SuppressWarnings("unused")
@Inject
RoboLogLifeCycleController mLifeCycleLogger;
*/
@SuppressWarnings("unused")
@ContextSingleton
public class RoboLifecycleLogger {
@Inject
Activity mActivity;
protected void print(Class eventClass, String eventValue) {
if (!BuildConfig.DEBUG)
return;
String tag = "DEBUG LifeCycle";
if (mActivity != null)
tag += " " + mActivity.getClass().getName();
String event = eventClass.getSimpleName().replace("Event", "");
Log.v(tag, event);
}
//region roboguice.activity.event.*
protected void OnActivityResult(@Observes OnActivityResultEvent event){
print(event.getClass(), event.toString());
}
protected void OnContentChanged(@Observes OnContentChangedEvent event){
print(event.getClass(), event.toString());
}
protected void OnNewIntent(@Observes OnNewIntentEvent event){
print(event.getClass(), event.toString());
}
protected void OnPause(@Observes OnPauseEvent event){
print(event.getClass(), event.toString());
}
protected void OnRestart(@Observes OnRestartEvent event){
print(event.getClass(), event.toString());
}
protected void OnResume(@Observes OnResumeEvent event){
print(event.getClass(), event.toString());
}
protected void OnSaveInstanceState(@Observes OnSaveInstanceStateEvent event){
print(event.getClass(), event.toString());
}
protected void OnStop(@Observes OnStopEvent event){
print(event.getClass(), event.toString());
}
//endregion roboguice.activity.event.*
//region roboguice.context.event.*
protected void OnConfigurationChanged(@Observes OnConfigurationChangedEvent event){
print(event.getClass(), event.toString());
}
protected void OnCreate(@Observes OnCreateEvent event){
print(event.getClass(), event.toString());
}
protected void OnDestroy(@Observes OnDestroyEvent event){
print(event.getClass(), event.toString());
}
protected void OnStart(@Observes OnStartEvent event){
print(event.getClass(), event.toString());
}
//endregion roboguice.context.event.*
/*
RG docs was talking about this one, but it's not available anymore
protected void OnContentViewAvailable(@Observes OnContentViewAvailableEvent event){
print(event.getClass(), event.toString());
}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment