private async void ButtonUpdateTile_Click(object sender, RoutedEventArgs e) { base.IsEnabled = false; // Grab the existing tile SecondaryTile tile = (await SecondaryTile.FindAllAsync()).FirstOrDefault(i => i.TileId.Equals(_tileId)); if (tile == null) { await new MessageDialog("The secondary tile that was previously pinned could not be found. Has it been removed from Start?", "Error").ShowAsync(); return; } // Change its name and logos tile.DisplayName = "Updated"; tile.VisualElements.Square150x150Logo = new Uri("ms-appx:///Assets/check.png"); tile.VisualElements.Square71x71Logo = new Uri("ms-appx:///Assets/check.png"); tile.VisualElements.Square310x310Logo = new Uri("ms-appx:///Assets/check.png"); tile.VisualElements.Wide310x150Logo = new Uri("ms-appx:///Assets/check.png"); // And request its properties to be updated await tile.UpdateAsync(); stepsControl.Step++; base.IsEnabled = true; }
public static IAsyncAction UpdateTile(TetheringState state) { var loader = new Windows.ApplicationModel.Resources.ResourceLoader(); var enabled = state == TetheringState.Enabled; var logo = enabled ? logoOn : logoOff; var deviceName = AppSettings.RemoteDevice; var tileText = string.Format(loader.GetString(enabled ? "Tile_Tooltip_ToDisable" : "Tile_Tooltip_ToEnable"), deviceName); var s = new SecondaryTile(SwitchTileId, tileText, !enabled ? EnableSwitchArgument : DisableSwitchArgument, logo, TileSize.Square150x150); // Specify a foreground text value. return(AsyncInfo.Run(async(cancel) => { try { await s.UpdateAsync(); } catch (Exception) { // Ignore } })); }
/// <summary> /// This is the click handler for the 'Update logo async' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void UpdateDefaultLogo_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; if (button != null) { if (Windows.UI.StartScreen.SecondaryTile.Exists(MainPage.logoSecondaryTileId)) { // Add the properties we want to update (logo in this example) SecondaryTile secondaryTile = new SecondaryTile(MainPage.logoSecondaryTileId); secondaryTile.VisualElements.Square150x150Logo = new Uri("ms-appx:///Assets/squareTileLogoUpdate-sdk.png"); bool isUpdated = await secondaryTile.UpdateAsync(); if (isUpdated) { rootPage.NotifyUser("Secondary tile logo updated.", NotifyType.StatusMessage); } else { rootPage.NotifyUser("Secondary tile logo not updated.", NotifyType.ErrorMessage); } } else { rootPage.NotifyUser("Please pin a secondary tile using scenario 1 before updating the Logo.", NotifyType.ErrorMessage); } } }
private async Task CreateSecondaryTileAsync(string category, string content) { string tileId = _secondTileId; string displayName = content; string arguments = "arguments"; // Initialize the tile with required arguments SecondaryTile tile = new SecondaryTile( tileId, displayName, arguments, new Uri("ms-appx:///Assets/SecondTile/Square150x150Logo.png"), TileSize.Wide310x150); tile.VisualElements.Wide310x150Logo = new Uri("ms-appx:///Assets/SecondTile/Square150x150Logo.png"); tile.VisualElements.ForegroundText = ForegroundText.Dark; tile.VisualElements.ShowNameOnSquare150x150Logo = true; tile.VisualElements.ShowNameOnWide310x150Logo = true; tile.VisualElements.ShowNameOnSquare310x310Logo = true; if (!SecondaryTile.Exists(_secondTileId)) { await tile.RequestCreateAsync(); } await tile.UpdateAsync(); }
private static async Task UpdateTileAsync(SecondaryTile tile, AccountDataItem account, AccountDataStore data, Guid classId) { try { DateTime todayInLocal = DateTime.Today; // Get the class tile settings ClassTileSettings settings = await account.GetClassTileSettings(classId); ClassData classData = await LoadDataAsync(data, classId, DateTime.SpecifyKind(todayInLocal, DateTimeKind.Utc), settings); // If classData was null, that means the class wasn't found, so we should delete the tile if (classData == null) { await tile.RequestDeleteAsync(); return; } bool changed = false; string desiredName = GetTrimmedClassName(classData.Class.Name); Color desiredColor; if (settings.CustomColor != null) desiredColor = ColorTools.GetColor(settings.CustomColor); else desiredColor = ColorTools.GetColor(classData.Class.Color); if (!tile.DisplayName.Equals(desiredName)) { changed = true; tile.DisplayName = desiredName; } if (!tile.VisualElements.BackgroundColor.Equals(desiredColor)) { changed = true; tile.VisualElements.BackgroundColor = desiredColor; } if (changed) await tile.UpdateAsync(); var updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId); UpdateUpcomingTile(updater, classData.AllUpcoming, todayInLocal, UpcomingTileType.ClassTile, settings); } catch (Exception ex) { if (!UWPExceptionHelper.TrackIfNotificationsIssue(ex, "Tiles")) { throw ex; } } }
private async void Pin() { if (this.Group == null) { return; } string tileID = $"Tile_Group_{this.GroupID}"; string argument = $"GroupDetail-{this.GroupID}"; SecondaryTile tile = new SecondaryTile(tileID, this.Group.Name, argument, new Uri("ms-appx:///Assets/logo-50.png"), TileSize.Square150x150); await tile.RequestCreateAsync(); TileBindingContentAdaptive bindingContent = new TileBindingContentAdaptive() { PeekImage = new TilePeekImage() { Source = new TileImageSource(this.Group.LargeAvatar) } }; bindingContent.Children.Add(new TileText { Text = this.Group.Name, Wrap = true, Style = TileTextStyle.Body }); TileBinding binding = new TileBinding() { Branding = TileBranding.NameAndLogo, DisplayName = this.Group.Name, Content = bindingContent }; TileContent content = new TileContent() { Visual = new TileVisual() { TileMedium = binding, TileWide = binding, TileLarge = binding } }; var notification = new TileNotification(content.GetXml()); var updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileID); updater.Update(notification); bool result = await tile.UpdateAsync(); }
public static async Task <bool> UpdateSecondaryTileAsync(BookmarkInfo bookmark) { if (SecondaryTile.Exists(bookmark.Position.SeriesId)) { var tile = new SecondaryTile(bookmark.Position.SeriesId); string args = bookmark.Position.ToString(); tile.Arguments = args; var result = await tile.UpdateAsync(); return(true); } return(false); }
private async Task <bool> CreateOrUpdateSecondaryTileAsync(SecondaryTile tile, TileVisualOptions options) { if (tile == null) { return(false); } tile.VisualElements.ShowNameOnSquare150x150Logo = true; tile.VisualElements.Square71x71Logo = options.Square71x71Logo ?? null; tile.VisualElements.Square150x150Logo = options.Square150x150Logo ?? null; if (!(ApiInformation.IsTypePresent(("Windows.Phone.UI.Input.HardwareButtons")))) { tile.VisualElements.Wide310x150Logo = options.Wide310x150Logo ?? null; tile.VisualElements.Square310x310Logo = options.Square310x310Logo ?? null; tile.VisualElements.ShowNameOnWide310x150Logo = true; tile.VisualElements.ShowNameOnSquare310x310Logo = true; } if (SecondaryTile.Exists(tile.TileId)) { return(await tile.UpdateAsync()); } else { if (!ApiInformation.IsTypePresent(("Windows.Phone.UI.Input.HardwareButtons"))) { if (options.Rect == null) { return(await tile.RequestCreateAsync()); } else { return(await tile.RequestCreateForSelectionAsync(options.Rect, options.PopupPlacement)); } } else if (ApiInformation.IsTypePresent(("Windows.Phone.UI.Input.HardwareButtons"))) { // OK, the tile is created and we can now attempt to pin the tile. // Since pinning a secondary tile on Windows Phone will exit the app and take you to the start screen, any code after // RequestCreateForSelectionAsync or RequestCreateAsync is not guaranteed to run. For an example of how to use the OnSuspending event to do // work after RequestCreateForSelectionAsync or RequestCreateAsync returns, see Scenario9_PinTileAndUpdateOnSuspend in the SecondaryTiles.WindowsPhone project. return(await tile.RequestCreateAsync()); } } return(false); }
internal static async Task <bool> AddSecondaryTile(string crypto) { hist = await Ioc.Default.GetService <ICryptoCompare>().GetHistoric_(crypto, "hour", 168); await RenderTileSVG(crypto); // Initialize the tile with required arguments SecondaryTile tile = new SecondaryTile( crypto, $"Crypto {crypto}", $"/coin-{crypto}", new Uri("ms-appx:///Assets/AppIcon.png"), TileSize.Wide310x150); tile.VisualElements.ShowNameOnSquare150x150Logo = true; tile.VisualElements.ShowNameOnSquare310x310Logo = false; tile.VisualElements.ShowNameOnWide310x150Logo = false; tile.VisualElements.Wide310x150Logo = new Uri("ms-appx:///Assets/Wide.png"); tile.VisualElements.Square44x44Logo = new Uri("ms-appx:///Assets/AppIcon.png"); tile.VisualElements.ForegroundText = (new UISettings().GetColorValue(UIColorType.Background) == Colors.Black) ? ForegroundText.Light : ForegroundText.Dark; if (!SecondaryTile.Exists(crypto)) { if (!await tile.RequestCreateAsync()) { return(false); } } else { await tile.UpdateAsync(); } XmlDocument content = await GenerateCoinTile(crypto); TileNotification notification = new TileNotification(content) { Tag = crypto }; TileUpdateManager.CreateTileUpdaterForSecondaryTile(crypto).Update(notification); return(true); }
public static async void UpdateSecondaryTile(string guid, string text, string icon, string imgSrc150x150, string imgSrc310x150, string imgSrc310x310) { if (Windows.UI.StartScreen.SecondaryTile.Exists(guid)) { SecondaryTile secondaryTile = new SecondaryTile(guid); secondaryTile.VisualElements.Square150x150Logo = new Uri(imgSrc150x150); secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true; secondaryTile.VisualElements.Wide310x150Logo = new Uri(imgSrc310x150); secondaryTile.VisualElements.ShowNameOnWide310x150Logo = true; secondaryTile.VisualElements.Square310x310Logo = new Uri(imgSrc310x310); secondaryTile.VisualElements.ShowNameOnSquare310x310Logo = true; bool isUpdated = await secondaryTile.UpdateAsync(); } else { // During creation of secondary tile, an application may set additional arguments on the tile that will be passed in during activation. // These arguments should be meaningful to the application. In this sample, we'll pass in the date and time the secondary tile was pinned. string tileActivationArguments = guid + " TabWasPinnedAt=" + DateTime.Now.ToLocalTime().ToString(); // Create a Secondary tile with all the required arguments. // Note the last argument specifies what size the Secondary tile should show up as by default in the Pin to start fly out. // It can be set to TileSize.Square150x150, TileSize.Wide310x150, or TileSize.Default. // If set to TileSize.Wide310x150, then the asset for the wide size must be supplied as well. // TileSize.Default will default to the wide size if a wide size is provided, and to the medium size otherwise. SecondaryTile secondaryTile = new SecondaryTile(guid, text, tileActivationArguments, new Uri(imgSrc150x150), TileSize.Square150x150); secondaryTile.BackgroundColor = Windows.UI.Colors.Black; secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true; secondaryTile.VisualElements.Wide310x150Logo = new Uri(imgSrc310x150); secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true; secondaryTile.VisualElements.Square310x310Logo = new Uri(imgSrc310x310); secondaryTile.VisualElements.ShowNameOnWide310x150Logo = true; bool isPinned = await secondaryTile.RequestCreateAsync(); } }
public static async Task UpdateTile(Route route, StopGroup stop, Grid containerGrid = null, SecondaryTile tile = null, bool doFlush = false) { DateTime now = DateTime.Now; int routeId = route.ID, stopId = stop.ID; var timeTable = TransitBaseComponent.Current.Logic.GetTimetable(route, stop, now); var control = await CreateStaticTileBackgroundControl(stop, route, timeTable, now); if (doFlush) { route = null; stop = null; timeTable = null; TransitBaseComponent.Current.Flush(); } string imageFileName = "stoproute" + stopId + "-" + routeId + ".png"; StorageFile imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(imageFileName, Windows.Storage.CreationCollisionOption.ReplaceExisting); if (containerGrid != null) { containerGrid.Children.Insert(0, control); } await RenderTileImage(control, imageFile, control.Width, control.Height); if (containerGrid != null) { containerGrid.Children.Remove(control); } if (tile == null) { var tiles = await SecondaryTile.FindAllAsync(); string tileArg = String.Format("{0}-{1}", routeId, stopId); tile = tiles.First(t => t.Arguments == tileArg); } tile.VisualElements.Square150x150Logo = new Uri("ms-appdata:///local/" + imageFileName); await tile.UpdateAsync(); }
public static async Task UpdateNoteTileBackgroundColor(Note note, bool transparentTile = false) { if (string.IsNullOrEmpty(note?.ID)) { return; } //must exists if (!SecondaryTile.Exists(note.ID)) { return; } var tile = new SecondaryTile(note.ID); if (tile == null) { return; } tile.VisualElements.BackgroundColor = transparentTile ? Colors.Transparent : note.Color.DarkColor.Color; await tile.UpdateAsync(); }
private async void PinButton_Click(object sender, RoutedEventArgs e) { var pinBtn = sender as AppBarButton; pinBtn.IsEnabled = false; if (SecondaryTileUtils.Exists(location.query)) { bool deleted = await new SecondaryTile( SecondaryTileUtils.GetTileId(location.query)).RequestDeleteAsync(); if (deleted) { SecondaryTileUtils.RemoveTileId(location.query); } SetPinButton(!deleted); GetPinBtn().IsEnabled = true; } else { // Initialize the tile with required arguments var tileID = DateTime.Now.Ticks.ToString(); var tile = new SecondaryTile( tileID, "SimpleWeather", "action=view-weather&query=" + location.query, new Uri("ms-appx:///Assets/Square150x150Logo.png"), TileSize.Default); // Enable wide and large tile sizes tile.VisualElements.Wide310x150Logo = new Uri("ms-appx:///Assets/Wide310x150Logo.png"); tile.VisualElements.Square310x310Logo = new Uri("ms-appx:///Assets/Square310x310Logo.png"); // Add a small size logo for better looking small tile tile.VisualElements.Square71x71Logo = new Uri("ms-appx:///Assets/Square71x71Logo.png"); // Add a unique corner logo for the secondary tile tile.VisualElements.Square44x44Logo = new Uri("ms-appx:///Assets/Square44x44Logo.png"); // Show the display name on all sizes tile.VisualElements.ShowNameOnSquare150x150Logo = true; tile.VisualElements.ShowNameOnWide310x150Logo = true; tile.VisualElements.ShowNameOnSquare310x310Logo = true; bool isPinned = await tile.RequestCreateAsync(); if (isPinned) { // Update tile with notifications SecondaryTileUtils.AddTileId(location.query, tileID); await WeatherTileCreator.TileUpdater(location); await tile.UpdateAsync(); } SetPinButton(isPinned); GetPinBtn().IsEnabled = true; } }
private async void Pin_Click(object sender, RoutedEventArgs e) { if (isPinned == false) { string filename = sid + ".bmp"; StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); // using (IRandomAccessStream ss = await file.OpenAsync(FileAccessMode.ReadWrite)) // { // await RandomAccessStream.CopyAndCloseAsync(pic, ss); // } // ((XmlElement)picNodes[0]).SetAttribute("src", "ms-appdata:// /local/pic.bmp"); IBuffer buffer = await DownloadHelper.GetBuffer(aa.SquareCover); CachedFileManager.DeferUpdates(file); await FileIO.WriteBufferAsync(file, buffer); FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); string tileID = "tile" + sid; string displayName = aa.Title; string args = "s" + sid; Uri logoUri = new Uri("ms-appdata:// /local/" + filename); var size = TileSize.Square150x150; SecondaryTile tile = new SecondaryTile(tileID, aa.Title, args, logoUri, size); tile.VisualElements.ShowNameOnSquare150x150Logo = true; tile.VisualElements.Square150x150Logo = logoUri; bool isCreated = await tile.RequestCreateAsync(); if (isCreated) { await tile.UpdateAsync(); pin.Icon = new SymbolIcon(Symbol.UnPin); pin.Label = "取消固定"; await popup.Show("固定成功"); } isPinned = true; } else { SecondaryTile tile = new SecondaryTile(); IReadOnlyList <SecondaryTile> tiles = await SecondaryTile.FindAllAsync(); foreach (var item in tiles) { if (item.Arguments == sid) { tile = item; break; } } // 有趣了,这个“‘从开始屏幕取消固定’浮出控件”压根就没有浮出过 bool isDeleted = await tile.RequestDeleteAsync(); if (isDeleted) { pin.Icon = new SymbolIcon(Symbol.Pin); pin.Label = "固定磁贴"; await popup.Show("已取消固定"); try { StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(sid + ".bmp"); await file.DeleteAsync(); } catch { } } isPinned = false; } }