android-lib/src/main/java/io/v/android/VAndroidContexts.java
/**
     * Creates a {@link VAndroidContext} with default settings, given a constructor function.
     *
     * @see #withDefaults(Activity, Bundle)
     */
Creates a  VAndroidContext with default settings, given a constructor function.
Creates a VAndroidContext with default settings given a constructor function .
public static <T extends Activity, C extends VAndroidContext> C withDefaults(
            final T activity, final Bundle savedInstanceState,
            final BiFunction<T, ErrorReporter, C> constructor) {
        final FragmentManager mgr = activity.getFragmentManager();
        final ErrorReporterFragment errorReporter;
        final DebugFragment debug;
        if (savedInstanceState == null) {
            errorReporter = new ErrorReporterFragment();
            final FragmentTransaction t = mgr.beginTransaction()
                    .add(errorReporter, ErrorReporterFragment.FRAGMENT_TAG);
            if (Debug.isApkDebug(activity)) {
                Log.i(TAG, "Debug menu enabled");
                debug = new DebugFragment();
                t.add(debug, null);
            } else {
                debug = null;
            }
            t.commit();
        } else {
            errorReporter = ErrorReporterFragment.find(mgr);
            debug = DebugFragment.find(mgr);
        }
        final C vac = constructor.apply(activity, errorReporter);
        if (debug != null) {
            debug.setVAndroidContext(vac);
        }
        return vac;
    }
public static < T extends Activity , C extends VAndroidContext > C withDefaults ( final T activity , final Bundle savedInstanceState , final BiFunction < T , ErrorReporter , C > constructor ) { final FragmentManager mgr = activity . getFragmentManager ( ) ; final ErrorReporterFragment errorReporter ; final DebugFragment debug ; if ( savedInstanceState == null ) { errorReporter = new ErrorReporterFragment ( ) ; final FragmentTransaction t = mgr . beginTransaction ( ) . add ( errorReporter , ErrorReporterFragment . FRAGMENT_TAG ) ; if ( Debug . isApkDebug ( activity ) ) { Log . i ( TAG , "Debug menu enabled" ) ; debug = new DebugFragment ( ) ; t . add ( debug , null ) ; } else { debug = null ; } t . commit ( ) ; } else { errorReporter = ErrorReporterFragment . find ( mgr ) ; debug = DebugFragment . find ( mgr ) ; } final C vac = constructor . apply ( activity , errorReporter ) ; if ( debug != null ) { debug . setVAndroidContext ( vac ) ; } return vac ; }
Creates a {@link VAndroidContext} with default settings, given a constructor function.
Creates a { @link VAndroidContext } with default settings given a constructor function .