Search in sources :

Example 1 with AsyncDocumentRequestHandlerImpl

use of com.codename1.ui.html.AsyncDocumentRequestHandlerImpl in project CodenameOne by codenameone.

the class Ads method setAd.

/**
 * HTML ad received from the server
 * @param ad the ad to set
 */
public void setAd(String ad) {
    HTMLComponent html = new HTMLComponent(new AsyncDocumentRequestHandlerImpl() {

        protected ConnectionRequest createConnectionRequest(DocumentInfo docInfo, IOCallback callback, Object[] response) {
            ConnectionRequest req = super.createConnectionRequest(docInfo, callback, response);
            req.setFailSilently(true);
            req.addResponseCodeListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                // do nothing, just make sure the html won't throw an error
                }
            });
            return req;
        }
    });
    html.setSupressExceptions(true);
    html.setHTMLCallback(this);
    html.setBodyText("<html><body><div align='center'>" + ad + "</div></body></html>");
    replace(getComponentAt(0), html, null);
    revalidate();
    html.setPageUIID("Container");
    html.getStyle().setBgTransparency(0);
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) AsyncDocumentRequestHandlerImpl(com.codename1.ui.html.AsyncDocumentRequestHandlerImpl) IOCallback(com.codename1.ui.html.IOCallback) HTMLComponent(com.codename1.ui.html.HTMLComponent) DocumentInfo(com.codename1.ui.html.DocumentInfo)

Aggregations

ConnectionRequest (com.codename1.io.ConnectionRequest)1 ActionEvent (com.codename1.ui.events.ActionEvent)1 ActionListener (com.codename1.ui.events.ActionListener)1 AsyncDocumentRequestHandlerImpl (com.codename1.ui.html.AsyncDocumentRequestHandlerImpl)1 DocumentInfo (com.codename1.ui.html.DocumentInfo)1 HTMLComponent (com.codename1.ui.html.HTMLComponent)1 IOCallback (com.codename1.ui.html.IOCallback)1