Search in sources :

Example 1 with BrowserField

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);
    }
}
Also used : PushInputStream(net.rim.device.api.io.http.PushInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DatabaseIOException(net.rim.device.api.database.DatabaseIOException) IOException(java.io.IOException) BrowserField(net.rim.device.api.browser.field2.BrowserField)

Example 2 with BrowserField

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);
    }
}
Also used : BrowserFieldListener(net.rim.device.api.browser.field2.BrowserFieldListener) BrowserComponent(com.codename1.ui.BrowserComponent) ActionEvent(com.codename1.ui.events.ActionEvent) Document(org.w3c.dom.Document) BrowserField(net.rim.device.api.browser.field2.BrowserField) DatabaseIOException(net.rim.device.api.database.DatabaseIOException) DatabasePathException(net.rim.device.api.database.DatabasePathException) IOException(java.io.IOException) ScriptEngine(net.rim.device.api.script.ScriptEngine)

Aggregations

IOException (java.io.IOException)2 BrowserField (net.rim.device.api.browser.field2.BrowserField)2 DatabaseIOException (net.rim.device.api.database.DatabaseIOException)2 BrowserComponent (com.codename1.ui.BrowserComponent)1 ActionEvent (com.codename1.ui.events.ActionEvent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 BrowserFieldListener (net.rim.device.api.browser.field2.BrowserFieldListener)1 DatabasePathException (net.rim.device.api.database.DatabasePathException)1 PushInputStream (net.rim.device.api.io.http.PushInputStream)1 ScriptEngine (net.rim.device.api.script.ScriptEngine)1 Document (org.w3c.dom.Document)1