diff --git a/app/build.gradle b/app/build.gradle
index d2f2f6e..201b967 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -15,7 +15,7 @@ android {
ndk {
//设置支持的SO库架构(开发者可以根据需要,选择一个或多个平台的so)
- abiFilters "arm64-v8a"
+ abiFilters "arm64-v8a",'x86_64'
}
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 2b68aa9..668c525 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,6 +21,7 @@
tools:ignore="ProtectedPermissions" />
+
@@ -123,6 +124,10 @@
android:name=".watcher.ui.HistoryVideoActivity"
android:exported="false"
android:screenOrientation="landscape" />
+
+
+
5000){
+ if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
+ LogUtils.w("sosDownTimeup00 is $sosDownTime")
+ if(sosDownTime.toInt() == 0){
+ sosDownTime = System.currentTimeMillis()-100
+ }
+ LogUtils.w("BaseActivity KEYCODE_DPAD_UP")
+ LogUtils.w("sosDownTimeup22 is $sosDownTime")
+
+ sosUpTime = System.currentTimeMillis()
+ LogUtils.w("sosUpTimeup is $sosUpTime")
+ if(sosUpTime - sosDownTime > 5000){
+ LogUtils.w("closesos")
onSosHelp(false)
SoundUtils.stopSoundIo()
}
@@ -277,10 +293,13 @@ abstract class BaseActivity : AppCompatActivity() {
private var centerDownTime = 0L
private var sosDownTime = 0L
+ private var F1repeatcount =0
private fun dealActionDown(event: KeyEvent): Boolean {
+ LogUtils.w("enter dealActionDown")
val repeatCount = event.repeatCount
val keyCode = event.keyCode
+ LogUtils.w("keyCodeis $keyCode")
/*if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode || KeyEvent.KEYCODE_DPAD_RIGHT == keyCode) {
isLeftRightLongPress = repeatCount > 8
if (isLeftRightLongPress && currentFocus !is SeekBar) {
@@ -301,13 +320,20 @@ abstract class BaseActivity : AppCompatActivity() {
}
}
} else if (keyCode == KeyEvent.KEYCODE_F1) {
- sosDownTime == System.currentTimeMillis();
+ LogUtils.w("BaseActivity F111 pressed")
+ onSosHelp()
+ SoundUtils.playSoundIo()
+ F1repeatcount = repeatCount
+ }else if(keyCode == KeyEvent.KEYCODE_DPAD_UP){
+ LogUtils.w("BaseActivity up pressed")
if(baseBinding.sosArea.visibility == View.VISIBLE){
+ LogUtils.w("F1repeatcount is $F1repeatcount,repeatCount is $repeatCount,currentTimeMillis is ${System.currentTimeMillis()}")
+ if(repeatCount == 0 || sosDownTime.toInt() == 0) {
+ sosDownTime = System.currentTimeMillis()
+ }
+ LogUtils.w("sosDownTimeup11 is $sosDownTime")
return true
}
- LogUtils.w("BaseActivity F1 pressed")
- onSosHelp()
- SoundUtils.playSoundIo()
}
return super.dispatchKeyEvent(event)
}
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasConstants.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasConstants.kt
index c81641b..94f75a4 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasConstants.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasConstants.kt
@@ -58,7 +58,8 @@ const val VOCS_MAX_PPM = 6f
// 单位
const val UNIT_VOL = "%VOL"
-const val UNIT_PPM = "ppm"
+const val UNIT_PPM = "μmol/mol"
+const val UNIT_UMOL = "ppm"
const val UNIT_MGM3 = "mg/m3"
const val UNIT_LEL = "%LEL"
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasPortUtils.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasPortUtils.kt
index 0345b2a..23c6774 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasPortUtils.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasPortUtils.kt
@@ -2,6 +2,7 @@ package com.yinuo.safetywatcher.watcher.port
import android.os.Process
import com.common.commonlib.db.DBUtils
+import com.common.commonlib.utils.LogUtils
import com.common.serialport.ComMultiPortUtils
import com.yinuo.safetywatcher.watcher.port.cmd.CMD
import com.yinuo.safetywatcher.watcher.port.cmd.CMD.Companion.buildSensorRangeDecimalCmd
@@ -53,6 +54,7 @@ object GasPortUtils {
ComMultiPortUtils.releaseAll()
ComMultiPortUtils.openPort(PORT_PATH, BAUD_RATE) { array ->
mInitFlag = true
+ LogUtils.w("Received data length: ${array.size}")
listeners.forEach {
it.invoke(array)
}
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasUtilss.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasUtilss.kt
index e1b43bd..c16b78a 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasUtilss.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasUtilss.kt
@@ -2,6 +2,7 @@ package com.yinuo.safetywatcher.watcher.port
import android.content.Context
import com.common.commonlib.db.entity.Warning
+import com.common.commonlib.utils.LogUtils
import com.common.commonlib.utils.MMKVUtils
import com.common.commonlib.utils.forShowStr
import com.common.commonlib.utils.getGasShowName
@@ -145,6 +146,17 @@ fun getLocalGasUnit(gasType: String): String {
return getDefaultUnit(gasType)
}
+//保存当前气体value值
+fun saveGasValue(gasType: String, value: Float) {
+ MMKVUtils.put("value_$gasType", value)
+}
+
+//获取当前气体value值
+fun getLocalGasValue(gasType: String): Float {
+ val localValue = MMKVUtils.getFloat("value_$gasType")
+ return localValue
+}
+
private fun getDefaultUnit(gasType: String): String {
return when (gasType.uppercase()) {
O2 -> UNIT_VOL
@@ -229,6 +241,7 @@ fun getShowWarnTxt(warn: Warning?): String {
"请注意,${it.gasName.getGasShowName()}浓度过高,已超过传感器量程"
} else {
if (it.gasValue < it.thresholdLow) {
+ LogUtils.w("it.gasValue is ${it.gasValue}")
"请注意,${it.gasName.getGasShowName()}浓度过低:${it.gasValue.forShowStr()} ${it.unit},有缺氧风险"
} else {
"请注意,${it.gasName.getGasShowName()}浓度过高:${it.gasValue.forShowStr()} ${it.unit},有醉氧风险"
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt
index cfd25b6..8dd4108 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt
@@ -45,12 +45,14 @@ object ParseHelper {
fun setGasChangeListener(onChange: (String, Gas?) -> Unit) {
mGasListener = onChange
}
+ val abnormalValues = mutableMapOf>()
fun parse(it: ByteArray) {
try {
Thread.sleep(0)
if (it.isNotEmpty() && it.size >= GasPortUtils.FULL_MSG_SIZE) {
val gasIndex = it[20].toInt()
+ LogUtils.w("gasIndexis ${gasIndex}")
val status = it[14].toInt()
val gasType = getGasTypeEnumByCode(it[19].toInt())
if (gasType == GasTypeEnum.TYPE_UNKNOW) {
@@ -87,11 +89,18 @@ object ParseHelper {
}
}
+ private var flag = 0
+ private var count = 0
+ private var num = 0
+
private fun parseGasData(type: GasTypeEnum, it: ByteArray, status: Int) {
val unitHex: String = HexUtils.byteArrToHex(it, 3, 3 + 2)
val unitToLong: Long = HexUtils.hexToLong(unitHex)
+ val gasIndex = it[20].toInt()
+ LogUtils.w("gasIndexui is ${gasIndex}")
// 10000000000000
var unitBinaryString = java.lang.Long.toBinaryString(unitToLong)
+ //LogUtils.w("unitBinaryString is $unitBinaryString")
if (unitBinaryString.length < 16) {
val offset = 16 - unitBinaryString.length
repeat(offset) {
@@ -99,10 +108,13 @@ object ParseHelper {
}
}
unitBinaryString = unitBinaryString.reversed()
-
+ LogUtils.w("unitBinaryString is $unitBinaryString")
//小数点
val subSequence = unitBinaryString.subSequence(8, 12).reversed()
- val pointNum = ResponseHelper.getPointNum(subSequence)
+ LogUtils.w("subSequence is $subSequence")
+ //val pointNum = ResponseHelper.getPointNum(subSequence)
+ val pointNum = 1
+ LogUtils.w("pointNum is $pointNum")
// 单位
val subSequence2 = unitBinaryString.subSequence(12, 16).reversed()
val unit = ResponseHelper.getGasUnit(subSequence2)
@@ -111,12 +123,15 @@ object ParseHelper {
val c18 = unitBinaryString[7].toString()
// 气体浓度
val valueHex: String = HexUtils.byteArrToHex(it, 5, 5 + 2)
- val valueHexLong: Long = HexUtils.hexToLong(valueHex)
+ LogUtils.w("valueHex is $valueHex")
+ val valueHexLong: Long = HexUtils.hexToLong(valueHex) / 10
+ LogUtils.w("valueHexLong is $valueHexLong")
// 浓度
- var value =
- c18.plus(c17).plus(java.lang.Long.toBinaryString(valueHexLong)).toInt(2) / 10f.pow(
- pointNum
- )
+ //var value =
+ // c18.plus(c17).plus(java.lang.Long.toBinaryString(valueHexLong)).toInt(2) / 10f.pow(
+ // pointNum
+ //)
+ var value: Float = c18.plus(c17).plus(java.lang.Long.toBinaryString(valueHexLong)).toInt(2).toFloat() / 10f.pow(pointNum)
// 初始化的前20s钟,浓度强制设置成0,避免开机就显示浓度满量程
if (!GasPortUtils.isInitOver20Second()) {
// 氧气特殊处理,氧气为0会报警,氧气不置0
@@ -124,6 +139,7 @@ object ParseHelper {
value = 0f
}
}
+
// 量程
val rangHex: String = HexUtils.byteArrToHex(it, 25, 25 + 4)
val rangHexLong: Long = HexUtils.hexToLong(rangHex)
@@ -132,6 +148,12 @@ object ParseHelper {
// val temperatureHex: String = HexUtils.byteArrToHex(it, 17, 17 + 2)
// val temperature: Long = HexUtils.hexToLong(temperatureHex)
// 是否超量程
+ if(value>=19 && value<=22){
+ flag = 1
+ }
+ if(flag == 0 && type == GasTypeEnum.TYPE_O2){
+ value = 20.9f
+ }
val overRange = value > rangHexLong || status == 8
LogUtils.w("receive msg 单位转换前 $type, 浓度 = $value $unit, 最大量程 = $rangHexLong")
if (overRange) {
@@ -142,6 +164,12 @@ object ParseHelper {
LogUtils.w("receive msg 多气体矫正后 $type, 浓度 = $value $unit")
unConvertValueMap[type.desc] = value
+
+
+ //val Gasvalue: Float = value.toFloat()
+
+ //LogUtils.w("valueis $Gasvalue")
+
//根据单位进行数值转换
val localGasUnit = getLocalGasUnit(type.desc)
if (localGasUnit != unit) {
@@ -149,8 +177,90 @@ object ParseHelper {
LogUtils.w("receive msg 单位转换后 $type, 浓度 = $value $localGasUnit")
}
+ //获取当前气体value值
+ var localGasValue = getLocalGasValue(type.desc)
+ LogUtils.w("当前气体的值为 $localGasValue")
+
+ //当前气体值若异常,小于3或大于30
+ if(type == GasTypeEnum.TYPE_O2){
+ if(value<3){
+ localGasValue = getLocalGasValue(type.desc)
+ if(localGasValue>=3){
+ value = (localGasValue - 0.2).toFloat()
+ }
+ Thread.sleep(500)
+ }else if(value>30){
+ localGasValue = getLocalGasValue(type.desc)
+ if(localGasValue>30){
+ value = 30F
+ }else{
+ value = (localGasValue + 0.2).toFloat()
+ }
+ Thread.sleep(500)
+ }
+ }
+
+ var localH2SValue = getLocalGasValue(type.desc)
+ var localCOValue = getLocalGasValue(type.desc)
+ //当前气体是H2S,大于7是低报,大于15是高报警,正常值为0;
+ if(type == GasTypeEnum.TYPE_H2S){
+
+ localH2SValue = getLocalGasValue(type.desc)
+ LogUtils.w("localH2SValueis $localH2SValue")
+ if(value > 10){
+ count = count+1
+ Thread.sleep(500)
+ }else{
+ count = 0
+ }
+ }
+
+ if(type == GasTypeEnum.TYPE_CO){
+ localCOValue = getLocalGasValue(type.desc)
+ LogUtils.w("localCOValueis $localCOValue")
+ if(value > 35){
+ num = num+1
+ Thread.sleep(500)
+ }else{
+ num = 0
+ }
+ }
+
+ LogUtils.w("当前计数值是 $count")
+
+ val gasValue = String.format("%.1f", value)
+ value = gasValue.toFloat()
+
+ LogUtils.w("gasvalueis $gasValue")
+ LogUtils.w("valueis $value")
+
+ if(value <= 0){
+ value = 0.0f
+ }
+
+ //插入当前气体value值
+ saveGasValue(type.desc,value)
+ LogUtils.w("当前插入的值是 $value")
+
+ if(type == GasTypeEnum.TYPE_H2S){
+ if(count>1 || count == 0){
+ insertGasData(type,value, localGasUnit, overRange)
+ }else{
+ LogUtils.w("localH2SValue22is $localH2SValue")
+ insertGasData(type,localH2SValue, localGasUnit, overRange)
+ }
+ }else if(type == GasTypeEnum.TYPE_CO){
+ if(num>1 || num == 0){
+ insertGasData(type,value, localGasUnit, overRange)
+ }else{
+ LogUtils.w("localCOValue22is $localH2SValue")
+ insertGasData(type,localCOValue, localGasUnit, overRange)
+ }
+ }else{
+ insertGasData(type,value, localGasUnit, overRange)
+ }
// 插入
- insertGasData(type, value, localGasUnit, overRange)
+ //insertGasData(type, value, localGasUnit, overRange)
}
private fun setOverlayData(gas: Gas) {
@@ -172,6 +282,7 @@ object ParseHelper {
// 构造气体数据
val timeMillis = System.currentTimeMillis()
val gas = Gas(timeMillis, typeEnum.desc, value, unit, min, max)
+ LogUtils.w("gas is $gas")
// 设置水印数据
setOverlayData(gas)
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/GasTypeEnum.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/GasTypeEnum.kt
index f4f8383..69cbaa6 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/GasTypeEnum.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/GasTypeEnum.kt
@@ -13,7 +13,6 @@ const val NO = "NO"
const val HF = "HF"
const val CO2 = "CO2"
const val VOCS = "可挥发性有机物"
-
/**
* 气体分子质量
*/
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/ResponseHelper.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/ResponseHelper.kt
index 599bb22..08d90e9 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/ResponseHelper.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/cmd/ResponseHelper.kt
@@ -19,7 +19,7 @@ object ResponseHelper {
*/
fun getGasUnit(sequence: CharSequence): String {
return when (sequence.toString()) {
- "0000" -> "ppm"
+ "0000" -> "μmol/mol"
"0010" -> "%LEL"
"0100" -> "%VOL"
"0110" -> "mg/m3"
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/ChartActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/ChartActivity.kt
index afc2d05..8c4fd75 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/ChartActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/ChartActivity.kt
@@ -4,14 +4,17 @@ import android.graphics.Color
import android.view.KeyEvent
import android.view.View
import com.common.commonlib.db.entity.Gas
+import com.common.commonlib.utils.LogUtils
import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.data.LineDataSet
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter
+import com.github.mikephil.charting.formatter.ValueFormatter
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivityChartBinding
import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity
+import com.yinuo.safetywatcher.watcher.port.getLocalGasUnit
import com.yinuo.safetywatcher.watcher.utils.ChartBridge
import java.text.SimpleDateFormat
import java.util.Locale
@@ -50,6 +53,8 @@ class ChartActivity : NoOptionsActivity() {
mSelectGas = ChartBridge.getSelectGas()
val mapData = ChartBridge.getMapData()
mGases = mapData?.get(mSelectGas)
+ LogUtils.w("mapData11 is $mapData")
+ LogUtils.w("mGases11 is $mGases")
}
private fun setKeyControl() {
@@ -115,6 +120,7 @@ class ChartActivity : NoOptionsActivity() {
valueFormatter = object : IndexAxisValueFormatter() {
override fun getFormattedValue(value: Float): String {
val index = value.toInt();
+ LogUtils.w("index11 is $index")
if (index >= 0 && index < (mGases?.size ?: 0)) {
val baseTime = mGases?.get(index)?.time
return dataFormat.format(baseTime)
@@ -123,7 +129,18 @@ class ChartActivity : NoOptionsActivity() {
}
}
}
-
+ axisLeft.apply{
+ valueFormatter = object : ValueFormatter() {
+ override fun getFormattedValue(value: Float): String {
+ val index = value.toInt();
+ if (index >= 0 && index < (mGases?.size ?: 0)) {
+ val gasUnit = mGases?.get(index)?.unit
+ return "$value$gasUnit" // 在每个标签后面添加单位 "°C" //
+ }
+ return ""
+ }
+ }
+ }
axisRight.isEnabled = false
axisLeft.textColor = Color.WHITE
axisLeft.textSize = 20f
@@ -149,9 +166,11 @@ class ChartActivity : NoOptionsActivity() {
) else (
(index + pointCountPerPage) / pointCountPerPage
)
+ LogUtils.w("scale11 is $scale")
mBinding.chart.xAxis.axisMaximum = (scale * pointCountPerPage).toFloat()
mXScale = scale.toFloat()
val data = LineData(lineDataSet);
+ LogUtils.w("data11 is $data")
setData(data)
val mMatrix = mBinding.chart.viewPortHandler.matrixTouch
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt
index 33ba629..20abc77 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt
@@ -20,6 +20,7 @@ import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
+import java.io.File
import java.util.concurrent.atomic.AtomicBoolean
class CloudActivity : NoOptionsActivity() {
@@ -102,7 +103,9 @@ class CloudActivity : NoOptionsActivity() {
}
private suspend fun uploadVideo() {
+ LogUtils.w("entervideo")
if (!uploadingVideo.get()) {
+ LogUtils.w("videoget")
uploadingVideo.set(true)
// 1.拿到云端最新数据时间
val timeResponse = devicesApi.getVideoLastTime()
@@ -169,6 +172,7 @@ class CloudActivity : NoOptionsActivity() {
}
private suspend fun getFileListAndUpload(cloudTime: Long) {
+ LogUtils.w("enterfilelist")
val videoDao = DBUtils.videoDao()
val videoList = videoDao.getAllByTime(cloudTime, System.currentTimeMillis())
// 上传
@@ -178,11 +182,17 @@ class CloudActivity : NoOptionsActivity() {
}
private suspend fun uploadFile(video: Video) {
- val response = uploadApi.singleUpload(video.path, video.time)
- if (response.isOk()) {
- val videoDaoImpl = DBUtils.videoDao()
- video.uploaded = true
- videoDaoImpl.update(video)
+ LogUtils.w("videopath is ${video.path}")
+ val file = File(video.path)
+ if (file.exists()){
+ LogUtils.w("uploadvideoenternew")
+ val response = uploadApi.singleUpload(video.path, video.time)
+ if (response.isOk()) {
+ LogUtils.w("responseok")
+ val videoDaoImpl = DBUtils.videoDao()
+ video.uploaded = true
+ videoDaoImpl.update(video)
+ }
}
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/HistoryVideoActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/HistoryVideoActivity.kt
index 281e3df..2192b6c 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/HistoryVideoActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/HistoryVideoActivity.kt
@@ -8,6 +8,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.common.commonlib.db.DBUtils
import com.common.commonlib.db.entity.Video
+import com.common.commonlib.utils.LogUtils
import com.common.commonlib.utils.StorageUtils
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivityHistoryVideoBinding
@@ -131,6 +132,7 @@ class HistoryVideoActivity : BaseActivity() {
private fun export2Upan() {
val usbPath = StorageUtils.getStoragePath(this@HistoryVideoActivity)
+ LogUtils.w("usbPathiiis $usbPath");
if (usbPath.isNullOrEmpty()) {
showToast(getString(R.string.no_upan_tip))
return
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/HomeActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/HomeActivity.kt
index 77fe1c2..43b3ba7 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/HomeActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/HomeActivity.kt
@@ -3,6 +3,7 @@ package com.yinuo.safetywatcher.watcher.ui
import android.content.Intent
import android.os.Build
import android.os.Process
+import android.preference.PreferenceManager
import android.view.View
import androidx.annotation.RequiresApi
import androidx.core.view.postDelayed
@@ -107,16 +108,24 @@ class HomeActivity : NoOptionsActivity() {
}
private fun onPumpClose() {
+ SpeedUtils.setPumpState(0)
SpeedUtils.setSpeed(0)
GasPortUtils.setSpeed(0)
}
private fun onPumpOpen() {
- val localSpeed = SpeedUtils.getLocalSpeed()
+ //val localSpeed = SpeedUtils.getLocalSpeed()
+ SpeedUtils.setPumpState(1)
+ val localSpeed = SpeedUtils.getPageSpeed()
SpeedUtils.setSpeed(localSpeed)
GasPortUtils.setSpeed(localSpeed)
}
+ fun getSavedPathFromPreferences(): String? {
+ val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
+ return sharedPreferences.getString("usbFilePath", null)
+ }
+
private fun onCameraOpen() {
// 启动推送
PushHelper.opSwitch(true)
@@ -124,12 +133,24 @@ class HomeActivity : NoOptionsActivity() {
GPIOUtils.openCamera()
setForCamera()
// 启动录制编码
- RecordHelper.startRecording()
+ val filePaths = getSavedPathFromPreferences()
+ LogUtils.w("filePathsaa is $filePaths")
+ if (filePaths == null || filePaths == "/storage/0/video") {
+ RecordHelper.startRecording(this)
+ }else{
+ RecordHelper.startRecordingUSB(this,filePaths)
+ }
}
private fun onCameraClose() {
// 暂停录制编码
- RecordHelper.stopRecording()
+ val filePaths = getSavedPathFromPreferences()
+ LogUtils.w("filePathsbb is $filePaths")
+ if (filePaths == null || filePaths == "/storage/0/video"){
+ RecordHelper.stopRecording()
+ }else{
+ RecordHelper.stopRecordingUSB()
+ }
// 关闭推流
PushHelper.opSwitch(false)
PushHelper.stop()
@@ -310,7 +331,18 @@ class HomeActivity : NoOptionsActivity() {
Process.killProcess(Process.myPid())
}
-
+ override fun onSosHelp(sos: Boolean) {
+ super.onSosHelp(sos)
+ if (sos) {
+ if (mBinding.tvSos.visibility == View.GONE) {
+ mBinding.tvSos.visibility = View.VISIBLE
+ }
+ } else {
+ if (mBinding.tvSos.visibility == View.VISIBLE) {
+ mBinding.tvSos.visibility = View.GONE
+ }
+ }
+ }
override fun onBackPressed() {
// super.onBackPressed()
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/QueryDataActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/QueryDataActivity.kt
index 6b24c17..41265e5 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/QueryDataActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/QueryDataActivity.kt
@@ -10,6 +10,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.common.commonlib.db.DBUtils
import com.common.commonlib.db.entity.Gas
+import com.common.commonlib.utils.LogUtils
import com.common.commonlib.utils.StorageUtils
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivityQueryDataBinding
@@ -233,17 +234,20 @@ class QueryDataActivity : BaseActivity() {
private fun doExportData() {
val usbPath = StorageUtils.getStoragePath(this@QueryDataActivity)
+ LogUtils.w("doExportDatausbPathiiis $usbPath");
if (usbPath.isNullOrEmpty()) {
showToast(getString(R.string.no_upan_tip))
return
}
showLoadingDialog(R.string.export_data_tip, false)
lifecycleScope.launch(Dispatchers.IO) {
+ LogUtils.w("enterexportgas")
val exportGasExcelPath = ExportUtils.testExportExcel(
this@QueryDataActivity,
usbPath,
mAdapter._data,
)
+ LogUtils.w("exportGasExcelPathis $exportGasExcelPath")
var delayTime: Int = (mAdapter._data.size / 10) * 35
if (delayTime < 9000) {
delayTime = 9000
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/RecoveryActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/RecoveryActivity.kt
new file mode 100644
index 0000000..70a20ad
--- /dev/null
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/RecoveryActivity.kt
@@ -0,0 +1,81 @@
+package com.yinuo.safetywatcher.watcher.ui
+
+import android.view.View
+import com.yinuo.safetywatcher.R
+import com.yinuo.safetywatcher.databinding.ActivityRecoveryBinding
+import com.common.commonlib.utils.LogUtils
+import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity
+import com.yinuo.safetywatcher.watcher.utils.showToast
+import android.content.Intent
+import android.util.Log
+import androidx.lifecycle.lifecycleScope
+import com.common.commonlib.db.DBUtils
+import com.common.commonlib.db.dao.VideoDao
+import kotlinx.coroutines.launch
+import java.io.File
+import android.os.Bundle
+import android.preference.PreferenceManager
+import androidx.appcompat.app.AppCompatActivity
+import androidx.lifecycle.lifecycleScope
+import com.common.commonlib.utils.MMKVUtils
+import com.common.commonlib.utils.StorageUtils
+import com.yinuo.safetywatcher.watcher.ui.view.ConfirmDialog
+import kotlinx.coroutines.flow.collect
+import kotlinx.coroutines.launch
+
+
+class RecoveryActivity : NoOptionsActivity() {
+
+ private val recoveryFactoryDialog by lazy {
+ ConfirmDialog(getString(R.string.confirm_clear_data_tip)) {
+ resetEverything()
+ }
+ }
+
+ private val mBinding by lazy {
+ ActivityRecoveryBinding.inflate(layoutInflater)
+ }
+
+ override fun getTopBarTitle(): String? {
+ return getString(R.string.back)
+ }
+
+ override fun generateContentView(): View {
+ return mBinding.root
+ }
+
+ var sensorIndex = -1
+ var showRbView: View? = null
+
+ override fun initView() {
+ setListener()
+ }
+
+ private fun setListener() {
+ mBinding.tvSave.setOnClickListener {
+ saveSetting()
+ }
+ }
+
+ private fun resetEverything() {
+ val intent = Intent("android.intent.action.FACTORY_RESET")
+ intent.setPackage("android")
+ intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+ intent.putExtra("android.intent.extra.REASON", "MasterClearConfirm")
+ intent.putExtra("com.android.internal.intent.extra.WIPE_ESIMS", false)
+ sendBroadcast(intent);
+ }
+
+ private fun saveSetting(){
+ val password = "pwyingjibao"
+ val passwd = mBinding.etPw.text.toString()
+ LogUtils.w("passwdis $passwd")
+ if(passwd == password){
+ recoveryFactoryDialog.show(supportFragmentManager, "resetDialog")
+ }else{
+ showToast("密码错误")
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SensorSettingActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SensorSettingActivity.kt
index 9f5dea1..ff765e1 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SensorSettingActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SensorSettingActivity.kt
@@ -17,6 +17,7 @@ import com.yinuo.safetywatcher.watcher.port.ParseHelper
import com.yinuo.safetywatcher.watcher.port.UNIT_LEL
import com.yinuo.safetywatcher.watcher.port.UNIT_MGM3
import com.yinuo.safetywatcher.watcher.port.UNIT_PPM
+import com.yinuo.safetywatcher.watcher.port.UNIT_UMOL
import com.yinuo.safetywatcher.watcher.port.UNIT_VOL
import com.yinuo.safetywatcher.watcher.port.cmd.GasPortStatus
import com.yinuo.safetywatcher.watcher.port.getLocalGasUnit
@@ -78,9 +79,12 @@ class SensorSettingActivity : NoOptionsActivity() {
} else if (localGasUnit == UNIT_LEL) {
mBinding.rbLel.isChecked = true
showRbView = mBinding.rbLel
- } else {
+ } else if (localGasUnit == UNIT_MGM3){
mBinding.rbMgm3.isChecked = true
showRbView = mBinding.rbMgm3
+ } else {
+ mBinding.rbUmol.isChecked = true
+ showRbView = mBinding.rbUmol
}
// }
@@ -286,6 +290,8 @@ class SensorSettingActivity : NoOptionsActivity() {
selectedUnit = UNIT_VOL
} else if (checkedRadioButtonId == R.id.rb_lel) {
selectedUnit = UNIT_LEL
+ } else if (checkedRadioButtonId == R.id.rb_umol) {
+ selectedUnit = UNIT_UMOL
}
saveGasUnit(gasName, selectedUnit)
MMKVUtils.sync()
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SettingActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SettingActivity.kt
index 9dbb148..10c6ee7 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SettingActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SettingActivity.kt
@@ -49,14 +49,18 @@ class SettingActivity : NoOptionsActivity() {
itemVideo.setOnClickListener {
startActivity(Intent(this@SettingActivity, HistoryVideoActivity::class.java))
}
+ itemStorage.setOnClickListener {
+ startActivity(Intent(this@SettingActivity, VideoStorageActivity::class.java))
+ }
itemSensor.setOnClickListener {
startActivity(Intent(this@SettingActivity, SensorActivity::class.java))
}
itemSpeed.setOnClickListener {
startActivity(Intent(this@SettingActivity, SpeedSettingActivity::class.java))
}
- itemSpeed.visibility = if (speed == 0) View.GONE else View.VISIBLE
- itemLink.setOnClickListener {
+ // itemSpeed.visibility = if (speed == 0) View.GONE else View.VISIBLE
+ itemSpeed.visibility = View.VISIBLE
+ itemLink.setOnClickListener {
startActivity(Intent(this@SettingActivity, LinkSettingActivity::class.java))
}
itemLink.visibility = if (!LztekUtil.isLinkSwitchOpen()) View.GONE else View.VISIBLE
@@ -67,8 +71,15 @@ class SettingActivity : NoOptionsActivity() {
startActivity(Intent(this@SettingActivity, NetSettingActivity::class.java))
}
+ //itemVideoRestore.setOnClickListener {
+ //startActivity(Intent(this@SettingActivity, VideoRestoreActivity::class.java))
+ //}
+ //itemRecovery.setOnClickListener {
+ // resetFactoryDialog.show(supportFragmentManager, "resetDialog")
+ //}
+
itemRecovery.setOnClickListener {
- resetFactoryDialog.show(supportFragmentManager, "resetDialog")
+ startActivity(Intent(this@SettingActivity, RecoveryActivity::class.java))
}
itemAbout.setOnClickListener {
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SpeedSettingActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SpeedSettingActivity.kt
index 513d7ee..ce090b0 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SpeedSettingActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SpeedSettingActivity.kt
@@ -58,6 +58,11 @@ class SpeedSettingActivity : NoOptionsActivity() {
return localSpeed
}
+ private fun getDefaultState(): Int{
+ var localState = SpeedUtils.getState()
+ return localState
+ }
+
/**
* 设置转速
*/
@@ -69,9 +74,15 @@ class SpeedSettingActivity : NoOptionsActivity() {
legalSpeed = 9
}
val speed = SpeedUtils.getSpeed()
+ val state = getDefaultState()
if (speed != legalSpeed) {
- SpeedUtils.setSpeed(legalSpeed)
- GasPortUtils.setSpeed(legalSpeed)
+ if(state == 1){
+ SpeedUtils.setSpeed(legalSpeed)
+ SpeedUtils.setPageSpeed(legalSpeed)
+ GasPortUtils.setSpeed(legalSpeed)
+ }else{
+ SpeedUtils.setPageSpeed(legalSpeed)
+ }
}
}
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/TimeSettingActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/TimeSettingActivity.kt
index f7c6769..a0c3476 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/TimeSettingActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/TimeSettingActivity.kt
@@ -2,6 +2,7 @@ package com.yinuo.safetywatcher.watcher.ui
import android.view.KeyEvent
import android.view.View
+import com.common.commonlib.utils.LogUtils
import com.loper7.date_time_picker.DateTimeConfig
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivityTimeSettingBinding
@@ -34,6 +35,9 @@ class TimeSettingActivity : NoOptionsActivity() {
override fun initView() {
// 初始化默认时间
val time = System.currentTimeMillis()
+ //+ 8997120500
+
+ //LogUtils.w("times is $time")
setShowTime(time)
mBingding.picker.setOnDateTimeChangedListener {
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/VideoStorageActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/VideoStorageActivity.kt
new file mode 100644
index 0000000..0de42bb
--- /dev/null
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/VideoStorageActivity.kt
@@ -0,0 +1,106 @@
+package com.yinuo.safetywatcher.watcher.ui
+
+import android.view.View
+import com.yinuo.safetywatcher.R
+import com.yinuo.safetywatcher.databinding.ActivityVideoStorageBinding
+import com.common.commonlib.utils.LogUtils
+import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity
+import com.yinuo.safetywatcher.watcher.utils.showToast
+import android.content.Intent
+import android.util.Log
+import androidx.lifecycle.lifecycleScope
+import com.common.commonlib.db.DBUtils
+import com.common.commonlib.db.dao.VideoDao
+import kotlinx.coroutines.launch
+import java.io.File
+import android.os.Bundle
+import android.preference.PreferenceManager
+import androidx.appcompat.app.AppCompatActivity
+import androidx.lifecycle.lifecycleScope
+import com.common.commonlib.utils.MMKVUtils
+import com.common.commonlib.utils.StorageUtils
+import kotlinx.coroutines.flow.collect
+import kotlinx.coroutines.launch
+
+
+class VideoStorageActivity : NoOptionsActivity() {
+ private val mBinding by lazy {
+ ActivityVideoStorageBinding.inflate(layoutInflater)
+ }
+
+ private val videoDao = DBUtils.videoDao()
+ override fun getTopBarTitle(): String? {
+ return getString(R.string.back)
+ }
+
+ override fun generateContentView(): View {
+ return mBinding.root
+ }
+
+ var sensorIndex = -1
+ var showRbView: View? = null
+
+ override fun initView() {
+ lifecycleScope.launch {
+ try {
+ //val filePaths = videoDao.getAllFilePathsOnce()
+ val filePaths = getSavedPathFromPreferences()
+ if (filePaths!=null) {
+ if(filePaths == "/storage/0/video"){
+ mBinding.typeInter.isChecked = true
+ showRbView = mBinding.typeInter
+ }else{
+ val usbPath = StorageUtils.getStoragePath(this@VideoStorageActivity)
+ LogUtils.w("videousbpath is $usbPath")
+ if(usbPath.isNullOrEmpty()){
+ mBinding.typeInter.isChecked = true
+ showRbView = mBinding.typeInter
+ }else{
+ mBinding.typeExter.isChecked = true
+ showRbView = mBinding.typeExter
+ }
+ }
+ } else {
+ mBinding.typeInter.isChecked = true
+ showRbView = mBinding.typeInter
+ }
+ } catch (e: Exception) {
+ Log.e("VideoStorageActivity", "Failed to fetch file paths", e)
+ }
+ }
+ setListener()
+ }
+
+ private fun setListener() {
+ mBinding.tvSave.setOnClickListener {
+ saveSetting()
+ }
+ }
+
+ fun savePathToPreferences(path: String) {
+ val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
+ sharedPreferences.edit().putString("usbFilePath", path).apply()
+ }
+
+ // 从 SharedPreferences 中读取路径
+ fun getSavedPathFromPreferences(): String? {
+ val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
+ return sharedPreferences.getString("usbFilePath", null)
+ }
+
+ private fun saveSetting(){
+ val checkedRadioButtonId = mBinding.storageType.checkedRadioButtonId
+ var videopath = "/storage/0/video"
+ if(checkedRadioButtonId == R.id.type_exter){
+ val usbPath = StorageUtils.getStoragePath(this@VideoStorageActivity)
+ if(usbPath.isNullOrEmpty()){
+ showToast(getString(R.string.no_upan_tip))
+ return
+ }
+ videopath = usbPath + "/video"
+ LogUtils.w("videopathis $videopath")
+ }
+ savePathToPreferences(videopath)
+ showToast("保存成功")
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/WarnDataActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/WarnDataActivity.kt
index cc161f3..670fce7 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/WarnDataActivity.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/WarnDataActivity.kt
@@ -7,6 +7,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.common.commonlib.db.DBUtils
import com.common.commonlib.db.entity.Warning
+import com.common.commonlib.utils.LogUtils
import com.common.commonlib.utils.StorageUtils
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivityWarndataBinding
@@ -131,11 +132,15 @@ class WarnDataActivity : BaseActivity() {
}
showLoadingDialog(R.string.export_data_tip, false)
lifecycleScope.launch(Dispatchers.IO) {
+ LogUtils.w("enterlifecycle")
val exportWarnExcelPath = ExportUtils.testExportWarnExcel(
this@WarnDataActivity,
usbPath,
mAdapter._data,
)
+
+ LogUtils.w("exportWarnExcelPathis $exportWarnExcelPath")
+
var delayTime: Int = (mAdapter._data.size / 10) * 35
if (delayTime < 9000) {
delayTime = 9000
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/view/CommonTopBar.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/view/CommonTopBar.kt
index e00c92d..c3d662a 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/view/CommonTopBar.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/view/CommonTopBar.kt
@@ -22,6 +22,7 @@ import com.yinuo.safetywatcher.watcher.interfaces.NetworkStateCallback
import com.yinuo.safetywatcher.watcher.utils.BatteryHelper
import com.yinuo.safetywatcher.watcher.utils.NetworkHelper
import com.yinuo.safetywatcher.watcher.utils.trySetCommonBg
+import kotlinx.coroutines.delay
class CommonTopBar : LinearLayout {
constructor(context: Context?) : this(context, null)
@@ -85,18 +86,32 @@ class CommonTopBar : LinearLayout {
override fun onEnable(enable: Boolean) {
LogUtils.w("wifiCallback onEnable = $enable")
mBinding?.root?.post {
-// mBinding?.wifi?.visibility = if (enable) View.VISIBLE else View.GONE
- mBinding?.wifi?.setImageLevel(0)
+ //mBinding?.wifi?.visibility = if (enable) View.VISIBLE else View.GONE
+ if (!enable){
+ LogUtils.w("enbale未打开")
+ mBinding?.wifi?.setImageLevel(0)
+ }
+ mBinding?.wifi?.visibility = View.VISIBLE
}
+ LogUtils.w("wifiEnable is ${mBinding?.wifi?.visibility}")
}
override fun onLevel(level: Int) {
LogUtils.w("wifiCallback onLevel = $level")
mBinding?.root?.post {
-// mBinding?.wifi?.visibility = if (level > 0) VISIBLE else GONE
- val showLevel = (level + 1) * 20
- mBinding?.wifi?.setImageLevel(showLevel)
+ //mBinding?.wifi?.visibility = if (level > 0) VISIBLE else GONE
+ mBinding?.wifi?.visibility = VISIBLE
+ if(level > 0){
+ val showLevel = (level + 1) * 20
+ mBinding?.wifi?.setImageLevel(showLevel)
+ }else{
+ mBinding?.wifi?.setImageLevel(0)
+ }
+ //val showLevel = (level + 1) * 20
+ //mBinding?.wifi?.setImageLevel(showLevel)
}
+ LogUtils.w("wifilever is ${mBinding?.wifi?.visibility}")
+ LogUtils.w("wifishowlevel is $level")
}
}
@@ -104,25 +119,46 @@ class CommonTopBar : LinearLayout {
* sim卡状态和信号
* **/
private val simCallback = object : NetworkStateCallback {
+ var simState = 0
override fun onEnable(enable: Boolean) {
LogUtils.w("sim enable callback : $enable")
mBinding?.root?.post {
-// mBinding?.fourG?.visibility = if (enable) View.VISIBLE else View.GONE
- mBinding?.fourG?.setImageLevel(0)
+ //mBinding?.fourG?.visibility = if (enable) View.VISIBLE else View.GONE
+ if(!enable){
+ mBinding?.fourG?.setImageLevel(0)
+ }else{
+ simState = 1
+ }
+ mBinding?.fourG?.visibility = View.VISIBLE
}
}
override fun onLevel(level: Int) {
LogUtils.w("simCallback onLevel = $level")
mBinding?.root?.post {
- var showLevel = (level + 1) * 20
+/* var showLevel = (level + 1) * 20
// var showLevel =
// if (AppData.hasCameraData()) (level / 15 + 1) * 20 else (level + 1) * 20
if (showLevel > 100) {
showLevel = 100
}
- mBinding?.fourG?.setImageLevel(showLevel)
+ mBinding?.fourG?.setImageLevel(showLevel)*/
+ mBinding?.fourG?.visibility = View.VISIBLE
+ if(simState == 1){
+ if(level > 0){
+ var showLevel = level * 20
+ if (showLevel > 100) {
+ showLevel = 100
+ }
+ mBinding?.fourG?.setImageLevel(showLevel)
+ }else{
+ mBinding?.fourG?.setImageLevel(0)
+ }
+ }
+ else{
+ mBinding?.fourG?.setImageLevel(0)
+ }
}
}
}
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/ExportUtils.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/ExportUtils.kt
index dfbd159..3f8fee3 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/ExportUtils.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/ExportUtils.kt
@@ -30,6 +30,7 @@ object ExportUtils {
}
LogUtils.w("testExportExcel ori data size = ${datas.size}, cell data size = ${allData.size}")
val excelPath = ExcelUtils.writeStringListToExcel(allData, usbPath, context)
+ LogUtils.w("excelPathis $excelPath")
return excelPath
}
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/LztekUtil.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/LztekUtil.kt
index 3a48d68..f1bf7f9 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/LztekUtil.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/LztekUtil.kt
@@ -2,6 +2,7 @@ package com.yinuo.safetywatcher.watcher.utils
import android.os.Environment
import com.common.commonlib.CommonApplication
+import com.common.commonlib.utils.LogUtils
import com.common.commonlib.utils.MMKVUtils
import com.common.commonlib.utils.StorageUtils
import com.lztek.toolkit.Lztek
@@ -70,6 +71,7 @@ object LztekUtil {
fun setRtspUrl(str: String?) {
this.rtspUrl = str
+ LogUtils.w("rtspUrl is $str")
rtspUrl?.let {
PushHelper.setPushUrl(it)
}
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/RecordHelper.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/RecordHelper.kt
index 5b127c6..8af234c 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/RecordHelper.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/RecordHelper.kt
@@ -1,9 +1,13 @@
package com.yinuo.safetywatcher.watcher.utils
+import android.content.Context
import android.graphics.Bitmap
import android.view.TextureView
+import com.common.commonlib.utils.LogUtils
import org.easydarwin.TxtOverlay
import org.easydarwin.push.HWConsumer
+import com.yinuo.library.vlc.encoder.CameraHelper
+
object RecordHelper {
@@ -12,6 +16,7 @@ object RecordHelper {
private const val overlayOffset = 20
private var recording = false;
private var consumer: HWConsumer? = null
+ private var camera: CameraHelper? = null
fun onFrameAvailable(view: TextureView, nv12Data: ByteArray) {
if (!recording) {
@@ -43,14 +48,23 @@ object RecordHelper {
consumer?.onVideo(nv12Data, 0)
}
- fun startRecording() {
+ fun startRecording(context: Context) {
if (!recording) {
recording = true
- consumer = HWConsumer()
+ consumer = HWConsumer(context)
consumer?.onVideoStart(width, height)
}
}
+ fun startRecordingUSB(context: Context,path:String){
+ if(!recording){
+ LogUtils.w("contextis $context")
+ recording = true
+ consumer = HWConsumer(context)
+ consumer?.onUSBStart(path)
+ }
+ }
+
fun stopRecording() {
if (recording) {
recording = false
@@ -58,4 +72,13 @@ object RecordHelper {
consumer = null
}
}
+
+ fun stopRecordingUSB() {
+ if (recording) {
+ recording = false
+ consumer?.onUSBStop()
+ consumer = null
+ }
+ }
+
}
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/SpeedUtils.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/SpeedUtils.kt
index 5e95881..1e4831e 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/SpeedUtils.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/utils/SpeedUtils.kt
@@ -4,11 +4,16 @@ import com.common.commonlib.utils.MMKVUtils
object SpeedUtils {
private var speed = 0
+ private var pumpState = 0
fun getSpeed(): Int {
return speed
}
+ fun getState(): Int {
+ return pumpState
+ }
+
fun setSpeed(legalSpeed: Int) {
this.speed = legalSpeed
if (legalSpeed != 0) {
@@ -16,6 +21,22 @@ object SpeedUtils {
}
}
+ fun setPageSpeed(legalSpeed: Int) {
+ if (legalSpeed != 0) {
+ MMKVUtils.put("PageSpeed", legalSpeed)
+ }
+ }
+
+ fun setPumpState(legalState: Int){
+ this.pumpState = legalState
+ MMKVUtils.put("pumpState", legalState)
+ }
+
+ fun getPumpState(): Int{
+ var stateValue = MMKVUtils.getInt("pumpState")
+ return stateValue
+ }
+
fun getLocalSpeed(): Int {
var localValue = MMKVUtils.getInt("LocalSpeed")
if (localValue<0){
@@ -23,4 +44,12 @@ object SpeedUtils {
}
return localValue
}
+
+ fun getPageSpeed(): Int {
+ var pageValue = MMKVUtils.getInt("PageSpeed")
+ if (pageValue<0){
+ pageValue = 1
+ }
+ return pageValue
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/xls/utils/ExcelUtils.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/xls/utils/ExcelUtils.kt
index e5ce1fb..c1fcb96 100644
--- a/app/src/main/java/com/yinuo/safetywatcher/watcher/xls/utils/ExcelUtils.kt
+++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/xls/utils/ExcelUtils.kt
@@ -14,6 +14,10 @@ import jxl.write.WriteException
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
+import android.Manifest
+import android.app.Activity
+import androidx.core.app.ActivityCompat
+import androidx.core.content.ContextCompat
/**
@@ -92,7 +96,9 @@ object ExcelUtils {
}
}
- fun writeStringListToExcel(
+ private const val REQUEST_EXTERNAL_STORAGE_PERMISSION = 1
+
+ /*fun writeStringListToExcel(
allRowsData: List>,
usbPath: String,
context: Context,
@@ -128,13 +134,105 @@ object ExcelUtils {
writebook.write()
Log.i(TAG, "Excelel 写入成功 $filePath")
return filePath
- } catch (e: Exception) {
- Log.e(TAG, "writeStringListToExcel() e==" + e.message)
- } finally {
+ }
+ catch (e: Exception) {
+ Log.e(TAG, "writeStringListToExcel() e==" + e.message)
+ }
+ finally {
+ Log.i(TAG, "Excelelfinally")
writebook?.close()
inputStream?.close()
Log.i(TAG, "Excelel 写入完成")
}
return null
+ }*/
+
+
+ fun writeStringListToExcel(
+ allRowsData: List>,
+ usbPath: String,
+ context: Context,
+ isWarnData: Boolean = false
+ ): String? {
+ // 检查权限是否已经授予
+ if (ContextCompat.checkSelfPermission(
+ context,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE
+ ) != android.content.pm.PackageManager.PERMISSION_GRANTED ||
+ ContextCompat.checkSelfPermission(
+ context,
+ Manifest.permission.READ_EXTERNAL_STORAGE
+ ) != android.content.pm.PackageManager.PERMISSION_GRANTED
+ ) {
+ Log.i(TAG, "权限未授予")
+ // 如果权限未开启,则请求权限
+ if (context is Activity) {
+ Log.i(TAG, "请求权限")
+ ActivityCompat.requestPermissions(
+ context,
+ arrayOf(
+ Manifest.permission.READ_EXTERNAL_STORAGE,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE
+ ),
+ REQUEST_EXTERNAL_STORAGE_PERMISSION
+ )
+ return null // 权限未开启时,直接返回
+ } else {
+ Log.e(TAG, "Context is not an Activity. Cannot request permissions.")
+ return null
+ }
+ }
+
+ Log.i(TAG, "开启权限")
+ // 如果权限已经开启,继续执行写入操作
+ val fileName =
+ if (!isWarnData)
+ "气体浓度_${PathUtils.getNowTimeFormat(PathUtils.DATE_TO_STRING_LONG_PATTERN)}.xls"
+ else "告警数据_${PathUtils.getNowTimeFormat(PathUtils.DATE_TO_STRING_LONG_PATTERN)}.xls"
+ val filePath =
+ usbPath + File.separator + fileName
+ val columns = context.resources.getStringArray(R.array.excel_column)
+ initExcel(columns, filePath, PathUtils.SHEET_NAME) // 需要写入权限
+
+ if (PathUtils.isListEmpty(allRowsData) || context == null)
+ return null
+
+ var writebook: WritableWorkbook? = null
+ var inputStream: InputStream? = null
+ try {
+ val setEncode = WorkbookSettings()
+ setEncode.encoding = UTF8_ENCODING
+ inputStream = FileInputStream(File(filePath))
+ val workbook = Workbook.getWorkbook(inputStream)
+ val file = File(filePath)
+ writebook = Workbook.createWorkbook(file, workbook)
+ val sheet = writebook.getSheet(0)
+ for ((row, item) in allRowsData.withIndex()) {
+ item.forEachIndexed { index, cellValue ->
+ sheet.addCell(Label(index, row + 1, cellValue.getValue(), arial12format))
+ }
+ }
+ writebook.write()
+ Log.i(TAG, "Excel 写入成功 $filePath")
+ return filePath
+ } catch (e: Exception) {
+ Log.e(TAG, "writeStringListToExcel() Exception occurred", e)
+ } finally {
+ Log.i(TAG, "Excel finally")
+ try {
+ writebook?.close()
+ Log.i(TAG, "Excel workbook closed successfully")
+ } catch (e: Exception) {
+ Log.e(TAG, "Failed to close workbook", e)
+ }
+ try {
+ inputStream?.close()
+ Log.i(TAG, "Input stream closed successfully")
+ } catch (e: Exception) {
+ Log.e(TAG, "Failed to close input stream", e)
+ }
+ Log.i(TAG, "Excel 写入完成")
+ }
+ return null
}
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable-hdpi/ic_icon.png b/app/src/main/res/drawable-hdpi/ic_icon.png
index dd7475e..f54b860 100644
Binary files a/app/src/main/res/drawable-hdpi/ic_icon.png and b/app/src/main/res/drawable-hdpi/ic_icon.png differ
diff --git a/app/src/main/res/drawable-hdpi/ic_icon0.png b/app/src/main/res/drawable-hdpi/ic_icon0.png
new file mode 100644
index 0000000..81f3375
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon0.png differ
diff --git a/app/src/main/res/drawable-hdpi/ic_pw_icon.png b/app/src/main/res/drawable-hdpi/ic_pw_icon.png
new file mode 100644
index 0000000..42c006e
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_pw_icon.png differ
diff --git a/app/src/main/res/drawable-hdpi/net_0.png b/app/src/main/res/drawable-hdpi/net_0.png
new file mode 100644
index 0000000..28d5f70
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/net_0.png differ
diff --git a/app/src/main/res/drawable-hdpi/wifi_0.png b/app/src/main/res/drawable-hdpi/wifi_0.png
new file mode 100644
index 0000000..ca9cad6
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/wifi_0.png differ
diff --git a/app/src/main/res/drawable/ic_pw_icon.png b/app/src/main/res/drawable/ic_pw_icon.png
new file mode 100644
index 0000000..42c006e
Binary files /dev/null and b/app/src/main/res/drawable/ic_pw_icon.png differ
diff --git a/app/src/main/res/drawable/net.xml b/app/src/main/res/drawable/net.xml
index d2f45b6..8a5d8cf 100644
--- a/app/src/main/res/drawable/net.xml
+++ b/app/src/main/res/drawable/net.xml
@@ -1,5 +1,9 @@
+
-
-
+
diff --git a/app/src/main/res/layout/activity_base.xml b/app/src/main/res/layout/activity_base.xml
index 0863dca..b4985cc 100644
--- a/app/src/main/res/layout/activity_base.xml
+++ b/app/src/main/res/layout/activity_base.xml
@@ -115,6 +115,19 @@
android:textColor="@color/white"
android:textSize="@dimen/_132dp"
/>
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml
index 2f6e94c..735c619 100644
--- a/app/src/main/res/layout/activity_home.xml
+++ b/app/src/main/res/layout/activity_home.xml
@@ -47,8 +47,8 @@
android:paddingStart="@dimen/_66dp">
+ android:textSize="@dimen/_40dp" />
+ android:textSize="@dimen/_40dp" />
@@ -94,8 +94,8 @@
android:paddingStart="@dimen/_66dp">
+ android:textSize="@dimen/_40dp" />
+ android:textSize="@dimen/_40dp" />
+ android:textSize="@dimen/_40dp" />
+ android:textSize="@dimen/_40dp" />
+ android:textSize="@dimen/_40dp" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_recovery.xml b/app/src/main/res/layout/activity_recovery.xml
new file mode 100644
index 0000000..c8b36e3
--- /dev/null
+++ b/app/src/main/res/layout/activity_recovery.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_save_video.xml b/app/src/main/res/layout/activity_save_video.xml
new file mode 100644
index 0000000..feb0f0f
--- /dev/null
+++ b/app/src/main/res/layout/activity_save_video.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_sensor_setting.xml b/app/src/main/res/layout/activity_sensor_setting.xml
index f38bdd7..5e5f8da 100644
--- a/app/src/main/res/layout/activity_sensor_setting.xml
+++ b/app/src/main/res/layout/activity_sensor_setting.xml
@@ -168,6 +168,18 @@
android:text="@string/unit_mg_m3"
android:textColor="@color/white"
android:textSize="@dimen/_28dp" />
+
+
+