Beispiel #1
0
        //        private Handler noteXMLParseHandler = new Handler() {
        //
        //            public override void handleMessage(Message msg) {
        //                
        //                //parsed ok - show
        //                if(msg.what == NoteContentBuilder.PARSE_OK) {
        //                    showNote(false);
        //
        //                //parsed not ok - error
        //                } else if(msg.what == NoteContentBuilder.PARSE_ERROR) {
        //                    
        //                    // TODO put this string in a translatable resource
        //                    new AlertDialog.Builder(EditNote.this)
        //                        .setMessage("The requested note could not be parsed. If you see this error " +
        //                                    " and you are able to replicate it, please file a bug!")
        //                        .setTitle("Error")
        //                        .setNeutralButton("Ok", new OnClickListener() {
        //                            public void onClick(DialogInterface dialog, int which) {
        //                                dialog.dismiss();
        //                                showNote(true);
        //                            }})
        //                        .Show();
        //                }
        //            }
        //        };
        //        private Handler noteXMLWriteHandler = new Handler() {
        //
        //            public override void handleMessage(Message msg) {
        //                
        //                //parsed ok - do nothing
        //                if(msg.what == NoteXMLContentBuilder.PARSE_OK) {
        //                //parsed not ok - error
        //                } else if(msg.what == NoteXMLContentBuilder.PARSE_ERROR) {
        //                    
        //                    // TODO put this string in a translatable resource
        //                    new AlertDialog.Builder(EditNote.this)
        //                        .setMessage("The requested note could not be parsed. If you see this error " +
        //                                    " and you are able to replicate it, please file a bug!")
        //                        .setTitle("Error")
        //                        .setNeutralButton("Ok", new OnClickListener() {
        //                            public void onClick(DialogInterface dialog, int which) {
        //                                dialog.dismiss();
        //                                Finish();
        //                            }})
        //                        .Show();
        //                }
        //            }
        //        };
        // custom transform filter that takes the note's title part of the URI and translate it into the note id
        // this was done to avoid problems with invalid characters in URI (ex: ? is the Query separator but could be in a note title)
        //        private TransformFilter noteTitleTransformFilter = new TransformFilter() {
        //
        //            public string transformUrl(Matcher m, string str) {
        //
        //                int id = NoteManager.getNoteId(EditNote.this, str);
        //                
        //                // return something like content://org.tomdroid.notes/notes/3
        //                return Tomdroid.CONTENT_URI.ToString()+"/"+id;
        //            }
        //        };
        private bool updateNoteContent(bool xml)
        {
            StringBuilder newNoteContent = new StringBuilder();
            if(xml) {
                // parse XML
                string xmlContent = "<note-content version=\"1.0\">"+this.content.getText().ToString()+"</note-content>";
                string subjectName = this.title.getText().ToString();
                InputSource noteContentIs = new InputSource(new stringReader(xmlContent));
                try {
                    // Parsing
                    // XML
                    // Get a SAXParser from the SAXPArserFactory
                    SAXParserFactory spf = SAXParserFactory.newInstance();

                    // trashing the namespaces but keep prefixes (since we don't have the xml header)
                    spf.setFeature("http://xml.org/sax/features/namespaces", false);
                    spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
                    SAXParser sp = spf.newSAXParser();

                    sp.parse(noteContentIs, new NoteContentHandler(newNoteContent));
                } catch (Exception e) {
                    e.PrintStackTrace();
                    // TODO handle error in a more granular way
                    TLog.e(TAG, "There was an error parsing the note {0}", subjectName);
                    return false;
                }

            }
            else
                newNoteContent = (StringBuilder) this.content.getText();

            // store changed note content
            string newXmlContent = new NoteXMLContentBuilder().setCaller(noteXMLWriteHandler).setInputSource(newNoteContent).build();

            // Since 0.5 EditNote expects the redundant title being removed from the note content, but we still may need this for debugging:
            //note.setXmlContent("<note-content version=\"0.1\">"+note.getTitle()+"\n\n"+newXmlContent+"</note-content>");
            note.setXmlContent(newXmlContent);
            noteContent = note.getNoteContent(noteXMLWriteHandler);
            return true;
        }
Beispiel #2
0
        void useSendText(string sharedContent, string sharedTitle)
        {
            if (sharedContent != null) {
                // parse XML
                StringBuilder newNoteContent = new StringBuilder();

                string xmlContent = "<note-content version=\"1.0\">"+sharedContent+"</note-content>";
                InputSource noteContentIs = new InputSource(new stringReader(xmlContent));
                try {
                    // Parsing
                    // XML
                    // Get a SAXParser from the SAXPArserFactory
                    SAXParserFactory spf = SAXParserFactory.newInstance();

                    // trashing the namespaces but keep prefixes (since we don't have the xml header)
                    spf.setFeature("http://xml.org/sax/features/namespaces", false);
                    spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
                    SAXParser sp = spf.newSAXParser();

                    sp.parse(noteContentIs, new NoteContentHandler(newNoteContent));
                } catch (Exception e) {
                    e.PrintStackTrace();
                    // TODO handle error in a more granular way
                    TLog.e(TAG, "There was an error parsing the note {0}", sharedTitle);
                }
                // store changed note content
                string newXmlContent = new NoteXMLContentBuilder().setCaller(noteXMLWriteHandler).setInputSource(newNoteContent).build();
                // validate title (duplicates, empty,...)
                string validTitle = NoteManager.validateNoteTitle(this, sharedTitle, UUID.RandomUUID().ToString());

                // add a new note
                Note note = NewNote.createNewNote(this, validTitle, newXmlContent);
                Android.Net.Uri uri = NoteManager.putNote(this, note);

                // view new note
                Intent i = new Intent(Intent.ActionView, uri, this, typeof(EditNote));
                StartActivity(i);
                Finish();
            }
        }