Esempio n. 1
0
 void showBatteryInfo(double chargeLevel, BatteryPowerSource batteryPowerSource, BatteryState batteryState)
 {
     labelBatteryInfo.Text = string.Format("Batterieladung {0}%{3}PowerSource {1}{3}Status {2}",
                                           100.0 * chargeLevel,
                                           batteryPowerSource.ToString(),
                                           batteryState.ToString(),
                                           System.Environment.NewLine);
 }
Esempio n. 2
0
        public void GetBatteryInfo()
        {
            BatteryChargeLevel = Battery.ChargeLevel * 100; // Returns battery charge level in percents.

            BatteryState = Battery.State;

            switch (BatteryState)
            {
            case BatteryState.Charging:
                // Currently charging
                break;

            case BatteryState.Full:
                // Battery is full
                break;

            case BatteryState.Discharging:
            case BatteryState.NotCharging:
                // Currently discharging battery or not being charged
                break;

            case BatteryState.NotPresent:
            // Battery doesn't exist in device (desktop computer)
            case BatteryState.Unknown:
                // Unable to detect battery state
                break;
            }

            BatterySource = Battery.PowerSource;

            switch (BatterySource)
            {
            case BatteryPowerSource.Battery:
                // Being powered by the battery
                break;

            case BatteryPowerSource.AC:
                // Being powered by A/C unit
                break;

            case BatteryPowerSource.Usb:
                // Being powered by USB cable
                break;

            case BatteryPowerSource.Wireless:
                // Powered via wireless charging
                break;

            case BatteryPowerSource.Unknown:
                // Unable to detect power source
                break;
            }
        }
        public BatteryViewModel()
        {
            battery = new BatteryModel()
            {
                Level  = Battery.ChargeLevel,
                State  = Battery.State,
                Source = Battery.PowerSource
            };

            Battery.BatteryInfoChanged += (s, e) =>
            {
                StatusChangeCommand.Execute(e);
            };

            StatusChangeCommand = new Command <BatteryInfoChangedEventArgs>((e) =>
            {
                Level  = e.ChargeLevel;
                State  = e.State;
                Source = e.PowerSource;
            });
        }
Esempio n. 4
0
        public BateriaViewModel()
        {
            bateria = new Bateria()
            {
                Nivel  = Battery.ChargeLevel,
                Estado = Battery.State,
                Fuente = Battery.PowerSource
            };

            Battery.BatteryChanged += (s, e) =>
            {
                CambioStatusCommand.Execute(e);
            };

            CambioStatusCommand = new Command <BatteryChangedEventArgs>((e) =>
            {
                Nivel  = e.ChargeLevel;
                Estado = e.State;
                Fuente = e.PowerSource;
            });
        }
Esempio n. 5
0
 internal BatteryChangedEventArgs(double level, BatteryState state, BatteryPowerSource source)
 {
     ChargeLevel = level;
     State       = state;
     PowerSource = source;
 }
Esempio n. 6
0
 static void OnBatteryChanged(double level, BatteryState state, BatteryPowerSource source)
 => OnBatteryChanged(new BatteryChangedEventArgs(level, state, source));
Esempio n. 7
0
 static void SetCurrent()
 {
     currentLevel  = Battery.ChargeLevel;
     currentSource = Battery.PowerSource;
     currentState  = Battery.State;
 }
Esempio n. 8
0
        void showActualBatteryState(double chargeLevel,
                                    BatteryPowerSource batteryPowerSource,
                                    BatteryState batteryState,
                                    EnergySaverStatus energySaverStatus)
        {
            labelCharge.Text = string.Format("{0}%", chargeLevel * 100);

            switch (batteryPowerSource)
            {
            case BatteryPowerSource.Battery:
                labelPowerSource.Text = "Batterie";
                break;

            case BatteryPowerSource.AC:
                labelPowerSource.Text = "Stromnetz";
                break;

            case BatteryPowerSource.Usb:
                labelPowerSource.Text = "USB-Anschluss";
                break;

            case BatteryPowerSource.Wireless:
                labelPowerSource.Text = "drahtlos";
                break;

            case BatteryPowerSource.Unknown:
                labelPowerSource.Text = "unbekannt";
                break;
            }

            switch (batteryState)
            {
            case BatteryState.Full:             // 5
                labelBatteryState.Text = "voll geladen";
                break;

            case BatteryState.Discharging:      // 3
                labelBatteryState.Text = "wird entladen";
                break;

            case BatteryState.Charging:         // 2
                labelBatteryState.Text = "wird geladen";
                break;

            case BatteryState.NotCharging:      // 4
                labelBatteryState.Text = "wird NICHT geladen";
                break;

            case BatteryState.NotPresent:
                labelBatteryState.Text = "keine Batterie vorhanden";
                break;

            case BatteryState.Unknown:
                labelBatteryState.Text = "unbekannt";
                break;
            }

            switch (energySaverStatus)
            {
            case EnergySaverStatus.Off:
                labelEnergySaverStatus.Text = "aus";
                break;

            case EnergySaverStatus.On:
                labelEnergySaverStatus.Text = "ein";
                break;

            case EnergySaverStatus.Unknown:
                labelEnergySaverStatus.Text = "unbekannt";
                break;
            }

            DependencyService.Get <IBatteryInfo>().GetAndroidBatteryExtendedData(out int health, out float temperature, out string technology, out long chargetimeremaining);
            string sHealth;

            switch (health)
            {
            case 1: // BATTERY_HEALTH_UNKNOWN
            default:
                sHealth = "unbekannt";
                break;

            case 2: // BATTERY_HEALTH_GOOD
                sHealth = "gut";
                break;

            case 3: // BATTERY_HEALTH_OVERHEAT
                sHealth = "schlecht (überhitzt)";
                break;

            case 4: // BATTERY_HEALTH_DEAD
                sHealth = "schlecht";
                break;

            case 5: // BATTERY_HEALTH_OVER_VOLTAGE
                sHealth = "schlecht (überladen)";
                break;

            case 6: // BATTERY_HEALTH_UNSPECIFIED_FAILURE
                sHealth = "Fehler";
                break;

            case 7: // BATTERY_HEALTH_COLD
                sHealth = "gut (kalt)";
                break;
            }

            string sChargetimeremaining = "";

            if (chargetimeremaining > 0)
            {
                sChargetimeremaining = ", verbleidende Ladezeit " + (chargetimeremaining / 60000).ToString() + " min";
            }

            labelExtendedData.Text = string.Format("„Batteriegesundheit“ {0}, Temperatur {1}°C{2}, {3}",
                                                   sHealth,
                                                   temperature / 10,
                                                   sChargetimeremaining,
                                                   technology);
        }