/// <summary> /// Starts observing battery information for changes. /// </summary> /// <remarks> /// Event BatteryInfoChanged will be never invoked before calling this method. /// </remarks> public void StartListening() { Battery.PercentChanged += (s, e) => { var batteryEventArgs = new BatteryEventArgs(e.Percent, IsCharging, BatteryLevelStatus); OnBatteryChanged(batteryEventArgs); }; Battery.ChargingStateChanged += (s, e) => { var batteryEventArgs = new BatteryEventArgs(BatteryLevel, e.IsCharging, BatteryLevelStatus); OnBatteryChanged(batteryEventArgs); }; Battery.LevelChanged += (s, e) => { var batteryEventArgs = new BatteryEventArgs(BatteryLevel, IsCharging, EnumMapper.BatteryLevelStatusMapper(e.Level)); OnBatteryChanged(batteryEventArgs); }; }
/// <summary> /// Battery property change handler. /// </summary> /// <param name="e">Event parameters.</param> protected virtual void OnBatteryChanged(BatteryEventArgs e) { BatteryInfoChanged?.Invoke(this, e); }