/* * 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. * 总体分析 这段 Java 代码定义了Notes类,它主要起到对笔记相关的常量、接口以及内部类进行统一管理的作用,涵盖了笔记应用中涉及的各种类型定义(如笔记类型、部件类型等)、系统文件夹的标识、用于数据查询的Uri地址,以及针对笔记列和数据列相关属性的接口定义(包括各属性的数据类型说明),还有针对文本笔记和通话记录笔记的具体内部类定义(包含各自特有的属性和对应的Uri等),整体为整个笔记应用在数据存储、查询以及不同类型笔记处理等方面提供了规范且统一的常量与结构定义基础。 函数分析 常量相关: AUTHORITY:定义了内容提供器的授权字符串为"micode_notes",用于在安卓系统中标识该应用对应的内容提供器,后续构建Uri等操作会依赖它来确定操作的数据来源。 TYPE_NOTE、TYPE_FOLDER、TYPE_SYSTEM:分别代表笔记、文件夹、系统相关的类型标识常量,用于区分不同类型的存储对象,在数据库存储、查询以及业务逻辑中根据类型进行不同处理时会用到这些标识。 ID_ROOT_FOLDER、ID_TEMPARAY_FOLDER、ID_CALL_RECORD_FOLDER、ID_TRASH_FOLER:定义了系统中不同功能文件夹的唯一标识常量,比如默认文件夹、临时文件夹、通话记录文件夹以及回收站文件夹等,方便在操作笔记与文件夹关联、移动等场景下通过这些固定标识来确定特定的文件夹。 INTENT_EXTRA_ALERT_DATE、INTENT_EXTRA_BACKGROUND_ID 等:一系列的字符串常量,用于作为传递额外意图信息的键值,比如在不同组件间传递提醒日期、背景颜色ID、部件相关属性以及文件夹ID等信息时,以此作为标准的键来传递对应的值。 TYPE_WIDGET_INVALIDE、TYPE_WIDGET_2X、TYPE_WIDGET_4X:定义了部件类型相关的常量,用于区分不同尺寸或者无效的部件类型,在涉及部件相关的业务逻辑(如笔记关联部件、部件显示等)中起到标识作用。 DataConstants内部类相关: NOTE和CALL_NOTE:分别通过引用TextNote.CONTENT_ITEM_TYPE和CallNote.CONTENT_ITEM_TYPE,定义了代表普通笔记和通话记录笔记的MIME_TYPE常量,用于在数据处理过程中区分不同类型的笔记数据,比如根据MIME_TYPE进行数据解析、存储等操作时可以通过这两个常量来判断。 CONTENT_NOTE_URI和CONTENT_DATA_URI: 这两个Uri常量分别定义了用于查询所有笔记和文件夹以及查询数据的统一资源标识符,是通过content://协议结合授权字符串构建而成,在使用ContentResolver进行数据库查询等操作时,作为查询的目标地址,方便从对应的数据库表中获取相应的数据。 NoteColumns接口相关: 该接口定义了一系列与笔记列相关的属性常量,比如笔记的唯一ID、父ID、创建日期、修改日期、提醒日期、名称或内容、部件相关属性(ID、类型、背景颜色ID)、是否有附件、笔记数量、类型、同步ID、本地修改标识以及关联的Gtask ID、版本号等,明确了笔记表中各列的名称以及对应的数据类型,为数据库操作中对笔记表的增删改查等操作提供了统一的列名引用规范,便于代码的可读性和维护性。 DataColumns接口相关: 此接口定义了一系列针对数据列的属性常量,涵盖了数据行的唯一ID、MIME_TYPE、所属笔记的ID、创建日期、修改日期、内容以及多个通用数据列(DATA1 - DATA5,其含义根据MIME_TYPE特定)等,同样为数据库中数据相关表的操作提供了统一的列名和数据类型规范,在处理笔记附属数据(如文本、多媒体等不同类型数据)的存储、查询等操作时可依据这些常量进行准确的操作。 TextNote内部类相关: 定义了文本笔记相关的属性和Uri等信息,比如MODE属性用于表示文本是否处于清单模式,还有代表文本笔记的内容类型(CONTENT_TYPE)、内容项类型(CONTENT_ITEM_TYPE)以及对应的Uri(CONTENT_URI),在处理文本笔记相关的数据存储、查询以及与其他组件交互等业务场景中提供了具体的类型标识和操作地址等依据。 CallNote内部类相关: 针对通话记录笔记,定义了通话日期(CALL_DATE)、电话号码(PHONE_NUMBER)等特有属性,以及内容类型(CONTENT_TYPE)、内容项类型(CONTENT_ITEM_TYPE)和对应的Uri(CONTENT_URI),方便在处理通话记录笔记数据时进行特定属性的操作以及基于Uri的数据库查询等操作。 */ package net.micode.notes.data; import android.net.Uri; public class Notes { public static final String AUTHORITY = "micode_notes"; 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 * {@link Notes#ID_ROOT_FOLDER } is default folder * {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder * {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records */ public static final int ID_ROOT_FOLDER = 0; public static final int ID_TEMPARAY_FOLDER = -1; public static final int ID_CALL_RECORD_FOLDER = -2; public static final int ID_TRASH_FOLER = -3; 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"; public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_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"; public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date"; public static final int TYPE_WIDGET_INVALIDE = -1; public static final int TYPE_WIDGET_2X = 0; public static final int TYPE_WIDGET_4X = 1; public static class DataConstants { public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; } /** * Uri to query all notes and folders */ public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); /** * Uri to query data */ public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); public interface NoteColumns { /** * The unique ID for a row *

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"; /** * 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"; /** * Note's widget type *

Type: INTEGER (long)

*/ public static final String WIDGET_TYPE = "widget_type"; /** * Note's background color's id *

Type: INTEGER (long)

*/ public static final String BG_COLOR_ID = "bg_color_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"; /** * 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"; /** * The gtask id *

Type : TEXT

*/ 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)

*/ 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"; /** * The reference id to note that this data belongs to *

Type: INTEGER (long)

*/ 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"; /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * integer data type *

Type: INTEGER

*/ public static final String DATA1 = "data1"; /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * integer data type *

Type: INTEGER

*/ public static final String DATA2 = "data2"; /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * TEXT data type *

Type: TEXT

*/ public static final String DATA3 = "data3"; /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * TEXT data type *

Type: TEXT

*/ public static final String DATA4 = "data4"; /** * Generic data column, the meaning is {@link #MIMETYPE} specific, used for * TEXT data type *

Type: TEXT

*/ public static final String DATA5 = "data5"; } 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"); } 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"); } }