// Path: lib-core/src/main/java/xdroid/core/ObjectUtils.java
// @SuppressWarnings("unchecked")
// public static <T> T cast(Object object) {
//     return (T) object;
// }
// 
// Path: lib-core/src/main/java/xdroid/core/ObjectUtils.java
// public static <T> T notNull(T object) {
//     if (object == null) {
//         throw new NullPointerException();
//     }
// 
//     return object;
// }


import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;
import java.lang.reflect.Method;
import static xdroid.core.ObjectUtils.cast;
import static xdroid.core.ObjectUtils.notNull;
package xdroid.core;




/**
 * @author Oleksii Kropachov (o.kropachov@shamanland.com)
 */
public final class Global {
    private static Context sContext;

    private Global() {
        // disallow public access
    }

    public static void setContext(Context context) {
        sContext = context;
    }

    public static Context getContext() {
        if (sContext == null) {
            sContext = CurrentApplicationHolder.INSTANCE;
        }

        return notNull(sContext);
    }

    public static Resources getResources() {
        return notNull(getContext().getResources());
    }

    public static Handler getUiHandler() {
        return UiHandlerHolder.INSTANCE;
    }

    public static Handler getBackgroundHandler() {
        return BackgroundHandlerHolder.INSTANCE;
    }

    static class CurrentApplicationHolder {
        static final Application INSTANCE;

        static {
            try {
                Class<?> clazz = Class.forName("android.app.ActivityThread");
                Method method = ReflectUtils.getMethod(clazz, "currentApplication");
// Path: lib-core/src/main/java/xdroid/core/ObjectUtils.java
// @SuppressWarnings("unchecked")
// public static <T> T cast(Object object) {
//     return (T) object;
// }
// 
// Path: lib-core/src/main/java/xdroid/core/ObjectUtils.java
// public static <T> T notNull(T object) {
//     if (object == null) {
//         throw new NullPointerException();
//     }
// 
//     return object;
// }


// Path: lib-core/src/main/java/xdroid/core/Global.java
import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;
import java.lang.reflect.Method;
import static xdroid.core.ObjectUtils.cast;
import static xdroid.core.ObjectUtils.notNull;

package xdroid.core;




/**
 * @author Oleksii Kropachov (o.kropachov@shamanland.com)
 */
public final class Global {
    private static Context sContext;

    private Global() {
        // disallow public access
    }

    public static void setContext(Context context) {
        sContext = context;
    }

    public static Context getContext() {
        if (sContext == null) {
            sContext = CurrentApplicationHolder.INSTANCE;
        }

        return notNull(sContext);
    }

    public static Resources getResources() {
        return notNull(getContext().getResources());
    }

    public static Handler getUiHandler() {
        return UiHandlerHolder.INSTANCE;
    }

    public static Handler getBackgroundHandler() {
        return BackgroundHandlerHolder.INSTANCE;
    }

    static class CurrentApplicationHolder {
        static final Application INSTANCE;

        static {
            try {
                Class<?> clazz = Class.forName("android.app.ActivityThread");
                Method method = ReflectUtils.getMethod(clazz, "currentApplication");
                INSTANCE = cast(ReflectUtils.invokeStaticMethod(method));