Back to project page droidnotes.
The source code is released under:
GNU General Public License
If you think the Android project droidnotes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.droidnotes.app; /* w w w. ja v a 2 s .c om*/ import android.content.*; import android.database.Cursor; import android.net.Uri; public class DNHelper { public static String MESSAGE_NOTE_ID = "com.example.droidnotes.app.MESSAGE_NOTE_ID"; public static Uri BASE_URI = new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority("com.example.droidnotes.provider") .path("notes") .build(); public static Loader<Cursor> getNotesLoader(Context context) { Uri contentUri = BASE_URI; String[] projection = {DNModel.Notes.ID, DNModel.Notes.NOTE}; String orderBy = DNModel.Notes.ID + " " + "DESC"; return new CursorLoader( context, contentUri, projection, null, null, orderBy ); } public static void insertNote(Context context, Integer id, String note) { assert (id == -1 || id > 0); Uri contentUri = BASE_URI; ContentValues contentValues = new ContentValues(); if (id == -1) { contentValues.put(DNModel.Notes.NOTE, note); } else { contentValues.put(DNModel.Notes.ID, id); contentValues.put(DNModel.Notes.NOTE, note); } context.getContentResolver().insert(contentUri, contentValues); } public static void deleteNote(Context context, Integer id) { assert (id > 0); Uri contentUri = ContentUris.withAppendedId(BASE_URI, id); context.getContentResolver().delete( contentUri, null, null ); } public static String queryNote(Context context, Integer id) { assert (id > 0); Uri contentUri = ContentUris.withAppendedId(BASE_URI, id); String[] projection = {DNModel.Notes.ID, DNModel.Notes.NOTE}; Cursor cursor = context.getContentResolver().query( contentUri, projection, null, null, null ); String note; if (cursor.getCount() > 0) { cursor.moveToFirst(); note = cursor.getString(1); } else { note = null; } return note; } public static void spawnInsertNoteActivity(Context context, Integer id) { Intent intent = new Intent(context, InsertNoteActivity.class); intent.putExtra(MESSAGE_NOTE_ID, id); context.startActivity(intent); } public static void spawnDeleteNoteDialog(Context context, Integer id) { deleteNote(context, id); } }