demo/app/assets/MotionRes/avatarRes
下)。由于 Demo 中的 demo/app/assets/MotionRes/avatarRes
下的 avatar 资源是加密授权过的,所以客户无法直接使用。com.tencent.demo.avatar
文件夹下的所有类到您的工程中。com.tencent.demo.avatar.AvatarEditActivity
类,添加如下代码。<com.tencent.demo.avatar.view.AvatarPanelandroid:id="@+id/avatar_panel"android:layout_width="match_parent"android:layout_height="300dp"app:layout_constraintBottom_toBottomOf="parent" />
avatarPanel.setAvatarPanelCallBack(new AvatarPanelCallBack() {@Overridepublic void onReceiverBindData(List<AvatarData> avatarData) {mXMagicApi.updateAvatar(avatarData, AvatarEditActivity.this);}@Overridepublic void onItemChecked(MainTab mainTab, AvatarItem avatarItem) {if (avatarItem.avatarData == null && URLUtil.isNetworkUrl(avatarItem.downloadUrl)) { //此处表示要进行动态下载downloadAvatarData(avatarItem, () -> updateConfig(avatarItem));} else {updateConfig(avatarItem);List<AvatarData> bindAvatarData = AvatarResManager.getAvatarDataByBindData(avatarItem.bindData);mXmagicApi.updateAvatar(bindAvatarData, AvatarActivity.this);}}@Overridepublic void onItemValueChange(AvatarItem avatarItem) {updateConfig(avatarItem);}@Overridepublic boolean onShowPage(AvatarPageInf avatarPageInf, SubTab subTab) {if (subTab != null && subTab.items != null && subTab.items.size() > 0) {AvatarItem avatarItem = subTab.items.get(0);if (avatarItem.type == AvatarData.TYPE_SLIDER && avatarItem.avatarData == null && URLUtil.isNetworkUrl(avatarItem.downloadUrl)) { //此处表示要进行动态下载downloadAvatarData(avatarItem, () -> {if (avatarPageInf != null) {avatarPageInf.refresh();}});return false;}}return true;}private void updateConfig(AvatarItem avatarItem) {if (mXmagicApi != null && avatarItem != null) {List<AvatarData> avatarConfigList = new ArrayList<>();avatarConfigList.add(avatarItem.avatarData);mXmagicApi.updateAvatar(avatarConfigList, AvatarActivity.this);}}});
AvatarResManager.getInstance().getAvatarData(avatarResName, getAvatarConfig(), allData -> {avatarPanel.initView(allData);});
protected void initXMagicAndLoadAvatar(String avatarConfig, UpdatePropertyListener updatePropertyListener) {if (mXMagicApi == null && !isFinishing() && !isDestroyed()) {WorkThread.getInstance().run(() - > {synchronized(lock) {if (isXMagicApiDestroyed) {return;}mXMagicApi = XmagicApiUtils.createXMagicApi(getApplicationContext(), null);AvatarResManager.getInstance().loadAvatarRes(mXMagicApi, avatarResName, avatarConfig == null ? getAvatarConfig() : avatarConfig, updatePropertyListener);setAvatarPlaneType();}}, this.hashCode());}}
/*** 保存用户设置的属性或者默认属性值*/public void onSaveBtnClick() {//通过AvatarResManager的getUsedAvatarData获取用户配置的属性List < AvatarData > avatarDataList = AvatarResManager.getUsedAvatarData(avatarPanel.getMainTabList());//通过XmagicApi.exportAvatar方法将配置的属性转换为字符串String content = XmagicApi.exportAvatar(avatarDataList);//保存此字符串即可,下载使用时将此字符串设置给SDK的loadAvatarRes方法,即可恢复此形象if (mXMagicApi != null) {mXMagicApi.exportCurrentTexture(bitmap - > saveAvatarModes(bitmap, content));}}
本页内容是否解决了您的问题?