|
|
@@ -1,240 +0,0 @@
|
|
|
-package com.adealink.frame.effect.view.helper
|
|
|
-
|
|
|
-import android.content.Context
|
|
|
-import android.graphics.Paint
|
|
|
-import android.os.Bundle
|
|
|
-import android.view.View
|
|
|
-import android.view.ViewGroup
|
|
|
-import android.widget.ImageView
|
|
|
-import androidx.core.view.isVisible
|
|
|
-import com.adealink.frame.base.AppBase
|
|
|
-import com.adealink.frame.effect.data.AnimExtraConfig
|
|
|
-import com.adealink.frame.effect.data.DynamicAnimImage
|
|
|
-import com.adealink.frame.effect.data.DynamicAnimText
|
|
|
-import com.adealink.frame.effect.data.IAnimDynamicProvider
|
|
|
-import com.adealink.frame.effect.data.INFINITE_LOOP
|
|
|
-import com.adealink.frame.effect.data.TAG_EFFECT_ANIM_VIEW_TC
|
|
|
-import com.adealink.frame.effect.view.IWeAnimPlayListener
|
|
|
-import com.adealink.frame.ext.safeParseColor
|
|
|
-import com.adealink.frame.tceffect.TCEffectManager
|
|
|
-import com.adealink.frame.util.runOnUiThread
|
|
|
-import com.tencent.tcmediax.tceffectplayer.api.TCEffectAnimView
|
|
|
-import com.tencent.tcmediax.tceffectplayer.api.TCEffectConfig
|
|
|
-import com.tencent.tcmediax.tceffectplayer.api.TCEffectPlayerConstant
|
|
|
-import com.tencent.tcmediax.tceffectplayer.api.data.TCEffectText
|
|
|
-import com.tencent.tcmediax.tceffectplayer.api.mix.IFetchResourceImgResult
|
|
|
-import com.tencent.tcmediax.tceffectplayer.api.mix.IFetchResourceTxtResult
|
|
|
-import java.lang.ref.WeakReference
|
|
|
-import com.tencent.tcmediax.tceffectplayer.api.mix.IFetchResource as ITCFetchResource
|
|
|
-
|
|
|
-class TCAnimViewHelper : IWeAnimViewHelper {
|
|
|
- private var animViewRef: WeakReference<TCEffectAnimView?> = WeakReference(null)
|
|
|
- private val animView: TCEffectAnimView?
|
|
|
- get() {
|
|
|
- return animViewRef.get()
|
|
|
- }
|
|
|
-
|
|
|
- private var animExtraConfig: AnimExtraConfig? = null
|
|
|
- private var listener: IWeAnimPlayListener? = null
|
|
|
- private var filePath: String? = null
|
|
|
- private var playListener = object : TCEffectAnimView.IAnimPlayListener {
|
|
|
- override fun onPlayStart() {
|
|
|
- runOnUiThread {
|
|
|
- listener?.onPlayStart()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun onPlayEnd() {
|
|
|
- runOnUiThread {
|
|
|
- listener?.onPlayEnd()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun onPlayError(p0: Int) {
|
|
|
- runOnUiThread {
|
|
|
- listener?.onPlayError(p0.toString())
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun onPlayEvent(p0: Int, p1: Bundle?) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun setFile(filePath: String, dynamicProvider: IAnimDynamicProvider?) {
|
|
|
- AppBase.log.d(TAG_EFFECT_ANIM_VIEW_TC, "setFile, filePath:${filePath}")
|
|
|
- this.filePath = filePath
|
|
|
- var fetchResource: ITCFetchResource? = null
|
|
|
- if (dynamicProvider != null) {
|
|
|
- val textProviderMap = hashMapOf<String, DynamicAnimText>()
|
|
|
- val imgProviderMap = hashMapOf<String, DynamicAnimImage>()
|
|
|
- dynamicProvider.provideText { map ->
|
|
|
- if (map.isNullOrEmpty()) {
|
|
|
- return@provideText
|
|
|
- }
|
|
|
- for (entry in map.entries) {
|
|
|
- textProviderMap[entry.key] = entry.value
|
|
|
- }
|
|
|
- }
|
|
|
- dynamicProvider.provideImage { map ->
|
|
|
- if (map.isNullOrEmpty()) {
|
|
|
- return@provideImage
|
|
|
- }
|
|
|
- for (entry in map.entries) {
|
|
|
- imgProviderMap[entry.key] = entry.value
|
|
|
- }
|
|
|
- }
|
|
|
- fetchResource = object : ITCFetchResource {
|
|
|
- override fun fetchImage(
|
|
|
- resource: com.tencent.tcmediax.tceffectplayer.api.mix.Resource,
|
|
|
- result: IFetchResourceImgResult
|
|
|
- ) {
|
|
|
- result.fetch(imgProviderMap[resource.tag]?.bitmapSupplier?.invoke())
|
|
|
- }
|
|
|
-
|
|
|
- override fun fetchText(
|
|
|
- resource: com.tencent.tcmediax.tceffectplayer.api.mix.Resource,
|
|
|
- result: IFetchResourceTxtResult
|
|
|
- ) {
|
|
|
- val resultText = textProviderMap[resource.tag]
|
|
|
- if (resultText == null) {
|
|
|
- // 使用loadTextForPlayer(null)时会显示占位tag文字,参考ludo游戏获胜宝箱动效,暂时先不用
|
|
|
- // result.loadTextForPlayer(null)
|
|
|
- result.fetch(null)
|
|
|
- } else {
|
|
|
- val tcEffectText = TCEffectText()
|
|
|
- tcEffectText.text = resultText.text
|
|
|
- tcEffectText.color = resultText.colorInt ?: safeParseColor(resultText.color)
|
|
|
- tcEffectText.alignment = when(resultText.textAlignment) {
|
|
|
- Paint.Align.LEFT -> TCEffectText.TEXT_ALIGNMENT_LEFT
|
|
|
- Paint.Align.RIGHT -> TCEffectText.TEXT_ALIGNMENT_RIGHT
|
|
|
- Paint.Align.CENTER -> TCEffectText.TEXT_ALIGNMENT_CENTER
|
|
|
- }
|
|
|
- if (resultText.fontBold) {
|
|
|
- tcEffectText.fontStyle = "bold"
|
|
|
- }
|
|
|
- result.loadTextForPlayer(tcEffectText)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun releaseResource(resources: MutableList<com.tencent.tcmediax.tceffectplayer.api.mix.Resource>) {
|
|
|
- resources.forEach {
|
|
|
- it.bitmap?.recycle()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- animView?.setPlayListener(playListener)
|
|
|
- animView?.setFetchResource(fetchResource)
|
|
|
- if (animExtraConfig?.autoPlay == true) {
|
|
|
- animView?.startPlay(filePath)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun startPlay() {
|
|
|
- //目前resume支持不完整,直接开始重新播放
|
|
|
- val filePath = filePath ?: return
|
|
|
- if (animView?.isPlaying == true) {
|
|
|
- return
|
|
|
- }
|
|
|
- AppBase.log.d(TAG_EFFECT_ANIM_VIEW_TC, "startPlay, filePath:${filePath}")
|
|
|
- animView?.startPlay(filePath)
|
|
|
- }
|
|
|
-
|
|
|
- override fun pausePlay() {
|
|
|
- animView?.pause()
|
|
|
- }
|
|
|
-
|
|
|
- override fun stopPlay() {
|
|
|
- animView?.stopPlay(true)
|
|
|
- }
|
|
|
-
|
|
|
- override fun setListener(listener: IWeAnimPlayListener?) {
|
|
|
- this.listener = listener
|
|
|
- }
|
|
|
-
|
|
|
- override fun setConfig(config: AnimExtraConfig) {
|
|
|
- this.animExtraConfig = config
|
|
|
- animView?.apply {
|
|
|
- val tceConfigExtendMap: HashMap<String, Any> = hashMapOf(
|
|
|
- TCEffectPlayerConstant.PARAM_OPTIONAL_STRING_EXTRA_LICENSE_KEY to TCEffectManager.getOldLicense()
|
|
|
- )
|
|
|
- setConfig(
|
|
|
- TCEffectConfig.Builder()
|
|
|
- .setFreezeFrame(if (animExtraConfig?.isFreezeLast == true) TCEffectConfig.FREEZE_FRAME_LAST else TCEffectConfig.FREEZE_FRAME_NONE)
|
|
|
- .setCodecType(TCEffectConfig.CodecType.TX_LITEAV_SDK)
|
|
|
- .setExtendMapParams(tceConfigExtendMap).build()
|
|
|
- )
|
|
|
- val loopCnt = config.loop
|
|
|
- //tc循环次数要特殊处理 <=0代表无限循环
|
|
|
- val loops = when {
|
|
|
- loopCnt < 0 -> {
|
|
|
- INFINITE_LOOP
|
|
|
- }
|
|
|
- loopCnt == 0 -> {
|
|
|
- 1
|
|
|
- }
|
|
|
- else -> {
|
|
|
- loopCnt
|
|
|
- }
|
|
|
- }
|
|
|
- setLoopCount(loops)
|
|
|
- setScaleType(
|
|
|
- getTCScaleTypeBy(
|
|
|
- config.scaleType
|
|
|
- ))
|
|
|
- setMute(config.mute)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun setMute(mute: Boolean) {
|
|
|
- animView?.setMute(mute)
|
|
|
- }
|
|
|
-
|
|
|
- override fun createView(context: Context): View {
|
|
|
- val animView = TCEffectAnimView(context)
|
|
|
- this.animViewRef = WeakReference(animView)
|
|
|
- return animView
|
|
|
- }
|
|
|
-
|
|
|
- override fun getView(context: Context): View? {
|
|
|
- return animView
|
|
|
- }
|
|
|
-
|
|
|
- override fun show() {
|
|
|
- animView?.visibility = View.VISIBLE
|
|
|
- }
|
|
|
-
|
|
|
- override fun gone() {
|
|
|
- animView?.visibility = View.GONE
|
|
|
- }
|
|
|
-
|
|
|
- override fun removeFromParent() {
|
|
|
- animView?.let {
|
|
|
- it.setPlayListener(null)
|
|
|
- (it.parent as? ViewGroup)?.removeView(it)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun onAttachedToWindow() {
|
|
|
- startPlay()
|
|
|
- }
|
|
|
-
|
|
|
- override fun onDetachedFromWindow() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private fun getTCScaleTypeBy(type: ImageView.ScaleType): TCEffectPlayerConstant.ScaleType? {
|
|
|
- return when (type) {
|
|
|
- ImageView.ScaleType.MATRIX -> null
|
|
|
- ImageView.ScaleType.FIT_XY -> TCEffectPlayerConstant.ScaleType.FIT_XY
|
|
|
- ImageView.ScaleType.FIT_START -> null
|
|
|
- ImageView.ScaleType.FIT_CENTER -> TCEffectPlayerConstant.ScaleType.FIT_CENTER
|
|
|
- ImageView.ScaleType.FIT_END -> null
|
|
|
- ImageView.ScaleType.CENTER -> null
|
|
|
- ImageView.ScaleType.CENTER_CROP -> TCEffectPlayerConstant.ScaleType.CENTER_CROP
|
|
|
- ImageView.ScaleType.CENTER_INSIDE -> null
|
|
|
- }
|
|
|
- }
|
|
|
-}
|