-
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.
Implement unpairDevice API in android and chip-tool (#24127)
* Implement unpairDevice * Check restyle * Delete unused file * Add default value * Update from review * Modify from reviewer comments * Modify from comment * Fix clang-tidy validation * Change check state
- Loading branch information
1 parent
a273c81
commit 1032258
Showing
18 changed files
with
634 additions
and
6 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
60 changes: 60 additions & 0 deletions
60
.../CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/UnpairDeviceFragment.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,60 @@ | ||
package com.google.chip.chiptool.provisioning | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.lifecycleScope | ||
import chip.devicecontroller.ChipDeviceController | ||
import chip.devicecontroller.UnpairDeviceCallback | ||
import com.google.chip.chiptool.ChipClient | ||
import com.google.chip.chiptool.R | ||
import com.google.chip.chiptool.clusterclient.AddressUpdateFragment | ||
import kotlinx.android.synthetic.main.unpair_device_fragment.view.unpairDeviceBtn | ||
import kotlinx.coroutines.* | ||
|
||
class UnpairDeviceFragment : Fragment() { | ||
private val deviceController: ChipDeviceController | ||
get() = ChipClient.getDeviceController(requireContext()) | ||
|
||
private lateinit var scope: CoroutineScope | ||
|
||
private lateinit var addressUpdateFragment: AddressUpdateFragment | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
scope = viewLifecycleOwner.lifecycleScope | ||
|
||
return inflater.inflate(R.layout.unpair_device_fragment, container, false).apply { | ||
addressUpdateFragment = | ||
childFragmentManager.findFragmentById(R.id.addressUpdateFragment) as AddressUpdateFragment | ||
|
||
unpairDeviceBtn.setOnClickListener { scope.launch { unpairDeviceClick() } } | ||
} | ||
} | ||
|
||
inner class ChipUnpairDeviceCallback : UnpairDeviceCallback { | ||
override fun onError(status: Int, remoteDeviceId: Long) { | ||
Log.d(TAG, "onError : $remoteDeviceId, $status") | ||
} | ||
|
||
override fun onSuccess(remoteDeviceId: Long) { | ||
Log.d(TAG, "onSuccess : $remoteDeviceId") | ||
} | ||
} | ||
|
||
private fun unpairDeviceClick() { | ||
deviceController.unpairDeviceCallback(addressUpdateFragment.deviceId, ChipUnpairDeviceCallback()) | ||
} | ||
|
||
|
||
companion object { | ||
private const val TAG = "UnpairDeviceFragment" | ||
fun newInstance(): UnpairDeviceFragment = UnpairDeviceFragment() | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
examples/android/CHIPTool/app/src/main/res/layout/unpair_device_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,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/addressUpdateFragment" | ||
android:name="com.google.chip.chiptool.clusterclient.AddressUpdateFragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent"/> | ||
|
||
<Button | ||
android:id="@+id/unpairDeviceBtn" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="10dp" | ||
android:text="@string/unpair_device_btn_text" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/addressUpdateFragment"/> | ||
|
||
</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
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
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
Oops, something went wrong.