/// <summary> /// Saves data into the Windows.Storage.ApplicaitonDataContainer object with the App.Apps enum /// as the key. Note: this will fail if the state to be saved is larger than 8k /// </summary> /// <param name="app">The calling app's identity</param> /// <param name="key">A unique key for the type of memory being saved, handy if the app saves more than one type of state</param> /// <param name="value">The object which represents the state to be serialized and saved into roaming state</param> /// <returns>True if the save was successfull, false otherwise</returns> public static bool SaveRoamingState(App.Apps app, string key, object value) { // Because there are many "calc" views but we want the memory to be preserved in between // all of the views if (Calc_MainPage.IsCalculator(app)) { app = App.Apps.Calculator; } try { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; string serialized = string.Empty; List <object> memoryItemsObj = new List <object>(); // Calc specific if (value is ObservableCollection <Calculator.MemoryItem> ) { foreach (Calculator.MemoryItem memItem in value as ObservableCollection <Calculator.MemoryItem> ) { memoryItemsObj.Add(memItem as object); } } else if (value is List <PCalender.Period> ) { foreach (PCalender.Period period in value as List <PCalender.Period> ) { memoryItemsObj.Add(period as object); } } // TODO other apps serialized = JSONCode.JSON.JsonEncode(memoryItemsObj); // add the value into the roaming state array if (roamingSettings.Values.ContainsKey(app.ToString() + key)) { roamingSettings.Values[app.ToString() + key] = serialized; } else { roamingSettings.Values.Add(app.ToString() + key, serialized); } } catch { return(false); } return(true); }
/// <summary> /// Clears the roaming state of a given application /// </summary> /// <param name="app">The calling app's identity</param> /// <returns>True if the clear was successfull, false otherwise</returns> public static bool ClearRoamingState(App.Apps app, string key) { try { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; if (roamingSettings.Values.ContainsKey(app.ToString() + key)) { roamingSettings.Values.Remove(app.ToString() + key); } } catch { return(false); } return(true); }
private void MainScape_RightTapped(object o, RightTappedEventArgs e) { if (RightPanel != null) { // capture the app thats been selected into the global selectedAppObject = e.appObject; // create the button pinToAppBar = new Button(); // check if the app is already pinned then change the button based on that information ToggleAppBarButton(!SecondaryTile.Exists(selectedAppObject.ToString())); // add the event handler for click pinToAppBar.Click += new RoutedEventHandler(pinToAppBar_Click); // clear all the childredn first RightPanel.Children.Clear(); // add the button to the app bar RightPanel.Children.Add(pinToAppBar); SecondaryTileAppBar.IsOpen = true; } }
/// <summary> /// Saves data into the Windows.Storage.ApplicaitonDataContainer object with the App.Apps enum /// as the key. Note: this will fail if the state to be saved is larger than 8k /// </summary> /// <param name="app">The calling app's identity</param> /// <param name="state">The object which represents the state to be serialized and saved into roaming state</param> /// <returns>True if the save was successfull, false otherwise</returns> public static bool SaveRoamingState(App.Apps app, string key, string value) { try { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; // add the value into the roaming state array if (roamingSettings.Values.ContainsKey(app.ToString() + key)) { roamingSettings.Values[app.ToString() + key] = value; } else { roamingSettings.Values.Add(app.ToString() + key, value); } } catch { return(false); } return(true); }
async void pinToAppBar_Click(object sender, RoutedEventArgs e) { string selectedApp = selectedAppObject.ToString(); SecondaryTileAppBar.IsSticky = true; if (SecondaryTile.Exists(selectedApp)) { SecondaryTile secondaryTile = new SecondaryTile(selectedApp); bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above); ToggleAppBarButton(isUnpinned); } else { Uri logo = Helpers.GetSnappedURI(Helpers.selectImage(selectedAppObject, true)); string tileActivationArguments = selectedApp; SecondaryTile secondaryTile = new SecondaryTile(selectedApp, App.Apps.UnitConverter.ToString() + " - " + selectedApp, tileActivationArguments, logo, TileSize.Default ); secondaryTile.VisualElements.ForegroundText = ForegroundText.Dark; secondaryTile.VisualElements.Square44x44Logo = Helpers.GetSnappedURI(Helpers.selectImage(selectedAppObject, true)); bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above); ToggleAppBarButton(!isPinned); // uncheck the items in mainscape MainScape.UnselectCurrentItem(); } SecondaryTileAppBar.IsSticky = false; SecondaryTileAppBar.IsOpen = false; }
/// <summary> /// Deserializes the input string into a c# generic object /// </summary> /// <param name="app">The calling app's identity</param> /// <param name="success">True if the clear was successfull, false otherwise</param> /// <returns>The deserialized generic object. If the method fails the return is null</returns> public static object LoadRoamingState(App.Apps app, string key, ref bool success, Calc_MainPage page = null) { success = false; try { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; string serialized = roamingSettings.Values[app.ToString() + key] as string; if (serialized.StartsWith("{") || serialized.StartsWith("[")) { object obj = JSONCode.JSON.JsonDecode(serialized, ref success); // Calculator specific if (app == App.Apps.Calculator) { return(ConvertToCalc(obj, ref success, page)); } // PCalendar specific else if (app == App.Apps.PCalendar) { return(ConvertToPCal(obj, ref success)); } // TODO other apps } else { return(serialized); } } catch { return(null); } return(null); }
/// <summary> /// Determines if the roaming state manager has the selected value saved /// </summary> /// <param name="app">The calling app's identity</param> /// <param name="key">The key for the settings</param> /// <returns></returns> public static bool RoamingStateExists(App.Apps app, string key) { Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; return(roamingSettings.Values.ContainsKey(app.ToString() + key)); }