package com.unit.util;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

public class GlobalUtil {

    private static Application gApplication;
    private static Activity gMainActivity;

    public static void setApplication(Application application){
        gApplication = application;
    }

    public static Application getApplication(){
        return gApplication;
    }

    public static Context getAppContext() {
        if(gApplication == null) return null;
        return gApplication.getApplicationContext();
    }

    public static void setMainActivity(Activity activity){
        gMainActivity = activity;
    }

    public static Activity getMainActivity(){
        return gMainActivity;
    }

    public static void uiRun(Runnable runnable, long delayMillis){
        if (runnable == null) {
            return;
        }
        if (Looper.myLooper()==Looper.getMainLooper() && delayMillis<=0){
            runnable.run();
            return;
        }
        new Handler(Looper.getMainLooper()).postDelayed(runnable, delayMillis);
    }
}
