Пример #1
0
                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);
                }
Пример #2
0
                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);
                }