From 252736e890fd50550ab9dec218159356e2a953c1 Mon Sep 17 00:00:00 2001 From: lmw <125975490@qq.com> Date: 星期四, 18 七月 2024 17:51:37 +0800 Subject: [PATCH] fix bug --- app/src/main/java/com/dollearn/student/ui/home/SuperListenActivity.kt | 126 +++++++++++++++++++++++++++++++++++++---- 1 files changed, 113 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/dollearn/student/ui/home/SuperListenActivity.kt b/app/src/main/java/com/dollearn/student/ui/home/SuperListenActivity.kt index bc2b591..2cfe8e6 100644 --- a/app/src/main/java/com/dollearn/student/ui/home/SuperListenActivity.kt +++ b/app/src/main/java/com/dollearn/student/ui/home/SuperListenActivity.kt @@ -1,10 +1,17 @@ package com.dollearn.student.ui.home +import android.R.attr.animation +import android.R.attr.max +import android.animation.Animator +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import android.animation.ValueAnimator import android.os.Handler import android.os.Looper import android.os.Message import android.util.Log import android.view.View +import android.view.animation.LinearInterpolator import androidx.recyclerview.widget.GridLayoutManager import cn.sinata.xldutils.gone import cn.sinata.xldutils.utils.SPUtils @@ -23,8 +30,11 @@ import com.dollearn.student.utils.event.EmptyEvent import com.dollearn.student.utils.interfaces.StringCallback import kotlinx.android.synthetic.main.activity_super_listen.* +import kotlinx.android.synthetic.main.fragment_q_a.* import kotlinx.android.synthetic.main.fragmetn_look_img.* +import kotlinx.android.synthetic.main.item_game_1.view.* import org.greenrobot.eventbus.EventBus +import org.jetbrains.anko.dip import kotlin.math.abs import kotlin.math.max import kotlin.math.min @@ -34,6 +44,9 @@ class SuperListenActivity : TransparentStatusBarActivity(), AudioUtils.OnAudioStatusUpdateListener { override fun setContentView() = R.layout.activity_super_listen + val level by lazy { //0就只能点入门,1就是入门和中级都能点,2就是入门、中级高级三个难度都可以点 + intent.getIntExtra("level", 0) + } private val week by lazy { intent.getIntExtra("week", 0) } @@ -48,7 +61,7 @@ val TAG = "Listen====>" - val list = arrayListOf<Subject>() + var list = arrayListOf<Subject>() private val adapter = GameAdapter(list) val PLAY_VOICE = 1 @@ -78,6 +91,9 @@ var state = 0 //0:准备听题 1:听题中 2:请作答 3:结束答题 + var showFullImage = false + var paused = false + override fun initClick() { tv_exit.setOnClickListener { if (tv_exit.text == "提交"){ @@ -97,6 +113,12 @@ finish() }else onBackPressed() + } + + cl_voice.setOnClickListener { + if (!playing){ + handler?.sendEmptyMessage(PLAY_VOICE) + } } } @@ -132,8 +154,10 @@ sendEmptyMessageDelayed(STUDY_TIME, 1000) } PLAY_VOICE -> { - if (index < voiceList.size) + if (!paused&&!playing&&index < voiceList.size) { + playing = true player.startPlayMusic(this@SuperListenActivity, voiceList[index]) + } } COUNT_DOWN -> { if (!playing) { @@ -143,16 +167,18 @@ tv_tip.text = "请在${countTime}s内选择答案!" if (countTime == 0) { index++ - startGame() + startGame(true) } else { sendEmptyMessageDelayed(COUNT_DOWN, 1000) } } PLAY_RIGHT -> { + playing = true rightPlaying = true player.startPlayMusic(this@SuperListenActivity, rightVoice) } PLAY_ERROR -> { + playing = true errorPlaying = true player.startPlayMusic(this@SuperListenActivity, errorVoice) } @@ -181,7 +207,7 @@ countdownDialog.callback = object :StringCallback{ override fun onResult(rst: String) { index = 0 - startGame() + startGame(true) } } countdownDialog.show(supportFragmentManager, "timer") @@ -206,15 +232,19 @@ } i++ } - Log.e(TAG,"总数:$total,计算得到行数:${min(bestColumns,bestRows)},列数:${max(bestColumns,bestRows)}") + Log.e(TAG, "总数:$total,计算得到行数:${min(bestColumns, bestRows)},列数:${max(bestColumns, bestRows)}") val lineHeight = rv_list.height.toDouble() / min(bestColumns, bestRows) - Log.e(TAG,"高度:${rv_list.height},计算得到行高:${lineHeight}") - rv_list.layoutManager = GridLayoutManager(this, max(bestColumns,bestRows)) + Log.e(TAG, "高度:${rv_list.height},计算得到行高:${lineHeight}") + rv_list.layoutManager = GridLayoutManager(this, max(bestColumns, bestRows)) adapter.height = lineHeight.toInt() adapter.notifyDataSetChanged() } - fun startGame() { + /** + * 切题 + * @param playNow true:表示立即播放下一题 false:3秒后播放下一题 + */ + fun startGame(playNow: Boolean = false) { if (index < voiceList.size){ Log.e(TAG, "开始答题:index=${index}") tv_sort.text = (index+1).toString() @@ -222,9 +252,10 @@ countTime = TIME //重置答题时间 tv_tip.text = "准备听题" state = 0 - handler?.sendEmptyMessageDelayed(PLAY_VOICE, if (index == 0) 200 else 3000) + handler?.sendEmptyMessageDelayed(PLAY_VOICE, if (playNow) 200 else 3000) }else{ tv_sort.visibility = View.INVISIBLE + cl_voice.visibility = View.INVISIBLE tv_tip.text = "" state = 3 tv_end.text = "已完成全部问题" @@ -232,6 +263,56 @@ handler?.removeMessages(STUDY_TIME) } } + + fun transAnimation(endView: View){ + val offx = getScreenX(endView) - getScreenX(cl_voice) + val offy = getScreenY(endView) - getScreenY(cl_voice) + val x = PropertyValuesHolder.ofFloat("translationX", 0f, offx.toFloat()) + val y = PropertyValuesHolder.ofFloat("translationY", 0f, offy.toFloat()) + val animator = ObjectAnimator.ofPropertyValuesHolder(cl_voice, x, y) + animator.duration = 500 + animator.interpolator = LinearInterpolator() + val withAnim = ValueAnimator.ofInt(cl_voice.width, endView.width).setDuration(500) //会影响结束坐标 + withAnim.addUpdateListener { + cl_voice.layoutParams.width = it.animatedValue as Int + cl_voice.requestLayout() + } + val heightAnim = ValueAnimator.ofInt(cl_voice.height, endView.height).setDuration(500) + heightAnim.addUpdateListener { + cl_voice.layoutParams.height = it.animatedValue as Int + cl_voice.requestLayout() + } + withAnim.start() + heightAnim.start() + animator.start() + animator.addListener(object : Animator.AnimatorListener { + override fun onAnimationStart(animation: Animator?) { + + } + + override fun onAnimationEnd(animation: Animator?) { + endView.visible() + } + + override fun onAnimationCancel(animation: Animator?) { + } + + override fun onAnimationRepeat(animation: Animator?) { + } + }) + } + + private fun getScreenY(v: View):Int{ + val xy = IntArray(2) + v.getLocationOnScreen(xy) + return xy[1] + } + private fun getScreenX(v: View):Int{ + val xy = IntArray(2) + v.getLocationOnScreen(xy) + return xy[0] + } + override fun onUpdate(db: Double, time: Long) { } @@ -243,7 +324,8 @@ playing = true if (errorPlaying||rightPlaying) return - if (!data!!.subjectList[data!!.subjectList.map { it.correct }.indexOf(voiceList[index])].completed){//首次播放 +// if (!data!!.subjectList[data!!.subjectList.map { it.correct }.indexOf(voiceList[index])].completed){//首次播放 + if (handler?.hasMessages(COUNT_DOWN) == false){//首次播放 state = 1 tv_tip.text = "请在${countTime}s内选择答案!" handler?.sendEmptyMessageDelayed(COUNT_DOWN, 1000) @@ -258,18 +340,24 @@ iv1.visible() iv2.visible() iv_playing.gone() - if (data!!.subjectList[data!!.subjectList.map { it.correct }.indexOf(voiceList[index])].completed){ //当前题目已作答,3秒后进入下一题 + if (data!!.subjectList[data!!.subjectList.map { it.correct }.indexOf(voiceList[min(index,voiceList.lastIndex)])].completed){ //当前题目已作答,3秒后进入下一题 index++ startGame() } if (errorPlaying) errorPlaying = false - if (rightPlaying){ + else if (rightPlaying){ rightPlaying = false val subject = data!!.subjectList[data!!.subjectList.map { it.correct } .indexOf(voiceList[index])] //当前音频对应题目 subject.completed = true handler?.sendEmptyMessage(PLAY_VOICE) + }else{ + cl_voice.translationX = 0f + cl_voice.translationY = 0f + cl_voice.layoutParams.width = dip(159) + cl_voice.layoutParams.height = dip(52) + cl_voice.requestLayout() } } @@ -285,8 +373,20 @@ EventBus.getDefault().post(EmptyEvent(Const.EventCode.STOP_TIMER)) } + override fun onResume() { + super.onResume() + if (paused){ + paused = false + handler?.sendEmptyMessageDelayed(PLAY_VOICE, 200) + } + } + override fun onPause() { super.onPause() - player.stopPlayMusic() + if (!showFullImage){ + player.stopPlayMusic() + paused = true + } + showFullImage = false } } -- Gitblit v1.7.1