Exemple #1
0
 /// <summary>
 /// Gets unified battery level state, common for all supported platform.
 /// </summary>
 /// <param name="batteryLevelStatus">Platform depended battery level state.</param>
 /// <returns>Common for all supported platform battery level state.</returns>
 public static Model.Battery.BatteryLevelStatus BatteryLevelStatusMapper(BatteryLevelStatus batteryLevelStatus)
 {
     return(BatteryLevelStatusDictionary[batteryLevelStatus]);
 }
Exemple #2
0
 /// <summary>
 /// Class constructor that allows to set values describing battery information.
 /// </summary>
 /// <param name="batteryLevel">Battery level.</param>
 /// <param name="isCharging">Charging status.</param>
 /// <param name="batteryLevelStatus">Battery level status.</param>
 public BatteryEventArgs(int batteryLevel, bool isCharging, BatteryLevelStatus batteryLevelStatus)
 {
     BatteryLevel       = batteryLevel;
     IsCharging         = isCharging;
     BatteryLevelStatus = batteryLevelStatus;
 }
        /// <summary>
        /// Method for battery feature
        /// </summary>
        private void BatterySample()
        {
            bool value;
            // Checks the battery feature is supported in this device
            var result = Information.TryGetValue <bool>("http://tizen.org/feature/battery", out value);

            if (!result || !value)
            {
                // Battery is not supported
                this.Navigation.PushAsync(new SimpleResult("Wearable doesn't support battery feature"));
                return;
            }

            try
            {
                // Gets the current battery level
                BatteryLevelStatus level = Battery.Level;
                // Gets the battery charge percentage
                int percent = Battery.Percent;
                if (percent < 0 || percent > 100)
                {
                    // Battery percent value is out of bound
                    this.Navigation.PushAsync(new SimpleResult("Failed: Battery\nBattery percent value is invalid"));
                }
                // Gets the current charging state
                bool   isCharging = Battery.IsCharging;
                string level_str, isCharing_str;

                // Gets the text of battery level value
                if (level == BatteryLevelStatus.Critical)
                {
                    level_str = "Critical";
                }
                else if (level == BatteryLevelStatus.Empty)
                {
                    level_str = "Empty";
                }
                else if (level == BatteryLevelStatus.Full)
                {
                    level_str = "Full";
                }
                else if (level == BatteryLevelStatus.High)
                {
                    level_str = "High";
                }
                else if (level == BatteryLevelStatus.Low)
                {
                    level_str = "Low";
                }
                else
                {
                    level_str = "Invalid";
                }

                // Gets the text of battery charging state
                if (isCharging)
                {
                    isCharing_str = "charging";
                }
                else
                {
                    isCharing_str = "not charging";
                }

                // Operations are succeed
                this.Navigation.PushAsync(new SimpleResult("Battery level: " + level_str + "\nPercent: " + percent + "\nBattery is " + isCharing_str));
            }
            catch (Exception e)
            {
                // Operations are failed
                this.Navigation.PushAsync(new SimpleResult("Failed: Battery\n" + e.Message));
            }
        }