Created
March 25, 2020 22:52
-
-
Save jcbribeiro/e349457d5298d05d1b90c65f713d7174 to your computer and use it in GitHub Desktop.
remove and query fences
This file contains hidden or 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
| fun onClick_button_remove(view: View?) { | |
| removeFences() | |
| } | |
| private fun removeFences() { | |
| Awareness.getFenceClient(this).updateFences( | |
| FenceUpdateRequest.Builder() | |
| .removeFence(myPendingIntent) | |
| .build() | |
| ) | |
| .addOnSuccessListener { | |
| val timestamp = Timestamp(System.currentTimeMillis()) | |
| val text = "[Fences @ $timestamp] Fences were successfully removed.".trimIndent() | |
| textViewMain.text = text + "\n" + textViewMain.text | |
| } | |
| .addOnFailureListener { e -> | |
| val timestamp = Timestamp(System.currentTimeMillis()) | |
| val text = "[Fences @ $timestamp] Fences could not be removed: ${e.message}".trimIndent() | |
| textViewMain.text = text + "\n" + textViewMain.text | |
| } | |
| } | |
| fun onClick_button_query(view: View?) { | |
| queryFences() | |
| } | |
| protected fun queryFences() { | |
| Awareness.getFenceClient(this).queryFences(FenceQueryRequest.all()) | |
| .addOnSuccessListener { fenceQueryResponse -> | |
| var fenceInfo = "" | |
| val fenceStateMap = fenceQueryResponse.fenceStateMap | |
| for (fenceKey in fenceStateMap.fenceKeys) { | |
| val state = fenceStateMap.getFenceState(fenceKey).currentState | |
| fenceInfo += "$fenceKey: ${if (state == FenceState.TRUE) "TRUE" else if (state == FenceState.FALSE) "FALSE" else "UNKNOWN"}".trimIndent() | |
| } | |
| val timestamp = Timestamp(System.currentTimeMillis()) | |
| val text = "[Fences @ $timestamp]> Fences' states: ${if (fenceInfo == "") "No registered fences." else fenceInfo}".trimIndent() | |
| textViewMain.text = text + "\n" + textViewMain.text | |
| } | |
| .addOnFailureListener { e -> | |
| val timestamp = Timestamp(System.currentTimeMillis()) | |
| val text = "[Fences @ $timestamp] Fences could not be queried: ${e.message}".trimIndent() | |
| textViewMain.text = text + "\n" + textViewMain.text | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment