private void DisableDisplayOnOffController() { if (_displayController != null) { _displayController.Dispose(); // closes the controller _displayController = null; } }
private void EnableDisplayOnOffController() { if (_sensor != null && _displayController == null) { // Acquires the display on/off controller for this proximity sensor. // This tells the system to use the sensor's IsDetected state to // turn the screen on or off. If the display does not support this // feature, this code will do nothing. _displayController = _sensor.CreateDisplayOnOffController(); } }
/// <summary> /// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame. /// </summary> /// <param name="e"> /// Event data that can be examined by overriding code. The event data is representative /// of the navigation that will unload the current Page unless canceled. The /// navigation can potentially be canceled by setting Cancel. /// </param> protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { if (ScenarioDisableButton.IsEnabled) { if (null != displayController) { displayController.Dispose(); // closes the controller displayController = null; } } base.OnNavigatingFrom(e); }
private async Task AttachAsync() { if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1)) { var devices = await DeviceInformation.FindAllAsync(ProximitySensor.GetDeviceSelector()); if (devices.Count > 0) { _sensor = ProximitySensor.FromId(devices[0].Id); //_sensor.ReadingChanged += OnReadingChanged; _controller = _sensor.CreateDisplayOnOffController(); } } }
/// <summary> /// This is the click handler for the 'Disable' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ScenarioDisable(object sender, RoutedEventArgs e) { // Releases the display on/off controller that is previously acquired. // This tells the system to stop using the sensor's IsDetected state to // turn the screen on or off. If the display does not support this // feature, this code will do nothing. if (null != displayController) { displayController.Dispose(); // closes the controller displayController = null; } ScenarioEnableButton.IsEnabled = true; ScenarioDisableButton.IsEnabled = false; }
public void EnableDisplayAutoOff(bool _enabled) { if (_enabled) { if ((_sensor != null) && (_displayController == null)) { _displayController = _sensor.CreateDisplayOnOffController(); } } else { if (_displayController != null) { _displayController.Dispose(); _displayController = null; } } }
/// <summary> /// This is the click handler for the 'Enable' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ScenarioEnable(object sender, RoutedEventArgs e) { if (null != sensor) { // Acquires the display on/off controller for this proximity sensor. // This tells the system to use the sensor's IsDetected state to // turn the screen on or off. If the display does not support this // feature, this code will do nothing. displayController = sensor.CreateDisplayOnOffController(); ScenarioEnableButton.IsEnabled = false; ScenarioDisableButton.IsEnabled = true; } else { rootPage.NotifyUser("No proximity sensors found", NotifyType.ErrorMessage); } }