desc:气体报警阈值设置界面按键操作

main
xiaowusky 2 years ago
parent f06c194210
commit d60730eaf9

@ -56,8 +56,10 @@ class SensorSettingActivity : NoOptionsActivity() {
lifecycleScope.launch {
val typeDao = DBUtils.gasTypeDao()
val gasType = typeDao.getByName(gasName)
gasType?.nickName?.let {
mBinding.etName.setText(it)
if (gasType != null && !gasType.nickName.isNullOrEmpty()) {
mBinding.etName.setText(gasType.nickName)
} else {
mBinding.etName.setText("${gasName}传感器")
}
val gasRange = getGasRange(gasName, localGasUnit)
mBinding.etStep.text = getString(R.string.sensor_step_txt).plus(": $gasRange")

@ -1,5 +1,6 @@
package com.yinuo.safetywatcher.watcher.ui
import android.view.KeyEvent
import android.view.View
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivitySensorThresholdBinding
@ -9,6 +10,7 @@ import com.yinuo.safetywatcher.watcher.port.getGasLowThreshold
import com.yinuo.safetywatcher.watcher.port.getLocalGasUnit
import com.yinuo.safetywatcher.watcher.port.saveHighThreshold
import com.yinuo.safetywatcher.watcher.port.saveLowThreshold
import com.yinuo.safetywatcher.watcher.utils.showIme
import com.yinuo.safetywatcher.watcher.utils.showToast
class SensorThresholdSetActivity : NoOptionsActivity() {
@ -46,6 +48,50 @@ class SensorThresholdSetActivity : NoOptionsActivity() {
saveData()
showToast("保存成功")
}
setListener()
}
private fun setListener() {
mBinding.etMin.setOnKeyListener { _, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
if (event.action == KeyEvent.ACTION_DOWN) {
tryFocusBackArea()
return@setOnKeyListener true
}
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
if (event.action == KeyEvent.ACTION_DOWN) {
mBinding.etMax.requestFocus()
return@setOnKeyListener true
}
} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
if (event.action == KeyEvent.ACTION_DOWN) {
mBinding.etMin.showIme()
return@setOnKeyListener true
}
}
return@setOnKeyListener false
}
mBinding.etMax.setOnKeyListener { _, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
if (event.action == KeyEvent.ACTION_DOWN) {
mBinding.etMin.requestFocus()
return@setOnKeyListener true
}
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
if (event.action == KeyEvent.ACTION_DOWN) {
mBinding.tvSave.requestFocus()
return@setOnKeyListener true
}
} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
if (event.action == KeyEvent.ACTION_DOWN) {
mBinding.etMax.showIme()
return@setOnKeyListener true
}
}
return@setOnKeyListener false
}
}
private fun saveData() {

@ -20,6 +20,8 @@
android:layout_height="@dimen/_100dp"
android:layout_marginTop="@dimen/_20dp"
android:background="@drawable/cloud_sync_btn_bg"
android:paddingStart="@dimen/_12dp"
android:focusable="true"
android:inputType="number"
android:textColor="@color/white"
android:textSize="@dimen/_30dp" />
@ -39,6 +41,8 @@
android:layout_height="@dimen/_100dp"
android:layout_marginTop="@dimen/_20dp"
android:background="@drawable/cloud_sync_btn_bg"
android:paddingStart="@dimen/_12dp"
android:focusable="true"
android:inputType="number"
android:textColor="@color/white"
android:textSize="@dimen/_30dp" />

Loading…
Cancel
Save