From Remote URL
PhotoEditor SDK supports loading stickers from a remote URL, this can be a resource hosted by a hosting provider or your servers.
Although the editor supports adding assets with remote URLs, we highly recommend that you manage the download of remote resources yourself, since this gives you more control over the whole process. In this example, we add a custom sticker by directly passing the remote URLs in the configuration. For an example of how to download the remote resources in advance see the font example.
Custom sticker asset#
Here, we create a custom sticker using ImageStickerAsset
. It takes in a unique identifier (used for serialization/deserialization purposes), and the sticker's ImageSource
.
Add sticker to AssetConfig
#
AssetConfig
#To use the sticker, it must first be available in the SDK's backend. This is done by adding the sticker to the AssetConfig
.
Create a custom sticker category#
We then add the stickers to a StickerCategoryItem
and provide it with an id, name, and thumbnail ImageSource
.
Configure UiConfigSticker
#
UiConfigSticker
#Here, we configure UiConfigSticker
and add the custom sticker category as the first item in the list.
class PhotoAddStickersFromRemoteURL(private val activity: AppCompatActivity) : Example(activity) {override fun invoke() {// In this example, we do not need access to the Uri(s) after the editor is closed// so we pass false in the constructorval settingsList = PhotoEditorSettingsList(false)// Set the source as the Uri of the image to be loaded.configure<LoadSettings> {it.source = activity.resourceUri(R.drawable.la)}// Create a custom stickerval customSticker = ImageStickerAsset("custom_sticker",ImageSource.create(Uri.parse("https://img.ly/static/example-assets/custom_sticker_igor.png")))val existingSticker = ImageStickerAsset("imgly_sticker_emoticons_grin",ly.img.android.pesdk.assets.sticker.emoticons.R.drawable.imgly_sticker_emoticons_grin)// Add custom sticker to AssetConfigsettingsList.config.addAsset(customSticker)// Create custom sticker categoryval customStickerCategory = StickerCategoryItem("custom_sticker_category","Custom",ImageSource.create(Uri.parse("https://img.ly/static/example-assets/custom_sticker_igor_thumb.png")),ImageStickerItem("custom_sticker","Igor",ImageSource.create(Uri.parse("https://img.ly/static/example-assets/custom_sticker_igor_thumb.png"))),ImageStickerItem("imgly_sticker_emoticons_grin","Grin",ImageSource.create(ly.img.android.pesdk.assets.sticker.emoticons.R.drawable.imgly_sticker_emoticons_grin)))settingsList.configure<UiConfigSticker> {// Add custom sticker category to the UIit.stickerLists.add(0, customStickerCategory)}// Start the photo editor using PhotoEditorBuilder// The result will be obtained in onActivityResult() corresponding to EDITOR_REQUEST_CODEPhotoEditorBuilder(activity).setSettingsList(settingsList).startActivityForResult(activity, EDITOR_REQUEST_CODE)// Release the SettingsList once donesettingsList.release()}override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {intent ?: returnif (requestCode == EDITOR_REQUEST_CODE) {// Wrap the intent into an EditorSDKResultval result = EditorSDKResult(intent)when (result.resultStatus) {EditorSDKResult.Status.CANCELED -> showMessage("Editor cancelled")EditorSDKResult.Status.EXPORT_DONE -> showMessage("Result saved at ${result.resultUri}")else -> {}}}}}