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);
            }
        }
		async partial void AddBarcodePageClick (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 barcode page
				var textBlock = new TextBlock (PageRect.Create (0, 0, 230, 40), TextBlockFont.Small);
				textBlock.ElementId = 10;
				textBlock.Baseline = 25;
				textBlock.HorizontalAlignment = HorizontalAlignment.Center;
				textBlock.BaselineAlignment = TextBlockBaselineAlignment.Relative;
				textBlock.AutoWidth = false;
		        
				var barcode = new Barcode (PageRect.Create (0, 5, 230, 95), BarcodeType.Code39);
				barcode.ElementId = 11;
		        
				var flowPanel = new FlowPanel (PageRect.Create (15, 0, 260, 105));
				flowPanel.AddElement (textBlock);
				flowPanel.AddElement (barcode);
		        
				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, "Barcode value: A1 B", out operationError),
						BarcodeData.Create (barcode.ElementId, BarcodeType.Code39, "A1 B", 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....");
			}
		}
        public async Task SyncToBand()
        {
            // Get the list of Microsoft Bands paired to the phone/tablet/PC.
            pairedBands = await BandClientManager.Instance.GetBandsAsync();

            if (pairedBands.Count() == 0)
            {
                BandStatusTxt = "You are not paired to a Microsoft Band";
                return;
            }

            BandStatusTxt = "Connecting to Microsoft Band...";
            try
            {
                // Connect to Microsoft Band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {
                    BandStatusTxt = "Connected...preparing to update";
                    Guid TileGuid = App.APP_SETTINGS.BandID;

                    BandTile RewardsTile = new BandTile(TileGuid)
                    {
                        Name = "Rewards Wallet",
                        SmallIcon = await LoadIcon("ms-appx:///Assets/BandTileIcon_sm.png"),
                        TileIcon = await LoadIcon("ms-appx:///Assets/BandTileIcon.png")
                    };


                    // CODE_39 Page
                    TextBlock myCardTextBlock = new TextBlock()
                    {
                        ColorSource = ElementColorSource.BandHighlight,
                        ElementId = 1, // the Id of the TextBlock element; we'll use it later to set its text to "MY CARD"
                        Rect = new PageRect(0, 0, 250, 30),
                        Margins = new Margins(15, 0, 15, 15)
                    };
                    Barcode barcode = new Barcode(BarcodeType.Code39)
                    {
                        ElementId = 2, // the Id of the Barcode element; we'll use it later to set its barcode value to be rendered
                        Rect = new PageRect(0, 0, 250, 100)
                    };
                    FlowPanel panel = new FlowPanel(myCardTextBlock, barcode)
                    {
                        Orientation = FlowPanelOrientation.Vertical,
                        Rect = new PageRect(0, 0, 250, 145)
                    };

                    PageLayout layout_CODE_39 = new PageLayout(panel);

                    // PDF_417 Page
                    TextBlock myCardTextBlock2 = new TextBlock()
                    {
                        ColorSource = ElementColorSource.BandHighlight,
                        ElementId = 1, // the Id of the TextBlock element; we'll use it later to set its text to "MY CARD"
                        Rect = new PageRect(0, 0, 250, 30),
                        Margins = new Margins(15, 0, 15, 15)
                    };
                    Barcode barcode2 = new Barcode(BarcodeType.Pdf417)
                    {
                        ElementId = 2, // the Id of the Barcode element; we'll use it later to set its barcode value to be rendered
                        Rect = new PageRect(0, 0, 250, 100)
                    };
                    FlowPanel panel2 = new FlowPanel(myCardTextBlock2, barcode2)
                    {
                        Orientation = FlowPanelOrientation.Vertical,
                        Rect = new PageRect(0, 0, 250, 145)
                    };

                    PageLayout layout_PDF_417 = new PageLayout(panel2);

                    try
                    {
                        // add the layout to the tile
                        RewardsTile.PageLayouts.Add(layout_CODE_39);
                        RewardsTile.PageLayouts.Add(layout_PDF_417);
                    }
                    catch (BandException ex)
                    {
                        // handle an error adding the layout
                    }

                    try
                    {
                        // Add tile only if it doesn't already exist
                        IEnumerable<BandTile> currTiles = await bandClient.TileManager.GetTilesAsync();
                        if (currTiles.Where(t => t.TileId == TileGuid).Count() == 0)
                        {
                            BandStatusTxt = "Updating Rewards Wallet Tile...";
                            await bandClient.TileManager.RemoveTileAsync(RewardsTile);
                            // add the tile to the Band
                            if (await bandClient.TileManager.AddTileAsync(RewardsTile))
                            {
                                // tile was successfully added
                                // can proceed to set tile content with SetPagesAsync
                            }
                            else
                            {
                                // tile failed to be added, handle error
                                BandStatusTxt = "Error adding Rewards Wallet Tile to the Band";
                            }
                        }
                    }
                    catch (BandException ex)
                    {
                        // handle a Band connection exception
                        BandStatusTxt = "Error adding Rewards Wallet Tile to the Band";
                        return;
                    }

                    await bandClient.TileManager.RemovePagesAsync(TileGuid);

                    int PagesAdded = 0;
                    for (var idx = 0; idx < App.APP_SETTINGS.RewardCards.Count && PagesAdded < 8; idx++)
                    {
                        BarcodeType pageBarcodeType = BarcodeType.Code39;

                        if (CanBeRenderedOnBand(App.APP_SETTINGS.RewardCards[idx]))
                        {                            
                            Guid messagesPageGuid = Guid.NewGuid();
                            string cardNumber = App.APP_SETTINGS.RewardCards[idx].Number;

                            // we're going from native UPC encoding to UPC39...some cases require the dropping of a check digit
                            switch(App.APP_SETTINGS.RewardCards[idx].Format)
                            {
                                case ZXing.BarcodeFormat.EAN_13:
                                case ZXing.BarcodeFormat.EAN_8:
                                case ZXing.BarcodeFormat.UPC_EAN_EXTENSION:
                                case ZXing.BarcodeFormat.UPC_A:
                                    pageBarcodeType = BarcodeType.Code39;
                                    cardNumber = App.APP_SETTINGS.RewardCards[idx].Number.Substring(0, App.APP_SETTINGS.RewardCards[idx].Number.Length - 1);
                                    break;
                                case ZXing.BarcodeFormat.PDF_417:
                                    pageBarcodeType = BarcodeType.Pdf417;
                                    cardNumber = App.APP_SETTINGS.RewardCards[idx].Number; ;
                                    break;
                                case ZXing.BarcodeFormat.CODE_128:
                                    pageBarcodeType = BarcodeType.Code39;
                                    cardNumber = App.APP_SETTINGS.RewardCards[idx].Number; ;
                                    break;
                            }

                            PageData pageContent;
                            if (pageBarcodeType == BarcodeType.Code39)
                            {
                                pageContent = new PageData(
                                    messagesPageGuid,
                                    0,
                                    new TextBlockData(1, App.APP_SETTINGS.RewardCards[idx].Name.Trim()),
                                    new BarcodeData(pageBarcodeType, barcode.ElementId.Value, cardNumber)
                                    );
                            }
                            else
                            {
                                pageContent = new PageData(
                                    messagesPageGuid,
                                    1,
                                    new TextBlockData(1, App.APP_SETTINGS.RewardCards[idx].Name.Trim()),
                                    new BarcodeData(pageBarcodeType, barcode.ElementId.Value, cardNumber)
                                    );
                            }

                            try
                            {
                                // set the page content on the Band
                                if (await bandClient.TileManager.SetPagesAsync(TileGuid, pageContent))
                                {
                                    // page content successfully set on Band
                                    BandStatusTxt = "Updating " + App.APP_SETTINGS.RewardCards[idx].Name.Trim() + " card";
                                    PagesAdded++;
                                }
                                else
                                {
                                    // unable to set content to the Band
                                    BandStatusTxt = "Failed to add " + App.APP_SETTINGS.RewardCards[idx].Name.Trim() + " card to the Band";
                                }
                            }
                            catch (BandException ex)
                            {
                                // handle a Band connection exception
                                BandStatusTxt = "Failed to add cards to the Band";
                            }
                        }
                    }
                    BandStatusTxt = "Sync to Band Complete!";
                    DispatcherTimer timer = new DispatcherTimer();
                    timer.Tick += (object sender, object e) => {
                        timer.Stop();
                        BandStatusTxt = string.Empty;
                    };
                    timer.Interval = new TimeSpan(0, 0, 3);
                    timer.Start();
                }
            }
            catch(Exception e)
            {
                BandStatusTxt = "Failed to connect to the Microsoft Band";
                
            }
        }
Exemple #4
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            this.viewModel.StatusMessage = "Running ...";

            try
            {
                // Get the list of Microsoft Bands paired to the phone/tablet/PC.
                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]))
                {
                    // We'll create a Tile that looks like this:
                    // +--------------------+
                    // | MY CARD            | 
                    // | |||||||||||||||||  | 
                    // | 123456789          |
                    // +--------------------+
                    
                    // First, we'll prepare the layout for the Tile page described above.
                    TextBlock myCardTextBlock = new TextBlock()
                    {
                        Color = Colors.Blue.ToBandColor(),
                        ElementId = 1, // the Id of the TextBlock element; we'll use it later to set its text to "MY CARD"
                        Rect = new PageRect(0, 0, 200, 25)
                    };
                    Barcode barcode = new Barcode(BarcodeType.Code39)
                    {
                        ElementId = 2, // the Id of the Barcode element; we'll use it later to set its barcode value to be rendered
                        Rect = new PageRect(0, 0, 250, 50)
                    };
                    TextBlock digitsTextBlock = new TextBlock()
                    {
                        ElementId = 3, // the Id of the TextBlock element; we'll use it later to set its text to "123456789"
                        Rect = new PageRect(0, 0, 200, 25)
                    };
                    FlowPanel panel = new FlowPanel(myCardTextBlock, barcode, digitsTextBlock)
                    {
                        Orientation = FlowPanelOrientation.Vertical,
                        Rect = new PageRect(0, 0, 250, 100)
                    };
                    
                    // Now we'll create the Tile.
                    Guid myTileId = new Guid("D781F673-6D05-4D69-BCFF-EA7E706C3418");
                    BandTile myTile = new BandTile(myTileId)
                    {
                        Name = "My Tile",
                        TileIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png"),
                        SmallIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png")
                    };
                    myTile.PageLayouts.Add(new PageLayout(panel));

                    // 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(myTile.TileId);

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

                    // And create the page with the specified texts and values.
                    PageData page = new PageData(
                        Guid.NewGuid(), // the Id for the page
                        0, // the index of the layout to be used; we have only one layout in this sample app, but up to 5 layouts can be registered for a Tile
                        new TextBlockData(myCardTextBlock.ElementId.Value, "MY CARD"),
                        new BarcodeData(barcode.BarcodeType, barcode.ElementId.Value, "123456789"),
                        new TextBlockData(digitsTextBlock.ElementId.Value, "123456789"));

                    await bandClient.TileManager.SetPagesAsync(myTile.TileId, page);

                    this.viewModel.StatusMessage = "Done. Check the Tile on your Band (it's the last Tile).";
                }
            }
            catch (Exception ex)
            {
                this.viewModel.StatusMessage = ex.ToString();
            }
        }
        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);
			mButtonAddButtonTile = header.FindViewById<Button>(Resource.Id.buttonAddButtonTile);
			mButtonAddButtonTile.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 = 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 e)
				{
					Util.ShowExceptionAlert(Activity, "Add tile", e);
				}
			};
			mButtonAddBarcodeTile = header.FindViewById<Button>(Resource.Id.buttonAddBarcodeTile);
			mButtonAddBarcodeTile.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 = 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 e)
				{
					Util.ShowExceptionAlert(Activity, "Add tile", e);
				}
			};
            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 = 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 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);
            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;
        }