|
@@ -1,16 +1,16 @@
|
|
|
package com.swago.room.giftdandao
|
|
|
|
|
|
import android.animation.Animator
|
|
|
+import android.animation.AnimatorInflater
|
|
|
+import android.animation.AnimatorListenerAdapter
|
|
|
import android.animation.AnimatorSet
|
|
|
import android.animation.ObjectAnimator
|
|
|
import android.app.Service
|
|
|
import android.content.Context
|
|
|
import android.os.Vibrator
|
|
|
import android.util.AttributeSet
|
|
|
-import android.util.Log
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
-import android.view.animation.BounceInterpolator
|
|
|
import android.view.animation.DecelerateInterpolator
|
|
|
import android.widget.FrameLayout
|
|
|
import android.widget.ImageView
|
|
@@ -26,7 +26,6 @@ import com.swago.baseswago.util.DpPxUtil
|
|
|
import com.swago.baseswago.util.LogUtil
|
|
|
import com.swago.baseswago.util.SwagoInfo
|
|
|
import com.swago.baseswago.util.UserInfo
|
|
|
-import com.swago.room.BuildConfig
|
|
|
import com.swago.room.R
|
|
|
import com.swago.room.databinding.ViewItemGiftBinding
|
|
|
import java.io.File
|
|
@@ -52,6 +51,10 @@ class GiftDanDaoView : FrameLayout {
|
|
|
ArrayList<ImageView>()
|
|
|
}
|
|
|
|
|
|
+ private val imageViewPrizeData by lazy {
|
|
|
+ ArrayList<ImageView>()
|
|
|
+ }
|
|
|
+
|
|
|
constructor(context: Context) : super(context) {
|
|
|
initView(context)
|
|
|
}
|
|
@@ -63,6 +66,9 @@ class GiftDanDaoView : FrameLayout {
|
|
|
private var svgaPlayWhichType = 0
|
|
|
|
|
|
private var vibrator: Vibrator? = null
|
|
|
+ private var aniamtionRotate:Animator ?= null
|
|
|
+ private var aniamtionScale:Animator ?= null
|
|
|
+ private var aniamtionNum:Animator ?= null
|
|
|
|
|
|
private fun initView(context: Context) {
|
|
|
vibrator = context.getSystemService(Service.VIBRATOR_SERVICE) as Vibrator
|
|
@@ -71,9 +77,48 @@ class GiftDanDaoView : FrameLayout {
|
|
|
svgParser2 = SVGAParser(context)
|
|
|
for (i in 0..5){
|
|
|
val imageView = ImageView(context)
|
|
|
+ val imageViewPrize = ImageView(context)
|
|
|
imageViewData.add(imageView)
|
|
|
+ imageViewPrizeData.add(imageViewPrize)
|
|
|
}
|
|
|
isDevicesRtl = SwagoInfo.isMirror()
|
|
|
+ setAniamtion()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun setAniamtion() {
|
|
|
+ aniamtionRotate = AnimatorInflater.loadAnimator(context,R.animator.scale_rotate)
|
|
|
+ aniamtionScale = AnimatorInflater.loadAnimator(context,R.animator.scale)
|
|
|
+ aniamtionNum = AnimatorInflater.loadAnimator(context,R.animator.scale)
|
|
|
+ aniamtionRotate?.setTarget(binding?.ivPrizeBg)
|
|
|
+ aniamtionScale?.setTarget(binding?.ivPrizeFrame)
|
|
|
+ aniamtionNum?.setTarget(binding?.llPrizeNum)
|
|
|
+ aniamtionRotate?.addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationEnd(animation: Animator) {
|
|
|
+ super.onAnimationEnd(animation)
|
|
|
+ binding?.ivPrizeBg?.rotation = 0f
|
|
|
+ binding?.ivPrizeBg?.scaleX = 1.0f
|
|
|
+ binding?.ivPrizeBg?.scaleY = 1.0f
|
|
|
+ aniamtionRotate?.setTarget(binding?.ivPrizeBg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ aniamtionScale?.addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationEnd(animation: Animator) {
|
|
|
+ super.onAnimationEnd(animation)
|
|
|
+ binding?.ivPrizeFrame?.rotation = 0f
|
|
|
+ binding?.ivPrizeFrame?.scaleX = 1.0f
|
|
|
+ binding?.ivPrizeFrame?.scaleY = 1.0f
|
|
|
+ aniamtionScale?.setTarget(binding?.ivPrizeFrame)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ aniamtionNum?.addListener(object : AnimatorListenerAdapter() {
|
|
|
+ override fun onAnimationEnd(animation: Animator) {
|
|
|
+ super.onAnimationEnd(animation)
|
|
|
+ binding?.llPrizeNum?.rotation = 0f
|
|
|
+ binding?.llPrizeNum?.scaleX = 1.0f
|
|
|
+ binding?.llPrizeNum?.scaleY = 1.0f
|
|
|
+ aniamtionNum?.setTarget(binding?.llPrizeNum)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
fun addData(imGiftModel: IMGiftModel) {
|
|
@@ -195,82 +240,51 @@ class GiftDanDaoView : FrameLayout {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
clItemGift.removeCallbacks(showRunnable)
|
|
|
clItemGift.postDelayed(showRunnable, 3000)
|
|
|
if (imGiftModel.multiple != 0) {
|
|
|
when (imGiftModel.multiple) {
|
|
|
- in 1..50 -> {
|
|
|
- iv.visibility = View.VISIBLE
|
|
|
- tvWinPrize2.visibility = View.GONE
|
|
|
- svgaWinPrize.visibility = View.GONE
|
|
|
- val layoutParams = tvWinPrize.layoutParams as ConstraintLayout.LayoutParams
|
|
|
- layoutParams.marginStart = DpPxUtil.dip2px(10f)
|
|
|
- tvWinPrize.layoutParams = layoutParams
|
|
|
- iv.setImageResource(R.mipmap.win_1_50_prize)
|
|
|
- clWinPrize.visibility = View.VISIBLE
|
|
|
- tvWinPrize.text =
|
|
|
- AppContext.getContext().resources.getString(R.string.win_num_prize)
|
|
|
- .format(imGiftModel.multiple)
|
|
|
- }
|
|
|
-
|
|
|
- in 51..100 -> {
|
|
|
- iv.visibility = View.VISIBLE
|
|
|
- tvWinPrize2.visibility = View.GONE
|
|
|
- svgaWinPrize.visibility = View.GONE
|
|
|
- val layoutParams = tvWinPrize.layoutParams as ConstraintLayout.LayoutParams
|
|
|
- layoutParams.marginStart = DpPxUtil.dip2px(26f)
|
|
|
- tvWinPrize.layoutParams = layoutParams
|
|
|
- iv.setImageResource(R.mipmap.win_51_100_prize)
|
|
|
- clWinPrize.visibility = View.VISIBLE
|
|
|
- tvWinPrize.text =
|
|
|
- AppContext.getContext().resources.getString(R.string.win_num_prize)
|
|
|
- .format(imGiftModel.multiple)
|
|
|
- }
|
|
|
-
|
|
|
- in 100..500 -> {
|
|
|
- iv.visibility = View.GONE
|
|
|
- svgaWinPrize.visibility = View.VISIBLE
|
|
|
- playSvg2("win_101_500_prize.svga")
|
|
|
- clWinPrize.visibility = View.GONE
|
|
|
- tvWinPrize2.visibility = View.VISIBLE
|
|
|
- tvWinPrize2.text =
|
|
|
- AppContext.getContext().resources.getString(R.string.win_num_prize)
|
|
|
- .format(imGiftModel.multiple)
|
|
|
- }
|
|
|
-
|
|
|
- in 501..1000 -> {
|
|
|
- iv.visibility = View.GONE
|
|
|
- svgaWinPrize.visibility = View.VISIBLE
|
|
|
- UserInfo.getUserInfo()?.let { userInfoModel ->
|
|
|
- if (userInfoModel.id == imGiftModel.senderId && imGiftModel.giftId.toInt() == 202){
|
|
|
- vibrator?.vibrate(2500)
|
|
|
- }
|
|
|
- }
|
|
|
- playSvg2("win_501_1000_prize.svga")
|
|
|
- tvWinPrize2.visibility = View.VISIBLE
|
|
|
- tvWinPrize2.text =
|
|
|
- AppContext.getContext().resources.getString(R.string.win_num_prize)
|
|
|
- .format(imGiftModel.multiple)
|
|
|
+ in 1..99 -> {
|
|
|
+ clPrize.visibility = View.VISIBLE
|
|
|
+ ivPrizeBg.visibility = View.INVISIBLE
|
|
|
+ ivPrizeFrame.setImageResource(R.mipmap.gift_prize_frame_1_99)
|
|
|
+ }
|
|
|
+
|
|
|
+ in 100..499 -> {
|
|
|
+ clPrize.visibility = View.VISIBLE
|
|
|
+ ivPrizeBg.visibility = View.VISIBLE
|
|
|
+ ivPrizeBg.setImageResource(R.mipmap.gift_bg_prize_100_499)
|
|
|
+ ivPrizeFrame.setImageResource(R.mipmap.gift_prize_frame_100_499)
|
|
|
+ }
|
|
|
+
|
|
|
+ in 500..999 -> {
|
|
|
+ clPrize.visibility = View.VISIBLE
|
|
|
+ ivPrizeBg.visibility = View.VISIBLE
|
|
|
+ ivPrizeBg.setImageResource(R.mipmap.gift_bg_prize_100_499)
|
|
|
+ ivPrizeFrame.setImageResource(R.mipmap.gift_prize_frame_500_999)
|
|
|
}
|
|
|
else -> {
|
|
|
- iv.visibility = View.GONE
|
|
|
- svgaWinPrize.visibility = View.VISIBLE
|
|
|
UserInfo.getUserInfo()?.let { userInfoModel ->
|
|
|
if (userInfoModel.id == imGiftModel.senderId && imGiftModel.giftId.toInt() == 202){
|
|
|
vibrator?.vibrate(2500)
|
|
|
}
|
|
|
}
|
|
|
- playSvg2("win_1001_prize.svga")
|
|
|
- tvWinPrize2.visibility = View.VISIBLE
|
|
|
- tvWinPrize2.text =
|
|
|
- AppContext.getContext().resources.getString(R.string.win_num_prize)
|
|
|
- .format(imGiftModel.multiple)
|
|
|
+ clPrize.visibility = View.VISIBLE
|
|
|
+ ivPrizeBg.visibility = View.VISIBLE
|
|
|
+ ivPrizeBg.setImageResource(R.mipmap.gift_bg_prize_1000)
|
|
|
+ ivPrizeFrame.setImageResource(R.mipmap.gift_prize_frame_1000)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- clWinPrize.removeCallbacks(winPrizeRunnable)
|
|
|
- clWinPrize.postDelayed(winPrizeRunnable, 1500)
|
|
|
+ clPrize.removeCallbacks(winPrizeRunnable)
|
|
|
+ clPrize.postDelayed(winPrizeRunnable, 1500)
|
|
|
+ if (aniamtionRotate?.isRunning ==false){
|
|
|
+ aniamtionRotate?.start()
|
|
|
+ }
|
|
|
+ if (aniamtionScale?.isRunning ==false){
|
|
|
+ aniamtionScale?.start()
|
|
|
+ }
|
|
|
+ loadGiftPrizeNum(imGiftModel.multiple)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -325,6 +339,60 @@ class GiftDanDaoView : FrameLayout {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun loadGiftPrizeNum(giftCount: Int) {
|
|
|
+ binding?.apply {
|
|
|
+ val giftContStr = giftCount.toString()
|
|
|
+ if (giftContStr.length>imageViewPrizeData.size){
|
|
|
+ imageViewPrizeData.clear()
|
|
|
+ for (i in 0..giftContStr.length){
|
|
|
+ val imageView = ImageView(context)
|
|
|
+ imageViewPrizeData.add(imageView)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ imageViewPrizeData[0].setImageResource(R.mipmap.ic_dan_dao_x)
|
|
|
+ llPrizeNum.removeAllViews()
|
|
|
+ llPrizeNum.addView(imageViewPrizeData[0])
|
|
|
+ giftCount.toString().toCharArray().forEachIndexed { index,char ->
|
|
|
+ when(char){
|
|
|
+ '0' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_zero)
|
|
|
+ }
|
|
|
+ '1' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_one)
|
|
|
+ }
|
|
|
+ '2' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_two)
|
|
|
+ }
|
|
|
+ '3' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_three)
|
|
|
+ }
|
|
|
+ '4' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_four)
|
|
|
+ }
|
|
|
+ '5' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_five)
|
|
|
+ }
|
|
|
+ '6' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_six)
|
|
|
+ }
|
|
|
+ '7' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_seven)
|
|
|
+ }
|
|
|
+ '8' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_eight)
|
|
|
+ }
|
|
|
+ '9' -> {
|
|
|
+ imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_nine)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ llPrizeNum.addView(imageViewPrizeData[index+1])
|
|
|
+ if (aniamtionNum?.isRunning ==false){
|
|
|
+ aniamtionNum?.start()
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
private fun loadGiftNum(giftCount: Int) {
|
|
|
binding?.apply {
|
|
|
val giftContStr = giftCount.toString()
|
|
@@ -406,11 +474,13 @@ class GiftDanDaoView : FrameLayout {
|
|
|
|
|
|
private val winPrizeRunnable by lazy {
|
|
|
Runnable {
|
|
|
+ LogUtil.d("winPrizeRunnable" , "clPrize")
|
|
|
vibrator?.cancel()
|
|
|
binding!!.clWinPrize.visibility = View.INVISIBLE
|
|
|
binding!!.tvWinPrize.text = ""
|
|
|
binding!!.svgaWinPrize.visibility = View.INVISIBLE
|
|
|
binding!!.tvWinPrize2.text = ""
|
|
|
+ binding!!.clPrize.visibility = INVISIBLE
|
|
|
}
|
|
|
}
|
|
|
|