diff --git a/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt b/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt index 4d3f9c1..7290218 100644 --- a/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt +++ b/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt @@ -32,7 +32,7 @@ this.axisLeft.setDrawGridLines(false) //设置x轴上每个点对应的线 this.axisLeft.setDrawZeroLine(true) //添加限制线 - val threshold = SaveKeyValues.getValue(LocaleConstant.METHANE_DEFAULT_VALUE_KEY, 2) + val threshold = SaveKeyValues.getValue(LocaleConstant.METHANE_DEFAULT_VALUE_KEY, 2.00f) val limitLine = LimitLine(threshold.toString().toFloat(), "阈值:${threshold}%LEL") limitLine.lineWidth = 1f limitLine.lineColor = Color.RED @@ -61,7 +61,7 @@ } fun LineChart.updateLimitLine(threshold: Float) { - val limitLine = LimitLine(threshold, "阈值:${threshold}%VOL") + val limitLine = LimitLine(threshold, "阈值:${threshold}%LEL") limitLine.lineWidth = 1f limitLine.lineColor = Color.RED //允许在虚线模式下绘制(线段长度,分隔长度,偏移量) diff --git a/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt b/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt index 4d3f9c1..7290218 100644 --- a/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt +++ b/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt @@ -32,7 +32,7 @@ this.axisLeft.setDrawGridLines(false) //设置x轴上每个点对应的线 this.axisLeft.setDrawZeroLine(true) //添加限制线 - val threshold = SaveKeyValues.getValue(LocaleConstant.METHANE_DEFAULT_VALUE_KEY, 2) + val threshold = SaveKeyValues.getValue(LocaleConstant.METHANE_DEFAULT_VALUE_KEY, 2.00f) val limitLine = LimitLine(threshold.toString().toFloat(), "阈值:${threshold}%LEL") limitLine.lineWidth = 1f limitLine.lineColor = Color.RED @@ -61,7 +61,7 @@ } fun LineChart.updateLimitLine(threshold: Float) { - val limitLine = LimitLine(threshold, "阈值:${threshold}%VOL") + val limitLine = LimitLine(threshold, "阈值:${threshold}%LEL") limitLine.lineWidth = 1f limitLine.lineColor = Color.RED //允许在虚线模式下绘制(线段长度,分隔长度,偏移量) diff --git a/app/src/main/java/com/casic/app/safetreecontroller/fragments/MethaneMonitorFragment.kt b/app/src/main/java/com/casic/app/safetreecontroller/fragments/MethaneMonitorFragment.kt index 0bfdbb9..3c0fb7f 100644 --- a/app/src/main/java/com/casic/app/safetreecontroller/fragments/MethaneMonitorFragment.kt +++ b/app/src/main/java/com/casic/app/safetreecontroller/fragments/MethaneMonitorFragment.kt @@ -132,7 +132,7 @@ SocketConnectionService.weakReferenceHandler ?: return@setOnClickListener val message = weakReferenceHandler.obtainMessage() message.what = LocaleConstant.UPDATE_GAS_THRESHOLD_CODE - //用户使用【%VOL】,但是单片机只能设置【ppm·m】,所以需要转换一下 + //用户使用【%LEL】,但是单片机只能设置【ppm·m】,所以需要转换一下 message.obj = (threshold * 10000).toInt() weakReferenceHandler.sendMessage(message) } @@ -157,7 +157,10 @@ isGetThreshold = true val ppm = msg.obj as Long val threshold = "%.2f".format(ppm / 10000f) - SaveKeyValues.putValue(LocaleConstant.METHANE_DEFAULT_VALUE_KEY, threshold) + SaveKeyValues.putValue( + LocaleConstant.METHANE_DEFAULT_VALUE_KEY, threshold.toFloat() + ) + binding.thresholdView.setText(threshold) binding.lineChart.updateLimitLine(ppm / 10000f) } @@ -190,20 +193,20 @@ //通常,对于气体在空气中的浓度,我们可以认为100000ppm大约等于200%LEL val formatValue = "%.2f".format(ppm / 500f) binding.currentGasValueView.text = "当前燃气浓度:${formatValue}%LEL" - if (ppm > binding.thresholdView.text.toString().toFloat() * 500) { - binding.currentGasValueView.setTextColor(Color.RED) - binding.currentGasValueView.typeface = Typeface.DEFAULT_BOLD - } else { - binding.currentGasValueView.setTextColor(Color.BLACK) - binding.currentGasValueView.typeface = Typeface.DEFAULT + if (!binding.thresholdView.text.isNullOrBlank()) { + if (ppm > binding.thresholdView.text.toString().toFloat() * 500) { + binding.currentGasValueView.setTextColor(Color.RED) + binding.currentGasValueView.typeface = Typeface.DEFAULT_BOLD + } else { + binding.currentGasValueView.setTextColor(Color.BLACK) + binding.currentGasValueView.typeface = Typeface.DEFAULT + } } //折线图添加数据 xAxisLabels.add(System.currentTimeMillis().timestampToTime()) //浓度线 - strengthEntries.add( - Entry(i++.toFloat(), formatValue.toFloat(), "浓度") - ) + strengthEntries.add(Entry(i++.toFloat(), formatValue.toFloat(), "浓度")) //设置数据 dataSet.values = strengthEntries lineDataSets.add(dataSet) diff --git a/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt b/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt index 4d3f9c1..7290218 100644 --- a/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt +++ b/app/src/main/java/com/casic/app/safetreecontroller/extensions/LineChart.kt @@ -32,7 +32,7 @@ this.axisLeft.setDrawGridLines(false) //设置x轴上每个点对应的线 this.axisLeft.setDrawZeroLine(true) //添加限制线 - val threshold = SaveKeyValues.getValue(LocaleConstant.METHANE_DEFAULT_VALUE_KEY, 2) + val threshold = SaveKeyValues.getValue(LocaleConstant.METHANE_DEFAULT_VALUE_KEY, 2.00f) val limitLine = LimitLine(threshold.toString().toFloat(), "阈值:${threshold}%LEL") limitLine.lineWidth = 1f limitLine.lineColor = Color.RED @@ -61,7 +61,7 @@ } fun LineChart.updateLimitLine(threshold: Float) { - val limitLine = LimitLine(threshold, "阈值:${threshold}%VOL") + val limitLine = LimitLine(threshold, "阈值:${threshold}%LEL") limitLine.lineWidth = 1f limitLine.lineColor = Color.RED //允许在虚线模式下绘制(线段长度,分隔长度,偏移量) diff --git a/app/src/main/java/com/casic/app/safetreecontroller/fragments/MethaneMonitorFragment.kt b/app/src/main/java/com/casic/app/safetreecontroller/fragments/MethaneMonitorFragment.kt index 0bfdbb9..3c0fb7f 100644 --- a/app/src/main/java/com/casic/app/safetreecontroller/fragments/MethaneMonitorFragment.kt +++ b/app/src/main/java/com/casic/app/safetreecontroller/fragments/MethaneMonitorFragment.kt @@ -132,7 +132,7 @@ SocketConnectionService.weakReferenceHandler ?: return@setOnClickListener val message = weakReferenceHandler.obtainMessage() message.what = LocaleConstant.UPDATE_GAS_THRESHOLD_CODE - //用户使用【%VOL】,但是单片机只能设置【ppm·m】,所以需要转换一下 + //用户使用【%LEL】,但是单片机只能设置【ppm·m】,所以需要转换一下 message.obj = (threshold * 10000).toInt() weakReferenceHandler.sendMessage(message) } @@ -157,7 +157,10 @@ isGetThreshold = true val ppm = msg.obj as Long val threshold = "%.2f".format(ppm / 10000f) - SaveKeyValues.putValue(LocaleConstant.METHANE_DEFAULT_VALUE_KEY, threshold) + SaveKeyValues.putValue( + LocaleConstant.METHANE_DEFAULT_VALUE_KEY, threshold.toFloat() + ) + binding.thresholdView.setText(threshold) binding.lineChart.updateLimitLine(ppm / 10000f) } @@ -190,20 +193,20 @@ //通常,对于气体在空气中的浓度,我们可以认为100000ppm大约等于200%LEL val formatValue = "%.2f".format(ppm / 500f) binding.currentGasValueView.text = "当前燃气浓度:${formatValue}%LEL" - if (ppm > binding.thresholdView.text.toString().toFloat() * 500) { - binding.currentGasValueView.setTextColor(Color.RED) - binding.currentGasValueView.typeface = Typeface.DEFAULT_BOLD - } else { - binding.currentGasValueView.setTextColor(Color.BLACK) - binding.currentGasValueView.typeface = Typeface.DEFAULT + if (!binding.thresholdView.text.isNullOrBlank()) { + if (ppm > binding.thresholdView.text.toString().toFloat() * 500) { + binding.currentGasValueView.setTextColor(Color.RED) + binding.currentGasValueView.typeface = Typeface.DEFAULT_BOLD + } else { + binding.currentGasValueView.setTextColor(Color.BLACK) + binding.currentGasValueView.typeface = Typeface.DEFAULT + } } //折线图添加数据 xAxisLabels.add(System.currentTimeMillis().timestampToTime()) //浓度线 - strengthEntries.add( - Entry(i++.toFloat(), formatValue.toFloat(), "浓度") - ) + strengthEntries.add(Entry(i++.toFloat(), formatValue.toFloat(), "浓度")) //设置数据 dataSet.values = strengthEntries lineDataSets.add(dataSet) diff --git a/app/src/main/java/com/casic/app/safetreecontroller/widgets/LineChartMarkerView.kt b/app/src/main/java/com/casic/app/safetreecontroller/widgets/LineChartMarkerView.kt index 50d1040..26cb255 100644 --- a/app/src/main/java/com/casic/app/safetreecontroller/widgets/LineChartMarkerView.kt +++ b/app/src/main/java/com/casic/app/safetreecontroller/widgets/LineChartMarkerView.kt @@ -41,7 +41,7 @@ super.refreshContent(e, highlight) try { timeView.text = xAxisDate[(e.x).toInt()] - valueView.text = "${"%.2f".format(e.y)}% VOL" + valueView.text = "${"%.2f".format(e.y)}%LEL" } catch (ex: Exception) { ex.printStackTrace() }