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
| <service | |
| android:name=".service.WearBridgeListenerService" | |
| android:exported="true"> | |
| <intent-filter> | |
| <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" /> | |
| <data android:scheme="wear" /> | |
| <data android:host="*" /> | |
| <data android:path="/request-control" /> | |
| <data android:path="/ping" /> | |
| <data android:path="/pong" /> |
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
| class WearBridgeListenerService : WearableListenerService() { | |
| private val manager by lazy { | |
| WearDataLayerManager(applicationContext, DeviceType.PHONE) | |
| } | |
| override fun onCreate() { | |
| super.onCreate() | |
| manager.refreshNodes() | |
| } |
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
| if (isRequesting) { | |
| Box( | |
| modifier = Modifier | |
| .fillMaxWidth() | |
| .padding(vertical = 2.dp), | |
| contentAlignment = Alignment.Center | |
| ) { | |
| CircularProgressIndicator(strokeWidth = 2.dp) | |
| } | |
| } else { |
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
| Chip( | |
| modifier = Modifier.fillMaxWidth(), | |
| enabled = !isRequesting, | |
| colors = ChipDefaults.primaryChipColors(), | |
| onClick = { | |
| coroutineScope.launch { | |
| showEmergency = false | |
| isRequesting = true | |
| val delivered = manager.requestControl() | |
| val success = delivered && withTimeoutOrNull(5000) { |
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
| @Composable | |
| fun WatchControlScreen(manager: WearDataLayerManager, modifier: Modifier = Modifier) { | |
| val connection by manager.connectionStatus.collectAsState() | |
| val control by manager.controlStatus.collectAsState() | |
| val profile by manager.userProfile.collectAsState() | |
| val coroutineScope = rememberCoroutineScope() | |
| var isRequesting by rememberSaveable { mutableStateOf(false) } | |
| var showEmergency by rememberSaveable { mutableStateOf(false) } | |
| val localDevice = DeviceType.WATCH |
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
| override fun onDataChanged(dataEvents: DataEventBuffer) { | |
| dataEvents.forEach { event -> | |
| when (event.type) { | |
| DataEvent.TYPE_CHANGED -> handleDataItem(event.dataItem) | |
| DataEvent.TYPE_DELETED -> handleDeletion(event.dataItem.uri) | |
| } | |
| } | |
| } |
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
| override fun onMessageReceived(event: MessageEvent) { | |
| when (event.path) { | |
| WearPaths.REQUEST_CONTROL -> { | |
| val requester = DeviceType.fromName(event.data.decodeToString()) | |
| publishControl( | |
| ControlStatus( | |
| holder = requester, | |
| emergency = false, | |
| timestamp = System.currentTimeMillis(), | |
| ) |
NewerOlder