Skip to content

Commit 2ee90eb

Browse files
authored
Implement Android ICD queue Btn (#33743)
1 parent bd0422b commit 2ee90eb

File tree

3 files changed

+87
-45
lines changed

3 files changed

+87
-45
lines changed

examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/WildcardFragment.kt

+53-30
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
174174
setVisibilityEachView(radioBtnId)
175175
}
176176

177-
binding.sendBtn.setOnClickListener { showDialog() }
177+
binding.sendBtn.setOnClickListener { showDialog(isICDQueueBtn = false) }
178178

179179
binding.shutdownSubscriptionBtn.setOnClickListener { showShutdownSubscriptionDialog() }
180180

@@ -183,6 +183,16 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
183183
binding.addListBtn.setOnClickListener { addRequest() }
184184
binding.resetBtn.setOnClickListener { resetPath() }
185185
binding.writeInvokeresetBtn.setOnClickListener { resetPath() }
186+
binding.icdQueueBtn.setOnCheckedChangeListener { _, isChecked ->
187+
if (isChecked) {
188+
val isSetting = showDialog(isICDQueueBtn = true)
189+
if (!isSetting) {
190+
binding.icdQueueBtn.isChecked = false
191+
}
192+
} else {
193+
resetICDConfig()
194+
}
195+
}
186196

187197
addressUpdateFragment =
188198
childFragmentManager.findFragmentById(R.id.addressUpdateFragment) as AddressUpdateFragment
@@ -202,11 +212,11 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
202212

203213
override fun notifyCheckInMessage() {
204214
Log.d(TAG, "notifyCheckInMessage")
205-
if (attributePath.isNotEmpty() || eventPath.isNotEmpty()) {
206-
if (binding.readRadioBtn.isChecked && readICDConfig != null) {
207-
scope.launch { read(readICDConfig!!.isFabricFiltered, readICDConfig!!.eventMin) }
208-
} else if (binding.subscribeRadioBtn.isChecked && subscribeICDConfig != null) {
209-
scope.launch {
215+
scope.launch {
216+
if (attributePath.isNotEmpty() || eventPath.isNotEmpty()) {
217+
if (binding.readRadioBtn.isChecked && readICDConfig != null) {
218+
read(readICDConfig!!.isFabricFiltered, readICDConfig!!.eventMin)
219+
} else if (binding.subscribeRadioBtn.isChecked && subscribeICDConfig != null) {
210220
subscribe(
211221
subscribeICDConfig!!.minInterval,
212222
subscribeICDConfig!!.maxInterval,
@@ -215,20 +225,27 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
215225
subscribeICDConfig!!.eventMin
216226
)
217227
}
218-
}
219-
} else if (
220-
binding.writeRadioBtn.isChecked && writePath.isNotEmpty() && writeICDConfig != null
221-
) {
222-
scope.launch { write(writeICDConfig!!.timedRequestTimeoutMs, writeICDConfig!!.imTimeoutMs) }
223-
} else if (
224-
binding.invokeRadioBtn.isChecked && invokePath.isNotEmpty() && invokeICDConfig != null
225-
) {
226-
scope.launch {
228+
} else if (
229+
binding.writeRadioBtn.isChecked && writePath.isNotEmpty() && writeICDConfig != null
230+
) {
231+
write(writeICDConfig!!.timedRequestTimeoutMs, writeICDConfig!!.imTimeoutMs)
232+
} else if (
233+
binding.invokeRadioBtn.isChecked && invokePath.isNotEmpty() && invokeICDConfig != null
234+
) {
227235
invoke(invokeICDConfig!!.timedRequestTimeoutMs, invokeICDConfig!!.imTimeoutMs)
228236
}
237+
requireActivity().runOnUiThread { binding.icdQueueBtn.isChecked = false }
238+
resetICDConfig()
229239
}
230240
}
231241

242+
private fun resetICDConfig() {
243+
readICDConfig = null
244+
subscribeICDConfig = null
245+
writeICDConfig = null
246+
invokeICDConfig = null
247+
}
248+
232249
private fun setVisibilityEachView(radioBtnId: Int) {
233250
val readBtnOn = (radioBtnId == R.id.readRadioBtn)
234251
val subscribeBtnOn = (radioBtnId == R.id.subscribeRadioBtn)
@@ -261,16 +278,20 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
261278
resetPath()
262279
}
263280

264-
private fun showDialog() {
281+
private fun showDialog(isICDQueueBtn: Boolean): Boolean {
282+
var ret = false
265283
if (binding.readRadioBtn.isChecked) {
266-
showReadDialog()
284+
ret = showReadDialog(isICDQueueBtn)
267285
} else if (binding.subscribeRadioBtn.isChecked) {
268-
showSubscribeDialog()
286+
ret = showSubscribeDialog(isICDQueueBtn)
269287
} else if (binding.writeRadioBtn.isChecked) {
270-
showWriteDialog()
288+
showWriteDialog(isICDQueueBtn)
289+
ret = true
271290
} else if (binding.invokeRadioBtn.isChecked) {
272-
showInvokeDialog()
291+
showInvokeDialog(isICDQueueBtn)
292+
ret = true
273293
}
294+
return ret
274295
}
275296

276297
private fun addRequest() {
@@ -547,7 +568,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
547568
)
548569
}
549570

550-
private fun showReadDialog() {
571+
private fun showReadDialog(isICDQueueBtn: Boolean): Boolean {
551572
if (attributePath.isEmpty() && eventPath.isEmpty()) {
552573
requireActivity().runOnUiThread {
553574
Toast.makeText(
@@ -557,7 +578,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
557578
)
558579
.show()
559580
}
560-
return
581+
return false
561582
}
562583
val dialogView = requireActivity().layoutInflater.inflate(R.layout.read_dialog, null)
563584
val eventMinEd = dialogView.findViewById<EditText>(R.id.eventMinEd)
@@ -576,7 +597,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
576597
if (eventPath.isNotEmpty() && eventMinEd.text.isNotBlank()) {
577598
eventMin = eventMinEd.text.toString().toULong().toLong()
578599
}
579-
if (addressUpdateFragment.isICDDevice()) {
600+
if (isICDQueueBtn) {
580601
readICDConfig =
581602
ReadICDConfig(isFabricFilteredEd.selectedItem.toString().toBoolean(), eventMin)
582603
} else {
@@ -586,9 +607,10 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
586607
}
587608
}
588609
dialog.show()
610+
return true
589611
}
590612

591-
private fun showWriteDialog() {
613+
private fun showWriteDialog(isICDQueueBtn: Boolean) {
592614
binding.outputTv.text = ""
593615
val dialogView = requireActivity().layoutInflater.inflate(R.layout.write_dialog, null)
594616
val dialog = AlertDialog.Builder(requireContext()).apply { setView(dialogView) }.create()
@@ -610,7 +632,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
610632
} else {
611633
imTimeout.toInt()
612634
}
613-
if (addressUpdateFragment.isICDDevice()) {
635+
if (isICDQueueBtn) {
614636
writeICDConfig = WriteInvokeICDConfig(timedRequestTimeoutInt, imTimeoutInt)
615637
} else {
616638
write(timedRequestTimeoutInt, imTimeoutInt)
@@ -621,7 +643,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
621643
dialog.show()
622644
}
623645

624-
private fun showSubscribeDialog() {
646+
private fun showSubscribeDialog(isICDQueueBtn: Boolean): Boolean {
625647
if (attributePath.isEmpty() && eventPath.isEmpty()) {
626648
requireActivity().runOnUiThread {
627649
Toast.makeText(
@@ -631,7 +653,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
631653
)
632654
.show()
633655
}
634-
return
656+
return false
635657
}
636658
val dialogView = requireActivity().layoutInflater.inflate(R.layout.subscribe_dialog, null)
637659
val eventMinEd = dialogView.findViewById<EditText>(R.id.eventMinEd)
@@ -654,7 +676,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
654676
if (eventPath.isNotEmpty() && eventMinEd.text.isNotBlank()) {
655677
eventMin = eventMinEd.text.toString().toULong().toLong()
656678
}
657-
if (addressUpdateFragment.isICDDevice()) {
679+
if (isICDQueueBtn) {
658680
subscribeICDConfig =
659681
SubscribeICDConfig(
660682
minIntervalEd.text.toString().toInt(),
@@ -679,9 +701,10 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
679701
}
680702
}
681703
dialog.show()
704+
return true
682705
}
683706

684-
private fun showInvokeDialog() {
707+
private fun showInvokeDialog(isICDQueueBtn: Boolean) {
685708
binding.outputTv.text = ""
686709
val dialogView = requireActivity().layoutInflater.inflate(R.layout.invoke_dialog, null)
687710
val dialog = AlertDialog.Builder(requireContext()).apply { setView(dialogView) }.create()
@@ -703,7 +726,7 @@ class WildcardFragment : Fragment(), AddressUpdateFragment.ICDCheckInMessageCall
703726
} else {
704727
imTimeout.toInt()
705728
}
706-
if (addressUpdateFragment.isICDDevice()) {
729+
if (isICDQueueBtn) {
707730
invokeICDConfig = WriteInvokeICDConfig(timedRequestTimeoutInt, imTimeoutInt)
708731
} else {
709732
invoke(timedRequestTimeoutInt, imTimeoutInt)

examples/android/CHIPTool/app/src/main/res/layout/wildcard_fragment.xml

+32-15
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,23 @@
299299
android:textSize="16sp"
300300
android:visibility="gone"
301301
app:layout_constraintStart_toStartOf="parent"
302-
app:layout_constraintEnd_toStartOf="@id/sendBtn"
302+
app:layout_constraintEnd_toStartOf="@id/writeInvokeresetBtn"
303303
app:layout_constraintTop_toBottomOf="@id/addLayout"/>
304304

305+
<Button
306+
android:id="@+id/writeInvokeresetBtn"
307+
android:layout_width="wrap_content"
308+
android:layout_height="wrap_content"
309+
android:padding="16dp"
310+
android:layout_marginTop="16dp"
311+
android:layout_marginBottom="8dp"
312+
android:text="@string/wildcard_reset_btn_text"
313+
app:layout_constraintStart_toEndOf="@id/addListBtn"
314+
app:layout_constraintEnd_toEndOf="parent"
315+
app:layout_constraintTop_toBottomOf="@id/addLayout"
316+
android:visibility="gone"
317+
android:textSize="16sp" />
318+
305319
<Button
306320
android:id="@+id/sendBtn"
307321
android:layout_width="wrap_content"
@@ -313,45 +327,48 @@
313327
android:text="@string/wildcard_send_btn_text"
314328
android:textSize="16sp"
315329
app:layout_constraintStart_toStartOf="parent"
316-
app:layout_constraintEnd_toStartOf="@id/shutdownSubscriptionBtn"
317-
app:layout_constraintTop_toBottomOf="@id/addLayout"/>
330+
app:layout_constraintEnd_toStartOf="@id/icdQueueBtn"
331+
app:layout_constraintTop_toBottomOf="@id/addListBtn"/>
318332

319-
<Button
320-
android:id="@+id/shutdownSubscriptionBtn"
333+
<ToggleButton
334+
android:id="@+id/icdQueueBtn"
321335
android:layout_width="wrap_content"
322336
android:layout_height="wrap_content"
323337
android:padding="16dp"
324338
android:layout_marginTop="16dp"
325339
android:layout_marginBottom="8dp"
326340
android:layout_gravity="center"
327-
android:text="@string/wildcard_shutdown_subscription_btn_text"
341+
android:textOn="@string/wildcard_wait_check_in_message_btn_text"
342+
android:textOff="@string/wildcard_send_when_check_in_message_btn_text"
328343
android:textSize="16sp"
329-
android:visibility="gone"
330344
app:layout_constraintStart_toEndOf="@id/sendBtn"
331345
app:layout_constraintEnd_toEndOf="parent"
332-
app:layout_constraintTop_toBottomOf="@id/addLayout"/>
346+
app:layout_constraintTop_toBottomOf="@id/addListBtn"/>
347+
348+
333349

334350
<Button
335-
android:id="@+id/writeInvokeresetBtn"
351+
android:id="@+id/shutdownSubscriptionBtn"
336352
android:layout_width="wrap_content"
337353
android:layout_height="wrap_content"
338354
android:padding="16dp"
339355
android:layout_marginTop="16dp"
340356
android:layout_marginBottom="8dp"
341-
android:text="@string/wildcard_reset_btn_text"
342-
app:layout_constraintStart_toEndOf="@id/sendBtn"
343-
app:layout_constraintEnd_toEndOf="parent"
344-
app:layout_constraintTop_toBottomOf="@id/addLayout"
357+
android:layout_gravity="center"
358+
android:text="@string/wildcard_shutdown_subscription_btn_text"
359+
android:textSize="16sp"
345360
android:visibility="gone"
346-
android:textSize="16sp" />
361+
app:layout_constraintStart_toStartOf="parent"
362+
app:layout_constraintEnd_toEndOf="parent"
363+
app:layout_constraintTop_toBottomOf="@id/sendBtn"/>
347364

348365
<ScrollView
349366
android:layout_width="match_parent"
350367
android:layout_height="0dp"
351368
android:fadeScrollbars="false"
352369
app:layout_constraintBottom_toBottomOf="parent"
353370
app:layout_constraintStart_toStartOf="parent"
354-
app:layout_constraintTop_toBottomOf="@id/sendBtn">
371+
app:layout_constraintTop_toBottomOf="@id/shutdownSubscriptionBtn">
355372
<TextView
356373
android:id="@+id/outputTv"
357374
android:layout_width="match_parent"

examples/android/CHIPTool/app/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@
192192
<string name="wildcard_add_btn_text">Add</string>
193193
<string name="wildcard_reset_btn_text">Reset</string>
194194
<string name="wildcard_send_btn_text">Send</string>
195+
<string name="wildcard_wait_check_in_message_btn_text">Wait Check In\nexperimental ICD Queue</string>
196+
<string name="wildcard_send_when_check_in_message_btn_text">Set Send\nexperimental ICD Queue</string>
195197
<string name="wildcard_shutdown_subscription_btn_text">Shutdown Subscription</string>
196198
<string name="wildcard_subscribe_event_btn_text">Subscribe Event</string>
197199
<string name="wildcard_read_event_btn_text">Read Event</string>

0 commit comments

Comments
 (0)