提交 bc7226b0 编写于 作者: B BlueRiverInteractive 提交者: Jake Wharton

Add support for iOS with RoboVM.

上级 e058a106
......@@ -20,6 +20,7 @@ import android.os.Handler;
import android.os.Looper;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.Executor;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
......@@ -44,6 +45,11 @@ class Platform {
return new Java8();
} catch (ClassNotFoundException ignored) {
}
try {
Class.forName("org.robovm.apple.foundation.NSObject");
return new IOS();
} catch (ClassNotFoundException ignored) {
}
return new Platform();
}
......@@ -98,4 +104,46 @@ class Platform {
}
}
}
static class IOS extends Platform {
@Override CallAdapter.Factory defaultCallAdapterFactory(Executor callbackExecutor) {
if (callbackExecutor == null) {
callbackExecutor = new MainThreadExecutor();
}
return new ExecutorCallAdapterFactory(callbackExecutor);
}
static class MainThreadExecutor implements Executor {
private static Object queue;
private static Method addOperation;
static {
try {
// queue = NSOperationQueue.getMainQueue();
Class<?> operationQueue = Class.forName("org.robovm.apple.foundation.NSOperationQueue");
queue = operationQueue.getDeclaredMethod("getMainQueue").invoke(null);
addOperation = operationQueue.getDeclaredMethod("addOperation", Runnable.class);
} catch (Exception e) {
throw new AssertionError(e);
}
}
@Override public void execute(Runnable r) {
try {
// queue.addOperation(r);
addOperation.invoke(queue, r);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else if (cause instanceof Error) {
throw (Error) cause;
}
throw new RuntimeException(cause);
}
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册