Esempio n. 1
0
        public MainPage()
        {
            this.InitializeComponent();

            FrameLeft.Navigate(typeof(WatchFacesPage));
            FrameRight.Navigate(typeof(ConnectPage));

            /*if (IsMobile)
             * {
             *  MySplitView.CompactPaneLength = 0;
             *  FrameRight.Visibility = Visibility.Collapsed;
             *  MainGrid.ColumnDefinitions.RemoveAt(1);
             *  btnConnect.Visibility = Visibility.Visible;
             * }
             * else
             * {
             *  FrameRight.Navigate(typeof(ConnectPage));
             *  //FrameRight.Navigate(typeof(JavascriptPage));
             *  btnConnect.Visibility = Visibility.Collapsed;
             * }*/

            _vmBinder = vmBinder.GetInstance();
            // _vmBinder.PageWatchApp = true;

            Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance();
            _pc.WatchItems.WatchItemListChanged += _vmBinder.WatchFaces.WatchItemListChanged;
            _pc.WatchItems.WatchItemListChanged += _vmBinder.WatchApps.WatchItemListChanged;
            _pc.WatchItems.Load();

            DataContext = _vmBinder;

            InitialiseStore();
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the global instance of the PebbleConnector class
        /// </summary>
        /// <returns></returns>
        public static PebbleConnector GetInstance()
        {
            if (_PebbleConnector == null)
            {
                _PebbleConnector = new PebbleConnector();
            }

            return(_PebbleConnector);
        }
        /// <summary>
        /// Process the download events
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void WatchItems_OnDownloadEvent(object sender, WatchItems.WatchItems.DownloadEventArgs e)
        {
            switch (e.State)
            {
            case WatchItems.WatchItems.DownloadState.Initiate:

                Updating = true;

                break;

            case WatchItems.WatchItems.DownloadState.InProgress:

                break;

            case WatchItems.WatchItems.DownloadState.Done:

                Updating             = false;
                Item.UpdateAvailable = false;

                NotifyPropertyChanged("UpdateAvailable");

                //Set the name of the file in a localsetting
                var localSettings = ApplicationData.Current.LocalSettings;
                localSettings.Values[Constants.BackgroundCommunicatieDownloadedItem] = e.Status;

                //Start background task to sed new item to pebble
                Pebble_Time_Manager.Connector.PebbleConnector _pc = Pebble_Time_Manager.Connector.PebbleConnector.GetInstance();
                try
                {
                    await _pc.StartBackgroundTask(Connector.PebbleConnector.Initiator.AddItem);
                }
                catch (Exception exp)
                {
                    System.Diagnostics.Debug.WriteLine(exp.Message);
                }

                //Add new item to viewmodel
                WatchItems.WatchItem _newItem;
                _newItem = await WatchItems.WatchItem.Load(e.Status);

                await _pc.WatchItems.AddWatchItem((WatchItems.WatchItem) _newItem);

                Item = _newItem;

                break;

            case WatchItems.WatchItems.DownloadState.Error:

                Updating = false;

                break;

            case WatchItems.WatchItems.DownloadState.Canceled:

                break;
            }
        }
Esempio n. 4
0
        public TimeLineSynchronizer()
        {
            _Weather         = new Weather.Weather();
            _Calender        = new Calender.Calender();
            _ConnectionToken = -1;
            _pc = PebbleConnector.GetInstance();

            BackgroundTaskStatus();

            Initialize();
        }
Esempio n. 5
0
 public void StopBackgroundTask(Initiator InitiatedBy)
 {
     PebbleConnector.ClearBackgroundTaskRunningStatus(InitiatedBy);
 }
Esempio n. 6
0
        public async Task StartBackgroundTask(Initiator InitiatedBy)
        {
            /* PebbleConnector _pc = PebbleConnector.GetInstance();
             * int Handler = await _pc.Connect(-1);
             *
             * return;*/
            var result = await BackgroundExecutionManager.RequestAccessAsync();

            if (result == BackgroundAccessStatus.Denied)
            {
                return;
            }

            PebbleConnector.SetBackgroundTaskRunningStatus(InitiatedBy);

            if (!await IsBackgroundTaskRunning())
            {
                backgroundSyncTaskRegistration = FindSyncTask();
                while (backgroundSyncTaskRegistration != null)
                {
                    backgroundSyncTaskRegistration.Unregister(true);

                    backgroundSyncTaskRegistration = FindSyncTask();
                }

                //if (backgroundSyncTaskRegistration == null)
                // {
                syncBackgroundTaskTrigger = new DeviceUseTrigger();

                // Create background task to write
                var backgroundTaskBuilder = new BackgroundTaskBuilder();

                backgroundTaskBuilder.Name           = Constants.BackgroundCommunicationTaskName;
                backgroundTaskBuilder.TaskEntryPoint = Constants.BackgroundCommunicationTaskEntry;
                backgroundTaskBuilder.SetTrigger(syncBackgroundTaskTrigger);
                backgroundSyncTaskRegistration = backgroundTaskBuilder.Register();


                // }


                try
                {
                    PebbleDevice _AssociatedDevice = PebbleDevice.LoadAssociatedDevice();
                    if (_AssociatedDevice != null)
                    {
                        var _device = await BluetoothDevice.FromIdAsync(_AssociatedDevice.ServiceId);

                        //var device = (await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(new Guid(Constants.PebbleGuid))))).FirstOrDefault(y => y.Name.ToLower().Contains("pebble"));

                        if (_device == null)
                        {
                            throw new OperationCanceledException("Is bluetooth enabled and the Pebble Time paired?");
                        }

                        //DeviceTriggerResult x = await syncBackgroundTaskTrigger.RequestAsync(device.Id);

                        var abc = syncBackgroundTaskTrigger.RequestAsync(_device.DeviceId).AsTask();
                        var x   = await abc;

                        System.Diagnostics.Debug.WriteLine("DeviceTriggerResult: " + x.ToString());

                        if (x != DeviceTriggerResult.Allowed)
                        {
                            throw new Exception(x.ToString());
                        }
                    }
                }
                catch (Exception exc)
                {
                    if (exc.GetType() == typeof(System.OperationCanceledException))
                    {
                        throw exc;
                    }
                    if (exc.GetType() != typeof(System.InvalidOperationException))
                    {
                        throw new Exception("Background communication task can't be started: " + exc.Message);
                    }
                    throw new Exception("Unexpected error: " + exc.Message);
                }
            }
        }