Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String ID = "_id"; +======= + public static final String ID = "_id";// 行的唯一标识符 +>>>>>>> liuyitao-branch /** * The parent's id for note or folder *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String PARENT_ID = "parent_id"; +======= + public static final String PARENT_ID = "parent_id";// 父级的ID +>>>>>>> liuyitao-branch /** * Created data for note or folder *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String CREATED_DATE = "created_date"; +======= + public static final String CREATED_DATE = "created_date";// 创建日期 +>>>>>>> liuyitao-branch /** * Latest modified date *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String MODIFIED_DATE = "modified_date"; +======= + public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 +>>>>>>> liuyitao-branch /** * Alert date *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String ALERTED_DATE = "alert_date"; +======= + public static final String ALERTED_DATE = "alert_date";// 提醒日期 +>>>>>>> liuyitao-branch /** * Folder's name or text content of note *Type: TEXT
*/ +<<<<<<< HEAD public static final String SNIPPET = "snippet"; +======= + public static final String SNIPPET = "snippet";// 文件夹名称或便签的文本内容 +>>>>>>> liuyitao-branch /** * Note's widget id *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String WIDGET_ID = "widget_id"; +======= + public static final String WIDGET_ID = "widget_id";// 便签的Widget ID +>>>>>>> liuyitao-branch /** * Note's widget type *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String WIDGET_TYPE = "widget_type"; +======= + public static final String WIDGET_TYPE = "widget_type";// 便签的Widget类型 +>>>>>>> liuyitao-branch /** * Note's background color's id *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String BG_COLOR_ID = "bg_color_id"; +======= + public static final String BG_COLOR_ID = "bg_color_id";// 便签的背景颜色ID +>>>>>>> liuyitao-branch /** * For text note, it doesn't has attachment, for multi-media * note, it has at least one attachment *Type: INTEGER
*/ +<<<<<<< HEAD public static final String HAS_ATTACHMENT = "has_attachment"; +======= + public static final String HAS_ATTACHMENT = "has_attachment";// 是否有附件 +>>>>>>> liuyitao-branch /** * Folder's count of notes *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String NOTES_COUNT = "notes_count"; +======= + public static final String NOTES_COUNT = "notes_count";// 文件夹中的便签数量 +>>>>>>> liuyitao-branch /** * The file type: folder or note *Type: INTEGER
*/ +<<<<<<< HEAD public static final String TYPE = "type"; +======= + public static final String TYPE = "type";// 文件类型:文件夹或便签 +>>>>>>> liuyitao-branch /** * The last sync id *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String SYNC_ID = "sync_id"; +======= + public static final String SYNC_ID = "sync_id";// 最后同步的ID +>>>>>>> liuyitao-branch /** * Sign to indicate local modified or not *Type: INTEGER
*/ +<<<<<<< HEAD public static final String LOCAL_MODIFIED = "local_modified"; +======= + public static final String LOCAL_MODIFIED = "local_modified";// 标识是否本地修改 +>>>>>>> liuyitao-branch /** * Original parent id before moving into temporary folder *Type : INTEGER
*/ +<<<<<<< HEAD public static final String ORIGIN_PARENT_ID = "origin_parent_id"; +======= + public static final String ORIGIN_PARENT_ID = "origin_parent_id";// 移动到临时文件夹之前的原始父级ID +>>>>>>> liuyitao-branch /** * The gtask id *Type : TEXT
*/ +<<<<<<< HEAD public static final String GTASK_ID = "gtask_id"; +======= + public static final String GTASK_ID = "gtask_id";// Google任务ID +>>>>>>> liuyitao-branch /** * The version code *Type : INTEGER (long)
*/ +<<<<<<< HEAD public static final String VERSION = "version"; } +======= + public static final String VERSION = "version";// 版本号 + } + + /* + * 功能描述:定义DataColumns接口数据的常量,用于创建数据库表头 + */ +>>>>>>> liuyitao-branch public interface DataColumns { /** * The unique ID for a row *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String ID = "_id"; +======= + public static final String ID = "_id";// 标识符 +>>>>>>> liuyitao-branch /** * The MIME type of the item represented by this row. *Type: Text
*/ +<<<<<<< HEAD public static final String MIME_TYPE = "mime_type"; +======= + public static final String MIME_TYPE = "mime_type";// 数据的MIME类型 +>>>>>>> liuyitao-branch /** * The reference id to note that this data belongs to *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String NOTE_ID = "note_id"; +======= + public static final String NOTE_ID = "note_id";// 数据ID +>>>>>>> liuyitao-branch /** * Created data for note or folder *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String CREATED_DATE = "created_date"; +======= + public static final String CREATED_DATE = "created_date";// 创建日期 +>>>>>>> liuyitao-branch /** * Latest modified date *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String MODIFIED_DATE = "modified_date"; +======= + public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 +>>>>>>> liuyitao-branch /** * Data's content *Type: TEXT
*/ +<<<<<<< HEAD public static final String CONTENT = "content"; +======= + public static final String CONTENT = "content";// 内容 +>>>>>>> liuyitao-branch /** @@ -210,42 +369,68 @@ public class Notes { * integer data type *Type: INTEGER
*/ +<<<<<<< HEAD public static final String DATA1 = "data1"; +======= + public static final String DATA1 = "data1";// 通用数据1 +>>>>>>> liuyitao-branch /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * integer data type *Type: INTEGER
*/ +<<<<<<< HEAD public static final String DATA2 = "data2"; +======= + public static final String DATA2 = "data2";// 通用数据2 +>>>>>>> liuyitao-branch /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * TEXT data type *Type: TEXT
*/ +<<<<<<< HEAD public static final String DATA3 = "data3"; +======= + public static final String DATA3 = "data3";// 通用数据3 +>>>>>>> liuyitao-branch /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * TEXT data type *Type: TEXT
*/ +<<<<<<< HEAD public static final String DATA4 = "data4"; +======= + public static final String DATA4 = "data4";// 通用数据4 +>>>>>>> liuyitao-branch /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * TEXT data type *Type: TEXT
*/ +<<<<<<< HEAD public static final String DATA5 = "data5"; } +======= + public static final String DATA5 = "data5";// 通用数据5 + } + + /* + * 定义了文本便签的数据结构 + */ +>>>>>>> liuyitao-branch public static final class TextNote implements DataColumns { /** * Mode to indicate the text in check list mode or not *Type: Integer 1:check list mode 0: normal mode
*/ +<<<<<<< HEAD public static final String MODE = DATA1; public static final int MODE_CHECK_LIST = 1; @@ -257,17 +442,38 @@ public class Notes { public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); } +======= + public static final String MODE = DATA1;// 模式 + + public static final int MODE_CHECK_LIST = 1;// 待办清单模式 + + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";// 内容类型 + + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";// 单个条目的内容类型 + + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");// 查询文本便签的URI + } + + /* + * 定义电话便签的数据结构 + */ +>>>>>>> liuyitao-branch public static final class CallNote implements DataColumns { /** * Call date for this record *Type: INTEGER (long)
*/ +<<<<<<< HEAD public static final String CALL_DATE = DATA1; +======= + public static final String CALL_DATE = DATA1;// 通话日期 +>>>>>>> liuyitao-branch /** * Phone number for this record *Type: TEXT
*/ +<<<<<<< HEAD public static final String PHONE_NUMBER = DATA3; public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note"; @@ -275,5 +481,14 @@ public class Notes { public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note"; public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); +======= + public static final String PHONE_NUMBER = DATA3;// 电话号码 + + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";// 内容类型 + + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";// 单个条目的内容类型 + + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");// 查询电话便签的URI +>>>>>>> liuyitao-branch } } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java index ffe5d57..59ced1d 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java @@ -16,6 +16,7 @@ package net.micode.notes.data; +<<<<<<< HEAD import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; @@ -33,11 +34,38 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { private static final int DB_VERSION = 4; public interface TABLE { +======= + +import android.content.ContentValues;//就是用于保存一些数据(string boolean byte double float int long short ...)信息,这些信息可以被数据库操作时使用。 +import android.content.Context;//加载和访问资源。(android中主要是这两个功能,但是这里具体不清楚) +import android.database.sqlite.SQLiteDatabase;//主要提供了对应于添加、删除、更新、查询的操作方法: insert()、delete()、update()和query()。配合content.values +import android.database.sqlite.SQLiteOpenHelper;//用来管理数据的创建和版本更新 +import android.util.Log; + + +import net.micode.notes.data.Notes.DataColumns; +import net.micode.notes.data.Notes.DataConstants; +import net.micode.notes.data.Notes.NoteColumns; +/* +* 功能描述:数据库操作,用SQLOpenhelper,对一些note和文件进行数据库的操作 +*/ + +public class NotesDatabaseHelper extends SQLiteOpenHelper { + private static final String DB_NAME = "note.db";// 数据库名 + + private static final int DB_VERSION = 4;// 版本号 + + public interface TABLE { + /* + * 接口,分成note和data,用于表示数据库中两种表格 + * */ +>>>>>>> liuyitao-branch public static final String NOTE = "note"; public static final String DATA = "data"; } +<<<<<<< HEAD private static final String TAG = "NotesDatabaseHelper"; private static NotesDatabaseHelper mInstance; @@ -78,6 +106,61 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" + ")"; +======= + private static final String TAG = "NotesDatabaseHelper";// 日志标签,用于在日志中标识数据库操作的相关信息 + + /* + * NotesDatabaseHelper 类的实例,用于单例模式的数据库操作,通过 getInstance() 方法获取 NotesDatabaseHelper 的唯一实例 + * 单例模式是一种设计模式,在数据库操作中使用单例模式可以确保只有一个数据库连接,避免了重复创建和关闭数据库连接可能导致的性能问题 + */ + private static NotesDatabaseHelper mInstance; + + /* + * 创建TABLE.NOTE表格,用于存储便签的相关信息 + */ + private static final String CREATE_NOTE_TABLE_SQL = + "CREATE TABLE " + TABLE.NOTE + "(" + + NoteColumns.ID + " INTEGER PRIMARY KEY," +// 便签ID + NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签父级的ID + NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," +// 便签的提醒日期 + NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," + // 便签的背景颜色ID + NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + // 便签的创建日期 + NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," +// 便签是否有附件 + NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 便签的最后修改日期 + NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," +// 文件夹中的便签数量 + NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," +// 文件夹名称或便签的文本内容 + NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," +// 便签的类型 + NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签的Widget ID + NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," +// 便签的Widget类型 + NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签的同步ID + NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +// 便签的本地修改标记 + NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +// 原始父级便签的ID + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +// 便签在Google任务中的ID + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +// 便签的版本号 + ")"; + + /* + * 创建TABLE.DATA表格,用于存储便签中的数据 + */ + private static final String CREATE_DATA_TABLE_SQL = + "CREATE TABLE " + TABLE.DATA + "(" + + DataColumns.ID + " INTEGER PRIMARY KEY," +// 数据ID + DataColumns.MIME_TYPE + " TEXT NOT NULL," +// 数据ID数据的MIME类型 + DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," +// 数据所属的便签的ID + NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 数据的创建日期 + NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 数据的最后修改日期 + DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," +// 数据的内容 + DataColumns.DATA1 + " INTEGER," +// 数据的附加信息1 + DataColumns.DATA2 + " INTEGER," +// 数据的附加信息2 + DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +// 数据的附加信息3 + DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +// 数据的附加信息4 + DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +// 数据的附加信息5 + ")"; + + /* + * 创建一个名为 note_id_index 的索引,在 TABLE.DATA 表格的 DataColumns.NOTE_ID 列上创建索引,以提高查询性能 + */ +>>>>>>> liuyitao-branch private static final String CREATE_DATA_NOTE_ID_INDEX_SQL = "CREATE INDEX IF NOT EXISTS note_id_index ON " + TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; @@ -85,6 +168,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Increase folder's note count when move note to the folder */ +<<<<<<< HEAD +======= + + /* + * 在更新 TABLE.NOTE 表格的 NoteColumns.PARENT_ID 列时,增加相应文件夹的便签计数 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其加1 + */ +>>>>>>> liuyitao-branch 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 + @@ -97,6 +188,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Decrease folder's note count when move note from folder */ +<<<<<<< HEAD +======= + + /* + * 在更新 TABLE.NOTE 表格的 NoteColumns.PARENT_ID 列时,减少相应文件夹的便签计数 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其减1 + */ +>>>>>>> liuyitao-branch 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 + @@ -110,6 +209,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Increase folder's note count when insert new note to the folder */ +<<<<<<< HEAD +======= + + /* + * 在向 TABLE.NOTE 表格插入新便签时,增加相应文件夹的便签计数 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其加1 + */ +>>>>>>> liuyitao-branch private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = "CREATE TRIGGER increase_folder_count_on_insert " + " AFTER INSERT ON " + TABLE.NOTE + @@ -122,6 +229,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Decrease folder's note count when delete note from the folder */ +<<<<<<< HEAD +======= + + /* + * 在从 TABLE.NOTE 表格删除便签时,减少相应文件夹的便签计数 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其减1 + */ +>>>>>>> liuyitao-branch private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_delete " + " AFTER DELETE ON " + TABLE.NOTE + @@ -135,6 +250,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Update note's content when insert data with type {@link DataConstants#NOTE} */ +<<<<<<< HEAD +======= + + /* + * 在向 TABLE.DATA 表格插入类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.SNIPPET 列,将其设置为新插入数据的内容 + */ +>>>>>>> liuyitao-branch private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = "CREATE TRIGGER update_note_content_on_insert " + " AFTER INSERT ON " + TABLE.DATA + @@ -148,6 +271,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Update note's content when data with {@link DataConstants#NOTE} type has changed */ +<<<<<<< HEAD +======= + + /* + * 在更新类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 + * 通过触发器在 TABLE.DATA 表格上创建,在数据被更新后将新的内容更新到对应的便签中 + */ +>>>>>>> liuyitao-branch private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = "CREATE TRIGGER update_note_content_on_update " + " AFTER UPDATE ON " + TABLE.DATA + @@ -161,6 +292,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Update note's content when data with {@link DataConstants#NOTE} type has deleted */ +<<<<<<< HEAD +======= + + /* + * 在删除类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 + * 通过触发器在 TABLE.DATA 表格上创建,在数据被删除后将对应的便签内容清空 + */ +>>>>>>> liuyitao-branch private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = "CREATE TRIGGER update_note_content_on_delete " + " AFTER delete ON " + TABLE.DATA + @@ -174,6 +313,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Delete datas belong to note which has been deleted */ +<<<<<<< HEAD +======= + + /* + * 在删除便签时,同时删除该便签相关的数据 + * 通过触发器在 TABLE.NOTE 表格上创建,在便签被删除后将与该便签相关的数据一并删除 + */ +>>>>>>> liuyitao-branch private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = "CREATE TRIGGER delete_data_on_delete " + " AFTER DELETE ON " + TABLE.NOTE + @@ -185,6 +332,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Delete notes belong to folder which has been deleted */ +<<<<<<< HEAD +======= + + /* + * 在删除文件夹时,同时删除该文件夹下的所有便签 + * 通过触发器在 TABLE.NOTE 表格上创建,在文件夹被删除后将该文件夹下的所有便签一并删除。 + */ +>>>>>>> liuyitao-branch private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = "CREATE TRIGGER folder_delete_notes_on_delete " + " AFTER DELETE ON " + TABLE.NOTE + @@ -196,6 +351,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * Move notes belong to folder which has been moved to trash folder */ +<<<<<<< HEAD +======= + + /* + * 在将文件夹移动到回收站时,同时将该文件夹下的所有便签一并移动到回收站 + * 通过触发器在 TABLE.NOTE 表格上创建,在文件夹被移动到回收站后将该文件夹下的所有便签的父文件夹ID更新为回收站的ID + */ +>>>>>>> liuyitao-branch private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = "CREATE TRIGGER folder_move_notes_on_trash " + " AFTER UPDATE ON " + TABLE.NOTE + @@ -206,10 +369,22 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + " END"; +<<<<<<< HEAD +======= + /* + * 构造函数,传入数据库的名称和版本 + */ +>>>>>>> liuyitao-branch public NotesDatabaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } +<<<<<<< HEAD +======= + /* + * 用于创建存储标签属性的表格 + */ +>>>>>>> liuyitao-branch public void createNoteTable(SQLiteDatabase db) { db.execSQL(CREATE_NOTE_TABLE_SQL); reCreateNoteTableTriggers(db); @@ -217,7 +392,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "note table has been created"); } +<<<<<<< HEAD private void reCreateNoteTableTriggers(SQLiteDatabase db) { +======= + /* + * 用于重新创建数据库中的触发器 + */ + private void reCreateNoteTableTriggers(SQLiteDatabase db) { + // 通过执行SQL语句DROP TRIGGER IF EXISTS来删除已存在的触发器,以确保不会重复创建 +>>>>>>> liuyitao-branch 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"); @@ -225,6 +408,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_insert"); db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete"); db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash"); +<<<<<<< HEAD db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER); db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER); @@ -235,12 +419,33 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER); } +======= + // 创建新的触发器 + db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 增加文件夹计数的触发器 + db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 减少文件夹计数的触发器 + db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER);// 删除文件夹计数的触发器 + db.execSQL(NOTE_DELETE_DATA_ON_DELETE_TRIGGER);// 在删除时同时删除数据的触发器 + db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER);// 增加文件夹计数的触发器 + db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER);// 在删除时同时删除文件夹中的笔记的触发器 + db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);// 将笔记移动到垃圾箱的触发器 + } + + /* + *用于创建系统文件夹,插入四个不同类型的文件夹记录到 NoteColumns 表中 + */ +>>>>>>> liuyitao-branch private void createSystemFolder(SQLiteDatabase db) { ContentValues values = new ContentValues(); /** * call record foler for call notes */ +<<<<<<< HEAD +======= + /* + * 创建通话记录文件夹 + */ +>>>>>>> liuyitao-branch values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); @@ -248,6 +453,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * root folder which is default folder */ +<<<<<<< HEAD +======= + /* + * 根目录,即默认文件夹 + */ +>>>>>>> liuyitao-branch values.clear(); values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); @@ -256,6 +467,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * temporary folder which is used for moving note */ +<<<<<<< HEAD +======= + /* + * 临时目录,用于移动笔记 + */ +>>>>>>> liuyitao-branch values.clear(); values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); @@ -264,12 +481,19 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /** * create trash folder */ +<<<<<<< HEAD +======= + /* + * 创建垃圾箱 + */ +>>>>>>> liuyitao-branch values.clear(); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); } +<<<<<<< HEAD public void createDataTable(SQLiteDatabase db) { db.execSQL(CREATE_DATA_TABLE_SQL); reCreateDataTableTriggers(db); @@ -277,6 +501,21 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "data table has been created"); } +======= + /* + * 用于创建存储标签内容的表格 + */ + public void createDataTable(SQLiteDatabase db) { + db.execSQL(CREATE_DATA_TABLE_SQL);// 执行 CREATE_DATA_TABLE_SQL 的 SQL 语句来创建数据表 + reCreateDataTableTriggers(db);// 调用 reCreateDataTableTriggers() 方法重新创建数据表中的触发器 + db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);// 执行 CREATE_DATA_NOTE_ID_INDEX_SQL 的 SQL 语句来创建一个索引 + Log.d(TAG, "data table has been created"); + } + + /* + * 用于重新创建数据表中的触发器 + */ +>>>>>>> liuyitao-branch 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"); @@ -287,6 +526,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER); } +<<<<<<< HEAD +======= + /* + * 用于获取单例的数据库帮助类对象 + * 解决同一时刻只能有一个线程执行. + * 在写程序库代码时,有时有一个类需要被所的其它类使用 + * 但又要求这个类只能被实例化一次,是个服务类,定义一次,其它类使用同一个这个类的实例 + */ +>>>>>>> liuyitao-branch static synchronized NotesDatabaseHelper getInstance(Context context) { if (mInstance == null) { mInstance = new NotesDatabaseHelper(context); @@ -295,44 +543,87 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } @Override +<<<<<<< HEAD +======= + /* + * 在数据库第一次创建时被调用,用于创建所需的表格和触发器 + */ +>>>>>>> liuyitao-branch public void onCreate(SQLiteDatabase db) { createNoteTable(db); createDataTable(db); } @Override +<<<<<<< HEAD public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { boolean reCreateTriggers = false; boolean skipV2 = false; +======= + /* + * 根据旧版本和新版本之间的差异来执行相应的数据库升级操作 + */ + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + boolean reCreateTriggers = false; + boolean skipV2 = false;// 是否进行V2升级 + /* + * 如果旧版本为1,则调用upgradeToV2方法 + */ +>>>>>>> liuyitao-branch if (oldVersion == 1) { upgradeToV2(db); skipV2 = true; // this upgrade including the upgrade from v2 to v3 oldVersion++; } +<<<<<<< HEAD +======= + /* + * 如果旧版本为2且未跳过V2升级,则调用upgradeToV3方法 + */ +>>>>>>> liuyitao-branch if (oldVersion == 2 && !skipV2) { upgradeToV3(db); reCreateTriggers = true; oldVersion++; } +<<<<<<< HEAD +======= + /* + * 如果旧版本为3,则调用upgradeToV4方法 + */ +>>>>>>> liuyitao-branch if (oldVersion == 3) { upgradeToV4(db); oldVersion++; } +<<<<<<< HEAD +======= + /* + * 如果需要重新创建触发器,则调用reCreateNoteTableTriggers和reCreateDataTableTriggers方法重新创建触发器 + */ +>>>>>>> liuyitao-branch if (reCreateTriggers) { reCreateNoteTableTriggers(db); reCreateDataTableTriggers(db); } +<<<<<<< HEAD +======= + /* + * 如果旧版本和新版本不匹配,则抛出异常 + */ +>>>>>>> liuyitao-branch if (oldVersion != newVersion) { throw new IllegalStateException("Upgrade notes database to version " + newVersion + "fails"); } } +<<<<<<< HEAD private void upgradeToV2(SQLiteDatabase db) { db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); @@ -341,13 +632,47 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } private void upgradeToV3(SQLiteDatabase db) { +======= + /* + * 更新到V2版本 + * */ + private void upgradeToV2(SQLiteDatabase db) { + /* + * 通过执行SQL语句DROP TABLE IF EXISTS来删除旧的NOTE和DATA表格 + * */ + db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); + db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); + createNoteTable(db);// 调用createNoteTable和createDataTable方法来创建新的NOTE表格 + createDataTable(db);// 调用createNoteTable和createDataTable方法来创建新的DATA表格 + } + + /* + * 更新到V3版本 + * */ + private void upgradeToV3(SQLiteDatabase db) { + /* + * 执行SQL语句DROP TRIGGER IF EXISTS来移除不再使用的触发器 + * */ +>>>>>>> liuyitao-branch // 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"); db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update"); +<<<<<<< HEAD // add a column for gtask id db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''"); +======= + /* + * 执行ALTER TABLE语句向NOTE表格中添加一个新的列GTASK_ID,该列的类型是TEXT,并设置默认值为'' + * */ + // add a column for gtask id + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID + + " TEXT NOT NULL DEFAULT ''"); + /* + * 通过ContentValues对象向NOTE表格中插入一条记录,该记录代表垃圾箱系统文件夹 + * */ +>>>>>>> liuyitao-branch // add a trash system folder ContentValues values = new ContentValues(); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); @@ -355,8 +680,17 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); } +<<<<<<< HEAD private void upgradeToV4(SQLiteDatabase db) { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0"); +======= + /* + * 更新到V4版本 + * */ + private void upgradeToV4(SQLiteDatabase db) { + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + + " INTEGER NOT NULL DEFAULT 0");// 通过执行ALTER TABLE语句向NOTE表格中添加一个新的列VERSION,该列的类型是INTEGER,并设置默认值为0 +>>>>>>> liuyitao-branch } } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java index edb0a60..1473b57 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java @@ -34,6 +34,7 @@ import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.NotesDatabaseHelper.TABLE; +<<<<<<< HEAD public class NotesProvider extends ContentProvider { private static final UriMatcher mMatcher; @@ -43,6 +44,19 @@ public class NotesProvider extends ContentProvider { private static final String TAG = "NotesProvider"; private static final int URI_NOTE = 1; +======= +/* +* 功能描述:用于提供对便签数据的存储和获取功能,实现了创建、读取、更新、删除操作,以便其他组件可以通过 ContentResolver 访问和管理便签数据。 +* */ +public class NotesProvider extends ContentProvider { + private static final UriMatcher mMatcher;// UriMatcher用于匹配Uri + + private NotesDatabaseHelper mHelper;// 数据库帮助类 + + private static final String TAG = "NotesProvider";// 标签 + + private static final int URI_NOTE = 1;// Uri匹配码 +>>>>>>> liuyitao-branch private static final int URI_NOTE_ITEM = 2; private static final int URI_DATA = 3; private static final int URI_DATA_ITEM = 4; @@ -51,6 +65,7 @@ public class NotesProvider extends ContentProvider { private static final int URI_SEARCH_SUGGEST = 6; static { +<<<<<<< HEAD mMatcher = new UriMatcher(UriMatcher.NO_MATCH); mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE); mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM); @@ -59,12 +74,32 @@ public class NotesProvider extends ContentProvider { mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH); mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST); mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST); +======= + mMatcher = new UriMatcher(UriMatcher.NO_MATCH);// 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码 + /* + * 把需要匹配Uri路径全部给注册上 + * */ + mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);// 便签列表的路径 + mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);// 便签详情的路径,其中 "#" 表示数字,表示具体的便签 ID + mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);// 数据列表的路径 + mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);// 数据详情的路径,其中 "#" 表示数字,表示具体的数据 ID + mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH);// 搜索的路径 + mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST);// 搜索建议的路径 + mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST);// 带搜索关键字的搜索建议的路径 +>>>>>>> liuyitao-branch } /** * x'0A' represents the '\n' character in sqlite. For title and content in the search result, * we will trim '\n' and white space in order to show more information. */ +<<<<<<< HEAD +======= + + /* + * 查询搜索结果的投影。该投影包含了搜索结果需要的各个字段,如便签的 ID、搜索文本等 + * */ +>>>>>>> liuyitao-branch private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + "," + NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + "," + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + "," @@ -73,6 +108,12 @@ public class NotesProvider extends ContentProvider { + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + "," + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA; +<<<<<<< HEAD +======= + /* + * 查询语句,用于查询搜索结果 + * */ +>>>>>>> liuyitao-branch private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION + " FROM " + TABLE.NOTE + " WHERE " + NoteColumns.SNIPPET + " LIKE ?" @@ -80,12 +121,19 @@ public class NotesProvider extends ContentProvider { + " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE; @Override +<<<<<<< HEAD +======= + /* + *在onCreate()中初始化Context,实例化mHelper + * */ +>>>>>>> liuyitao-branch public boolean onCreate() { mHelper = NotesDatabaseHelper.getInstance(getContext()); return true; } @Override +<<<<<<< HEAD public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor c = null; @@ -109,17 +157,53 @@ public class NotesProvider extends ContentProvider { id = uri.getPathSegments().get(1); c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs, null, null, sortOrder); +======= + /* + * 根据传入的Uri进行数据库查询操作 + * */ + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + Cursor c = null;// 定义一个Cursor对象用于存放查询结果 + SQLiteDatabase db = mHelper.getReadableDatabase();// 获取可读数据库实例 + String id = null;// 用于存放ID值 + /* + * 根据Uri使用Matcher匹配相应的操作,对于不同的匹配值,在数据库中查找相应的条目 + * */ + switch (mMatcher.match(uri)) { + case URI_NOTE: + c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null, + sortOrder);// 查询便签列表 + break; + case URI_NOTE_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID值 + c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id + + parseSelection(selection), selectionArgs, null, null, sortOrder);// 查询特定ID的便签详情 + break; + case URI_DATA: + c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null, + sortOrder);// 查询数据列表 + break; + case URI_DATA_ITEM: + id = uri.getPathSegments().get(1); // 获取Uri中的ID值 + c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id + + parseSelection(selection), selectionArgs, null, null, sortOrder);// 查询特定ID的数据详情 +>>>>>>> liuyitao-branch break; case URI_SEARCH: case URI_SEARCH_SUGGEST: if (sortOrder != null || projection != null) { throw new IllegalArgumentException( +<<<<<<< HEAD "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query"); +======= + "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");// 如果存在不合法的参数则抛出异常 +>>>>>>> liuyitao-branch } String searchString = null; if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) { if (uri.getPathSegments().size() > 1) { +<<<<<<< HEAD searchString = uri.getPathSegments().get(1); } } else { @@ -194,11 +278,103 @@ public class NotesProvider extends ContentProvider { break; case URI_NOTE_ITEM: id = uri.getPathSegments().get(1); +======= + searchString = uri.getPathSegments().get(1); // 获取搜索关键字 + } + } else { + searchString = uri.getQueryParameter("pattern"); // 获取搜索关键字 + } + + if (TextUtils.isEmpty(searchString)) { + return null;// 如果搜索关键字为空则直接返回null + } + + try { + searchString = String.format("%%%s%%", searchString);// 格式化搜索关键字 + c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY, + new String[] { searchString });// 执行搜索查询 + } catch (IllegalStateException ex) { + Log.e(TAG, "got exception: " + ex.toString());// 捕获异常 + } + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 + } + if (c != null) { + c.setNotificationUri(getContext().getContentResolver(), uri);// 设置查询结果的变更通知URI + } + return c;// 返回查询结果的Cursor对象 + } + + @Override + /* + * 功能描述:实现对数据库表单的增加记录操作 + * 输入参数:参数 uri 表示插入的 URI,values 表示插入的值 + * */ + public Uri insert(Uri uri, ContentValues values) { + SQLiteDatabase db = mHelper.getWritableDatabase();// 获得可写的数据库 + long dataId = 0, noteId = 0, insertedId = 0;// 定义三个id值变量 + /* + * 根据Uri使用Matcher匹配相应的操作 + * */ + switch (mMatcher.match(uri)) { + case URI_NOTE: + insertedId = noteId = db.insert(TABLE.NOTE, null, values);// 在便签表中插入新记录 + break; + case URI_DATA: + if (values.containsKey(DataColumns.NOTE_ID)) { + noteId = values.getAsLong(DataColumns.NOTE_ID);// 如果数据内容包含NOTE_ID字段,获取NOTE_ID值 + } else { + Log.d(TAG, "Wrong data format without note id:" + values.toString());// 如果不包含则输出日志信息 + } + insertedId = dataId = db.insert(TABLE.DATA, null, values);// 在数据表中插入新记录 + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 + } + // Notify the note uri + if (noteId > 0) {// 如果是便签新增操作 + getContext().getContentResolver().notifyChange( + ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);// 通过ContentResolver对象发送通知,更新便签的变更通知URI + } + + // Notify the data uri + if (dataId > 0) {// 如果是数据新增操作 + getContext().getContentResolver().notifyChange( + ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);// 通过ContentResolver对象发送通知,更新数据的变更通知URI + } + + return ContentUris.withAppendedId(uri, insertedId);// 返回插入的uri的路径 + } + + @Override + /* + * 功能描述:实现对数据库表单的删除记录操作 + * 输入参数:参数 uri 表示删除的 URI,selection 表示删除条件,selectionArgs 表示删除条件值 + * */ + public int delete(Uri uri, String selection, String[] selectionArgs) { + //Uri代表要操作的数据,Android上可用的每种资源 -包括 图像、视频片段、音频资源等都可以用Uri来表示 + int count = 0;// 定义计数变量 + String id = null;// 定义id字符串变量 + SQLiteDatabase db = mHelper.getWritableDatabase();// 获取可写数据库实例 + boolean deleteData = false;// 是否删除数据标志位 + /* + * 根据Uri使用Matcher匹配相应的操作 + * */ + switch (mMatcher.match(uri)) { + case URI_NOTE: + selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";// 对于便签的删除操作,添加额外的条件限制 + count = db.delete(TABLE.NOTE, selection, selectionArgs);// 在便签表中删除符合条件的记录 + break; + case URI_NOTE_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 +>>>>>>> liuyitao-branch /** * ID that smaller than 0 is system folder which is not allowed to * trash */ long noteId = Long.valueOf(id); +<<<<<<< HEAD if (noteId <= 0) { break; } @@ -267,10 +443,91 @@ public class NotesProvider extends ContentProvider { return count; } +======= + if (noteId <= 0) {// 如果ID小于等于0,则不允许删除 + break; + } + count = db.delete(TABLE.NOTE, + NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);// 在便签表中删除指定ID的记录 + break; + case URI_DATA: + count = db.delete(TABLE.DATA, selection, selectionArgs);// 在数据表中删除符合条件的记录 + deleteData = true;// 设置删除数据标志位为true + break; + case URI_DATA_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 + count = db.delete(TABLE.DATA, + DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);// 在数据表中删除指定ID的记录 + deleteData = true;// 设置删除数据标志位为true + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 + } + if (count > 0) {// 如果删除记录数大于0 + if (deleteData) { + getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);// 通过ContentResolver对象发送通知,更新便签变更通知URI + } + getContext().getContentResolver().notifyChange(uri, null);// 通过ContentResolver对象发送通知,更新变更通知URI + } + return count;// 返回删除的记录数 + } + + @Override + /* + * 功能描述:实现对数据库表单的更新操作 + * 输入参数:参数 uri 表示更新的 URI,values 表示更新的值,selection 表示更新条件,selectionArgs 表示更新条件值 + * */ + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + int count = 0;// 定义计数变量 + String id = null;// 定义id字符串变量 + SQLiteDatabase db = mHelper.getWritableDatabase();// 获取可写数据库实例 + boolean updateData = false;// 是否更新数据标志位 + /* + * 根据Uri使用Matcher匹配相应的操作 + * */ + switch (mMatcher.match(uri)) { + case URI_NOTE: + increaseNoteVersion(-1, selection, selectionArgs);// 增加便签版本号,针对便签的更新操作,添加额外的条件限制 + count = db.update(TABLE.NOTE, values, selection, selectionArgs);// 在便签表中更新符合条件的记录 + break; + case URI_NOTE_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 + increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);// 增加便签版本号,针对便签的更新操作,添加额外的条件限制 + count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id + + parseSelection(selection), selectionArgs);// 在便签表中更新指定ID的记录 + break; + case URI_DATA: + count = db.update(TABLE.DATA, values, selection, selectionArgs);// 在数据表中更新符合条件的记录 + updateData = true;// 设置更新数据标志位为tru + break; + case URI_DATA_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 + count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id + + parseSelection(selection), selectionArgs);// 在数据表中更新指定ID的记录 + updateData = true;// 设置更新数据标志位为true + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 + } + + if (count > 0) {// 如果更新记录数大于0 + if (updateData) { + getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);// 通过ContentResolver对象发送通知,更新便签变更通知URI + } + getContext().getContentResolver().notifyChange(uri, null);// 通过ContentResolver对象发送通知,更新变更通知URI + } + return count;// 返回更新的记录数 + } + + /* + * 解析查询条件selection,如果selection不为空,则在其前面加上" AND ",用于拼接SQL语句 + * */ +>>>>>>> liuyitao-branch private String parseSelection(String selection) { return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } +<<<<<<< HEAD private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { StringBuilder sql = new StringBuilder(120); sql.append("UPDATE "); @@ -297,9 +554,49 @@ public class NotesProvider extends ContentProvider { } @Override +======= + /* + * 根据传入的id和selection参数确定要更新的记录,并将版本号加1 + * */ + private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { + StringBuilder sql = new StringBuilder(120);// 创建一个StringBuilder对象,用于构建SQL语句 + sql.append("UPDATE ");// 构建UPDATE语句,指定要更新的表名 + sql.append(TABLE.NOTE);// 表名 + sql.append(" SET ");// 指定要更新的字段和新的值 + sql.append(NoteColumns.VERSION);// 字段名 + sql.append("=" + NoteColumns.VERSION + "+1 ");// 将版本号加1 + + if (id > 0 || !TextUtils.isEmpty(selection)) { + sql.append(" WHERE ");// 根据传入的参数决定是否添加WHERE子句 + } + if (id > 0) { + sql.append(NoteColumns.ID + "=" + String.valueOf(id)); // 如果传入的id大于0,则表示只更新指定id的记录 + } + if (!TextUtils.isEmpty(selection)) {// 如果传入的selection不为空,则根据它来确定要更新的记录 + String selectString = id > 0 ? parseSelection(selection) : selection;// 调用parseSelection方法将selection转换为SQL语句中的WHERE子句 + for (String args : selectionArgs) { + selectString = selectString.replaceFirst("\\?", args);// 替换WHERE子句中的问号占位符为实际的参数值 + } + sql.append(selectString);// 添加WHERE子句到SQL语句中 + } + + // execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句 + mHelper.getWritableDatabase().execSQL(sql.toString());// 添加WHERE子句到SQL语句中 + } + + @Override + /* + * 功能描述:用于根据 URI 返回相应的 MIME 类型 + * 输入参数:参数 uri 表示查询或操作的 URI + * 函数中是环境自动生成的,也可自己改写 + * */ +>>>>>>> liuyitao-branch public String getType(Uri uri) { // TODO Auto-generated method stub return null; } +<<<<<<< HEAD +======= +>>>>>>> liuyitao-branch } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java index 3128286..1edcef7 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java @@ -26,6 +26,7 @@ import org.json.JSONObject; public class MetaData extends Task { +<<<<<<< HEAD /* * 功能描述:得到类的简写名称存入字符串TAG中 * 实现过程:调用getSimpleName ()函数 @@ -50,10 +51,22 @@ public class MetaData extends Task { /* * 输出错误信息 */ +======= + private final static String TAG = MetaData.class.getSimpleName(); + + private String mRelatedGid = null; + + public void setMeta(String gid, JSONObject metaInfo) { + try { + metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); + } catch (JSONException e) { + Log.e(TAG, "failed to put related gid"); +>>>>>>> liuyitao-branch } setNotes(metaInfo.toString()); setName(GTaskStringUtils.META_NOTE_NAME); } +<<<<<<< HEAD /* * 功能描述:获取相关联的Gid */ @@ -63,15 +76,26 @@ public class MetaData extends Task { /* * 功能描述:判断当前数据是否为空,若为空则返回真即值得保存 */ +======= + + public String getRelatedGid() { + return mRelatedGid; + } + +>>>>>>> liuyitao-branch @Override public boolean isWorthSaving() { return getNotes() != null; } +<<<<<<< HEAD /* * 功能描述:使用远程json数据对象设置元数据内容 * 实现过程:调用父类Task中的setContentByRemoteJSON ()函数,并 * 参数注解: */ +======= + +>>>>>>> liuyitao-branch @Override public void setContentByRemoteJSON(JSONObject js) { super.setContentByRemoteJSON(js); @@ -81,21 +105,29 @@ public class MetaData extends Task { mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); } catch (JSONException e) { Log.w(TAG, "failed to get related gid"); +<<<<<<< HEAD /* * 输出警告信息 */ +======= +>>>>>>> liuyitao-branch mRelatedGid = null; } } } +<<<<<<< HEAD /* * 功能描述:使用本地json数据对象设置元数据内容,一般不会用到,若用到,则抛出异常 */ +======= + +>>>>>>> liuyitao-branch @Override public void setContentByLocalJSON(JSONObject js) { // this function should not be called throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); } +<<<<<<< HEAD @Override public JSONObject getLocalJSONFromContent() { throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); @@ -113,4 +145,17 @@ public class MetaData extends Task { 传递非法参数异常 */ } +======= + + @Override + public JSONObject getLocalJSONFromContent() { + throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); + } + + @Override + public int getSyncAction(Cursor c) { + throw new IllegalAccessError("MetaData:getSyncAction should not be called"); + } + +>>>>>>> liuyitao-branch } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java index 15f2f24..91a34fd 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java @@ -20,6 +20,7 @@ import android.database.Cursor; import org.json.JSONObject; +<<<<<<< HEAD /** * 应该是同步操作的基础数据类型,定义了相关指示同步操作的常量 * 关键字:abstract @@ -43,11 +44,32 @@ public abstract class Node { public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;// 同步出现冲突 public static final int SYNC_ACTION_ERROR = 8;// 同步出现错误 +======= +public abstract class Node { + public static final int SYNC_ACTION_NONE = 0; + + public static final int SYNC_ACTION_ADD_REMOTE = 1; + + public static final int SYNC_ACTION_ADD_LOCAL = 2; + + public static final int SYNC_ACTION_DEL_REMOTE = 3; + + public static final int SYNC_ACTION_DEL_LOCAL = 4; + + public static final int SYNC_ACTION_UPDATE_REMOTE = 5; + + public static final int SYNC_ACTION_UPDATE_LOCAL = 6; + + public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; + + public static final int SYNC_ACTION_ERROR = 8; +>>>>>>> liuyitao-branch private String mGid; private String mName; +<<<<<<< HEAD private long mLastModified;//记录最后一次修改时间 private boolean mDeleted;//表征是否被删除 @@ -102,4 +124,61 @@ public abstract class Node { public boolean getDeleted() { return this.mDeleted; // 返回 mDeleted 的取值 } +======= + private long mLastModified; + + private boolean mDeleted; + + public Node() { + mGid = null; + mName = ""; + mLastModified = 0; + mDeleted = false; + } + + public abstract JSONObject getCreateAction(int actionId); + + public abstract JSONObject getUpdateAction(int actionId); + + public abstract void setContentByRemoteJSON(JSONObject js); + + public abstract void setContentByLocalJSON(JSONObject js); + + public abstract JSONObject getLocalJSONFromContent(); + + public abstract int getSyncAction(Cursor c); + + public void setGid(String gid) { + this.mGid = gid; + } + + public void setName(String name) { + this.mName = name; + } + + public void setLastModified(long lastModified) { + this.mLastModified = lastModified; + } + + public void setDeleted(boolean deleted) { + this.mDeleted = deleted; + } + + public String getGid() { + return this.mGid; + } + + public String getName() { + return this.mName; + } + + public long getLastModified() { + return this.mLastModified; + } + + public boolean getDeleted() { + return this.mDeleted; + } + +>>>>>>> liuyitao-branch } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java index 9a1d281..a7c6ac0 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java @@ -14,6 +14,7 @@ * limitations under the License. */ +<<<<<<< HEAD /* * Description:用于支持小米便签最底层的数据库相关操作,和sqlnote的关系上是子集关系,即data是note的子集(节点)。 * SqlData其实就是也就是所谓数据中的数据 @@ -25,6 +26,9 @@ package net.micode.notes.gtask.data; * 实现过程: * 参数注解: */ +======= +package net.micode.notes.gtask.data; +>>>>>>> liuyitao-branch import android.content.ContentResolver; import android.content.ContentUris; @@ -46,6 +50,7 @@ import org.json.JSONObject; public class SqlData { +<<<<<<< HEAD /* * 功能描述:得到类的简写名称存入字符串TAG中 * 实现过程:调用getSimpleName ()函数 @@ -59,10 +64,17 @@ public class SqlData { */ // 集合了interface DataColumns中所有SF常量 +======= + private static final String TAG = SqlData.class.getSimpleName(); + + private static final int INVALID_ID = -99999; + +>>>>>>> liuyitao-branch public static final String[] PROJECTION_DATA = new String[] { DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1, DataColumns.DATA3 }; +<<<<<<< HEAD /* * 以下五个变量作为sql表中5列的编号 */ @@ -102,6 +114,39 @@ public class SqlData { mContentResolver = context.getContentResolver(); mIsCreate = true; mDataId = INVALID_ID;//mDataId置初始值-99999 +======= + + public static final int DATA_ID_COLUMN = 0; + + public static final int DATA_MIME_TYPE_COLUMN = 1; + + public static final int DATA_CONTENT_COLUMN = 2; + + public static final int DATA_CONTENT_DATA_1_COLUMN = 3; + + public static final int DATA_CONTENT_DATA_3_COLUMN = 4; + + private ContentResolver mContentResolver; + + private boolean mIsCreate; + + private long mDataId; + + private String mDataMimeType; + + private String mDataContent; + + private long mDataContentData1; + + private String mDataContentData3; + + private ContentValues mDiffDataValues; + + public SqlData(Context context) { + mContentResolver = context.getContentResolver(); + mIsCreate = true; + mDataId = INVALID_ID; +>>>>>>> liuyitao-branch mDataMimeType = DataConstants.NOTE; mDataContent = ""; mDataContentData1 = 0; @@ -109,6 +154,7 @@ public class SqlData { mDiffDataValues = new ContentValues(); } +<<<<<<< HEAD /* * 功能描述:构造函数,初始化数据 @@ -216,6 +262,82 @@ public class SqlData { mDataId = Long.valueOf(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { // 如果获取ID出错则输出错误日志并抛出ActionFailureException异常 +======= + public SqlData(Context context, Cursor c) { + mContentResolver = context.getContentResolver(); + mIsCreate = false; + loadFromCursor(c); + mDiffDataValues = new ContentValues(); + } + + private void loadFromCursor(Cursor c) { + mDataId = c.getLong(DATA_ID_COLUMN); + mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN); + mDataContent = c.getString(DATA_CONTENT_COLUMN); + mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN); + mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN); + } + + public void setContent(JSONObject js) throws JSONException { + long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID; + if (mIsCreate || mDataId != dataId) { + mDiffDataValues.put(DataColumns.ID, dataId); + } + mDataId = dataId; + + String dataMimeType = js.has(DataColumns.MIME_TYPE) ? js.getString(DataColumns.MIME_TYPE) + : DataConstants.NOTE; + if (mIsCreate || !mDataMimeType.equals(dataMimeType)) { + mDiffDataValues.put(DataColumns.MIME_TYPE, dataMimeType); + } + mDataMimeType = dataMimeType; + + String dataContent = js.has(DataColumns.CONTENT) ? js.getString(DataColumns.CONTENT) : ""; + if (mIsCreate || !mDataContent.equals(dataContent)) { + mDiffDataValues.put(DataColumns.CONTENT, dataContent); + } + mDataContent = dataContent; + + long dataContentData1 = js.has(DataColumns.DATA1) ? js.getLong(DataColumns.DATA1) : 0; + if (mIsCreate || mDataContentData1 != dataContentData1) { + mDiffDataValues.put(DataColumns.DATA1, dataContentData1); + } + mDataContentData1 = dataContentData1; + + String dataContentData3 = js.has(DataColumns.DATA3) ? js.getString(DataColumns.DATA3) : ""; + if (mIsCreate || !mDataContentData3.equals(dataContentData3)) { + mDiffDataValues.put(DataColumns.DATA3, dataContentData3); + } + mDataContentData3 = dataContentData3; + } + + public JSONObject getContent() throws JSONException { + if (mIsCreate) { + Log.e(TAG, "it seems that we haven't created this in database yet"); + return null; + } + JSONObject js = new JSONObject(); + js.put(DataColumns.ID, mDataId); + js.put(DataColumns.MIME_TYPE, mDataMimeType); + js.put(DataColumns.CONTENT, mDataContent); + js.put(DataColumns.DATA1, mDataContentData1); + js.put(DataColumns.DATA3, mDataContentData3); + return js; + } + + public void commit(long noteId, boolean validateVersion, long version) { + + if (mIsCreate) { + if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) { + mDiffDataValues.remove(DataColumns.ID); + } + + mDiffDataValues.put(DataColumns.NOTE_ID, noteId); + Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues); + try { + mDataId = Long.valueOf(uri.getPathSegments().get(1)); + } catch (NumberFormatException e) { +>>>>>>> liuyitao-branch Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); } @@ -223,6 +345,7 @@ public class SqlData { if (mDiffDataValues.size() > 0) { int result = 0; if (!validateVersion) { +<<<<<<< HEAD // 如果不需要验证版本,则直接通过mDataId更新mDiffDataValues到数据库中 result = mContentResolver.update(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null); @@ -230,18 +353,29 @@ public class SqlData { // 如果需要验证版本,则通过noteId和version进行更新 result = mContentResolver.update(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, +======= + result = mContentResolver.update(ContentUris.withAppendedId( + Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null); + } else { + result = mContentResolver.update(ContentUris.withAppendedId( + Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, +>>>>>>> liuyitao-branch " ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE + " WHERE " + NoteColumns.VERSION + "=?)", new String[] { String.valueOf(noteId), String.valueOf(version) }); } if (result == 0) { +<<<<<<< HEAD // 如果没有更新任何数据,则输出警告日志 +======= +>>>>>>> liuyitao-branch Log.w(TAG, "there is no update. maybe user updates note when syncing"); } } } +<<<<<<< HEAD // 清空差异数据 mDiffDataValues.clear(); // 将新建标记设为false @@ -255,4 +389,13 @@ public class SqlData { return mDataId; } +======= + mDiffDataValues.clear(); + mIsCreate = false; + } + + public long getId() { + return mDataId; + } +>>>>>>> liuyitao-branch } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java index 5edea99..127b78a 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java @@ -43,6 +43,7 @@ public class SqlNote { private static final int INVALID_ID = -99999; +<<<<<<< HEAD // 定义查询笔记的投影,包含需要查询的列 public static final String[] PROJECTION_NOTE = new String[] { NoteColumns.ID, // 笔记ID @@ -148,11 +149,140 @@ public class SqlNote { Cursor c = null;// 初始化游标对象 try { // 通过 ID 查询笔记数据 +======= + public static final String[] PROJECTION_NOTE = new String[] { + NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, + NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE, + NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE, + NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.SYNC_ID, + NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID, + NoteColumns.VERSION + }; + + public static final int ID_COLUMN = 0; + + public static final int ALERTED_DATE_COLUMN = 1; + + public static final int BG_COLOR_ID_COLUMN = 2; + + public static final int CREATED_DATE_COLUMN = 3; + + public static final int HAS_ATTACHMENT_COLUMN = 4; + + public static final int MODIFIED_DATE_COLUMN = 5; + + public static final int NOTES_COUNT_COLUMN = 6; + + public static final int PARENT_ID_COLUMN = 7; + + public static final int SNIPPET_COLUMN = 8; + + public static final int TYPE_COLUMN = 9; + + public static final int WIDGET_ID_COLUMN = 10; + + public static final int WIDGET_TYPE_COLUMN = 11; + + public static final int SYNC_ID_COLUMN = 12; + + public static final int LOCAL_MODIFIED_COLUMN = 13; + + public static final int ORIGIN_PARENT_ID_COLUMN = 14; + + public static final int GTASK_ID_COLUMN = 15; + + public static final int VERSION_COLUMN = 16; + + private Context mContext; + + private ContentResolver mContentResolver; + + private boolean mIsCreate; + + private long mId; + + private long mAlertDate; + + private int mBgColorId; + + private long mCreatedDate; + + private int mHasAttachment; + + private long mModifiedDate; + + private long mParentId; + + private String mSnippet; + + private int mType; + + private int mWidgetId; + + private int mWidgetType; + + private long mOriginParent; + + private long mVersion; + + private ContentValues mDiffNoteValues; + + private ArrayListType: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String ID = "_id"; +======= + public static final String ID = "_id";// 行的唯一标识符 +>>>>>>> liuyitao-branch ======= public static final String ID = "_id";// 行的唯一标识符 >>>>>>> liuyitao-branch @@ -138,8 +164,12 @@ public class Notes { * The parent's id for note or folder *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String PARENT_ID = "parent_id"; +======= + public static final String PARENT_ID = "parent_id";// 父级的ID +>>>>>>> liuyitao-branch ======= public static final String PARENT_ID = "parent_id";// 父级的ID >>>>>>> liuyitao-branch @@ -148,8 +178,12 @@ public class Notes { * Created data for note or folder *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String CREATED_DATE = "created_date"; +======= + public static final String CREATED_DATE = "created_date";// 创建日期 +>>>>>>> liuyitao-branch ======= public static final String CREATED_DATE = "created_date";// 创建日期 >>>>>>> liuyitao-branch @@ -158,19 +192,27 @@ public class Notes { * Latest modified date *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String MODIFIED_DATE = "modified_date"; ======= public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 >>>>>>> liuyitao-branch +======= + public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 +>>>>>>> liuyitao-branch /** * Alert date *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String ALERTED_DATE = "alert_date"; +======= + public static final String ALERTED_DATE = "alert_date";// 提醒日期 +>>>>>>> liuyitao-branch ======= public static final String ALERTED_DATE = "alert_date";// 提醒日期 >>>>>>> liuyitao-branch @@ -179,8 +221,12 @@ public class Notes { * Folder's name or text content of note *Type: TEXT
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String SNIPPET = "snippet"; +======= + public static final String SNIPPET = "snippet";// 文件夹名称或便签的文本内容 +>>>>>>> liuyitao-branch ======= public static final String SNIPPET = "snippet";// 文件夹名称或便签的文本内容 >>>>>>> liuyitao-branch @@ -189,8 +235,12 @@ public class Notes { * Note's widget id *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String WIDGET_ID = "widget_id"; +======= + public static final String WIDGET_ID = "widget_id";// 便签的Widget ID +>>>>>>> liuyitao-branch ======= public static final String WIDGET_ID = "widget_id";// 便签的Widget ID >>>>>>> liuyitao-branch @@ -199,8 +249,12 @@ public class Notes { * Note's widget type *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String WIDGET_TYPE = "widget_type"; +======= + public static final String WIDGET_TYPE = "widget_type";// 便签的Widget类型 +>>>>>>> liuyitao-branch ======= public static final String WIDGET_TYPE = "widget_type";// 便签的Widget类型 >>>>>>> liuyitao-branch @@ -209,8 +263,12 @@ public class Notes { * Note's background color's id *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String BG_COLOR_ID = "bg_color_id"; +======= + public static final String BG_COLOR_ID = "bg_color_id";// 便签的背景颜色ID +>>>>>>> liuyitao-branch ======= public static final String BG_COLOR_ID = "bg_color_id";// 便签的背景颜色ID >>>>>>> liuyitao-branch @@ -220,8 +278,12 @@ public class Notes { * note, it has at least one attachment *Type: INTEGER
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String HAS_ATTACHMENT = "has_attachment"; +======= + public static final String HAS_ATTACHMENT = "has_attachment";// 是否有附件 +>>>>>>> liuyitao-branch ======= public static final String HAS_ATTACHMENT = "has_attachment";// 是否有附件 >>>>>>> liuyitao-branch @@ -230,8 +292,12 @@ public class Notes { * Folder's count of notes *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String NOTES_COUNT = "notes_count"; +======= + public static final String NOTES_COUNT = "notes_count";// 文件夹中的便签数量 +>>>>>>> liuyitao-branch ======= public static final String NOTES_COUNT = "notes_count";// 文件夹中的便签数量 >>>>>>> liuyitao-branch @@ -240,8 +306,12 @@ public class Notes { * The file type: folder or note *Type: INTEGER
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String TYPE = "type"; +======= + public static final String TYPE = "type";// 文件类型:文件夹或便签 +>>>>>>> liuyitao-branch ======= public static final String TYPE = "type";// 文件类型:文件夹或便签 >>>>>>> liuyitao-branch @@ -250,8 +320,12 @@ public class Notes { * The last sync id *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String SYNC_ID = "sync_id"; +======= + public static final String SYNC_ID = "sync_id";// 最后同步的ID +>>>>>>> liuyitao-branch ======= public static final String SYNC_ID = "sync_id";// 最后同步的ID >>>>>>> liuyitao-branch @@ -260,8 +334,12 @@ public class Notes { * Sign to indicate local modified or not *Type: INTEGER
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String LOCAL_MODIFIED = "local_modified"; +======= + public static final String LOCAL_MODIFIED = "local_modified";// 标识是否本地修改 +>>>>>>> liuyitao-branch ======= public static final String LOCAL_MODIFIED = "local_modified";// 标识是否本地修改 >>>>>>> liuyitao-branch @@ -270,8 +348,12 @@ public class Notes { * Original parent id before moving into temporary folder *Type : INTEGER
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String ORIGIN_PARENT_ID = "origin_parent_id"; +======= + public static final String ORIGIN_PARENT_ID = "origin_parent_id";// 移动到临时文件夹之前的原始父级ID +>>>>>>> liuyitao-branch ======= public static final String ORIGIN_PARENT_ID = "origin_parent_id";// 移动到临时文件夹之前的原始父级ID >>>>>>> liuyitao-branch @@ -280,8 +362,12 @@ public class Notes { * The gtask id *Type : TEXT
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String GTASK_ID = "gtask_id"; +======= + public static final String GTASK_ID = "gtask_id";// Google任务ID +>>>>>>> liuyitao-branch ======= public static final String GTASK_ID = "gtask_id";// Google任务ID >>>>>>> liuyitao-branch @@ -290,25 +376,35 @@ public class Notes { * The version code *Type : INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String VERSION = "version"; } ======= +======= +>>>>>>> liuyitao-branch public static final String VERSION = "version";// 版本号 } /* * 功能描述:定义DataColumns接口数据的常量,用于创建数据库表头 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch public interface DataColumns { /** * The unique ID for a row *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String ID = "_id"; +======= + public static final String ID = "_id";// 标识符 +>>>>>>> liuyitao-branch ======= public static final String ID = "_id";// 标识符 >>>>>>> liuyitao-branch @@ -317,8 +413,12 @@ public class Notes { * The MIME type of the item represented by this row. *Type: Text
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String MIME_TYPE = "mime_type"; +======= + public static final String MIME_TYPE = "mime_type";// 数据的MIME类型 +>>>>>>> liuyitao-branch ======= public static final String MIME_TYPE = "mime_type";// 数据的MIME类型 >>>>>>> liuyitao-branch @@ -327,8 +427,12 @@ public class Notes { * The reference id to note that this data belongs to *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String NOTE_ID = "note_id"; +======= + public static final String NOTE_ID = "note_id";// 数据ID +>>>>>>> liuyitao-branch ======= public static final String NOTE_ID = "note_id";// 数据ID >>>>>>> liuyitao-branch @@ -337,8 +441,12 @@ public class Notes { * Created data for note or folder *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String CREATED_DATE = "created_date"; +======= + public static final String CREATED_DATE = "created_date";// 创建日期 +>>>>>>> liuyitao-branch ======= public static final String CREATED_DATE = "created_date";// 创建日期 >>>>>>> liuyitao-branch @@ -347,8 +455,12 @@ public class Notes { * Latest modified date *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String MODIFIED_DATE = "modified_date"; +======= + public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 +>>>>>>> liuyitao-branch ======= public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 >>>>>>> liuyitao-branch @@ -357,11 +469,15 @@ public class Notes { * Data's content *Type: TEXT
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String CONTENT = "content"; ======= public static final String CONTENT = "content";// 内容 >>>>>>> liuyitao-branch +======= + public static final String CONTENT = "content";// 内容 +>>>>>>> liuyitao-branch /** @@ -369,8 +485,12 @@ public class Notes { * integer data type *Type: INTEGER
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String DATA1 = "data1"; +======= + public static final String DATA1 = "data1";// 通用数据1 +>>>>>>> liuyitao-branch ======= public static final String DATA1 = "data1";// 通用数据1 >>>>>>> liuyitao-branch @@ -380,8 +500,12 @@ public class Notes { * integer data type *Type: INTEGER
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String DATA2 = "data2"; +======= + public static final String DATA2 = "data2";// 通用数据2 +>>>>>>> liuyitao-branch ======= public static final String DATA2 = "data2";// 通用数据2 >>>>>>> liuyitao-branch @@ -391,8 +515,12 @@ public class Notes { * TEXT data type *Type: TEXT
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String DATA3 = "data3"; +======= + public static final String DATA3 = "data3";// 通用数据3 +>>>>>>> liuyitao-branch ======= public static final String DATA3 = "data3";// 通用数据3 >>>>>>> liuyitao-branch @@ -402,8 +530,12 @@ public class Notes { * TEXT data type *Type: TEXT
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String DATA4 = "data4"; +======= + public static final String DATA4 = "data4";// 通用数据4 +>>>>>>> liuyitao-branch ======= public static final String DATA4 = "data4";// 通用数据4 >>>>>>> liuyitao-branch @@ -413,23 +545,30 @@ public class Notes { * TEXT data type *Type: TEXT
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String DATA5 = "data5"; } ======= +======= +>>>>>>> liuyitao-branch public static final String DATA5 = "data5";// 通用数据5 } /* * 定义了文本便签的数据结构 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch public static final class TextNote implements DataColumns { /** * Mode to indicate the text in check list mode or not *Type: Integer 1:check list mode 0: normal mode
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String MODE = DATA1; @@ -443,6 +582,8 @@ public class Notes { } ======= +======= +>>>>>>> liuyitao-branch public static final String MODE = DATA1;// 模式 public static final int MODE_CHECK_LIST = 1;// 待办清单模式 @@ -457,14 +598,21 @@ public class Notes { /* * 定义电话便签的数据结构 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch public static final class CallNote implements DataColumns { /** * Call date for this record *Type: INTEGER (long)
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String CALL_DATE = DATA1; +======= + public static final String CALL_DATE = DATA1;// 通话日期 +>>>>>>> liuyitao-branch ======= public static final String CALL_DATE = DATA1;// 通话日期 >>>>>>> liuyitao-branch @@ -473,6 +621,7 @@ public class Notes { * Phone number for this record *Type: TEXT
*/ +<<<<<<< HEAD <<<<<<< HEAD public static final String PHONE_NUMBER = DATA3; @@ -482,6 +631,8 @@ public class Notes { public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); ======= +======= +>>>>>>> liuyitao-branch public static final String PHONE_NUMBER = DATA3;// 电话号码 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";// 内容类型 @@ -489,6 +640,9 @@ public class Notes { public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";// 单个条目的内容类型 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");// 查询电话便签的URI +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java index 59ced1d..ffb00d3 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java @@ -16,6 +16,7 @@ package net.micode.notes.data; +<<<<<<< HEAD <<<<<<< HEAD import android.content.ContentValues; import android.content.Context; @@ -35,6 +36,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { public interface TABLE { ======= +======= +>>>>>>> liuyitao-branch import android.content.ContentValues;//就是用于保存一些数据(string boolean byte double float int long short ...)信息,这些信息可以被数据库操作时使用。 import android.content.Context;//加载和访问资源。(android中主要是这两个功能,但是这里具体不清楚) @@ -59,12 +62,16 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /* * 接口,分成note和data,用于表示数据库中两种表格 * */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch public static final String NOTE = "note"; public static final String DATA = "data"; } +<<<<<<< HEAD <<<<<<< HEAD private static final String TAG = "NotesDatabaseHelper"; @@ -107,6 +114,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { ")"; ======= +======= +>>>>>>> liuyitao-branch private static final String TAG = "NotesDatabaseHelper";// 日志标签,用于在日志中标识数据库操作的相关信息 /* @@ -160,6 +169,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /* * 创建一个名为 note_id_index 的索引,在 TABLE.DATA 表格的 DataColumns.NOTE_ID 列上创建索引,以提高查询性能 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String CREATE_DATA_NOTE_ID_INDEX_SQL = "CREATE INDEX IF NOT EXISTS note_id_index ON " + @@ -169,12 +181,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Increase folder's note count when move note to the folder */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在更新 TABLE.NOTE 表格的 NoteColumns.PARENT_ID 列时,增加相应文件夹的便签计数 * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其加1 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER increase_folder_count_on_update "+ @@ -189,12 +207,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Decrease folder's note count when move note from folder */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在更新 TABLE.NOTE 表格的 NoteColumns.PARENT_ID 列时,减少相应文件夹的便签计数 * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其减1 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_update " + @@ -210,12 +234,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Increase folder's note count when insert new note to the folder */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在向 TABLE.NOTE 表格插入新便签时,增加相应文件夹的便签计数 * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其加1 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = "CREATE TRIGGER increase_folder_count_on_insert " + @@ -230,12 +260,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Decrease folder's note count when delete note from the folder */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在从 TABLE.NOTE 表格删除便签时,减少相应文件夹的便签计数 * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其减1 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_delete " + @@ -251,12 +287,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Update note's content when insert data with type {@link DataConstants#NOTE} */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在向 TABLE.DATA 表格插入类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 * 通过更新 TABLE.NOTE 表格中的 NoteColumns.SNIPPET 列,将其设置为新插入数据的内容 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = "CREATE TRIGGER update_note_content_on_insert " + @@ -272,12 +314,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Update note's content when data with {@link DataConstants#NOTE} type has changed */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在更新类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 * 通过触发器在 TABLE.DATA 表格上创建,在数据被更新后将新的内容更新到对应的便签中 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = "CREATE TRIGGER update_note_content_on_update " + @@ -293,12 +341,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Update note's content when data with {@link DataConstants#NOTE} type has deleted */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在删除类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 * 通过触发器在 TABLE.DATA 表格上创建,在数据被删除后将对应的便签内容清空 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = "CREATE TRIGGER update_note_content_on_delete " + @@ -314,12 +368,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Delete datas belong to note which has been deleted */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在删除便签时,同时删除该便签相关的数据 * 通过触发器在 TABLE.NOTE 表格上创建,在便签被删除后将与该便签相关的数据一并删除 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = "CREATE TRIGGER delete_data_on_delete " + @@ -333,12 +393,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Delete notes belong to folder which has been deleted */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在删除文件夹时,同时删除该文件夹下的所有便签 * 通过触发器在 TABLE.NOTE 表格上创建,在文件夹被删除后将该文件夹下的所有便签一并删除。 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = "CREATE TRIGGER folder_delete_notes_on_delete " + @@ -352,12 +418,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * Move notes belong to folder which has been moved to trash folder */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 在将文件夹移动到回收站时,同时将该文件夹下的所有便签一并移动到回收站 * 通过触发器在 TABLE.NOTE 表格上创建,在文件夹被移动到回收站后将该文件夹下的所有便签的父文件夹ID更新为回收站的ID */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = "CREATE TRIGGER folder_move_notes_on_trash " + @@ -370,6 +442,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 构造函数,传入数据库的名称和版本 + */ +>>>>>>> liuyitao-branch ======= /* * 构造函数,传入数据库的名称和版本 @@ -379,7 +457,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { super(context, DB_NAME, null, DB_VERSION); } +<<<<<<< HEAD <<<<<<< HEAD +======= + /* + * 用于创建存储标签属性的表格 + */ +>>>>>>> liuyitao-branch ======= /* * 用于创建存储标签属性的表格 @@ -392,14 +476,20 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "note table has been created"); } +<<<<<<< HEAD <<<<<<< HEAD private void reCreateNoteTableTriggers(SQLiteDatabase db) { ======= +======= +>>>>>>> liuyitao-branch /* * 用于重新创建数据库中的触发器 */ private void reCreateNoteTableTriggers(SQLiteDatabase db) { // 通过执行SQL语句DROP TRIGGER IF EXISTS来删除已存在的触发器,以确保不会重复创建 +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update"); db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update"); @@ -408,6 +498,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_insert"); db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete"); db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash"); +<<<<<<< HEAD <<<<<<< HEAD db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER); @@ -420,6 +511,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } ======= +======= +>>>>>>> liuyitao-branch // 创建新的触发器 db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 增加文件夹计数的触发器 db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 减少文件夹计数的触发器 @@ -433,6 +526,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /* *用于创建系统文件夹,插入四个不同类型的文件夹记录到 NoteColumns 表中 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private void createSystemFolder(SQLiteDatabase db) { ContentValues values = new ContentValues(); @@ -441,6 +537,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * call record foler for call notes */ <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 创建通话记录文件夹 + */ +>>>>>>> liuyitao-branch ======= /* * 创建通话记录文件夹 @@ -454,6 +556,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * root folder which is default folder */ <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 根目录,即默认文件夹 + */ +>>>>>>> liuyitao-branch ======= /* * 根目录,即默认文件夹 @@ -468,6 +576,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * temporary folder which is used for moving note */ <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 临时目录,用于移动笔记 + */ +>>>>>>> liuyitao-branch ======= /* * 临时目录,用于移动笔记 @@ -482,6 +596,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { * create trash folder */ <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 创建垃圾箱 + */ +>>>>>>> liuyitao-branch ======= /* * 创建垃圾箱 @@ -493,6 +613,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); } +<<<<<<< HEAD <<<<<<< HEAD public void createDataTable(SQLiteDatabase db) { db.execSQL(CREATE_DATA_TABLE_SQL); @@ -502,6 +623,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } ======= +======= +>>>>>>> liuyitao-branch /* * 用于创建存储标签内容的表格 */ @@ -515,6 +638,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /* * 用于重新创建数据表中的触发器 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private void reCreateDataTableTriggers(SQLiteDatabase db) { db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert"); @@ -527,13 +653,19 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 用于获取单例的数据库帮助类对象 * 解决同一时刻只能有一个线程执行. * 在写程序库代码时,有时有一个类需要被所的其它类使用 * 但又要求这个类只能被实例化一次,是个服务类,定义一次,其它类使用同一个这个类的实例 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch static synchronized NotesDatabaseHelper getInstance(Context context) { if (mInstance == null) { @@ -544,6 +676,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { @Override <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 在数据库第一次创建时被调用,用于创建所需的表格和触发器 + */ +>>>>>>> liuyitao-branch ======= /* * 在数据库第一次创建时被调用,用于创建所需的表格和触发器 @@ -555,12 +693,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } @Override +<<<<<<< HEAD <<<<<<< HEAD public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { boolean reCreateTriggers = false; boolean skipV2 = false; ======= +======= +>>>>>>> liuyitao-branch /* * 根据旧版本和新版本之间的差异来执行相应的数据库升级操作 */ @@ -570,6 +711,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /* * 如果旧版本为1,则调用upgradeToV2方法 */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (oldVersion == 1) { upgradeToV2(db); @@ -577,7 +721,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { oldVersion++; } <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 如果旧版本为2且未跳过V2升级,则调用upgradeToV3方法 + */ +>>>>>>> liuyitao-branch ======= /* * 如果旧版本为2且未跳过V2升级,则调用upgradeToV3方法 @@ -589,7 +739,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { oldVersion++; } <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 如果旧版本为3,则调用upgradeToV4方法 + */ +>>>>>>> liuyitao-branch ======= /* * 如果旧版本为3,则调用upgradeToV4方法 @@ -600,7 +756,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { oldVersion++; } <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 如果需要重新创建触发器,则调用reCreateNoteTableTriggers和reCreateDataTableTriggers方法重新创建触发器 + */ +>>>>>>> liuyitao-branch ======= /* * 如果需要重新创建触发器,则调用reCreateNoteTableTriggers和reCreateDataTableTriggers方法重新创建触发器 @@ -611,7 +773,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { reCreateDataTableTriggers(db); } <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 如果旧版本和新版本不匹配,则抛出异常 + */ +>>>>>>> liuyitao-branch ======= /* * 如果旧版本和新版本不匹配,则抛出异常 @@ -623,6 +791,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } } +<<<<<<< HEAD <<<<<<< HEAD private void upgradeToV2(SQLiteDatabase db) { db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); @@ -633,6 +802,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { private void upgradeToV3(SQLiteDatabase db) { ======= +======= +>>>>>>> liuyitao-branch /* * 更新到V2版本 * */ @@ -653,16 +824,22 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /* * 执行SQL语句DROP TRIGGER IF EXISTS来移除不再使用的触发器 * */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch // 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"); db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update"); +<<<<<<< HEAD <<<<<<< HEAD // add a column for gtask id db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''"); ======= +======= +>>>>>>> liuyitao-branch /* * 执行ALTER TABLE语句向NOTE表格中添加一个新的列GTASK_ID,该列的类型是TEXT,并设置默认值为'' * */ @@ -672,6 +849,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { /* * 通过ContentValues对象向NOTE表格中插入一条记录,该记录代表垃圾箱系统文件夹 * */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch // add a trash system folder ContentValues values = new ContentValues(); @@ -680,17 +860,23 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); } +<<<<<<< HEAD <<<<<<< HEAD private void upgradeToV4(SQLiteDatabase db) { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0"); ======= +======= +>>>>>>> liuyitao-branch /* * 更新到V4版本 * */ private void upgradeToV4(SQLiteDatabase db) { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0");// 通过执行ALTER TABLE语句向NOTE表格中添加一个新的列VERSION,该列的类型是INTEGER,并设置默认值为0 +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java index 1473b57..17b96e6 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java @@ -34,6 +34,7 @@ import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.NotesDatabaseHelper.TABLE; +<<<<<<< HEAD <<<<<<< HEAD public class NotesProvider extends ContentProvider { @@ -45,6 +46,8 @@ public class NotesProvider extends ContentProvider { private static final int URI_NOTE = 1; ======= +======= +>>>>>>> liuyitao-branch /* * 功能描述:用于提供对便签数据的存储和获取功能,实现了创建、读取、更新、删除操作,以便其他组件可以通过 ContentResolver 访问和管理便签数据。 * */ @@ -56,6 +59,9 @@ public class NotesProvider extends ContentProvider { private static final String TAG = "NotesProvider";// 标签 private static final int URI_NOTE = 1;// Uri匹配码 +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final int URI_NOTE_ITEM = 2; private static final int URI_DATA = 3; @@ -65,6 +71,7 @@ public class NotesProvider extends ContentProvider { private static final int URI_SEARCH_SUGGEST = 6; static { +<<<<<<< HEAD <<<<<<< HEAD mMatcher = new UriMatcher(UriMatcher.NO_MATCH); mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE); @@ -75,6 +82,8 @@ public class NotesProvider extends ContentProvider { mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST); mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST); ======= +======= +>>>>>>> liuyitao-branch mMatcher = new UriMatcher(UriMatcher.NO_MATCH);// 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码 /* * 把需要匹配Uri路径全部给注册上 @@ -86,6 +95,9 @@ public class NotesProvider extends ContentProvider { mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH);// 搜索的路径 mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST);// 搜索建议的路径 mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST);// 带搜索关键字的搜索建议的路径 +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } @@ -94,11 +106,17 @@ public class NotesProvider extends ContentProvider { * we will trim '\n' and white space in order to show more information. */ <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> liuyitao-branch /* * 查询搜索结果的投影。该投影包含了搜索结果需要的各个字段,如便签的 ID、搜索文本等 * */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + "," + NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + "," @@ -109,6 +127,12 @@ public class NotesProvider extends ContentProvider { + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA; <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + * 查询语句,用于查询搜索结果 + * */ +>>>>>>> liuyitao-branch ======= /* * 查询语句,用于查询搜索结果 @@ -122,6 +146,12 @@ public class NotesProvider extends ContentProvider { @Override <<<<<<< HEAD +<<<<<<< HEAD +======= + /* + *在onCreate()中初始化Context,实例化mHelper + * */ +>>>>>>> liuyitao-branch ======= /* *在onCreate()中初始化Context,实例化mHelper @@ -133,6 +163,7 @@ public class NotesProvider extends ContentProvider { } @Override +<<<<<<< HEAD <<<<<<< HEAD public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { @@ -158,6 +189,8 @@ public class NotesProvider extends ContentProvider { c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs, null, null, sortOrder); ======= +======= +>>>>>>> liuyitao-branch /* * 根据传入的Uri进行数据库查询操作 * */ @@ -187,14 +220,21 @@ public class NotesProvider extends ContentProvider { id = uri.getPathSegments().get(1); // 获取Uri中的ID值 c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs, null, null, sortOrder);// 查询特定ID的数据详情 +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch break; case URI_SEARCH: case URI_SEARCH_SUGGEST: if (sortOrder != null || projection != null) { throw new IllegalArgumentException( +<<<<<<< HEAD <<<<<<< HEAD "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query"); +======= + "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");// 如果存在不合法的参数则抛出异常 +>>>>>>> liuyitao-branch ======= "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");// 如果存在不合法的参数则抛出异常 >>>>>>> liuyitao-branch @@ -203,6 +243,7 @@ public class NotesProvider extends ContentProvider { String searchString = null; if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) { if (uri.getPathSegments().size() > 1) { +<<<<<<< HEAD <<<<<<< HEAD searchString = uri.getPathSegments().get(1); } @@ -279,6 +320,8 @@ public class NotesProvider extends ContentProvider { case URI_NOTE_ITEM: id = uri.getPathSegments().get(1); ======= +======= +>>>>>>> liuyitao-branch searchString = uri.getPathSegments().get(1); // 获取搜索关键字 } } else { @@ -368,12 +411,16 @@ public class NotesProvider extends ContentProvider { break; case URI_NOTE_ITEM: id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch /** * ID that smaller than 0 is system folder which is not allowed to * trash */ long noteId = Long.valueOf(id); +<<<<<<< HEAD <<<<<<< HEAD if (noteId <= 0) { break; @@ -444,6 +491,8 @@ public class NotesProvider extends ContentProvider { } ======= +======= +>>>>>>> liuyitao-branch if (noteId <= 0) {// 如果ID小于等于0,则不允许删除 break; } @@ -522,11 +571,15 @@ public class NotesProvider extends ContentProvider { /* * 解析查询条件selection,如果selection不为空,则在其前面加上" AND ",用于拼接SQL语句 * */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private String parseSelection(String selection) { return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } +<<<<<<< HEAD <<<<<<< HEAD private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { StringBuilder sql = new StringBuilder(120); @@ -555,6 +608,8 @@ public class NotesProvider extends ContentProvider { @Override ======= +======= +>>>>>>> liuyitao-branch /* * 根据传入的id和selection参数确定要更新的记录,并将版本号加1 * */ @@ -590,13 +645,19 @@ public class NotesProvider extends ContentProvider { * 输入参数:参数 uri 表示查询或操作的 URI * 函数中是环境自动生成的,也可自己改写 * */ +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch public String getType(Uri uri) { // TODO Auto-generated method stub return null; } <<<<<<< HEAD +<<<<<<< HEAD +======= +>>>>>>> liuyitao-branch ======= >>>>>>> liuyitao-branch } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java index 1edcef7..f4fdcca 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/MetaData.java @@ -26,6 +26,7 @@ import org.json.JSONObject; public class MetaData extends Task { +<<<<<<< HEAD <<<<<<< HEAD /* * 功能描述:得到类的简写名称存入字符串TAG中 @@ -52,6 +53,8 @@ public class MetaData extends Task { * 输出错误信息 */ ======= +======= +>>>>>>> liuyitao-branch private final static String TAG = MetaData.class.getSimpleName(); private String mRelatedGid = null; @@ -61,11 +64,15 @@ public class MetaData extends Task { metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); } catch (JSONException e) { Log.e(TAG, "failed to put related gid"); +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } setNotes(metaInfo.toString()); setName(GTaskStringUtils.META_NOTE_NAME); } +<<<<<<< HEAD <<<<<<< HEAD /* * 功能描述:获取相关联的Gid @@ -77,16 +84,22 @@ public class MetaData extends Task { * 功能描述:判断当前数据是否为空,若为空则返回真即值得保存 */ ======= +======= +>>>>>>> liuyitao-branch public String getRelatedGid() { return mRelatedGid; } +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch @Override public boolean isWorthSaving() { return getNotes() != null; } +<<<<<<< HEAD <<<<<<< HEAD /* * 功能描述:使用远程json数据对象设置元数据内容 @@ -95,6 +108,9 @@ public class MetaData extends Task { */ ======= +>>>>>>> liuyitao-branch +======= + >>>>>>> liuyitao-branch @Override public void setContentByRemoteJSON(JSONObject js) { @@ -105,28 +121,36 @@ public class MetaData extends Task { mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); } catch (JSONException e) { Log.w(TAG, "failed to get related gid"); +<<<<<<< HEAD <<<<<<< HEAD /* * 输出警告信息 */ ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch mRelatedGid = null; } } } +<<<<<<< HEAD <<<<<<< HEAD /* * 功能描述:使用本地json数据对象设置元数据内容,一般不会用到,若用到,则抛出异常 */ ======= +>>>>>>> liuyitao-branch +======= + >>>>>>> liuyitao-branch @Override public void setContentByLocalJSON(JSONObject js) { // this function should not be called throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); } +<<<<<<< HEAD <<<<<<< HEAD @Override public JSONObject getLocalJSONFromContent() { @@ -146,6 +170,8 @@ public class MetaData extends Task { */ } ======= +======= +>>>>>>> liuyitao-branch @Override public JSONObject getLocalJSONFromContent() { @@ -157,5 +183,8 @@ public class MetaData extends Task { throw new IllegalAccessError("MetaData:getSyncAction should not be called"); } +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java index 91a34fd..2fe8195 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Node.java @@ -20,6 +20,7 @@ import android.database.Cursor; import org.json.JSONObject; +<<<<<<< HEAD <<<<<<< HEAD /** * 应该是同步操作的基础数据类型,定义了相关指示同步操作的常量 @@ -45,6 +46,8 @@ public abstract class Node { public static final int SYNC_ACTION_ERROR = 8;// 同步出现错误 ======= +======= +>>>>>>> liuyitao-branch public abstract class Node { public static final int SYNC_ACTION_NONE = 0; @@ -63,12 +66,16 @@ public abstract class Node { public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; public static final int SYNC_ACTION_ERROR = 8; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch private String mGid; private String mName; +<<<<<<< HEAD <<<<<<< HEAD private long mLastModified;//记录最后一次修改时间 @@ -125,6 +132,8 @@ public abstract class Node { return this.mDeleted; // 返回 mDeleted 的取值 } ======= +======= +>>>>>>> liuyitao-branch private long mLastModified; private boolean mDeleted; @@ -180,5 +189,8 @@ public abstract class Node { return this.mDeleted; } +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java index a7c6ac0..489141e 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlData.java @@ -14,6 +14,7 @@ * limitations under the License. */ +<<<<<<< HEAD <<<<<<< HEAD /* * Description:用于支持小米便签最底层的数据库相关操作,和sqlnote的关系上是子集关系,即data是note的子集(节点)。 @@ -29,6 +30,9 @@ package net.micode.notes.gtask.data; ======= package net.micode.notes.gtask.data; >>>>>>> liuyitao-branch +======= +package net.micode.notes.gtask.data; +>>>>>>> liuyitao-branch import android.content.ContentResolver; import android.content.ContentUris; @@ -50,6 +54,7 @@ import org.json.JSONObject; public class SqlData { +<<<<<<< HEAD <<<<<<< HEAD /* * 功能描述:得到类的简写名称存入字符串TAG中 @@ -65,15 +70,21 @@ public class SqlData { // 集合了interface DataColumns中所有SF常量 ======= +======= +>>>>>>> liuyitao-branch private static final String TAG = SqlData.class.getSimpleName(); private static final int INVALID_ID = -99999; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch public static final String[] PROJECTION_DATA = new String[] { DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1, DataColumns.DATA3 }; +<<<<<<< HEAD <<<<<<< HEAD /* * 以下五个变量作为sql表中5列的编号 @@ -115,6 +126,8 @@ public class SqlData { mIsCreate = true; mDataId = INVALID_ID;//mDataId置初始值-99999 ======= +======= +>>>>>>> liuyitao-branch public static final int DATA_ID_COLUMN = 0; @@ -146,6 +159,9 @@ public class SqlData { mContentResolver = context.getContentResolver(); mIsCreate = true; mDataId = INVALID_ID; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch mDataMimeType = DataConstants.NOTE; mDataContent = ""; @@ -154,6 +170,7 @@ public class SqlData { mDiffDataValues = new ContentValues(); } +<<<<<<< HEAD <<<<<<< HEAD /* @@ -263,6 +280,8 @@ public class SqlData { } catch (NumberFormatException e) { // 如果获取ID出错则输出错误日志并抛出ActionFailureException异常 ======= +======= +>>>>>>> liuyitao-branch public SqlData(Context context, Cursor c) { mContentResolver = context.getContentResolver(); mIsCreate = false; @@ -337,6 +356,9 @@ public class SqlData { try { mDataId = Long.valueOf(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); @@ -345,6 +367,7 @@ public class SqlData { if (mDiffDataValues.size() > 0) { int result = 0; if (!validateVersion) { +<<<<<<< HEAD <<<<<<< HEAD // 如果不需要验证版本,则直接通过mDataId更新mDiffDataValues到数据库中 result = mContentResolver.update(ContentUris.withAppendedId( @@ -354,11 +377,16 @@ public class SqlData { result = mContentResolver.update(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, ======= +======= +>>>>>>> liuyitao-branch result = mContentResolver.update(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null); } else { result = mContentResolver.update(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch " ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE + " WHERE " + NoteColumns.VERSION + "=?)", new String[] { @@ -366,15 +394,19 @@ public class SqlData { }); } if (result == 0) { +<<<<<<< HEAD <<<<<<< HEAD // 如果没有更新任何数据,则输出警告日志 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch Log.w(TAG, "there is no update. maybe user updates note when syncing"); } } } +<<<<<<< HEAD <<<<<<< HEAD // 清空差异数据 mDiffDataValues.clear(); @@ -390,6 +422,8 @@ public class SqlData { } ======= +======= +>>>>>>> liuyitao-branch mDiffDataValues.clear(); mIsCreate = false; } @@ -397,5 +431,8 @@ public class SqlData { public long getId() { return mDataId; } +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java index 127b78a..d6db183 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java @@ -43,6 +43,7 @@ public class SqlNote { private static final int INVALID_ID = -99999; +<<<<<<< HEAD <<<<<<< HEAD // 定义查询笔记的投影,包含需要查询的列 public static final String[] PROJECTION_NOTE = new String[] { @@ -150,6 +151,8 @@ public class SqlNote { try { // 通过 ID 查询笔记数据 ======= +======= +>>>>>>> liuyitao-branch public static final String[] PROJECTION_NOTE = new String[] { NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE, @@ -276,12 +279,16 @@ public class SqlNote { private void loadFromCursor(long id) { Cursor c = null; try { +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)", new String[] { String.valueOf(id) }, null); if (c != null) { +<<<<<<< HEAD <<<<<<< HEAD c.moveToNext(); // 移动到第一条数据 loadFromCursor(c); // 载入数据 @@ -292,6 +299,8 @@ public class SqlNote { if (c != null) c.close(); // 关闭游标 ======= +======= +>>>>>>> liuyitao-branch c.moveToNext(); loadFromCursor(c); } else { @@ -300,11 +309,15 @@ public class SqlNote { } finally { if (c != null) c.close(); +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } } private void loadFromCursor(Cursor c) { +<<<<<<< HEAD <<<<<<< HEAD mId = c.getLong(ID_COLUMN); // 从游标中获取并设置 ID mAlertDate = c.getLong(ALERTED_DATE_COLUMN); // 从游标中获取并设置提醒日期 @@ -327,6 +340,8 @@ public class SqlNote { try { // 通过笔记ID查询数据内容 ======= +======= +>>>>>>> liuyitao-branch mId = c.getLong(ID_COLUMN); mAlertDate = c.getLong(ALERTED_DATE_COLUMN); mBgColorId = c.getInt(BG_COLOR_ID_COLUMN); @@ -345,6 +360,9 @@ public class SqlNote { Cursor c = null; mDataList.clear(); try { +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA, "(note_id=?)", new String[] { @@ -352,6 +370,7 @@ public class SqlNote { }, null); if (c != null) { if (c.getCount() == 0) { +<<<<<<< HEAD <<<<<<< HEAD Log.w(TAG, "it seems that the note has not data");// 输出警告日志 return; @@ -367,6 +386,8 @@ public class SqlNote { if (c != null) c.close();// 关闭游标 ======= +======= +>>>>>>> liuyitao-branch Log.w(TAG, "it seems that the note has not data"); return; } @@ -380,12 +401,16 @@ public class SqlNote { } finally { if (c != null) c.close(); +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } } public boolean setContent(JSONObject js) { try { +<<<<<<< HEAD <<<<<<< HEAD // 解析JSON对象中的note字段 JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); @@ -400,6 +425,8 @@ public class SqlNote { .getString(NoteColumns.SNIPPET) : ""; // 如果正在创建一个新的note,或者之前的snippet和当前传入的snippet不相等,则更新snippet字段 ======= +======= +>>>>>>> liuyitao-branch JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { Log.w(TAG, "cannot set system folder"); @@ -407,6 +434,9 @@ public class SqlNote { // for folder we can only update the snnipet and type String snippet = note.has(NoteColumns.SNIPPET) ? note .getString(NoteColumns.SNIPPET) : ""; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (mIsCreate || !mSnippet.equals(snippet)) { mDiffNoteValues.put(NoteColumns.SNIPPET, snippet); @@ -415,14 +445,18 @@ public class SqlNote { int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) : Notes.TYPE_NOTE; +<<<<<<< HEAD <<<<<<< HEAD // 如果正在创建一个新的note,或者之前的type和当前传入的type不相等,则更新type字段 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (mIsCreate || mType != type) { mDiffNoteValues.put(NoteColumns.TYPE, type); } mType = type; +<<<<<<< HEAD <<<<<<< HEAD }else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { // 如果类型为笔记类型,则解析data数组 @@ -430,6 +464,11 @@ public class SqlNote { // 获取note的ID字段,如果没有则设置为INVALID_ID常量值 long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID; // 如果正在创建一个新的note,或者之前的id和当前传入的id不相等,则更新ID字段 +======= + } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { + JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); + long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID; +>>>>>>> liuyitao-branch ======= } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); @@ -440,9 +479,14 @@ public class SqlNote { } mId = id; +<<<<<<< HEAD <<<<<<< HEAD // 解析并更新其他成员变量 long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note.getLong(NoteColumns.ALERTED_DATE) : 0; +======= + long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note + .getLong(NoteColumns.ALERTED_DATE) : 0; +>>>>>>> liuyitao-branch ======= long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note .getLong(NoteColumns.ALERTED_DATE) : 0; @@ -452,11 +496,14 @@ public class SqlNote { } mAlertDate = alertDate; +<<<<<<< HEAD <<<<<<< HEAD // 解析snippet和type字段 String snippet = note.has(NoteColumns.SNIPPET) ? note.getString(NoteColumns.SNIPPET) : ""; // 如果正在创建一个新的note,或者之前的snippet和当前传入的snippet不相等,则更新snippet字段 ======= +======= +>>>>>>> liuyitao-branch int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note .getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext); if (mIsCreate || mBgColorId != bgColorId) { @@ -494,15 +541,23 @@ public class SqlNote { String snippet = note.has(NoteColumns.SNIPPET) ? note .getString(NoteColumns.SNIPPET) : ""; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (mIsCreate || !mSnippet.equals(snippet)) { mDiffNoteValues.put(NoteColumns.SNIPPET, snippet); } mSnippet = snippet; +<<<<<<< HEAD <<<<<<< HEAD int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) : Notes.TYPE_NOTE; // 如果正在创建一个新的note,或者之前的type和当前传入的type不相等,则更新type字段 +======= + int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) + : Notes.TYPE_NOTE; +>>>>>>> liuyitao-branch ======= int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) : Notes.TYPE_NOTE; @@ -512,6 +567,7 @@ public class SqlNote { } mType = type; +<<<<<<< HEAD <<<<<<< HEAD // 遍历data数组 for (int i = 0; i < dataArray.length(); i++) { @@ -520,6 +576,8 @@ public class SqlNote { // 检查data数组中的id字段,并查找对应的SqlData对象 ======= +======= +>>>>>>> liuyitao-branch int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID) : AppWidgetManager.INVALID_APPWIDGET_ID; if (mIsCreate || mWidgetId != widgetId) { @@ -544,6 +602,9 @@ public class SqlNote { for (int i = 0; i < dataArray.length(); i++) { JSONObject data = dataArray.getJSONObject(i); SqlData sqlData = null; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (data.has(DataColumns.ID)) { long dataId = data.getLong(DataColumns.ID); @@ -554,31 +615,41 @@ public class SqlNote { } } +<<<<<<< HEAD <<<<<<< HEAD // 如果未找到对应的SqlData对象,则创建一个新的对象并添加到数据列表中 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (sqlData == null) { sqlData = new SqlData(mContext); mDataList.add(sqlData); } +<<<<<<< HEAD <<<<<<< HEAD // 调用SqlData对象的setContent方法,传递JSON数据进行处理 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch sqlData.setContent(data); } } } catch (JSONException e) { +<<<<<<< HEAD <<<<<<< HEAD // 处理异常情况,打印错误信息并返回false ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch Log.e(TAG, e.toString()); e.printStackTrace(); return false; } +<<<<<<< HEAD <<<<<<< HEAD // 返回true,表示设置内容成功 @@ -640,6 +711,8 @@ public class SqlNote { // 如果出现异常,则返回 null return null; // 返回null ======= +======= +>>>>>>> liuyitao-branch return true; } @@ -689,14 +762,21 @@ public class SqlNote { e.printStackTrace(); } return null; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } public void setParentId(long id) { mParentId = id; mDiffNoteValues.put(NoteColumns.PARENT_ID, id); +<<<<<<< HEAD <<<<<<< HEAD }//设置父节点ID +======= + } +>>>>>>> liuyitao-branch ======= } >>>>>>> liuyitao-branch @@ -704,6 +784,7 @@ public class SqlNote { public void setGtaskId(String gid) { mDiffNoteValues.put(NoteColumns.GTASK_ID, gid); } +<<<<<<< HEAD <<<<<<< HEAD //设置Google任务ID public void setSyncId(long syncId) { @@ -745,6 +826,8 @@ public class SqlNote { try { // 将Uri路径中的第二个片段转换为long类型,并赋值给mId ======= +======= +>>>>>>> liuyitao-branch public void setSyncId(long syncId) { mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId); @@ -778,6 +861,9 @@ public class SqlNote { Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues); try { +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch mId = Long.valueOf(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { @@ -788,9 +874,12 @@ public class SqlNote { throw new IllegalStateException("Create thread id failed"); } +<<<<<<< HEAD <<<<<<< HEAD // 如果是笔记类型,则循环提交数据内容更改 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (mType == Notes.TYPE_NOTE) { for (SqlData sqlData : mDataList) { @@ -798,9 +887,12 @@ public class SqlNote { } } } else { +<<<<<<< HEAD <<<<<<< HEAD // 如果不是新建笔记 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) { Log.e(TAG, "No such note"); @@ -810,6 +902,7 @@ public class SqlNote { mVersion ++; int result = 0; if (!validateVersion) { +<<<<<<< HEAD <<<<<<< HEAD // 如果不需要验证版本,则直接通过mId更新mDiffNoteValues到数据库中 result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" @@ -821,6 +914,8 @@ public class SqlNote { result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)", ======= +======= +>>>>>>> liuyitao-branch result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?)", new String[] { String.valueOf(mId) @@ -828,6 +923,9 @@ public class SqlNote { } else { result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)", +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch new String[] { String.valueOf(mId), String.valueOf(mVersion) @@ -838,9 +936,12 @@ public class SqlNote { } } +<<<<<<< HEAD <<<<<<< HEAD // 如果是笔记类型,则循环提交数据内容更改 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (mType == Notes.TYPE_NOTE) { for (SqlData sqlData : mDataList) { @@ -849,8 +950,12 @@ public class SqlNote { } } +<<<<<<< HEAD <<<<<<< HEAD // 刷新本地信息 +======= + // refresh local info +>>>>>>> liuyitao-branch ======= // refresh local info >>>>>>> liuyitao-branch @@ -858,9 +963,12 @@ public class SqlNote { if (mType == Notes.TYPE_NOTE) loadDataContent(); +<<<<<<< HEAD <<<<<<< HEAD // 清空mDiffNoteValues和将mIsCreate设置为false ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch mDiffNoteValues.clear(); mIsCreate = false; diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Task.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Task.java index a896f91..36c0c17 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Task.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/Task.java @@ -33,6 +33,7 @@ import org.json.JSONObject; public class Task extends Node { +<<<<<<< HEAD <<<<<<< HEAD private static final String TAG = Task.class.getSimpleName(); // 定义一个私有静态常量TAG,值为Task.class.getSimpleName() @@ -146,6 +147,8 @@ public class Task extends Node { try { // 获取Google Task的ID并设置到本地笔记或任务中 ======= +======= +>>>>>>> liuyitao-branch private static final String TAG = Task.class.getSimpleName(); private boolean mCompleted; @@ -252,13 +255,20 @@ public class Task extends Node { if (js != null) { try { // id +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (js.has(GTaskStringUtils.GTASK_JSON_ID)) { setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID)); } +<<<<<<< HEAD <<<<<<< HEAD // 获取Google Task的最后修改时间戳并设置到本地笔记或任务中 +======= + // last_modified +>>>>>>> liuyitao-branch ======= // last_modified >>>>>>> liuyitao-branch @@ -266,8 +276,12 @@ public class Task extends Node { setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)); } +<<<<<<< HEAD <<<<<<< HEAD // 获取Google Task的名称并设置到本地笔记或任务中 +======= + // name +>>>>>>> liuyitao-branch ======= // name >>>>>>> liuyitao-branch @@ -275,8 +289,12 @@ public class Task extends Node { setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); } +<<<<<<< HEAD <<<<<<< HEAD // 获取Google Task的备注信息并设置到本地笔记或任务中 +======= + // notes +>>>>>>> liuyitao-branch ======= // notes >>>>>>> liuyitao-branch @@ -284,8 +302,12 @@ public class Task extends Node { setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES)); } +<<<<<<< HEAD <<<<<<< HEAD // 获取Google Task的删除状态并设置到本地笔记或任务中 +======= + // deleted +>>>>>>> liuyitao-branch ======= // deleted >>>>>>> liuyitao-branch @@ -293,6 +315,7 @@ public class Task extends Node { setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED)); } +<<<<<<< HEAD <<<<<<< HEAD // 获取Google Task的完成状态并设置到本地笔记或任务中 if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) { @@ -301,11 +324,16 @@ public class Task extends Node { } catch (JSONException e) { // 如果解析过程出现异常 // 记录异常日志并抛出异常 ======= +======= +>>>>>>> liuyitao-branch // completed if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) { setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED)); } } catch (JSONException e) { +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch Log.e(TAG, e.toString()); e.printStackTrace(); @@ -316,6 +344,7 @@ public class Task extends Node { public void setContentByLocalJSON(JSONObject js) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) +<<<<<<< HEAD <<<<<<< HEAD || !js.has(GTaskStringUtils.META_HEAD_DATA)) { // 如果参数为空或缺少必要的数据字段 Log.w(TAG, "setContentByLocalJSON: nothing is available"); // 记录警告日志 @@ -346,6 +375,8 @@ public class Task extends Node { Log.e(TAG, e.toString()); // 记录异常日志 e.printStackTrace(); // 打印异常堆栈信息 ======= +======= +>>>>>>> liuyitao-branch || !js.has(GTaskStringUtils.META_HEAD_DATA)) { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); } @@ -370,11 +401,15 @@ public class Task extends Node { } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } } public JSONObject getLocalJSONFromContent() { +<<<<<<< HEAD <<<<<<< HEAD String name = getName(); // 获取名称 try { @@ -387,6 +422,8 @@ public class Task extends Node { // 创建JSON对象,并填充数据 ======= +======= +>>>>>>> liuyitao-branch String name = getName(); try { if (mMetaInfo == null) { @@ -396,13 +433,20 @@ public class Task extends Node { return null; } +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch JSONObject js = new JSONObject(); JSONObject note = new JSONObject(); JSONArray dataArray = new JSONArray(); JSONObject data = new JSONObject(); +<<<<<<< HEAD <<<<<<< HEAD data.put(DataColumns.CONTENT, name); // 设置数据内容为名称 +======= + data.put(DataColumns.CONTENT, name); +>>>>>>> liuyitao-branch ======= data.put(DataColumns.CONTENT, name); >>>>>>> liuyitao-branch @@ -410,6 +454,7 @@ public class Task extends Node { js.put(GTaskStringUtils.META_HEAD_DATA, dataArray); note.put(NoteColumns.TYPE, Notes.TYPE_NOTE); js.put(GTaskStringUtils.META_HEAD_NOTE, note); +<<<<<<< HEAD <<<<<<< HEAD return js; // 返回JSON对象 } else { @@ -425,6 +470,8 @@ public class Task extends Node { data.put(DataColumns.CONTENT, getName()); // 设置数据内容为名称 break; // 跳出循环 ======= +======= +>>>>>>> liuyitao-branch return js; } else { // synced task @@ -436,11 +483,15 @@ public class Task extends Node { if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) { data.put(DataColumns.CONTENT, getName()); break; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } } note.put(NoteColumns.TYPE, Notes.TYPE_NOTE); +<<<<<<< HEAD <<<<<<< HEAD return mMetaInfo; // 返回元信息对象 } @@ -449,17 +500,23 @@ public class Task extends Node { e.printStackTrace(); // 打印异常堆栈信息 return null; // 返回null ======= +======= +>>>>>>> liuyitao-branch return mMetaInfo; } } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); return null; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } } public void setMetaInfo(MetaData metaData) { +<<<<<<< HEAD <<<<<<< HEAD if (metaData != null && metaData.getNotes() != null) { // 如果元数据不为空且笔记不为空 try { @@ -468,25 +525,34 @@ public class Task extends Node { Log.w(TAG, e.toString()); // 记录警告日志 mMetaInfo = null; // 设置元信息为空 ======= +======= +>>>>>>> liuyitao-branch if (metaData != null && metaData.getNotes() != null) { try { mMetaInfo = new JSONObject(metaData.getNotes()); } catch (JSONException e) { Log.w(TAG, e.toString()); mMetaInfo = null; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } } } +<<<<<<< HEAD <<<<<<< HEAD //获取同步操作类型 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch public int getSyncAction(Cursor c) { try { JSONObject noteInfo = null; if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) { +<<<<<<< HEAD <<<<<<< HEAD noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); // 获取笔记信息对象 } @@ -573,6 +639,8 @@ public class Task extends Node { return this.mParent; }//获取任务的父任务列表 ======= +======= +>>>>>>> liuyitao-branch noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); } @@ -658,6 +726,9 @@ public class Task extends Node { public TaskList getParent() { return this.mParent; } +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/TaskList.java b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/TaskList.java index a72fc3d..12f8ace 100644 --- a/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/TaskList.java +++ b/src/Notes-master/app/src/main/java/net/micode/notes/gtask/data/TaskList.java @@ -31,6 +31,7 @@ import java.util.ArrayList; public class TaskList extends Node { +<<<<<<< HEAD <<<<<<< HEAD private static final String TAG = TaskList.class.getSimpleName(); // TAG用于在日志中标识类名 @@ -90,6 +91,8 @@ public class TaskList extends Node { ======= +======= +>>>>>>> liuyitao-branch private static final String TAG = TaskList.class.getSimpleName(); private int mIndex; @@ -133,11 +136,15 @@ public class TaskList extends Node { return js; } +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch public JSONObject getUpdateAction(int actionId) { JSONObject js = new JSONObject(); try { +<<<<<<< HEAD <<<<<<< HEAD // 设置操作类型为更新 js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE); @@ -167,6 +174,8 @@ public class TaskList extends Node { // 抛出自定义异常 ======= +======= +>>>>>>> liuyitao-branch // action_type js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE); @@ -186,6 +195,9 @@ public class TaskList extends Node { } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch throw new ActionFailureException("fail to generate tasklist-update jsonobject"); } @@ -198,38 +210,52 @@ public class TaskList extends Node { try { // id if (js.has(GTaskStringUtils.GTASK_JSON_ID)) { +<<<<<<< HEAD <<<<<<< HEAD // 如果JSON对象包含ID字段,则将ID设置为相应的值 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID)); } // last_modified if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) { +<<<<<<< HEAD <<<<<<< HEAD // 如果JSON对象包含last_modified字段,则将last_modified设置为相应的值 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)); } // name if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) { +<<<<<<< HEAD <<<<<<< HEAD // 如果JSON对象包含name字段,则将name设置为相应的值 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); } } catch (JSONException e) { +<<<<<<< HEAD <<<<<<< HEAD // 打印异常信息 Log.e(TAG, e.toString()); e.printStackTrace(); // 抛出自定义异常 +======= + Log.e(TAG, e.toString()); + e.printStackTrace(); +>>>>>>> liuyitao-branch ======= Log.e(TAG, e.toString()); e.printStackTrace(); @@ -240,6 +266,7 @@ public class TaskList extends Node { } public void setContentByLocalJSON(JSONObject js) { +<<<<<<< HEAD <<<<<<< HEAD // 检查传入的JSON对象是否为空或者不包含指定的字段 if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) { @@ -276,6 +303,8 @@ public class TaskList extends Node { } catch (JSONException e) { // 打印异常信息 ======= +======= +>>>>>>> liuyitao-branch if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); } @@ -298,12 +327,16 @@ public class TaskList extends Node { Log.e(TAG, "error type"); } } catch (JSONException e) { +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch Log.e(TAG, e.toString()); e.printStackTrace(); } } +<<<<<<< HEAD <<<<<<< HEAD /* * 从内容中获取本地JSON对象 @@ -326,6 +359,8 @@ public class TaskList extends Node { // 检查文件夹名称是否为默认文件夹或通话笔记文件夹,如果是,则设置文件夹类型为系统类型,否则设置为文件夹类型 ======= +======= +>>>>>>> liuyitao-branch public JSONObject getLocalJSONFromContent() { try { JSONObject js = new JSONObject(); @@ -336,6 +371,9 @@ public class TaskList extends Node { folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(), folderName.length()); folder.put(NoteColumns.SNIPPET, folderName); +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT) || folderName.equals(GTaskStringUtils.FOLDER_CALL_NOTE)) @@ -343,6 +381,7 @@ public class TaskList extends Node { else folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER); +<<<<<<< HEAD <<<<<<< HEAD // 将文件夹JSON对象放入根JSON对象中的头部注释字段中 js.put(GTaskStringUtils.META_HEAD_NOTE, folder); @@ -355,17 +394,23 @@ public class TaskList extends Node { e.printStackTrace(); // 返回空值 ======= +======= +>>>>>>> liuyitao-branch js.put(GTaskStringUtils.META_HEAD_NOTE, folder); return js; } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch return null; } } +<<<<<<< HEAD <<<<<<< HEAD /* * 获取同步操作类型 @@ -386,6 +431,8 @@ public class TaskList extends Node { } else { // 验证gtask id ======= +======= +>>>>>>> liuyitao-branch public int getSyncAction(Cursor c) { try { if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) { @@ -399,35 +446,48 @@ public class TaskList extends Node { } } else { // validate gtask id +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) { Log.e(TAG, "gtask id doesn't match"); return SYNC_ACTION_ERROR; } if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) { +<<<<<<< HEAD <<<<<<< HEAD // 仅有本地修改 return SYNC_ACTION_UPDATE_REMOTE; } else { // 对于文件夹冲突,只应用本地修改 ======= +======= +>>>>>>> liuyitao-branch // local modification only return SYNC_ACTION_UPDATE_REMOTE; } else { // for folder conflicts, just apply local modification +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch return SYNC_ACTION_UPDATE_REMOTE; } } } catch (Exception e) { +<<<<<<< HEAD <<<<<<< HEAD // 打印异常信息 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch Log.e(TAG, e.toString()); e.printStackTrace(); } +<<<<<<< HEAD <<<<<<< HEAD // 返回错误的同步操作类型 return SYNC_ACTION_ERROR; @@ -456,6 +516,8 @@ public class TaskList extends Node { if (ret) { // 设置子任务的前一个兄弟和父任务 ======= +======= +>>>>>>> liuyitao-branch return SYNC_ACTION_ERROR; } @@ -469,12 +531,16 @@ public class TaskList extends Node { ret = mChildren.add(task); if (ret) { // need to set prior sibling and parent +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch task.setPriorSibling(mChildren.isEmpty() ? null : mChildren .get(mChildren.size() - 1)); task.setParent(this); } } +<<<<<<< HEAD <<<<<<< HEAD // 返回是否成功添加子任务的信息 return ret; @@ -491,16 +557,22 @@ public class TaskList extends Node { if (index < 0 || index > mChildren.size()) { // 如果不合法,则记录日志,返回失败 ======= +======= +>>>>>>> liuyitao-branch return ret; } public boolean addChildTask(Task task, int index) { if (index < 0 || index > mChildren.size()) { +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch Log.e(TAG, "add child task: invalid index"); return false; } +<<<<<<< HEAD <<<<<<< HEAD // 查找子任务是否已经在列表中 int pos = mChildren.indexOf(task); @@ -511,11 +583,16 @@ public class TaskList extends Node { // 更新任务列表 ======= +======= +>>>>>>> liuyitao-branch int pos = mChildren.indexOf(task); if (task != null && pos == -1) { mChildren.add(index, task); // update the task list +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch Task preTask = null; Task afterTask = null; @@ -524,15 +601,19 @@ public class TaskList extends Node { if (index != mChildren.size() - 1) afterTask = mChildren.get(index + 1); +<<<<<<< HEAD <<<<<<< HEAD // 设置前一个兄弟和后一个兄弟 ======= +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch task.setPriorSibling(preTask); if (afterTask != null) afterTask.setPriorSibling(task); } +<<<<<<< HEAD <<<<<<< HEAD // 返回是否成功添加子任务的信息 return true; @@ -582,6 +663,8 @@ public class TaskList extends Node { int pos = mChildren.indexOf(task); // 查找子任务在列表中的位置 // 如果子任务不在列表中,则记录日志,返回失败 ======= +======= +>>>>>>> liuyitao-branch return true; } @@ -614,12 +697,16 @@ public class TaskList extends Node { } int pos = mChildren.indexOf(task); +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch if (pos == -1) { Log.e(TAG, "move child task: the task should in the list"); return false; } +<<<<<<< HEAD <<<<<<< HEAD // 如果子任务本来就在目标位置上,则直接返回成功 if (pos == index) @@ -702,6 +789,8 @@ public class TaskList extends Node { public int getIndex() { return this.mIndex; // 返回索引位置 ======= +======= +>>>>>>> liuyitao-branch if (pos == index) return true; return (removeChildTask(task) && addChildTask(task, index)); @@ -747,6 +836,9 @@ public class TaskList extends Node { public int getIndex() { return this.mIndex; +<<<<<<< HEAD +>>>>>>> liuyitao-branch +======= >>>>>>> liuyitao-branch } } diff --git a/src/Notes-master/local.properties b/src/Notes-master/local.properties index 41c8053..438588c 100644 --- a/src/Notes-master/local.properties +++ b/src/Notes-master/local.properties @@ -3,6 +3,7 @@ # # Location of the SDK. This is only used by Gradle. <<<<<<< HEAD +<<<<<<< HEAD # For customization when using a Version Control System, please read the # header note. #Thu Dec 21 01:09:02 CST 2023 @@ -12,3 +13,8 @@ sdk.dir=C\:\\Users\\lenovo\\AppData\\Local\\Android\\Sdk #Thu Nov 09 19:48:40 CST 2023 sdk.dir=D\:\\Android\\Sdk >>>>>>> liuyitao-branch +======= +# +#Thu Nov 09 19:48:40 CST 2023 +sdk.dir=D\:\\Android\\Sdk +>>>>>>> liuyitao-branch From 95e08907722b42fc502cc03ddcd56a5e93d2ac1d Mon Sep 17 00:00:00 2001 From: liuyitao <2371837061@qq.com> Date: Wed, 27 Dec 2023 21:35:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?Signed-off-by:=20liuyitao=20<2371837061@qq.?= =?UTF-8?q?com>=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea/sonarlint/issuestore/index.pb | 14 +- .../sonarlint/securityhotspotstore/index.pb | 14 +- .../java/net/micode/notes/data/Contact.java | 181 --- .../java/net/micode/notes/data/Notes.java | 840 ------------ .../notes/data/NotesDatabaseHelper.java | 1137 ----------------- .../net/micode/notes/data/NotesProvider.java | 723 ----------- 6 files changed, 26 insertions(+), 2883 deletions(-) delete mode 100644 src/Notes-master/app/src/main/java/net/micode/notes/data/Contact.java delete mode 100644 src/Notes-master/app/src/main/java/net/micode/notes/data/Notes.java delete mode 100644 src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java delete mode 100644 src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java diff --git a/src/Notes-master/.idea/sonarlint/issuestore/index.pb b/src/Notes-master/.idea/sonarlint/issuestore/index.pb index 730b0f7..d596b31 100644 --- a/src/Notes-master/.idea/sonarlint/issuestore/index.pb +++ b/src/Notes-master/.idea/sonarlint/issuestore/index.pb @@ -6,4 +6,16 @@ b j :app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5 d -4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f \ No newline at end of file +4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f +k +;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88 +g +7app/src/main/java/net/micode/notes/gtask/data/Node.java,3\a\3aac5305cb73bfbdeb8078cd264d04323fa80e92 +u +Eapp/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java,f\0\f087b1ba1b9c91b7293fea0fb071eaed62a42137 +q +Aapp/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java,a\b\ab153b0256bc5f6c194e188cec0b8e327e347a90 +p +@app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312 +s +Capp/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java,0\2\023468cfdd0b71d4098903b9070e364658e2fbcf \ No newline at end of file diff --git a/src/Notes-master/.idea/sonarlint/securityhotspotstore/index.pb b/src/Notes-master/.idea/sonarlint/securityhotspotstore/index.pb index 730b0f7..d596b31 100644 --- a/src/Notes-master/.idea/sonarlint/securityhotspotstore/index.pb +++ b/src/Notes-master/.idea/sonarlint/securityhotspotstore/index.pb @@ -6,4 +6,16 @@ b j :app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5 d -4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f \ No newline at end of file +4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f +k +;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88 +g +7app/src/main/java/net/micode/notes/gtask/data/Node.java,3\a\3aac5305cb73bfbdeb8078cd264d04323fa80e92 +u +Eapp/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java,f\0\f087b1ba1b9c91b7293fea0fb071eaed62a42137 +q +Aapp/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java,a\b\ab153b0256bc5f6c194e188cec0b8e327e347a90 +p +@app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312 +s +Capp/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java,0\2\023468cfdd0b71d4098903b9070e364658e2fbcf \ No newline at end of file diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/Contact.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/Contact.java deleted file mode 100644 index c016945..0000000 --- a/src/Notes-master/app/src/main/java/net/micode/notes/data/Contact.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.data; - -import android.content.Context; -import android.database.Cursor; -import android.provider.ContactsContract.CommonDataKinds.Phone; -import android.provider.ContactsContract.Data; -import android.telephony.PhoneNumberUtils; -import android.util.Log; - -import java.util.HashMap; - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -public class Contact { - private static HashMapType: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String ID = "_id"; -======= - public static final String ID = "_id";// 行的唯一标识符 ->>>>>>> liuyitao-branch -======= - public static final String ID = "_id";// 行的唯一标识符 ->>>>>>> liuyitao-branch -======= - public static final String ID = "_id";// 行的唯一标识符 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * The parent's id for note or folder - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String PARENT_ID = "parent_id"; -======= - public static final String PARENT_ID = "parent_id";// 父级的ID ->>>>>>> liuyitao-branch -======= - public static final String PARENT_ID = "parent_id";// 父级的ID ->>>>>>> liuyitao-branch -======= - public static final String PARENT_ID = "parent_id";// 父级的ID ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Created data for note or folder - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String CREATED_DATE = "created_date"; -======= - public static final String CREATED_DATE = "created_date";// 创建日期 ->>>>>>> liuyitao-branch -======= - public static final String CREATED_DATE = "created_date";// 创建日期 ->>>>>>> liuyitao-branch -======= - public static final String CREATED_DATE = "created_date";// 创建日期 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Latest modified date - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String MODIFIED_DATE = "modified_date"; -======= - public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 ->>>>>>> liuyitao-branch -======= - public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 ->>>>>>> liuyitao-branch -======= - public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - - /** - * Alert date - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String ALERTED_DATE = "alert_date"; -======= - public static final String ALERTED_DATE = "alert_date";// 提醒日期 ->>>>>>> liuyitao-branch -======= - public static final String ALERTED_DATE = "alert_date";// 提醒日期 ->>>>>>> liuyitao-branch -======= - public static final String ALERTED_DATE = "alert_date";// 提醒日期 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Folder's name or text content of note - *Type: TEXT
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String SNIPPET = "snippet"; -======= - public static final String SNIPPET = "snippet";// 文件夹名称或便签的文本内容 ->>>>>>> liuyitao-branch -======= - public static final String SNIPPET = "snippet";// 文件夹名称或便签的文本内容 ->>>>>>> liuyitao-branch -======= - public static final String SNIPPET = "snippet";// 文件夹名称或便签的文本内容 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Note's widget id - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String WIDGET_ID = "widget_id"; -======= - public static final String WIDGET_ID = "widget_id";// 便签的Widget ID ->>>>>>> liuyitao-branch -======= - public static final String WIDGET_ID = "widget_id";// 便签的Widget ID ->>>>>>> liuyitao-branch -======= - public static final String WIDGET_ID = "widget_id";// 便签的Widget ID ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Note's widget type - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String WIDGET_TYPE = "widget_type"; -======= - public static final String WIDGET_TYPE = "widget_type";// 便签的Widget类型 ->>>>>>> liuyitao-branch -======= - public static final String WIDGET_TYPE = "widget_type";// 便签的Widget类型 ->>>>>>> liuyitao-branch -======= - public static final String WIDGET_TYPE = "widget_type";// 便签的Widget类型 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Note's background color's id - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String BG_COLOR_ID = "bg_color_id"; -======= - public static final String BG_COLOR_ID = "bg_color_id";// 便签的背景颜色ID ->>>>>>> liuyitao-branch -======= - public static final String BG_COLOR_ID = "bg_color_id";// 便签的背景颜色ID ->>>>>>> liuyitao-branch -======= - public static final String BG_COLOR_ID = "bg_color_id";// 便签的背景颜色ID ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * For text note, it doesn't has attachment, for multi-media - * note, it has at least one attachment - *Type: INTEGER
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String HAS_ATTACHMENT = "has_attachment"; -======= - public static final String HAS_ATTACHMENT = "has_attachment";// 是否有附件 ->>>>>>> liuyitao-branch -======= - public static final String HAS_ATTACHMENT = "has_attachment";// 是否有附件 ->>>>>>> liuyitao-branch -======= - public static final String HAS_ATTACHMENT = "has_attachment";// 是否有附件 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Folder's count of notes - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String NOTES_COUNT = "notes_count"; -======= - public static final String NOTES_COUNT = "notes_count";// 文件夹中的便签数量 ->>>>>>> liuyitao-branch -======= - public static final String NOTES_COUNT = "notes_count";// 文件夹中的便签数量 ->>>>>>> liuyitao-branch -======= - public static final String NOTES_COUNT = "notes_count";// 文件夹中的便签数量 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * The file type: folder or note - *Type: INTEGER
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String TYPE = "type"; -======= - public static final String TYPE = "type";// 文件类型:文件夹或便签 ->>>>>>> liuyitao-branch -======= - public static final String TYPE = "type";// 文件类型:文件夹或便签 ->>>>>>> liuyitao-branch -======= - public static final String TYPE = "type";// 文件类型:文件夹或便签 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * The last sync id - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String SYNC_ID = "sync_id"; -======= - public static final String SYNC_ID = "sync_id";// 最后同步的ID ->>>>>>> liuyitao-branch -======= - public static final String SYNC_ID = "sync_id";// 最后同步的ID ->>>>>>> liuyitao-branch -======= - public static final String SYNC_ID = "sync_id";// 最后同步的ID ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Sign to indicate local modified or not - *Type: INTEGER
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String LOCAL_MODIFIED = "local_modified"; -======= - public static final String LOCAL_MODIFIED = "local_modified";// 标识是否本地修改 ->>>>>>> liuyitao-branch -======= - public static final String LOCAL_MODIFIED = "local_modified";// 标识是否本地修改 ->>>>>>> liuyitao-branch -======= - public static final String LOCAL_MODIFIED = "local_modified";// 标识是否本地修改 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Original parent id before moving into temporary folder - *Type : INTEGER
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String ORIGIN_PARENT_ID = "origin_parent_id"; -======= - public static final String ORIGIN_PARENT_ID = "origin_parent_id";// 移动到临时文件夹之前的原始父级ID ->>>>>>> liuyitao-branch -======= - public static final String ORIGIN_PARENT_ID = "origin_parent_id";// 移动到临时文件夹之前的原始父级ID ->>>>>>> liuyitao-branch -======= - public static final String ORIGIN_PARENT_ID = "origin_parent_id";// 移动到临时文件夹之前的原始父级ID ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * The gtask id - *Type : TEXT
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String GTASK_ID = "gtask_id"; -======= - public static final String GTASK_ID = "gtask_id";// Google任务ID ->>>>>>> liuyitao-branch -======= - public static final String GTASK_ID = "gtask_id";// Google任务ID ->>>>>>> liuyitao-branch -======= - public static final String GTASK_ID = "gtask_id";// Google任务ID ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * The version code - *Type : INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String VERSION = "version"; - } - -======= -======= ->>>>>>> liuyitao-branch - public static final String VERSION = "version";// 版本号 - } - - /* - * 功能描述:定义DataColumns接口数据的常量,用于创建数据库表头 - */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - public static final String VERSION = "version";// 版本号 - } - - /* - * 功能描述:定义DataColumns接口数据的常量,用于创建数据库表头 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public interface DataColumns { - /** - * The unique ID for a row - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String ID = "_id"; -======= - public static final String ID = "_id";// 标识符 ->>>>>>> liuyitao-branch -======= - public static final String ID = "_id";// 标识符 ->>>>>>> liuyitao-branch -======= - public static final String ID = "_id";// 标识符 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * The MIME type of the item represented by this row. - *Type: Text
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String MIME_TYPE = "mime_type"; -======= - public static final String MIME_TYPE = "mime_type";// 数据的MIME类型 ->>>>>>> liuyitao-branch -======= - public static final String MIME_TYPE = "mime_type";// 数据的MIME类型 ->>>>>>> liuyitao-branch -======= - public static final String MIME_TYPE = "mime_type";// 数据的MIME类型 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * The reference id to note that this data belongs to - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String NOTE_ID = "note_id"; -======= - public static final String NOTE_ID = "note_id";// 数据ID ->>>>>>> liuyitao-branch -======= - public static final String NOTE_ID = "note_id";// 数据ID ->>>>>>> liuyitao-branch -======= - public static final String NOTE_ID = "note_id";// 数据ID ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Created data for note or folder - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String CREATED_DATE = "created_date"; -======= - public static final String CREATED_DATE = "created_date";// 创建日期 ->>>>>>> liuyitao-branch -======= - public static final String CREATED_DATE = "created_date";// 创建日期 ->>>>>>> liuyitao-branch -======= - public static final String CREATED_DATE = "created_date";// 创建日期 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Latest modified date - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String MODIFIED_DATE = "modified_date"; -======= - public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 ->>>>>>> liuyitao-branch -======= - public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 ->>>>>>> liuyitao-branch -======= - public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Data's content - *Type: TEXT
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String CONTENT = "content"; -======= - public static final String CONTENT = "content";// 内容 ->>>>>>> liuyitao-branch -======= - public static final String CONTENT = "content";// 内容 ->>>>>>> liuyitao-branch -======= - public static final String CONTENT = "content";// 内容 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - - /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, used for - * integer data type - *Type: INTEGER
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String DATA1 = "data1"; -======= - public static final String DATA1 = "data1";// 通用数据1 ->>>>>>> liuyitao-branch -======= - public static final String DATA1 = "data1";// 通用数据1 ->>>>>>> liuyitao-branch -======= - public static final String DATA1 = "data1";// 通用数据1 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, used for - * integer data type - *Type: INTEGER
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String DATA2 = "data2"; -======= - public static final String DATA2 = "data2";// 通用数据2 ->>>>>>> liuyitao-branch -======= - public static final String DATA2 = "data2";// 通用数据2 ->>>>>>> liuyitao-branch -======= - public static final String DATA2 = "data2";// 通用数据2 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, used for - * TEXT data type - *Type: TEXT
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String DATA3 = "data3"; -======= - public static final String DATA3 = "data3";// 通用数据3 ->>>>>>> liuyitao-branch -======= - public static final String DATA3 = "data3";// 通用数据3 ->>>>>>> liuyitao-branch -======= - public static final String DATA3 = "data3";// 通用数据3 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, used for - * TEXT data type - *Type: TEXT
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String DATA4 = "data4"; -======= - public static final String DATA4 = "data4";// 通用数据4 ->>>>>>> liuyitao-branch -======= - public static final String DATA4 = "data4";// 通用数据4 ->>>>>>> liuyitao-branch -======= - public static final String DATA4 = "data4";// 通用数据4 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Generic data column, the meaning is {@link #MIMETYPE} specific, used for - * TEXT data type - *Type: TEXT
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String DATA5 = "data5"; - } - -======= -======= ->>>>>>> liuyitao-branch - public static final String DATA5 = "data5";// 通用数据5 - } - - /* - * 定义了文本便签的数据结构 - */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - public static final String DATA5 = "data5";// 通用数据5 - } - - /* - * 功能描述:定义了文本便签的数据结构 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public static final class TextNote implements DataColumns { - /** - * Mode to indicate the text in check list mode or not - *Type: Integer 1:check list mode 0: normal mode
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String MODE = DATA1; -======= - public static final String MODE = DATA1;// 模式 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - public static final int MODE_CHECK_LIST = 1;// 待办清单模式 - - public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";// 内容类型 - - public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";// 单个条目的内容类型 - - public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");// 查询文本便签的URI - } - -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch - public static final String MODE = DATA1;// 模式 - - public static final int MODE_CHECK_LIST = 1;// 待办清单模式 - - public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";// 内容类型 - - public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";// 单个条目的内容类型 - - public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");// 查询文本便签的URI - } - - /* - * 定义电话便签的数据结构 - */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - /* - * 功能描述:定义电话便签的数据结构 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public static final class CallNote implements DataColumns { - /** - * Call date for this record - *Type: INTEGER (long)
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String CALL_DATE = DATA1; -======= - public static final String CALL_DATE = DATA1;// 通话日期 ->>>>>>> liuyitao-branch -======= - public static final String CALL_DATE = DATA1;// 通话日期 ->>>>>>> liuyitao-branch -======= - public static final String CALL_DATE = DATA1;// 通话日期 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /** - * Phone number for this record - *Type: TEXT
- */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public static final String PHONE_NUMBER = DATA3; -======= - public static final String PHONE_NUMBER = DATA3;// 电话号码 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";// 内容类型 - - public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";// 单个条目的内容类型 - -<<<<<<< HEAD - public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); -======= -======= ->>>>>>> liuyitao-branch - public static final String PHONE_NUMBER = DATA3;// 电话号码 - - public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";// 内容类型 - - public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";// 单个条目的内容类型 - - public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");// 查询电话便签的URI -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");// 查询电话便签的URI ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - } -} diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java deleted file mode 100644 index 2c079d2..0000000 --- a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java +++ /dev/null @@ -1,1137 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.data; - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -import android.content.ContentValues; -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -======= - -import android.content.ContentValues;//就是用于保存一些数据(string boolean byte double float int long short ...)信息,这些信息可以被数据库操作时使用。 -import android.content.Context;//加载和访问资源。(android中主要是这两个功能,但是这里具体不清楚) -import android.database.sqlite.SQLiteDatabase;//主要提供了对应于添加、删除、更新、查询的操作方法: insert()、delete()、update()和query()。配合content.values -import android.database.sqlite.SQLiteOpenHelper;//用来管理数据的创建和版本更新 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b -import android.util.Log; - - -import net.micode.notes.data.Notes.DataColumns; -import net.micode.notes.data.Notes.DataConstants; -import net.micode.notes.data.Notes.NoteColumns; -/* -* 功能描述:数据库操作,用SQLOpenhelper,对一些note和文件进行数据库的操作 -*/ - -public class NotesDatabaseHelper extends SQLiteOpenHelper { - private static final String DB_NAME = "note.db";// 数据库名 - - private static final int DB_VERSION = 4;// 版本号 - - public interface TABLE { -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch - -import android.content.ContentValues;//就是用于保存一些数据(string boolean byte double float int long short ...)信息,这些信息可以被数据库操作时使用。 -import android.content.Context;//加载和访问资源。(android中主要是这两个功能,但是这里具体不清楚) -import android.database.sqlite.SQLiteDatabase;//主要提供了对应于添加、删除、更新、查询的操作方法: insert()、delete()、update()和query()。配合content.values -import android.database.sqlite.SQLiteOpenHelper;//用来管理数据的创建和版本更新 -import android.util.Log; - - -import net.micode.notes.data.Notes.DataColumns; -import net.micode.notes.data.Notes.DataConstants; -import net.micode.notes.data.Notes.NoteColumns; -/* -* 功能描述:数据库操作,用SQLOpenhelper,对一些note和文件进行数据库的操作 -*/ - -public class NotesDatabaseHelper extends SQLiteOpenHelper { - private static final String DB_NAME = "note.db";// 数据库名 - - private static final int DB_VERSION = 4;// 版本号 - - public interface TABLE { - /* - * 接口,分成note和data,用于表示数据库中两种表格 - * */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - /* - * 接口,分成note和data,用于表示数据库中两种表格 - * */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public static final String NOTE = "note"; - - public static final String DATA = "data"; - } - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - private static final String TAG = "NotesDatabaseHelper"; -======= - private static final String TAG = "NotesDatabaseHelper";// 日志标签,用于在日志中标识数据库操作的相关信息 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * NotesDatabaseHelper 类的实例,用于单例模式的数据库操作,通过 getInstance() 方法获取 NotesDatabaseHelper 的唯一实例 - * 单例模式是一种设计模式,在数据库操作中使用单例模式可以确保只有一个数据库连接,避免了重复创建和关闭数据库连接可能导致的性能问题 - */ - private static NotesDatabaseHelper mInstance; - - /* - * 创建TABLE.NOTE表格,用于存储便签的相关信息 - */ - private static final String CREATE_NOTE_TABLE_SQL = - "CREATE TABLE " + TABLE.NOTE + "(" + - NoteColumns.ID + " INTEGER PRIMARY KEY," +// 便签ID - NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签父级的ID - NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," +// 便签的提醒日期 - NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," + // 便签的背景颜色ID - NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + // 便签的创建日期 - NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," +// 便签是否有附件 - NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 便签的最后修改日期 - NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," +// 文件夹中的便签数量 - NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," +// 文件夹名称或便签的文本内容 - NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," +// 便签的类型 - NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签的Widget ID - NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," +// 便签的Widget类型 - NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签的同步ID - NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +// 便签的本地修改标记 - NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +// 原始父级便签的ID - NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +// 便签在Google任务中的ID - NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +// 便签的版本号 - ")"; - - /* - * 创建TABLE.DATA表格,用于存储便签中的数据 - */ - private static final String CREATE_DATA_TABLE_SQL = - "CREATE TABLE " + TABLE.DATA + "(" + - DataColumns.ID + " INTEGER PRIMARY KEY," +// 数据ID - DataColumns.MIME_TYPE + " TEXT NOT NULL," +// 数据ID数据的MIME类型 - DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," +// 数据所属的便签的ID - NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 数据的创建日期 - NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 数据的最后修改日期 - DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," +// 数据的内容 - DataColumns.DATA1 + " INTEGER," +// 数据的附加信息1 - DataColumns.DATA2 + " INTEGER," +// 数据的附加信息2 - DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +// 数据的附加信息3 - DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +// 数据的附加信息4 - DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +// 数据的附加信息5 - ")"; - -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch - private static final String TAG = "NotesDatabaseHelper";// 日志标签,用于在日志中标识数据库操作的相关信息 - - /* - * NotesDatabaseHelper 类的实例,用于单例模式的数据库操作,通过 getInstance() 方法获取 NotesDatabaseHelper 的唯一实例 - * 单例模式是一种设计模式,在数据库操作中使用单例模式可以确保只有一个数据库连接,避免了重复创建和关闭数据库连接可能导致的性能问题 - */ - private static NotesDatabaseHelper mInstance; - - /* - * 创建TABLE.NOTE表格,用于存储便签的相关信息 - */ - private static final String CREATE_NOTE_TABLE_SQL = - "CREATE TABLE " + TABLE.NOTE + "(" + - NoteColumns.ID + " INTEGER PRIMARY KEY," +// 便签ID - NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签父级的ID - NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," +// 便签的提醒日期 - NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," + // 便签的背景颜色ID - NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + // 便签的创建日期 - NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," +// 便签是否有附件 - NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 便签的最后修改日期 - NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," +// 文件夹中的便签数量 - NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," +// 文件夹名称或便签的文本内容 - NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," +// 便签的类型 - NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签的Widget ID - NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," +// 便签的Widget类型 - NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签的同步ID - NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +// 便签的本地修改标记 - NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +// 原始父级便签的ID - NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +// 便签在Google任务中的ID - NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +// 便签的版本号 - ")"; - - /* - * 创建TABLE.DATA表格,用于存储便签中的数据 - */ - private static final String CREATE_DATA_TABLE_SQL = - "CREATE TABLE " + TABLE.DATA + "(" + - DataColumns.ID + " INTEGER PRIMARY KEY," +// 数据ID - DataColumns.MIME_TYPE + " TEXT NOT NULL," +// 数据ID数据的MIME类型 - DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," +// 数据所属的便签的ID - NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 数据的创建日期 - NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 数据的最后修改日期 - DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," +// 数据的内容 - DataColumns.DATA1 + " INTEGER," +// 数据的附加信息1 - DataColumns.DATA2 + " INTEGER," +// 数据的附加信息2 - DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +// 数据的附加信息3 - DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +// 数据的附加信息4 - DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +// 数据的附加信息5 - ")"; - - /* - * 创建一个名为 note_id_index 的索引,在 TABLE.DATA 表格的 DataColumns.NOTE_ID 列上创建索引,以提高查询性能 - */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - /* - * 创建一个名为 note_id_index 的索引,在 TABLE.DATA 表格的 DataColumns.NOTE_ID 列上创建索引,以提高查询性能 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String CREATE_DATA_NOTE_ID_INDEX_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 - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在更新 TABLE.NOTE 表格的 NoteColumns.PARENT_ID 列时,增加相应文件夹的便签计数 - * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其加1 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - 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 " + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + - " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + - " END"; - - /** - * Decrease folder's note count when move note from folder - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在更新 TABLE.NOTE 表格的 NoteColumns.PARENT_ID 列时,减少相应文件夹的便签计数 - * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其减1 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - 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 " + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + - " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + - " AND " + NoteColumns.NOTES_COUNT + ">0" + ";" + - " END"; - - /** - * Increase folder's note count when insert new note to the folder - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在向 TABLE.NOTE 表格插入新便签时,增加相应文件夹的便签计数 - * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其加1 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = - "CREATE TRIGGER increase_folder_count_on_insert " + - " AFTER INSERT ON " + TABLE.NOTE + - " BEGIN " + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + - " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + - " END"; - - /** - * Decrease folder's note count when delete note from the folder - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在从 TABLE.NOTE 表格删除便签时,减少相应文件夹的便签计数 - * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其减1 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = - "CREATE TRIGGER decrease_folder_count_on_delete " + - " AFTER DELETE ON " + TABLE.NOTE + - " BEGIN " + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + - " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + - " AND " + NoteColumns.NOTES_COUNT + ">0;" + - " END"; - - /** - * Update note's content when insert data with type {@link DataConstants#NOTE} - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在向 TABLE.DATA 表格插入类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 - * 通过更新 TABLE.NOTE 表格中的 NoteColumns.SNIPPET 列,将其设置为新插入数据的内容 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = - "CREATE TRIGGER update_note_content_on_insert " + - " AFTER INSERT ON " + TABLE.DATA + - " WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + - " BEGIN" + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + - " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + - " END"; - - /** - * Update note's content when data with {@link DataConstants#NOTE} type has changed - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在更新类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 - * 通过触发器在 TABLE.DATA 表格上创建,在数据被更新后将新的内容更新到对应的便签中 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = - "CREATE TRIGGER update_note_content_on_update " + - " AFTER UPDATE ON " + TABLE.DATA + - " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + - " BEGIN" + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + - " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + - " END"; - - /** - * Update note's content when data with {@link DataConstants#NOTE} type has deleted - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在删除类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 - * 通过触发器在 TABLE.DATA 表格上创建,在数据被删除后将对应的便签内容清空 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = - "CREATE TRIGGER update_note_content_on_delete " + - " AFTER delete ON " + TABLE.DATA + - " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + - " BEGIN" + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.SNIPPET + "=''" + - " WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" + - " END"; - - /** - * Delete datas belong to note which has been deleted - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在删除便签时,同时删除该便签相关的数据 - * 通过触发器在 TABLE.NOTE 表格上创建,在便签被删除后将与该便签相关的数据一并删除 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = - "CREATE TRIGGER delete_data_on_delete " + - " AFTER DELETE ON " + TABLE.NOTE + - " BEGIN" + - " DELETE FROM " + TABLE.DATA + - " WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" + - " END"; - - /** - * Delete notes belong to folder which has been deleted - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在删除文件夹时,同时删除该文件夹下的所有便签 - * 通过触发器在 TABLE.NOTE 表格上创建,在文件夹被删除后将该文件夹下的所有便签一并删除。 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = - "CREATE TRIGGER folder_delete_notes_on_delete " + - " AFTER DELETE ON " + TABLE.NOTE + - " BEGIN" + - " DELETE FROM " + TABLE.NOTE + - " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + - " END"; - - /** - * Move notes belong to folder which has been moved to trash folder - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - - /* - * 在将文件夹移动到回收站时,同时将该文件夹下的所有便签一并移动到回收站 - * 通过触发器在 TABLE.NOTE 表格上创建,在文件夹被移动到回收站后将该文件夹下的所有便签的父文件夹ID更新为回收站的ID - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = - "CREATE TRIGGER folder_move_notes_on_trash " + - " AFTER UPDATE ON " + TABLE.NOTE + - " WHEN new." + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + - " BEGIN" + - " UPDATE " + TABLE.NOTE + - " SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + - " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + - " END"; - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 构造函数,传入数据库的名称和版本 - */ ->>>>>>> liuyitao-branch -======= - /* - * 构造函数,传入数据库的名称和版本 - */ ->>>>>>> liuyitao-branch -======= - /* - * 构造函数,传入数据库的名称和版本 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public NotesDatabaseHelper(Context context) { - super(context, DB_NAME, null, DB_VERSION); - } - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 用于创建存储标签属性的表格 - */ ->>>>>>> liuyitao-branch -======= - /* - * 用于创建存储标签属性的表格 - */ ->>>>>>> liuyitao-branch -======= - /* - * 用于创建存储标签属性的表格 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public void createNoteTable(SQLiteDatabase db) { - db.execSQL(CREATE_NOTE_TABLE_SQL); - reCreateNoteTableTriggers(db); - createSystemFolder(db); - Log.d(TAG, "note table has been created"); - } - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - private void reCreateNoteTableTriggers(SQLiteDatabase db) { -======= -======= ->>>>>>> liuyitao-branch - /* - * 用于重新创建数据库中的触发器 - */ - private void reCreateNoteTableTriggers(SQLiteDatabase db) { - // 通过执行SQL语句DROP TRIGGER IF EXISTS来删除已存在的触发器,以确保不会重复创建 -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - /* - * 用于重新创建数据库中的触发器 - */ - private void reCreateNoteTableTriggers(SQLiteDatabase db) { - // 通过执行SQL语句DROP TRIGGER IF EXISTS来删除已存在的触发器,以确保不会重复创建 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - 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"); - db.execSQL("DROP TRIGGER IF EXISTS delete_data_on_delete"); - db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_insert"); - db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete"); - db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash"); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - - db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER); - db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER); - db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER); - db.execSQL(NOTE_DELETE_DATA_ON_DELETE_TRIGGER); - db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER); - db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER); - db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER); - } - -======= -======= ->>>>>>> liuyitao-branch - // 创建新的触发器 - db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 增加文件夹计数的触发器 - db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 减少文件夹计数的触发器 - db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER);// 删除文件夹计数的触发器 - db.execSQL(NOTE_DELETE_DATA_ON_DELETE_TRIGGER);// 在删除时同时删除数据的触发器 - db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER);// 增加文件夹计数的触发器 - db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER);// 在删除时同时删除文件夹中的笔记的触发器 - db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);// 将笔记移动到垃圾箱的触发器 - } - - /* - *用于创建系统文件夹,插入四个不同类型的文件夹记录到 NoteColumns 表中 - */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - // 创建新的触发器 - db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 增加文件夹计数的触发器 - db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 减少文件夹计数的触发器 - db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER);// 删除文件夹计数的触发器 - db.execSQL(NOTE_DELETE_DATA_ON_DELETE_TRIGGER);// 在删除时同时删除数据的触发器 - db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER);// 增加文件夹计数的触发器 - db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER);// 在删除时同时删除文件夹中的笔记的触发器 - db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);// 将笔记移动到垃圾箱的触发器 - } - - /* - *用于创建系统文件夹,插入四个不同类型的文件夹记录到 NoteColumns 表中 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private void createSystemFolder(SQLiteDatabase db) { - ContentValues values = new ContentValues(); - - /** - * call record foler for call notes - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 创建通话记录文件夹 - */ ->>>>>>> liuyitao-branch -======= - /* - * 创建通话记录文件夹 - */ ->>>>>>> liuyitao-branch -======= - /* - * 创建通话记录文件夹 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - 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 - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 根目录,即默认文件夹 - */ ->>>>>>> liuyitao-branch -======= - /* - * 根目录,即默认文件夹 - */ ->>>>>>> liuyitao-branch -======= - /* - * 根目录,即默认文件夹 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - values.clear(); - values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER); - values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); - db.insert(TABLE.NOTE, null, values); - - /** - * temporary folder which is used for moving note - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 临时目录,用于移动笔记 - */ ->>>>>>> liuyitao-branch -======= - /* - * 临时目录,用于移动笔记 - */ ->>>>>>> liuyitao-branch -======= - /* - * 临时目录,用于移动笔记 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - values.clear(); - values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER); - values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); - db.insert(TABLE.NOTE, null, values); - - /** - * create trash folder - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 创建垃圾箱 - */ ->>>>>>> liuyitao-branch -======= - /* - * 创建垃圾箱 - */ ->>>>>>> liuyitao-branch -======= - /* - * 创建垃圾箱 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - values.clear(); - values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); - values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); - db.insert(TABLE.NOTE, null, values); - } - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 用于创建存储标签内容的表格 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public void createDataTable(SQLiteDatabase db) { - db.execSQL(CREATE_DATA_TABLE_SQL);// 执行 CREATE_DATA_TABLE_SQL 的 SQL 语句来创建数据表 - reCreateDataTableTriggers(db);// 调用 reCreateDataTableTriggers() 方法重新创建数据表中的触发器 - db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);// 执行 CREATE_DATA_NOTE_ID_INDEX_SQL 的 SQL 语句来创建一个索引 - Log.d(TAG, "data table has been created"); - } - -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch - /* - * 用于创建存储标签内容的表格 - */ - public void createDataTable(SQLiteDatabase db) { - db.execSQL(CREATE_DATA_TABLE_SQL);// 执行 CREATE_DATA_TABLE_SQL 的 SQL 语句来创建数据表 - reCreateDataTableTriggers(db);// 调用 reCreateDataTableTriggers() 方法重新创建数据表中的触发器 - db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);// 执行 CREATE_DATA_NOTE_ID_INDEX_SQL 的 SQL 语句来创建一个索引 - Log.d(TAG, "data table has been created"); - } - - /* - * 用于重新创建数据表中的触发器 - */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - /* - * 用于重新创建数据表中的触发器 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - 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); - } - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - /* - * 用于获取单例的数据库帮助类对象 - * 解决同一时刻只能有一个线程执行. - * 在写程序库代码时,有时有一个类需要被所的其它类使用 - * 但又要求这个类只能被实例化一次,是个服务类,定义一次,其它类使用同一个这个类的实例 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - static synchronized NotesDatabaseHelper getInstance(Context context) { - if (mInstance == null) { - mInstance = new NotesDatabaseHelper(context); - } - return mInstance; - } - - @Override -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 在数据库第一次创建时被调用,用于创建所需的表格和触发器 - */ ->>>>>>> liuyitao-branch -======= - /* - * 在数据库第一次创建时被调用,用于创建所需的表格和触发器 - */ ->>>>>>> liuyitao-branch -======= - /* - * 在数据库第一次创建时被调用,用于创建所需的表格和触发器 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public void onCreate(SQLiteDatabase db) { - createNoteTable(db); - createDataTable(db); - } - - @Override -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - boolean reCreateTriggers = false; - boolean skipV2 = false; - -======= -======= ->>>>>>> liuyitao-branch - /* - * 根据旧版本和新版本之间的差异来执行相应的数据库升级操作 - */ - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - boolean reCreateTriggers = false; -======= - /* - * 根据旧版本和新版本之间的差异来执行相应的数据库升级操作 - */ - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - boolean reCreateTriggers = false; ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - boolean skipV2 = false;// 是否进行V2升级 - /* - * 如果旧版本为1,则调用upgradeToV2方法 - */ -<<<<<<< HEAD -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - if (oldVersion == 1) { - upgradeToV2(db); - skipV2 = true; // this upgrade including the upgrade from v2 to v3 - oldVersion++; - } -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - -======= - /* - * 如果旧版本为2且未跳过V2升级,则调用upgradeToV3方法 - */ ->>>>>>> liuyitao-branch -======= - /* - * 如果旧版本为2且未跳过V2升级,则调用upgradeToV3方法 - */ ->>>>>>> liuyitao-branch -======= - /* - * 如果旧版本为2且未跳过V2升级,则调用upgradeToV3方法 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - if (oldVersion == 2 && !skipV2) { - upgradeToV3(db); - reCreateTriggers = true; - oldVersion++; - } -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - -======= - /* - * 如果旧版本为3,则调用upgradeToV4方法 - */ ->>>>>>> liuyitao-branch -======= - /* - * 如果旧版本为3,则调用upgradeToV4方法 - */ ->>>>>>> liuyitao-branch -======= - /* - * 如果旧版本为3,则调用upgradeToV4方法 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - if (oldVersion == 3) { - upgradeToV4(db); - oldVersion++; - } -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - -======= - /* - * 如果需要重新创建触发器,则调用reCreateNoteTableTriggers和reCreateDataTableTriggers方法重新创建触发器 - */ ->>>>>>> liuyitao-branch -======= - /* - * 如果需要重新创建触发器,则调用reCreateNoteTableTriggers和reCreateDataTableTriggers方法重新创建触发器 - */ ->>>>>>> liuyitao-branch -======= - /* - * 如果需要重新创建触发器,则调用reCreateNoteTableTriggers和reCreateDataTableTriggers方法重新创建触发器 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - if (reCreateTriggers) { - reCreateNoteTableTriggers(db); - reCreateDataTableTriggers(db); - } -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - -======= - /* - * 如果旧版本和新版本不匹配,则抛出异常 - */ ->>>>>>> liuyitao-branch -======= - /* - * 如果旧版本和新版本不匹配,则抛出异常 - */ ->>>>>>> liuyitao-branch -======= - /* - * 如果旧版本和新版本不匹配,则抛出异常 - */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - if (oldVersion != newVersion) { - throw new IllegalStateException("Upgrade notes database to version " + newVersion - + "fails"); - } - } - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 更新到V2版本 - * */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private void upgradeToV2(SQLiteDatabase db) { - /* - * 通过执行SQL语句DROP TABLE IF EXISTS来删除旧的NOTE和DATA表格 - * */ - db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); - db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); - createNoteTable(db);// 调用createNoteTable和createDataTable方法来创建新的NOTE表格 - createDataTable(db);// 调用createNoteTable和createDataTable方法来创建新的DATA表格 - } - - /* - * 更新到V3版本 - * */ - private void upgradeToV3(SQLiteDatabase db) { -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch - /* - * 更新到V2版本 - * */ - private void upgradeToV2(SQLiteDatabase db) { - /* - * 通过执行SQL语句DROP TABLE IF EXISTS来删除旧的NOTE和DATA表格 - * */ - db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); - db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); - createNoteTable(db);// 调用createNoteTable和createDataTable方法来创建新的NOTE表格 - createDataTable(db);// 调用createNoteTable和createDataTable方法来创建新的DATA表格 - } - - /* - * 更新到V3版本 - * */ - private void upgradeToV3(SQLiteDatabase db) { - /* - * 执行SQL语句DROP TRIGGER IF EXISTS来移除不再使用的触发器 - * */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - /* - * 执行SQL语句DROP TRIGGER IF EXISTS来移除不再使用的触发器 - * */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - // 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"); - db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update"); -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - // add a column for gtask id - db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID - + " TEXT NOT NULL DEFAULT ''"); -======= -======= ->>>>>>> liuyitao-branch - /* - * 执行ALTER TABLE语句向NOTE表格中添加一个新的列GTASK_ID,该列的类型是TEXT,并设置默认值为'' - * */ - // add a column for gtask id - db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID - + " TEXT NOT NULL DEFAULT ''"); - /* - * 通过ContentValues对象向NOTE表格中插入一条记录,该记录代表垃圾箱系统文件夹 - * */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - /* - * 执行ALTER TABLE语句向NOTE表格中添加一个新的列GTASK_ID,该列的类型是TEXT,并设置默认值为'' - * */ - // add a column for gtask id - db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID - + " TEXT NOT NULL DEFAULT ''"); - /* - * 通过ContentValues对象向NOTE表格中插入一条记录,该记录代表垃圾箱系统文件夹 - * */ ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - // add a trash system folder - ContentValues values = new ContentValues(); - values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); - values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); - db.insert(TABLE.NOTE, null, values); - } - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - private void upgradeToV4(SQLiteDatabase db) { - db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION - + " INTEGER NOT NULL DEFAULT 0"); -======= -======= ->>>>>>> liuyitao-branch - /* - * 更新到V4版本 - * */ - private void upgradeToV4(SQLiteDatabase db) { - db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION - + " INTEGER NOT NULL DEFAULT 0");// 通过执行ALTER TABLE语句向NOTE表格中添加一个新的列VERSION,该列的类型是INTEGER,并设置默认值为0 -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - /* - * 更新到V4版本 - * */ - private void upgradeToV4(SQLiteDatabase db) { - db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION - + " INTEGER NOT NULL DEFAULT 0");// 通过执行ALTER TABLE语句向NOTE表格中添加一个新的列VERSION,该列的类型是INTEGER,并设置默认值为0 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - } -} diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java deleted file mode 100644 index 4ba9973..0000000 --- a/src/Notes-master/app/src/main/java/net/micode/notes/data/NotesProvider.java +++ /dev/null @@ -1,723 +0,0 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.micode.notes.data; - - -import android.app.SearchManager; -import android.content.ContentProvider; -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.Intent; -import android.content.UriMatcher; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.net.Uri; -import android.text.TextUtils; -import android.util.Log; - -import net.micode.notes.R; -import net.micode.notes.data.Notes.DataColumns; -import net.micode.notes.data.Notes.NoteColumns; -import net.micode.notes.data.NotesDatabaseHelper.TABLE; - -<<<<<<< HEAD -<<<<<<< HEAD - -//为存储和获取数据提供接口。可以在不同的应用程序之间共享数据 -//ContentProvider提供的方法 -//query:查询 -//insert:插入 -//update:更新 -//delete:删除 -//getType:得到数据类型 -public class NotesProvider extends ContentProvider { - // UriMatcher用于匹配Uri - private static final UriMatcher mMatcher; - - private NotesDatabaseHelper mHelper; - - private static final String TAG = "NotesProvider"; - - private static final int URI_NOTE = 1; -======= -======= ->>>>>>> liuyitao-branch -/* -* 功能描述:用于提供对便签数据的存储和获取功能,实现了创建、读取、更新、删除操作,以便其他组件可以通过 ContentResolver 访问和管理便签数据。 -* */ -public class NotesProvider extends ContentProvider { - private static final UriMatcher mMatcher;// UriMatcher用于匹配Uri - - private NotesDatabaseHelper mHelper;// 数据库帮助类 - - private static final String TAG = "NotesProvider";// 标签 - - private static final int URI_NOTE = 1;// Uri匹配码 -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch - private static final int URI_NOTE_ITEM = 2; - private static final int URI_DATA = 3; - private static final int URI_DATA_ITEM = 4; - - private static final int URI_SEARCH = 5; - private static final int URI_SEARCH_SUGGEST = 6; - - static { -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - // 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - mMatcher = new UriMatcher(UriMatcher.NO_MATCH); - // 把需要匹配Uri路径全部给注册上 - mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE); - mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM); - mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA); - mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM); - mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH); - mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST); - mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST); -======= -======= ->>>>>>> liuyitao-branch - mMatcher = new UriMatcher(UriMatcher.NO_MATCH);// 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码 - /* - * 把需要匹配Uri路径全部给注册上 - * */ - mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);// 便签列表的路径 - mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);// 便签详情的路径,其中 "#" 表示数字,表示具体的便签 ID - mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);// 数据列表的路径 - mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);// 数据详情的路径,其中 "#" 表示数字,表示具体的数据 ID - mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH);// 搜索的路径 - mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST);// 搜索建议的路径 - mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST);// 带搜索关键字的搜索建议的路径 -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch - } - - /** - * x'0A' represents the '\n' character in sqlite. For title and content in the search result, - * we will trim '\n' and white space in order to show more information. - */ -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch - - /* - * 查询搜索结果的投影。该投影包含了搜索结果需要的各个字段,如便签的 ID、搜索文本等 - * */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - - // 声明 NOTES_SEARCH_PROJECTION ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + "," - + NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + "," - + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + "," - + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + "," - + R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + "," - + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + "," - + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA; - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - * 查询语句,用于查询搜索结果 - * */ ->>>>>>> liuyitao-branch -======= - /* - * 查询语句,用于查询搜索结果 - * */ ->>>>>>> liuyitao-branch -======= - // 声明NOTES_SNIPPET_SEARCH_QUERY ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION - + " FROM " + TABLE.NOTE - + " WHERE " + NoteColumns.SNIPPET + " LIKE ?" - + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER - + " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE; - - @Override -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - /* - *在onCreate()中初始化Context,实例化mHelper - * */ ->>>>>>> liuyitao-branch -======= - /* - *在onCreate()中初始化Context,实例化mHelper - * */ ->>>>>>> liuyitao-branch -======= - // Context只有在onCreate()中才被初始化 - // 对mHelper进行实例化 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public boolean onCreate() { - mHelper = NotesDatabaseHelper.getInstance(getContext()); - return true; - } - - @Override -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - // 查询uri在数据库中对应的位置 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, - String sortOrder) { - Cursor c = null; - // 获取可读数据库 - SQLiteDatabase db = mHelper.getReadableDatabase(); - String id = null; - // 匹配查找uri - switch (mMatcher.match(uri)) { - // 对于不同的匹配值,在数据库中查找相应的条目 - case URI_NOTE: - c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null, - sortOrder); - break; - case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1); - c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id - + parseSelection(selection), selectionArgs, null, null, sortOrder); - break; - case URI_DATA: - c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null, - sortOrder); - break; - case URI_DATA_ITEM: - id = uri.getPathSegments().get(1); - c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id - + parseSelection(selection), selectionArgs, null, null, sortOrder); -======= -======= ->>>>>>> liuyitao-branch - /* - * 根据传入的Uri进行数据库查询操作 - * */ - public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, - String sortOrder) { - Cursor c = null;// 定义一个Cursor对象用于存放查询结果 - SQLiteDatabase db = mHelper.getReadableDatabase();// 获取可读数据库实例 - String id = null;// 用于存放ID值 - /* - * 根据Uri使用Matcher匹配相应的操作,对于不同的匹配值,在数据库中查找相应的条目 - * */ - switch (mMatcher.match(uri)) { - case URI_NOTE: - c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null, - sortOrder);// 查询便签列表 - break; - case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1);// 获取Uri中的ID值 - c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id - + parseSelection(selection), selectionArgs, null, null, sortOrder);// 查询特定ID的便签详情 - break; - case URI_DATA: - c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null, - sortOrder);// 查询数据列表 - break; - case URI_DATA_ITEM: - id = uri.getPathSegments().get(1); // 获取Uri中的ID值 - c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id - + parseSelection(selection), selectionArgs, null, null, sortOrder);// 查询特定ID的数据详情 -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch - break; - case URI_SEARCH: - case URI_SEARCH_SUGGEST: - if (sortOrder != null || projection != null) { - // 不合法的参数异常 - throw new IllegalArgumentException( -<<<<<<< HEAD -<<<<<<< HEAD - "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query"); -======= - "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");// 如果存在不合法的参数则抛出异常 ->>>>>>> liuyitao-branch -======= - "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");// 如果存在不合法的参数则抛出异常 ->>>>>>> liuyitao-branch - } - - String searchString = null; - if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) { - if (uri.getPathSegments().size() > 1) { -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - // getPathSegments()方法得到一个String的List, - // 在uri.getPathSegments().get(1)为第2个元素 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - searchString = uri.getPathSegments().get(1); - } - } else { - searchString = uri.getQueryParameter("pattern"); - } - - if (TextUtils.isEmpty(searchString)) { - return null; - } - - try { - searchString = String.format("%%%s%%", searchString); - c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY, - new String[] { searchString }); - } catch (IllegalStateException ex) { - Log.e(TAG, "got exception: " + ex.toString()); - } - break; - default: - // 抛出异常 - throw new IllegalArgumentException("Unknown URI " + uri); - } - if (c != null) { - c.setNotificationUri(getContext().getContentResolver(), uri); - } - return c; - } - - @Override - // 插入一个uri - public Uri insert(Uri uri, ContentValues values) { - // 获得可写的数据库 - SQLiteDatabase db = mHelper.getWritableDatabase(); - long dataId = 0, noteId = 0, insertedId = 0; - switch (mMatcher.match(uri)) { - // 新增一个条目 - case URI_NOTE: - insertedId = noteId = db.insert(TABLE.NOTE, null, values); - break; - // 如果存在,查找NOTE_ID - case URI_DATA: - if (values.containsKey(DataColumns.NOTE_ID)) { - noteId = values.getAsLong(DataColumns.NOTE_ID); - } else { - Log.d(TAG, "Wrong data format without note id:" + values.toString()); - } - insertedId = dataId = db.insert(TABLE.DATA, null, values); - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - // Notify the note uri - // notifyChange获得一个ContextResolver对象并且更新里面的内容 - if (noteId > 0) { - getContext().getContentResolver().notifyChange( - ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); - } - - // Notify the data uri - if (dataId > 0) { - getContext().getContentResolver().notifyChange( - ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null); - } - - // 返回插入的uri的路径 - return ContentUris.withAppendedId(uri, insertedId); - } - - @Override - // 删除一个uri - public int delete(Uri uri, String selection, String[] selectionArgs) { - //Uri代表要操作的数据,Android上可用的每种资源 -包括 图像、视频片段、音频资源等都可以用Uri来表示 - int count = 0; - String id = null; - // 获得可写的数据库 - SQLiteDatabase db = mHelper.getWritableDatabase(); - boolean deleteData = false; - switch (mMatcher.match(uri)) { - case URI_NOTE: - selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 "; - count = db.delete(TABLE.NOTE, selection, selectionArgs); - break; - case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1); -======= -======= ->>>>>>> liuyitao-branch - searchString = uri.getPathSegments().get(1); // 获取搜索关键字 - } - } else { - searchString = uri.getQueryParameter("pattern"); // 获取搜索关键字 - } - - if (TextUtils.isEmpty(searchString)) { - return null;// 如果搜索关键字为空则直接返回null - } - - try { - searchString = String.format("%%%s%%", searchString);// 格式化搜索关键字 - c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY, - new String[] { searchString });// 执行搜索查询 - } catch (IllegalStateException ex) { - Log.e(TAG, "got exception: " + ex.toString());// 捕获异常 - } - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 - } - if (c != null) { - c.setNotificationUri(getContext().getContentResolver(), uri);// 设置查询结果的变更通知URI - } - return c;// 返回查询结果的Cursor对象 - } - - @Override - /* - * 功能描述:实现对数据库表单的增加记录操作 - * 输入参数:参数 uri 表示插入的 URI,values 表示插入的值 - * */ - public Uri insert(Uri uri, ContentValues values) { - SQLiteDatabase db = mHelper.getWritableDatabase();// 获得可写的数据库 - long dataId = 0, noteId = 0, insertedId = 0;// 定义三个id值变量 - /* - * 根据Uri使用Matcher匹配相应的操作 - * */ - switch (mMatcher.match(uri)) { - case URI_NOTE: - insertedId = noteId = db.insert(TABLE.NOTE, null, values);// 在便签表中插入新记录 - break; - case URI_DATA: - if (values.containsKey(DataColumns.NOTE_ID)) { - noteId = values.getAsLong(DataColumns.NOTE_ID);// 如果数据内容包含NOTE_ID字段,获取NOTE_ID值 - } else { - Log.d(TAG, "Wrong data format without note id:" + values.toString());// 如果不包含则输出日志信息 - } - insertedId = dataId = db.insert(TABLE.DATA, null, values);// 在数据表中插入新记录 - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 - } - // Notify the note uri - if (noteId > 0) {// 如果是便签新增操作 - getContext().getContentResolver().notifyChange( - ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);// 通过ContentResolver对象发送通知,更新便签的变更通知URI - } - - // Notify the data uri - if (dataId > 0) {// 如果是数据新增操作 - getContext().getContentResolver().notifyChange( - ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);// 通过ContentResolver对象发送通知,更新数据的变更通知URI - } - - return ContentUris.withAppendedId(uri, insertedId);// 返回插入的uri的路径 - } - - @Override - /* - * 功能描述:实现对数据库表单的删除记录操作 - * 输入参数:参数 uri 表示删除的 URI,selection 表示删除条件,selectionArgs 表示删除条件值 - * */ - public int delete(Uri uri, String selection, String[] selectionArgs) { - //Uri代表要操作的数据,Android上可用的每种资源 -包括 图像、视频片段、音频资源等都可以用Uri来表示 - int count = 0;// 定义计数变量 - String id = null;// 定义id字符串变量 - SQLiteDatabase db = mHelper.getWritableDatabase();// 获取可写数据库实例 - boolean deleteData = false;// 是否删除数据标志位 - /* - * 根据Uri使用Matcher匹配相应的操作 - * */ - switch (mMatcher.match(uri)) { - case URI_NOTE: - selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";// 对于便签的删除操作,添加额外的条件限制 - count = db.delete(TABLE.NOTE, selection, selectionArgs);// 在便签表中删除符合条件的记录 - break; - case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch - /** - * ID that smaller than 0 is system folder which is not allowed to - * trash - */ - long noteId = Long.valueOf(id); -<<<<<<< HEAD -<<<<<<< HEAD - if (noteId <= 0) { - break; - } - count = db.delete(TABLE.NOTE, - NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs); - break; - case URI_DATA: - count = db.delete(TABLE.DATA, selection, selectionArgs); - deleteData = true; - break; - case URI_DATA_ITEM: - id = uri.getPathSegments().get(1); - count = db.delete(TABLE.DATA, - DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs); - deleteData = true; - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - if (count > 0) { - if (deleteData) { - getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); - } - getContext().getContentResolver().notifyChange(uri, null); - } - return count; - } - - @Override - // 更新一个uri - public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { - int count = 0; - String id = null; - SQLiteDatabase db = mHelper.getWritableDatabase(); - boolean updateData = false; - switch (mMatcher.match(uri)) { - case URI_NOTE: - increaseNoteVersion(-1, selection, selectionArgs); - count = db.update(TABLE.NOTE, values, selection, selectionArgs); - break; - case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1); - increaseNoteVersion(Long.valueOf(id), selection, selectionArgs); - count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id - + parseSelection(selection), selectionArgs); - break; - case URI_DATA: - count = db.update(TABLE.DATA, values, selection, selectionArgs); - updateData = true; - break; - case URI_DATA_ITEM: - id = uri.getPathSegments().get(1); - count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id - + parseSelection(selection), selectionArgs); - updateData = true; - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri); - } - - if (count > 0) { - if (updateData) { - getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); - } - getContext().getContentResolver().notifyChange(uri, null); - } - return count; - } - -<<<<<<< HEAD -======= -======= ->>>>>>> liuyitao-branch - if (noteId <= 0) {// 如果ID小于等于0,则不允许删除 - break; - } - count = db.delete(TABLE.NOTE, - NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);// 在便签表中删除指定ID的记录 - break; - case URI_DATA: - count = db.delete(TABLE.DATA, selection, selectionArgs);// 在数据表中删除符合条件的记录 - deleteData = true;// 设置删除数据标志位为true - break; - case URI_DATA_ITEM: - id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 - count = db.delete(TABLE.DATA, - DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);// 在数据表中删除指定ID的记录 - deleteData = true;// 设置删除数据标志位为true - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 - } - if (count > 0) {// 如果删除记录数大于0 - if (deleteData) { - getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);// 通过ContentResolver对象发送通知,更新便签变更通知URI - } - getContext().getContentResolver().notifyChange(uri, null);// 通过ContentResolver对象发送通知,更新变更通知URI - } - return count;// 返回删除的记录数 - } - - @Override - /* - * 功能描述:实现对数据库表单的更新操作 - * 输入参数:参数 uri 表示更新的 URI,values 表示更新的值,selection 表示更新条件,selectionArgs 表示更新条件值 - * */ - public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { - int count = 0;// 定义计数变量 - String id = null;// 定义id字符串变量 - SQLiteDatabase db = mHelper.getWritableDatabase();// 获取可写数据库实例 - boolean updateData = false;// 是否更新数据标志位 - /* - * 根据Uri使用Matcher匹配相应的操作 - * */ - switch (mMatcher.match(uri)) { - case URI_NOTE: - increaseNoteVersion(-1, selection, selectionArgs);// 增加便签版本号,针对便签的更新操作,添加额外的条件限制 - count = db.update(TABLE.NOTE, values, selection, selectionArgs);// 在便签表中更新符合条件的记录 - break; - case URI_NOTE_ITEM: - id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 - increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);// 增加便签版本号,针对便签的更新操作,添加额外的条件限制 - count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id - + parseSelection(selection), selectionArgs);// 在便签表中更新指定ID的记录 - break; - case URI_DATA: - count = db.update(TABLE.DATA, values, selection, selectionArgs);// 在数据表中更新符合条件的记录 - updateData = true;// 设置更新数据标志位为tru - break; - case URI_DATA_ITEM: - id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 - count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id - + parseSelection(selection), selectionArgs);// 在数据表中更新指定ID的记录 - updateData = true;// 设置更新数据标志位为true - break; - default: - throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 - } - - if (count > 0) {// 如果更新记录数大于0 - if (updateData) { - getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);// 通过ContentResolver对象发送通知,更新便签变更通知URI - } - getContext().getContentResolver().notifyChange(uri, null);// 通过ContentResolver对象发送通知,更新变更通知URI - } - return count;// 返回更新的记录数 - } - - /* - * 解析查询条件selection,如果selection不为空,则在其前面加上" AND ",用于拼接SQL语句 - * */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -======= - // 将字符串解析成规定格式 ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private String parseSelection(String selection) { - return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); - } - -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -======= - //增加一个noteVersion ->>>>>>> c984adcce551cff51ee11d737f171a1841d04f9b - private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { - StringBuilder sql = new StringBuilder(120); - sql.append("UPDATE "); - sql.append(TABLE.NOTE); - sql.append(" SET "); - sql.append(NoteColumns.VERSION); - sql.append("=" + NoteColumns.VERSION + "+1 "); - - if (id > 0 || !TextUtils.isEmpty(selection)) { - sql.append(" WHERE "); - } - if (id > 0) { - sql.append(NoteColumns.ID + "=" + String.valueOf(id)); - } - if (!TextUtils.isEmpty(selection)) { - String selectString = id > 0 ? parseSelection(selection) : selection; - for (String args : selectionArgs) { - selectString = selectString.replaceFirst("\\?", args); - } - sql.append(selectString); - } - - // execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句 - mHelper.getWritableDatabase().execSQL(sql.toString()); - } - - @Override -======= -======= ->>>>>>> liuyitao-branch - /* - * 根据传入的id和selection参数确定要更新的记录,并将版本号加1 - * */ - private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { - StringBuilder sql = new StringBuilder(120);// 创建一个StringBuilder对象,用于构建SQL语句 - sql.append("UPDATE ");// 构建UPDATE语句,指定要更新的表名 - sql.append(TABLE.NOTE);// 表名 - sql.append(" SET ");// 指定要更新的字段和新的值 - sql.append(NoteColumns.VERSION);// 字段名 - sql.append("=" + NoteColumns.VERSION + "+1 ");// 将版本号加1 - - if (id > 0 || !TextUtils.isEmpty(selection)) { - sql.append(" WHERE ");// 根据传入的参数决定是否添加WHERE子句 - } - if (id > 0) { - sql.append(NoteColumns.ID + "=" + String.valueOf(id)); // 如果传入的id大于0,则表示只更新指定id的记录 - } - if (!TextUtils.isEmpty(selection)) {// 如果传入的selection不为空,则根据它来确定要更新的记录 - String selectString = id > 0 ? parseSelection(selection) : selection;// 调用parseSelection方法将selection转换为SQL语句中的WHERE子句 - for (String args : selectionArgs) { - selectString = selectString.replaceFirst("\\?", args);// 替换WHERE子句中的问号占位符为实际的参数值 - } - sql.append(selectString);// 添加WHERE子句到SQL语句中 - } - - // execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句 - mHelper.getWritableDatabase().execSQL(sql.toString());// 添加WHERE子句到SQL语句中 - } - - @Override - /* - * 功能描述:用于根据 URI 返回相应的 MIME 类型 - * 输入参数:参数 uri 表示查询或操作的 URI - * 函数中是环境自动生成的,也可自己改写 - * */ -<<<<<<< HEAD ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch - public String getType(Uri uri) { - // TODO Auto-generated method stub - return null; - } -<<<<<<< HEAD -<<<<<<< HEAD - -======= ->>>>>>> liuyitao-branch -======= ->>>>>>> liuyitao-branch -} From a4e6a999cda38ba8e889b6df983ccc713736adfb Mon Sep 17 00:00:00 2001 From: liuyitao <2371837061@qq.com> Date: Wed, 27 Dec 2023 21:36:08 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Signed-off-by:=20liuyitao=20<2371837061@qq.?= =?UTF-8?q?com>=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../023468cfdd0b71d4098903b9070e364658e2fbcf | 21 + .../3aac5305cb73bfbdeb8078cd264d04323fa80e92 | 0 .../4529b3a97b0f3b19b895aa06f23bed63ff38a312 | 117 ++++ .../ab153b0256bc5f6c194e188cec0b8e327e347a90 | 43 ++ .../c182d0c9c237ea8a46a92ccaae9bb5c751923a88 | 0 .../f087b1ba1b9c91b7293fea0fb071eaed62a42137 | 27 + .../023468cfdd0b71d4098903b9070e364658e2fbcf | 0 .../3aac5305cb73bfbdeb8078cd264d04323fa80e92 | 0 .../4529b3a97b0f3b19b895aa06f23bed63ff38a312 | 0 .../ab153b0256bc5f6c194e188cec0b8e327e347a90 | 0 .../c182d0c9c237ea8a46a92ccaae9bb5c751923a88 | 0 .../f087b1ba1b9c91b7293fea0fb071eaed62a42137 | 0 .../net/micode/notes/data/data/Contact.java | 92 ++++ .../net/micode/notes/data/data/Notes.java | 310 +++++++++++ .../notes/data/data/NotesDatabaseHelper.java | 506 ++++++++++++++++++ .../micode/notes/data/data/NotesProvider.java | 359 +++++++++++++ 16 files changed, 1475 insertions(+) create mode 100644 src/Notes-master/.idea/sonarlint/issuestore/0/2/023468cfdd0b71d4098903b9070e364658e2fbcf create mode 100644 src/Notes-master/.idea/sonarlint/issuestore/3/a/3aac5305cb73bfbdeb8078cd264d04323fa80e92 create mode 100644 src/Notes-master/.idea/sonarlint/issuestore/4/5/4529b3a97b0f3b19b895aa06f23bed63ff38a312 create mode 100644 src/Notes-master/.idea/sonarlint/issuestore/a/b/ab153b0256bc5f6c194e188cec0b8e327e347a90 create mode 100644 src/Notes-master/.idea/sonarlint/issuestore/c/1/c182d0c9c237ea8a46a92ccaae9bb5c751923a88 create mode 100644 src/Notes-master/.idea/sonarlint/issuestore/f/0/f087b1ba1b9c91b7293fea0fb071eaed62a42137 create mode 100644 src/Notes-master/.idea/sonarlint/securityhotspotstore/0/2/023468cfdd0b71d4098903b9070e364658e2fbcf create mode 100644 src/Notes-master/.idea/sonarlint/securityhotspotstore/3/a/3aac5305cb73bfbdeb8078cd264d04323fa80e92 create mode 100644 src/Notes-master/.idea/sonarlint/securityhotspotstore/4/5/4529b3a97b0f3b19b895aa06f23bed63ff38a312 create mode 100644 src/Notes-master/.idea/sonarlint/securityhotspotstore/a/b/ab153b0256bc5f6c194e188cec0b8e327e347a90 create mode 100644 src/Notes-master/.idea/sonarlint/securityhotspotstore/c/1/c182d0c9c237ea8a46a92ccaae9bb5c751923a88 create mode 100644 src/Notes-master/.idea/sonarlint/securityhotspotstore/f/0/f087b1ba1b9c91b7293fea0fb071eaed62a42137 create mode 100644 src/Notes-master/app/src/main/java/net/micode/notes/data/data/Contact.java create mode 100644 src/Notes-master/app/src/main/java/net/micode/notes/data/data/Notes.java create mode 100644 src/Notes-master/app/src/main/java/net/micode/notes/data/data/NotesDatabaseHelper.java create mode 100644 src/Notes-master/app/src/main/java/net/micode/notes/data/data/NotesProvider.java diff --git a/src/Notes-master/.idea/sonarlint/issuestore/0/2/023468cfdd0b71d4098903b9070e364658e2fbcf b/src/Notes-master/.idea/sonarlint/issuestore/0/2/023468cfdd0b71d4098903b9070e364658e2fbcf new file mode 100644 index 0000000..fb72d00 --- /dev/null +++ b/src/Notes-master/.idea/sonarlint/issuestore/0/2/023468cfdd0b71d4098903b9070e364658e2fbcf @@ -0,0 +1,21 @@ + +> +java:S1604t"(Make this anonymous inner class a lambda(î +V java:S125"Type: INTEGER (long)
+ */ + public static final String ID = "_id";// 行的唯一标识符 + + /** + * The parent's id for note or folder + *Type: INTEGER (long)
+ */ + public static final String PARENT_ID = "parent_id";// 父级的ID + + /** + * Created data for note or folder + *Type: INTEGER (long)
+ */ + public static final String CREATED_DATE = "created_date";// 创建日期 + + /** + * Latest modified date + *Type: INTEGER (long)
+ */ + public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 + + + /** + * Alert date + *Type: INTEGER (long)
+ */ + public static final String ALERTED_DATE = "alert_date";// 提醒日期 + + /** + * Folder's name or text content of note + *Type: TEXT
+ */ + public static final String SNIPPET = "snippet";// 文件夹名称或便签的文本内容 + + /** + * Note's widget id + *Type: INTEGER (long)
+ */ + public static final String WIDGET_ID = "widget_id";// 便签的Widget ID + + /** + * Note's widget type + *Type: INTEGER (long)
+ */ + public static final String WIDGET_TYPE = "widget_type";// 便签的Widget类型 + + /** + * Note's background color's id + *Type: INTEGER (long)
+ */ + public static final String BG_COLOR_ID = "bg_color_id";// 便签的背景颜色ID + + /** + * For text note, it doesn't has attachment, for multi-media + * note, it has at least one attachment + *Type: INTEGER
+ */ + public static final String HAS_ATTACHMENT = "has_attachment";// 是否有附件 + + /** + * Folder's count of notes + *Type: INTEGER (long)
+ */ + public static final String NOTES_COUNT = "notes_count";// 文件夹中的便签数量 + + /** + * The file type: folder or note + *Type: INTEGER
+ */ + public static final String TYPE = "type";// 文件类型:文件夹或便签 + + /** + * The last sync id + *Type: INTEGER (long)
+ */ + public static final String SYNC_ID = "sync_id";// 最后同步的ID + + /** + * Sign to indicate local modified or not + *Type: INTEGER
+ */ + public static final String LOCAL_MODIFIED = "local_modified";// 标识是否本地修改 + + /** + * Original parent id before moving into temporary folder + *Type : INTEGER
+ */ + public static final String ORIGIN_PARENT_ID = "origin_parent_id";// 移动到临时文件夹之前的原始父级ID + + /** + * The gtask id + *Type : TEXT
+ */ + public static final String GTASK_ID = "gtask_id";// Google任务ID + + /** + * The version code + *Type : INTEGER (long)
+ */ + public static final String VERSION = "version";// 版本号 + } + + /* + * 功能描述:定义DataColumns接口数据的常量,用于创建数据库表头 + */ + public interface DataColumns { + /** + * The unique ID for a row + *Type: INTEGER (long)
+ */ + public static final String ID = "_id";// 标识符 + + /** + * The MIME type of the item represented by this row. + *Type: Text
+ */ + public static final String MIME_TYPE = "mime_type";// 数据的MIME类型 + + /** + * The reference id to note that this data belongs to + *Type: INTEGER (long)
+ */ + public static final String NOTE_ID = "note_id";// 数据ID + + /** + * Created data for note or folder + *Type: INTEGER (long)
+ */ + public static final String CREATED_DATE = "created_date";// 创建日期 + + /** + * Latest modified date + *Type: INTEGER (long)
+ */ + public static final String MODIFIED_DATE = "modified_date";// 最后修改日期 + + /** + * Data's content + *Type: TEXT
+ */ + public static final String CONTENT = "content";// 内容 + + + /** + * Generic data column, the meaning is {@link #MIMETYPE} specific, used for + * integer data type + *Type: INTEGER
+ */ + public static final String DATA1 = "data1";// 通用数据1 + + /** + * Generic data column, the meaning is {@link #MIMETYPE} specific, used for + * integer data type + *Type: INTEGER
+ */ + public static final String DATA2 = "data2";// 通用数据2 + + /** + * Generic data column, the meaning is {@link #MIMETYPE} specific, used for + * TEXT data type + *Type: TEXT
+ */ + public static final String DATA3 = "data3";// 通用数据3 + + /** + * Generic data column, the meaning is {@link #MIMETYPE} specific, used for + * TEXT data type + *Type: TEXT
+ */ + public static final String DATA4 = "data4";// 通用数据4 + + /** + * Generic data column, the meaning is {@link #MIMETYPE} specific, used for + * TEXT data type + *Type: TEXT
+ */ + public static final String DATA5 = "data5";// 通用数据5 + } + + /* + * 定义了文本便签的数据结构 + */ + public static final class TextNote implements DataColumns { + /** + * Mode to indicate the text in check list mode or not + *Type: Integer 1:check list mode 0: normal mode
+ */ + public static final String MODE = DATA1;// 模式 + + public static final int MODE_CHECK_LIST = 1;// 待办清单模式 + + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";// 内容类型 + + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";// 单个条目的内容类型 + + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");// 查询文本便签的URI + } + + /* + * 定义电话便签的数据结构 + */ + public static final class CallNote implements DataColumns { + /** + * Call date for this record + *Type: INTEGER (long)
+ */ + public static final String CALL_DATE = DATA1;// 通话日期 + + /** + * Phone number for this record + *Type: TEXT
+ */ + public static final String PHONE_NUMBER = DATA3;// 电话号码 + + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";// 内容类型 + + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";// 单个条目的内容类型 + + public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");// 查询电话便签的URI + } +} diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/data/NotesDatabaseHelper.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/data/NotesDatabaseHelper.java new file mode 100644 index 0000000..373201a --- /dev/null +++ b/src/Notes-master/app/src/main/java/net/micode/notes/data/data/NotesDatabaseHelper.java @@ -0,0 +1,506 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.micode.notes.data; + + +import android.content.ContentValues;//就是用于保存一些数据(string boolean byte double float int long short ...)信息,这些信息可以被数据库操作时使用。 +import android.content.Context;//加载和访问资源。(android中主要是这两个功能,但是这里具体不清楚) +import android.database.sqlite.SQLiteDatabase;//主要提供了对应于添加、删除、更新、查询的操作方法: insert()、delete()、update()和query()。配合content.values +import android.database.sqlite.SQLiteOpenHelper;//用来管理数据的创建和版本更新 +import android.util.Log; + + +import net.micode.notes.data.Notes.DataColumns; +import net.micode.notes.data.Notes.DataConstants; +import net.micode.notes.data.Notes.NoteColumns; +/* +* 功能描述:数据库操作,用SQLOpenhelper,对一些note和文件进行数据库的操作 +*/ + +public class NotesDatabaseHelper extends SQLiteOpenHelper { + private static final String DB_NAME = "note.db";// 数据库名 + + private static final int DB_VERSION = 4;// 版本号 + + public interface TABLE { + /* + * 接口,分成note和data,用于表示数据库中两种表格 + * */ + public static final String NOTE = "note"; + + public static final String DATA = "data"; + } + + private static final String TAG = "NotesDatabaseHelper";// 日志标签,用于在日志中标识数据库操作的相关信息 + + /* + * NotesDatabaseHelper 类的实例,用于单例模式的数据库操作,通过 getInstance() 方法获取 NotesDatabaseHelper 的唯一实例 + * 单例模式是一种设计模式,在数据库操作中使用单例模式可以确保只有一个数据库连接,避免了重复创建和关闭数据库连接可能导致的性能问题 + */ + private static NotesDatabaseHelper mInstance; + + /* + * 创建TABLE.NOTE表格,用于存储便签的相关信息 + */ + private static final String CREATE_NOTE_TABLE_SQL = + "CREATE TABLE " + TABLE.NOTE + "(" + + NoteColumns.ID + " INTEGER PRIMARY KEY," +// 便签ID + NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签父级的ID + NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," +// 便签的提醒日期 + NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," + // 便签的背景颜色ID + NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," + // 便签的创建日期 + NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," +// 便签是否有附件 + NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 便签的最后修改日期 + NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," +// 文件夹中的便签数量 + NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," +// 文件夹名称或便签的文本内容 + NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," +// 便签的类型 + NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签的Widget ID + NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," +// 便签的Widget类型 + NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," +// 便签的同步ID + NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +// 便签的本地修改标记 + NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +// 原始父级便签的ID + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +// 便签在Google任务中的ID + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +// 便签的版本号 + ")"; + + /* + * 创建TABLE.DATA表格,用于存储便签中的数据 + */ + private static final String CREATE_DATA_TABLE_SQL = + "CREATE TABLE " + TABLE.DATA + "(" + + DataColumns.ID + " INTEGER PRIMARY KEY," +// 数据ID + DataColumns.MIME_TYPE + " TEXT NOT NULL," +// 数据ID数据的MIME类型 + DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," +// 数据所属的便签的ID + NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 数据的创建日期 + NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +// 数据的最后修改日期 + DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," +// 数据的内容 + DataColumns.DATA1 + " INTEGER," +// 数据的附加信息1 + DataColumns.DATA2 + " INTEGER," +// 数据的附加信息2 + DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +// 数据的附加信息3 + DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +// 数据的附加信息4 + DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +// 数据的附加信息5 + ")"; + + /* + * 创建一个名为 note_id_index 的索引,在 TABLE.DATA 表格的 DataColumns.NOTE_ID 列上创建索引,以提高查询性能 + */ + private static final String CREATE_DATA_NOTE_ID_INDEX_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 + */ + + /* + * 在更新 TABLE.NOTE 表格的 NoteColumns.PARENT_ID 列时,增加相应文件夹的便签计数 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其加1 + */ + 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 " + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + + " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + + " END"; + + /** + * Decrease folder's note count when move note from folder + */ + + /* + * 在更新 TABLE.NOTE 表格的 NoteColumns.PARENT_ID 列时,减少相应文件夹的便签计数 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其减1 + */ + 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 " + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + + " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + + " AND " + NoteColumns.NOTES_COUNT + ">0" + ";" + + " END"; + + /** + * Increase folder's note count when insert new note to the folder + */ + + /* + * 在向 TABLE.NOTE 表格插入新便签时,增加相应文件夹的便签计数 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其加1 + */ + private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = + "CREATE TRIGGER increase_folder_count_on_insert " + + " AFTER INSERT ON " + TABLE.NOTE + + " BEGIN " + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" + + " WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" + + " END"; + + /** + * Decrease folder's note count when delete note from the folder + */ + + /* + * 在从 TABLE.NOTE 表格删除便签时,减少相应文件夹的便签计数 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.NOTES_COUNT 列,将其减1 + */ + private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = + "CREATE TRIGGER decrease_folder_count_on_delete " + + " AFTER DELETE ON " + TABLE.NOTE + + " BEGIN " + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" + + " WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID + + " AND " + NoteColumns.NOTES_COUNT + ">0;" + + " END"; + + /** + * Update note's content when insert data with type {@link DataConstants#NOTE} + */ + + /* + * 在向 TABLE.DATA 表格插入类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 + * 通过更新 TABLE.NOTE 表格中的 NoteColumns.SNIPPET 列,将其设置为新插入数据的内容 + */ + private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = + "CREATE TRIGGER update_note_content_on_insert " + + " AFTER INSERT ON " + TABLE.DATA + + " WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + + " BEGIN" + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + + " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + + " END"; + + /** + * Update note's content when data with {@link DataConstants#NOTE} type has changed + */ + + /* + * 在更新类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 + * 通过触发器在 TABLE.DATA 表格上创建,在数据被更新后将新的内容更新到对应的便签中 + */ + private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = + "CREATE TRIGGER update_note_content_on_update " + + " AFTER UPDATE ON " + TABLE.DATA + + " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + + " BEGIN" + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT + + " WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" + + " END"; + + /** + * Update note's content when data with {@link DataConstants#NOTE} type has deleted + */ + + /* + * 在删除类型为 DataConstants.NOTE 的数据时,更新对应便签的内容 + * 通过触发器在 TABLE.DATA 表格上创建,在数据被删除后将对应的便签内容清空 + */ + private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = + "CREATE TRIGGER update_note_content_on_delete " + + " AFTER delete ON " + TABLE.DATA + + " WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" + + " BEGIN" + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.SNIPPET + "=''" + + " WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" + + " END"; + + /** + * Delete datas belong to note which has been deleted + */ + + /* + * 在删除便签时,同时删除该便签相关的数据 + * 通过触发器在 TABLE.NOTE 表格上创建,在便签被删除后将与该便签相关的数据一并删除 + */ + private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = + "CREATE TRIGGER delete_data_on_delete " + + " AFTER DELETE ON " + TABLE.NOTE + + " BEGIN" + + " DELETE FROM " + TABLE.DATA + + " WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" + + " END"; + + /** + * Delete notes belong to folder which has been deleted + */ + + /* + * 在删除文件夹时,同时删除该文件夹下的所有便签 + * 通过触发器在 TABLE.NOTE 表格上创建,在文件夹被删除后将该文件夹下的所有便签一并删除。 + */ + private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = + "CREATE TRIGGER folder_delete_notes_on_delete " + + " AFTER DELETE ON " + TABLE.NOTE + + " BEGIN" + + " DELETE FROM " + TABLE.NOTE + + " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + + " END"; + + /** + * Move notes belong to folder which has been moved to trash folder + */ + + /* + * 在将文件夹移动到回收站时,同时将该文件夹下的所有便签一并移动到回收站 + * 通过触发器在 TABLE.NOTE 表格上创建,在文件夹被移动到回收站后将该文件夹下的所有便签的父文件夹ID更新为回收站的ID + */ + private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = + "CREATE TRIGGER folder_move_notes_on_trash " + + " AFTER UPDATE ON " + TABLE.NOTE + + " WHEN new." + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + + " BEGIN" + + " UPDATE " + TABLE.NOTE + + " SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER + + " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + + " END"; + + /* + * 构造函数,传入数据库的名称和版本 + */ + public NotesDatabaseHelper(Context context) { + super(context, DB_NAME, null, DB_VERSION); + } + + /* + * 用于创建存储标签属性的表格 + */ + public void createNoteTable(SQLiteDatabase db) { + db.execSQL(CREATE_NOTE_TABLE_SQL); + reCreateNoteTableTriggers(db); + createSystemFolder(db); + Log.d(TAG, "note table has been created"); + } + + /* + * 用于重新创建数据库中的触发器 + */ + private void reCreateNoteTableTriggers(SQLiteDatabase db) { + // 通过执行SQL语句DROP TRIGGER IF EXISTS来删除已存在的触发器,以确保不会重复创建 + 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"); + db.execSQL("DROP TRIGGER IF EXISTS delete_data_on_delete"); + db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_insert"); + db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete"); + db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash"); + // 创建新的触发器 + db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 增加文件夹计数的触发器 + db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);// 减少文件夹计数的触发器 + db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER);// 删除文件夹计数的触发器 + db.execSQL(NOTE_DELETE_DATA_ON_DELETE_TRIGGER);// 在删除时同时删除数据的触发器 + db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER);// 增加文件夹计数的触发器 + db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER);// 在删除时同时删除文件夹中的笔记的触发器 + db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);// 将笔记移动到垃圾箱的触发器 + } + + /* + *用于创建系统文件夹,插入四个不同类型的文件夹记录到 NoteColumns 表中 + */ + 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); + values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); + db.insert(TABLE.NOTE, null, values); + + /** + * temporary folder which is used for moving note + */ + /* + * 临时目录,用于移动笔记 + */ + values.clear(); + values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER); + values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); + db.insert(TABLE.NOTE, null, values); + + /** + * create trash folder + */ + /* + * 创建垃圾箱 + */ + values.clear(); + values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); + values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); + db.insert(TABLE.NOTE, null, values); + } + + /* + * 用于创建存储标签内容的表格 + */ + public void createDataTable(SQLiteDatabase db) { + db.execSQL(CREATE_DATA_TABLE_SQL);// 执行 CREATE_DATA_TABLE_SQL 的 SQL 语句来创建数据表 + reCreateDataTableTriggers(db);// 调用 reCreateDataTableTriggers() 方法重新创建数据表中的触发器 + db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);// 执行 CREATE_DATA_NOTE_ID_INDEX_SQL 的 SQL 语句来创建一个索引 + Log.d(TAG, "data table has been created"); + } + + /* + * 用于重新创建数据表中的触发器 + */ + 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) { + if (mInstance == null) { + mInstance = new NotesDatabaseHelper(context); + } + return mInstance; + } + + @Override + /* + * 在数据库第一次创建时被调用,用于创建所需的表格和触发器 + */ + public void onCreate(SQLiteDatabase db) { + createNoteTable(db); + createDataTable(db); + } + + @Override + /* + * 根据旧版本和新版本之间的差异来执行相应的数据库升级操作 + */ + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + boolean reCreateTriggers = false; + boolean skipV2 = false;// 是否进行V2升级 + /* + * 如果旧版本为1,则调用upgradeToV2方法 + */ + if (oldVersion == 1) { + upgradeToV2(db); + skipV2 = true; // this upgrade including the upgrade from v2 to v3 + oldVersion++; + } + /* + * 如果旧版本为2且未跳过V2升级,则调用upgradeToV3方法 + */ + if (oldVersion == 2 && !skipV2) { + upgradeToV3(db); + reCreateTriggers = true; + oldVersion++; + } + /* + * 如果旧版本为3,则调用upgradeToV4方法 + */ + if (oldVersion == 3) { + upgradeToV4(db); + oldVersion++; + } + /* + * 如果需要重新创建触发器,则调用reCreateNoteTableTriggers和reCreateDataTableTriggers方法重新创建触发器 + */ + if (reCreateTriggers) { + reCreateNoteTableTriggers(db); + reCreateDataTableTriggers(db); + } + /* + * 如果旧版本和新版本不匹配,则抛出异常 + */ + if (oldVersion != newVersion) { + throw new IllegalStateException("Upgrade notes database to version " + newVersion + + "fails"); + } + } + + /* + * 更新到V2版本 + * */ + private void upgradeToV2(SQLiteDatabase db) { + /* + * 通过执行SQL语句DROP TABLE IF EXISTS来删除旧的NOTE和DATA表格 + * */ + db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); + db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); + createNoteTable(db);// 调用createNoteTable和createDataTable方法来创建新的NOTE表格 + createDataTable(db);// 调用createNoteTable和createDataTable方法来创建新的DATA表格 + } + + /* + * 更新到V3版本 + * */ + private void upgradeToV3(SQLiteDatabase db) { + /* + * 执行SQL语句DROP TRIGGER IF EXISTS来移除不再使用的触发器 + * */ + // 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"); + db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update"); + /* + * 执行ALTER TABLE语句向NOTE表格中添加一个新的列GTASK_ID,该列的类型是TEXT,并设置默认值为'' + * */ + // add a column for gtask id + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID + + " TEXT NOT NULL DEFAULT ''"); + /* + * 通过ContentValues对象向NOTE表格中插入一条记录,该记录代表垃圾箱系统文件夹 + * */ + // add a trash system folder + ContentValues values = new ContentValues(); + values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); + values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); + db.insert(TABLE.NOTE, null, values); + } + + /* + * 更新到V4版本 + * */ + private void upgradeToV4(SQLiteDatabase db) { + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + + " INTEGER NOT NULL DEFAULT 0");// 通过执行ALTER TABLE语句向NOTE表格中添加一个新的列VERSION,该列的类型是INTEGER,并设置默认值为0 + } +} diff --git a/src/Notes-master/app/src/main/java/net/micode/notes/data/data/NotesProvider.java b/src/Notes-master/app/src/main/java/net/micode/notes/data/data/NotesProvider.java new file mode 100644 index 0000000..64ac3bd --- /dev/null +++ b/src/Notes-master/app/src/main/java/net/micode/notes/data/data/NotesProvider.java @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.micode.notes.data; + + +import android.app.SearchManager; +import android.content.ContentProvider; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Intent; +import android.content.UriMatcher; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.net.Uri; +import android.text.TextUtils; +import android.util.Log; + +import net.micode.notes.R; +import net.micode.notes.data.Notes.DataColumns; +import net.micode.notes.data.Notes.NoteColumns; +import net.micode.notes.data.NotesDatabaseHelper.TABLE; + +/* +* 功能描述:用于提供对便签数据的存储和获取功能,实现了创建、读取、更新、删除操作,以便其他组件可以通过 ContentResolver 访问和管理便签数据。 +* */ +public class NotesProvider extends ContentProvider { + private static final UriMatcher mMatcher;// UriMatcher用于匹配Uri + + private NotesDatabaseHelper mHelper;// 数据库帮助类 + + private static final String TAG = "NotesProvider";// 标签 + + private static final int URI_NOTE = 1;// Uri匹配码 + private static final int URI_NOTE_ITEM = 2; + private static final int URI_DATA = 3; + private static final int URI_DATA_ITEM = 4; + + private static final int URI_SEARCH = 5; + private static final int URI_SEARCH_SUGGEST = 6; + + static { + mMatcher = new UriMatcher(UriMatcher.NO_MATCH);// 创建UriMatcher时,调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码 + /* + * 把需要匹配Uri路径全部给注册上 + * */ + mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);// 便签列表的路径 + mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);// 便签详情的路径,其中 "#" 表示数字,表示具体的便签 ID + mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);// 数据列表的路径 + mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);// 数据详情的路径,其中 "#" 表示数字,表示具体的数据 ID + mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH);// 搜索的路径 + mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST);// 搜索建议的路径 + mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST);// 带搜索关键字的搜索建议的路径 + } + + /** + * x'0A' represents the '\n' character in sqlite. For title and content in the search result, + * we will trim '\n' and white space in order to show more information. + */ + + /* + * 查询搜索结果的投影。该投影包含了搜索结果需要的各个字段,如便签的 ID、搜索文本等 + * */ + private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + "," + + NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + "," + + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + "," + + "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + "," + + R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + "," + + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + "," + + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA; + + /* + * 查询语句,用于查询搜索结果 + * */ + private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION + + " FROM " + TABLE.NOTE + + " WHERE " + NoteColumns.SNIPPET + " LIKE ?" + + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + + " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE; + + @Override + /* + *在onCreate()中初始化Context,实例化mHelper + * */ + public boolean onCreate() { + mHelper = NotesDatabaseHelper.getInstance(getContext()); + return true; + } + + @Override + /* + * 根据传入的Uri进行数据库查询操作 + * */ + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + Cursor c = null;// 定义一个Cursor对象用于存放查询结果 + SQLiteDatabase db = mHelper.getReadableDatabase();// 获取可读数据库实例 + String id = null;// 用于存放ID值 + /* + * 根据Uri使用Matcher匹配相应的操作,对于不同的匹配值,在数据库中查找相应的条目 + * */ + switch (mMatcher.match(uri)) { + case URI_NOTE: + c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null, + sortOrder);// 查询便签列表 + break; + case URI_NOTE_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID值 + c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id + + parseSelection(selection), selectionArgs, null, null, sortOrder);// 查询特定ID的便签详情 + break; + case URI_DATA: + c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null, + sortOrder);// 查询数据列表 + break; + case URI_DATA_ITEM: + id = uri.getPathSegments().get(1); // 获取Uri中的ID值 + c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id + + parseSelection(selection), selectionArgs, null, null, sortOrder);// 查询特定ID的数据详情 + break; + case URI_SEARCH: + case URI_SEARCH_SUGGEST: + if (sortOrder != null || projection != null) { + throw new IllegalArgumentException( + "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");// 如果存在不合法的参数则抛出异常 + } + + String searchString = null; + if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) { + if (uri.getPathSegments().size() > 1) { + searchString = uri.getPathSegments().get(1); // 获取搜索关键字 + } + } else { + searchString = uri.getQueryParameter("pattern"); // 获取搜索关键字 + } + + if (TextUtils.isEmpty(searchString)) { + return null;// 如果搜索关键字为空则直接返回null + } + + try { + searchString = String.format("%%%s%%", searchString);// 格式化搜索关键字 + c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY, + new String[] { searchString });// 执行搜索查询 + } catch (IllegalStateException ex) { + Log.e(TAG, "got exception: " + ex.toString());// 捕获异常 + } + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 + } + if (c != null) { + c.setNotificationUri(getContext().getContentResolver(), uri);// 设置查询结果的变更通知URI + } + return c;// 返回查询结果的Cursor对象 + } + + @Override + /* + * 功能描述:实现对数据库表单的增加记录操作 + * 输入参数:参数 uri 表示插入的 URI,values 表示插入的值 + * */ + public Uri insert(Uri uri, ContentValues values) { + SQLiteDatabase db = mHelper.getWritableDatabase();// 获得可写的数据库 + long dataId = 0, noteId = 0, insertedId = 0;// 定义三个id值变量 + /* + * 根据Uri使用Matcher匹配相应的操作 + * */ + switch (mMatcher.match(uri)) { + case URI_NOTE: + insertedId = noteId = db.insert(TABLE.NOTE, null, values);// 在便签表中插入新记录 + break; + case URI_DATA: + if (values.containsKey(DataColumns.NOTE_ID)) { + noteId = values.getAsLong(DataColumns.NOTE_ID);// 如果数据内容包含NOTE_ID字段,获取NOTE_ID值 + } else { + Log.d(TAG, "Wrong data format without note id:" + values.toString());// 如果不包含则输出日志信息 + } + insertedId = dataId = db.insert(TABLE.DATA, null, values);// 在数据表中插入新记录 + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 + } + // Notify the note uri + if (noteId > 0) {// 如果是便签新增操作 + getContext().getContentResolver().notifyChange( + ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);// 通过ContentResolver对象发送通知,更新便签的变更通知URI + } + + // Notify the data uri + if (dataId > 0) {// 如果是数据新增操作 + getContext().getContentResolver().notifyChange( + ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);// 通过ContentResolver对象发送通知,更新数据的变更通知URI + } + + return ContentUris.withAppendedId(uri, insertedId);// 返回插入的uri的路径 + } + + @Override + /* + * 功能描述:实现对数据库表单的删除记录操作 + * 输入参数:参数 uri 表示删除的 URI,selection 表示删除条件,selectionArgs 表示删除条件值 + * */ + public int delete(Uri uri, String selection, String[] selectionArgs) { + //Uri代表要操作的数据,Android上可用的每种资源 -包括 图像、视频片段、音频资源等都可以用Uri来表示 + int count = 0;// 定义计数变量 + String id = null;// 定义id字符串变量 + SQLiteDatabase db = mHelper.getWritableDatabase();// 获取可写数据库实例 + boolean deleteData = false;// 是否删除数据标志位 + /* + * 根据Uri使用Matcher匹配相应的操作 + * */ + switch (mMatcher.match(uri)) { + case URI_NOTE: + selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";// 对于便签的删除操作,添加额外的条件限制 + count = db.delete(TABLE.NOTE, selection, selectionArgs);// 在便签表中删除符合条件的记录 + break; + case URI_NOTE_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 + /** + * ID that smaller than 0 is system folder which is not allowed to + * trash + */ + long noteId = Long.valueOf(id); + if (noteId <= 0) {// 如果ID小于等于0,则不允许删除 + break; + } + count = db.delete(TABLE.NOTE, + NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);// 在便签表中删除指定ID的记录 + break; + case URI_DATA: + count = db.delete(TABLE.DATA, selection, selectionArgs);// 在数据表中删除符合条件的记录 + deleteData = true;// 设置删除数据标志位为true + break; + case URI_DATA_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 + count = db.delete(TABLE.DATA, + DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);// 在数据表中删除指定ID的记录 + deleteData = true;// 设置删除数据标志位为true + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 + } + if (count > 0) {// 如果删除记录数大于0 + if (deleteData) { + getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);// 通过ContentResolver对象发送通知,更新便签变更通知URI + } + getContext().getContentResolver().notifyChange(uri, null);// 通过ContentResolver对象发送通知,更新变更通知URI + } + return count;// 返回删除的记录数 + } + + @Override + /* + * 功能描述:实现对数据库表单的更新操作 + * 输入参数:参数 uri 表示更新的 URI,values 表示更新的值,selection 表示更新条件,selectionArgs 表示更新条件值 + * */ + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + int count = 0;// 定义计数变量 + String id = null;// 定义id字符串变量 + SQLiteDatabase db = mHelper.getWritableDatabase();// 获取可写数据库实例 + boolean updateData = false;// 是否更新数据标志位 + /* + * 根据Uri使用Matcher匹配相应的操作 + * */ + switch (mMatcher.match(uri)) { + case URI_NOTE: + increaseNoteVersion(-1, selection, selectionArgs);// 增加便签版本号,针对便签的更新操作,添加额外的条件限制 + count = db.update(TABLE.NOTE, values, selection, selectionArgs);// 在便签表中更新符合条件的记录 + break; + case URI_NOTE_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 + increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);// 增加便签版本号,针对便签的更新操作,添加额外的条件限制 + count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id + + parseSelection(selection), selectionArgs);// 在便签表中更新指定ID的记录 + break; + case URI_DATA: + count = db.update(TABLE.DATA, values, selection, selectionArgs);// 在数据表中更新符合条件的记录 + updateData = true;// 设置更新数据标志位为tru + break; + case URI_DATA_ITEM: + id = uri.getPathSegments().get(1);// 获取Uri中的ID参数 + count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id + + parseSelection(selection), selectionArgs);// 在数据表中更新指定ID的记录 + updateData = true;// 设置更新数据标志位为true + break; + default: + throw new IllegalArgumentException("Unknown URI " + uri);// 对于未知的Uri抛出异常 + } + + if (count > 0) {// 如果更新记录数大于0 + if (updateData) { + getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);// 通过ContentResolver对象发送通知,更新便签变更通知URI + } + getContext().getContentResolver().notifyChange(uri, null);// 通过ContentResolver对象发送通知,更新变更通知URI + } + return count;// 返回更新的记录数 + } + + /* + * 解析查询条件selection,如果selection不为空,则在其前面加上" AND ",用于拼接SQL语句 + * */ + private String parseSelection(String selection) { + return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); + } + + /* + * 根据传入的id和selection参数确定要更新的记录,并将版本号加1 + * */ + private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { + StringBuilder sql = new StringBuilder(120);// 创建一个StringBuilder对象,用于构建SQL语句 + sql.append("UPDATE ");// 构建UPDATE语句,指定要更新的表名 + sql.append(TABLE.NOTE);// 表名 + sql.append(" SET ");// 指定要更新的字段和新的值 + sql.append(NoteColumns.VERSION);// 字段名 + sql.append("=" + NoteColumns.VERSION + "+1 ");// 将版本号加1 + + if (id > 0 || !TextUtils.isEmpty(selection)) { + sql.append(" WHERE ");// 根据传入的参数决定是否添加WHERE子句 + } + if (id > 0) { + sql.append(NoteColumns.ID + "=" + String.valueOf(id)); // 如果传入的id大于0,则表示只更新指定id的记录 + } + if (!TextUtils.isEmpty(selection)) {// 如果传入的selection不为空,则根据它来确定要更新的记录 + String selectString = id > 0 ? parseSelection(selection) : selection;// 调用parseSelection方法将selection转换为SQL语句中的WHERE子句 + for (String args : selectionArgs) { + selectString = selectString.replaceFirst("\\?", args);// 替换WHERE子句中的问号占位符为实际的参数值 + } + sql.append(selectString);// 添加WHERE子句到SQL语句中 + } + + // execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句 + mHelper.getWritableDatabase().execSQL(sql.toString());// 添加WHERE子句到SQL语句中 + } + + @Override + /* + * 功能描述:用于根据 URI 返回相应的 MIME 类型 + * 输入参数:参数 uri 表示查询或操作的 URI + * 函数中是环境自动生成的,也可自己改写 + * */ + public String getType(Uri uri) { + // TODO Auto-generated method stub + return null; + } +}