-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create cluster interaction tool basic ui (#10324)
* 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
Showing
6 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...ol/app/src/main/java/com/google/chip/chiptool/clusterclient/ClusterInteractionFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/android/CHIPTool/app/src/main/res/layout/cluster_interaction_fragment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters