diff --git a/src/net/micode/notes/data/Notes.java b/src/net/micode/notes/data/Notes.java index f240604b4c96bbe184d33fb1e67039d23a1cbc24..fd5f5e22b2ba627d828c96fcf8a2ddbc418225bd 100644 --- a/src/net/micode/notes/data/Notes.java +++ b/src/net/micode/notes/data/Notes.java @@ -1,88 +1,137 @@ +小米便签Notes.java代码(带批注) + /* * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * 版权声明:明确代码版权归属小米开源社区,时间范围2010-2011年 * * Licensed under the Apache License, Version 2.0 (the "License"); + * 遵循Apache License 2.0开源协议(对应提供的协议文档),所有使用、修改、分发需遵守该协议 * 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. + * 具体的权限和限制,参考完整的Apache License 2.0协议 */ package net.micode.notes.data; +// 包声明:该类属于小米便签的数据层(data包),用于定义数据相关的常量和接口 import android.net.Uri; +// 导入Android系统的Uri类,用于定义ContentProvider的数据访问地址(Android特有) + public class Notes { + // 核心数据定义类,相当于小米便签的"数据字典",集中定义所有数据相关的约定 public static final String AUTHORITY = "micode_notes"; + // ContentProvider的唯一标识(相当于数据库的"访问标识"),用于Android系统识别该应用的数据提供者 public static final String TAG = "Notes"; + // 日志标签,打印日志时用于标识该类,方便调试定位问题 public static final int TYPE_NOTE = 0; + // 常量:标识"便签"类型(用常量替代魔法值,提升可读性) public static final int TYPE_FOLDER = 1; + // 常量:标识"文件夹"类型 public static final int TYPE_SYSTEM = 2; + // 常量:标识"系统"类型(用于系统级文件夹/便签) /** * Following IDs are system folders' identifiers + * 文档注释:说明下方是系统文件夹的固定ID(预定义,不可修改) * {@link Notes#ID_ROOT_FOLDER } is default folder + * 根文件夹ID,是便签的默认存放文件夹 * {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder + * 临时文件夹ID,用于存放无归属(未分类)的便签 * {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records + * 通话记录文件夹ID,专门用于存放通话记录类便签 */ public static final int ID_ROOT_FOLDER = 0; + // 系统根文件夹ID(默认文件夹) public static final int ID_TEMPARAY_FOLDER = -1; + // 系统临时文件夹ID(无归属便签) public static final int ID_CALL_RECORD_FOLDER = -2; + // 系统通话记录文件夹ID public static final int ID_TRASH_FOLER = -3; + // 系统回收站文件夹ID(存放已删除的便签/文件夹) + // 以下是Intent参数常量:页面间传递数据的"参数名",避免拼写错误,保证全局统一 public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date"; + // 传递"便签提醒时间"的参数名 public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id"; + // 传递"便签背景色ID"的参数名 public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_id"; + // 传递"桌面小组件ID"的参数名 public static final String INTENT_EXTRA_WIDGET_TYPE = "net.micode.notes.widget_type"; + // 传递"桌面小组件类型"的参数名 public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id"; + // 传递"文件夹ID"的参数名 public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date"; + // 传递"通话记录日期"的参数名 + // 桌面小组件类型常量:区分不同尺寸的便签小组件(Android桌面组件适配) public static final int TYPE_WIDGET_INVALIDE = -1; + // 无效的小组件类型 public static final int TYPE_WIDGET_2X = 0; + // 2x尺寸的桌面小组件(适配手机桌面布局) public static final int TYPE_WIDGET_4X = 1; + // 4x尺寸的桌面小组件 public static class DataConstants { + // 内部类:汇总不同类型便签的MIME类型(ContentProvider识别数据类型的标识) public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; + // 文本便签的MIME类型标识(关联TextNote内部类) public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; + // 通话便签的MIME类型标识(关联CallNote内部类) } /** * Uri to query all notes and folders + * 文档注释:查询所有便签和文件夹的Uri(数据访问地址) */ public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); + // 访问"便签/文件夹列表"的Uri,通过该地址可查询所有便签和文件夹数据 /** * Uri to query data + * 文档注释:查询便签详情数据的Uri */ public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); + // 访问"便签详情"的Uri,通过该地址可查询具体便签的详细内容 public interface NoteColumns { + // 接口:定义"便签/文件夹数据表"的所有字段名(与数据库表字段一一对应) + // 接口中字段默认public static final,简洁且保证全局字段名统一 /** * The unique ID for a row *

Type: INTEGER (long)

+ * 文档注释:数据表的主键ID,唯一标识一条记录,数据类型为长整型 */ public static final String ID = "_id"; /** * The parent's id for note or folder *

Type: INTEGER (long)

+ * 文档注释:父文件夹ID,用于实现文件夹嵌套(如子文件夹的parent_id是根文件夹ID) */ public static final String PARENT_ID = "parent_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"; @@ -90,30 +139,35 @@ public class Notes { /** * Alert date *

Type: INTEGER (long)

+ * 文档注释:便签提醒时间,以时间戳存储,无提醒则为0 */ public static final String ALERTED_DATE = "alert_date"; /** * Folder's name or text content of note - *

Type: TEXT

+ *

Type: TEXT

+ * 文档注释:复用字段,文件夹存名称,便签存文本内容(节省数据库空间) */ public static final String SNIPPET = "snippet"; /** * Note's widget id *

Type: INTEGER (long)

+ * 文档注释:便签关联的桌面小组件ID,无关联则为0 */ public static final String WIDGET_ID = "widget_id"; /** * Note's widget type *

Type: INTEGER (long)

+ * 文档注释:便签关联的桌面小组件类型(对应上方的小组件类型常量) */ public static final String WIDGET_TYPE = "widget_type"; /** * Note's background color's id *

Type: INTEGER (long)

+ * 文档注释:便签背景色ID,对应不同的背景色(如1=黄色,2=蓝色) */ public static final String BG_COLOR_ID = "bg_color_id"; @@ -121,86 +175,101 @@ public class Notes { * For text note, it doesn't has attachment, for multi-media * note, it has at least one attachment *

Type: INTEGER

+ * 文档注释:是否有附件(0=无,1=有),文本便签无附件,多媒体便签有附件 */ 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

+ * 文档注释:类型标识(对应上方的TYPE_NOTE/TYPE_FOLDER/TYPE_SYSTEM) */ public static final String TYPE = "type"; /** * The last sync id *

Type: INTEGER (long)

+ * 文档注释:最后同步ID,用于便签数据同步(如云端同步) */ public static final String SYNC_ID = "sync_id"; /** * Sign to indicate local modified or not *

Type: INTEGER

+ * 文档注释:本地修改标识(0=未修改,1=已修改),用于同步时判断是否需要上传 */ public static final String LOCAL_MODIFIED = "local_modified"; /** * Original parent id before moving into temporary folder *

Type : INTEGER

+ * 文档注释:便签进入临时文件夹前的原始父文件夹ID,用于恢复便签归属 */ public static final String ORIGIN_PARENT_ID = "origin_parent_id"; /** * The gtask id *

Type : TEXT

+ * 文档注释:谷歌任务ID,用于与谷歌任务同步(可选功能) */ public static final String GTASK_ID = "gtask_id"; /** * The version code *

Type : INTEGER (long)

+ * 文档注释:版本号,用于处理数据版本兼容(如升级后的数据适配) */ public static final String VERSION = "version"; } public interface DataColumns { + // 接口:定义"便签详情数据表"的所有字段名,存储便签的具体内容 /** * The unique ID for a row *

Type: INTEGER (long)

+ * 文档注释:详情表的主键ID,唯一标识一条详情记录 */ public static final String ID = "_id"; /** * The MIME type of the item represented by this row. *

Type: Text

+ * 文档注释:数据类型(MIME类型),区分文本便签、通话便签等 */ public static final String MIME_TYPE = "mime_type"; /** * The reference id to note that this data belongs to *

Type: INTEGER (long)

+ * 文档注释:关联的便签ID,用于关联"便签基础表"和"便签详情表" */ public static final String NOTE_ID = "note_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"; @@ -209,6 +278,7 @@ public class Notes { * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * integer data type *

Type: INTEGER

+ * 文档注释:通用整型字段,含义由MIME_TYPE决定(不同便签类型用法不同) */ public static final String DATA1 = "data1"; @@ -216,6 +286,7 @@ public class Notes { * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * integer data type *

Type: INTEGER

+ * 文档注释:通用整型字段,同DATA1,用于存储不同便签的个性化整型数据 */ public static final String DATA2 = "data2"; @@ -223,6 +294,7 @@ public class Notes { * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * TEXT data type *

Type: TEXT

+ * 文档注释:通用文本字段,含义由MIME_TYPE决定,存储个性化文本数据 */ public static final String DATA3 = "data3"; @@ -230,6 +302,7 @@ public class Notes { * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * TEXT data type *

Type: TEXT

+ * 文档注释:通用文本字段,同DATA3 */ public static final String DATA4 = "data4"; @@ -237,43 +310,56 @@ public class Notes { * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * TEXT data type *

Type: TEXT

+ * 文档注释:通用文本字段,同DATA3 */ public static final String DATA5 = "data5"; } public static final class TextNote implements DataColumns { + // 内部类:文本便签的具体定义,实现DataColumns接口,复用通用字段 /** * Mode to indicate the text in check list mode or not *

Type: Integer 1:check list mode 0: normal mode

+ * 文档注释:文本便签的模式(1=待办清单模式,0=普通文本模式) */ public static final String MODE = DATA1; + // 复用DATA1字段,定义为文本便签的模式标识 public static final int MODE_CHECK_LIST = 1; + // 常量:待办清单模式(对应MODE字段的1) public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note"; - + // 文本便签列表的MIME类型,用于ContentProvider查询所有文本便签 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note"; - + // 单个文本便签的MIME类型,用于ContentProvider查询单个文本便签 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); + // 文本便签的专属Uri,通过该地址可查询/操作所有文本便签 } public static final class CallNote implements DataColumns { + // 内部类:通话便签的具体定义,实现DataColumns接口,复用通用字段 /** * Call date for this record *

Type: INTEGER (long)

+ * 文档注释:通话记录的日期,以时间戳存储 */ public static final String CALL_DATE = DATA1; + // 复用DATA1字段,定义为通话便签的通话日期 /** * Phone number for this record *

Type: TEXT

+ * 文档注释:通话记录的电话号码 */ public static final String PHONE_NUMBER = DATA3; + // 复用DATA3字段,定义为通话便签的电话号码 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note"; - + // 通话便签列表的MIME类型,用于查询所有通话便签 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note"; - + // 单个通话便签的MIME类型,用于查询单个通话便签 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); + // 通话便签的专属Uri,用于查询/操作所有通话便签 } } +