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