public void Destroy(object obj) { // release references to our UI objects if (ChildControls != null) { foreach (IUIControl uiControl in ChildControls) { uiControl.RemoveFromView(obj); } // and clear our UI list ChildControls.Clear( ); } if (UserNoteControls != null) { // remove (but don't destroy) the notes foreach (IUIControl uiControl in UserNoteControls) { uiControl.RemoveFromView(obj); } UserNoteControls.Clear(); } NoteXml = null; }
public bool DidDoubleTap(PointF touch) { // do not allow a new note within range of another's anchor. bool allowNoteCreation = true; // don't let them get ridiculous with their notes if (UserNoteControls.Count < 20) { foreach (UserNote userNote in UserNoteControls) { if (userNote.TouchInAnchorRange(touch)) { allowNoteCreation = false; } } } else { throw new Exception(MobileApp.Shared.Strings.MessagesStrings.TooManyNotes); } // don't let them create one on top of a reveal box. //Reveal Boxes List <IUIControl> revealBoxes = new List <IUIControl>( ); GetControlOfType <RevealBox>(revealBoxes); foreach (IUIControl control in revealBoxes) { // test for this touch position inside a reveal box RectangleF frame = ((RevealBox)control).GetHitTarget( ); if (frame.Contains(touch)) { allowNoteCreation = false; } } if (allowNoteCreation) { UserNote userNote = new UserNote(new BaseControl.CreateParams(this, Frame.Width, Frame.Height, ref mStyle), DeviceHeight, touch, UserNoteChanged); UserNoteControls.Add(userNote); userNote.AddToView(MasterView); userNote.OpenNote(true); return(true); } return(false); }
public void GetNotesForEmail(out string htmlStream, out string textStream) { // first setup the string that will contain the notes htmlStream = "<!DOCTYPE html PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<HTML><Body>\n"; textStream = ""; // make a COPY of the user notes so the html stream generator can modify it IUIControl[] userNotes = UserNoteControls.ToArray( ); List <IUIControl> userNoteListCopy = new List <IUIControl>( ); for (int i = 0; i < userNotes.Length; i++) { userNoteListCopy.Add(userNotes[i]); } // let each control recursively build its html stream. // provide the user note list so it can embed user notes in the appropriate spots. foreach (IUIControl control in ChildControls) { control.BuildHTMLContent(ref htmlStream, ref textStream, userNoteListCopy); htmlStream += "<br><br>"; textStream += "\n\n"; } // if there happened to be any user note that wasn't already added, drop it in at the bottom if (userNoteListCopy.Count > 0) { foreach (UserNote note in userNoteListCopy) { note.BuildHTMLContent(ref htmlStream, ref textStream, null); } } htmlStream += "</Body></HTML>"; }
protected NoteState LoadState(string filePath) { NoteState noteState = null; // if the file exists if (System.IO.File.Exists(filePath) == true) { // read it using (StreamReader reader = new StreamReader(filePath)) { // grab the stream that reprents a list of all their notes string json = reader.ReadLine(); if (json != null) { noteState = JsonConvert.DeserializeObject <NoteState>(json) as NoteState; } } } if (noteState != null) { // restore each user note foreach (NoteState.UserNoteContent note in noteState.UserNoteContentList) { // create the note, add it to our list, and to the view UserNote userNote = new UserNote(new BaseControl.CreateParams(this, Frame.Width, Frame.Height, ref mStyle), DeviceHeight, note, UserNoteChanged); UserNoteControls.Add(userNote); userNote.AddToView(MasterView); } // we can assume that the states are 1:1 in the same order as the controls, // because the controls are sorted right after being created, so we're guaranteed // their order is known. There's no risk they were created in a different order. // collect all the reveal boxes and restore them List <IUIControl> revealBoxes = new List <IUIControl>( ); GetControlOfType <RevealBox>(revealBoxes); // for the count, take whichever is less, the number of reveal boxes OR the state list, // because it's possible the note was changed after the last save, and a reveal box // may have been added / removed. int revealBoxCount = Math.Min(revealBoxes.Count, noteState.RevealBoxStateList.Count); for (int i = 0; i < revealBoxCount; i++) { RevealBox revealBox = revealBoxes[i] as RevealBox; revealBox.SetRevealed(noteState.RevealBoxStateList[i].Revealed); } // collect all the text inputs and restore them List <IUIControl> textInputList = new List <IUIControl>( ); GetControlOfType <TextInput>(textInputList); // for the count, take whichever is less, the number of text inputs OR the state list, // because it's possible the note was changed after the last save, and a text input // may have been added / removed. int textInputCount = Math.Min(textInputList.Count, noteState.TextInputStateList.Count); for (int i = 0; i < textInputCount; i++) { TextInput textInput = textInputList[i] as TextInput; textInput.SetText(noteState.TextInputStateList[i].Text); } } return(noteState); }
public string TouchesEnded(PointF touch, out bool urlLaunchesExternalBrowser, out bool urlUsesRockImpersonation) { // TouchesEnded is tricky. It's reasonable a User will have // the keyboard up and decide to open/close/move another Note. // This should NOT cause the keyboard to hide. The only time a keyboard // should hide is if a User taps on a general area of the screen. // To accomplish this, we rely on ActiveUserNoteAnchor. If it's valid in TouchesEnded, // that means the touch was in an anchor and not a general part of the screen. // Secondly, if a normal control was touched, it may contain an active link. If a control // consumes input, we will ask it for its link and return that to the caller. // An example would be a Quote. It will consume input and then return a link to the citation. string activeUrl = string.Empty; urlLaunchesExternalBrowser = false; urlUsesRockImpersonation = false; // If there's an active UserNote Anchor, notify only it. if (ActiveUserNoteAnchor != null) { // Notify the active anchor, and clear it since the user released input. ActiveUserNoteAnchor.TouchesEnded(touch); // does this note want to be deleted? if (ActiveUserNoteAnchor.State == UserNote.TouchState.Delete) { // reset its state, and we'll let the messagebox result decide ActiveUserNoteAnchor.State = UserNote.TouchState.None; // then store a pointer to this note UserNote activeNote = ActiveUserNoteAnchor; // and have the system prompt the user for confirmation RequestDisplayMessageBox(MessagesStrings.UserNote_DeleteTitle, MessagesStrings.UserNote_DeleteMessage, delegate(int result) { // if they said yes, do it. if (result == 0) { // remove it from our list. UserNoteControls.Remove(activeNote); // notify our parent UserNoteChanged(activeNote); // now clear the anchor ref, which will effectively delete the note (eligible for garbage collection) activeNote.Dispose(MasterView); } }); } // clear the user note ActiveUserNoteAnchor = null; } else { // Since a UserNote Anchor was NOT touched, we know it was a "general" // area of the screen, and can allow the keyboard to hide. foreach (UserNote userNote in UserNoteControls) { userNote.NoteTouchesCleared( ); } // Now notify all remaining controls until we find out one consumed it. // 1. Start with User Notes. They should get first priority bool consumed = false; foreach (IUIControl control in UserNoteControls) { // was it consumed? IUIControl consumingControl = control.TouchesEnded(touch); if (consumingControl != null) { consumed = true; break; } } // if no user note consumed it, notify all regular controls if (consumed == false) { // 2. check all NON-revealed reveal boxees. // This allows them to get priority over taps on URLs and already-revealed boxes. List <IUIControl> revealBoxes = new List <IUIControl>( ); GetControlOfType <RevealBox>(revealBoxes); foreach (IUIControl control in revealBoxes) { // if not revealed and consuming input, we're good. if ((control as RevealBox).Revealed == false && control.TouchesEnded(touch) != null) { consumed = true; break; } } // 3. notify all remaining controls if (consumed == false) { foreach (IUIControl control in ChildControls) { // was it consumed? IUIControl consumingControl = control.TouchesEnded(touch); if (consumingControl != null) { // then see if it has an active URL we should hit activeUrl = consumingControl.GetActiveUrl(out urlLaunchesExternalBrowser, out urlUsesRockImpersonation); break; } } } } } return(activeUrl); }