Beispiel #1
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);
            }
        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....");
            }
        }
Beispiel #3
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);
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="id">ID</param>
        /// <param name="name">名称</param>
        /// <param name="icon">アイコン(46 x 46 px)</param>
        /// <param name="smallIcon">小さいアイコン(24 x 24 px)</param>
        public NativeBandTile(Guid id, string name, BandIcon icon, BandIcon smallIcon)
        {
            this.tileId = id;

            this.tile = new BandTile(id)
            {
                IsBadgingEnabled = true,
                Name             = name,
                TileIcon         = icon,
                SmallIcon        = smallIcon,
            };
        }
Beispiel #5
0
        async Task AddTileAsync()
        {
            string tileName = "8Ball";

            try
            {
                //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
                //ORIGINAL LINE: final android.graphics.BitmapFactory.Options options = new android.graphics.BitmapFactory.Options();
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.InScaled = false;
                BandIcon tileIcon = BandIcon.ToBandIcon(BitmapFactory.DecodeResource(Resources, Resource.Raw.tile, options));

                //BandIcon badgeIcon = mCheckboxBadging.Checked ? BandIcon.ToBandIcon(BitmapFactory.DecodeResource(Resources, Resource.Raw.badge, options)) : null;
                BandIcon badgeIcon = BandIcon.ToBandIcon(BitmapFactory.DecodeResource(Resources, Resource.Raw.badge, options));

                uuid = Java.Util.UUID.RandomUUID();

                BandTile tile =
                    new BandTile.Builder(uuid, tileName, tileIcon)
                    .SetTileSmallIcon(badgeIcon)
                    //	.SetTheme(mCheckboxCustomTheme.Checked ? mThemeView.Theme : null)
                    .Build();

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

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

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

                RefreshControls();
            }
            catch (Exception e)
            {
                Util.ShowExceptionAlert(this, "Add tile", e);
            }
        }
Beispiel #6
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....");
            }
        }
Beispiel #8
0
        public static async Task <BandIcon> MakeTileIconFromFileAsync(
            Uri packageFileUri, int size)
        {
            BandIcon icon = null;

            var file = await StorageFile.GetFileFromApplicationUriAsync(
                packageFileUri);

            using (var stream = await file.OpenReadAsync())
            {
                var bitmap = new WriteableBitmap(size, size);
                bitmap.SetSource(stream);
                icon = bitmap.ToBandIcon();
            }
            return(icon);
        }
        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 }
            }
        }
Beispiel #10
0
 /// <summary>
 /// アイコン画像の変換
 /// </summary>
 /// <param name="icon">アイコン画像情報</param>
 /// <returns>画像ソース</returns>
 public static StreamImageSource FromNative(BandIcon icon)
 {
     return((StreamImageSource)ImageSource.FromStream(() => icon.ToWriteableBitmap().PixelBuffer.AsStream()));
 }
 public TileRepresentation(TileData data, BandIcon icon)
 {
     this.Data = data;
     this.Icon = icon;
 }
Beispiel #12
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View rootView = inflater.Inflate(Resource.Layout.fragment_tiles, container, false);

            mListTiles = rootView.FindViewById <ListView>(Resource.Id.listTiles);

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

            mTextRemainingCapacity = header.FindViewById <TextView>(Resource.Id.textAvailableCapacity);
            mButtonAddTile         = header.FindViewById <Button>(Resource.Id.buttonAddTile);
            mButtonAddTile.Click  += async delegate
            {
                try
                {
                    //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
                    //ORIGINAL LINE: final android.graphics.BitmapFactory.Options options = new android.graphics.BitmapFactory.Options();
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.InScaled = false;
                    BandIcon tileIcon = BandIcon.ToBandIcon(BitmapFactory.DecodeResource(Resources, Resource.Raw.tile, options));

                    BandIcon badgeIcon = mCheckboxBadging.Checked ? BandIcon.ToBandIcon(BitmapFactory.DecodeResource(Resources, Resource.Raw.badge, options)) : null;

                    BandTile tile =
                        new BandTile.Builder(Java.Util.UUID.RandomUUID(), mEditTileName.Text, tileIcon)
                        .SetTileSmallIcon(badgeIcon)
                        .SetTheme(mCheckboxCustomTheme.Checked ? mThemeView.Theme : null)
                        .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 e)
                {
                    Util.ShowExceptionAlert(Activity, "Add tile", e);
                }
            };
            mButtonRemoveTile        = header.FindViewById <Button>(Resource.Id.buttonRemoveTile);
            mButtonRemoveTile.Click += async delegate
            {
                try
                {
                    await Model.Instance.Client.TileManager.RemoveTileTaskAsync(mSelectedTile.TileId);

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

                    RefreshControls();
                }
                catch (Exception e)
                {
                    Util.ShowExceptionAlert(Activity, "Remove tile", e);
                }
            };
            mCheckboxBadging = header.FindViewById <CheckBox>(Resource.Id.cbBadging);

            mThemeView           = header.FindViewById <BandThemeView>(Resource.Id.viewCustomTheme);
            mThemeView.Theme     = BandTheme.CyberTheme;
            mCheckboxCustomTheme = header.FindViewById <CheckBox>(Resource.Id.cbCustomTheme);
            mCheckboxCustomTheme.CheckedChange += (sender, e) =>
            {
                mThemeView.Visibility = e.IsChecked ? ViewStates.Visible : ViewStates.Gone;
            };

            mEditTileName              = header.FindViewById <EditText>(Resource.Id.editTileName);
            mEditTileName.TextChanged += (sender, e) => RefreshControls();

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

            mEditTitle          = footer.FindViewById <EditText>(Resource.Id.editTitle);
            mEditBody           = footer.FindViewById <EditText>(Resource.Id.editBody);
            mCheckboxWithDialog = footer.FindViewById <CheckBox>(Resource.Id.cbWithDialog);

            mButtonSendMessage        = footer.FindViewById <Button>(Resource.Id.buttonSendMessage);
            mButtonSendMessage.Click += async delegate
            {
                try
                {
                    await Model.Instance.Client.NotificationManager.SendMessageTaskAsync(
                        mSelectedTile.TileId,
                        mEditTitle.Text,
                        mEditBody.Text,
                        DateTime.Now,
                        mCheckboxWithDialog.Checked);
                }
                catch (Exception e)
                {
                    Util.ShowExceptionAlert(Activity, "Send message", e);
                }
            };

            mButtonSendDialog        = footer.FindViewById <Button>(Resource.Id.buttonSendDialog);
            mButtonSendDialog.Click += async delegate
            {
                try
                {
                    await Model.Instance.Client.NotificationManager.ShowDialogTaskAsync(mSelectedTile.TileId, mEditTitle.Text, mEditBody.Text);
                }
                catch (Exception e)
                {
                    Util.ShowExceptionAlert(Activity, "Show dialog", e);
                }
            };

            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);
        }
Beispiel #13
0
        private async void OnAddBarcodeButtonClick(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));

                // create layout 1

                Barcode barcode1 = new Barcode(new PageRect(0, 0, 221, 70), BarcodeType.Code39);
                barcode1.Margins   = new Margins(3, 0, 0, 0);
                barcode1.ElementId = 11;

                TextBlock textBlock1 = new TextBlock(new PageRect(0, 0, 230, 30), TextBlockFont.Small, 0);
                textBlock1.Color     = Color.Red;
                textBlock1.ElementId = 21;

                FlowPanel flowPanel1 = new FlowPanel(new PageRect(15, 0, 245, 105), FlowPanelOrientation.Vertical);
                flowPanel1.AddElements(barcode1);
                flowPanel1.AddElements(textBlock1);

                PageLayout pageLayout1 = new PageLayout(flowPanel1);

                // create layout 2

                Barcode barcode2 = new Barcode(0, 0, 221, 70, BarcodeType.Pdf417);
                barcode2.Margins   = new Margins(3, 0, 0, 0);
                barcode2.ElementId = 11;

                TextBlock textBlock2 = new TextBlock(0, 0, 230, 30, TextBlockFont.Small, 0);
                textBlock2.Color     = Color.Red;
                textBlock2.ElementId = 21;

                FlowPanel flowPanel2 = new FlowPanel(15, 0, 245, 105, FlowPanelOrientation.Vertical);
                flowPanel2.AddElements(barcode2);
                flowPanel2.AddElements(textBlock2);

                PageLayout pageLayout2 = new PageLayout(flowPanel2);

                // create the tile

                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);
                }
                builder.SetPageLayouts(pageLayout1, pageLayout2);
                BandTile tile = builder.Build();

                // add tile

                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);
                }

                PageData pageData1 = new PageData(Java.Util.UUID.RandomUUID(), 0);
                pageData1.Update(new BarcodeData(11, "MK12345509", BarcodeType.Code39));
                pageData1.Update(new TextButtonData(21, "MK12345509"));

                PageData pageData2 = new PageData(Java.Util.UUID.RandomUUID(), 1);
                pageData2.Update(new BarcodeData(11, "901234567890123456", BarcodeType.Pdf417));
                pageData2.Update(new TextButtonData(21, "901234567890123456"));

                await Model.Instance.Client.TileManager.SetPagesTaskAsync(tile.TileId, pageData1, pageData2);

                Toast.MakeText(Activity, "Page updated", ToastLength.Short).Show();

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

                RefreshControls();
            }
            catch (Exception ex)
            {
                Util.ShowExceptionAlert(Activity, "Add tile", ex);
            }
        }
Beispiel #14
0
        private async void OnAddButtonTileClick(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));

                FilledButton button = new FilledButton(0, 5, 210, 45);
                button.BackgroundColor = Color.Red;
                button.Margins         = new Margins(0, 5, 0, 0);
                button.ElementId       = 12;

                TextButton button2 = new TextButton(0, 0, 210, 45);
                button2.PressedColor = Color.Blue;
                button2.Margins      = new Margins(0, 5, 0, 0);
                button2.ElementId    = 21;

                FlowPanel flowPanel = new FlowPanel(15, 0, 260, 105, FlowPanelOrientation.Vertical);
                flowPanel.AddElements(button);
                flowPanel.AddElements(button2);

                PageLayout pageLayout = new PageLayout(flowPanel);

                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);
                }
                builder.SetPageLayouts(pageLayout);
                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);
                }

                PageData pageData = new PageData(Java.Util.UUID.RandomUUID(), 0);
                pageData.Update(new FilledButtonData(12, Color.Yellow));
                pageData.Update(new TextButtonData(21, "Text Button"));
                await Model.Instance.Client.TileManager.SetPagesTaskAsync(tile.TileId, pageData);

                Toast.MakeText(Activity, "Page updated", ToastLength.Short).Show();

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

                RefreshControls();
            }
            catch (Exception ex)
            {
                Util.ShowExceptionAlert(Activity, "Add tile", ex);
            }
        }
        /// <summary>
        /// Ensure if the tile should exist it does, if it shouldn't it won't.
        /// </summary>
        public async Task <bool> EnsureBandTileState()
        {
            IBandInfo pairedBand = await GetPairedBand();

            if (pairedBand == null)
            {
                // We don't have a band.
                return(false);
            }

            bool wasSuccess = true;

            try
            {
                // Try to connect to the band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBand))
                {
                    // Get the current set of tiles
                    IEnumerable <BandTile> tiles = await bandClient.TileManager.GetTilesAsync();

                    // See if our tile exists
                    BandTile baconitTile = null;
                    foreach (BandTile tile in tiles)
                    {
                        if (tile.TileId.Equals(c_bandTileGuid))
                        {
                            baconitTile = tile;
                        }
                    }

                    if (baconitTile == null)
                    {
                        // The tile doesn't exist
                        if (ShowInboxOnBand)
                        {
                            // We need a tile, try to make one.
                            int tileCapacity = await bandClient.TileManager.GetRemainingTileCapacityAsync();

                            if (tileCapacity == 0)
                            {
                                m_baconMan.MessageMan.ShowMessageSimple("Can't add tile to Band", "Baconit can't add a tile to your Microsoft Band because you reached the maximum number of tile. To add the Baconit tile remove one of the other tiles on your band.");
                                wasSuccess = false;
                            }
                            else
                            {
                                // Create the icons
                                BandIcon smallIcon = null;
                                BandIcon tileIcon  = null;

                                // This icon should be 24x24 pixels
                                WriteableBitmap smallIconBitmap = await BitmapFactory.New(1, 1).FromContent(new Uri("ms-appx:///Assets/AppAssets/BandIcons/BandImage24.png", UriKind.Absolute));

                                smallIcon = smallIconBitmap.ToBandIcon();
                                // This icon should be 46x46 pixels
                                WriteableBitmap tileIconBitmap = await BitmapFactory.New(1, 1).FromContent(new Uri("ms-appx:///Assets/AppAssets/BandIcons/BandImage46.png", UriKind.Absolute));

                                tileIcon = tileIconBitmap.ToBandIcon();

                                // Create a new tile
                                BandTile tile = new BandTile(c_bandTileGuid)
                                {
                                    IsBadgingEnabled = true,
                                    Name             = "Baconit",
                                    SmallIcon        = smallIcon,
                                    TileIcon         = tileIcon
                                };

                                if (!await bandClient.TileManager.AddTileAsync(tile))
                                {
                                    m_baconMan.MessageMan.DebugDia("failed to create tile");
                                    m_baconMan.TelemetryMan.ReportUnExpectedEvent(this, "FailedToCreateTileOnBand");
                                    wasSuccess = false;
                                }
                            }
                        }
                    }
                    else
                    {
                        // The tile exists
                        if (!ShowInboxOnBand)
                        {
                            // We need to remove it
                            if (!await bandClient.TileManager.RemoveTileAsync(baconitTile))
                            {
                                m_baconMan.MessageMan.DebugDia("failed to remove tile");
                                m_baconMan.TelemetryMan.ReportUnExpectedEvent(this, "FailedToRemoveTileOnBand");
                                wasSuccess = false;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_baconMan.MessageMan.DebugDia("band connect failed", e);
                wasSuccess = false;
            }
            return(wasSuccess);
        }
Beispiel #16
0
        async partial void AddButtonPageClick(UIButton sender)
        {
            if (client != null && client.IsConnected)
            {
                Output("Creating tile...");

                // remove an old tile
                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!");
                    }
                } catch (BandException ex) {
                    Output("Error: " + ex.Message);
                }

                // create the tile
                NSError operationError;
                var     tileName  = "iOS Sample";
                var     tileIcon  = BandIcon.FromUIImage(UIImage.FromBundle("tile.png"), out operationError);
                var     smallIcon = BandIcon.FromUIImage(UIImage.FromBundle("badge.png"), out operationError);
                var     tile      = BandTile.Create(tileId, tileName, tileIcon, smallIcon, out operationError);
                tile.BadgingEnabled = true;

                // create the button page
                var textBlock = new TextBlock(PageRect.Create(0, 0, 200, 40), TextBlockFont.Small);
                textBlock.ElementId           = 10;
                textBlock.Baseline            = 25;
                textBlock.HorizontalAlignment = HorizontalAlignment.Center;
                textBlock.BaselineAlignment   = TextBlockBaselineAlignment.Relative;
                textBlock.AutoWidth           = false;
                textBlock.Color   = BandColor.FromUIColor(UIColor.Red, out operationError);
                textBlock.Margins = Margins.Create(5, 2, 5, 2);

                var button = new TextButton(PageRect.Create(0, 0, 200, 40));
                button.ElementId           = 11;
                button.HorizontalAlignment = HorizontalAlignment.Center;
                button.PressedColor        = BandColor.FromUIColor(UIColor.Purple, out operationError);
                button.Margins             = Margins.Create(5, 2, 5, 2);

                var flowPanel = new FlowPanel(PageRect.Create(15, 0, 260, 105));
                flowPanel.AddElement(textBlock);
                flowPanel.AddElement(button);

                var pageLayout = new PageLayout();
                pageLayout.Root = flowPanel;
                tile.PageLayouts.Add(pageLayout);

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

                // set the page data
                try {
                    Output("Creating page data...");
                    var pageValues = new PageElementData [] {
                        TextBlockData.Create(textBlock.ElementId, "TextButton sample", out operationError),
                        TextButtonData.Create(button.ElementId, "Press Me", out operationError)
                    };
                    var page = PageData.Create(barcodePageId, 0, pageValues);

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

                    Output("Completed custom page!");
                } catch (BandException ex) {
                    Output("Error: " + ex.Message);
                }
            }
            else
            {
                Output("Band is not connected. Please wait....");
            }
        }
Beispiel #17
0
        async partial void RegisterNotificationsClick(UIButton sender)
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                var types      = UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert;
                var mySettings = UIUserNotificationSettings.GetSettingsForTypes(types, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(mySettings);
            }

            if (client != null && client.IsConnected)
            {
                Output("Creating tile...");

                // remove an old tile
                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!");
                    }
                } catch (BandException ex) {
                    Output("Error: " + ex.Message);
                }

                // create the tile
                NSError operationError;
                var     tileName  = "iOS Sample";
                var     tileIcon  = BandIcon.FromUIImage(UIImage.FromBundle("tile.png"), out operationError);
                var     smallIcon = BandIcon.FromUIImage(UIImage.FromBundle("badge.png"), out operationError);
                var     tile      = BandTile.Create(tileId, tileName, tileIcon, smallIcon, out operationError);
                tile.BadgingEnabled = true;

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

                try {
                    Output("Registering notification...");
                    await client.NotificationManager.RegisterNotificationTaskAsync();

                    Output("Completed registration!");

                    Output("Sending notification...");

                    var localNotification = new UILocalNotification();
                    localNotification.FireDate    = NSDate.Now.AddSeconds(20);
                    localNotification.TimeZone    = NSTimeZone.DefaultTimeZone;
                    localNotification.AlertBody   = "Local notification";
                    localNotification.AlertAction = "View Details";
                    localNotification.SoundName   = UILocalNotification.DefaultSoundName;

                    UIApplication.SharedApplication.PresentLocalNotificationNow(localNotification);

                    Output("Notification sent!");
                } catch (BandException ex) {
                    Output("Error: " + ex.Message);
                }
            }
            else
            {
                Output("Band is not connected. Please wait....");
            }
        }