feat:调整通用飘屏-SVGA方案(自己做进场/退出动画,不用SVGA的动态文本了,自己叠加一个TextView)

This commit is contained in:
max
2024-04-23 18:58:50 +08:00
parent e334c7ce16
commit ac14be2c88
4 changed files with 76 additions and 44 deletions

View File

@@ -2,18 +2,18 @@ package com.chwl.app.notify.views
import android.content.Context
import android.graphics.Color
import android.text.Layout
import android.text.StaticLayout
import android.text.TextPaint
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.chwl.app.R
import com.chwl.app.avroom.widget.TemplateMessageAdapter
import com.chwl.app.common.svga.SimpleSvgaCallback
import com.chwl.app.support.float.BaseFloatView
import com.chwl.app.utils.CommonJumpHelper
import com.chwl.core.home.bean.BannerInfo
import com.chwl.core.im.custom.bean.RoomTemplateNotifyMsgBean
import com.example.lib_utils.log.ILog
import com.opensource.svgaplayer.SVGADrawable
import com.opensource.svgaplayer.SVGADynamicEntity
import com.opensource.svgaplayer.SVGAImageView
import com.opensource.svgaplayer.SVGAParser
import com.opensource.svgaplayer.SVGAVideoEntity
@@ -21,17 +21,14 @@ import java.net.URL
class TemplateSvgaNotify(context: Context) : BaseFloatView(context),
TemplateMessageAdapter.Listener {
TemplateMessageAdapter.Listener, ILog {
private val templateMessageAdapter = TemplateMessageAdapter(this)
private val svgaView = SVGAImageView(context)
var onShowUserCard: ((String) -> Unit)? = null
init {
svgaView.loops = 1
svgaView.clearsAfterDetached = true
addView(svgaView, LayoutParams(LayoutParams.MATCH_PARENT, 0))
LayoutInflater.from(context).inflate(R.layout.layout_template_notify_svga, this, true)
}
override fun onBind(item: Any) {
@@ -49,53 +46,47 @@ class TemplateSvgaNotify(context: Context) : BaseFloatView(context),
requestRemoveSelf()
return
}
val params = svgaView.layoutParams as ConstraintLayout.LayoutParams
params.dimensionRatio = data.getDimensionRatio() ?: "75:11"
svgaView.layoutParams = params
svgaView.callback = object : SimpleSvgaCallback() {
override fun onFinished() {
requestRemoveSelf()
}
}
val textView = rootView.findViewById<TextView>(R.id.tv_text)
val textSize = data.fontSize?.toFloat() ?: 12f
val textColor =
templateMessageAdapter.parseColor(data.textColor) ?: Color.WHITE
textView.textSize = textSize
textView.setTextColor(textColor)
val svgaView = rootView.findViewById<SVGAImageView>(R.id.iv_bg)
SVGAParser.shareParser().decodeFromURL(
URL(resourceContent),
object : SVGAParser.ParseCompletion {
override fun onComplete(videoItem: SVGAVideoEntity) {
val text = templateMessageAdapter.parse(context, data) ?: ""
val textKey = data.getSvgaTextKey()
val textSize = data.fontSize?.toFloat() ?: 24f
val textColor =
templateMessageAdapter.parseColor(data.textColor) ?: Color.WHITE
val dynamicEntity = SVGADynamicEntity()
val textPaint = TextPaint()
textPaint.color = textColor //字體顏色
textPaint.textSize = textSize //字體大小
dynamicEntity.setDynamicText(
StaticLayout(
text,
0,
text.length,
textPaint,
0,
Layout.Alignment.ALIGN_CENTER,
1.0f,
0.0f,
false
), textKey
)
logD("onComplete width:${videoItem.videoSize.width}")
logD("onComplete height:${videoItem.videoSize.height}")
val width = videoItem.videoSize.width
val height = videoItem.videoSize.height
var dimensionRatio = "75:11"
if (width > 0 && height > 0) {
dimensionRatio = "$width:$height"
}
val params = svgaView.layoutParams as ConstraintLayout.LayoutParams
params.dimensionRatio = dimensionRatio
svgaView.layoutParams = params
val skipType = data.skipType
if (skipType != null) {
svgaView.setOnClickListener {
val clickAction = View.OnClickListener {
if (skipType == BannerInfo.SKIP_TYPE_ROOM_USER_CARD) {
onShowUserCard?.invoke(data.skipContent ?: "")
} else {
CommonJumpHelper.bannerJump(context, skipType, data.skipContent)
}
}
rootView.setOnClickListener(clickAction)
textView.setOnClickListener(clickAction)
}
val drawable = SVGADrawable(videoItem, dynamicEntity)
val drawable = SVGADrawable(videoItem)
svgaView.setImageDrawable(drawable)
svgaView.stepToFrame(0, true)
svgaView.startAnimation()
templateMessageAdapter.convert(textView, data)
startEnterAnim()
startDelayRemove()
}
override fun onError() {

View File

@@ -32,7 +32,7 @@
app:layout_constraintEnd_toEndOf="@id/iv_bg"
app:layout_constraintStart_toStartOf="@id/iv_bg"
app:layout_constraintTop_toTopOf="@id/iv_bg"
app:layout_constraintWidth_percent="0.626"
app:layout_constraintWidth_percent="0.68"
tools:layout_height="wrap_content"
tools:text="Message" />
</merge>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<com.opensource.svgaplayer.SVGAImageView
android:id="@+id/iv_bg"
android:layout_width="match_parent"
android:layout_height="0dp"
app:clearsAfterDetached="true"
app:layout_constraintTop_toTopOf="parent"
app:loopCount="1"
tools:src="@drawable/smash_eggs_notity_bg_4" />
<com.coorchice.library.SuperTextView
android:id="@+id/tv_text"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:includeFontPadding="false"
android:lineSpacingExtra="0dp"
android:lineSpacingMultiplier="0.8"
android:maxLines="2"
android:textColor="@color/white"
android:textDirection="locale"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@id/iv_bg"
app:layout_constraintEnd_toEndOf="@id/iv_bg"
app:layout_constraintStart_toStartOf="@id/iv_bg"
app:layout_constraintTop_toTopOf="@id/iv_bg"
app:layout_constraintWidth_percent="0.68"
tools:layout_height="wrap_content"
tools:text="Message" />
</merge>