// Path: lib/src/main/java/mortar/lib/activity/ResumeAndPauseActivity.java
// public interface ResumeAndPauseActivity {
// 
//   boolean isRunning();
//   MortarScope getMortarScope();
//   ResumeAndPauseOwner getResumeAndPausePresenter();
// 
// }
// 
// Path: lib/src/main/java/mortar/lib/activity/ResumeAndPauseOwner.java
// public class ResumeAndPauseOwner extends Presenter<ResumeAndPauseActivity>
//     implements ResumeAndPauseRegistrar {
// 
//   private final Set<Registration> registrations = new LinkedHashSet<Registration>();
// 
//   public ResumeAndPauseOwner() {
//   }
// 
//   @Override protected MortarScope extractScope(ResumeAndPauseActivity view) {
//     return view.getMortarScope();
//   }
// 
//   @Override public void onExitScope() {
//     registrations.clear();
//   }
// 
//   @Override public void register(MortarScope scope, ResumesAndPauses listener) {
//     Registration registration = new Registration(listener);
//     scope.register(registration);
// 
//     boolean added = registrations.add(registration);
//     if (added && isRunning()) {
//       listener.onResume();
//     }
//   }
// 
//   @Override public boolean isRunning() {
//     return getView() != null && getView().isRunning();
//   }
// 
//   public void activityPaused() {
//     for (Registration registration : registrations) {
//       registration.registrant.onPause();
//     }
//   }
// 
//   public void activityResumed() {
//     for (Registration registration : registrations) {
//       registration.registrant.onResume();
//     }
//   }
// 
//   private class Registration implements Scoped {
//     final ResumesAndPauses registrant;
// 
//     private Registration(ResumesAndPauses registrant) {
//       this.registrant = registrant;
//     }
// 
//     @Override public void onEnterScope(MortarScope scope) {
//     }
// 
//     @Override public void onExitScope() {
//       if (registrant.isRunning())
//         registrant.onPause();
//       registrations.remove(this);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//       if (this == o) return true;
//       if (o == null || getClass() != o.getClass()) return false;
// 
//       Registration that = (Registration) o;
// 
//       return registrant.equals(that.registrant);
//     }
// 
//     @Override
//     public int hashCode() {
//       return registrant.hashCode();
//     }
//   }
// }
// 
// Path: lib/src/main/java/mortar/lib/activity/ResumesAndPauses.java
// public interface ResumesAndPauses {
//   void onResume();
//   void onPause();
// 
//   /**
//    * @return true if is running, meaning has been resumed, and has not been paused yet; false otherwise
//    */
//   boolean isRunning();
// }
// 
// Path: lib/src/main/java/mortar/lib/util/MortarUtil.java
// public class MortarUtil {
// 
//   public static View createScreen(Context context, Blueprint screen) {
//     MortarScope scope = Mortar.getScope(context);
//     MortarScope newChildScope = scope.requireChild(screen);
// 
//     Context childContext = newChildScope.createContext(context);
//     return Layouts.createView(childContext, screen);
//   }
// 
//   public static int getLayoutId(Blueprint screen) {
//     Class<? extends Blueprint> screenType = screen.getClass();
//     Layout layoutAnnotation = screenType.getAnnotation(Layout.class);
//     if (layoutAnnotation == null) {
//       throw new IllegalArgumentException(
//           String.format("@%s annotation not found on class %s", Layout.class.getSimpleName(),
//               screenType.getName()));
//     }
// 
//     return layoutAnnotation.value();
//   }
// 
//   public static void destroyScreen(View view) {
//     destroyScreen(view.getContext().getApplicationContext(), view);
//   }
// 
//   public static void destroyScreen(Context parentContext, View view) {
//     MortarScope parentScope = Mortar.getScope(parentContext);
//     MortarScope oldChildScope = Mortar.getScope(view.getContext());
//     parentScope.destroyChild(oldChildScope);
//   }
// 
//   public static Activity getActivity(Context context) {
//     Context currentContext = context;
//     while (currentContext instanceof ContextWrapper) {
//       currentContext = ((ContextWrapper) currentContext).getBaseContext();
// 
//       if (currentContext instanceof Activity) {
//         return (Activity) currentContext;
//       } else if (currentContext instanceof Application) {
//         return null;
//       }
//     }
// 
//     return null;
//   }
// 
// }


import android.app.Activity;
import android.view.View;
import mortar.MortarScope;
import mortar.ViewPresenter;
import mortar.lib.activity.ResumeAndPauseActivity;
import mortar.lib.activity.ResumeAndPauseOwner;
import mortar.lib.activity.ResumesAndPauses;
import mortar.lib.util.MortarUtil;
package mortar.lib.presenter;



public abstract class ResumeAndPausePresenter<V extends View> extends ViewPresenter<V> 
    implements ResumesAndPauses {

  private ResumeAndPauseOwner mResumeAndPauseOwner = null;
  private boolean mIsRunning = false;
  
  @Override protected void onEnterScope(MortarScope scope) {
    super.onEnterScope(scope);
    
    Activity activity = MortarUtil.getActivity(getView().getContext());
// Path: lib/src/main/java/mortar/lib/activity/ResumeAndPauseActivity.java
// public interface ResumeAndPauseActivity {
// 
//   boolean isRunning();
//   MortarScope getMortarScope();
//   ResumeAndPauseOwner getResumeAndPausePresenter();
// 
// }
// 
// Path: lib/src/main/java/mortar/lib/activity/ResumeAndPauseOwner.java
// public class ResumeAndPauseOwner extends Presenter<ResumeAndPauseActivity>
//     implements ResumeAndPauseRegistrar {
// 
//   private final Set<Registration> registrations = new LinkedHashSet<Registration>();
// 
//   public ResumeAndPauseOwner() {
//   }
// 
//   @Override protected MortarScope extractScope(ResumeAndPauseActivity view) {
//     return view.getMortarScope();
//   }
// 
//   @Override public void onExitScope() {
//     registrations.clear();
//   }
// 
//   @Override public void register(MortarScope scope, ResumesAndPauses listener) {
//     Registration registration = new Registration(listener);
//     scope.register(registration);
// 
//     boolean added = registrations.add(registration);
//     if (added && isRunning()) {
//       listener.onResume();
//     }
//   }
// 
//   @Override public boolean isRunning() {
//     return getView() != null && getView().isRunning();
//   }
// 
//   public void activityPaused() {
//     for (Registration registration : registrations) {
//       registration.registrant.onPause();
//     }
//   }
// 
//   public void activityResumed() {
//     for (Registration registration : registrations) {
//       registration.registrant.onResume();
//     }
//   }
// 
//   private class Registration implements Scoped {
//     final ResumesAndPauses registrant;
// 
//     private Registration(ResumesAndPauses registrant) {
//       this.registrant = registrant;
//     }
// 
//     @Override public void onEnterScope(MortarScope scope) {
//     }
// 
//     @Override public void onExitScope() {
//       if (registrant.isRunning())
//         registrant.onPause();
//       registrations.remove(this);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//       if (this == o) return true;
//       if (o == null || getClass() != o.getClass()) return false;
// 
//       Registration that = (Registration) o;
// 
//       return registrant.equals(that.registrant);
//     }
// 
//     @Override
//     public int hashCode() {
//       return registrant.hashCode();
//     }
//   }
// }
// 
// Path: lib/src/main/java/mortar/lib/activity/ResumesAndPauses.java
// public interface ResumesAndPauses {
//   void onResume();
//   void onPause();
// 
//   /**
//    * @return true if is running, meaning has been resumed, and has not been paused yet; false otherwise
//    */
//   boolean isRunning();
// }
// 
// Path: lib/src/main/java/mortar/lib/util/MortarUtil.java
// public class MortarUtil {
// 
//   public static View createScreen(Context context, Blueprint screen) {
//     MortarScope scope = Mortar.getScope(context);
//     MortarScope newChildScope = scope.requireChild(screen);
// 
//     Context childContext = newChildScope.createContext(context);
//     return Layouts.createView(childContext, screen);
//   }
// 
//   public static int getLayoutId(Blueprint screen) {
//     Class<? extends Blueprint> screenType = screen.getClass();
//     Layout layoutAnnotation = screenType.getAnnotation(Layout.class);
//     if (layoutAnnotation == null) {
//       throw new IllegalArgumentException(
//           String.format("@%s annotation not found on class %s", Layout.class.getSimpleName(),
//               screenType.getName()));
//     }
// 
//     return layoutAnnotation.value();
//   }
// 
//   public static void destroyScreen(View view) {
//     destroyScreen(view.getContext().getApplicationContext(), view);
//   }
// 
//   public static void destroyScreen(Context parentContext, View view) {
//     MortarScope parentScope = Mortar.getScope(parentContext);
//     MortarScope oldChildScope = Mortar.getScope(view.getContext());
//     parentScope.destroyChild(oldChildScope);
//   }
// 
//   public static Activity getActivity(Context context) {
//     Context currentContext = context;
//     while (currentContext instanceof ContextWrapper) {
//       currentContext = ((ContextWrapper) currentContext).getBaseContext();
// 
//       if (currentContext instanceof Activity) {
//         return (Activity) currentContext;
//       } else if (currentContext instanceof Application) {
//         return null;
//       }
//     }
// 
//     return null;
//   }
// 
// }


// Path: lib/src/main/java/mortar/lib/presenter/ResumeAndPausePresenter.java
import android.app.Activity;
import android.view.View;
import mortar.MortarScope;
import mortar.ViewPresenter;
import mortar.lib.activity.ResumeAndPauseActivity;
import mortar.lib.activity.ResumeAndPauseOwner;
import mortar.lib.activity.ResumesAndPauses;
import mortar.lib.util.MortarUtil;

package mortar.lib.presenter;



public abstract class ResumeAndPausePresenter<V extends View> extends ViewPresenter<V> 
    implements ResumesAndPauses {

  private ResumeAndPauseOwner mResumeAndPauseOwner = null;
  private boolean mIsRunning = false;
  
  @Override protected void onEnterScope(MortarScope scope) {
    super.onEnterScope(scope);
    
    Activity activity = MortarUtil.getActivity(getView().getContext());
    if (activity instanceof ResumeAndPauseActivity) {