Web Screenlet for Android

Requirements

  • Android SDK 4.0 (API Level 15) or above
  • Liferay Portal 6.2 (CE or EE), Liferay 7.0 CE, Liferay DXP
  • Liferay Screens Compatibility Plugin (for Liferay Portal CE or Liferay Portal EE).

Compatibility

  • Android SDK 4.0 (API Level 15) and above

Xamarin Requirements

  • Visual Studio 7.2
  • Mono .NET framework 5.4.1.6

Features

Web Screenlet lets you display any web page. It also lets you customize the web page through injection of local and remote JavaScript and CSS files. If you’re using @product@ as backend, you can use Application Display Templates in your page to customize its content from the server side.

Module

  • None

Views

  • Default

Figure 1: The Web Screenlet with the Default View Set.

Figure 1: The Web Screenlet with the Default View Set.

Configuration

To learn how to use Web Screenlet, follow the steps in the tutorial Rendering Web Pages in Your Android App. That tutorial gives detailed instructions for using the configuration items described here.

Web Screenlet has WebScreenletConfiguration and WebScreenletConfiguration.Builder classes that you can use together to supply the parameters that the Screenlet needs to work. WebScreenletConfiguration.Builder has the following methods, which let you supply the described configuration parameters:

MethodReturnExplanation
addLocalJs(fileName)WebScreenletConfiguration.BuilderAdds a local JavaScript file with the supplied filename. You must save the JavaScript files in the asset folder’s first level.
addLocalCss(fileName)WebScreenletConfiguration.BuilderAdds a local CSS file with the supplied filename. You must save the CSS files in the asset folder’s first level.
addRawJs(rawJs, name)WebScreenletConfiguration.BuilderAdds a JavaScript file from the res/raw folder. Reference the file using R.raw.rawJs. This method also takes a second parameter called name, which is only for debugging purposes. If there’s an error, the console displays it with this name value.
addRawCss(rawCss, name)WebScreenletConfiguration.BuilderAdds a CSS file from the res/raw folder. Reference the file using R.raw.rawCss. This method also takes a second parameter called name, which is only for debugging purposes. If there’s an error, the console displays it with this name value.
addRemoteJs(url)WebScreenletConfiguration.BuilderAdds a JavaScript file from the supplied URL.
addRemoteCss(url)WebScreenletConfiguration.BuilderAdds a CSS file from the supplied URL.
setWebType(webType)WebScreenletConfiguration.BuilderSets the WebType.
enableCordova(observer)WebScreenletConfiguration.BuilderEnables Cordova inside the Web Screenlet.
load()WebScreenletConfigurationReturns the WebScreenletConfiguration object that you can set to the Screenlet instance.

WebType

  • WebType.LIFERAY_AUTHENTICATED (default): Displays a @product@ page that requires authentication. The user must therefore be logged in with Screens via Login Screenlet or a SessionContext method. For this WebType, the URL you must pass to the WebScreenletConfiguration.Builder constructor is a relative URL. For example, if the full URL is http://screens.liferay.org.es/web/guest/blog, then the URL you must supply to the constructor is /web/guest/blog.

  • WebType.OTHER: Displays any other page. For this WebType, the URL you must pass to the WebScreenletConfiguration.Builder constructor is a full URL. For example, if the full URL is http://screens.liferay.org.es/web/guest/blog, then you must supply that URL to the constructor.

Attributes

AttributeData typeExplanation
autoLoadbooleanWhether to load the page automatically when the Screenlet appears in the app’s UI. The default value is true.
layoutId@layoutThe layout to use to show the View.
isLoggingEnabledbooleanWhether logging is enabled.
isScrollEnabledbooleanWhether to enable scrolling on the page inside the Screenlet.

Methods

MethodReturnExplanation
load()voidChecks if the page’s URL is valid, and then loads it. The operation fails if the URL is invalid.
clearCache()voidClears the Web Screenlet’s cache.
injectScript(script)voidInjects a script when the page is already loaded.

Listener

Web Screenlet delegates some events to an object or class that implements its WebListener interface. This interface extends the BaseCacheListener interface. Therefore, Web Screenlet’s listener methods are as follows:

  • onPageLoaded(String url): Called when the Screenlet loads the page correctly.

  • onScriptMessageHandler(String namespace, String body): Called when the WebView in the Screenlet sends a message. The namespace parameter is the source namespace key, and body is the source namespace body.

  • error(Exception e, String userAction): Called when an error occurs in the process. The userAction argument distinguishes the specific action in which the error occurred.

« PDF Display Screenlet for AndroidAndroid Breaking Changes »
Was this article helpful?
0 out of 0 found this helpful