Jot Settings:
public List<StrokeCollection> StrokeCollections { get; set; } public int PageNumber { set; get; } public Color Foreground { set; get; } public Color Background { set; get; } public int StrokeWidth { set; get; } public JotAppSettings() { this.PageNumber = 0; this.Foreground = (Color)Application.Current.Resources["PhoneForegroundColor"]; this.Background = (Color)Application.Current.Resources["PhoneBackgroundColor"]; this.StrokeWidth = 3; } public void Save() { IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); IsolatedStorageFileStream stream = iso.CreateFile("settings.xml"); StreamWriter writer = new StreamWriter(stream); XmlSerializer ser = new XmlSerializer(typeof(JotAppSettings)); ser.Serialize(writer, this); writer.Close(); iso.Dispose(); } public static JotAppSettings Load() { JotAppSettings settings; IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); if (iso.FileExists("settings.xml")) { IsolatedStorageFileStream stream = iso.OpenFile("settings.xml", FileMode.Open); StreamReader reader = new StreamReader(stream); XmlSerializer ser = new XmlSerializer(typeof(JotAppSettings)); settings = ser.Deserialize(reader) as JotAppSettings; reader.Close(); } else { // Create and initialize new JotAppSettings object settings = new JotAppSettings(); settings.StrokeCollections = new List<StrokeCollection>(); settings.StrokeCollections.Add(new StrokeCollection()); } iso.Dispose(); return settings; }
App集中存取:
public JotAppSettings AppSettings { set; get; } private void Application_Launching(object sender, LaunchingEventArgs e) { AppSettings = JotAppSettings.Load(); } private void Application_Activated(object sender, ActivatedEventArgs e) { AppSettings = JotAppSettings.Load(); } private void Application_Deactivated(object sender, DeactivatedEventArgs e) { AppSettings.Save(); } private void Application_Closing(object sender, ClosingEventArgs e) { AppSettings.Save(); }
Jot Touch:
public partial class MainPage : PhoneApplicationPage { JotAppSettings appSettings = (Application.Current as App).AppSettings; Dictionary<int, Stroke> activeStrokes = new Dictionary<int, Stroke>(); public MainPage() { InitializeComponent(); inkPresenter.Strokes = appSettings.StrokeCollections[appSettings.PageNumber]; inkPresenter.Background = new SolidColorBrush(appSettings.Background); TitleAndAppbarUpdate(); Touch.FrameReported += OnTouchFrameReported; } void OnTouchFrameReported(object sender, TouchFrameEventArgs args) { TouchPoint primaryTouchPoint = args.GetPrimaryTouchPoint(null); if (primaryTouchPoint != null && primaryTouchPoint.Action == TouchAction.Down) args.SuspendMousePromotionUntilTouchUp(); TouchPointCollection touchPoints = args.GetTouchPoints(inkPresenter); foreach (TouchPoint touchPoint in touchPoints) { Point pt = touchPoint.Position; int id = touchPoint.TouchDevice.Id; switch (touchPoint.Action) { case TouchAction.Down: Stroke stroke = new Stroke(); stroke.DrawingAttributes.Color = appSettings.Foreground; stroke.DrawingAttributes.Height = appSettings.StrokeWidth; stroke.DrawingAttributes.Width = appSettings.StrokeWidth; stroke.StylusPoints.Add(new StylusPoint(pt.X, pt.Y)); inkPresenter.Strokes.Add(stroke); activeStrokes.Add(id, stroke); break; case TouchAction.Move: activeStrokes[id].StylusPoints.Add(new StylusPoint(pt.X, pt.Y)); break; case TouchAction.Up: activeStrokes[id].StylusPoints.Add(new StylusPoint(pt.X, pt.Y)); activeStrokes.Remove(id); TitleAndAppbarUpdate(); break; } } } }
Jot ApplicationBar:
<phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> <shell:ApplicationBarIconButton x:Name="appbarAddButton" IconUri="/Images/appbar.add.rest.png" Text="add page" Click="OnAppbarAddClick" /> <shell:ApplicationBarIconButton x:Name="appbarLastButton" IconUri="/Images/appbar.back.rest.png" Text="last page" Click="OnAppbarLastClick" /> <shell:ApplicationBarIconButton x:Name="appbarNextButton" IconUri="/Images/appbar.next.rest.png" Text="next page" Click="OnAppbarNextClick" /> <shell:ApplicationBarIconButton x:Name="appbarDeleteButton" IconUri="/Images/appbar.delete.rest.png" Text="delete page" Click="OnAppbarDeleteClick" /> <shell:ApplicationBar.MenuItems> <shell:ApplicationBarMenuItem Text="swap colors" Click="OnAppbarSwapColorsClick" /> <shell:ApplicationBarMenuItem Text="light stroke width" Click="OnAppbarSetStrokeWidthClick" /> <shell:ApplicationBarMenuItem Text="medium stroke width" Click="OnAppbarSetStrokeWidthClick" /> <shell:ApplicationBarMenuItem Text="heavy stroke width" Click="OnAppbarSetStrokeWidthClick" /> </shell:ApplicationBar.MenuItems> </shell:ApplicationBar> </phone:PhoneApplicationPage.ApplicationBar>
public MainPage() { InitializeComponent(); appbarLastButton = this.ApplicationBar.Buttons[1] as ApplicationBarIconButton; appbarNextButton = this.ApplicationBar.Buttons[2] as ApplicationBarIconButton; appbarDeleteButton = this.ApplicationBar.Buttons[3] as ApplicationBarIconButton; } void OnAppbarAddClick(object sender, EventArgs args) { StrokeCollection strokes = new StrokeCollection(); appSettings.PageNumber += 1; appSettings.StrokeCollections.Insert(appSettings.PageNumber, strokes); inkPresenter.Strokes = strokes; TitleAndAppbarUpdate(); } void OnAppbarLastClick(object sender, EventArgs args) { appSettings.PageNumber -= 1; inkPresenter.Strokes = appSettings.StrokeCollections[appSettings.PageNumber]; TitleAndAppbarUpdate(); } void OnAppbarNextClick(object sender, EventArgs args) { appSettings.PageNumber += 1; inkPresenter.Strokes = appSettings.StrokeCollections[appSettings.PageNumber]; TitleAndAppbarUpdate(); } void OnAppbarDeleteClick(object sender, EventArgs args) { MessageBoxResult result = MessageBox.Show("Delete this page?", "Jot", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { if (appSettings.StrokeCollections.Count == 1) { appSettings.StrokeCollections[0].Clear(); } else { appSettings.StrokeCollections.RemoveAt(appSettings.PageNumber); if (appSettings.PageNumber == appSettings.StrokeCollections.Count) appSettings.PageNumber -= 1; inkPresenter.Strokes = appSettings.StrokeCollections[appSettings.PageNumber]; } TitleAndAppbarUpdate(); } } void OnAppbarSwapColorsClick(object sender, EventArgs args) { Color foreground = appSettings.Background; appSettings.Background = appSettings.Foreground; appSettings.Foreground = foreground; inkPresenter.Background = new SolidColorBrush(appSettings.Background); foreach (StrokeCollection strokeCollection in appSettings.StrokeCollections) foreach (Stroke stroke in strokeCollection) stroke.DrawingAttributes.Color = appSettings.Foreground; } void OnAppbarSetStrokeWidthClick(object sender, EventArgs args) { ApplicationBarMenuItem item = sender as ApplicationBarMenuItem; if (item.Text.StartsWith("light")) appSettings.StrokeWidth = 1; else if (item.Text.StartsWith("medium")) appSettings.StrokeWidth = 3; else if (item.Text.StartsWith("heavy")) appSettings.StrokeWidth = 5; } void TitleAndAppbarUpdate() { pageInfoTitle.Text = String.Format(" - PAGE {0} OF {1}", appSettings.PageNumber + 1, appSettings.StrokeCollections.Count); appbarLastButton.IsEnabled = appSettings.PageNumber > 0; appbarNextButton.IsEnabled = appSettings.PageNumber < appSettings.StrokeCollections.Count - 1; appbarDeleteButton.IsEnabled = (appSettings.StrokeCollections.Count > 1) || (appSettings.StrokeCollections[0].Count > 0); }