修改首页游戏遮罩
This commit is contained in:
54
app/src/main/java/com/gh/common/view/RadiusCardView.kt
Normal file
54
app/src/main/java/com/gh/common/view/RadiusCardView.kt
Normal file
@ -0,0 +1,54 @@
|
||||
package com.gh.common.view
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.util.AttributeSet
|
||||
import androidx.cardview.widget.CardView
|
||||
import com.gh.common.util.dip2px
|
||||
import com.gh.gamecenter.R
|
||||
|
||||
class RadiusCardView : CardView {
|
||||
var topLeftRadius = 0f
|
||||
var topRightRadius = 0f
|
||||
var bottomLeftRadius = 0f
|
||||
var bottomRightRadius = 0f
|
||||
|
||||
constructor(context: Context) : this(context, null)
|
||||
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
||||
radius = 0f
|
||||
val array = context.obtainStyledAttributes(attrs, R.styleable.RadiusCardView)
|
||||
topLeftRadius = array.getDimensionPixelSize(R.styleable.RadiusCardView_topLeftRadius, 0).toFloat()
|
||||
topRightRadius = array.getDimensionPixelSize(R.styleable.RadiusCardView_topRightRadius, 0).toFloat()
|
||||
bottomLeftRadius = array.getDimensionPixelSize(R.styleable.RadiusCardView_bottomLeftRadius, 0).toFloat()
|
||||
bottomRightRadius = array.getDimensionPixelSize(R.styleable.RadiusCardView_bottomRightRadius, 0).toFloat()
|
||||
background = ColorDrawable()
|
||||
array.recycle()
|
||||
}
|
||||
|
||||
@SuppressLint("DrawAllocation")
|
||||
override fun onDraw(canvas: Canvas?) {
|
||||
val path = Path()
|
||||
val rectF: RectF = getRectF()
|
||||
val radius = floatArrayOf(topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomLeftRadius, bottomLeftRadius, bottomLeftRadius, bottomLeftRadius)
|
||||
path.addRoundRect(rectF, radius, Path.Direction.CW)
|
||||
canvas?.clipPath(path, Region.Op.INTERSECT)
|
||||
super.onDraw(canvas)
|
||||
}
|
||||
|
||||
fun setRadius(tLRadius: Float, tRRadius: Float, bLRadius: Float, bRRadius: Float) {
|
||||
topLeftRadius = tLRadius.dip2px().toFloat()
|
||||
topRightRadius = tRRadius.dip2px().toFloat()
|
||||
bottomLeftRadius = bLRadius.dip2px().toFloat()
|
||||
bottomRightRadius = bRRadius.dip2px().toFloat()
|
||||
invalidate()
|
||||
}
|
||||
|
||||
private fun getRectF(): RectF {
|
||||
val rect = Rect()
|
||||
getDrawingRect(rect)
|
||||
return RectF(rect)
|
||||
}
|
||||
}
|
||||
@ -2,10 +2,8 @@ package com.gh.gamecenter.home
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.gh.common.constant.ItemViewType
|
||||
@ -14,6 +12,7 @@ import com.gh.common.exposure.ExposureSource
|
||||
import com.gh.common.exposure.ExposureType
|
||||
import com.gh.common.exposure.IExposable
|
||||
import com.gh.common.util.*
|
||||
import com.gh.common.view.DrawableView
|
||||
import com.gh.gamecenter.AboutActivity
|
||||
import com.gh.gamecenter.GameDetailActivity
|
||||
import com.gh.gamecenter.R
|
||||
@ -190,8 +189,8 @@ class HomeFragmentAdapter(context: Context,
|
||||
eTrace = null,
|
||||
event = ExposureType.EXPOSURE)
|
||||
|
||||
holder.binding.gameImage.goneIf(homeItemData.attachGame?.displayContent == "video" && homeItemData.attachGame?.linkGame?.topVideo != null)
|
||||
holder.binding.gameBrief.goneIf(homeItemData.attachGame?.displayContent == "video" && homeItemData.attachGame?.linkGame?.topVideo != null)
|
||||
holder.binding.gameBrief.text = homeItemData.attachGame?.recommendText
|
||||
holder.binding.gameImage.visibleIf(!(homeItemData.attachGame?.displayContent == "video" && homeItemData.attachGame?.linkGame?.topVideo != null))
|
||||
holder.binding.autoVideoView.goneIf(homeItemData.attachGame?.displayContent != "video" || homeItemData.attachGame?.linkGame?.topVideo == null)
|
||||
if (!holder.binding.autoVideoView.isInPlayingState
|
||||
&& homeItemData.attachGame?.displayContent == "video"
|
||||
@ -209,23 +208,12 @@ class HomeFragmentAdapter(context: Context,
|
||||
.setShowFullAnimation(false)
|
||||
.build(holder.binding.autoVideoView)
|
||||
holder.binding.autoVideoView.updateThumb(topVideo?.poster ?: "")
|
||||
holder.binding.autoVideoView.setGameEntity(homeItemData.attachGame?.linkGame)
|
||||
if (!homeSetting?.placeholderColor.isNullOrEmpty()) {
|
||||
try {
|
||||
holder.binding.autoVideoView.detailBtn.background = ColorDrawable(Color.parseColor(game.homeSetting.placeholderColor))
|
||||
} catch (e: Exception) {
|
||||
val color = RandomUtils.getRandomPlaceholderColor()
|
||||
holder.binding.autoVideoView.detailBtn.setBackgroundColor(ContextCompat.getColor(holder.itemView.context, color))
|
||||
}
|
||||
} else {
|
||||
val color = RandomUtils.getRandomPlaceholderColor()
|
||||
holder.binding.autoVideoView.detailBtn.setBackgroundColor(ContextCompat.getColor(holder.itemView.context, color))
|
||||
}
|
||||
holder.binding.autoVideoView.detailBtn.setOnClickListener {
|
||||
holder.binding.autoVideoView.setData(homeItemData.attachGame?.linkGame,homeSetting?.placeholderColor)
|
||||
holder.binding.autoVideoView.detailBtn?.setOnClickListener {
|
||||
holder.itemView.performClick()
|
||||
holder.binding.autoVideoView.uploadVideoStreamingPlaying("点击遮罩")
|
||||
}
|
||||
holder.binding.autoVideoView.setOnclickListener(View.OnClickListener { holder.itemView.performClick() })
|
||||
holder.binding.autoVideoView.setOnVideoClickListener(View.OnClickListener { holder.itemView.performClick() })
|
||||
}
|
||||
|
||||
holder.binding.gameImage.setOnClickListener {
|
||||
|
||||
@ -13,7 +13,6 @@ class HomeGameItemViewHolder(val binding: HomeGameItemBinding) : BaseRecyclerVie
|
||||
|
||||
fun bindGame(game: GameEntity) {
|
||||
binding.data = game
|
||||
binding.gameBrief.text = game.brief
|
||||
|
||||
binding.gameTags.postDelayed({
|
||||
binding.gameTags.visibility = if (game.tagStyle.isNotEmpty()) {
|
||||
|
||||
@ -1,15 +1,22 @@
|
||||
package com.gh.gamecenter.home.video
|
||||
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ValueAnimator
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.view.Surface
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import com.gh.common.constant.Constants
|
||||
import com.gh.common.runOnIoThread
|
||||
import com.gh.common.runOnUiThread
|
||||
import com.gh.common.util.*
|
||||
import com.gh.common.view.DrawableView
|
||||
import com.gh.common.view.RadiusCardView
|
||||
import com.gh.download.cache.ExoCacheManager
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
@ -18,26 +25,28 @@ import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
|
||||
import com.shuyu.gsyvideoplayer.video.base.GSYVideoViewBridge
|
||||
import com.squareup.picasso.Picasso
|
||||
import io.reactivex.disposables.Disposable
|
||||
import moe.codeest.enviews.ENDownloadView
|
||||
import java.util.*
|
||||
|
||||
class AutomaticVideoView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : StandardGSYVideoPlayer(context, attrs) {
|
||||
var thumbImage: ImageView = findViewById(R.id.thumbImage)
|
||||
var detailBtn: TextView = findViewById(R.id.detailBtn)
|
||||
var containerView: RadiusCardView = findViewById(R.id.container)
|
||||
var detailBtn: TextView? = null
|
||||
private var mMuteDisposable: Disposable? = null
|
||||
private var mMaskDisposable: Disposable? = null
|
||||
private val mUUID = UUID.randomUUID().toString()
|
||||
private var shouldShowMask = true
|
||||
private var mContentLength = 0.0
|
||||
private var gameEntity: GameEntity? = null
|
||||
private var placeholderColor: String? = null
|
||||
private var mClickListener: OnClickListener? = null
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.empty_control_video
|
||||
}
|
||||
|
||||
fun setGameEntity(entity: GameEntity?) {
|
||||
fun setData(entity: GameEntity?, color: String?) {
|
||||
gameEntity = entity
|
||||
placeholderColor = color
|
||||
}
|
||||
|
||||
fun startPlayLogic(showMask: Boolean) {
|
||||
@ -84,25 +93,73 @@ class AutomaticVideoView @JvmOverloads constructor(context: Context, attrs: Attr
|
||||
}
|
||||
|
||||
private fun showDetailMask() {
|
||||
detailBtn = (parent as ViewGroup).findViewById(R.id.detailBtn)
|
||||
if (mMaskDisposable != null) {
|
||||
mMaskDisposable?.dispose()
|
||||
mMaskDisposable = null
|
||||
}
|
||||
setDetailMaskBackground()
|
||||
mMaskDisposable = countDownTimer(5) { finish, _ ->
|
||||
if (finish) {
|
||||
val offset = 44f.dip2px().toFloat()
|
||||
detailBtn.translationY = offset
|
||||
detailBtn.alpha = 0f
|
||||
detailBtn.visibility = View.VISIBLE
|
||||
detailBtn.animate().translationY(0f).alpha(1f).setDuration(800).doOnEnd {
|
||||
uploadVideoStreamingPlaying("出现遮罩")
|
||||
}.start()
|
||||
containerView.setRadius(6f, 6f, 0f, 0f)
|
||||
|
||||
detailBtn?.let { mask ->
|
||||
var params = mask.layoutParams as ConstraintLayout.LayoutParams
|
||||
params.height = 0
|
||||
mask.layoutParams = params
|
||||
mask.alpha = 0f
|
||||
mask.visibility = View.VISIBLE
|
||||
val heightAnimator = ValueAnimator.ofFloat(0f, offset).apply {
|
||||
addUpdateListener {
|
||||
params = mask.layoutParams as ConstraintLayout.LayoutParams
|
||||
params.height = (it.animatedValue as Float).toInt()
|
||||
mask.layoutParams = params
|
||||
}
|
||||
}
|
||||
val alphaAnimator = ValueAnimator.ofFloat(0f, 1F).apply {
|
||||
addUpdateListener {
|
||||
mask.alpha = it.animatedValue as Float
|
||||
}
|
||||
}
|
||||
val animatorSet = AnimatorSet()
|
||||
animatorSet.playTogether(heightAnimator, alphaAnimator)
|
||||
animatorSet.duration = 800L
|
||||
animatorSet.doOnEnd {
|
||||
uploadVideoStreamingPlaying("出现遮罩")
|
||||
}
|
||||
animatorSet.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setDetailMaskBackground() {
|
||||
if (!placeholderColor.isNullOrEmpty()) {
|
||||
try {
|
||||
//去掉透明度
|
||||
val color = if (placeholderColor!!.length == 9) {
|
||||
"#${placeholderColor!!.substring(3)}"
|
||||
} else {
|
||||
placeholderColor
|
||||
}
|
||||
val drawable = DrawableView.getCornerDrawable(Color.parseColor(color), 0f, 0f, 6f, 6f)
|
||||
detailBtn?.background = drawable
|
||||
} catch (e: Exception) {
|
||||
val color = RandomUtils.getRandomPlaceholderColor()
|
||||
val drawable = DrawableView.getCornerDrawable(color, 0f, 0f, 6f, 6f)
|
||||
detailBtn?.background = drawable
|
||||
}
|
||||
} else {
|
||||
val color = RandomUtils.getRandomPlaceholderColor()
|
||||
val drawable = DrawableView.getCornerDrawable(color, 0f, 0f, 6f, 6f)
|
||||
detailBtn?.background = drawable
|
||||
}
|
||||
}
|
||||
|
||||
fun resetDetailMask() {
|
||||
detailBtn.visibility = View.GONE
|
||||
detailBtn?.visibility = View.GONE
|
||||
containerView.setRadius(6f, 6f, 6f, 6f)
|
||||
if (mMaskDisposable != null && !mMaskDisposable!!.isDisposed) {
|
||||
mMaskDisposable?.dispose()
|
||||
mMaskDisposable = null
|
||||
@ -184,7 +241,7 @@ class AutomaticVideoView @JvmOverloads constructor(context: Context, attrs: Attr
|
||||
resetDetailMask()
|
||||
}
|
||||
|
||||
fun setOnclickListener(listener: OnClickListener) {
|
||||
fun setOnVideoClickListener(listener: OnClickListener) {
|
||||
mClickListener = listener
|
||||
}
|
||||
|
||||
@ -207,7 +264,7 @@ class AutomaticVideoView @JvmOverloads constructor(context: Context, attrs: Attr
|
||||
|
||||
//https://exoplayer.dev/hello-world.html#a-note-on-threading
|
||||
runOnUiThread {
|
||||
LogUtils.uploadHomeVideoStreamingPlaying(action, detailBtn.visibility == View.VISIBLE, topVideo.id, topVideo.title,
|
||||
LogUtils.uploadHomeVideoStreamingPlaying(action, detailBtn?.visibility == View.VISIBLE, topVideo.id, topVideo.title,
|
||||
gameEntity?.id, gameEntity?.name, mContentLength, videoTotalTime, videoPlayTs, progress.toInt())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user