Beispiel #1
0
        /// <summary>
        /// Set the active watch face
        /// </summary>
        /// <param name="_item"></param>
        public async Task SetActiveWatchFace(vmWatchFace _item)
        {
            try
            {
                Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance();

                await _pc.Select(_item.Model, WatchItemType.WatchFace);

                ActiveItem = _item;
            }
            catch (Exception)
            {
            }
        }
Beispiel #2
0
        private void Initialize()
        {
            EditMode = false;

            vmWatchFace _WatchFace = new vmWatchFace();

            _WatchFace.Name      = "TicToc";
            _WatchFace.Developer = "Pebble";
            _WatchFace.ImageFile = "ms-appx:///Assets/tictoc_icon.png";
            byte[] TicTocGuid = new byte[16] {
                0x8F, 0x3C, 0x86, 0x86, 0x31, 0xA1, 0x4F, 0x5F, 0x91, 0xF5, 0x01, 0x60, 0x0C, 0x9B, 0xDC, 0x59
            };
            _WatchFace.Model = new Guid(TicTocGuid);
            WatchFaces.Add(_WatchFace);
            LoadImage(_WatchFace);

            EditCommand   = new RelayCommand(EditSwitch);
            DeleteCommand = new RelayCommand(Delete);
            BackupCommand = new RelayCommand(Backup);
        }
Beispiel #3
0
        public async void LoadImage(vmWatchFace item)
        {
            try
            {
                Windows.Storage.StorageFolder LocalFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

                item.Image = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                if (item.ImageFile.Contains("ms-app"))
                {
                    item.Image = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(item.ImageFile));
                }
                else
                {
                    Windows.Storage.StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(item.ImageFile);

                    await item.Image.SetSourceAsync(await file.OpenAsync(Windows.Storage.FileAccessMode.Read));
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("vmWatchFaces:LoadImage: " + e.Message);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Event handler for watch items
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void WatchItemListChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            //Clear all watchfaces
            case NotifyCollectionChangedAction.Reset:

                WatchFaces.Clear();

                vmWatchFace _WatchFace = new vmWatchFace();
                _WatchFace.Name      = "TicToc";
                _WatchFace.Developer = "Pebble";
                _WatchFace.ImageFile = "ms-appx:///Assets/tictoc_icon.png";
                byte[] TicTocGuid = new byte[16] {
                    0x8F, 0x3C, 0x86, 0x86, 0x31, 0xA1, 0x4F, 0x5F, 0x91, 0xF5, 0x01, 0x60, 0x0C, 0x9B, 0xDC, 0x59
                };
                _WatchFace.Model    = new Guid(TicTocGuid);
                _WatchFace.Editable = false;
                WatchFaces.Add(_WatchFace);
                LoadImage(_WatchFace);

                System.Diagnostics.Debug.WriteLine("vmWatchFaces reset. ");

                break;


            //Add viewmodel WatchFace
            case NotifyCollectionChangedAction.Add:

                Guid CurrentWatchFace = Guid.Empty;
                var  localSettings    = Windows.Storage.ApplicationData.Current.LocalSettings;
                if (localSettings.Values.ContainsKey("CurrentWatchFace"))
                {
                    CurrentWatchFace = (Guid)localSettings.Values["CurrentWatchFace"];
                }

                foreach (IWatchItem item in e.NewItems)
                {
                    if (item.Type == WatchItemType.WatchFace)
                    {
                        try
                        {
                            var vmExistingWatchFace = WatchFaces.Single(x => x.Model == item.ID);
                            WatchFaces.Remove(vmExistingWatchFace);
                        }
                        catch (Exception) { };

                        vmWatchFace _newWatchFace = new vmWatchFace();
                        _newWatchFace.Name         = item.Name;
                        _newWatchFace.Developer    = item.Developer;
                        _newWatchFace.Model        = item.ID;
                        _newWatchFace.Editable     = true;
                        _newWatchFace.Item         = item;
                        _newWatchFace.Active       = (CurrentWatchFace == item.ID);
                        _newWatchFace.ImageFile    = item.File.Replace(".zip", ".gif");
                        _newWatchFace.Configurable = item.Configurable;
                        WatchFaces.Add(_newWatchFace);
                        LoadImage(_newWatchFace);

                        if (_newWatchFace.Active)
                        {
                            ActiveItem = _newWatchFace;
                        }

                        System.Diagnostics.Debug.WriteLine("vmWatchFaces add item: " + item.Name);
                    }
                }

                //Sort
                var SortedFaces = WatchFaces.OrderBy(x => x.Name).ToList();
                WatchFaces.Clear();

                foreach (var App in SortedFaces)
                {
                    WatchFaces.Add(App);
                }

                break;

            //Remove viewmodel WatchFace
            case NotifyCollectionChangedAction.Remove:

                foreach (IWatchItem item in e.OldItems)
                {
                    if (item.Type == WatchItemType.WatchFace)
                    {
                        vmWatchFace element = null;

                        foreach (var WatchFace in WatchFaces)
                        {
                            if (WatchFace.Model == item.ID)
                            {
                                element = WatchFace;
                                break;
                            }
                        }

                        try
                        {
                            if (element != null)
                            {
                                WatchFaces.Remove(element);
                            }
                        }
                        catch (Exception) { }
                    }

                    System.Diagnostics.Debug.WriteLine("vmWatchFaces remove item: " + item.Name);
                }

                break;
            }
        }