public async Task InitAsync() { // NEEDS BT VERIFICATION IF THIS STILL HAPPENS: check if there is a MeTile to grab (otherwise you get an exception // that will also kill the BT connection for daring to read to far beyond the Stream) // Need to find a workaround, since this is not exposed in the new lib: var tileId = _client.GetMeTileId(); BandImage meTileImage = null; try { meTileImage = await _client.PersonalizationManager.GetMeTileImageAsync(); } catch (InvalidOperationException) { } // no background image if (meTileImage != null) { _background = meTileImage.ToWriteableBitmap(); } _themeColor = await _client.PersonalizationManager.GetThemeAsync(); SetColorProperties(); // Notify that all properties have changed NotifyPropertyChanged(null); _inited = true; }
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); }
public static async Task Set_Image(object path) { BandClient = await Connect_Band(await Get_Band()); if (BandClient == null) { return; } using (BandClient) { if (path is WriteableBitmap) { WriteableBitmap wb = (WriteableBitmap)path; BandImage bi = wb.ToBandImage(); await BandClient.PersonalizationManager.SetMeTileImageAsync(bi); //set } else if (path is string) { WriteableBitmap writeableBitmap = await Loader.LoadImage((string)path); BandImage bandImage = writeableBitmap.ToBandImage(); await BandClient.PersonalizationManager.SetMeTileImageAsync(bandImage); } } }
public async Task SetMeTileImageAsync(BandImage image) { #if __ANDROID__ await Native.SetMeTileImageTaskAsync(image.ToBitmap()); #elif __IOS__ await Native.SetMeTileImageTaskAsync(image.ToUIImage().ToBandImage()); #elif WINDOWS_PHONE_APP await Native.SetMeTileImageAsync(image.ToWriteableBitmap().ToBandImage()); #endif }
public static async Task <BandImage> LoadBandImageFromResourceAsync(string resourcePath) { var stream = await Task.Run(() => { var assembly = typeof(MainViewModel).GetTypeInfo().Assembly; resourcePath = "MicrosoftBand." + resourcePath.Replace("/", ".").Replace("\\", "."); return(assembly.GetManifestResourceStream(resourcePath)); }); return(await BandImage.FromStreamAsync(stream)); }
private async void SetGetMeTileImage_Click(object sender, RoutedEventArgs args) { IBandInfo[] pairedBands; IBandClient client = null; this.viewModel.StatusMessage = "Running Me Tile image demo ..."; // Enumerate Bands that are paired to this device. pairedBands = await BandClientManager.Instance.GetBandsAsync(); if (pairedBands.Length == 0) { 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; } try { // Connect to the first Band in the enumeration. client = await BandClientManager.Instance.ConnectAsync(pairedBands[0]); } catch (Exception e) { this.viewModel.StatusMessage = "Failed to connect to a Band.\r\n" + e.Message; return; } using (client) { // Get the custom image from storage, and convert it to a BandImage. WriteableBitmap meTileBitmap = await LoadImage("ms-appx:///Assets/SampleMeTileImage.jpg"); BandImage meTileImage = meTileBitmap.ToBandImage(); // Set the MeTile image on the band. await client.PersonalizationManager.SetMeTileImageAsync(meTileImage); // Read the MeTile image back from the band. meTileImage = await client.PersonalizationManager.GetMeTileImageAsync(); // Convert the image back to a WritableBitmap. meTileBitmap = meTileImage.ToWriteableBitmap(); // Display the image on screen. this.MeTileImage.Source = meTileBitmap; // To clear the MeTile image on the Band, set it to null. // await client.PersonalizationManager.SetMeTileImageAsync(null); } this.viewModel.StatusMessage = "Done."; }
public static async Task <BandImage> LoadImageResourceAsync(string resourcePath) { // get the resource stream from Embedded Resources var stream = await Task.Run(() => { var assembly = typeof(ClientViewModel).GetTypeInfo().Assembly; resourcePath = "Microsoft.Band.Portable.Sample." + resourcePath.Replace("/", ".").Replace("\\", "."); return(assembly.GetManifestResourceStream(resourcePath)); }); // load the image return(await BandImage.FromStreamAsync(stream)); }
/// <summary> /// Returns MeTile from Microsoft Band /// </summary> /// <returns></returns> public static async Task <WriteableBitmap> Get_Image() { BandClient = await Connect_Band(await Get_Band()); if (BandClient == null) { return(new WriteableBitmap(1, 1)); } using (BandClient) { BandImage bandImage = await BandClient.PersonalizationManager.GetMeTileImageAsync(); return(bandImage.ToWriteableBitmap()); } }
public override async void OnAppearing(object navigationContext) { // Init BandClient = navigationContext as BandClient; _personalizationManager = BandClient.PersonalizationManager; Base = new BandColor(10, 110, 20); HighContrast = new BandColor(20, 120, 30); Highlight = new BandColor(30, 130, 40); Lowlight = new BandColor(40, 140, 50); Muted = new BandColor(50, 150, 60); SecondaryText = new BandColor(60, 160, 70); MeTileImage = await ResourcesHelper.LoadBandImageFromResourceAsync("Resources/metile.png"); base.OnAppearing(navigationContext); }
public PersonalizationViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { personalizationManager = bandClient.PersonalizationManager; GetBandThemeCommand = new Command(async() => { BandTheme = await personalizationManager.GetThemeAsync(); }); DefaultBandThemeCommand = new Command(() => { BandTheme = App.DefaultTheme; }); SetBandThemeCommand = new Command(async() => { await personalizationManager.SetThemeAsync(BandTheme); }); GetMeTileImageCommand = new Command(async() => { MeTileImage = await personalizationManager.GetMeTileImageAsync(); }); DefaultMeTileImageCommand = new Command(async() => { MeTileImage = await App.LoadImageResourceAsync("Resources/metile.png"); }); SelectMeTileImageCommand = new Command(async() => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { MeTileImage = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); SetMeTileImageCommand = new Command(async() => { await personalizationManager.SetMeTileImageAsync(MeTileImage); }); Init(); }
/// <summary> /// 壁紙の設定 /// </summary> /// <param name="image">壁紙画像</param> /// <returns>Task</returns> public Task SetMeTileImageAsync(BandImage image) { throw new NotImplementedException(); }
public Task SetMeTileImageAsync(BandImage image, CancellationToken cancel) { return(this.SetMeTileImageAsync(image)); }
private async Task<BandImage> GetMeTileAsync(CancellationToken cancel) { if (_meTileImage == null) _meTileImage = await CreateMeTileAsync(cancel); return _meTileImage; }
public static Task SetMeTileImageTaskAsync(this IBandPersonalizationManager manager, BandImage image) { var tcs = new TaskCompletionSource <object> (); manager.SetMeTileImageAsync(image, tcs.AttachCompletionHandler()); return(tcs.Task); }
public BandTile(Guid tileId, string name, BandImage icon) : this(tileId) { Name = name; Icon = icon; }
public Tile(Guid tileId, string name, BandImage icon, BandImage smallIcon) : this(tileId) { Name = name; Icon = icon; SmallIcon = smallIcon; }
public BandTile(Guid tileId, string name, BandImage icon, BandImage smallIcon) : this(tileId, name, icon) { SmallIcon = smallIcon; }
public BandTile(Guid tileId, string name, BandImage icon) : this(tileId) { Name = name; Icon = icon; }
/// <summary> /// Updates the band wallpaper /// </summary> /// <param name="file"></param> public async Task <bool> UpdateBandWallpaper(StorageFile file) { try { IBandInfo pairedBand = await GetPairedBand(); if (pairedBand == null) { // We don't have a band. return(true); } // Try to connect to the band. using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBand)) { WriteableBitmap bitmap = null; BandImage newBandImage = null; //byte[] pixelArray = null; using (AutoResetEvent are = new AutoResetEvent(false)) { // Get the bitmap on the UI thread. await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, async() => { try { // Create a bitmap for the Me Tile image. // The image must be 310x102 pixels for Microsoft Band 1 // and 310x102 or 310x128 pixels for Microsoft Band 2. ImageProperties properties = await file.Properties.GetImagePropertiesAsync(); bitmap = new WriteableBitmap((int)properties.Width, (int)properties.Height); bitmap.SetSource((await file.OpenReadAsync())); newBandImage = bitmap.ToBandImage(); //pixelArray = bitmap.ToByteArray(); } catch (Exception) { } are.Set(); }); are.WaitOne(10000); } // Check if we failed if (bitmap == null || newBandImage == null) { throw new Exception("Failed to make new bitmap image."); } // Try to set the image. await bandClient.PersonalizationManager.SetMeTileImageAsync(newBandImage); //// Compute the average color //Color averageColor = new Color(); //uint bAvg = 0; //uint rAvg = 0; //uint gAvg = 0; //uint count = 0; //for (int i = 0; i < pixelArray.Length; i += 4) //{ // rAvg += pixelArray[i + 1]; // gAvg += pixelArray[i + 2]; // bAvg += pixelArray[i + 3]; // count++; //} //averageColor.R = (byte)(rAvg / count); //averageColor.B = (byte)(bAvg / count); //averageColor.G = (byte)(gAvg / count); //BandTheme theme = new BandTheme() { Base = averageColor.ToBandColor() }; //await bandClient.PersonalizationManager.SetThemeAsync(theme); } } catch (Exception e) { m_baconMan.MessageMan.DebugDia("failed to set band wallpaper", e); return(false); } return(true); }
public AddTileViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { tileManager = bandClient.TileManager; tileTheme = App.DefaultTheme; tileId = Guid.NewGuid(); tileName = "New Tile"; GenerateTileIdCommand = new Command(() => { TileId = Guid.NewGuid().ToString("D"); }); DefaultTileIconCommand = new Command(async() => { TileIcon = await App.LoadImageResourceAsync("Resources/tile.png"); }); SelectTileIconCommand = new Command(async() => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { TileIcon = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); DefaultTileBadgeCommand = new Command(async() => { TileBadge = await App.LoadImageResourceAsync("Resources/badge.png"); }); SelectTileBadgeCommand = new Command(async() => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { TileBadge = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); DefaultThemeCommand = new Command(() => { TileTheme = App.DefaultTheme; }); AddTileCommand = new Command(async() => { var tile = new BandTile(tileId) { Icon = TileIcon, Name = TileName }; if (AllowBadging) { tile.SmallIcon = TileBadge; } if (UseCustomTheme) { tile.Theme = TileTheme; } await tileManager.AddTileAsync(tile); }); RemoveTileCommand = new Command(async() => { await tileManager.RemoveTileAsync(tileId); }); }
/// <summary> /// 画像の変換 /// </summary> /// <param name="image">画像情報</param> /// <returns>画像ソース</returns> public static StreamImageSource FromNative(BandImage image) { return((StreamImageSource)ImageSource.FromStream(() => image.ToWriteableBitmap().PixelBuffer.AsStream())); }
public AddTileViewModel(BandDeviceInfo info, BandClient bandClient) : base(info, bandClient) { tileManager = bandClient.TileManager; tileTheme = App.DefaultTheme; tileId = Guid.NewGuid(); tileName = "New Tile"; GenerateTileIdCommand = new Command(() => { TileId = Guid.NewGuid().ToString("D"); }); DefaultTileIconCommand = new Command(async () => { TileIcon = await App.LoadImageResourceAsync("Resources/tile.png"); }); SelectTileIconCommand = new Command(async () => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { TileIcon = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); DefaultTileBadgeCommand = new Command(async () => { TileBadge = await App.LoadImageResourceAsync("Resources/badge.png"); }); SelectTileBadgeCommand = new Command(async () => { var photo = await CrossMedia.Current.PickPhotoAsync(); if (photo != null) { TileBadge = await BandImage.FromStreamAsync(photo.GetStream()); } }, () => CrossMedia.Current.IsPickPhotoSupported); DefaultThemeCommand = new Command(() => { TileTheme = App.DefaultTheme; }); AddTileCommand = new Command(async () => { var tile = new BandTile(tileId) { Icon = TileIcon, Name = TileName, SmallIcon = TileBadge, IsScreenTimeoutDisabled = DisableScreenTimeout }; if (UseCustomTheme) { tile.Theme = TileTheme; } tile.PageImages.AddRange(new[] { await App.LoadImageResourceAsync("Resources/star.png") }); var layouts = CreatePageLayouts(); tile.PageLayouts.AddRange(layouts); await tileManager.AddTileAsync(tile); var datas = CreatePageDatas(); await tileManager.SetTilePageDataAsync(tile.Id, datas); }); RemoveTileCommand = new Command(async () => { await tileManager.RemoveTileAsync(tileId); }); }
public static Task SetMeTileImageTaskAsync (this IBandPersonalizationManager manager, BandImage image) { var tcs = new TaskCompletionSource<object> (); manager.SetMeTileImageAsync (image, tcs.AttachCompletionHandler ()); return tcs.Task; }
public Task SetMeTileImageAsync(BandImage image, CancellationToken cancel) { throw new NotImplementedException(); }
public Task SetMeTileImageAsync(BandImage image, CancellationToken cancel) { var tcs = new TaskCompletionSource<bool>(); Task.Run(() => { Task.Delay(500, cancel); _meTileImage = image; tcs.SetResult(true); }); return tcs.Task; }
public BandTile(Guid tileId, string name, BandImage icon, BandImage smallIcon) : this(tileId, name, icon) { SmallIcon = smallIcon; }
public BandTile(Guid tileId, string name, BandImage icon) { Id = tileId; Name = name; Icon = icon; }
public Task SetMeTileImageAsync(BandImage image) { throw new NotImplementedException(); }
async void AddTileButton_Click(object sender, EventArgs e) { if (0 == String.Compare(addTileButton.Text, AddTileString)) { // add tile try { BitmapFactory.Options options = new BitmapFactory.Options(); options.InScaled = false; var tile = new BandTile(tileId) { Icon = BandImage.FromBitmap(BitmapFactory.DecodeResource(Resources, Resource.Raw.tile, options)), Name = "Altitude", SmallIcon = BandImage.FromBitmap(BitmapFactory.DecodeResource(Resources, Resource.Raw.badge, options)), IsScreenTimeoutDisabled = true }; // define the page layout var pageLayout = new PageLayout { Root = new FlowPanel { Orientation = FlowPanelOrientation.Vertical, Rect = new PageRect(0, 0, 258, 128), } }; // Page1 line1 var line1 = new FlowPanel { Orientation = FlowPanelOrientation.Horizontal, Rect = new PageRect(0, 0, 258, 30), Elements = { new TextBlock { ElementId = 1, Rect = new PageRect(0, 0, 258, 30), Margins = new Margins(15, 0, 0, 0), VerticalAlignment = VerticalAlignment.Bottom, Font = TextBlockFont.Small, ColorSource = ElementColorSource.BandHighlight, }, new TextBlock { ElementId = 2, Rect = new PageRect(0, 0, 258, 30), Margins = new Margins(10, 0, 0, 0), VerticalAlignment = VerticalAlignment.Bottom, Font = TextBlockFont.Small } } }; // Page1 Line2 var line2 = new FlowPanel { Orientation = FlowPanelOrientation.Horizontal, Rect = new PageRect(0, 38, 280, 90), Elements = { new Icon { ElementId = 10, Rect = new PageRect(0, 0, 24, 24), Margins = new Margins(15, 35, 0, 0), VerticalAlignment = VerticalAlignment.Top, ColorSource = ElementColorSource.BandBase }, new Icon { ElementId = 11, Rect = new PageRect(0, 0, 24, 24), Margins = new Margins(-24, 35, 0, 0), VerticalAlignment = VerticalAlignment.Top, Color = new BandColor(0xff, 0, 0) //red }, new Icon { ElementId = 12, Rect = new PageRect(0, 0, 24, 24), Margins = new Margins(-24, 35, 0, 0), VerticalAlignment = VerticalAlignment.Bottom, Color = new BandColor(0xff, 0xff, 0) //yellow }, new Icon { ElementId = 13, Rect = new PageRect(0, 0, 24, 24), Margins = new Margins(-24, 35, 0, 0), VerticalAlignment = VerticalAlignment.Bottom, Color = new BandColor(0, 0xff, 0) //green }, new TextBlock { ElementId = 5, Rect = new PageRect(0, 0, 228, 90), Margins = new Margins(10, 0, 0, 15), VerticalAlignment = VerticalAlignment.Bottom, Font = TextBlockFont.ExtraLargeNumbersBold } } }; pageLayout.Root.Elements.Add(line1); pageLayout.Root.Elements.Add(line2); // add the page layout to the tile tile.PageLayouts.Add(pageLayout); // add the tile to the Band await Model.Instance.Client.TileManager.AddTileAsync(tile); addTileButton.Text = RemoveTileString; } catch (Exception ex) { Util.ShowExceptionAlert(this, "Add Tile", ex); } } else { // remove tile try { await Model.Instance.Client.TileManager.RemoveTileAsync(tileId); addTileButton.Text = AddTileString; } catch (Exception ex) { Util.ShowExceptionAlert(this, "Remove Tile", ex); } } }
private async Task CreateBandTitle() { var Tiles = await BandClient.TileManager.GetTilesAsync(); if (Tiles.Count(u => u.Id == BandManagement.tileGuid) > 0) { return; //await BandClient.TileManager.RemoveTileAsync(BandManagement.tileGuid); } var Theme = await BandClient.PersonalizationManager.GetThemeAsync(); var IconStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("PowerfulTrainer.Images.BandIcon.png"); var SmallIconStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("PowerfulTrainer.Images.BandSmallIcon.png"); var Icon = await BandImage.FromStreamAsync(IconStream); var SmallIcon = await BandImage.FromStreamAsync(SmallIconStream); BandTile tile = new BandTile(BandManagement.tileGuid) { Name = "Powerful Trainer", Icon = Icon, SmallIcon = SmallIcon, IsScreenTimeoutDisabled = true }; FilledPanel panel = new FilledPanel { Rect = new PageRect(0, 0, 270, 120), }; panel.Elements.Add(new TextButton { ElementId = 1, Rect = new PageRect(188, 70, 80, 50), }); panel.Elements.Add(new WrappedTextBlock { ElementId = 2, Rect = new PageRect(5, 2, 270, 50), AutoHeight = true, Color = Theme.Highlight }); panel.Elements.Add(new TextBlock { ElementId = 3, Rect = new PageRect(2, 90, 270, 50), AutoWidth = true }); PageLayout layout = new PageLayout(panel); tile.PageLayouts.Add(layout); try { await BandClient.TileManager.AddTileAsync(tile); } catch { } }
/// <summary> /// 壁紙の設定 /// </summary> /// <param name="image">壁紙画像</param> /// <returns>Task</returns> public Task SetMeTileImageAsync(BandImage image) { return(this.manager.SetMeTileImageAsync(image)); }