desc:设置报警阈值
parent
cb2805e8a0
commit
2ea7836a55
@ -0,0 +1,70 @@
|
||||
package com.yinuo.safetywatcher.watcher.constant
|
||||
|
||||
import com.common.commonlib.utils.MMKVUtils
|
||||
|
||||
const val CO_MIN = 0f
|
||||
const val CO_MAX = 0f
|
||||
|
||||
const val O2_MIN = 0f
|
||||
const val O2_MAX = 0f
|
||||
|
||||
const val CH4_MIN = 0f
|
||||
const val CH4_MAX = 0f
|
||||
|
||||
const val H2S_MIN = 0f
|
||||
const val H2S_MAX = 0f
|
||||
|
||||
val default_map = hashMapOf<String, Float>(
|
||||
Pair("CO_min", CO_MIN),
|
||||
Pair("CO_max", CO_MAX),
|
||||
Pair("O2_min", O2_MIN),
|
||||
Pair("O2_max", O2_MAX),
|
||||
Pair("CH4_min", CH4_MIN),
|
||||
Pair("CH4_max", CH4_MAX),
|
||||
Pair("H2S_min", H2S_MIN),
|
||||
Pair("H2S_max", H2S_MAX)
|
||||
)
|
||||
|
||||
fun getLowThresHoldKey(gasType: String): String {
|
||||
return "${gasType.uppercase()}_min"
|
||||
}
|
||||
|
||||
fun getHighThresHoldKey(gasType: String): String {
|
||||
return "${gasType.uppercase()}_max"
|
||||
}
|
||||
|
||||
fun saveLowThreshold(gasType: String, value: Float){
|
||||
MMKVUtils.put(getLowThresHoldKey(gasType), value)
|
||||
}
|
||||
|
||||
fun saveHighThreshold(gasType: String, value: Float){
|
||||
MMKVUtils.put(getHighThresHoldKey(gasType), value)
|
||||
}
|
||||
|
||||
fun getGasLowThreshold(gasType: String): Float {
|
||||
val lowThresholdKey = getLowThresHoldKey(gasType)
|
||||
val float = MMKVUtils.getFloat(lowThresholdKey)
|
||||
if (float <= 0) {
|
||||
return default_map[lowThresholdKey] ?: -1f
|
||||
}
|
||||
return float
|
||||
}
|
||||
|
||||
fun getGasHighThreshold(gasType: String): Float {
|
||||
val highThresholdKey = getHighThresHoldKey(gasType)
|
||||
val float = MMKVUtils.getFloat(highThresholdKey)
|
||||
if (float <= 0) {
|
||||
return default_map[highThresholdKey] ?: -1f
|
||||
}
|
||||
return float
|
||||
}
|
||||
|
||||
fun getGasUnit(gasType: String): String {
|
||||
return when (gasType.uppercase()) {
|
||||
"CO" -> "ppm"
|
||||
"CH4" -> "%VOL"
|
||||
"O2" -> "%LEL"
|
||||
"H2S" -> "ppm"
|
||||
else -> ""
|
||||
}
|
||||
}
|
@ -1,7 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="@dimen/_121dp"
|
||||
android:paddingTop="@dimen/_61dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_min"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/low_threshold"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_30dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_min"
|
||||
android:layout_width="@dimen/_600dp"
|
||||
android:layout_height="@dimen/_100dp"
|
||||
android:layout_marginTop="@dimen/_20dp"
|
||||
android:background="@drawable/cloud_sync_btn_bg"
|
||||
android:inputType="number"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_30dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_max"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/_40dp"
|
||||
android:text="@string/high_threshold"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_30dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_max"
|
||||
android:layout_width="@dimen/_600dp"
|
||||
android:layout_height="@dimen/_100dp"
|
||||
android:layout_marginTop="@dimen/_20dp"
|
||||
android:background="@drawable/cloud_sync_btn_bg"
|
||||
android:inputType="number"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_30dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_save"
|
||||
android:layout_width="@dimen/_160dp"
|
||||
android:layout_height="@dimen/_80dp"
|
||||
android:layout_marginTop="@dimen/_40dp"
|
||||
android:background="@drawable/save_btn_bg"
|
||||
android:focusable="true"
|
||||
android:gravity="center"
|
||||
android:text="@string/save"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_30dp" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue