示例#1
0
        async Task <BandTile> CreateTileAsync(IBandClient client)
        {
            BandTile bandTile = null;

            var tileSpace = await client.TileManager.GetRemainingTileCapacityAsync();

            if (tileSpace > 0)
            {
                var smallIcon = await TileImageUtility.MakeTileIconFromFileAsync(
                    new Uri("ms-appx:///Assets/bandSmall.png"), 24);

                var largeIcon = await TileImageUtility.MakeTileIconFromFileAsync(
                    new Uri("ms-appx:///Assets/bandLarge.png"), 48);

                TheTask.TileIdentifier = Guid.NewGuid();

                bandTile = new BandTile(TheTask.TileIdentifier)
                {
                    Name      = "Beacon",
                    TileIcon  = largeIcon,
                    SmallIcon = smallIcon
                };

                var added = await client.TileManager.AddTileAsync(bandTile);
            }
            return(bandTile);
        }
        public async Task<bool> AddTileAsync(BandTile tile)
        {
            bool result = false;
#if __ANDROID__
            result = await ActivityWrappedActionExtensions.WrapActionAsync(activity =>
            {
                return Native.AddTileTaskAsync(activity, tile.ToNative());
            });
#elif __IOS__
            try
            {
                await Native.AddTileTaskAsync(tile.ToNative());
                result = true;
            }
            catch (BandException ex)
            {
                if (ex.Code == (int)BandNSErrorCodes.UserDeclinedTile)
                {
                    result = false;
                }
                else 
                {
                    throw;
                }
            }
#elif WINDOWS_PHONE_APP
            result = await Native.AddTileAsync(tile.ToNative());
#endif
            return result;
        }
示例#3
0
            public override View GetView(int position, View convertView, ViewGroup parent)
            {
                View view = convertView;

                if (view == null)
                {
                    view = fragment.Activity.LayoutInflater.Inflate(Resource.Layout.item_tilelist, null);
                }

                BandTile tile = mList[position];

                ImageView tileImage = view.FindViewById <ImageView>(Resource.Id.imageTileListImage);
                TextView  tileTitle = view.FindViewById <TextView>(Resource.Id.textTileListTitle);

                if (tile.TileIcon != null)
                {
                    tileImage.SetImageBitmap(tile.TileIcon.Icon);
                }
                else
                {
                    BandIcon tileIcon = BandIcon.ToBandIcon(BitmapFactory.DecodeResource(fragment.Resources, Resource.Raw.badge));
                    tileImage.SetImageBitmap(tileIcon.Icon);
                }

                tileImage.SetBackgroundColor(Color.Blue);
                tileTitle.Text = tile.TileName;

                return(view);
            }
示例#4
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // all the splicing is optional as we are going to populate
            // the members/events from three different views (fragment/header/footer)

            var rootView = inflater.Inflate(Resource.Layout.fragment_tiles, container, false);

            Geneticist.Splice(this, rootView);

            var header = inflater.Inflate(Resource.Layout.fragment_tiles_header, null);

            Geneticist.Splice(this, header);

            var footer = inflater.Inflate(Resource.Layout.fragment_tiles_footer, null);

            Geneticist.Splice(this, footer);

            mListTiles.AddHeaderView(header);
            mListTiles.AddFooterView(footer);

            mTileListAdapter      = new TileListAdapter(this);
            mListTiles.Adapter    = mTileListAdapter;
            mListTiles.ItemClick += (sender, e) =>
            {
                var position = e.Position - 1; // ignore the header
                if (position >= 0 && position < mTileListAdapter.Count)
                {
                    mSelectedTile = (BandTile)mTileListAdapter.GetItem(position);
                    RefreshControls();
                }
            };

            return(rootView);
        }
示例#5
0
        public async Task LoadIconsAsync(BandTile tile)
        {
            int firstIconIndex = tile.AdditionalIcons.Count + 2;             // First 2 are used by the Tile itself

            tile.AdditionalIcons.Add(await LoadIconMethod(AdjustUriMethod("ms-appx:///Assets/smallCalling.png")));
            pageLayoutData.ById <IconData>(2).IconIndex = (ushort)(firstIconIndex + 0);
        }
示例#6
0
        private async Task RefreshData()
        {
            if (Model.Instance.Connected)
            {
                try
                {
                    var capacity = await Model.Instance.Client.TileManager.GetRemainingTileCapacityTaskAsync();

                    mRemainingCapacity = capacity;
                }
                catch (Exception e)
                {
                    mRemainingCapacity = -1;
                    Util.ShowExceptionAlert(this, "Check capacity", e);
                }

                try
                {
                    tiles = (await Model.Instance.Client.TileManager.GetTilesTaskAsync()).ToList();
//					mTileListAdapter.TileList = tiles.ToList();
                }
                catch (Exception e)
                {
                    mTiles        = null;
                    mSelectedTile = null;
                    Util.ShowExceptionAlert(this, "Get tiles", e);
                }
            }
            else
            {
                mRemainingCapacity = -1;
                mTiles             = null;
            }
        }
        private async Task AddTileToBand()
        {
            //NOTE: During debugging this makes it easier to update things.
            await bandClient.TileManager.RemoveTileAsync(tileGuid);

            // Add tile to the Band
            // The name and icons are required
            tile = new BandTile(tileGuid)
            {
                Name      = "Home Monitor",
                SmallIcon = await LoadIconAsync(uri : "ms-appx:///Assets/SmallIcon.png"),
                TileIcon  = await LoadIconAsync(uri : "ms-appx:///Assets/LargeIcon.png")
            };

            tile.PageLayouts.Add(statusLayout.Layout);
            tile.PageLayouts.Add(controlsLayout.Layout);
            tile.PageLayouts.Add(barCodeLayout.Layout);

            bool succeeded = await bandClient.TileManager.AddTileAsync(tile);

            if (!succeeded)
            {
                StatusMessage = "Failed to add UI";
            }

            // This will cause the page to display with the Open/Close buttons
            var pageData = new PageData(garageControlPageGuid, 1, controlsLayout.Data.All);
            await bandClient.TileManager.SetPagesAsync(tileGuid, pageData);
        }
示例#8
0
        async Task CreateTileOnPhoneAsync()
        {
            BandTile bandTile = null;

            var tileSpace = await this.bandClient.TileManager.GetRemainingTileCapacityAsync();

            if (tileSpace > 0)
            {
                var smallIcon = await TileImageUtility.MakeTileIconFromFileAsync(
                    new Uri("ms-appx:///Assets/tileSmall.png"), 24);

                var largeIcon = await TileImageUtility.MakeTileIconFromFileAsync(
                    new Uri("ms-appx:///Assets/tileLarge.png"), 48);

                var tileGuid = Guid.NewGuid();

                bandTile = new BandTile(tileGuid)
                {
                    Name      = "Coffee",
                    TileIcon  = largeIcon,
                    SmallIcon = smallIcon
                };
                bandTile.PageLayouts.Add(this.designedLayout.Layout);

                var added = await this.bandClient.TileManager.AddTileAsync(bandTile);

                this.storage.SetGuid(ItemType.TileId, tileGuid);
                this.storage.SetGuid(ItemType.PageId, Guid.NewGuid());

                await UpdatePageDataAsync();
            }
        }
示例#9
0
        public static async Task <BandTile> CreateTile(string tileName)
        {
            var assembly = typeof(Flowpilots.Wearables.App).GetTypeInfo().Assembly;

            BandImage smallIcon;

            using (var stream = assembly.GetManifestResourceStream("Flowpilots.Wearables.Assets.BandLogo-24x24.png"))
            {
                smallIcon = await BandImage.FromStreamAsync(stream);
            }

            BandImage tileIcon;

            using (var stream = assembly.GetManifestResourceStream("Flowpilots.Wearables.Assets.BandLogo-46x46.png"))
            {
                tileIcon = await BandImage.FromStreamAsync(stream);
            }

            // create a new Guid for the tile
            var tileGuid = Guid.NewGuid();

            // create a new tile with a new Guid
            var tile = new BandTile(tileGuid)
            {
                // enable badging (the count of unread messages)
                //IsBadgingEnabled = true,
                // set the name
                Name = tileName,
                // set the icons
                SmallIcon = smallIcon,
                Icon      = tileIcon
            };

            return(tile);
        }
示例#10
0
        private async Task CreateTileCommandExecute()
        {
            try
            {
                // Create Tile
                var tile = new BandTile(TileId)
                {
                    Icon      = TileIcon,
                    Name      = TileName,
                    SmallIcon = TileBadge,
                    IsScreenTimeoutDisabled = DisableScreenTimeout
                };

                // Tile Custom Layouts
                var layouts = CreatePageLayouts();
                tile.PageLayouts.AddRange(layouts);

                // Add Tile
                await _tileManager.AddTileAsync(tile);

                // Update with page data
                var datas = CreatePageDatas();
                await _tileManager.SetTilePageDataAsync(tile.Id, datas);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
示例#11
0
        private async void ButtonDisplayTileClick(object sender, RoutedEventArgs e)
        {
            var myTile = new BandTile(_myTileId)
            {
                Name      = "El Bruno Tile",
                TileIcon  = await LoadIcon("ms-appx:///Assets/RugbyBall46.png"),
                SmallIcon = await LoadIcon("ms-appx:///Assets/RugbyBall24.png")
            };
            var button = new TextButton()
            {
                ElementId = 1, Rect = new PageRect(10, 10, 200, 90)
            };
            var panel = new FilledPanel(button)
            {
                Rect = new PageRect(0, 0, 220, 150)
            };

            myTile.PageLayouts.Add(new PageLayout(panel));

            await _bandClient.TileManager.RemoveTileAsync(_myTileId);

            await _bandClient.TileManager.AddTileAsync(myTile);

            await _bandClient.TileManager.SetPagesAsync(_myTileId,
                                                        new PageData(new Guid("5F5FD06E-BD37-4B71-B36C-3ED9D721F200"), 0, new TextButtonData(1, "Click here")));
        }
        public NotificationsPage(BandDeviceInfo info, BandClient bandClient, BandTile tile)
            : base(info, bandClient)
        {
            InitializeComponent();

            ViewModel = new NotificationsViewModel(info, bandClient, tile);
        }
示例#13
0
        public async Task AddTile()
        {
            // Tile Definition
            var myTile = new BandTile(TileId)
            {
                Name      = "El Bruno Tile Simple",
                TileIcon  = await ImageHelper.LoadIcon("ms-appx:///Assets/RugbyBall46.png"),
                SmallIcon = await ImageHelper.LoadIcon("ms-appx:///Assets/RugbyBall24.png")
            };

            // Page UI
            var button = new TextButton
            {
                ElementId = 1,
                Rect      = new PageRect(10, 10, 200, 90)
            };
            var panel = new FilledPanel(button)
            {
                Rect = new PageRect(0, 0, 220, 150)
            };

            myTile.PageLayouts.Add(new PageLayout(panel));

            await BandHub.Instance.BandClient.TileManager.RemoveTileAsync(TileId);

            await BandHub.Instance.BandClient.TileManager.AddTileAsync(myTile);

            // Page Data
            var pageId      = new Guid("5F5FD06E-BD37-4B71-B36C-3ED9D721F200");
            var textButtonA = new TextButtonData(1, "El Button");
            var page        = new PageData(pageId, 0, textButtonA);
            await BandHub.Instance.BandClient.TileManager.SetPagesAsync(TileId, page);
        }
        async partial void ToggleCustomTileClick(UIButton sender)
        {
            if (client != null && client.IsDeviceConnected)
            {
                Output("Creating tile...");

                NSError operationError;
                var     tileName  = "A tile";
                var     tileIcon  = BandIcon.FromUIImage(UIImage.FromBundle("A.png"), out operationError);
                var     smallIcon = BandIcon.FromUIImage(UIImage.FromBundle("Aa.png"), out operationError);
                var     tile      = BandTile.Create(customId, tileName, tileIcon, smallIcon, out operationError);

                var textBlock = new BandTextBlock(BandRect.Create(0, 0, 230, 40), BandTextBlockFont.Small, 25);
                textBlock.ElementId           = 10;
                textBlock.HorizontalAlignment = BandPageElementHorizontalAlignment.Left;
                textBlock.BaselineAlignment   = BandTextBlockBaselineAlignment.Absolute;
                textBlock.Color = BandColor.FromRgb(0xff, 0xff, 0xff);

                var barcode = new BandBarcode(BandRect.Create(0, 5, 230, 95), BandBarcodeType.CODE39);
                barcode.ElementId = 11;
                barcode.Color     = BandColor.FromRgb(0xff, 0xff, 0xff);

                var flowList = new BandFlowList(BandRect.Create(15, 0, 260, 105), BandFlowListOrientation.Vertical);
                flowList.Margins = BandMargins.Create(0, 0, 0, 0);
                flowList.Color   = null;
                flowList.Children.Add(textBlock);
                flowList.Children.Add(barcode);

                var pageLaypout = new BandPageLayout();
                pageLaypout.Root = flowList;
                tile.PageLayouts.Add(pageLaypout);

                try {
                    Output("Adding tile...");
                    await client.TileManager.AddTileTaskAsync(tile);
                } catch (BandException ex) {
                    Output("Error: " + ex.Message);
                }

                try {
                    Output("Creating page...");
                    var pageValues = new BandPageElementData [] {
                        BandPageBarcodeCode39Data.Create(11, "A1 B", out operationError),
                        BandPageTextData.Create(10, "Barcode value: A1 B", out operationError)
                    };
                    var page = BandPageData.Create(pageId, 0, pageValues);

                    await client.TileManager.SetPagesTaskAsync(new[] { page }, customId);

                    Output("Completed custom page!");
                } catch (BandException ex) {
                    Output("Error: " + ex.Message);
                }
            }
            else
            {
                Output("Band is not connected. Please wait....");
            }
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            this.viewModel.StatusMessage = "Running ...";

            try
            {
                // Get the list of Microsoft Bands paired to the phone.
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
                if (pairedBands.Length < 1)
                {
                    this.viewModel.StatusMessage = "This sample app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                    return;
                }

                // Connect to Microsoft Band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {
                    // Create a Tile.
                    // WARNING! This tile guid is only an example. Please do not copy it to your test application;
                    // always create a unique guid for each application.
                    // If one application installs its tile, a second application using the same guid will fail to install
                    // its tile due to a guid conflict. In the event of such a failure, the text of the exception will not
                    // report that the tile with the same guid already exists on the band.
                    // There might be other unexpected behavior.
                    Guid myTileId = new Guid("06CF1D20-81F5-4200-AA8B-C694BAFDA0A8");
                    BandTile myTile = new BandTile(myTileId)
                    {
                        Name = "My Tile",
                        TileIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png"),
                        SmallIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png")
                    };

                    // Remove the Tile from the Band, if present. An application won't need to do this everytime it runs. 
                    // But in case you modify this sample code and run it again, let's make sure to start fresh.
                    await bandClient.TileManager.RemoveTileAsync(myTileId);
                    
                    // Check if there is space for your tile on the band before adding it.
                    if (await bandClient.TileManager.GetRemainingTileCapacityAsync() > 0)
                    {
                        // Create the Tile on the Band.
                        await bandClient.TileManager.AddTileAsync(myTile);

                        // Send a notification.
                        await bandClient.NotificationManager.SendMessageAsync(myTileId, "Microsoft Band", "Hello World !", DateTimeOffset.Now, MessageFlags.ShowDialog);

                        this.viewModel.StatusMessage = "Done. Check the Tile on your Band (it's the last Tile).";
                    }
                    else
                    {
                        this.viewModel.StatusMessage = "No space on the band for your tile, remove a tile and try again.";
                    }
                }
            }
            catch (Exception ex)
            {
                this.viewModel.StatusMessage = ex.ToString();
            }
        }
示例#16
0
        public async Task <bool> AddTileAsync(BandTile tile, CancellationToken token)
        {
            if (tile == null)
            {
                throw new ArgumentNullException("tile");
            }
            if (string.IsNullOrWhiteSpace(tile.Name))
            {
                throw new ArgumentException(BandResource.BandTileEmptyName, "tile");
            }
            if (tile.SmallIcon == null)
            {
                throw new ArgumentException(BandResource.BandTileNoSmallIcon, "tile");
            }
            if (tile.TileIcon == null)
            {
                throw new ArgumentException(BandResource.BandTileNoTileIcon, "tile");
            }
            if (tile.AdditionalIcons.Count + 2 > _constants.BandTypeConstants.MaxIconsPerTile)
            {
                throw new ArgumentException(BandResource.BandTileTooManyIcons, "tile");
            }
            if (tile.PageLayouts.Count > 5)
            {
                throw new ArgumentException(BandResource.BandTileTooManyTemplates, "tile");
            }
            foreach (PageLayout layout in tile.PageLayouts)
            {
                if (layout == null)
                {
                    throw new InvalidOperationException(BandResource.BandTileNullTemplateEncountered);
                }
                // TODO: add this back...
                //if (layout.GetSerializedByteCountAndValidate() > 768)
                //{
                //    throw new ArgumentException(BandResource.BandTilePageTemplateBlobTooBig);
                //}
            }

            await Task.Delay(500);

            // We will only run against one app so don't need much complexity here (would be nice at some
            // point to be able the client to be able to test against a pre-configured setup of app tiles
            // on the band though)

            // request consent from user (TODO: make this a configurable property).
            // generate application ID which identifies the application package
            //var package = System.Windows.ApplicationModel.Package.current;
            var appId = _appIdProvider.GetAppId(); // TODO: Fix this - all this to be configured

            // store that against the tile...
            var tr = new TileRepresentation(tile.ToTileData(_tiles.GetCount(), appId), null);

            _tiles.AddTile(tr);

            return(true);
        }
示例#17
0
        public async Task <bool> RemoveTileAsync(BandTile tile, CancellationToken token)
        {
            await Task.Run(() =>
            {
                _tiles.RemoveTile(tile);
            }, token);

            return(true);
        }
示例#18
0
        private async Task <bool> AddTile()
        {
            try
            {
                // Create the small and tile icons from writable bitmaps.
                // Small icons are 24x24 pixels.
                //WriteableBitmap smallIconBitmap = new WriteableBitmap(24, 24);
                //BandIcon smallIcon = smallIconBitmap.ToBandIcon();
                //// Tile icons are 46x46 pixels for Microsoft Band 1, and 48x48 pixels
                //// for Microsoft Band 2.
                //WriteableBitmap tileIconBitmap = new WriteableBitmap(46, 46);
                //BandIcon tileIcon = tileIconBitmap.ToBandIcon();

                int version = Convert.ToInt32(bandVersion);

                if (version <= 19)
                {
                    BandIcon tileIcon = await ConvertIMG("ms-appx:///Assets/46x46.png");

                    BandIcon smallIcon = await ConvertIMG("ms-appx:///Assets/24x24.png");
                }
                else
                {
                    BandIcon tileIcon = await ConvertIMG("ms-appx:///Assets/48x48.png");

                    BandIcon smallIcon = await ConvertIMG("ms-appx:///Assets/24x24.png");
                }



                var myTile = new BandTile(myTileId)
                {
                    IsBadgingEnabled = true,
                    Name             = "MS Band Data Collection",
                    //TileIcon = tileIcon,
                    //SmallIcon = smallIcon
                    TileIcon  = tileIcon,
                    SmallIcon = smallIcon
                };

                // Remove the Tile from the Band, if present. An application won't need to do this everytime it runs.
                // But in case you modify this sample code and run it again, let's make sure to start fresh.
                //await bandClient.TileManager.RemoveTileAsync(myTileId);

                // Create the Tile on the Band.
                await bandClient.TileManager.AddTileAsync(myTile);

                // Subscribe to Tile events.
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error on adding a tile to the band:  " + ex);
                await c.saveStringToLocalFile("DebugLogs.txt", "TimeStamp: " + BandController.CurrentDate() + " Debug: " + " Error on adding a tile to the band - " + ex);
            }
            return(false);
        }
示例#19
0
        public override void OnAppearing(object navigationContext)
        {
            var notificationData = navigationContext as NotificationData;

            BandClient           = notificationData.BandClient;
            _tile                = notificationData.Tile;
            _notifiactionManager = BandClient.NotificationManager;

            base.OnAppearing(navigationContext);
        }
        public AddTilePage(BandDeviceInfo info, BandClient bandClient, BandTile tile)
            : base(info, bandClient)
        {
            InitializeComponent();

            addTileViewModel = new AddTileViewModel(info, bandClient, tile);

            Init();

            ViewModel = addTileViewModel;
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="tile">アプリタイル</param>
        public NativeBandTile(BandTile tile)
        {
            this.tile = tile;

            this.tileId         = tile.TileId;
            this.tileIconSource = NativeBandImageConvert.FromNative(tile.TileIcon);

            if (tile.SmallIcon != null)
            {
                this.smallIconSource = NativeBandImageConvert.FromNative(tile.SmallIcon);
            }
        }
示例#22
0
        /// <summary>
        /// Creates the custom band tile.
        /// </summary>
        /// <param name="tileDefinition">The tile definition.</param>
        protected virtual async Task CreateCustomBandTileAsync(ICustomBandTile tileDefinition)
        {
            try
            {
                // Construct tile
                var tile = new BandTile(tileDefinition.Guid)
                {
                    Name      = tileDefinition.Name,
                    TileIcon  = await LoadIconAsync(tileDefinition.LargeIconPath),
                    SmallIcon = await LoadIconAsync(tileDefinition.SmallIconPath)
                };

                // Construct layouts
                var indexCounter  = 0;
                var layoutIndexes = new Dictionary <Guid, int>();
                foreach (var layoutDefinition in tileDefinition.Layouts)
                {
                    // Add to tile page layouts
                    tile.PageLayouts.Add(layoutDefinition.Value.Layout);

                    // Load icons
                    await layoutDefinition.Value.LoadIconsAsync(tile);

                    // Assign index
                    layoutIndexes.Add(layoutDefinition.Key, indexCounter++);
                }

                // Remove existing tile
                if (await this.IsTileInstalledAsync(tileDefinition.Guid))
                {
                    await this.bandConnectionsManager.BandClient.TileManager.RemoveTileAsync(tileDefinition.Guid);
                }

                // Add tile
                await this.bandConnectionsManager.BandClient.TileManager.AddTileAsync(tile);

                // Populate with default data
                await this.bandConnectionsManager.BandClient.TileManager.SetPagesAsync(
                    tileDefinition.Guid,
                    tileDefinition.Layouts.Select(layoutDefinition => new PageData(
                                                      layoutDefinition.Key,
                                                      layoutIndexes[layoutDefinition.Key],
                                                      layoutDefinition.Value.Data.All)));
            }
            catch (Exception ex)
            {
                this.logger.Error(ex, "Failed to create tile.");
            }
        }
示例#23
0
        public static BandTile FromNative(this NativeBandTile tile)
        {
#if __ANDROID__
            var bandTile = new BandTile(tile.TileId.FromNative())
            {
                Name = tile.TileName,
                Icon = BandImage.FromBitmap(tile.TileIcon.Icon)
            };
            if (tile.TileSmallIcon != null)
            {
                bandTile.SmallIcon = BandImage.FromBitmap(tile.TileSmallIcon.Icon);
            }
            if (tile.Theme != null)
            {
                bandTile.Theme = tile.Theme.FromNative();
            }
            return(bandTile);
#elif __IOS__
            var bandTile = new BandTile(tile.TileId.FromNative())
            {
                Name = tile.Name,
                Icon = BandImage.FromUIImage(tile.TileIcon.UIImage)
            };
            if (tile.SmallIcon != null)
            {
                bandTile.SmallIcon = BandImage.FromUIImage(tile.SmallIcon.UIImage);
            }
            if (tile.Theme != null)
            {
                bandTile.Theme = tile.Theme.FromNative();
            }
            return(bandTile);
#elif WINDOWS_PHONE_APP
            var bandTile = new BandTile(tile.TileId.FromNative())
            {
                Name = tile.Name,
                Icon = BandImage.FromWriteableBitmap(tile.TileIcon.ToWriteableBitmap())
            };
            if (tile.SmallIcon != null)
            {
                bandTile.SmallIcon = BandImage.FromWriteableBitmap(tile.SmallIcon.ToWriteableBitmap());
            }
            if (tile.Theme != null)
            {
                bandTile.Theme = tile.Theme.FromNative();
            }
            return(bandTile);
#endif
        }
示例#24
0
        private async void OnAddTileClick(object sender, EventArgs e)
        {
            try
            {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.InScaled = false;
                BandIcon tileIcon  = BandIcon.ToBandIcon(BitmapFactory.DecodeResource(Resources, Resource.Raw.tile, options));
                BandIcon badgeIcon = BandIcon.ToBandIcon(BitmapFactory.DecodeResource(Resources, Resource.Raw.badge, options));

                BandTile.Builder builder = new BandTile.Builder(Java.Util.UUID.RandomUUID(), mEditTileName.Text, tileIcon);
                if (mCheckboxBadging.Checked)
                {
                    builder.SetTileSmallIcon(badgeIcon);
                }
                if (mCheckboxCustomTheme.Checked)
                {
                    builder.SetTheme(mThemeView.Theme);
                }
                BandTile tile = builder.Build();

                try
                {
                    var result = await Model.Instance.Client.TileManager.AddTileTaskAsync(Activity, tile);

                    if (result)
                    {
                        Toast.MakeText(Activity, "Tile added", ToastLength.Short).Show();
                    }
                    else
                    {
                        Toast.MakeText(Activity, "Unable to add tile", ToastLength.Short).Show();
                    }
                }
                catch (Exception ex)
                {
                    Util.ShowExceptionAlert(Activity, "Add tile", ex);
                }

                // Refresh our tile list and count
                await RefreshData();

                RefreshControls();
            }
            catch (Exception ex)
            {
                Util.ShowExceptionAlert(Activity, "Add tile", ex);
            }
        }
        async partial void ToggleAppTileClick(UIButton sender)
        {
            if (_client != null && _client.IsDeviceConnected)
            {
                Output("Creating tile...");

                // the number of tile spaces left
                var capacity = await _client.TileManager.RemainingTileCapacityTaskAsync();

                Output("Remaning tile space: " + capacity);

                // create the tile
                NSError      operationError;
                const string tileName  = "CRM Notifications";
                var          tileIcon  = BandIcon.FromUIImage(UIImage.FromBundle("CRM.png"), out operationError);
                var          smallIcon = BandIcon.FromUIImage(UIImage.FromBundle("CRMb.png"), out operationError);
                var          tile      = BandTile.Create(TileId, tileName, tileIcon, smallIcon, out operationError);

                // get the tiles
                try
                {
                    var tiles = await _client.TileManager.GetTilesTaskAsync();

                    if (tiles.Any(x => x.TileId.AsString() == TileId.AsString()))
                    {
                        // a tile exists, so remove it
                        await _client.TileManager.RemoveTileTaskAsync(TileId);

                        Output("Removed tile!");
                    }
                    else
                    {
                        // the tile does not exist, so add it
                        await _client.TileManager.AddTileTaskAsync(tile);

                        Output("Added tile!");
                    }
                }
                catch (BandException ex)
                {
                    Output("Error: " + ex.Message);
                }
            }
            else
            {
                Output("Band is not connected. Please wait....");
            }
        }
        private async Task setupBand()
        {
            band = clientViewModel.BandClient;
            var newTiles = (await band.TileManager.GetTilesAsync());

            foreach (var item in newTiles)
            {
                if (item.Name == "New Tile")
                {
                    tile = item;
                }
            }
            //Debug.WriteLine("loading tiles");
            //tile = newTiles.Where(n => newTiles.All(o => o.Name == "New Tile")).First();
            //Debug.WriteLine("found tile");
        }
示例#27
0
        private async void AddTileButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (canSetTile)
            {
                BandTile tile = await CreateTile();

                if (await CreateLayout(tile))
                {
                    resultText.Text = "Tile added successfuly";
                }
                else
                {
                    resultText.Text = "Something wrong, debug this Hello App";
                }
            }
        }
示例#28
0
        public async void TileManager_SetNewTile()
        {
            var bandClient = await TestUtils.GetBandClientAsync();

            // create a new Guid for the tile
            Guid tileGuid = Guid.NewGuid();

            // Create the small and tile icons from writable bitmaps.
            // Small icons are 24x24 pixels.
            WriteableBitmap smallIconBitmap = new WriteableBitmap(24, 24);
            BandIcon        smallIcon       = smallIconBitmap.ToBandIcon();

            // Tile icons are 46x46 pixels for Microsoft Band 1, and 48x48 pixels
            // for Microsoft Band 2.
            WriteableBitmap tileIconBitmap = new WriteableBitmap(46, 46);
            BandIcon        tileIcon       = tileIconBitmap.ToBandIcon();

            // create a new tile
            BandTile tile = new BandTile(tileGuid)
            {
                // set the name
                Name = "MyTile",

                // set the icons
                SmallIcon = smallIcon,
                TileIcon  = tileIcon
            };

            // get the current set of tiles
            try
            {
                // add the tile to the Band
                if (await bandClient.TileManager.AddTileAsync(tile))
                {
                    // tile was successfully added
                    // can proceed to set tile content with SetPagesAsync
                }
                else
                {
                    // tile failed to be added, handle error
                }
            }
            catch (BandException ex)
            {
                // handle a Band connection exception }
            }
        }
示例#29
0
        public static NativeBandTile ToNative(this BandTile tile)
        {
#if __ANDROID__
            var icon = NativeBandIcon.ToBandIcon(tile.Icon.ToBitmap());
            using (var builder = new NativeBandTile.Builder(tile.Id.ToNative(), tile.Name, icon))
            {
                if (tile.IsCustomThemeEnabled)
                {
                    builder.SetTheme(tile.Theme.ToNative());
                }
                if (tile.IsBadgingEnabled)
                {
                    icon = NativeBandIcon.ToBandIcon(tile.SmallIcon.ToBitmap());
                    builder.SetTileSmallIcon(icon);
                }
                return(builder.Build());
            }
#elif __IOS__
            // TODO: iOS - SmallIcon may not be optional
            Foundation.NSError error;
            var icon      = NativeBandIcon.FromUIImage(tile.Icon.ToUIImage(), out error);
            var smallIcon = tile.IsBadgingEnabled ? NativeBandIcon.FromUIImage(tile.SmallIcon.ToUIImage(), out error) : null;
            var bandTile  = NativeBandTile.Create(tile.Id.ToNative(), tile.Name, icon, smallIcon, out error);
            bandTile.BadgingEnabled = tile.IsBadgingEnabled;
            if (tile.IsCustomThemeEnabled)
            {
                bandTile.Theme = tile.Theme.ToNative();
            }
            return(bandTile);
#elif WINDOWS_PHONE_APP
            var bandTile = new NativeBandTile(tile.Id.ToNative())
            {
                Name     = tile.Name,
                TileIcon = tile.Icon.ToWriteableBitmap().ToBandIcon()
            };
            if (tile.IsCustomThemeEnabled)
            {
                bandTile.Theme = tile.Theme.ToNative();
            }
            if (tile.IsBadgingEnabled)
            {
                bandTile.SmallIcon        = tile.SmallIcon.ToWriteableBitmap().ToBandIcon();
                bandTile.IsBadgingEnabled = true;
            }
            return(bandTile);
#endif
        }
示例#30
0
        private async void OnRemoveTileClick(object sender, EventArgs e)
        {
            try
            {
                await Model.Instance.Client.TileManager.RemoveTileTaskAsync(mSelectedTile.TileId);

                mSelectedTile = null;
                Toast.MakeText(Activity, "Tile removed", ToastLength.Short).Show();
                await RefreshData();

                RefreshControls();
            }
            catch (Exception ex)
            {
                Util.ShowExceptionAlert(Activity, "Remove tile", ex);
            }
        }
        /// <summary>
        /// Connect to Microsoft Band and read Accelerometer data.
        /// </summary>
        public async void GetTemp(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get the list of Microsoft Bands paired to the phone.
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();

                if (pairedBands.Length < 1)
                {
                    this.warnings.Text = "This sample app requires a Microsoft Band paired to your phone. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                    return;
                }

                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {
                    // normally wouldn't do it this way obviously
                    bandClientCopy = bandClient;

                    tilesRemaining = await bandClient.TileManager.GetRemainingTileCapacityAsync();

                    if (tilesRemaining > 0)
                    {
                        Guid     myTileId = new Guid(tileId);
                        BandTile myTile   = new BandTile(myTileId)
                        {
                            Name             = "My Tile",
                            IsBadgingEnabled = true,
                            TileIcon         = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png"),
                            SmallIcon        = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png")
                        };
                        //await bandClient.TileManager.AddTileAsync(myTile);
                    }

                    bandClient.SensorManager.SkinTemperature.ReadingChanged += SkinTemperature_ReadingChanged;
                    await bandClient.SensorManager.SkinTemperature.StartReadingsAsync();

                    await Task.Delay(TimeSpan.FromMinutes(1));

                    await bandClient.SensorManager.SkinTemperature.StopReadingsAsync();
                }
            }
            catch (Exception ex)
            {
                this.warnings.Text = ex.ToString();
            }
        }