|
@@ -1,7 +1,10 @@
|
|
|
package com.yingyangfly.mmse.fragment
|
|
|
|
|
|
+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
|
|
@@ -10,6 +13,8 @@ import com.yingyang.mmse.R
|
|
|
import com.yingyang.mmse.databinding.FragmentCountBinding
|
|
|
import com.yingyangfly.baselib.base.BaseFragment
|
|
|
import com.yingyangfly.baselib.db.QuestionsBean
|
|
|
+import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
+import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
import com.yingyangfly.baselib.ext.setOnSingleClickListener
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.mmse.adapter.NumberAdapter
|
|
@@ -17,7 +22,7 @@ import com.yingyangfly.mmse.adapter.NumberAdapter
|
|
|
/**
|
|
|
* 计算题fragment
|
|
|
*/
|
|
|
-class CountFragment : BaseFragment<FragmentCountBinding>() {
|
|
|
+class CountFragment : BaseFragment<FragmentCountBinding>(), View.OnTouchListener {
|
|
|
|
|
|
/**
|
|
|
* 问题id
|
|
@@ -86,69 +91,11 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
override fun initListener() {
|
|
|
binding {
|
|
|
- btnPrevious.setOnSingleClickListener {
|
|
|
- val bundle = Bundle()
|
|
|
- bundle.putInt("questionId", 11)
|
|
|
- bundle.putString("choiceItems", choiceItems)
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_countFragment_to_multipleChoiceFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- btnNext.setOnSingleClickListener {
|
|
|
- if (judge()) {
|
|
|
- val bundle = bundleOf("questionId" to 22)
|
|
|
- val controller = Navigation.findNavController(it)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_countFragment_to_recognitionImageFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- editResultOne.setOnFocusChangeListener { v, hasFocus ->
|
|
|
- questionOne = hasFocus
|
|
|
- binding.editResultOne.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultOne, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- editResultTwo.setOnFocusChangeListener { v, hasFocus ->
|
|
|
- questionTwo = hasFocus
|
|
|
- binding.editResultTwo.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultTwo, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- editResultThree.setOnFocusChangeListener { v, hasFocus ->
|
|
|
- questionThree = hasFocus
|
|
|
- binding.editResultThree.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultThree, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- editResultFour.setOnFocusChangeListener { v, hasFocus ->
|
|
|
- questionFour = hasFocus
|
|
|
- binding.editResultFour.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultFour, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- editResultFive.setOnFocusChangeListener { v, hasFocus ->
|
|
|
- questionFive = hasFocus
|
|
|
- binding.editResultFive.postDelayed(
|
|
|
- { closeKeyBord(binding.editResultFive, mContext) },
|
|
|
- 300
|
|
|
- )
|
|
|
- }
|
|
|
+ btnPrevious.setOnTouchListener(this@CountFragment)
|
|
|
+ btnNext.setOnTouchListener(this@CountFragment)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -308,7 +255,7 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
|
|
|
if (fourthQuestion != null) {
|
|
|
fourthQuestion?.inputString = binding.editResultFour.text.toString().trim()
|
|
|
fourthQuestion!!.reviewId = fourthQuestion!!.id
|
|
|
- fourthQuestion!!.reviewAnswer = binding.editResultFour.text.toString().trim()
|
|
|
+ fourthQuestion!!.reviewAnswer = binding.editResultFour.text.toString().trim()
|
|
|
fourthQuestion!!.correct = ""
|
|
|
dao?.update(fourthQuestion!!)
|
|
|
}
|
|
@@ -488,4 +435,42 @@ class CountFragment : BaseFragment<FragmentCountBinding>() {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ val bundle = Bundle()
|
|
|
+ bundle.putInt("questionId", 11)
|
|
|
+ bundle.putString("choiceItems", choiceItems)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_countFragment_to_multipleChoiceFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ } else if (v.id == R.id.btnNext) {
|
|
|
+ if (judge()) {
|
|
|
+ val bundle = bundleOf("questionId" to 22)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_countFragment_to_recognitionImageFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MotionEvent.ACTION_CANCEL -> {
|
|
|
+ if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
|
|
|
+ v.startAnimation(getEndAnimation())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
}
|