diff --git a/examples/virtual-device-app/android/App/core/common/src/main/res/values/strings.xml b/examples/virtual-device-app/android/App/core/common/src/main/res/values/strings.xml
index 7afe5953bf2dfd..896c9d0fcae7fe 100644
--- a/examples/virtual-device-app/android/App/core/common/src/main/res/values/strings.xml
+++ b/examples/virtual-device-app/android/App/core/common/src/main/res/values/strings.xml
@@ -1,6 +1,7 @@
Matter OnOff Switch
+ Matter Door Lock
Matter Device
icon
\ No newline at end of file
diff --git a/examples/virtual-device-app/android/App/core/model/src/main/java/com/matter/virtual/device/app/core/model/databinding/SeekbarData.kt b/examples/virtual-device-app/android/App/core/model/src/main/java/com/matter/virtual/device/app/core/model/databinding/SeekbarData.kt
new file mode 100644
index 00000000000000..1c705277210c50
--- /dev/null
+++ b/examples/virtual-device-app/android/App/core/model/src/main/java/com/matter/virtual/device/app/core/model/databinding/SeekbarData.kt
@@ -0,0 +1,5 @@
+package com.matter.virtual.device.app.core.model.databinding
+
+import androidx.lifecycle.LiveData
+
+data class SeekbarData(val progress: LiveData, val min: Int = 0, val max: Int = 100)
diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_radio_button_checked_24.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_radio_button_checked_24.xml
new file mode 100644
index 00000000000000..51d6c60882ff8a
--- /dev/null
+++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_radio_button_checked_24.xml
@@ -0,0 +1,6 @@
+
+
+
+
diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_settings_24.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_settings_24.xml
new file mode 100644
index 00000000000000..6828a1e8db4507
--- /dev/null
+++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/drawable/round_settings_24.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_seekbar.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_seekbar.xml
new file mode 100644
index 00000000000000..ea1ce4ea2ec124
--- /dev/null
+++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_seekbar.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_simple_button.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_simple_button.xml
new file mode 100644
index 00000000000000..95677bcd9eaa3f
--- /dev/null
+++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/layout/layout_item_title_value_simple_button.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/virtual-device-app/android/App/core/ui/src/main/res/values/strings.xml b/examples/virtual-device-app/android/App/core/ui/src/main/res/values/strings.xml
index 70fd88fd75a365..feab13c39647af 100644
--- a/examples/virtual-device-app/android/App/core/ui/src/main/res/values/strings.xml
+++ b/examples/virtual-device-app/android/App/core/ui/src/main/res/values/strings.xml
@@ -1,12 +1,18 @@
button
+ seekbar
+
Reset
"The Matter device app will be reset and closed. Continue?"
"The commissioning was not completed. The Matter device app will be reset and closed. Continue?"
- "The fabric was removed. The Matter device app will be reset and closed."
+ "The fabric was removed. The Matter device app will be reset and closed."
+
+ Battery
+ %d <small><small>%%</small></small>
+ Cancel
On
Off
\ No newline at end of file
diff --git a/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockFragment.kt b/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockFragment.kt
index 8cfe6a403f53ed..7e0553b7653223 100644
--- a/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockFragment.kt
+++ b/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockFragment.kt
@@ -1,7 +1,12 @@
package com.matter.virtual.device.app.feature.closure
+import android.text.Html
+import android.widget.SeekBar
+import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.navArgs
+import com.matter.virtual.device.app.core.model.databinding.SeekbarData
+import com.matter.virtual.device.app.core.model.matter.LockState
import com.matter.virtual.device.app.core.ui.BaseFragment
import com.matter.virtual.device.app.core.ui.databinding.LayoutAppbarBinding
import com.matter.virtual.device.app.feature.closure.databinding.FragmentDoorLockBinding
@@ -16,6 +21,7 @@ class DoorLockFragment :
BaseFragment(R.layout.fragment_door_lock) {
override val viewModel: DoorLockViewModel by viewModels()
+ private var lockState: LockState = LockState.LOCKED
@OptIn(ExperimentalSerializationApi::class)
override fun setupNavArgs() {
@@ -25,9 +31,55 @@ class DoorLockFragment :
override fun setupAppbar(): LayoutAppbarBinding = binding.appbar
- override fun setupUi() {}
+ override fun setupUi() {
+ /** title text */
+ binding.appbar.toolbarTitle.text = getString(R.string.matter_door_lock)
- override fun setupObservers() {}
+ /** LockState layout */
+ binding.doorLockLockStateLayout.titleText.text = getString(R.string.door_lock_lock_state)
+ binding.doorLockLockStateLayout.button.setImageResource(R.drawable.round_settings_24)
+ binding.doorLockLockStateLayout.button.setOnClickListener { showLockStatePopup() }
+
+ /** Send alarm layout */
+ binding.doorLockSendAlarmLayout.valueText.text =
+ getString(R.string.door_lock_send_lock_alarm_event)
+ binding.doorLockSendAlarmLayout.button.setImageResource(
+ R.drawable.round_radio_button_checked_24
+ )
+ binding.doorLockSendAlarmLayout.button.setOnClickListener {
+ viewModel.onClickSendLockAlarmEventButton()
+ }
+
+ /** Battery layout */
+ binding.doorLockBatteryLayout.titleText.text = getString(R.string.battery)
+ binding.doorLockBatteryLayout.seekbarData =
+ SeekbarData(progress = viewModel.batteryRemainingPercentage)
+ binding.doorLockBatteryLayout.seekbar.setOnSeekBarChangeListener(
+ object : SeekBar.OnSeekBarChangeListener {
+ override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
+ viewModel.updateBatterySeekbarProgress(progress)
+ }
+
+ override fun onStartTrackingTouch(seekBar: SeekBar) {}
+
+ override fun onStopTrackingTouch(seekBar: SeekBar) {
+ viewModel.updateBatteryStatusToCluster(seekBar.progress)
+ }
+ }
+ )
+ }
+
+ override fun setupObservers() {
+ viewModel.lockState.observe(viewLifecycleOwner) {
+ this.lockState = it
+ binding.doorLockLockStateLayout.valueText.text = it.toString()
+ }
+
+ viewModel.batteryRemainingPercentage.observe(viewLifecycleOwner) {
+ val text: String = getString(R.string.battery_format, it)
+ binding.doorLockBatteryLayout.valueText.text = Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)
+ }
+ }
override fun onResume() {
Timber.d("onResume()")
@@ -38,4 +90,23 @@ class DoorLockFragment :
Timber.d("onDestroy()")
super.onDestroy()
}
+
+ private fun showLockStatePopup() {
+ val list =
+ arrayOf(
+ LockState.NOT_FULLY_LOCKED.toString(),
+ LockState.LOCKED.toString(),
+ LockState.UNLOCKED.toString(),
+ LockState.UNLATCHED.toString()
+ )
+
+ AlertDialog.Builder(requireContext())
+ .setTitle(R.string.door_lock_lock_state)
+ .setSingleChoiceItems(list, list.indexOf(this.lockState.toString())) { dialog, which ->
+ viewModel.setLockState(enumValueOf(list[which]))
+ dialog.dismiss()
+ }
+ .setNegativeButton(R.string.cancel, null)
+ .show()
+ }
}
diff --git a/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockViewModel.kt b/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockViewModel.kt
index 4f9b0b3a48ce55..f5d430b0e669c3 100644
--- a/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockViewModel.kt
+++ b/examples/virtual-device-app/android/App/feature/closure/src/main/java/com/matter/virtual/device/app/feature/closure/DoorLockViewModel.kt
@@ -61,18 +61,9 @@ constructor(
super.onCleared()
}
- fun onClickButton() {
- Timber.d("onClickButton()")
- viewModelScope.launch {
- Timber.d("current lockState value = ${_lockState.value}")
- if (_lockState.value == LockState.LOCKED) {
- Timber.d("set value = unlocked")
- setLockStateUseCase(LockState.UNLOCKED)
- } else {
- Timber.d("set value = locked")
- setLockStateUseCase(LockState.LOCKED)
- }
- }
+ fun setLockState(lockState: LockState) {
+ Timber.d("setLockState():new:$lockState")
+ viewModelScope.launch { setLockStateUseCase(lockState) }
}
fun onClickSendLockAlarmEventButton() {
diff --git a/examples/virtual-device-app/android/App/feature/closure/src/main/res/layout/fragment_door_lock.xml b/examples/virtual-device-app/android/App/feature/closure/src/main/res/layout/fragment_door_lock.xml
index d726e82e616348..9caa1a2b67a48b 100644
--- a/examples/virtual-device-app/android/App/feature/closure/src/main/res/layout/fragment_door_lock.xml
+++ b/examples/virtual-device-app/android/App/feature/closure/src/main/res/layout/fragment_door_lock.xml
@@ -1,5 +1,6 @@
+
@@ -15,6 +16,34 @@
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/examples/virtual-device-app/android/App/feature/closure/src/main/res/values/strings.xml b/examples/virtual-device-app/android/App/feature/closure/src/main/res/values/strings.xml
new file mode 100644
index 00000000000000..5f0ec3d4e84114
--- /dev/null
+++ b/examples/virtual-device-app/android/App/feature/closure/src/main/res/values/strings.xml
@@ -0,0 +1,5 @@
+
+
+ Lock state
+ Send Alarm
+
\ No newline at end of file
diff --git a/examples/virtual-device-app/android/App/feature/setup/src/main/res/values/strings.xml b/examples/virtual-device-app/android/App/feature/setup/src/main/res/values/strings.xml
index e8ae1eb4677b47..75f4022f6ebef9 100644
--- a/examples/virtual-device-app/android/App/feature/setup/src/main/res/values/strings.xml
+++ b/examples/virtual-device-app/android/App/feature/setup/src/main/res/values/strings.xml
@@ -11,7 +11,6 @@
Make sure your Mobile/Hub/Device App are connected to the same Wi-Fi network.
Save
Invalid input value
- Cancel
Start
Wi-Fi : %1$s
%1$s : %2$s