package com.ee.core.internal;

import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.widget.FrameLayout;

import com.ee.core.Logger;

/**
 * Created by Zinge on 10/9/17.
 */

public class Utils {
    private static final Logger _logger = new Logger(Utils.class.getName());

    public static FrameLayout getRootView(Activity activity) {
        return (FrameLayout) activity.findViewById(android.R.id.content).getRootView();
    }

    private static native void signal();

    @SuppressWarnings("unused")
    public static void runOnUiThread() {
        if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
            signal();
        } else {
            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                    signal();
                }
            });
        }
    }

    public static void checkMainThread() {
        if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
            _logger.error("Current thread is not the main thread");
            assert false;
        }
    }

    @NonNull
    public static String toString(boolean value) {
        return value ? "true" : "false";
    }

    @NonNull
    public static Boolean toBoolean(@NonNull String value) {
        assert value.equals("true") || value.equals("false");
        return value.equals("true");
    }
}

@@ -149,16 +149,60 @@
 onNull;%0A
+import android.support.annotation.Nullable;%0A
 import a
@@ -686,60 +686,14 @@
 if (
-Thread.currentThread() == Looper.getMainLooper().get
+isMain
 Thre
@@ -817,16 +817,33 @@
         
+ boolean result =
  handler
@@ -991,16 +991,134 @@
     %7D);%0A
+            if (!result) %7B%0A                _logger.error(%22runOnUiThread: failed to post the runnable%22);%0A            %7D%0A
         
@@ -1185,60 +1185,15 @@
 if (
-Thread.currentThread() != Looper.getMainLooper().get
+!isMain
 Thre
@@ -1303,32 +1303,159 @@
        %7D%0A    %7D%0A%0A
+    public static boolean isMainThread() %7B%0A        return Thread.currentThread() == Looper.getMainLooper().getThread();%0A    %7D%0A%0A
     @NonNull%0A   
@@ -1728,11 +1728,233 @@
 );%0A    %7D
+%0A%0A    /// https://stackoverflow.com/questions/1069066/get-current-stack-trace-in-java%0A    @NonNull%0A    public static StackTraceElement%5B%5D getCurrentStackTrace() %7B%0A        return Thread.currentThread().getStackTrace();%0A    %7D
 %0A%7D%0A

Update utils.