Class WebBrowser

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class WebBrowser extends Container

A simple browser view that encapsulates a usable version of HTMLComponent or BrowserComponent and automatically picks the right component for the platform preferring BrowserComponent whenever it is supported.

On Android this component might show a native progress indicator dialog. You can disable that functionality using the call.

  • Constructor Details

    • WebBrowser

      public WebBrowser(String url)

      Constructor with a URL

      Parameters
      • url: the url
    • WebBrowser

      public WebBrowser()
      Default constructor
  • Method Details

    • createDataURI

      public static String createDataURI(byte[] data, String mime)

      This method creates a data URI which allows developers creating HTML for local use to embed local images into the HTML by appending them as a URI. E.g. instead of referencing a file or URL just load the image data and place the contents of this string into the src attribute.

      This is the easiest way to get an HTML with local images to work on all mobile platforms.

      Parameters
      • data: data of an image

      • mime: the mime type of the image e.g. image/png

      Returns

      a data URL that can be placed into the img src attribute in HTML e.g. data:image/png;base64,encodedData

    • onStart

      public void onStart(String url)

      This is a callback method, this method is called before the url has been loaded

      Parameters
      • url
    • onLoad

      public void onLoad(String url)

      This is a callback method, this method is called after the url has been loaded

      Parameters
      • url
    • getBrowserNavigationCallback

      public BrowserNavigationCallback getBrowserNavigationCallback()

      The browser navigation callback interface allows handling a case where a URL invocation can be delegated to Java code. This allows binding Java side functionality to JavaScript functionality in the same way PhoneGap/Cordova work

      Returns

      the callback interface

    • setBrowserNavigationCallback

      public void setBrowserNavigationCallback(BrowserNavigationCallback callback)

      Set the browser navigation callback which allows handling a case where a URL invocation can be delegated to Java code. This allows binding Java side functionality to JavaScript functionality in the same way PhoneGap/Cordova work

      Parameters
      • callback: the callback interface
    • onError

      public void onError(String message, int errorCode)

      This is a callback method to inform on an error.

      Parameters
      • message

      • errorCode

    • getInternal

      public Component getInternal()

      Since the internal component can be either an HTMLComponent or a BrowserComponent one of them will be returned. If you are targeting modern smartphones only you can rely on this method returning a BrowserComponent instance.

      Returns

      BrowserComponent or HTMLComponent

    • getTitle

      public String getTitle()

      Returns the title for the browser page

      Returns

      the title

    • getURL

      public String getURL()

      The page URL

      Returns

      the URL

    • setURL

      public void setURL(String url)

      Sets the page URL, jar: URL's must be supported by the implementation

      Parameters
      • url: the URL
    • reload

      public void reload()
      Reload the current page
    • stop

      public void stop()
      Stop loading the current page
    • destroy

      public void destroy()
      Release WebBrowser native resources.
    • setPage

      public void setPage(String html, String baseUrl)

      Shows the given HTML in the native viewer

      Parameters
      • html: HTML web page

      • baseUrl: base URL to associate with the HTML

    • getPage

      public String getPage()

      Returns the page set by getPage for the GUI builder

      Returns

      the HTML page set manually

    • getPropertyNames

      public String[] getPropertyNames()

      A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code

      Returns

      the property names allowing mutation

      Overrides:
      getPropertyNames in class Component
    • getPropertyTypes

      public Class[] getPropertyTypes()

      Matches the property names method (see that method for further details).

      Returns

      the types of the properties

      Overrides:
      getPropertyTypes in class Component
    • getPropertyTypeNames

      public String[] getPropertyTypeNames()

      This method is here to workaround an XMLVM array type bug where property types aren't identified properly, it returns the names of the types using the following type names: String,int,double,long,byte,short,char,String[],String[][],byte[],Image,Image[],Object[],ListModel,ListCellRenderer

      Returns

      Array of type names

      Overrides:
      getPropertyTypeNames in class Component
    • getPropertyValue

      public Object getPropertyValue(String name)

      Returns the current value of the property name, this method is used by the GUI builder

      Parameters
      • name: the name of the property
      Returns

      the value of said property

      Overrides:
      getPropertyValue in class Component
    • setPropertyValue

      public String setPropertyValue(String name, Object value)

      Sets a new value to the given property, returns an error message if failed and null if successful. Notice that some builtin properties such as "$designMode" might be sent to components to indicate application state.

      Parameters
      • name: the name of the property

      • value: new value for the property

      Returns

      error message or null

      Overrides:
      setPropertyValue in class Component