Asset Display 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

Asset Display Screenlet can display an asset from a Liferay instance. The Screenlet can currently display Documents and Media files (DLFileEntry images, videos, audio files, and PDFs), blogs entries (BlogsEntry) and web content articles (WebContent).

Asset Display Screenlet can also display your custom asset types. See the Listener section of this document for details.

JSON Services Used

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

ServiceMethodNotes
ScreensassetentryService (Screens compatibility plugin)getAssetEntryWith entryId
ScreensassetentryService (Screens compatibility plugin)getAssetEntryWith classPK and className
ScreensassetentryService (Screens compatibility plugin)getAssetEntriesWith entryQuery
ScreensassetentryService (Screens compatibility plugin)getAssetEntriesWith companyId, groupId, and portletItemName

Module

  • None

Views

  • Default

Figure 1: Asset Display Screenlet using the Default View.

Figure 1: Asset Display Screenlet using the Default View.

The Default View uses different UI elements to show each asset type. For example, it displays images with ImageView and blogs with TextView. Note that other Views may use different UI elements.

This Screenlet can also render other Screenlets as inner Screenlets:

  • Images: Image Display Screenlet
  • Videos: Video Display Screenlet
  • Audios: Audio Display Screenlet
  • PDFs: PDF Display Screenlet
  • Blogs entries: Blogs Entry Display Screenlet
  • Web content: Web Content Display Screenlet

These Screenlets can also be used alone without Asset Display Screenlet.

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 data from the Liferay instance. If a connection issue occurs, the Screenlet uses the listener to notify the developer about the error. If the Screenlet successfully loads the data, it stores it in the local cache for later use.Use this policy when you always need to show updated data, and show nothing when there’s no connection.
CACHE_ONLYThe Screenlet loads the data from the local cache. If the data 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 data, without retrieving remote information under any circumstance.
REMOTE_FIRSTThe Screenlet loads the data from the Liferay instance. If this succeeds, the Screenlet shows the data to the user and stores it in the local cache for later use. If a connection issue occurs, the Screenlet retrieves the data from the local cache. If the data 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 data when connected, but show an outdated version when there’s no connection.
CACHE_FIRSTThe Screenlet loads the data from the local cache. If the data isn’t there, the Screenlet requests it from the Liferay instance 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) data.

Required Attributes

  • entryId

Instead of entryId, you can use both of the following attributes:

  • className
  • classPK

If you don’t use entryId, className, or classPK, you must use this attribute:

  • portletItemName

Attributes

AttributeData typeExplanation
layoutId@layoutThe layout to use to show the View.
autoLoadbooleanWhether the asset automatically loads when the Screenlet appears in the app’s UI. The default value is true.
entryIdnumberThe primary key of the asset.
classNamestringThe asset’s fully qualified class name. For example, a blog entry’s className is com.liferay.blogs.kernel.model.BlogsEntry. The className and classPK attributes are required to instantiate the Screenlet.
classPKnumberThe asset’s unique identifier. The className and classPK attributes are required to instantiate the Screenlet.
portletItemNamestringThe name of the archived setup you used in the Asset Publisher. To use this feature, add an Asset Publisher to one of your site’s pages (it may be a hidden page), configure the Asset Publisher’s filter (in ConfigurationSetupAsset Selection), and then use the Asset Publisher’s Archived/Restore Setup option to save this setup with a name. Use this name in this attribute. If there is more than one asset in the setup, the Screenlet displays only the first one.
cachePolicystringThe offline mode setting. See the Offline section for details.
imageLayoutId@layoutThe layout to use to show an image (DLFileEntry).
videoLayoutId@layoutThe layout to use to show a video (DLFileEntry).
audioLayoutId@layoutThe layout to use to show an audio file (DLFileEntry).
pdfLayoutId@layoutThe layout to use to show a PDF (DLFileEntry).
blogsLayoutId@layoutThe layout to use to show a blog entry (BlogsEntry).
webDisplayLayoutId@layoutThe layout to use to show a web content article (WebContent).

Methods

MethodReturnExplanation
load(AssetEntry assetEntry)voidLoads the given AssetEntry in the Screenlet. If no inner Screenlet is instantiated, the method tries to load the asset with a custom asset listener method. If this returns null, a new Intent is called to display the asset.
loadAsset()voidSearches for the AssetEntry defined by the required attributes and loads it in the Screenlet.

Listener

Asset Display Screenlet delegates some events to a class that implements AssetDisplayListener. This interface contains the following methods:

  • onRetrieveAssetSuccess(AssetEntry assetEntry): Called when the Screenlet successfully loads the asset.

A second listener, AssetDisplayInnerScreenletListener, also exists for configuring a child Screenlet (the Screenlet rendered inside Asset Display Screenlet) or rendering a custom asset.

  • onConfigureChildScreenlet(AssetDisplayScreenlet screenlet, BaseScreenlet innerScreenlet, AssetEntry assetEntry): Called when the child Screenlet has been successfully initialized. Use this method to configure or customize the child Screenlet. The example implementation here sets the child Screenlet’s background color to light gray if the asset is a blog entry entity (BlogsEntry):

      @Override
      public void onConfigureChildScreenlet(AssetDisplayScreenlet screenlet,
          BaseScreenlet innerScreenlet, AssetEntry assetEntry) {
              if ("blogsEntry".equals(assetEntry.getObjectType())) {
                  innerScreenlet.setBackgroundColor(ContextCompat.getColor(this,
                  R.color.light_gray));
              }
      }
    
  • onRenderCustomAsset(AssetEntry assetEntry): Called to render a custom asset. The following example implementation inflates and returns the custom View necessary to render a user from a Liferay instance (User):

      @Override
      public View onRenderCustomAsset(AssetEntry assetEntry) {
          if (assetEntry instanceof User) {
              View view = getLayoutInflater().inflate(R.layout.user_display, null);
              User user = (User) assetEntry;
    
              TextView username = (TextView) view.findViewById(R.id.liferay_username);
    
              username(user.getUsername());
    
              return view;
          }
          return null;
      }
    
« Comment Add Screenlet for AndroidBlogs Entry Display Screenlet for Android »
Was this article helpful?
0 out of 0 found this helpful