User Portrait 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
  • Picasso library

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 User Portrait Screenlet shows the users’ profile pictures. If a user doesn’t have a profile picture, a placeholder image is shown. The Screenlet allows the profile picture to be edited via the editable property.

JSON Services Used

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

ServiceMethodNotes
UserServicegetUserById

Module

  • None

Views

  • Default
  • Material

The User Portrait Screenlet using the Default (left) and Material (right) Views.

Portal Configuration

No additional steps required.

Activity Configuration

The User Portrait Screenlet needs the following user permissions:

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

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.

When loading the portrait, the Screenlet supports the following offline mode policies:

PolicyWhat happensWhen to use
REMOTE_ONLYThe Screenlet loads the user portrait from the portal. If a connection issue occurs, the Screenlet uses the listener to notify the developer about the error. If the Screenlet loads the portrait, it stores the received image in the local cache for later use.Use this policy when you always need to show updated portraits, and show the default placeholder when there’s no connection.
CACHE_ONLYThe Screenlet loads the user portrait from the local cache. If the portrait isn’t there, the Screenlet uses the listener to notify the developer about the error.Use this policy to show local portraits, without retrieving remote information under any circumstance.
REMOTE_FIRSTThe Screenlet loads the user portrait from the portal. The Screenlet displays the portrait to the user and stores it in the local cache for later use. If a connection issue occurs, the Screenlet retrieves the portrait from the local cache. If the portrait doesn’t exist there, the Screenlet uses the listener to notify the developer about the error.Use this policy to show the most recent portrait when connected, but show a potentially outdated version when there’s no connection.
CACHE_FIRSTIf the portrait exists in the local cache, the Screenlet loads it from there. If it doesn’t exist there, the Screenlet requests the portrait from the portal and uses the listener to notify the developer about any connection errors.Use this policy to save bandwidth and loading time in the event a local (but probably outdated) portrait exists.

When editing the portrait, the Screenlet supports the following offline mode policies:

PolicyWhat happensWhen to use
REMOTE_ONLYThe Screenlet sends the user portrait to the portal. If a connection issue occurs, the Screenlet uses the listener to notify the developer about the error, but it also discards the new portrait.Use this policy when you need to make sure portal always has the most recent version of the portrait.
CACHE_ONLYThe Screenlet stores the user portrait in the local cache.Use this policy when you need to save the portrait locally, but don’t want to change the portrait in the portal.
REMOTE_FIRSTThe Screenlet sends the user portrait to the portal. If this succeeds, the Screenlet also stores the portrait in the local cache for later usage. If a connection issue occurs, the Screenlet stores the portrait in the local cache with the dirty flag enabled. This causes the portrait to be sent to the portal when the synchronization process runs.Use this policy when you need to make sure the Screenlet sends the new portrait to the portal as soon as the connection is restored.
CACHE_FIRSTThe Screenlet stores the user portrait in the local cache and then sends it to the portal. If a connection issue occurs, the Screenlet stores the portrait in the local cache with the dirty flag enabled. This causes the portrait to be sent to the portal when the synchronization process runs.Use this policy when you need to make sure the Screenlet sends the new portrait to the portal as soon as the connection is restored. Compared to REMOTE_FIRST, this policy always stores the portrait in the cache. The REMOTE_FIRST policy only stores the new image in the cache in the event of a network error or a successful upload.

Required Attributes

  • None

Note that if you don’t set any attributes, the Screenlet loads the logged-in user’s portrait.

Attributes

AttributeData typeExplanation
layoutId@layoutThe layout used to show the View.
autoLoadbooleanWhether the portrait should load when the Screenlet is attached to the window.
userIdnumberThe ID of the user whose portrait is being requested. If this attribute is set, the male, portraitId, and uuid attributes are ignored.
malebooleanWhether the default portrait placeholder shows a male or female outline. This attribute is used if userId isn’t specified.
portraitIdnumberThe ID of the portrait to load. This attribute is used if userId isn’t specified.
uuidstringThe uuid of the user whose portrait is being requested. This attribute is used if userId isn’t specified.
editablebooleanLets the user change the portrait image by taking a photo or selecting a gallery picture.
offlinePolicyenumConfigure the loading and saving behavior in case of connectivity issues. For more details, read the “Offline” section below.

Methods

MethodReturnExplanation
load()voidStarts the request to load the user specified in the userId property, or the portrait specified in the portraitIdand uuid properties.
upload(int requestCode,
Intent onActivityResultData)
voidStarts the request to upload a profile picture from the source specified in the requestCode property (gallery or camera), and with the path stored in the onActivityResultData variable.

Listener

The User Portrait Screenlet delegates some events to an object that implements the UserPortraitListener interface. This interface lets you implement the following methods:

  • onUserPortraitLoadReceived(Bitmap bitmap): Called when an image is received from the server. You can then apply image filters (grayscale, for example) and return the new image. You can return null or the original image supplied as the argument if you don’t want to modify it.

  • onUserPortraitUploaded(): Called when the user portrait upload service finishes.

  • error(Exception e, String userAction): Called when an error occurs in the process. For example, an error can occur when receiving or uploading a user portrait. The userAction argument distinguishes the specific action in which the error occurred.

« Forgot Password Screenlet for AndroidDDL Form Screenlet for Android »
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています