in notepad/app/src/main/java/com/example/android/notepad/NotePadProvider.java [154:196]
public Uri insert(Uri uri, ContentValues initialValues) {
// Validate the requested uri
if (sUriMatcher.match(uri) != NOTES) {
throw new IllegalArgumentException("Unknown URI " + uri);
}
ContentValues values;
if (initialValues != null) {
values = new ContentValues(initialValues);
} else {
values = new ContentValues();
}
Long now = Long.valueOf(System.currentTimeMillis());
// Make sure that the fields are all set
if (values.containsKey(NoteColumns.CREATED_DATE) == false) {
values.put(NoteColumns.CREATED_DATE, now);
}
if (values.containsKey(NoteColumns.MODIFIED_DATE) == false) {
values.put(NoteColumns.MODIFIED_DATE, now);
}
if (values.containsKey(NoteColumns.TITLE) == false) {
Resources r = Resources.getSystem();
values.put(NoteColumns.TITLE, r.getString(android.R.string.untitled));
}
if (values.containsKey(NoteColumns.NOTE) == false) {
values.put(NoteColumns.NOTE, "");
}
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
long rowId = db.insert(NOTES_TABLE_NAME, NoteColumns.NOTE, values);
if (rowId > 0) {
Uri noteUri = ContentUris.withAppendedId(NoteColumns.CONTENT_URI, rowId);
getContext().getContentResolver().notifyChange(noteUri, null);
return noteUri;
}
throw new SQLException("Failed to insert row into " + uri);
}