// gets a note from the content provider public static Note getNote(Activity activity, Uri uri) { Note note = null; // can we find a matching note? ICursor cursor = activity.ManagedQuery(uri, FULL_PROJECTION, null, null, null); // cursor must not be null and must return more than 0 entry if (!(cursor == null || cursor.Count == 0)) { // create the note from the cursor cursor.MoveToFirst(); string noteContent = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.NOTE_CONTENT)); string noteTitle = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TITLE)); string noteChangeDate = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.MODIFIED_DATE)); string noteTags = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TAGS)); string noteGUID = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.GUID)); int noteDbid = cursor.GetInt(cursor.GetColumnIndexOrThrow(Note.ID)); note = new Note(); note.setTitle(noteTitle); note.setXmlContent(stripTitleFromContent(noteContent, noteTitle)); note.setLastChangeDate(noteChangeDate); note.setTags(noteTags); note.setGuid(noteGUID); note.setDbId(noteDbid); } cursor.Close(); return note; }
// gets a note from the content provider, based on guid public static Note getNoteByGuid(Activity activity, string guid) { Uri notes = Tomdroid.CONTENT_URI; string[] whereArgs = new string[1]; whereArgs[0] = guid; // The note identifier is the guid ContentResolver cr = activity.ContentResolver; ICursor cursor = cr.Query(notes, FULL_PROJECTION, Note.GUID + "= ?", whereArgs, null); activity.StartManagingCursor(cursor); if (cursor == null || cursor.Count == 0) { cursor.Close(); return null; } else { cursor.MoveToFirst(); string noteContent = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.NOTE_CONTENT)); string noteTitle = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TITLE)); string noteChangeDate = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.MODIFIED_DATE)); string noteTags = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TAGS)); string noteGUID = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.GUID)); int noteDbid = cursor.GetInt(cursor.GetColumnIndexOrThrow(Note.ID)); Note note = new Note(); note.setTitle(noteTitle); note.setXmlContent(stripTitleFromContent(noteContent, noteTitle)); note.setLastChangeDate(noteChangeDate); note.addTag(noteTags); note.setGuid(noteGUID); note.setDbId(noteDbid); cursor.Close(); return note; } }
// this function gets all non-deleted notes as notes in an array public static Note[] getAllNotesAsNotes(Activity activity, bool includeNotebookTemplates) { Uri uri = Tomdroid.CONTENT_URI; string where = "("+Note.TAGS + " NOT LIKE '%" + "system:deleted" + "%')"; string orderBy; if (!includeNotebookTemplates) { where += " AND (" + Note.TAGS + " NOT LIKE '%" + "system:template" + "%')"; } orderBy = Note.MODIFIED_DATE + " DESC"; ICursor cursor = activity.ManagedQuery(uri, FULL_PROJECTION, where, null, orderBy); if (cursor == null || cursor.Count == 0) { TLog.d(TAG, "no notes in cursor"); return null; } TLog.d(TAG, "{0} notes in cursor",cursor.Count); Note[] notes = new Note[cursor.Count]; cursor.MoveToFirst(); int key = 0; while(!cursor.IsAfterLast) { string noteContent = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.NOTE_CONTENT)); string noteTitle = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TITLE)); string noteChangeDate = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.MODIFIED_DATE)); string noteTags = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TAGS)); string noteGUID = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.GUID)); int noteDbid = cursor.GetInt(cursor.GetColumnIndexOrThrow(Note.ID)); Note note = new Note(); note.setTitle(noteTitle); note.setXmlContent(stripTitleFromContent(noteContent, noteTitle)); note.setLastChangeDate(noteChangeDate); note.addTag(noteTags); note.setGuid(noteGUID); note.setDbId(noteDbid); notes[key++] = note; cursor.MoveToNext(); } cursor.Close(); return notes; }