private async Task FindServerNode() { var capabilityInfo = await WearableClass.GetCapabilityClient(this) .GetCapabilityAsync(ProtocolVersion, CapabilityClient.FilterReachable); var capableNode = capabilityInfo.Nodes.FirstOrDefault(n => n.IsNearby); if (capableNode == null) { _serverNode = null; return; } // Immediately after disconnecting from the phone, the device may still show up in the list of reachable nodes. // But since it's disconnected, any attempt to send a message will fail. // So, make sure that the phone *really* is connected before continuing. try { await WearableClass.GetMessageClient(this).SendMessageAsync(capableNode.Id, ProtocolVersion, new byte[] { }); _serverNode = capableNode; } catch (ApiException) { _serverNode = null; } }
public async Task NotifyChange() { if (!_hasWearCompanion) { return; } ICollection <INode> nodes; try { nodes = (await WearableClass.GetCapabilityClient(_context) .GetCapabilityAsync(RefreshCapability, CapabilityClient.FilterReachable)).Nodes; } catch (ApiException e) { Logger.Error(e); return; } var client = WearableClass.GetMessageClient(_context); foreach (var node in nodes) { try { await client.SendMessageAsync(node.Id, RefreshCapability, Array.Empty <byte>()); } catch (ApiException e) { Logger.Error(e); } } }
public async Task StartListening() { if (_hasWearAPIs) { await WearableClass.GetCapabilityClient(_context).AddListenerAsync(this, RefreshCapability); } }
private async Task FindServerNode() { var capabilityInfo = await WearableClass.GetCapabilityClient(this) .GetCapabilityAsync(QueryCapability, CapabilityClient.FilterReachable); _serverNode = capabilityInfo.Nodes.FirstOrDefault(n => n.IsNearby); }
protected override async void OnPause() { base.OnPause(); _timer?.Stop(); _pauseTime = DateTime.Now; if (_hasWearAPIs) { await WearableClass.GetCapabilityClient(this).RemoveListenerAsync(this, WearRefreshCapability); } }
public async Task StopListening() { if (!_hasWearApis) { return; } try { await WearableClass.GetCapabilityClient(_context).RemoveListenerAsync(this, RefreshCapability); } catch (ApiException e) { Logger.Error(e); } }
private async Task NotifyWearAppOfChange() { if (!_hasWearCompanion) { return; } var nodes = (await WearableClass.GetCapabilityClient(this) .GetCapabilityAsync(WearRefreshCapability, CapabilityClient.FilterReachable)).Nodes; var client = WearableClass.GetMessageClient(this); foreach (var node in nodes) { await client.SendMessageAsync(node.Id, WearRefreshCapability, new byte[] { }); } }
private async Task DetectWearOSCapability() { if (!_areGoogleAPIsAvailable) { _hasWearAPIs = false; _hasWearCompanion = false; return; } try { var capabiltyInfo = await WearableClass.GetCapabilityClient(this) .GetCapabilityAsync(WearRefreshCapability, CapabilityClient.FilterReachable); _hasWearAPIs = true; _hasWearCompanion = capabiltyInfo.Nodes.Count > 0; } catch (ApiException) { _hasWearAPIs = false; _hasWearCompanion = false; } }
protected override async void OnResume() { base.OnResume(); if (RequiresAuthentication()) { if ((DateTime.Now - _pauseTime).TotalMinutes >= 1) { _isAuthenticated = false; } if (!_isAuthenticated) { _refreshOnActivityResume = true; StartActivityForResult(typeof(LoginActivity), ResultLogin); return; } } // Just launched if (_connection == null) { try { _connection = await Database.Connect(this); } catch (SQLiteException) { ShowDatabaseErrorDialog(); return; } await Init(); } else if (_refreshOnActivityResume) { _refreshOnActivityResume = false; _authList.Visibility = ViewStates.Invisible; await RefreshAuthenticators(); await _categorySource.Update(); await _customIconSource.Update(); // Currently visible category has been deleted if (_authSource.CategoryId != null && _categorySource.GetView().FirstOrDefault(c => c.Id == _authSource.CategoryId) == null) { await SwitchCategory(null); } } CheckEmptyState(); // Launch task that needs to wait for the activity to resume // Useful because an activity result is called before resume if (_onceResumedTask != null) { _onceResumedTask.Start(); _onceResumedTask = null; } _timer.Start(); Tick(); var showBackupReminders = PreferenceManager.GetDefaultSharedPreferences(this) .GetBoolean("pref_showBackupReminders", true); if (showBackupReminders) { RemindBackup(); } await DetectWearOSCapability(); if (_hasWearAPIs) { await WearableClass.GetCapabilityClient(this).AddListenerAsync(this, WearRefreshCapability); } }
protected override async void OnResume() { base.OnResume(); if ((DateTime.Now - _pauseTime).TotalMinutes >= 1 && PerformLogin()) { return; } // Just launched if (_connection == null) { try { _connection = await Database.Connect(this); } catch (SQLiteException) { ShowDatabaseErrorDialog(); return; } await Init(); } else if (_isChildActivityOpen) { _isChildActivityOpen = false; _authList.Visibility = ViewStates.Invisible; await RefreshAuthenticators(); await _categorySource.Update(); // Currently visible category has been deleted if (_authenticatorSource.CategoryId != null && _categorySource.Categories.FirstOrDefault(c => c.Id == _authenticatorSource.CategoryId) == null) { await SwitchCategory(null); } } CheckEmptyState(); // Launch task that needs to wait for the activity to resume // Useful because an activity result is called before resume if (_onceResumedTask != null) { _onceResumedTask.Start(); _onceResumedTask = null; } _timer.Start(); Tick(); await DetectWearOSCapability(); if (_hasWearAPIs) { await WearableClass.GetCapabilityClient(this).AddListenerAsync(this, WearRefreshCapability); } }