|
@@ -3,21 +3,20 @@ package com.dlc.chemical.ui.common
|
|
|
import android.annotation.SuppressLint
|
|
import android.annotation.SuppressLint
|
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
|
import android.graphics.Typeface
|
|
import android.graphics.Typeface
|
|
|
-import android.os.*
|
|
|
|
|
|
|
+import android.os.Bundle
|
|
|
|
|
+import android.os.Handler
|
|
|
|
|
+import android.os.Looper
|
|
|
|
|
+import android.os.Message
|
|
|
|
|
+import android.os.Parcel
|
|
|
|
|
+import android.os.Parcelable
|
|
|
import android.view.View
|
|
import android.view.View
|
|
|
-import android.view.ViewTreeObserver
|
|
|
|
|
import com.dlc.chemical.R
|
|
import com.dlc.chemical.R
|
|
|
import com.dlc.chemical.camera.ISafetyCheck
|
|
import com.dlc.chemical.camera.ISafetyCheck
|
|
|
-import com.dlc.chemical.camera.MediaType
|
|
|
|
|
-import com.dlc.chemical.camera.OnMediaResultListener
|
|
|
|
|
-import com.dlc.chemical.camera.TakeVideoHelper
|
|
|
|
|
import com.dlc.chemical.common.CommonUtils
|
|
import com.dlc.chemical.common.CommonUtils
|
|
|
import com.dlc.chemical.databinding.ActivitySteelyardVideoBinding
|
|
import com.dlc.chemical.databinding.ActivitySteelyardVideoBinding
|
|
|
import com.dlc.chemical.iflytek.AudioPlayerManager
|
|
import com.dlc.chemical.iflytek.AudioPlayerManager
|
|
|
import com.dlc.chemical.serial.usb.steelyard.SteelyardHelper
|
|
import com.dlc.chemical.serial.usb.steelyard.SteelyardHelper
|
|
|
import com.dlc.chemical.serial.usb.steelyard.SteelyardManager
|
|
import com.dlc.chemical.serial.usb.steelyard.SteelyardManager
|
|
|
-import com.dlc.chemical.sp.CameraSp
|
|
|
|
|
-import com.dlc.chemical.sp.CameraType
|
|
|
|
|
import com.dlc.chemical.ui.MainActivity
|
|
import com.dlc.chemical.ui.MainActivity
|
|
|
import com.dlc.chemical.ui.dialog.InputWeightDialog
|
|
import com.dlc.chemical.ui.dialog.InputWeightDialog
|
|
|
import com.dlc.chemical.ui.dialog.SimpleTwoLinesDialog
|
|
import com.dlc.chemical.ui.dialog.SimpleTwoLinesDialog
|
|
@@ -26,8 +25,6 @@ import com.dlc.chemical.ui.widget.TitleBar
|
|
|
import com.rc.core.log.RcLog
|
|
import com.rc.core.log.RcLog
|
|
|
import com.rc.core.util.FastClickDelegate
|
|
import com.rc.core.util.FastClickDelegate
|
|
|
import com.rc.core.util.trimEndZero
|
|
import com.rc.core.util.trimEndZero
|
|
|
-import com.rc.httpcore.net.UploadTask
|
|
|
|
|
-import okhttp3.*
|
|
|
|
|
import java.math.BigDecimal
|
|
import java.math.BigDecimal
|
|
|
import java.math.RoundingMode
|
|
import java.math.RoundingMode
|
|
|
|
|
|
|
@@ -38,27 +35,13 @@ import java.math.RoundingMode
|
|
|
* @author ReiChin_
|
|
* @author ReiChin_
|
|
|
*/
|
|
*/
|
|
|
class SteelyardVideoActivity : BaseCountDownActivity<ActivitySteelyardVideoBinding>(),
|
|
class SteelyardVideoActivity : BaseCountDownActivity<ActivitySteelyardVideoBinding>(),
|
|
|
- TitleBar.TitleListener,
|
|
|
|
|
- ViewTreeObserver.OnGlobalLayoutListener,
|
|
|
|
|
- OnMediaResultListener {
|
|
|
|
|
|
|
+ TitleBar.TitleListener {
|
|
|
|
|
|
|
|
- companion object {
|
|
|
|
|
- private const val WHAT_RECORDING = 1
|
|
|
|
|
-
|
|
|
|
|
- private const val RECORDING_HEART = 300L
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // private val weakHandler by lazy { WeakReferenceHandler(this) }
|
|
|
|
|
private lateinit var mModuleEnum: ModuleEnum
|
|
private lateinit var mModuleEnum: ModuleEnum
|
|
|
private lateinit var mExtraParam: ExtraParam
|
|
private lateinit var mExtraParam: ExtraParam
|
|
|
private var mSteelyard = true
|
|
private var mSteelyard = true
|
|
|
private lateinit var mChemicalUnit: String
|
|
private lateinit var mChemicalUnit: String
|
|
|
|
|
|
|
|
- private var mISafetyCheck: ISafetyCheck? = null
|
|
|
|
|
- private var mVideoFilepath: String? = null // 录制的视频文件
|
|
|
|
|
- private var mVideoError = false
|
|
|
|
|
-
|
|
|
|
|
- private val mHandler = Handler()
|
|
|
|
|
override fun beforeSetContentView() {
|
|
override fun beforeSetContentView() {
|
|
|
mModuleEnum = intent.getSerializableExtra("moduleEnum") as ModuleEnum
|
|
mModuleEnum = intent.getSerializableExtra("moduleEnum") as ModuleEnum
|
|
|
mExtraParam = intent.getParcelableExtra("extraParam") as ExtraParam
|
|
mExtraParam = intent.getParcelableExtra("extraParam") as ExtraParam
|
|
@@ -78,8 +61,8 @@ class SteelyardVideoActivity : BaseCountDownActivity<ActivitySteelyardVideoBindi
|
|
|
|
|
|
|
|
viewBinding.steelyardImg.setImageResource(if (mSteelyard) R.mipmap.icon_dzc else R.mipmap.icon_rk_pzhxp)
|
|
viewBinding.steelyardImg.setImageResource(if (mSteelyard) R.mipmap.icon_dzc else R.mipmap.icon_rk_pzhxp)
|
|
|
|
|
|
|
|
- // 在布局结束后才做初始化操作
|
|
|
|
|
- viewBinding.previewView.viewTreeObserver.addOnGlobalLayoutListener(this)
|
|
|
|
|
|
|
+// // 在布局结束后才做初始化操作
|
|
|
|
|
+// viewBinding.previewView.viewTreeObserver.addOnGlobalLayoutListener(this)
|
|
|
|
|
|
|
|
// 重量
|
|
// 重量
|
|
|
viewBinding.weighingValue.setOnClickListener {
|
|
viewBinding.weighingValue.setOnClickListener {
|
|
@@ -101,7 +84,6 @@ class SteelyardVideoActivity : BaseCountDownActivity<ActivitySteelyardVideoBindi
|
|
|
|
|
|
|
|
// 取消
|
|
// 取消
|
|
|
viewBinding.cancel.setOnClickListener(FastClickDelegate {
|
|
viewBinding.cancel.setOnClickListener(FastClickDelegate {
|
|
|
- mISafetyCheck?.cancel()
|
|
|
|
|
finish()
|
|
finish()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -116,7 +98,7 @@ class SteelyardVideoActivity : BaseCountDownActivity<ActivitySteelyardVideoBindi
|
|
|
// AudioPlayerManager.speakVoice(R.raw.audio_weight_idle)
|
|
// AudioPlayerManager.speakVoice(R.raw.audio_weight_idle)
|
|
|
// thread = Thread(Runnable {
|
|
// thread = Thread(Runnable {
|
|
|
// RcLog.info("子线程播放语音")
|
|
// RcLog.info("子线程播放语音")
|
|
|
- AudioPlayerManager.speakVoice(R.raw.audio_weight_idle)
|
|
|
|
|
|
|
+ AudioPlayerManager.speakVoice(R.raw.audio_weight_idle)
|
|
|
// })
|
|
// })
|
|
|
} else {
|
|
} else {
|
|
|
// viewBinding.weighingTips.setText(R.string.weight_idle_hand)
|
|
// viewBinding.weighingTips.setText(R.string.weight_idle_hand)
|
|
@@ -138,18 +120,18 @@ class SteelyardVideoActivity : BaseCountDownActivity<ActivitySteelyardVideoBindi
|
|
|
private fun dispatchSaveClicked() {
|
|
private fun dispatchSaveClicked() {
|
|
|
if (verifySaveParam()) {
|
|
if (verifySaveParam()) {
|
|
|
handleSaveAction {
|
|
handleSaveAction {
|
|
|
- if (mVideoError) {
|
|
|
|
|
- showToast("视频录制出错,请返回重新操作。")
|
|
|
|
|
- return@handleSaveAction
|
|
|
|
|
- }
|
|
|
|
|
- if (mSteelyard) mSteelyardHelper.stopWeighing = true
|
|
|
|
|
- if (null == mVideoFilepath) {
|
|
|
|
|
- RcLog.info("clicked save button, then call stopRecording(), mISafetyCheck is null? ${null == mISafetyCheck}")
|
|
|
|
|
- mISafetyCheck?.stopRecording()
|
|
|
|
|
- } else {
|
|
|
|
|
- // 直接上传视频文件
|
|
|
|
|
- callUploadFile(mVideoFilepath!!)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// if (mVideoError) {
|
|
|
|
|
+// showToast("视频录制出错,请返回重新操作。")
|
|
|
|
|
+// return@handleSaveAction
|
|
|
|
|
+// }
|
|
|
|
|
+// if (mSteelyard) mSteelyardHelper.stopWeighing = true
|
|
|
|
|
+// if (null == mVideoFilepath) {
|
|
|
|
|
+// RcLog.info("clicked save button, then call stopRecording(), mISafetyCheck is null? ${null == mISafetyCheck}")
|
|
|
|
|
+// mISafetyCheck?.stopRecording()
|
|
|
|
|
+// } else {
|
|
|
|
|
+ // 直接上传视频文件
|
|
|
|
|
+ callUploadFile()
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -285,7 +267,7 @@ class SteelyardVideoActivity : BaseCountDownActivity<ActivitySteelyardVideoBindi
|
|
|
RcLog.info("[input] weight=${weight}, tareWeight=${mExtraParam.tareWeight}, netWeight=${netWeight}, joinType=${formatJoinType()}")
|
|
RcLog.info("[input] weight=${weight}, tareWeight=${mExtraParam.tareWeight}, netWeight=${netWeight}, joinType=${formatJoinType()}")
|
|
|
RcLog.info("参数$netWeight")
|
|
RcLog.info("参数$netWeight")
|
|
|
RcLog.info("参数{$mExtraParam.chemicalAmount}")
|
|
RcLog.info("参数{$mExtraParam.chemicalAmount}")
|
|
|
- RcLog.info("参数"+CommonUtils.stringParseFloat(mExtraParam.chemicalAmount))
|
|
|
|
|
|
|
+ RcLog.info("参数" + CommonUtils.stringParseFloat(mExtraParam.chemicalAmount))
|
|
|
if (netWeight > CommonUtils.stringParseFloat(mExtraParam.chemicalAmount)) {
|
|
if (netWeight > CommonUtils.stringParseFloat(mExtraParam.chemicalAmount)) {
|
|
|
showToast("化学品净重超过规格!")
|
|
showToast("化学品净重超过规格!")
|
|
|
return false
|
|
return false
|
|
@@ -361,101 +343,25 @@ class SteelyardVideoActivity : BaseCountDownActivity<ActivitySteelyardVideoBindi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
override fun onDestroy() {
|
|
|
- mRecordingHandler.removeMessages(WHAT_RECORDING)
|
|
|
|
|
- mISafetyCheck?.releaseCamera()
|
|
|
|
|
- mISafetyCheck = null
|
|
|
|
|
-// if (thread != null) {
|
|
|
|
|
-// thread = null
|
|
|
|
|
-// }
|
|
|
|
|
super.onDestroy()
|
|
super.onDestroy()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- override fun onGlobalLayout() {
|
|
|
|
|
- viewBinding.previewView.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
|
|
|
|
- if (null == mISafetyCheck) {
|
|
|
|
|
- val cameraId = CameraSp.loadConfig(this, CameraType.VIDEO)
|
|
|
|
|
- mISafetyCheck = TakeVideoHelper(
|
|
|
|
|
- this,
|
|
|
|
|
- viewBinding.previewView,
|
|
|
|
|
- cameraId
|
|
|
|
|
- ).apply {
|
|
|
|
|
- registerMediaResultListener(this@SteelyardVideoActivity)
|
|
|
|
|
- initCamera()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- viewBinding.previewView.postDelayed({
|
|
|
|
|
- viewBinding.recording.visibility = View.VISIBLE
|
|
|
|
|
- val message = mRecordingHandler.obtainMessage(WHAT_RECORDING, false)
|
|
|
|
|
- mRecordingHandler.sendMessageDelayed(message, RECORDING_HEART)
|
|
|
|
|
- mISafetyCheck?.capture()
|
|
|
|
|
- }, 500)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private val mRecordingHandler = object : Handler(Looper.getMainLooper()) {
|
|
|
|
|
-
|
|
|
|
|
- override fun handleMessage(msg: Message) {
|
|
|
|
|
- if (isDestroyed) return
|
|
|
|
|
-
|
|
|
|
|
- val visibility = msg.obj as? Boolean ?: false
|
|
|
|
|
- viewBinding.recording.visibility =
|
|
|
|
|
- if (visibility) View.VISIBLE else View.INVISIBLE
|
|
|
|
|
-
|
|
|
|
|
- val message = obtainMessage(WHAT_RECORDING, !visibility)
|
|
|
|
|
- sendMessageDelayed(message, RECORDING_HEART)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- override fun onMedia(filepath: String?, mediaType: MediaType, timeout: Boolean) {
|
|
|
|
|
- RcLog.info("onMedia() filepath=${filepath}, mediaType=${mediaType}, timeout=${timeout}")
|
|
|
|
|
-
|
|
|
|
|
- viewBinding.recording.visibility = View.GONE
|
|
|
|
|
- mRecordingHandler.removeMessages(WHAT_RECORDING)
|
|
|
|
|
-
|
|
|
|
|
- if (filepath.isNullOrEmpty()) {
|
|
|
|
|
- showToast("请重新拍摄!")
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- mVideoFilepath = filepath
|
|
|
|
|
- if (!timeout) callUploadFile(filepath)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private fun callUploadFile(filepath: String) {
|
|
|
|
|
|
|
+ private fun callUploadFile() {
|
|
|
// 开始上传:停止倒计时,避免在网络不好的情况下,未上传完成倒计时结束,关闭画面
|
|
// 开始上传:停止倒计时,避免在网络不好的情况下,未上传完成倒计时结束,关闭画面
|
|
|
stopCountDown()
|
|
stopCountDown()
|
|
|
|
|
+
|
|
|
if (isFinishing || isDestroyed) return
|
|
if (isFinishing || isDestroyed) return
|
|
|
|
|
|
|
|
- showLoading("上传中...")
|
|
|
|
|
- UploadTask({ progress ->
|
|
|
|
|
- showLoading("上传中...${progress}%")
|
|
|
|
|
- }, { data ->
|
|
|
|
|
- dismissLoading()
|
|
|
|
|
- // 化学品重量
|
|
|
|
|
- val weight =
|
|
|
|
|
- viewBinding.weighingValue.getTag(R.id.tag_join_weight) as String? ?: "0.0"
|
|
|
|
|
- // 入库方式(1 称重,2 录入)
|
|
|
|
|
- val joinType = viewBinding.weighingValue.getTag(R.id.tag_join_type) as String?
|
|
|
|
|
- val intent = Intent()
|
|
|
|
|
- intent.putExtra("weight", weight)
|
|
|
|
|
- intent.putExtra("joinType", joinType)
|
|
|
|
|
- intent.putExtra("remoteFileUrl", data.url)
|
|
|
|
|
- setResult(RESULT_OK, intent)
|
|
|
|
|
- finish()
|
|
|
|
|
- }, { throwable ->
|
|
|
|
|
- startCountDown()
|
|
|
|
|
- dismissLoading()
|
|
|
|
|
- throwable?.let {
|
|
|
|
|
- it.printStackTrace()
|
|
|
|
|
- showNetError(it)
|
|
|
|
|
- }
|
|
|
|
|
- }).execute(filepath)
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- override fun onError(message: String?) {
|
|
|
|
|
- mVideoError = true
|
|
|
|
|
- RcLog.info("视频录入错误${message}")
|
|
|
|
|
- showToast("视频录制出错,请返回重新操作。${message ?: ""}")
|
|
|
|
|
|
|
+ // 化学品重量
|
|
|
|
|
+ val weight = viewBinding.weighingValue.getTag(R.id.tag_join_weight) as String? ?: "0.0"
|
|
|
|
|
+ // 入库方式(1 称重,2 录入)
|
|
|
|
|
+ val joinType = viewBinding.weighingValue.getTag(R.id.tag_join_type) as String?
|
|
|
|
|
+ intent.putExtra("weight", weight)
|
|
|
|
|
+ intent.putExtra("joinType", joinType)
|
|
|
|
|
+// intent.putExtra("remoteFileUrl", data.url)
|
|
|
|
|
+ setResult(RESULT_OK, intent)
|
|
|
|
|
+ finish()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onHomeViewClicked(view: View) {
|
|
override fun onHomeViewClicked(view: View) {
|
|
@@ -463,7 +369,6 @@ class SteelyardVideoActivity : BaseCountDownActivity<ActivitySteelyardVideoBindi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onBackViewClicked(view: View) {
|
|
override fun onBackViewClicked(view: View) {
|
|
|
- mISafetyCheck?.cancel()
|
|
|
|
|
finish()
|
|
finish()
|
|
|
}
|
|
}
|
|
|
|
|
|