// 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; }
// 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 just adds a "deleted" tag, to allow remote delete when syncing public static void deleteNote(Activity activity, Note note) { note.addTag("system:deleted"); Time now = new Time(); now.SetToNow(); note.setLastChangeDate(now); putNote(activity,note); }