[Huawei Developers] XDARoni:
Overview

The Image Render service provides five basic animation effects and nine advanced animation effects. Basic animation effects can be used in flexible combinations to suit different user needs. Advanced animation effects are not only stunning but easy to use and interesting, bringing more fun to user interactions.

Use Cases

An app needs to apply animation to the lock screen, wallpaper, or theme.

Development Procedure

To use the Image Render service, your app needs to provide resource files including bitmap images and the manifest.xml script that contain information about the images to be rendered. The Image Render service will parse the manifest.xml script, generate a rendered view, and return it to your app.

1. Prepare the resource file to be parsed. Make sure that the manifest.xml script complies with the XML Syntax Specifications for Image Render.

2. Import the Image Render service package.

import com.huawei.hms.image.render.*;

3. Obtain an ImageRender instance.

This step is mainly to obtain an ImageRender instance by calling the getInstance(Context context, RenderCallBack callback) method. To call the method, your app must implement the ImageRender.RenderCallBack API with its onSuccess(ImageRenderImpl imageRender) and onFailure(int errorCode) methods rewritten. If the ImageRender instance is successfully obtained, the onSuccess method is called, and obtained instance will be used for subsequent operations, such as initializing the service and obtaining rendered views. If the ImageRender instance fails to be obtained, the onFailure method is called and an error code is returned.

ImageRenderImpl imageRenderAPI;
// Obtain an ImageRender instance.
ImageRender.getInstance(this, new ImageRender.RenderCallBack() {
@Override
public void onSuccess(ImageRenderImpl imageRender) {
imageRenderAPI = imageRender;
...
}
@Override
public void onFailure(int i) {
...
}
});

4. Initialize the Image Render service.

When initializing the service, your app needs to pass the sourcePath (path of the resources to be parsed) and authentication information (for example, APIKey and certificate fingerprint, in JSON format). For details, please refer to Description of authJson parameters. Your app can use the service only after it is successfully authenticated.

// Initialize the ImageRender object.
// Obtain the authentication information (for example, APIKey and certificate fingerprint, in JSON format).
int initResult = imageRenderAPI.doInit(sourcePath, getAuthJson());

5. Obtain the rendered views.

After the getRenderView() API is called, the Image Render service parses the image and script in sourcePath and returns the rendered views to the app. User interaction is supported for advanced animation views, such as particles and ripples. For better interaction effects, it is recommended that the obtained rendered view be displayed in full screen.

//Obtain rendered views.
RenderView renderView = imageRenderAPI.getRenderView();
if (renderView.getResultCode() == ResultCode.SUCCEED) {
View view = renderView.getView();
}

6. Play animation views.

This operation is applicable to basic animation views. Basic animation views, such as rotation, translation, and scaling, are not played by default. You need to call the playAnimation() API to play the animation views.

// Play the rendered view.
if (null != imageRenderAPI) {
imageRenderAPI.playAnimation();
}

7. Stop animation views.

This operation is applicable to basic animation views. To stop an animation, call the stopAnimation() API.

// Stop the rendered views.
if (null != imageRenderAPI) {
imageRenderAPI.stopAnimation();
}

8. Release animation views.

If an animation view is no longer needed, call the removeRenderView() API to release the view.