Requirements
- Android SDK 4.0 (API Level 15) or above
- Liferay Portal 6.2 (CE or EE), Liferay 7.0 CE, Liferay DXP
- Picasso library
Compatibility
- Android SDK 4.0 (API Level 15) and 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.
Service | Method | Notes |
---|---|---|
UserService | getUserById |
Module
- None
Views
- Default
- Material
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:
Policy | What happens | When to use |
---|---|---|
REMOTE_ONLY | The 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_ONLY | The 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_FIRST | The 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_FIRST | If 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:
Policy | What happens | When to use |
---|---|---|
REMOTE_ONLY | The 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_ONLY | The 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_FIRST | The 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_FIRST | The 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
Attribute | Data type | Explanation |
---|---|---|
layoutId | @layout | The layout used to show the View. |
autoLoad | boolean | Whether the portrait should load when the Screenlet is attached to the window. |
userId | number | The ID of the user whose portrait is being requested. If this attribute is set, the male , portraitId , and uuid attributes are ignored. |
male | boolean | Whether the default portrait placeholder shows a male or female outline. This attribute is used if userId isn’t specified. |
portraitId | number | The ID of the portrait to load. This attribute is used if userId isn’t specified. |
uuid | string | The uuid of the user whose portrait is being requested. This attribute is used if userId isn’t specified. |
editable | boolean | Lets the user change the portrait image by taking a photo or selecting a gallery picture. |
offlinePolicy | enum | Configure the loading and saving behavior in case of connectivity issues. For more details, read the “Offline” section below. |
Methods
Method | Return | Explanation |
---|---|---|
load() | void | Starts the request to load the user specified in the userId property, or the portrait specified in the portraitId and uuid properties. |
upload(int requestCode, Intent onActivityResultData) | void | Starts 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 returnnull
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. TheuserAction
argument distinguishes the specific action in which the error occurred.