Skip to content

Commit

Permalink
create cluster interaction tool basic ui (#10324)
Browse files Browse the repository at this point in the history
* first commit

* create two editText field and a enroll device button on the new cluster interaction tool page

* change back the unwanted changes

* revert one more change

* remove zapt generation code, also added a toast to indicate status

* fix naming for updateAddressBtn
  • Loading branch information
JasonLiuZhuoCheng authored and pull[bot] committed Nov 18, 2021
1 parent 1fdfb46 commit 1220242
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import chip.setuppayload.SetupPayload
import chip.setuppayload.SetupPayloadParser
import chip.setuppayload.SetupPayloadParser.UnrecognizedQrCodeException
import com.google.chip.chiptool.attestation.AttestationTestFragment
import com.google.chip.chiptool.clusterclient.ClusterInteractionFragment
import com.google.chip.chiptool.clusterclient.MultiAdminClientFragment
import com.google.chip.chiptool.clusterclient.OpCredClientFragment
import com.google.chip.chiptool.clusterclient.BasicClientFragment
Expand Down Expand Up @@ -112,6 +113,10 @@ class CHIPToolActivity :
showFragment(AddressCommissioningFragment.newInstance(), false)
}

override fun handleClusterInteractionClicked() {
showFragment(ClusterInteractionFragment.newInstance())
}

override fun handleOnOffClicked() {
showFragment(OnOffClientFragment.newInstance())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SelectActionFragment : Fragment() {
opCredClustersBtn.setOnClickListener{ getCallback()?.handleOpCredClicked() }
basicClusterBtn.setOnClickListener{ getCallback()?.handleBasicClicked() }
attestationTestBtn.setOnClickListener { getCallback()?.handleAttestationTestClicked() }
clusterInteractionBtn.setOnClickListener { getCallback()?.handleClusterInteractionClicked() }
}
}

Expand Down Expand Up @@ -122,6 +123,8 @@ class SelectActionFragment : Fragment() {
fun handleAttestationTestClicked()
/** Notifies listener of a click to manually input the CHIP device address.. */
fun onShowDeviceAddressInput()
/** Notifies listener of cluster interaction button click.. */
fun handleClusterInteractionClicked()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.google.chip.chiptool.clusterclient

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import chip.devicecontroller.ChipClusters
import chip.devicecontroller.ChipDeviceController
import com.google.chip.chiptool.ChipClient
import com.google.chip.chiptool.GenericChipDeviceListener
import com.google.chip.chiptool.R
import com.google.chip.chiptool.SelectActionFragment
import com.google.chip.chiptool.util.DeviceIdUtil
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
import kotlinx.android.synthetic.main.cluster_interaction_fragment.*
import kotlinx.android.synthetic.main.cluster_interaction_fragment.view.updateAddressBtn
import kotlinx.android.synthetic.main.on_off_client_fragment.commandStatusTv
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel

class ClusterInteractionFragment: Fragment() {
private val deviceController: ChipDeviceController
get() = ChipClient.getDeviceController(requireContext())

private val scope = CoroutineScope(Dispatchers.Main + Job())

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.cluster_interaction_fragment, container, false).apply {
deviceController.setCompletionListener(ChipControllerCallback())
updateAddressBtn.setOnClickListener { updateAddressClick() }
} }

private fun updateAddressClick() {
try{
deviceController.updateDevice(
fabricId.text.toString().toULong().toLong(),
deviceId.text.toString().toULong().toLong()
)
showMessage("Address update started")
} catch (ex: Exception) {
showMessage("Address update failed: $ex")
}
}

private fun showMessage(msg: String) {
requireActivity().runOnUiThread {
Toast.makeText(
requireContext(),
msg,
Toast.LENGTH_SHORT).show()
}
}

override fun onStart() {
super.onStart()
// TODO: use the fabric ID that was used to commission the device
val testFabricId = "5544332211"
fabricId.setText(testFabricId)
deviceId.setText(DeviceIdUtil.getLastDeviceId(requireContext()).toString())
}

inner class ChipControllerCallback : GenericChipDeviceListener() {
override fun onConnectDeviceComplete() {}

override fun onCommissioningComplete(nodeId: Long, errorCode: Int) {
}

override fun onNotifyChipConnectionClosed() {
Log.d(TAG, "onNotifyChipConnectionClosed")
}

override fun onCloseBleComplete() {
Log.d(TAG, "onCloseBleComplete")
}

override fun onError(error: Throwable?) {
Log.d(TAG, "onError: $error")
}
}

override fun onStop() {
super.onStop()
scope.cancel()
}

companion object {
private const val TAG = "ClusterInteractionFragment"
fun newInstance(): ClusterInteractionFragment = ClusterInteractionFragment()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/fabricId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:hint="@string/enter_fabric_id_hint_text"
android:inputType="text"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/deviceId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_alignParentEnd="true"
android:layout_toEndOf="@id/fabricId"
android:hint="@string/enter_device_id_hint_text"
android:inputType="text"
android:textSize="20sp"
app:layout_constraintStart_toEndOf="@+id/fabricId"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/updateAddressBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="23dp"
android:text="Enroll"
app:layout_constraintStart_toEndOf="@+id/deviceId"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/endpointList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:layout_marginTop="48dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fabricId" />



</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,12 @@
android:layout_marginTop="8dp"
android:visibility="gone"
android:text="@string/attestation_test_btn_text" />
<Button
android:id="@+id/clusterInteractionBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/cluster_interaction_tool" />

</LinearLayout>
1 change: 1 addition & 0 deletions src/android/CHIPTool/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<string name="sensor_client_watch_btn_text">Watch</string>
<string name="sensor_client_last_value_text">Last value: %1$.2f %2$s</string>
<string name="sensor_client_read_error_text">Failed to read the sensor: %1$s</string>
<string name="cluster_interaction_tool">Cluster Interaction Tool</string>

<string name="multi_admin_client_btn_text">Multi-admin cluster</string>
<string name="basic_commissioning_method_btn_text">Basic Commissioning Method</string>
Expand Down

0 comments on commit 1220242

Please sign in to comment.