Explorar o código

1.点击控件添加动画效果

王鹏鹏 %!s(int64=2) %!d(string=hai) anos
pai
achega
4aeca1a643
Modificáronse 19 ficheiros con 1513 adicións e 817 borrados
  1. 2 43
      mmse/src/main/java/com/yingyangfly/mmse/fragment/CountFragment.kt
  2. 66 22
      moca/src/main/java/com/yingyangfly/moca/drawdesign/DrawDesignFragment.kt
  3. 68 28
      moca/src/main/java/com/yingyangfly/moca/drawdesign/VerifyAnswersFragment.kt
  4. 71 31
      moca/src/main/java/com/yingyangfly/moca/identify/IdentifyPictureFragment.kt
  5. 63 23
      moca/src/main/java/com/yingyangfly/moca/identify/IdentifyResultFragment.kt
  6. 77 35
      moca/src/main/java/com/yingyangfly/moca/listenspeak/ListenSpeakFragment.kt
  7. 69 31
      moca/src/main/java/com/yingyangfly/moca/listenspeak/ListenSpeakResultFragment.kt
  8. 97 48
      moca/src/main/java/com/yingyangfly/moca/memorizenumbers/MemorizeNumbersFragment.kt
  9. 71 31
      moca/src/main/java/com/yingyangfly/moca/memorizenumbers/MemorizeResultFragment.kt
  10. 161 96
      moca/src/main/java/com/yingyangfly/moca/numberrecords/NumberRecordsFragment.kt
  11. 116 110
      moca/src/main/java/com/yingyangfly/moca/omputation/ComputationFragment.kt
  12. 80 37
      moca/src/main/java/com/yingyangfly/moca/record/ListenRecordFragment.kt
  13. 96 56
      moca/src/main/java/com/yingyangfly/moca/record/RecordResultFragment.kt
  14. 72 31
      moca/src/main/java/com/yingyangfly/moca/signature/DesignsChoiceFragment.kt
  15. 71 30
      moca/src/main/java/com/yingyangfly/moca/signature/SignatureFragment.kt
  16. 96 57
      moca/src/main/java/com/yingyangfly/moca/singlechoice/SingleChoiceFragment.kt
  17. 109 59
      moca/src/main/java/com/yingyangfly/moca/timepiece/TimepieceFragment.kt
  18. 67 26
      moca/src/main/java/com/yingyangfly/moca/tips/TipsFragment.kt
  19. 61 23
      moca/src/main/java/com/yingyangfly/moca/week/WeekFragment.kt

+ 2 - 43
mmse/src/main/java/com/yingyangfly/mmse/fragment/CountFragment.kt

@@ -170,8 +170,8 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
                     binding.editResultOne.setSelection(firstQuestion!!.inputString.length)
                 }
             }
-            val secondQuestionnId = questionId + 1
-            secondQuestion = dao?.getQuestion(secondQuestionnId)
+            val secondQuestionId = questionId + 1
+            secondQuestion = dao?.getQuestion(secondQuestionId)
             if (secondQuestion != null && secondQuestion!!.inputString.isNullOrEmpty().not()) {
                 binding.editResultTwo.post {
                     if (stringBufferTwo.toString().isEmpty().not()) {
@@ -228,13 +228,6 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
         if (dao != null) {
             if (binding.editResultOne.text.toString().trim().isEmpty()) {
                 "请输入第一道题目的答案".toast()
-                binding.editResultOne.requestFocus()
-                binding.editResultOne.isFocusable = true
-                binding.editResultOne.isFocusableInTouchMode = true
-                binding.editResultOne.postDelayed(
-                    { closeKeyBord(binding.editResultOne, mContext) },
-                    300
-                )
                 return false
             } else {
                 if (firstQuestion != null) {
@@ -247,13 +240,6 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
             }
             if (binding.editResultTwo.text.toString().trim().isEmpty()) {
                 "请输入第二道题目的答案".toast()
-                binding.editResultTwo.requestFocus()
-                binding.editResultTwo.isFocusable = true
-                binding.editResultTwo.isFocusableInTouchMode = true
-                binding.editResultTwo.postDelayed(
-                    { closeKeyBord(binding.editResultOne, mContext) },
-                    300
-                )
                 return false
             } else {
                 if (secondQuestion != null) {
@@ -266,15 +252,6 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
             }
             if (binding.editResultThree.text.toString().trim().isEmpty()) {
                 "请输入第三道题目的答案".toast()
-                binding.editResultThree.requestFocus()
-                binding.editResultThree.isFocusable = true
-                binding.editResultThree.isFocusableInTouchMode = true
-                binding.editResultThree.postDelayed({
-                    closeKeyBord(
-                        binding.editResultOne,
-                        mContext
-                    )
-                }, 300)
                 return false
             } else {
                 if (thirdQuestion != null) {
@@ -287,15 +264,6 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
             }
             if (binding.editResultFour.text.toString().trim().isEmpty()) {
                 "请输入第四道题目的答案".toast()
-                binding.editResultFour.requestFocus()
-                binding.editResultFour.isFocusable = true
-                binding.editResultFour.isFocusableInTouchMode = true
-                binding.editResultFour.postDelayed({
-                    closeKeyBord(
-                        binding.editResultOne,
-                        mContext
-                    )
-                }, 300)
                 return false
             } else {
                 if (fourthQuestion != null) {
@@ -308,15 +276,6 @@ class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener
             }
             if (binding.editResultFive.text.toString().trim().isEmpty()) {
                 "请输入第五道题目的答案".toast()
-                binding.editResultFive.requestFocus()
-                binding.editResultFive.isFocusable = true
-                binding.editResultFive.isFocusableInTouchMode = true
-                binding.editResultFive.postDelayed({
-                    closeKeyBord(
-                        binding.editResultOne,
-                        mContext
-                    )
-                }, 300)
                 return false
             } else {
                 if (fifthQuestion != null) {

+ 66 - 22
moca/src/main/java/com/yingyangfly/moca/drawdesign/DrawDesignFragment.kt

@@ -1,22 +1,26 @@
 package com.yingyangfly.moca.drawdesign
 
+import android.annotation.SuppressLint
 import android.graphics.Bitmap
 import android.graphics.Color
 import android.os.Bundle
 import android.text.SpannableString
 import android.text.Spanned
 import android.text.style.ForegroundColorSpan
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentDrawDesignBinding
 import com.yingyangfly.baselib.base.BaseFragment
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 
 /**
  * 画钟表
  */
-class DrawDesignFragment : BaseFragment<FragmentDrawDesignBinding>() {
+class DrawDesignFragment : BaseFragment<FragmentDrawDesignBinding>(), View.OnTouchListener {
 
     override fun initViews() {
         binding {
@@ -29,34 +33,74 @@ class DrawDesignFragment : BaseFragment<FragmentDrawDesignBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            rubberLayout.setOnSingleClickListener {
-                signatureView.clear()
+            rubberLayout.setOnTouchListener(this@DrawDesignFragment)
+            btnPrevious.setOnTouchListener(this@DrawDesignFragment)
+            btnNext.setOnTouchListener(this@DrawDesignFragment)
+        }
+    }
+
+    override fun initData() {
+
+    }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.rubberLayout) {
+                    v.startAnimation(getScaleAnimation())
+                }
             }
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 33)
-                controller.navigate(
-                    R.id.action_drawDesignFragment_to_designsChoiceFragment,
-                    bundle
-                )
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                when (v.id) {
+                    R.id.btnPrevious -> {
+                        previousPage(v)
+                    }
+                    R.id.btnNext -> {
+                        nextPage(v)
+                    }
+                    R.id.rubberLayout -> {
+                        binding.signatureView.clear()
+                    }
+                }
             }
-            btnNext.setOnSingleClickListener {
-                val bundle = Bundle()
-                bundle.putInt("questionId", 38)
-                val bitmap: Bitmap = signatureView.getCachebBitmaps()
-                bundle.putParcelable("bitmap", bitmap)
-                val controller = Navigation.findNavController(it)
-                controller.navigate(
-                    R.id.action_drawDesignFragment_to_verifyAnswersFragment,
-                    bundle
-                )
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.rubberLayout) {
+                    v.startAnimation(getEndAnimation())
+                }
             }
         }
+        return true
     }
 
-    override fun initData() {
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 33)
+        controller.navigate(
+            R.id.action_drawDesignFragment_to_designsChoiceFragment,
+            bundle
+        )
+    }
 
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        val bundle = Bundle()
+        bundle.putInt("questionId", 38)
+        val bitmap: Bitmap = binding.signatureView.getCachebBitmaps()
+        bundle.putParcelable("bitmap", bitmap)
+        val controller = Navigation.findNavController(v)
+        controller.navigate(
+            R.id.action_drawDesignFragment_to_verifyAnswersFragment,
+            bundle
+        )
     }
 }

+ 68 - 28
moca/src/main/java/com/yingyangfly/moca/drawdesign/VerifyAnswersFragment.kt

@@ -1,16 +1,20 @@
 package com.yingyangfly.moca.drawdesign
 
+import android.annotation.SuppressLint
 import android.graphics.Bitmap
 import android.graphics.drawable.BitmapDrawable
 import android.graphics.drawable.Drawable
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentVerifyAnswersBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.baselib.utils.ImageUtil
 import com.yingyangfly.moca.adapter.VerifyAnswersAdapter
@@ -18,7 +22,7 @@ import com.yingyangfly.moca.adapter.VerifyAnswersAdapter
 /**
  * 验证钟表结果
  */
-class VerifyAnswersFragment : BaseFragment<FragmentVerifyAnswersBinding>() {
+class VerifyAnswersFragment : BaseFragment<FragmentVerifyAnswersBinding>(), View.OnTouchListener {
 
     /**
      * 问题id
@@ -45,29 +49,11 @@ class VerifyAnswersFragment : BaseFragment<FragmentVerifyAnswersBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 38)
-                controller.navigate(
-                    R.id.action_verifyAnswersFragment_to_drawDesignFragment,
-                    bundle
-                )
-            }
-            btnNext.setOnSingleClickListener {
-                if (judge()) {
-                    binding.rvChoice.post {
-                        updateStatus()
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 41)
-                        controller.navigate(
-                            R.id.action_verifyAnswersFragment_to_identifyPictureFragment,
-                            bundle
-                        )
-                    }
-                }
-            }
+            btnPrevious.setOnTouchListener(this@VerifyAnswersFragment)
+            btnNext.setOnTouchListener(this@VerifyAnswersFragment)
         }
     }
 
@@ -88,9 +74,9 @@ class VerifyAnswersFragment : BaseFragment<FragmentVerifyAnswersBinding>() {
 
         choiceItemList.clear()
         if (dao != null) {
-            val firstquestion = dao?.getQuestion(questionId)
-            if (firstquestion != null) {
-                choiceItemList.add(firstquestion)
+            val firstQuestion = dao?.getQuestion(questionId)
+            if (firstQuestion != null) {
+                choiceItemList.add(firstQuestion)
             }
             val secondQuestionnId = questionId + 1
             val secondQuestion = dao?.getQuestion(secondQuestionnId)
@@ -110,7 +96,7 @@ class VerifyAnswersFragment : BaseFragment<FragmentVerifyAnswersBinding>() {
      * 非空判断
      */
     private fun judge(): Boolean {
-        if (choiceItemList.isNullOrEmpty().not()) {
+        if (choiceItemList.isEmpty().not()) {
             choiceItemList.forEach {
                 if (it.inputString.isNullOrEmpty()) {
                     "请判断答案是否正确".toast()
@@ -126,7 +112,7 @@ class VerifyAnswersFragment : BaseFragment<FragmentVerifyAnswersBinding>() {
      */
     private fun updateStatus() {
         var isAllCorrect = true
-        if (choiceItemList.isNullOrEmpty().not()) {
+        if (choiceItemList.isEmpty().not()) {
             choiceItemList.forEach {
                 if (it.correct == "0") {
                     isAllCorrect = false
@@ -153,4 +139,58 @@ class VerifyAnswersFragment : BaseFragment<FragmentVerifyAnswersBinding>() {
             }
         }
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 38)
+        controller.navigate(
+            R.id.action_verifyAnswersFragment_to_drawDesignFragment,
+            bundle
+        )
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (judge()) {
+            binding.rvChoice.post {
+                updateStatus()
+                val controller = Navigation.findNavController(v)
+                val bundle = bundleOf("questionId" to 41)
+                controller.navigate(
+                    R.id.action_verifyAnswersFragment_to_identifyPictureFragment,
+                    bundle
+                )
+            }
+        }
+    }
 }

+ 71 - 31
moca/src/main/java/com/yingyangfly/moca/identify/IdentifyPictureFragment.kt

@@ -1,24 +1,29 @@
 package com.yingyangfly.moca.identify
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentIdentifyPictureBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 
 /**
  * 识图
  */
-class IdentifyPictureFragment : BaseFragment<FragmentIdentifyPictureBinding>() {
+class IdentifyPictureFragment : BaseFragment<FragmentIdentifyPictureBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
      */
-    var questionId = 0
-    var question: QuestionsBean? = null
+    private var questionId = 0
+    private var question: QuestionsBean? = null
 
     override fun onCreate(savedInstanceState: Bundle?) {
         questionId = arguments?.getInt("questionId") ?: 3
@@ -29,35 +34,11 @@ class IdentifyPictureFragment : BaseFragment<FragmentIdentifyPictureBinding>() {
 
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                if (questionId == 41) {
-                    val bundle = bundleOf("questionId" to 38)
-                    controller.navigate(
-                        R.id.action_identifyPictureFragment_to_verifyAnswersFragment,
-                        bundle
-                    )
-                } else {
-                    questionId--
-                    loadData()
-                }
-            }
-
-            btnNext.setOnSingleClickListener {
-                if (questionId < 43) {
-                    questionId++
-                    loadData()
-                } else {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 41)
-                    controller.navigate(
-                        R.id.action_identifyPictureFragment_to_identifyResultFragment,
-                        bundle
-                    )
-                }
-            }
+            btnPrevious.setOnTouchListener(this@IdentifyPictureFragment)
+            btnNext.setOnTouchListener(this@IdentifyPictureFragment)
         }
     }
 
@@ -81,4 +62,63 @@ class IdentifyPictureFragment : BaseFragment<FragmentIdentifyPictureBinding>() {
             }
         }
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        if (questionId == 41) {
+            val bundle = bundleOf("questionId" to 38)
+            controller.navigate(
+                R.id.action_identifyPictureFragment_to_verifyAnswersFragment,
+                bundle
+            )
+        } else {
+            questionId--
+            loadData()
+        }
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (questionId < 43) {
+            questionId++
+            loadData()
+        } else {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 41)
+            controller.navigate(
+                R.id.action_identifyPictureFragment_to_identifyResultFragment,
+                bundle
+            )
+        }
+    }
 }

+ 63 - 23
moca/src/main/java/com/yingyangfly/moca/identify/IdentifyResultFragment.kt

@@ -1,25 +1,30 @@
 package com.yingyangfly.moca.identify
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentIdentifyResultBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.moca.adapter.ChoiceAdapter
 
 /**
  * 识图结果
  */
-class IdentifyResultFragment : BaseFragment<FragmentIdentifyResultBinding>() {
+class IdentifyResultFragment : BaseFragment<FragmentIdentifyResultBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
      */
-    var questionId = 0
+    private var questionId = 0
     private val choiceItemList = mutableListOf<QuestionsBean>()
     private val adapter by lazy { ChoiceAdapter() }
 
@@ -39,27 +44,11 @@ class IdentifyResultFragment : BaseFragment<FragmentIdentifyResultBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 43)
-                controller.navigate(
-                    R.id.action_identifyResultFragment_to_identifyPictureFragment,
-                    bundle
-                )
-            }
-
-            btnNext.setOnSingleClickListener {
-                if (judge()) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 44)
-                    controller.navigate(
-                        R.id.action_identifyResultFragment_to_listenRecordFragment,
-                        bundle
-                    )
-                }
-            }
+            btnPrevious.setOnTouchListener(this@IdentifyResultFragment)
+            btnNext.setOnTouchListener(this@IdentifyResultFragment)
         }
     }
 
@@ -100,7 +89,7 @@ class IdentifyResultFragment : BaseFragment<FragmentIdentifyResultBinding>() {
      * 非空判断
      */
     private fun judge(): Boolean {
-        if (choiceItemList.isNullOrEmpty().not()) {
+        if (choiceItemList.isEmpty().not()) {
             choiceItemList.forEach {
                 if (it.inputString.isNullOrEmpty()) {
                     "请判断答案是否正确".toast()
@@ -110,4 +99,55 @@ class IdentifyResultFragment : BaseFragment<FragmentIdentifyResultBinding>() {
         }
         return true
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 43)
+        controller.navigate(
+            R.id.action_identifyResultFragment_to_identifyPictureFragment,
+            bundle
+        )
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (judge()) {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 44)
+            controller.navigate(
+                R.id.action_identifyResultFragment_to_listenRecordFragment,
+                bundle
+            )
+        }
+    }
 }

+ 77 - 35
moca/src/main/java/com/yingyangfly/moca/listenspeak/ListenSpeakFragment.kt

@@ -1,17 +1,21 @@
 package com.yingyangfly.moca.listenspeak
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentListenSpeakBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.voice.PlayVoice
 
-class ListenSpeakFragment : BaseFragment<FragmentListenSpeakBinding>() {
-
+class ListenSpeakFragment : BaseFragment<FragmentListenSpeakBinding>(),
+    View.OnTouchListener {
     /**
      * 问题id
      */
@@ -29,40 +33,12 @@ class ListenSpeakFragment : BaseFragment<FragmentListenSpeakBinding>() {
         playVoice?.setContext(mContext)
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                if (questionId == 57) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 52)
-                    controller.navigate(
-                        R.id.action_listenSpeakFragment_to_computationFragment,
-                        bundle
-                    )
-                } else {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 57)
-                    controller.navigate(
-                        R.id.action_listenSpeakFragment_to_listenSpeakResultFragment,
-                        bundle
-                    )
-                }
-            }
-
-            btnNext.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to questionId)
-                controller.navigate(
-                    R.id.action_listenSpeakFragment_to_listenSpeakResultFragment,
-                    bundle
-                )
-            }
-
-            imagePlay.setOnSingleClickListener {
-                if (questionsBean != null) {
-                    playVoice?.speak(questionsBean?.reviewDesc!!)
-                }
-            }
+            btnPrevious.setOnTouchListener(this@ListenSpeakFragment)
+            btnNext.setOnTouchListener(this@ListenSpeakFragment)
+            imagePlay.setOnTouchListener(this@ListenSpeakFragment)
         }
     }
 
@@ -95,4 +71,70 @@ class ListenSpeakFragment : BaseFragment<FragmentListenSpeakBinding>() {
             playVoice?.stop()
         }
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.imagePlay) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                when (v.id) {
+                    R.id.btnPrevious -> {
+                        previousPage(v)
+                    }
+                    R.id.btnNext -> {
+                        nextPage(v)
+                    }
+                    R.id.imagePlay -> {
+                        if (questionsBean != null) {
+                            playVoice?.speak(questionsBean?.reviewDesc!!)
+                        }
+                    }
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.imagePlay) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        if (questionId == 57) {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 52)
+            controller.navigate(
+                R.id.action_listenSpeakFragment_to_computationFragment,
+                bundle
+            )
+        } else {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 57)
+            controller.navigate(
+                R.id.action_listenSpeakFragment_to_listenSpeakResultFragment,
+                bundle
+            )
+        }
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to questionId)
+        controller.navigate(
+            R.id.action_listenSpeakFragment_to_listenSpeakResultFragment,
+            bundle
+        )
+    }
 }

+ 69 - 31
moca/src/main/java/com/yingyangfly/moca/listenspeak/ListenSpeakResultFragment.kt

@@ -1,18 +1,22 @@
 package com.yingyangfly.moca.listenspeak
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentListenSpeakResultBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
-import com.yingyangfly.moca.adapter.ChoiceAdapter
 import com.yingyangfly.moca.adapter.SpeakResultAdapter
 
-class ListenSpeakResultFragment : BaseFragment<FragmentListenSpeakResultBinding>() {
+class ListenSpeakResultFragment : BaseFragment<FragmentListenSpeakResultBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
@@ -37,36 +41,11 @@ class ListenSpeakResultFragment : BaseFragment<FragmentListenSpeakResultBinding>
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to questionId)
-                controller.navigate(
-                    R.id.action_listenSpeakResultFragment_to_listenSpeakFragment,
-                    bundle
-                )
-            }
-
-            btnNext.setOnSingleClickListener {
-                if (judge()) {
-                    if (questionId == 57) {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 58)
-                        controller.navigate(
-                            R.id.action_listenSpeakResultFragment_to_listenSpeakFragment,
-                            bundle
-                        )
-                    } else {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 59)
-                        controller.navigate(
-                            R.id.action_listenSpeakResultFragment_to_timepieceFragment,
-                            bundle
-                        )
-                    }
-                }
-            }
+            btnPrevious.setOnTouchListener(this@ListenSpeakResultFragment)
+            btnNext.setOnTouchListener(this@ListenSpeakResultFragment)
         }
     }
 
@@ -107,4 +86,63 @@ class ListenSpeakResultFragment : BaseFragment<FragmentListenSpeakResultBinding>
         }
         return true
     }
+
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to questionId)
+        controller.navigate(
+            R.id.action_listenSpeakResultFragment_to_listenSpeakFragment,
+            bundle
+        )
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (judge()) {
+            if (questionId == 57) {
+                val controller = Navigation.findNavController(v)
+                val bundle = bundleOf("questionId" to 58)
+                controller.navigate(
+                    R.id.action_listenSpeakResultFragment_to_listenSpeakFragment,
+                    bundle
+                )
+            } else {
+                val controller = Navigation.findNavController(v)
+                val bundle = bundleOf("questionId" to 59)
+                controller.navigate(
+                    R.id.action_listenSpeakResultFragment_to_timepieceFragment,
+                    bundle
+                )
+            }
+        }
+    }
 }

+ 97 - 48
moca/src/main/java/com/yingyangfly/moca/memorizenumbers/MemorizeNumbersFragment.kt

@@ -1,19 +1,24 @@
 package com.yingyangfly.moca.memorizenumbers
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentMemorizeNumbersBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.voice.PlayVoice
 
 /**
  * 背数字
  */
-class MemorizeNumbersFragment : BaseFragment<FragmentMemorizeNumbersBinding>() {
+class MemorizeNumbersFragment : BaseFragment<FragmentMemorizeNumbersBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
@@ -32,48 +37,12 @@ class MemorizeNumbersFragment : BaseFragment<FragmentMemorizeNumbersBinding>() {
         playVoice?.setContext(mContext)
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            imagePlay.setOnSingleClickListener {
-                if (question != null) {
-                    playVoice?.speak(question?.reviewDesc!!)
-                }
-            }
-            btnPrevious.setOnSingleClickListener {
-                if (questionId == 49) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 78)
-                    controller.navigate(
-                        R.id.action_memorizeNumbersFragment_to_recordResultFragment,
-                        bundle
-                    )
-                } else {
-                    questionId--
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to questionId)
-                    controller.navigate(
-                        R.id.action_memorizeNumbersFragment_to_memorizeResultFragment,
-                        bundle
-                    )
-                }
-            }
-            btnNext.setOnSingleClickListener {
-                if (questionId == 51) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 51)
-                    controller.navigate(
-                        R.id.action_memorizeNumbersFragment_to_numberRecordsFragment,
-                        bundle
-                    )
-                } else {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to questionId)
-                    controller.navigate(
-                        R.id.action_memorizeNumbersFragment_to_memorizeResultFragment,
-                        bundle
-                    )
-                }
-            }
+            imagePlay.setOnTouchListener(this@MemorizeNumbersFragment)
+            btnPrevious.setOnTouchListener(this@MemorizeNumbersFragment)
+            btnNext.setOnTouchListener(this@MemorizeNumbersFragment)
         }
     }
 
@@ -90,12 +59,16 @@ class MemorizeNumbersFragment : BaseFragment<FragmentMemorizeNumbersBinding>() {
      * 加载数据
      */
     private fun loadData() {
-        binding.tvTitle.text = if (questionId == 49) {
-            "下面给您听一些数字,听完后请按照顺序背出来请听题"
-        } else if (questionId == 50) {
-            "下面再给您听一些数字,听完后请从后往前倒着背出来,请听题"
-        } else {
-            "下面将给您听一串数字,请您仔细听,当您听到数字“1”时,请敲一下桌面,听到其他数字不用做反应"
+        binding.tvTitle.text = when (questionId) {
+            49 -> {
+                "下面给您听一些数字,听完后请按照顺序背出来请听题"
+            }
+            50 -> {
+                "下面再给您听一些数字,听完后请从后往前倒着背出来,请听题"
+            }
+            else -> {
+                "下面将给您听一串数字,请您仔细听,当您听到数字“1”时,请敲一下桌面,听到其他数字不用做反应"
+            }
         }
         if (dao != null) {
             question = dao?.getQuestion(questionId)
@@ -108,4 +81,80 @@ class MemorizeNumbersFragment : BaseFragment<FragmentMemorizeNumbersBinding>() {
             playVoice?.stop()
         }
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.imagePlay) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                when (v.id) {
+                    R.id.btnPrevious -> {
+                        previousPage(v)
+                    }
+                    R.id.btnNext -> {
+                        nextPage(v)
+                    }
+                    R.id.imagePlay -> {
+                        if (question != null) {
+                            playVoice?.speak(question?.reviewDesc!!)
+                        }
+                    }
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.imagePlay) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        if (questionId == 49) {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 78)
+            controller.navigate(
+                R.id.action_memorizeNumbersFragment_to_recordResultFragment,
+                bundle
+            )
+        } else {
+            questionId--
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to questionId)
+            controller.navigate(
+                R.id.action_memorizeNumbersFragment_to_memorizeResultFragment,
+                bundle
+            )
+        }
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (questionId == 51) {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 51)
+            controller.navigate(
+                R.id.action_memorizeNumbersFragment_to_numberRecordsFragment,
+                bundle
+            )
+        } else {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to questionId)
+            controller.navigate(
+                R.id.action_memorizeNumbersFragment_to_memorizeResultFragment,
+                bundle
+            )
+        }
+    }
 }

+ 71 - 31
moca/src/main/java/com/yingyangfly/moca/memorizenumbers/MemorizeResultFragment.kt

@@ -1,18 +1,22 @@
 package com.yingyangfly.moca.memorizenumbers
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentMemorizeResultBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.moca.adapter.ChoiceAdapter
 
-class MemorizeResultFragment : BaseFragment<FragmentMemorizeResultBinding>() {
-
+class MemorizeResultFragment : BaseFragment<FragmentMemorizeResultBinding>(),
+    View.OnTouchListener {
     /**
      * 问题id
      */
@@ -36,35 +40,11 @@ class MemorizeResultFragment : BaseFragment<FragmentMemorizeResultBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to questionId)
-                controller.navigate(
-                    R.id.action_memorizeResultFragment_to_memorizeNumbersFragment,
-                    bundle
-                )
-            }
-            btnNext.setOnSingleClickListener {
-                if (judge()) {
-                    if (questionId == 49) {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 50)
-                        controller.navigate(
-                            R.id.action_memorizeResultFragment_to_memorizeNumbersFragment,
-                            bundle
-                        )
-                    } else {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 51)
-                        controller.navigate(
-                            R.id.action_memorizeResultFragment_to_memorizeNumbersFragment,
-                            bundle
-                        )
-                    }
-                }
-            }
+            btnPrevious.setOnTouchListener(this@MemorizeResultFragment)
+            btnNext.setOnTouchListener(this@MemorizeResultFragment)
         }
     }
 
@@ -100,7 +80,7 @@ class MemorizeResultFragment : BaseFragment<FragmentMemorizeResultBinding>() {
      * 非空判断
      */
     private fun judge(): Boolean {
-        if (choiceItemList.isNullOrEmpty().not()) {
+        if (choiceItemList.isEmpty().not()) {
             choiceItemList.forEach {
                 if (it.inputString.isNullOrEmpty()) {
                     "请判断答案是否正确".toast()
@@ -111,4 +91,64 @@ class MemorizeResultFragment : BaseFragment<FragmentMemorizeResultBinding>() {
         return true
     }
 
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to questionId)
+        controller.navigate(
+            R.id.action_memorizeResultFragment_to_memorizeNumbersFragment,
+            bundle
+        )
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (judge()) {
+            if (questionId == 49) {
+                val controller = Navigation.findNavController(v)
+                val bundle = bundleOf("questionId" to 50)
+                controller.navigate(
+                    R.id.action_memorizeResultFragment_to_memorizeNumbersFragment,
+                    bundle
+                )
+            } else {
+                val controller = Navigation.findNavController(v)
+                val bundle = bundleOf("questionId" to 51)
+                controller.navigate(
+                    R.id.action_memorizeResultFragment_to_memorizeNumbersFragment,
+                    bundle
+                )
+            }
+        }
+    }
+
 }

+ 161 - 96
moca/src/main/java/com/yingyangfly/moca/numberrecords/NumberRecordsFragment.kt

@@ -1,6 +1,9 @@
 package com.yingyangfly.moca.numberrecords
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import androidx.recyclerview.widget.GridLayoutManager
@@ -8,7 +11,8 @@ import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentNumberRecordsBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.show
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.moca.adapter.NumberAdapter
@@ -16,7 +20,8 @@ import com.yingyangfly.moca.adapter.NumberAdapter
 /**
  * 记录患者错了几次
  */
-class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>() {
+class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
@@ -26,7 +31,7 @@ class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>() {
     private val numberList = mutableListOf<String>()
     private val numberAdapter by lazy { NumberAdapter() }
     private val stringBuffer = StringBuffer()
-    var question: QuestionsBean? = null
+    private var question: QuestionsBean? = null
 
     override fun onCreate(savedInstanceState: Bundle?) {
         questionId = arguments?.getInt("questionId") ?: 57
@@ -39,109 +44,24 @@ class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>() {
         numberAdapter.onNumClickListener = { bean, type ->
             when (type) {
                 "0" -> {
-                    binding.editTime.post {
-                        stringBuffer.append(bean)
-                        binding.editTime.setText(stringBuffer.toString())
-                        binding.editTime.setSelection(stringBuffer.toString().length)
-                    }
+                    append(bean)
                 }
                 "1" -> {
-                    binding.editTime.post {
-                        if (stringBuffer.toString().isNullOrEmpty().not()) {
-                            val size = stringBuffer.toString().length - 1
-                            stringBuffer.deleteCharAt(size)
-                            binding.editTime.setText(stringBuffer.toString())
-                            binding.editTime.setSelection(stringBuffer.toString().length)
-                        }
-                    }
+                    delect()
                 }
                 "2" -> {
-                    if (dao != null) {
-                        if (question != null) {
-                            question!!.inputString = binding.editTime.text.toString().trim()
-                            question!!.reviewId = question!!.id
-                            question!!.reviewAnswer = binding.editTime.text.toString().trim()
-                            question!!.correct = ""
-                            dao?.update(question!!)
-                        }
-                    }
+                    update()
                 }
             }
 
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                when (questionId) {
-                    74 -> {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 67)
-                        controller.navigate(
-                            R.id.action_numberRecordsFragment_to_tipsFragment,
-                            bundle
-                        )
-                    }
-                    73, 72 -> {
-                        questionId++
-                        loadData()
-                    }
-                    59 -> {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to questionId)
-                        controller.navigate(
-                            R.id.action_numberRecordsFragment_to_timepieceFragment,
-                            bundle
-                        )
-                    }
-                    else -> {
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 51)
-                        controller.navigate(
-                            R.id.action_numberRecordsFragment_to_memorizeNumbersFragment,
-                            bundle
-                        )
-                    }
-                }
-            }
-            btnNext.setOnSingleClickListener {
-                if (binding.editTime.text.isNullOrEmpty()) {
-                    toastIndo.toast()
-                } else {
-                    saveData()
-                    when (questionId) {
-                        72 -> {
-                            val controller = Navigation.findNavController(it)
-                            val bundle = bundleOf("questionId" to 75)
-                            controller.navigate(
-                                R.id.action_numberRecordsFragment_to_weekFragment,
-                                bundle
-                            )
-                        }
-                        73, 74 -> {
-                            questionId--
-                            loadData()
-                        }
-                        59 -> {
-                            val controller = Navigation.findNavController(it)
-                            val bundle = bundleOf("questionId" to 60)
-                            controller.navigate(
-                                R.id.action_numberRecordsFragment_to_singleChoiceFragment,
-                                bundle
-                            )
-                        }
-                        else -> {
-                            val controller = Navigation.findNavController(it)
-                            val bundle = bundleOf("questionId" to 52)
-                            controller.navigate(
-                                R.id.action_numberRecordsFragment_to_computationFragment,
-                                bundle
-                            )
-                        }
-                    }
-                }
-            }
+            btnPrevious.setOnTouchListener(this@NumberRecordsFragment)
+            btnNext.setOnTouchListener(this@NumberRecordsFragment)
         }
     }
 
@@ -149,6 +69,49 @@ class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>() {
 
     }
 
+    /**
+     * 添加字段
+     */
+    private fun append(bean: String) {
+        binding.editTime.post {
+            stringBuffer.append(bean)
+            binding.editTime.setText(stringBuffer.toString())
+            binding.editTime.setSelection(stringBuffer.toString().length)
+        }
+    }
+
+    /**
+     * 删除字段
+     */
+    private fun delect() {
+        binding.editTime.post {
+            if (stringBuffer.toString().isEmpty().not()) {
+                val size = stringBuffer.toString().length - 1
+                stringBuffer.deleteCharAt(size)
+                binding.editTime.setText(stringBuffer.toString())
+                binding.editTime.setSelection(stringBuffer.toString().length)
+            }
+        }
+    }
+
+    /**
+     * 保存信息
+     */
+    private fun update() {
+        binding.editTime.post {
+            if (dao != null) {
+                if (question != null) {
+                    question!!.inputString = binding.editTime.text.toString().trim()
+                    question!!.reviewId = question!!.id
+                    question!!.reviewAnswer = binding.editTime.text.toString().trim()
+                    question!!.correct = ""
+                    dao?.update(question!!)
+                }
+            }
+        }
+    }
+
+
     override fun onResume() {
         super.onResume()
         loadData()
@@ -159,7 +122,7 @@ class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>() {
      */
     private fun loadData() {
         binding.editTime.setText("")
-        if (stringBuffer.toString().isNullOrEmpty().not()) {
+        if (stringBuffer.toString().isEmpty().not()) {
             val length = stringBuffer.length
             stringBuffer.delete(0, length)
         }
@@ -210,7 +173,7 @@ class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>() {
                 binding.data = question
                 if (question!!.inputString.isNullOrEmpty().not()) {
                     binding.editTime.post {
-                        if (stringBuffer.toString().isNullOrEmpty().not()) {
+                        if (stringBuffer.toString().isEmpty().not()) {
                             stringBuffer.delete(0, question!!.inputString.length - 1)
                         }
                         stringBuffer.append(question!!.inputString)
@@ -233,4 +196,106 @@ class NumberRecordsFragment : BaseFragment<FragmentNumberRecordsBinding>() {
             dao?.update(question!!)
         }
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        when (questionId) {
+            74 -> {
+                val controller = Navigation.findNavController(v)
+                val bundle = bundleOf("questionId" to 67)
+                controller.navigate(
+                    R.id.action_numberRecordsFragment_to_tipsFragment,
+                    bundle
+                )
+            }
+            73, 72 -> {
+                questionId++
+                loadData()
+            }
+            59 -> {
+                val controller = Navigation.findNavController(v)
+                val bundle = bundleOf("questionId" to questionId)
+                controller.navigate(
+                    R.id.action_numberRecordsFragment_to_timepieceFragment,
+                    bundle
+                )
+            }
+            else -> {
+                val controller = Navigation.findNavController(v)
+                val bundle = bundleOf("questionId" to 51)
+                controller.navigate(
+                    R.id.action_numberRecordsFragment_to_memorizeNumbersFragment,
+                    bundle
+                )
+            }
+        }
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (binding.editTime.text.isNullOrEmpty()) {
+            toastIndo.toast()
+        } else {
+            saveData()
+            when (questionId) {
+                72 -> {
+                    val controller = Navigation.findNavController(v)
+                    val bundle = bundleOf("questionId" to 75)
+                    controller.navigate(
+                        R.id.action_numberRecordsFragment_to_weekFragment,
+                        bundle
+                    )
+                }
+                73, 74 -> {
+                    questionId--
+                    loadData()
+                }
+                59 -> {
+                    val controller = Navigation.findNavController(v)
+                    val bundle = bundleOf("questionId" to 60)
+                    controller.navigate(
+                        R.id.action_numberRecordsFragment_to_singleChoiceFragment,
+                        bundle
+                    )
+                }
+                else -> {
+                    val controller = Navigation.findNavController(v)
+                    val bundle = bundleOf("questionId" to 52)
+                    controller.navigate(
+                        R.id.action_numberRecordsFragment_to_computationFragment,
+                        bundle
+                    )
+                }
+            }
+        }
+    }
 }

+ 116 - 110
moca/src/main/java/com/yingyangfly/moca/omputation/ComputationFragment.kt

@@ -1,6 +1,11 @@
 package com.yingyangfly.moca.omputation
 
+import android.annotation.SuppressLint
+import android.os.Build
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
+import androidx.annotation.RequiresApi
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import androidx.recyclerview.widget.GridLayoutManager
@@ -8,21 +13,21 @@ import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentComputationBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.moca.adapter.NumberAdapter
 
 /**
  * 计算题
  */
-class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
+class ComputationFragment : BaseFragment<FragmentComputationBinding>(), View.OnTouchListener {
 
     /**
      * 问题id
      */
-    var questionId = 0
-
-    var choiceItems = ""
+    private var questionId = 0
+    private var choiceItems = ""
     private val numberList = mutableListOf<String>()
     private val adapter by lazy { NumberAdapter() }
 
@@ -32,7 +37,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
     private var fourthQuestion: QuestionsBean? = null
     private var fifthQuestion: QuestionsBean? = null
 
-    private var questionOne = false
+    private var questionOne = true
     private var questionTwo = false
     private var questionThree = false
     private var questionFour = false
@@ -50,8 +55,14 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
         super.onCreate(savedInstanceState)
     }
 
+    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
     override fun initViews() {
         binding {
+            editResultOne.showSoftInputOnFocus = false
+            editResultTwo.showSoftInputOnFocus = false
+            editResultThree.showSoftInputOnFocus = false
+            editResultFour.showSoftInputOnFocus = false
+            editResultFive.showSoftInputOnFocus = false
             numberList.clear()
             for (i in 1..9) {
                 numberList.add(i.toString())
@@ -78,74 +89,63 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
+        setOnFocusChangeListener()
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 51)
-                controller.navigate(
-                    R.id.action_computationFragment_to_numberRecordsFragment,
-                    bundle
-                )
-            }
+            btnPrevious.setOnTouchListener(this@ComputationFragment)
+            btnNext.setOnTouchListener(this@ComputationFragment)
+        }
+    }
 
-            btnNext.setOnSingleClickListener {
-                if (judge()) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 57)
-                    controller.navigate(
-                        R.id.action_computationFragment_to_listenSpeakFragment,
-                        bundle
-                    )
-                }
-            }
+    override fun initData() {
+
+    }
 
+    private fun setOnFocusChangeListener() {
+        binding {
             editResultOne.setOnFocusChangeListener { v, hasFocus ->
                 questionOne = hasFocus
-                binding.editResultOne.postDelayed(
-                    { closeKeyBord(binding.editResultOne, mContext) },
-                    300
-                )
+                questionTwo = false
+                questionThree = false
+                questionFour = false
+                questionFive = false
             }
 
             editResultTwo.setOnFocusChangeListener { v, hasFocus ->
+                questionOne = false
                 questionTwo = hasFocus
-                binding.editResultTwo.postDelayed(
-                    { closeKeyBord(binding.editResultTwo, mContext) },
-                    300
-                )
+                questionThree = false
+                questionFour = false
+                questionFive = false
             }
 
             editResultThree.setOnFocusChangeListener { v, hasFocus ->
+                questionOne = false
+                questionTwo = false
                 questionThree = hasFocus
-                binding.editResultThree.postDelayed(
-                    { closeKeyBord(binding.editResultThree, mContext) },
-                    300
-                )
+                questionFour = false
+                questionFive = false
             }
 
             editResultFour.setOnFocusChangeListener { v, hasFocus ->
+                questionOne = false
+                questionTwo = false
+                questionThree = false
                 questionFour = hasFocus
-                binding.editResultFour.postDelayed(
-                    { closeKeyBord(binding.editResultFour, mContext) },
-                    300
-                )
+                questionFive = false
             }
 
             editResultFive.setOnFocusChangeListener { v, hasFocus ->
+                questionOne = false
+                questionTwo = false
+                questionThree = false
+                questionFour = false
                 questionFive = hasFocus
-                binding.editResultFive.postDelayed(
-                    { closeKeyBord(binding.editResultFive, mContext) },
-                    300
-                )
             }
         }
     }
 
-    override fun initData() {
-
-    }
-
     override fun onResume() {
         super.onResume()
         loadData()
@@ -155,15 +155,11 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
      * 加载数据
      */
     private fun loadData() {
-        binding.editResultOne.requestFocus()
-        binding.editResultOne.isFocusable = true
-        binding.editResultOne.isFocusableInTouchMode = true
-        binding.editResultOne.postDelayed({ closeKeyBord(binding.editResultOne, mContext) }, 300)
         if (dao != null) {
             firstquestion = dao?.getQuestion(questionId)
             if (firstquestion != null && firstquestion!!.inputString.isNullOrEmpty().not()) {
                 binding.editResultOne.post {
-                    if (stringBufferOne.toString().isNullOrEmpty().not()) {
+                    if (stringBufferOne.toString().isEmpty().not()) {
                         stringBufferOne.delete(0, firstquestion!!.inputString.length - 1)
                     }
                     stringBufferOne.append(firstquestion!!.inputString)
@@ -171,11 +167,11 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
                     binding.editResultOne.setSelection(firstquestion!!.inputString.length)
                 }
             }
-            val secondQuestionnId = questionId + 1
-            secondQuestion = dao?.getQuestion(secondQuestionnId)
+            val secondQuestionId = questionId + 1
+            secondQuestion = dao?.getQuestion(secondQuestionId)
             if (secondQuestion != null && secondQuestion!!.inputString.isNullOrEmpty().not()) {
                 binding.editResultTwo.post {
-                    if (stringBufferTwo.toString().isNullOrEmpty().not()) {
+                    if (stringBufferTwo.toString().isEmpty().not()) {
                         stringBufferTwo.delete(0, secondQuestion!!.inputString.length - 1)
                     }
                     stringBufferTwo.append(secondQuestion!!.inputString)
@@ -187,7 +183,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
             thirdQuestion = dao?.getQuestion(thirdQuestionId)
             if (thirdQuestion != null && thirdQuestion!!.inputString.isNullOrEmpty().not()) {
                 binding.editResultThree.post {
-                    if (stringBufferThree.toString().isNullOrEmpty().not()) {
+                    if (stringBufferThree.toString().isEmpty().not()) {
                         stringBufferThree.delete(0, thirdQuestion!!.inputString.length - 1)
                     }
                     stringBufferThree.append(thirdQuestion!!.inputString)
@@ -199,7 +195,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
             fourthQuestion = dao?.getQuestion(fourthQuestionId)
             if (fourthQuestion != null && fourthQuestion!!.inputString.isNullOrEmpty().not()) {
                 binding.editResultFour.post {
-                    if (stringBufferFour.toString().isNullOrEmpty().not()) {
+                    if (stringBufferFour.toString().isEmpty().not()) {
                         stringBufferFour.delete(0, fourthQuestion!!.inputString.length - 1)
                     }
                     stringBufferFour.append(fourthQuestion!!.inputString)
@@ -211,7 +207,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
             fifthQuestion = dao?.getQuestion(fifthQuestionId)
             if (fifthQuestion != null && fifthQuestion!!.inputString.isNullOrEmpty().not()) {
                 binding.editResultFive.post {
-                    if (stringBufferFive.toString().isNullOrEmpty().not()) {
+                    if (stringBufferFive.toString().isEmpty().not()) {
                         stringBufferFive.delete(0, fifthQuestion!!.inputString.length - 1)
                     }
                     stringBufferFive.append(fifthQuestion!!.inputString)
@@ -227,15 +223,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
      */
     private fun judge(): Boolean {
         if (dao != null) {
-            if (binding.editResultOne.text.toString().trim().isNullOrEmpty()) {
+            if (binding.editResultOne.text.toString().trim().isEmpty()) {
                 "请输入第一道题目的答案".toast()
-                binding.editResultOne.requestFocus()
-                binding.editResultOne.isFocusable = true
-                binding.editResultOne.isFocusableInTouchMode = true
-                binding.editResultOne.postDelayed(
-                    { closeKeyBord(binding.editResultOne, mContext) },
-                    300
-                )
                 return false
             } else {
                 if (firstquestion != null) {
@@ -246,15 +235,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
                     dao?.update(firstquestion!!)
                 }
             }
-            if (binding.editResultTwo.text.toString().trim().isNullOrEmpty()) {
+            if (binding.editResultTwo.text.toString().trim().isEmpty()) {
                 "请输入第二道题目的答案".toast()
-                binding.editResultTwo.requestFocus()
-                binding.editResultTwo.isFocusable = true
-                binding.editResultTwo.isFocusableInTouchMode = true
-                binding.editResultTwo.postDelayed(
-                    { closeKeyBord(binding.editResultOne, mContext) },
-                    300
-                )
                 return false
             } else {
                 if (secondQuestion != null) {
@@ -265,17 +247,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
                     dao?.update(secondQuestion!!)
                 }
             }
-            if (binding.editResultThree.text.toString().trim().isNullOrEmpty()) {
+            if (binding.editResultThree.text.toString().trim().isEmpty()) {
                 "请输入第三道题目的答案".toast()
-                binding.editResultThree.requestFocus()
-                binding.editResultThree.isFocusable = true
-                binding.editResultThree.isFocusableInTouchMode = true
-                binding.editResultThree.postDelayed({
-                    closeKeyBord(
-                        binding.editResultOne,
-                        mContext
-                    )
-                }, 300)
                 return false
             } else {
                 if (thirdQuestion != null) {
@@ -286,17 +259,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
                     dao?.update(thirdQuestion!!)
                 }
             }
-            if (binding.editResultFour.text.toString().trim().isNullOrEmpty()) {
+            if (binding.editResultFour.text.toString().trim().isEmpty()) {
                 "请输入第四道题目的答案".toast()
-                binding.editResultFour.requestFocus()
-                binding.editResultFour.isFocusable = true
-                binding.editResultFour.isFocusableInTouchMode = true
-                binding.editResultFour.postDelayed({
-                    closeKeyBord(
-                        binding.editResultOne,
-                        mContext
-                    )
-                }, 300)
                 return false
             } else {
                 if (fourthQuestion != null) {
@@ -307,17 +271,8 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
                     dao?.update(fourthQuestion!!)
                 }
             }
-            if (binding.editResultFive.text.toString().trim().isNullOrEmpty()) {
+            if (binding.editResultFive.text.toString().trim().isEmpty()) {
                 "请输入第五道题目的答案".toast()
-                binding.editResultFive.requestFocus()
-                binding.editResultFive.isFocusable = true
-                binding.editResultFive.isFocusableInTouchMode = true
-                binding.editResultFive.postDelayed({
-                    closeKeyBord(
-                        binding.editResultOne,
-                        mContext
-                    )
-                }, 300)
                 return false
             } else {
                 if (fifthQuestion != null) {
@@ -379,7 +334,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
     private fun delete() {
         if (questionOne) {
             binding.editResultOne.post {
-                if (stringBufferOne.toString().isNullOrEmpty().not()) {
+                if (stringBufferOne.toString().isEmpty().not()) {
                     val size = stringBufferOne.toString().length - 1
                     stringBufferOne.deleteCharAt(size)
                     binding.editResultOne.setText(stringBufferOne.toString())
@@ -389,7 +344,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
         }
         if (questionTwo) {
             binding.editResultTwo.post {
-                if (stringBufferTwo.toString().isNullOrEmpty().not()) {
+                if (stringBufferTwo.toString().isEmpty().not()) {
                     val size = stringBufferTwo.toString().length - 1
                     stringBufferTwo.deleteCharAt(size)
                     binding.editResultTwo.setText(stringBufferTwo.toString())
@@ -399,7 +354,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
         }
         if (questionThree) {
             binding.editResultThree.post {
-                if (stringBufferThree.toString().isNullOrEmpty().not()) {
+                if (stringBufferThree.toString().isEmpty().not()) {
                     val size = stringBufferThree.toString().length - 1
                     stringBufferThree.deleteCharAt(size)
                     binding.editResultThree.setText(stringBufferThree.toString())
@@ -409,7 +364,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
         }
         if (questionFour) {
             binding.editResultFour.post {
-                if (stringBufferFour.toString().isNullOrEmpty().not()) {
+                if (stringBufferFour.toString().isEmpty().not()) {
                     val size = stringBufferFour.toString().length - 1
                     stringBufferFour.deleteCharAt(size)
                     binding.editResultFour.setText(stringBufferFour.toString())
@@ -419,7 +374,7 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
         }
         if (questionFive) {
             binding.editResultFive.post {
-                if (stringBufferFive.toString().isNullOrEmpty().not()) {
+                if (stringBufferFive.toString().isEmpty().not()) {
                     val size = stringBufferFive.toString().length - 1
                     stringBufferFive.deleteCharAt(size)
                     binding.editResultFive.setText(stringBufferFive.toString())
@@ -482,4 +437,55 @@ class ComputationFragment : BaseFragment<FragmentComputationBinding>() {
 
         }
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    pageUp(v)
+                } else if (v.id == R.id.btnNext) {
+                    pageNext(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun pageUp(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 51)
+        controller.navigate(
+            R.id.action_computationFragment_to_numberRecordsFragment,
+            bundle
+        )
+    }
+
+    /**
+     * 下一页
+     */
+    private fun pageNext(v: View) {
+        if (judge()) {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 57)
+            controller.navigate(
+                R.id.action_computationFragment_to_listenSpeakFragment,
+                bundle
+            )
+        }
+    }
 }

+ 80 - 37
moca/src/main/java/com/yingyangfly/moca/record/ListenRecordFragment.kt

@@ -1,18 +1,23 @@
 package com.yingyangfly.moca.record
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentListenRecordBinding
 import com.yingyangfly.baselib.base.BaseFragment
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.voice.PlayVoice
 
 /**
  * 听录音说答案
  */
-class ListenRecordFragment : BaseFragment<FragmentListenRecordBinding>() {
+class ListenRecordFragment : BaseFragment<FragmentListenRecordBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
@@ -31,38 +36,12 @@ class ListenRecordFragment : BaseFragment<FragmentListenRecordBinding>() {
         playVoice?.setContext(mContext)
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                if (questionId == 44) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 41)
-                    controller.navigate(
-                        R.id.action_listenRecordFragment_to_identifyResultFragment,
-                        bundle
-                    )
-                } else {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 44)
-                    controller.navigate(
-                        R.id.action_listenRecordFragment_to_recordResultFragment,
-                        bundle
-                    )
-                }
-            }
-
-            btnNext.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to questionId)
-                controller.navigate(
-                    R.id.action_listenRecordFragment_to_recordResultFragment,
-                    bundle
-                )
-            }
-
-            imagePlay.setOnSingleClickListener {
-                playVoice?.speakWithParagraph(words)
-            }
+            btnPrevious.setOnTouchListener(this@ListenRecordFragment)
+            btnNext.setOnTouchListener(this@ListenRecordFragment)
+            imagePlay.setOnTouchListener(this@ListenRecordFragment)
         }
     }
 
@@ -86,12 +65,12 @@ class ListenRecordFragment : BaseFragment<FragmentListenRecordBinding>() {
         }
         words.clear()
         if (dao != null) {
-            val firstquestion = dao?.getQuestion(questionId)
-            if (firstquestion != null) {
-                words.add(firstquestion.reviewItem)
+            val firstQuestion = dao?.getQuestion(questionId)
+            if (firstQuestion != null) {
+                words.add(firstQuestion.reviewItem)
             }
-            val secondQuestionnId = questionId + 1
-            val secondQuestion = dao?.getQuestion(secondQuestionnId)
+            val secondQuestionId = questionId + 1
+            val secondQuestion = dao?.getQuestion(secondQuestionId)
             if (secondQuestion != null) {
                 words.add(secondQuestion.reviewItem)
             }
@@ -119,4 +98,68 @@ class ListenRecordFragment : BaseFragment<FragmentListenRecordBinding>() {
             playVoice?.stop()
         }
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.imagePlay) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                when (v.id) {
+                    R.id.btnPrevious -> {
+                        previousPage(v)
+                    }
+                    R.id.btnNext -> {
+                        nextPage(v)
+                    }
+                    R.id.imagePlay -> {
+                        playVoice?.speakWithParagraph(words)
+                    }
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.imagePlay) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        if (questionId == 44) {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 41)
+            controller.navigate(
+                R.id.action_listenRecordFragment_to_identifyResultFragment,
+                bundle
+            )
+        } else {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 44)
+            controller.navigate(
+                R.id.action_listenRecordFragment_to_recordResultFragment,
+                bundle
+            )
+        }
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to questionId)
+        controller.navigate(
+            R.id.action_listenRecordFragment_to_recordResultFragment,
+            bundle
+        )
+    }
 }

+ 96 - 56
moca/src/main/java/com/yingyangfly/moca/record/RecordResultFragment.kt

@@ -1,20 +1,25 @@
 package com.yingyangfly.moca.record
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentRecordResultBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.moca.adapter.ChoiceAdapter
 
 /**
  * 判断结果
  */
-class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
+class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
@@ -39,56 +44,11 @@ class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                if (questionId == 62) {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to 61)
-                    controller.navigate(
-                        R.id.action_recordResultFragment_to_singleChoiceFragment,
-                        bundle
-                    )
-                } else {
-                    val controller = Navigation.findNavController(it)
-                    val bundle = bundleOf("questionId" to questionId)
-                    controller.navigate(
-                        R.id.action_recordResultFragment_to_listenRecordFragment,
-                        bundle
-                    )
-                }
-            }
-
-            btnNext.setOnSingleClickListener {
-                if (judge()) {
-                    when (questionId) {
-                        62 -> {
-                            val controller = Navigation.findNavController(it)
-                            val bundle = bundleOf("questionId" to 67)
-                            controller.navigate(
-                                R.id.action_recordResultFragment_to_tipsFragment,
-                                bundle
-                            )
-                        }
-                        44 -> {
-                            val controller = Navigation.findNavController(it)
-                            val bundle = bundleOf("questionId" to 78)
-                            controller.navigate(
-                                R.id.action_recordResultFragment_to_listenRecordFragment,
-                                bundle
-                            )
-                        }
-                        else -> {
-                            val controller = Navigation.findNavController(it)
-                            val bundle = bundleOf("questionId" to 49)
-                            controller.navigate(
-                                R.id.action_recordResultFragment_to_memorizeNumbersFragment,
-                                bundle
-                            )
-                        }
-                    }
-                }
-            }
+            btnPrevious.setOnTouchListener(this@RecordResultFragment)
+            btnNext.setOnTouchListener(this@RecordResultFragment)
         }
     }
 
@@ -112,12 +72,12 @@ class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
         }
         choiceItemList.clear()
         if (dao != null) {
-            val firstquestion = dao?.getQuestion(questionId)
-            if (firstquestion != null) {
-                choiceItemList.add(firstquestion)
+            val firstQuestion = dao?.getQuestion(questionId)
+            if (firstQuestion != null) {
+                choiceItemList.add(firstQuestion)
             }
-            val secondQuestionnId = questionId + 1
-            val secondQuestion = dao?.getQuestion(secondQuestionnId)
+            val secondQuestionId = questionId + 1
+            val secondQuestion = dao?.getQuestion(secondQuestionId)
             if (secondQuestion != null) {
                 choiceItemList.add(secondQuestion)
             }
@@ -145,7 +105,7 @@ class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
      * 非空判断
      */
     private fun judge(): Boolean {
-        if (choiceItemList.isNullOrEmpty().not()) {
+        if (choiceItemList.isEmpty().not()) {
             choiceItemList.forEach {
                 if (it.inputString.isNullOrEmpty()) {
                     "请判断答案是否正确".toast()
@@ -155,4 +115,84 @@ class RecordResultFragment : BaseFragment<FragmentRecordResultBinding>() {
         }
         return true
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        if (questionId == 62) {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 61)
+            controller.navigate(
+                R.id.action_recordResultFragment_to_singleChoiceFragment,
+                bundle
+            )
+        } else {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to questionId)
+            controller.navigate(
+                R.id.action_recordResultFragment_to_listenRecordFragment,
+                bundle
+            )
+        }
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (judge()) {
+            when (questionId) {
+                62 -> {
+                    val controller = Navigation.findNavController(v)
+                    val bundle = bundleOf("questionId" to 67)
+                    controller.navigate(
+                        R.id.action_recordResultFragment_to_tipsFragment,
+                        bundle
+                    )
+                }
+                44 -> {
+                    val controller = Navigation.findNavController(v)
+                    val bundle = bundleOf("questionId" to 78)
+                    controller.navigate(
+                        R.id.action_recordResultFragment_to_listenRecordFragment,
+                        bundle
+                    )
+                }
+                else -> {
+                    val controller = Navigation.findNavController(v)
+                    val bundle = bundleOf("questionId" to 49)
+                    controller.navigate(
+                        R.id.action_recordResultFragment_to_memorizeNumbersFragment,
+                        bundle
+                    )
+                }
+            }
+        }
+    }
 }

+ 72 - 31
moca/src/main/java/com/yingyangfly/moca/signature/DesignsChoiceFragment.kt

@@ -1,9 +1,12 @@
 package com.yingyangfly.moca.signature
 
+import android.annotation.SuppressLint
 import android.graphics.Bitmap
 import android.graphics.drawable.BitmapDrawable
 import android.graphics.drawable.Drawable
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import androidx.recyclerview.widget.LinearLayoutManager
@@ -11,7 +14,8 @@ import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentDesignsChoiceBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.baselib.utils.ImageUtil
 import com.yingyangfly.moca.adapter.ChoiceAdapter
@@ -19,12 +23,13 @@ import com.yingyangfly.moca.adapter.ChoiceAdapter
 /**
  * 画图判断
  */
-class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
+class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
      */
-    var questionId = 0
+    private var questionId = 0
 
     private val choiceItemList = mutableListOf<QuestionsBean>()
     private val adapter by lazy { ChoiceAdapter() }
@@ -48,29 +53,11 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 33)
-                controller.navigate(
-                    R.id.action_designsChoiceFragment_to_signatureFragment,
-                    bundle
-                )
-            }
-            btnNext.setOnSingleClickListener {
-                if (judge()) {
-                    binding.rvChoice.post {
-                        updateStatus()
-                        val controller = Navigation.findNavController(it)
-                        val bundle = bundleOf("questionId" to 38)
-                        controller.navigate(
-                            R.id.action_designsChoiceFragment_to_drawDesignFragment,
-                            bundle
-                        )
-                    }
-                }
-            }
+            btnPrevious.setOnTouchListener(this@DesignsChoiceFragment)
+            btnNext.setOnTouchListener(this@DesignsChoiceFragment)
         }
     }
 
@@ -79,7 +66,7 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
      */
     private fun updateStatus() {
         var isAllCorrect = true
-        if (choiceItemList.isNullOrEmpty().not()) {
+        if (choiceItemList.isEmpty().not()) {
             choiceItemList.forEach {
                 if (it.correct == "0") {
                     isAllCorrect = false
@@ -126,12 +113,12 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
         }
         choiceItemList.clear()
         if (dao != null) {
-            val firstquestion = dao?.getQuestion(questionId)
-            if (firstquestion != null) {
-                choiceItemList.add(firstquestion)
+            val firstQuestion = dao?.getQuestion(questionId)
+            if (firstQuestion != null) {
+                choiceItemList.add(firstQuestion)
             }
-            val secondQuestionnId = questionId + 1
-            val secondQuestion = dao?.getQuestion(secondQuestionnId)
+            val secondQuestionId = questionId + 1
+            val secondQuestion = dao?.getQuestion(secondQuestionId)
             if (secondQuestion != null) {
                 choiceItemList.add(secondQuestion)
             }
@@ -159,7 +146,7 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
      * 非空判断
      */
     private fun judge(): Boolean {
-        if (choiceItemList.isNullOrEmpty().not()) {
+        if (choiceItemList.isEmpty().not()) {
             choiceItemList.forEach {
                 if (it.inputString.isNullOrEmpty()) {
                     "请判断答案是否正确".toast()
@@ -169,4 +156,58 @@ class DesignsChoiceFragment : BaseFragment<FragmentDesignsChoiceBinding>() {
         }
         return true
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 33)
+        controller.navigate(
+            R.id.action_designsChoiceFragment_to_signatureFragment,
+            bundle
+        )
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (judge()) {
+            binding.rvChoice.post {
+                updateStatus()
+                val controller = Navigation.findNavController(v)
+                val bundle = bundleOf("questionId" to 38)
+                controller.navigate(
+                    R.id.action_designsChoiceFragment_to_drawDesignFragment,
+                    bundle
+                )
+            }
+        }
+    }
 }

+ 71 - 30
moca/src/main/java/com/yingyangfly/moca/signature/SignatureFragment.kt

@@ -1,26 +1,29 @@
 package com.yingyangfly.moca.signature
 
+import android.annotation.SuppressLint
 import android.graphics.Bitmap
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentSignatureBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 
 /**
  * 视结构技能
  */
-class SignatureFragment : BaseFragment<FragmentSignatureBinding>() {
-
+class SignatureFragment : BaseFragment<FragmentSignatureBinding>(),
+    View.OnTouchListener {
     /**
      * 原始问题id
      */
-    var questionId = 0
-
-    var question: QuestionsBean? = null
+    private var questionId = 0
+    private var question: QuestionsBean? = null
 
     override fun onCreate(savedInstanceState: Bundle?) {
         questionId = arguments?.getInt("questionId") ?: 33
@@ -31,32 +34,12 @@ class SignatureFragment : BaseFragment<FragmentSignatureBinding>() {
 
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            rubberLayout.setOnSingleClickListener {
-                signatureView.clear()
-            }
-
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 32)
-                controller.navigate(
-                    R.id.action_signatureFragment_to_alternatingconnectionFragment,
-                    bundle
-                )
-            }
-
-            btnNext.setOnSingleClickListener {
-                val bundle = Bundle()
-                bundle.putInt("questionId", 33)
-                val bitmap: Bitmap = signatureView.getCachebBitmaps()
-                bundle.putParcelable("bitmap", bitmap)
-                val controller = Navigation.findNavController(it)
-                controller.navigate(
-                    R.id.action_signatureFragment_to_designsChoiceFragment,
-                    bundle
-                )
-            }
+            rubberLayout.setOnTouchListener(this@SignatureFragment)
+            btnPrevious.setOnTouchListener(this@SignatureFragment)
+            btnNext.setOnTouchListener(this@SignatureFragment)
         }
     }
 
@@ -82,4 +65,62 @@ class SignatureFragment : BaseFragment<FragmentSignatureBinding>() {
             }
         }
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.rubberLayout) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                when (v.id) {
+                    R.id.btnPrevious -> {
+                        previousPage(v)
+                    }
+                    R.id.btnNext -> {
+                        nextPage(v)
+                    }
+                    R.id.rubberLayout -> {
+                        binding.signatureView.clear()
+                    }
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.rubberLayout) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 32)
+        controller.navigate(
+            R.id.action_signatureFragment_to_alternatingconnectionFragment,
+            bundle
+        )
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        val bundle = Bundle()
+        bundle.putInt("questionId", 33)
+        val bitmap: Bitmap = binding.signatureView.getCachebBitmaps()
+        bundle.putParcelable("bitmap", bitmap)
+        val controller = Navigation.findNavController(v)
+        controller.navigate(
+            R.id.action_signatureFragment_to_designsChoiceFragment,
+            bundle
+        )
+    }
 }

+ 96 - 57
moca/src/main/java/com/yingyangfly/moca/singlechoice/SingleChoiceFragment.kt

@@ -1,13 +1,17 @@
 package com.yingyangfly.moca.singlechoice
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentSingleChoiceBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
 import com.yingyangfly.baselib.utils.RxBusCodes
 import com.yingyangfly.moca.adapter.SpeakResultAdapter
@@ -16,7 +20,8 @@ import gorden.rxbus2.RxBus
 /**
  * 单选
  */
-class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
+class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
@@ -42,62 +47,11 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                when (questionId) {
-                    76 -> {
-                        questionId++
-                        loadData()
-                    }
-                    77 -> {
-                        val bundle = bundleOf("questionId" to questionId)
-                        controller.navigate(
-                            R.id.action_singleChoiceFragment_to_weekFragment,
-                            bundle
-                        )
-                    }
-                    60 -> {
-                        btnPrevious.setOnSingleClickListener {
-                            val bundle = bundleOf("questionId" to 59)
-                            controller.navigate(
-                                R.id.action_singleChoiceFragment_to_numberRecordsFragment,
-                                bundle
-                            )
-                        }
-                    }
-                    else -> {
-                        questionId--
-                        loadData()
-                    }
-                }
-            }
-            btnNext.setOnSingleClickListener {
-                if (judge()) {
-                    when (questionId) {
-                        60 -> {
-                            questionId++
-                            loadData()
-                        }
-                        77 -> {
-                            questionId--
-                            loadData()
-                        }
-                        76 -> {
-                            RxBus.get().send(RxBusCodes.EndMOCAQuestion)
-                        }
-                        else -> {
-                            val controller = Navigation.findNavController(it)
-                            val bundle = bundleOf("questionId" to 62)
-                            controller.navigate(
-                                R.id.action_singleChoiceFragment_to_recordresultfragment,
-                                bundle
-                            )
-                        }
-                    }
-                }
-            }
+            btnPrevious.setOnTouchListener(this@SingleChoiceFragment)
+            btnNext.setOnTouchListener(this@SingleChoiceFragment)
         }
     }
 
@@ -142,7 +96,7 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
      * 非空判断
      */
     private fun judge(): Boolean {
-        if (choiceItemList.isNullOrEmpty().not()) {
+        if (choiceItemList.isEmpty().not()) {
             choiceItemList.forEach {
                 if (it.inputString.isNullOrEmpty()) {
                     "请判断答案是否正确".toast()
@@ -152,4 +106,89 @@ class SingleChoiceFragment : BaseFragment<FragmentSingleChoiceBinding>() {
         }
         return true
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        when (questionId) {
+            76 -> {
+                questionId++
+                loadData()
+            }
+            77 -> {
+                val bundle = bundleOf("questionId" to questionId)
+                controller.navigate(
+                    R.id.action_singleChoiceFragment_to_weekFragment,
+                    bundle
+                )
+            }
+            60 -> {
+                val bundle = bundleOf("questionId" to 59)
+                controller.navigate(
+                    R.id.action_singleChoiceFragment_to_numberRecordsFragment,
+                    bundle
+                )
+            }
+            else -> {
+                questionId--
+                loadData()
+            }
+        }
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (judge()) {
+            when (questionId) {
+                60 -> {
+                    questionId++
+                    loadData()
+                }
+                77 -> {
+                    questionId--
+                    loadData()
+                }
+                76 -> {
+                    RxBus.get().send(RxBusCodes.EndMOCAQuestion)
+                }
+                else -> {
+                    val controller = Navigation.findNavController(v)
+                    val bundle = bundleOf("questionId" to 62)
+                    controller.navigate(
+                        R.id.action_singleChoiceFragment_to_recordresultfragment,
+                        bundle
+                    )
+                }
+            }
+        }
+    }
 }

+ 109 - 59
moca/src/main/java/com/yingyangfly/moca/timepiece/TimepieceFragment.kt

@@ -1,6 +1,7 @@
 package com.yingyangfly.moca.timepiece
 
 import android.annotation.SuppressLint
+import android.view.MotionEvent
 import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
@@ -8,98 +9,147 @@ import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentTimepieceBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.dialog.TipsDialog
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.utils.RxTimer
 
 /**
  * 计时器
  */
-class TimepieceFragment : BaseFragment<FragmentTimepieceBinding>() {
+class TimepieceFragment : BaseFragment<FragmentTimepieceBinding>(),
+    View.OnTouchListener {
 
-    lateinit var rxTimer: RxTimer
+    private lateinit var rxTimer: RxTimer
     private var seconds: Long = 0
 
     override fun initViews() {
         rxTimer = RxTimer()
     }
 
-    @SuppressLint("SetTextI18n")
+    @SuppressLint("SetTextI18n", "ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnStartClock.setOnSingleClickListener {
-                tvMinute.text = "00"
-                val m: Long = 1000
-                val time = 59.toLong()
-                rxTimer.interval(m) {
-                    if (it < time) {
-                        seconds = it + 1
-                        val second = it + 1
-                        tvSecond.text = if (second < 9) {
-                            "0$second"
-                        } else {
-                            second.toString()
-                        }
-                    } else {
-                        seconds = 0
-                        tvMinute.text = "01"
-                        tvSecond.text = "00"
+            btnStartClock.setOnTouchListener(this@TimepieceFragment)
+            btnResetting.setOnTouchListener(this@TimepieceFragment)
+            btnPrevious.setOnTouchListener(this@TimepieceFragment)
+            btnNext.setOnTouchListener(this@TimepieceFragment)
+        }
+    }
+
+    override fun initData() {
+
+    }
+
+    override fun onPause() {
+        super.onPause()
+        rxTimer.cancel()
+    }
+
+    @SuppressLint("ClickableViewAccessibility", "SetTextI18n")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.btnStartClock || v.id == R.id.btnResetting) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                when (v.id) {
+                    R.id.btnPrevious -> {
+                        previousPage(v)
+                    }
+                    R.id.btnNext -> {
+                        nextPage(v)
+                    }
+                    R.id.btnStartClock -> {
+                        startClock()
+                    }
+                    R.id.btnResetting -> {
                         rxTimer.cancel()
+                        binding.tvMinute.text = "00"
+                        binding.tvSecond.text = "00"
                     }
                 }
             }
-
-            btnResetting.setOnSingleClickListener {
-                rxTimer.cancel()
-                tvMinute.text = "00"
-                tvSecond.text = "00"
-            }
-
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 58)
-                controller.navigate(
-                    R.id.action_timepieceFragment_to_listenSpeakResultFragment,
-                    bundle
-                )
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext || v.id == R.id.btnStartClock || v.id == R.id.btnResetting) {
+                    v.startAnimation(getEndAnimation())
+                }
             }
+        }
+        return true
+    }
 
-            btnNext.setOnSingleClickListener {
-                if (seconds < 60) {
-                    TipsDialog.TipDialogBuilder()
-                        .title("提示", R.color.color_FF222222)
-                        .content("时间还未满1分钟,确定继续下一页吗?")
-                        .leftBtnText("取消")
-                        .rightBtnText("确定")
-                        .leftClick({
-                            null
-                        }, true)
-                        .rightClick({
-                            goNextPage(it)
-                            null
-                        }, true)
-                        .show(childFragmentManager)
+    /**
+     * 开始计时
+     */
+    @SuppressLint("SetTextI18n")
+    private fun startClock() {
+        binding.tvMinute.text = "00"
+        val m: Long = 1000
+        val time = 59.toLong()
+        rxTimer.interval(m) {
+            if (it < time) {
+                seconds = it + 1
+                val second = it + 1
+                binding.tvSecond.text = if (second < 9) {
+                    "0$second"
                 } else {
-                    goNextPage(it)
+                    second.toString()
                 }
+            } else {
+                seconds = 0
+                binding.tvMinute.text = "01"
+                binding.tvSecond.text = "00"
+                rxTimer.cancel()
             }
         }
     }
 
-    private fun goNextPage(view: View) {
-        val controller = Navigation.findNavController(view)
-        val bundle = bundleOf("questionId" to 59)
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 58)
         controller.navigate(
-            R.id.action_timepieceFragment_to_numberRecordsFragment,
+            R.id.action_timepieceFragment_to_listenSpeakResultFragment,
             bundle
         )
     }
 
-    override fun initData() {
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (seconds < 60) {
+            TipsDialog.TipDialogBuilder()
+                .title("提示", R.color.color_FF222222)
+                .content("时间还未满1分钟,确定继续下一页吗?")
+                .leftBtnText("取消")
+                .rightBtnText("确定")
+                .leftClick({
 
+                }, true)
+                .rightClick({
+                    goNextPage(v)
+                }, true)
+                .show(childFragmentManager)
+        } else {
+            goNextPage(v)
+        }
     }
 
-    override fun onPause() {
-        super.onPause()
-        rxTimer.cancel()
+    /**
+     * 跳转下一页
+     */
+    private fun goNextPage(view: View) {
+        val controller = Navigation.findNavController(view)
+        val bundle = bundleOf("questionId" to 59)
+        controller.navigate(
+            R.id.action_timepieceFragment_to_numberRecordsFragment,
+            bundle
+        )
     }
 }

+ 67 - 26
moca/src/main/java/com/yingyangfly/moca/tips/TipsFragment.kt

@@ -1,21 +1,25 @@
 package com.yingyangfly.moca.tips
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentTipsBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.ext.toast
-import com.yingyangfly.moca.adapter.ChoiceAdapter
 import com.yingyangfly.moca.adapter.TipsAdapter
 
 /**
  * 特别提示
  */
-class TipsFragment : BaseFragment<FragmentTipsBinding>() {
+class TipsFragment : BaseFragment<FragmentTipsBinding>(),
+    View.OnTouchListener {
 
     /**
      * 问题id
@@ -40,25 +44,11 @@ class TipsFragment : BaseFragment<FragmentTipsBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 62)
-                controller.navigate(
-                    R.id.action_tipsFragment_to_recordResultFragment,
-                    bundle
-                )
-            }
-
-            btnNext.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 74)
-                controller.navigate(
-                    R.id.action_tipsFragment_to_numberRecordsFragment,
-                    bundle
-                )
-            }
+            btnPrevious.setOnTouchListener(this@TipsFragment)
+            btnNext.setOnTouchListener(this@TipsFragment)
         }
     }
 
@@ -77,12 +67,12 @@ class TipsFragment : BaseFragment<FragmentTipsBinding>() {
     private fun loadData() {
         choiceItemList.clear()
         if (dao != null) {
-            val firstquestion = dao?.getQuestion(questionId)
-            if (firstquestion != null) {
-                choiceItemList.add(firstquestion)
+            val firstQuestion = dao?.getQuestion(questionId)
+            if (firstQuestion != null) {
+                choiceItemList.add(firstQuestion)
             }
-            val secondQuestionnId = questionId + 1
-            val secondQuestion = dao?.getQuestion(secondQuestionnId)
+            val secondQuestionId = questionId + 1
+            val secondQuestion = dao?.getQuestion(secondQuestionId)
             if (secondQuestion != null) {
                 choiceItemList.add(secondQuestion)
             }
@@ -110,7 +100,7 @@ class TipsFragment : BaseFragment<FragmentTipsBinding>() {
      * 非空判断
      */
     private fun judge(): Boolean {
-        if (choiceItemList.isNullOrEmpty().not()) {
+        if (choiceItemList.isEmpty().not()) {
             choiceItemList.forEach {
                 if (it.inputString.isNullOrEmpty()) {
                     "请判断答案是否正确".toast()
@@ -120,4 +110,55 @@ class TipsFragment : BaseFragment<FragmentTipsBinding>() {
         }
         return true
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 62)
+        controller.navigate(
+            R.id.action_tipsFragment_to_recordResultFragment,
+            bundle
+        )
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        if (judge()) {
+            val controller = Navigation.findNavController(v)
+            val bundle = bundleOf("questionId" to 74)
+            controller.navigate(
+                R.id.action_tipsFragment_to_numberRecordsFragment,
+                bundle
+            )
+        }
+    }
 }

+ 61 - 23
moca/src/main/java/com/yingyangfly/moca/week/WeekFragment.kt

@@ -1,6 +1,9 @@
 package com.yingyangfly.moca.week
 
+import android.annotation.SuppressLint
 import android.os.Bundle
+import android.view.MotionEvent
+import android.view.View
 import androidx.core.os.bundleOf
 import androidx.navigation.Navigation
 import com.google.android.flexbox.FlexWrap
@@ -10,21 +13,21 @@ import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentWeekBinding
 import com.yingyangfly.baselib.base.BaseFragment
 import com.yingyangfly.baselib.db.QuestionsBean
-import com.yingyangfly.baselib.ext.setOnSingleClickListener
+import com.yingyangfly.baselib.ext.getEndAnimation
+import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.moca.adapter.SelectedItemAdapter
 
 /**
  * 星期选择
  */
-class WeekFragment : BaseFragment<FragmentWeekBinding>() {
+class WeekFragment : BaseFragment<FragmentWeekBinding>(),
+    View.OnTouchListener {
 
     /**
      * 原始问题id
      */
-    var questionId = 0
-
-    var question: QuestionsBean? = null
-
+    private var questionId = 0
+    private var question: QuestionsBean? = null
     private val itemList = mutableListOf<String>()
     private val selectedAdapter by lazy { SelectedItemAdapter() }
 
@@ -52,25 +55,11 @@ class WeekFragment : BaseFragment<FragmentWeekBinding>() {
         }
     }
 
+    @SuppressLint("ClickableViewAccessibility")
     override fun initListener() {
         binding {
-            btnPrevious.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 72)
-                controller.navigate(
-                    R.id.action_weekFragment_to_numberRecordsFragment,
-                    bundle
-                )
-            }
-
-            btnNext.setOnSingleClickListener {
-                val controller = Navigation.findNavController(it)
-                val bundle = bundleOf("questionId" to 77)
-                controller.navigate(
-                    R.id.action_weekFragment_to_singleChoiceFragment,
-                    bundle
-                )
-            }
+            btnPrevious.setOnTouchListener(this@WeekFragment)
+            btnNext.setOnTouchListener(this@WeekFragment)
         }
     }
 
@@ -136,4 +125,53 @@ class WeekFragment : BaseFragment<FragmentWeekBinding>() {
             }
         }
     }
+
+    @SuppressLint("ClickableViewAccessibility")
+    override fun onTouch(v: View, event: MotionEvent): Boolean {
+        when (event.action) {
+            MotionEvent.ACTION_DOWN -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getScaleAnimation())
+                }
+            }
+            MotionEvent.ACTION_UP -> {
+                v.startAnimation(getEndAnimation())
+                if (v.id == R.id.btnPrevious) {
+                    previousPage(v)
+                } else if (v.id == R.id.btnNext) {
+                    nextPage(v)
+                }
+            }
+            MotionEvent.ACTION_CANCEL -> {
+                if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
+                    v.startAnimation(getEndAnimation())
+                }
+            }
+        }
+        return true
+    }
+
+    /**
+     * 上一页
+     */
+    private fun previousPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 72)
+        controller.navigate(
+            R.id.action_weekFragment_to_numberRecordsFragment,
+            bundle
+        )
+    }
+
+    /**
+     * 下一页
+     */
+    private fun nextPage(v: View) {
+        val controller = Navigation.findNavController(v)
+        val bundle = bundleOf("questionId" to 77)
+        controller.navigate(
+            R.id.action_weekFragment_to_singleChoiceFragment,
+            bundle
+        )
+    }
 }