use of net.rim.device.api.browser.field2.BrowserField in project CodenameOne by codenameone.
the class BlackBerryOS5Implementation method setBrowserURL.
public void setBrowserURL(PeerComponent browserPeer, String url) {
if (url.startsWith("jar://")) {
// load from jar:// URL's
try {
InputStream i = Display.getInstance().getResourceAsStream(getClass(), url.substring(6));
if (i == null) {
System.out.println("Local resource not found: " + url);
return;
}
byte[] buffer = new byte[4096];
ByteArrayOutputStream bo = new ByteArrayOutputStream();
int size = i.read(buffer);
while (size > -1) {
bo.write(buffer, 0, size);
size = i.read(buffer);
}
i.close();
bo.close();
String htmlText = new String(bo.toByteArray(), "UTF-8");
int pos = url.lastIndexOf('/');
if (pos > 6) {
url = url.substring(6, pos);
} else {
url = "/";
}
String baseUrl = "local://" + url;
setBrowserPage(browserPeer, htmlText, baseUrl);
return;
} catch (IOException ex) {
ex.printStackTrace();
}
return;
}
synchronized (UiApplication.getEventLock()) {
((BrowserField) browserPeer.getNativePeer()).requestContent(url);
}
}
use of net.rim.device.api.browser.field2.BrowserField in project CodenameOne by codenameone.
the class BlackBerryOS5Implementation method createBrowserComponent.
public PeerComponent createBrowserComponent(Object browserComponent) {
synchronized (UiApplication.getEventLock()) {
BrowserField bff = new BrowserField();
final BrowserComponent cmp = (BrowserComponent) browserComponent;
bff.addListener(new BrowserFieldListener() {
public void documentError(BrowserField browserField, Document document) throws Exception {
cmp.fireWebEvent("onError", new ActionEvent(document.getDocumentURI()));
super.documentError(browserField, document);
}
public void documentCreated(BrowserField browserField, ScriptEngine scriptEngine, Document document) throws Exception {
cmp.fireWebEvent("onStart", new ActionEvent(document.getDocumentURI()));
super.documentCreated(browserField, scriptEngine, document);
}
public void documentLoaded(BrowserField browserField, Document document) throws Exception {
cmp.fireWebEvent("onLoad", new ActionEvent(document.getDocumentURI()));
super.documentLoaded(browserField, document);
}
});
return PeerComponent.create(bff);
}
}
Aggregations