// 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.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import mortar.Blueprint;
import mortar.lib.util.MortarUtil;
package mortar.lib.view;



public abstract class MortarPagerAdapter extends PagerAdapter {

  public abstract Blueprint getScreen(int position);

  public Context getContext(ViewGroup container) {
    return container.getContext();
  }

  @Override public boolean isViewFromObject(View view, Object o) {
    return view == o;
  }

  @Override public Object instantiateItem(ViewGroup container, int position) {
    Blueprint blueprint = getScreen(position);
    View child = MortarUtil.createScreen(getContext(container), blueprint);
    container.addView(child);
    return child;
  }

  @Override public void destroyItem(ViewGroup container, int position, Object object) {
    View child = (View) object;
// 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/view/MortarPagerAdapter.java
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import mortar.Blueprint;
import mortar.lib.util.MortarUtil;

package mortar.lib.view;



public abstract class MortarPagerAdapter extends PagerAdapter {

  public abstract Blueprint getScreen(int position);

  public Context getContext(ViewGroup container) {
    return container.getContext();
  }

  @Override public boolean isViewFromObject(View view, Object o) {
    return view == o;
  }

  @Override public Object instantiateItem(ViewGroup container, int position) {
    Blueprint blueprint = getScreen(position);
    View child = MortarUtil.createScreen(getContext(container), blueprint);
    container.addView(child);
    return child;
  }

  @Override public void destroyItem(ViewGroup container, int position, Object object) {
    View child = (View) object;
    MortarUtil.destroyScreen(getContext(container), child);