Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Background;
using Windows.Data.Xml.Dom;
using Windows.Phone.Devices.Power;
using Windows.UI.Notifications;

namespace WindowsRuntimeComponent1
{
    public sealed class BatteryBackgroundTask : IBackgroundTask
    {
        
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            Battery bat = Battery.GetDefault();
             var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

             if (bat.RemainingChargePercent < 20 && (localSettings.Values["EnableBatteryCheck"] == null || (bool)localSettings.Values["EnableBatteryCheck"] ) )
            {
                showToastNotification("Batteria al " + bat.RemainingChargePercent+"%", "Usa SmartCharging!");
            }
            
        }

        private void registration_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
        {
           


        }

        async void RegisterBackgrountTasks()
        {
            var access = await BackgroundExecutionManager.RequestAccessAsync();
        }

        private void showToastNotification(string line1, string line2)
        {   ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText02;  
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].AppendChild(toastXml.CreateTextNode(line1));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(line2));

            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
            ((XmlElement)toastNode).SetAttribute("duration", "long");

            ToastNotification toast = new ToastNotification(toastXml);
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
    }
}

Commits for Nextrek/Android/SmartCharging/SmartCharging_WP/WindowsRuntimeComponent1/BatteryBackgroundTask.cs

Diff revisions: vs.
Revision Author Commited Message
799 JMBauan picture JMBauan Thu 08 Oct, 2015 13:36:32 +0000