diff --git a/Notes-master/.idea/.gitignore b/Notes-master/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Notes-master/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Notes-master/.idea/misc.xml b/Notes-master/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/Notes-master/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Notes-master/.idea/modules.xml b/Notes-master/.idea/modules.xml new file mode 100644 index 0000000..7800270 --- /dev/null +++ b/Notes-master/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Notes-master/Notes-master.iml b/Notes-master/Notes-master.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Notes-master/Notes-master.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java b/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java index ffe5d57..cd5b2af 100644 --- a/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java +++ b/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java @@ -30,19 +30,19 @@ import net.micode.notes.data.Notes.NoteColumns; public class NotesDatabaseHelper extends SQLiteOpenHelper { private static final String DB_NAME = "note.db"; - private static final int DB_VERSION = 4; + private static final int DB_VERSION = 4;// 数据库版本号 public interface TABLE { - public static final String NOTE = "note"; + public static final String NOTE = "note";// 笔记表名 - public static final String DATA = "data"; + public static final String DATA = "data";// 数据表名 } private static final String TAG = "NotesDatabaseHelper"; private static NotesDatabaseHelper mInstance; - private static final String CREATE_NOTE_TABLE_SQL = + private static final String CREATE_NOTE_TABLE_SQL =// 创建笔记表的SQL语句 "CREATE TABLE " + TABLE.NOTE + "(" + NoteColumns.ID + " INTEGER PRIMARY KEY," + NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + @@ -63,7 +63,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" + ")"; - private static final String CREATE_DATA_TABLE_SQL = + private static final String CREATE_DATA_TABLE_SQL =// 创建数据表的SQL语句 "CREATE TABLE " + TABLE.DATA + "(" + DataColumns.ID + " INTEGER PRIMARY KEY," + DataColumns.MIME_TYPE + " TEXT NOT NULL," + @@ -78,14 +78,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" + ")"; - private static final String CREATE_DATA_NOTE_ID_INDEX_SQL = + private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =// 创建数据表中NOTE_ID的索引SQL语句 "CREATE INDEX IF NOT EXISTS note_id_index ON " + TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; /** * Increase folder's note count when move note to the folder */ - private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = + private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =// 触发器:更新时增加文件夹笔记数量 "CREATE TRIGGER increase_folder_count_on_update "+ " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + " BEGIN " + @@ -97,7 +97,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Decrease folder's note count when move note from folder */ - private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = + private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = // 触发器:更新时减少文件夹笔记数量 "CREATE TRIGGER decrease_folder_count_on_update " + " AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE + " BEGIN " + @@ -110,7 +110,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Increase folder's note count when insert new note to the folder */ - private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = + private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =// 触发器:删除时减少文件夹笔记数量 "CREATE TRIGGER increase_folder_count_on_insert " + " AFTER INSERT ON " + TABLE.NOTE + " BEGIN " + @@ -133,7 +133,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Update note's content when insert data with type {@link DataConstants#NOTE} + * 当插入数据类型为 {@link DataConstants#NOTE} 时,更新笔记内容 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = "CREATE TRIGGER update_note_content_on_insert " + @@ -146,7 +146,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Update note's content when data with {@link DataConstants#NOTE} type has changed + * 当数据类型为 {@link DataConstants#NOTE} 的数据发生更改时,更新笔记内容 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = "CREATE TRIGGER update_note_content_on_update " + @@ -172,7 +172,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Delete datas belong to note which has been deleted + * 当数据表中的笔记被删除时,更新笔记内容触发器 */ private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = "CREATE TRIGGER delete_data_on_delete " + @@ -182,8 +182,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" + " END"; + /** - * Delete notes belong to folder which has been deleted + * 当文件夹被删除时,删除其中的笔记触发器 */ private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = "CREATE TRIGGER folder_delete_notes_on_delete " + @@ -194,7 +195,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Move notes belong to folder which has been moved to trash folder + * 当文件夹中的笔记被移动到垃圾箱时,触发器将其移动到垃圾箱 */ private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = "CREATE TRIGGER folder_move_notes_on_trash " + @@ -211,13 +212,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } public void createNoteTable(SQLiteDatabase db) { - db.execSQL(CREATE_NOTE_TABLE_SQL); + db.execSQL(CREATE_NOTE_TABLE_SQL); // 创建笔记表 reCreateNoteTableTriggers(db); createSystemFolder(db); Log.d(TAG, "note table has been created"); } - private void reCreateNoteTableTriggers(SQLiteDatabase db) { + private void reCreateNoteTableTriggers(SQLiteDatabase db) {// 重新创建笔记表触发器 db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update"); db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update"); db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_delete"); @@ -235,18 +236,17 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER); } - private void createSystemFolder(SQLiteDatabase db) { + private void createSystemFolder(SQLiteDatabase db) { // 创建系统文件夹 ContentValues values = new ContentValues(); - - /** - * call record foler for call notes - */ +/** + * 通话记录文件夹 + */ values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); /** - * root folder which is default folder + * 默认根文件夹 */ values.clear(); values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER); @@ -254,7 +254,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); /** - * temporary folder which is used for moving note + * 临时文件夹,用于移动笔记 */ values.clear(); values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER); @@ -262,7 +262,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); /** - * create trash folder + * 创建垃圾箱文件夹 */ values.clear(); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); @@ -270,24 +270,24 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); } - public void createDataTable(SQLiteDatabase db) { + public void createDataTable(SQLiteDatabase db) { // 创建数据表 db.execSQL(CREATE_DATA_TABLE_SQL); reCreateDataTableTriggers(db); db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL); Log.d(TAG, "data table has been created"); } - private void reCreateDataTableTriggers(SQLiteDatabase db) { + private void reCreateDataTableTriggers(SQLiteDatabase db) { // 删除旧的触发器 db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert"); db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update"); db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_delete"); - + // 创建新的数据表触发器 db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER); db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER); db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER); } - static synchronized NotesDatabaseHelper getInstance(Context context) { + static synchronized NotesDatabaseHelper getInstance(Context context) { // 获取单例实例 if (mInstance == null) { mInstance = new NotesDatabaseHelper(context); } @@ -295,7 +295,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } @Override - public void onCreate(SQLiteDatabase db) { + public void onCreate(SQLiteDatabase db) { // 创建数据库时调用的方法,创建笔记表和数据表 createNoteTable(db); createDataTable(db); } @@ -305,24 +305,24 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { boolean reCreateTriggers = false; boolean skipV2 = false; - if (oldVersion == 1) { + if (oldVersion == 1) { // 升级到版本2 upgradeToV2(db); - skipV2 = true; // this upgrade including the upgrade from v2 to v3 + skipV2 = true; // 此次升级包括从版本2到版本3的升级 oldVersion++; } if (oldVersion == 2 && !skipV2) { - upgradeToV3(db); + upgradeToV3(db); // 升级到版本3 reCreateTriggers = true; oldVersion++; } - if (oldVersion == 3) { + if (oldVersion == 3) { // 升级到版本4 upgradeToV4(db); oldVersion++; } - if (reCreateTriggers) { + if (reCreateTriggers) { // 重新创建触发器 reCreateNoteTableTriggers(db); reCreateDataTableTriggers(db); } @@ -333,14 +333,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } } - private void upgradeToV2(SQLiteDatabase db) { + private void upgradeToV2(SQLiteDatabase db) { // 升级到版本2,重新创建笔记表和数据表 db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); createNoteTable(db); createDataTable(db); } - private void upgradeToV3(SQLiteDatabase db) { + private void upgradeToV3(SQLiteDatabase db) { // 升级到版本3,添加新列和系统文件夹 // drop unused triggers db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert"); db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_delete"); @@ -355,7 +355,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); } - private void upgradeToV4(SQLiteDatabase db) { + private void upgradeToV4(SQLiteDatabase db) { // 升级到版本4,添加新列 db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0"); }