Web Content Display Screenlet for Android

Requirements

  • Android SDK 4.1 (API Level 16) or above
  • Liferay Portal 6.2 CE/EE, Liferay CE Portal 7.0/7.1, Liferay DXP 7.0+
  • Liferay Screens Compatibility app (CE or EE/DXP). This app is preinstalled in Liferay CE Portal 7.0/7.1 and Liferay DXP 7.0+.

Compatibility

  • Android SDK 4.1 (API Level 16) or above

Xamarin Requirements

  • Visual Studio 7.2
  • Mono .NET framework 5.4.1.6

Features

The Web Content Display Screenlet shows web content elements in your app, rendering the web content’s inner HTML. The Screenlet also supports i18n, rendering contents differently depending on the device’s locale.

JSON Services Used

Screenlets in Liferay Screens call JSON web services in the portal. This Screenlet calls the following services and methods.

ServiceMethodNotes
DDMStructureServicegetStructure
JournalArticleServicegetArticle
JournalArticleServicegetArticleContent
ScreensddlrecordService (Screens compatibility plugin)getJournalArticleContentWith entryQuery

Module

  • None

Views

  • Default

The Default View uses a standard WebView to render the HTML.

Web Content Display Screenlet using the Default View.

Portal Configuration

For the Web Content Display Screenlet to function properly, there should be web content in the Liferay instance your app connects to. For more details on web content, see the Creating Web Content section of the Liferay User Guide.

Offline

This Screenlet supports offline mode so it can function without a network connection. For more information on how offline mode works, see the tutorial on its architecture. Here are the offline mode policies that you can use with this Screenlet:

PolicyWhat happensWhen to use
REMOTE_ONLYThe Screenlet loads the content from the portal. If a connection issue occurs, the Screenlet uses the listener to notify the developer about the error. If the Screenlet successfully loads the content, it stores the data in the local cache for later use.Use this policy when you always need to show updated content, and show nothing when there’s no connection.
CACHE_ONLYThe Screenlet loads the content from the local cache. If the content isn’t there, the Screenlet uses the listener to notify the developer about the error.Use this policy when you always need to show local content, without retrieving remote content under any circumstance.
REMOTE_FIRSTThe Screenlet loads the content from the portal. If this succeeds, the Screenlet shows the content to the user and stores it in the local cache for later use. If a connection issue occurs, the Screenlet retrieves the content from the local cache. If the content doesn’t exist there, the Screenlet uses the listener to notify the developer about the error.Use this policy to show the most recent version of the content when connected, but show a possibly outdated version when there’s no connection.
CACHE_FIRSTThe Screenlet loads the content from the local cache. If the content isn’t there, the Screenlet requests it from the portal and notifies the developer about any errors that occur (including connectivity errors).Use this policy to save bandwidth and loading time in case you have local (but probably outdated) content.

Required Attributes

  • articleId

Note that if your web content uses structures and templates, you can use templateId or structureId in conjunction with articleId.

Attributes

AttributeData typeExplanation
layoutId@layoutThe layout used to show the View.
groupIdnumberThe site (group) identifier where the asset is stored. If this value is 0, the groupId specified in LiferayServerContext is used.
articleIdstringThe identifier of the web content to display. You can find the identifier by clicking Edit on the web content in the portal.
classPKnumberThe corresponding asset’s class primary key. If the web content is an asset (from Asset List Screenlet, for example), this is the asset’s identifier. This attribute is used only if articleId is empty.
templateIdnumberThe identifier of the template used to render the web content. This only applies to structured web content.
structureIdnumberThe identifier of the DDMStructure used to model the web content. This parameter lets the Screenlet retrieve and parse the structure.
labelFieldsstringA comma-delimited list of DDMStructure fields to display in the Screenlet.
autoLoadbooleanWhether the content should be retrieved from the portal as soon as the screenlet appears. Default value is true.
javascriptEnabledbooleanEnables support for JavaScript. This is disabled by default.
cachePolicystringThe offline mode setting. See the Offline section for details.

Methods

MethodReturnExplanation
load()voidStarts the request to load the web content. The HTML is rendered when the response is received.

Listener

The Web Content Display Screenlet delegates some events to an object that implements the WebContentDisplayListener interface. This interface lets you implement the following methods:

  • onWebContentReceived(WebContent webContent): Called when the web content’s HTML or DDMStructure is received. The HTML is available by calling the getHtml method. To make some adaptations, the listener may return a modified version of the HTML. The original HTML is rendered if the listener returns null.

  • onUrlClicked(String url): Called when a URL is clicked. Return true to replace the default behavior, or false to load the url.

  • onWebContentTouched(View view, MotionEvent event): Called when something is touched in the web content. Return true to replace the default behavior, or false to keep processing the event.

  • 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.

« Asset List Screenlet for AndroidWeb Content List Screenlet for Android »
Was this article helpful?
0 out of 0 found this helpful