author | Jaroslav Tulach <jtulach@netbeans.org> |
Mon, 10 Mar 2014 12:56:48 +0100 | |
branch | ibrwsr |
changeset 101 | 5ef40158eb9c |
permissions | -rw-r--r-- |
jtulach@101 | 1 |
package org.apidesign.demo.minesweeper; |
jtulach@101 | 2 |
|
jtulach@101 | 3 |
import java.io.IOException; |
jtulach@101 | 4 |
import java.net.URI; |
jtulach@101 | 5 |
import java.util.logging.Logger; |
jtulach@101 | 6 |
import org.apidesign.html.brwsr.XtrnlBrwsrPrsntr; |
jtulach@101 | 7 |
import org.robovm.cocoatouch.foundation.NSURL; |
jtulach@101 | 8 |
import org.robovm.cocoatouch.uikit.UIWebView; |
jtulach@101 | 9 |
import org.robovm.objc.ObjCBlock; |
jtulach@101 | 10 |
import org.robovm.objc.block.VoidBlock; |
jtulach@101 | 11 |
import org.robovm.rt.bro.Bro; |
jtulach@101 | 12 |
import org.robovm.rt.bro.NativeObject; |
jtulach@101 | 13 |
import org.robovm.rt.bro.annotation.Bridge; |
jtulach@101 | 14 |
import org.robovm.rt.bro.annotation.Library; |
jtulach@101 | 15 |
|
jtulach@101 | 16 |
/** |
jtulach@101 | 17 |
* |
jtulach@101 | 18 |
* @author jtulach |
jtulach@101 | 19 |
*/ |
jtulach@101 | 20 |
@Library("dispatch") |
jtulach@101 | 21 |
final class IBrwsrPrsntr extends XtrnlBrwsrPrsntr { |
jtulach@101 | 22 |
private final UIWebView wv; |
jtulach@101 | 23 |
|
jtulach@101 | 24 |
static { |
jtulach@101 | 25 |
Bro.bind(); |
jtulach@101 | 26 |
} |
jtulach@101 | 27 |
|
jtulach@101 | 28 |
public static class Queue extends NativeObject { |
jtulach@101 | 29 |
} |
jtulach@101 | 30 |
|
jtulach@101 | 31 |
@Bridge(symbol = "dispatch_get_current_queue") |
jtulach@101 | 32 |
public static native Queue getMainQueue(); |
jtulach@101 | 33 |
|
jtulach@101 | 34 |
@Bridge(symbol = "dispatch_async") |
jtulach@101 | 35 |
public static native void async(Queue queue, ObjCBlock block); |
jtulach@101 | 36 |
|
jtulach@101 | 37 |
public IBrwsrPrsntr(UIWebView wv) throws Exception { |
jtulach@101 | 38 |
this.wv = wv; |
jtulach@101 | 39 |
} |
jtulach@101 | 40 |
|
jtulach@101 | 41 |
@Override |
jtulach@101 | 42 |
public void runSafe(final Runnable r) { |
jtulach@101 | 43 |
VoidBlock vb = new VoidBlock() { |
jtulach@101 | 44 |
@Override |
jtulach@101 | 45 |
public void invoke() { |
jtulach@101 | 46 |
r.run(); |
jtulach@101 | 47 |
} |
jtulach@101 | 48 |
}; |
jtulach@101 | 49 |
ObjCBlock ocb = VoidBlock.Marshaler.toObjCBlock(vb); |
jtulach@101 | 50 |
async(getMainQueue(), ocb); |
jtulach@101 | 51 |
} |
jtulach@101 | 52 |
|
jtulach@101 | 53 |
@Override |
jtulach@101 | 54 |
protected void showBrwsr(URI page) throws IOException { |
jtulach@101 | 55 |
wv.loadRequest(Foo.requestWithURL(new NSURL(page.toString()))); |
jtulach@101 | 56 |
} |
jtulach@101 | 57 |
private static final Logger LOG = Logger.getLogger(IBrwsrPrsntr.class.getName()); |
jtulach@101 | 58 |
|
jtulach@101 | 59 |
} |