use of com.codename1.ui.BrowserComponent in project CodenameOne by codenameone.
the class IOSImplementation method createBrowserComponent.
/*class RunnableCleanup implements Runnable {
long[] peer;
Runnable onCompletion;
public void run() {
if(onCompletion != null) {
onCompletion.run();
}
if(peer != null && peer[0] != 0) {
cleanupAudio(peer);
}
}
}
@Override
public Object createAudio(String uri, Runnable onCompletion) throws IOException {
RunnableCleanup c = new RunnableCleanup();
long[] p = new long[] {nativeInstance.createAudio(uri, c)};
c.peer = p;
c.onCompletion = onCompletion;
return p;
}
@Override
public Object createAudio(InputStream stream, String mimeType, Runnable onCompletion) throws IOException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int size = stream.read(buffer);
while(size > -1) {
bo.write(buffer, 0, size);
size = stream.read(buffer);
}
bo.close();
stream.close();
RunnableCleanup c = new RunnableCleanup();
long[] p = new long[] {nativeInstance.createAudio(bo.toByteArray(), c)};
c.peer = p;
c.onCompletion = onCompletion;
return p;
}*/
@Override
public PeerComponent createBrowserComponent(Object browserComponent) {
long browserPeer = nativeInstance.createBrowserComponent(browserComponent);
PeerComponent pc = createNativePeer(new long[] { browserPeer });
nativeInstance.releasePeer(browserPeer);
return pc;
}
use of com.codename1.ui.BrowserComponent in project CodenameOne by codenameone.
the class JavaSEPort method createBrowserComponent.
public PeerComponent createBrowserComponent(final Object parent) {
java.awt.Container cnt = canvas.getParent();
while (!(cnt instanceof JFrame)) {
cnt = cnt.getParent();
if (cnt == null) {
return null;
}
}
final java.awt.Container c = cnt;
final Exception[] err = new Exception[1];
final javafx.embed.swing.JFXPanel webContainer = new CN1JFXPanel();
final SEBrowserComponent[] bc = new SEBrowserComponent[1];
Platform.runLater(new Runnable() {
@Override
public void run() {
StackPane root = new StackPane();
final WebView webView = new WebView();
root.getChildren().add(webView);
webContainer.setScene(new Scene(root));
// now wait for the Swing side to finish initializing f'ing JavaFX is so broken its unbeliveable
final SEBrowserComponent bcc = new SEBrowserComponent(JavaSEPort.this, ((JPanel) canvas.getParent()), webContainer, webView, (BrowserComponent) parent, hSelector, vSelector);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
bc[0] = bcc;
synchronized (bc) {
bc.notify();
}
}
});
}
});
Display.getInstance().invokeAndBlock(new Runnable() {
@Override
public void run() {
synchronized (bc) {
while (bc[0] == null && err[0] == null) {
try {
bc.wait(20);
} catch (InterruptedException ex) {
}
}
}
}
});
return bc[0];
}
use of com.codename1.ui.BrowserComponent in project CodenameOne by codenameone.
the class TestComponent method getComponentAt_int_int_browsercomponent.
private void getComponentAt_int_int_browsercomponent() {
int w = Display.getInstance().getDisplayWidth();
int h = Display.getInstance().getDisplayHeight();
Form mapDemo = new Form("Maps", new LayeredLayout());
Toolbar.setOnTopSideMenu(true);
Toolbar tb = new Toolbar();
mapDemo.setToolbar(tb);
mapDemo.setTitle("Maps");
tb.addCommandToSideMenu(new Command("Test") {
@Override
public void actionPerformed(ActionEvent e) {
// testNestedScrollingLabels();
}
});
BrowserComponent mc = new BrowserComponent();
mapDemo.add(mc);
mapDemo.show();
TestUtils.waitForFormTitle("Maps", 2000);
Component middleComponent = mapDemo.getComponentAt(w / 2, h / 2);
assertTrue(mc == middleComponent || mc.contains(middleComponent), "Wrong component found in middle. Expected " + mc + " but found " + middleComponent);
tb.openSideMenu();
// wait for side menu to open
TestUtils.waitFor(500);
Component res = null;
res = tb.getComponentAt(10, h / 2);
// System.out.println("tb size = "+tb.getAbsoluteX()+", "+tb.getAbsoluteY()+", "+tb.getWidth()+", "+tb.getHeight());
// System.out.println("mb size = "+tb.getMenuBar().getAbsoluteX()+", "+tb.getMenuBar().getAbsoluteY()+", "+tb.getMenuBar().getWidth()+", "+tb.getMenuBar().getHeight());
// System.out.println("res is "+res);
res = mapDemo.getComponentAt(10, h / 2);
// Let's find the interaction dialog on the form
Component interactionDialog = $("*", mapDemo).filter(c -> {
return c instanceof InteractionDialog;
}).asComponent();
assertTrue(((InteractionDialog) interactionDialog).contains(res), "Toolbar is open so getComponentAt() should return something on the toolbar. But received " + res + ". Toolbar is " + tb);
}
use of com.codename1.ui.BrowserComponent in project CodenameOne by codenameone.
the class TestComponent method testCookiesInBrowserComponent.
private void testCookiesInBrowserComponent() throws IOException {
Cookie.clearCookiesFromStorage();
Form f = new Form("CookiesInBrowser");
String formName = "CookiesInBrowser";
f.setName(formName);
f.setLayout(new BorderLayout());
BrowserComponent bc = new BrowserComponent();
f.add(BorderLayout.CENTER, bc);
f.show();
TestUtils.waitForFormName(formName, 2000);
String baseUrl = "http://solutions.weblite.ca/cn1tests/cookie";
String clearCookiesUrl = baseUrl + "/reset.php";
String setCookiesUrl = baseUrl + "/set.php";
String checkCookiesUrl = baseUrl + "/check.php";
String setCookiesUrlSession = baseUrl + "/set_session.php";
final BrowserStatus status = new BrowserStatus(bc);
bc.setURL(clearCookiesUrl);
status.waitReady();
status.reset();
bc.setURL(checkCookiesUrl);
status.waitReady();
Map<String, Object> res = status.getJSONContent();
TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
status.reset();
bc.setURL(setCookiesUrl);
status.waitReady();
status.reset();
bc.setURL(checkCookiesUrl);
status.waitReady();
res = status.getJSONContent();
TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
status.reset();
bc.setURL(clearCookiesUrl);
status.waitReady();
status.reset();
bc.setURL(checkCookiesUrl);
status.waitReady();
res = status.getJSONContent();
TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
status.reset();
bc.setURL(setCookiesUrlSession);
status.waitReady();
status.reset();
bc.setURL(checkCookiesUrl);
status.waitReady();
res = status.getJSONContent();
TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
// Now let's try to share cookies between the browser component and
// a connection request.
ConnectionRequest.setUseNativeCookieStore(true);
Cookie.clearCookiesFromStorage();
BrowserComponent bc2 = new BrowserComponent();
bc.getParent().replace(bc, bc2, null);
bc = bc2;
f.revalidate();
final BrowserStatus status2 = new BrowserStatus(bc);
bc.setURL(clearCookiesUrl);
status2.waitReady();
status2.reset();
// First verify that the cookie is not set in either browser or connection request
bc.setURL(checkCookiesUrl);
status2.waitReady();
res = status2.getJSONContent();
TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
res = ConnectionRequest.fetchJSON(checkCookiesUrl);
TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
// Next let's set the cookie in the browser, and verify that it is set in both
// browser and connection request.
status2.reset();
bc.setURL(setCookiesUrl);
status2.waitReady();
status2.reset();
bc.setURL(checkCookiesUrl);
status2.waitReady();
res = status2.getJSONContent();
TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
res = ConnectionRequest.fetchJSON(checkCookiesUrl);
TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
// Now let's delete the cookie in the browser and verify that it is deleted in
// both the browser and connection request.
status2.reset();
bc.setURL(clearCookiesUrl);
status2.waitReady();
status2.reset();
bc.setURL(checkCookiesUrl);
status2.waitReady();
res = status2.getJSONContent();
TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
res = ConnectionRequest.fetchJSON(checkCookiesUrl);
TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
// Now let's set the cookie in the ConnectionRequest and verify that it is set in both
// connection request and browser.
ConnectionRequest.fetchJSON(setCookiesUrl);
res = ConnectionRequest.fetchJSON(checkCookiesUrl);
TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
status2.reset();
bc.setURL(checkCookiesUrl);
status2.waitReady();
res = status2.getJSONContent();
TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
}
use of com.codename1.ui.BrowserComponent in project CodenameOne by codenameone.
the class VServAds method getPendingAd.
/**
* {@inheritDoc}
*/
protected Component getPendingAd() {
if (imageURL == null) {
return null;
}
if (renderNotify != null && renderNotify.length() > 0) {
ConnectionRequest c = new ConnectionRequest();
c.setFailSilently(true);
c.setUrl(renderNotify);
c.setPost(false);
NetworkManager.getInstance().addToQueue(c);
}
if ("image".equalsIgnoreCase(contentType)) {
Button adComponent = new Button() {
public void setIcon(Image icon) {
if (icon != null && isScaleMode()) {
icon = icon.scaledWidth(Display.getInstance().getDisplayWidth());
}
super.setIcon(icon);
}
};
adComponent.setUIID("Container");
adComponent.getStyle().setBgColor(backgroundColor);
adComponent.getStyle().setOpacity(0xff);
ImageDownloadService imd = new ImageDownloadService(imageURL, adComponent);
NetworkManager.getInstance().addToQueueAndWait(imd);
/*adComponent.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Display.getInstance().execute(getAdDestination());
}
});*/
return adComponent;
} else {
WebBrowser wb = new WebBrowser();
if (wb.getInternal() instanceof BrowserComponent) {
BrowserComponent bc = (BrowserComponent) wb.getInternal();
bc.setBrowserNavigationCallback(new BrowserNavigationCallback() {
public boolean shouldNavigate(final String url) {
unlock(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Display.getInstance().execute(url);
}
});
return false;
}
});
}
wb.setURL(imageURL);
return wb;
}
}
Aggregations