From 4cfeb6bfd5f483d5fd8dfd59b08bedf41ec4baa3 Mon Sep 17 00:00:00 2001 From: AetherPendragon Date: Mon, 22 Dec 2025 00:10:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=89=80=E6=9C=89ja?= =?UTF-8?q?va=E6=96=87=E4=BB=B6=E7=9A=84=E4=BB=A3=E7=A0=81=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/net/micode/notes/data/Contact.java | 65 ++----- .../src/net/micode/notes/data/Notes.java | 183 +++++++++++------- .../notes/data/NotesDatabaseHelper.java | 94 +++++++-- .../net/micode/notes/data/NotesProvider.java | 53 ++++- .../src/net/micode/notes/model/Note.java | 103 +++++++++- .../net/micode/notes/model/WorkingNote.java | 129 ++++++++++-- .../net/micode/notes/tool/BackupUtils.java | 49 ++++- .../src/net/micode/notes/tool/DataUtils.java | 26 ++- .../micode/notes/tool/GTaskStringUtils.java | 4 + .../net/micode/notes/tool/ResourceParser.java | 33 ++++ .../micode/notes/ui/AlarmAlertActivity.java | 5 +- .../micode/notes/ui/AlarmInitReceiver.java | 5 +- .../net/micode/notes/ui/AlarmReceiver.java | 9 + .../net/micode/notes/ui/DateTimePicker.java | 4 + .../micode/notes/ui/DateTimePickerDialog.java | 4 + .../src/net/micode/notes/ui/DropdownMenu.java | 4 + .../micode/notes/ui/FoldersListAdapter.java | 5 +- .../src/net/micode/notes/ui/NoteEditText.java | 4 + .../src/net/micode/notes/ui/NoteItemData.java | 5 +- .../net/micode/notes/ui/NotesListAdapter.java | 14 +- .../net/micode/notes/ui/NotesListItem.java | 5 +- .../notes/ui/NotesPreferenceActivity.java | 5 +- .../notes/widget/NoteWidgetProvider.java | 47 ++++- .../notes/widget/NoteWidgetProvider_2x.java | 5 +- .../notes/widget/NoteWidgetProvider_4x.java | 5 +- 25 files changed, 677 insertions(+), 188 deletions(-) diff --git a/src/Notes-master/src/net/micode/notes/data/Contact.java b/src/Notes-master/src/net/micode/notes/data/Contact.java index 6850334..2b1de54 100644 --- a/src/Notes-master/src/net/micode/notes/data/Contact.java +++ b/src/Notes-master/src/net/micode/notes/data/Contact.java @@ -27,92 +27,63 @@ import java.util.HashMap; /** * 联系人查询工具类 - * 核心功能:在小米便签中用于智能识别电话号码并显示联系人名称 - * 实现方法:通过电话号码查询系统联系人的姓名,并通过哈希表缓存查询结果,避免重复查询,提升性能 - * + * 用于根据电话号码查询联系人姓名 */ public class Contact { - // 功能:缓存查询结果,,暂时存储电话号码与联系人的映射关系,避免重复查询,节省开销 + /** 联系人缓存,用于提高查询效率 */ private static HashMap sContactCache; - // 日志标签为Contact private static final String TAG = "Contact"; - /** - * 联系人查询函数中用到的SQL选择语句模板 - * 功能:在联系人数据库中匹配电话号码 - */ + /** 查询联系人的SQL选择语句,用于匹配电话号码 */ private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER + ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'" + " AND " + Data.RAW_CONTACT_ID + " IN " + "(SELECT raw_contact_id " + " FROM phone_lookup" + " WHERE min_match = '+')"; - /** - * SQL语句逻辑解读 - * AND 连接一个条件与下一个条件 - * 第一个条件:PHONE_NUMBERS_EQUAL(Phone.NUMBER,?) - * PHONE_NUMBERS_EQUAL 函数:Android系统提供的特殊函数,用于查找和Phone.NUMBER相同的电话号码 - * 第二个条件:Data.MIMETYPE = 'Phone.CONTENT_ITEM_TYPE' - * 确保数据类型必须是电话号码类型 - * 第三个条件:Data.RAW_CONTACT_ID IN A - * 联系人的ID必须存在于这个表格A中 - * 表格A:(SELECT raw_contact_id FROM phone_lookup WHERE min_match = '+') - * phone_lookup:Android系统中的一个与联系人数据有关的特殊表 - * min_match:最小匹配位数 - * 预先计算一个电话号码的最小匹配形式的表格 - */ /** - * getContact函数:查询联系人的姓名 - * @param context Android应用程序上下文 - * @param phoneNumber 要查询的电话号码 - * @return 联系人姓名,如果查询不到则返回null + * 根据电话号码获取联系人姓名 + * @param context 上下文对象 + * @param phoneNumber 电话号码 + * @return 联系人姓名,如果未找到则返回null */ public static String getContact(Context context, String phoneNumber) { - // 初始化查询缓存 + // 初始化缓存 if(sContactCache == null) { sContactCache = new HashMap(); } - // 检查缓存中是否已存在该电话号码的查询结果 + // 先从缓存中查找 if(sContactCache.containsKey(phoneNumber)) { return sContactCache.get(phoneNumber); } - // PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)用于计算电话号码的最小匹配位数 - // 将占位符"+"替换为最小匹配数,以构建完整的查询语句 + // 构建查询选择语句,使用电话号码的最小匹配格式 String selection = CALLER_ID_SELECTION.replace("+", PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); - - /** - * 查询联系人数据库 - * context.getContentResolver().query:查询当前应用程序的数据 - */ + // 查询联系人数据库 Cursor cursor = context.getContentResolver().query( - Data.CONTENT_URI, // 查询URI - new String [] { Phone.DISPLAY_NAME }, // 联系人的名称作为返回值 - selection, // 查询条件 - new String[] { phoneNumber }, // 电话号码作为查询参数 - null); // 无排序方式 + Data.CONTENT_URI, + new String [] { Phone.DISPLAY_NAME }, + selection, + new String[] { phoneNumber }, + null); - // 查询系统联系人数据库 if (cursor != null && cursor.moveToFirst()) { try { - // 获取第一行第一列的联系人姓名 + // 获取联系人姓名 String name = cursor.getString(0); - // 将查询结果存入缓存 + // 将结果存入缓存 sContactCache.put(phoneNumber, name); return name; } catch (IndexOutOfBoundsException e) { - // 发生数组越界异常,将异常记录到日志Log中 Log.e(TAG, " Cursor get string error " + e.toString()); return null; } finally { - // 关闭Cursor,防止内存泄露 cursor.close(); } } else { - // 没有找到匹配的联系人,将信息写入日志中 Log.d(TAG, "No contact matched with number:" + phoneNumber); return null; } diff --git a/src/Notes-master/src/net/micode/notes/data/Notes.java b/src/Notes-master/src/net/micode/notes/data/Notes.java index f240604..dccc41f 100644 --- a/src/Notes-master/src/net/micode/notes/data/Notes.java +++ b/src/Notes-master/src/net/micode/notes/data/Notes.java @@ -17,22 +17,35 @@ package net.micode.notes.data; import android.net.Uri; + +/** + * 笔记应用的常量定义类 + * 定义了笔记类型、文件夹ID、URI、数据库列名等常量 + */ public class Notes { + /** ContentProvider的授权标识 */ 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 + * 系统文件夹的ID标识符 + * {@link Notes#ID_ROOT_FOLDER } 是默认文件夹 + * {@link Notes#ID_TEMPARAY_FOLDER } 用于存放不属于任何文件夹的笔记 + * {@link Notes#ID_CALL_RECORD_FOLDER} 用于存储通话记录 */ + /** 根文件夹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; public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date"; @@ -42,238 +55,260 @@ public class Notes { 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; + /** 2x2小部件类型 */ public static final int TYPE_WIDGET_2X = 0; + /** 4x4小部件类型 */ public static final int TYPE_WIDGET_4X = 1; + /** + * 数据常量类 + */ public static class DataConstants { + /** 普通笔记的MIME类型 */ public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; + /** 通话记录笔记的MIME类型 */ public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE; } /** - * Uri to query all notes and folders + * 查询所有笔记和文件夹的URI */ public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); /** - * Uri to query data + * 查询数据的URI */ public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); + /** + * 笔记表的列名接口 + */ public interface NoteColumns { /** - * The unique ID for a row - *

Type: INTEGER (long)

+ * 行的唯一ID + *

类型: INTEGER (long)

*/ public static final String ID = "_id"; /** - * The parent's id for note or folder - *

Type: INTEGER (long)

+ * 笔记或文件夹的父ID + *

类型: INTEGER (long)

*/ public static final String PARENT_ID = "parent_id"; /** - * Created data for note or folder - *

Type: INTEGER (long)

+ * 笔记或文件夹的创建日期 + *

类型: INTEGER (long)

*/ public static final String CREATED_DATE = "created_date"; /** - * Latest modified date - *

Type: INTEGER (long)

+ * 最后修改日期 + *

类型: INTEGER (long)

*/ public static final String MODIFIED_DATE = "modified_date"; /** - * Alert date - *

Type: INTEGER (long)

+ * 提醒日期 + *

类型: INTEGER (long)

*/ public static final String ALERTED_DATE = "alert_date"; /** - * Folder's name or text content of note - *

Type: TEXT

+ * 文件夹名称或笔记的文本内容摘要 + *

类型: TEXT

*/ public static final String SNIPPET = "snippet"; /** - * Note's widget id - *

Type: INTEGER (long)

+ * 笔记的小部件ID + *

类型: INTEGER (long)

*/ public static final String WIDGET_ID = "widget_id"; /** - * Note's widget type - *

Type: INTEGER (long)

+ * 笔记的小部件类型 + *

类型: INTEGER (long)

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

Type: INTEGER (long)

+ * 笔记的背景颜色ID + *

类型: 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

+ * 是否有附件 + * 对于文本笔记,没有附件;对于多媒体笔记,至少有一个附件 + *

类型: INTEGER

*/ public static final String HAS_ATTACHMENT = "has_attachment"; /** - * Folder's count of notes - *

Type: INTEGER (long)

+ * 文件夹中的笔记数量 + *

类型: INTEGER (long)

*/ public static final String NOTES_COUNT = "notes_count"; /** - * The file type: folder or note - *

Type: INTEGER

+ * 文件类型:文件夹或笔记 + *

类型: INTEGER

*/ public static final String TYPE = "type"; /** - * The last sync id - *

Type: INTEGER (long)

+ * 最后一次同步的ID + *

类型: INTEGER (long)

*/ public static final String SYNC_ID = "sync_id"; /** - * Sign to indicate local modified or not - *

Type: INTEGER

+ * 标记是否在本地被修改 + *

类型: INTEGER

*/ public static final String LOCAL_MODIFIED = "local_modified"; /** - * Original parent id before moving into temporary folder - *

Type : INTEGER

+ * 移动到临时文件夹之前的原始父ID + *

类型: INTEGER

*/ public static final String ORIGIN_PARENT_ID = "origin_parent_id"; /** - * The gtask id - *

Type : TEXT

+ * Google Task的ID + *

类型: TEXT

*/ public static final String GTASK_ID = "gtask_id"; /** - * The version code - *

Type : INTEGER (long)

+ * 版本号 + *

类型: INTEGER (long)

*/ public static final String VERSION = "version"; } + /** + * 数据表的列名接口 + */ public interface DataColumns { /** - * The unique ID for a row - *

Type: INTEGER (long)

+ * 行的唯一ID + *

类型: INTEGER (long)

*/ public static final String ID = "_id"; /** - * The MIME type of the item represented by this row. - *

Type: Text

+ * 该行数据项的MIME类型 + *

类型: Text

*/ public static final String MIME_TYPE = "mime_type"; /** - * The reference id to note that this data belongs to - *

Type: INTEGER (long)

+ * 该数据所属笔记的引用ID + *

类型: INTEGER (long)

*/ public static final String NOTE_ID = "note_id"; /** - * Created data for note or folder - *

Type: INTEGER (long)

+ * 笔记或文件夹的创建日期 + *

类型: INTEGER (long)

*/ public static final String CREATED_DATE = "created_date"; /** - * Latest modified date - *

Type: INTEGER (long)

+ * 最后修改日期 + *

类型: INTEGER (long)

*/ public static final String MODIFIED_DATE = "modified_date"; /** - * Data's content - *

Type: TEXT

+ * 数据内容 + *

类型: TEXT

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

Type: INTEGER

+ * 通用数据列1,含义由{@link #MIME_TYPE}决定,用于存储整数类型数据 + *

类型: INTEGER

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

Type: INTEGER

+ * 通用数据列2,含义由{@link #MIME_TYPE}决定,用于存储整数类型数据 + *

类型: INTEGER

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

Type: TEXT

+ * 通用数据列3,含义由{@link #MIME_TYPE}决定,用于存储TEXT类型数据 + *

类型: TEXT

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

Type: TEXT

+ * 通用数据列4,含义由{@link #MIME_TYPE}决定,用于存储TEXT类型数据 + *

类型: TEXT

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

Type: TEXT

+ * 通用数据列5,含义由{@link #MIME_TYPE}决定,用于存储TEXT类型数据 + *

类型: 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

+ * 模式标识:文本是否为清单模式 + *

类型: Integer 1:清单模式 0:普通模式

*/ public static final String MODE = DATA1; + /** 清单模式常量 */ public static final int MODE_CHECK_LIST = 1; + /** 文本笔记的目录MIME类型 */ public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note"; + /** 文本笔记的单项MIME类型 */ public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note"; + /** 文本笔记的URI */ 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)

+ * 通话日期 + *

类型: INTEGER (long)

*/ public static final String CALL_DATE = DATA1; /** - * Phone number for this record - *

Type: TEXT

+ * 电话号码 + *

类型: TEXT

*/ public static final String PHONE_NUMBER = DATA3; + /** 通话记录笔记的目录MIME类型 */ 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"; + /** 通话记录笔记的URI */ public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); } } diff --git a/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java b/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java index ffe5d57..9a3ef8d 100644 --- a/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java +++ b/src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java @@ -26,20 +26,31 @@ import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.NoteColumns; - +/** + * 笔记数据库帮助类 + * 负责创建和管理SQLite数据库,包括笔记表和数据表 + */ public class NotesDatabaseHelper extends SQLiteOpenHelper { + /** 数据库名称 */ private static final String DB_NAME = "note.db"; + /** 数据库版本号 */ private static final int DB_VERSION = 4; + /** + * 数据库表名接口 + */ public interface TABLE { + /** 笔记表名 */ public static final String NOTE = "note"; + /** 数据表名 */ public static final String DATA = "data"; } private static final String TAG = "NotesDatabaseHelper"; + /** 数据库帮助类的单例实例 */ private static NotesDatabaseHelper mInstance; private static final String CREATE_NOTE_TABLE_SQL = @@ -83,7 +94,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { TABLE.DATA + "(" + DataColumns.NOTE_ID + ");"; /** - * Increase folder's note count when move note to the folder + * 触发器:当笔记移动到文件夹时,增加文件夹的笔记计数 */ private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER increase_folder_count_on_update "+ @@ -95,7 +106,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Decrease folder's note count when move note from folder + * 触发器:当笔记从文件夹移出时,减少文件夹的笔记计数 */ private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_update " + @@ -108,7 +119,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Increase folder's note count when insert new note to the folder + * 触发器:当向文件夹插入新笔记时,增加文件夹的笔记计数 */ private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER = "CREATE TRIGGER increase_folder_count_on_insert " + @@ -120,7 +131,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Decrease folder's note count when delete note from the folder + * 触发器:当从文件夹删除笔记时,减少文件夹的笔记计数 */ private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER = "CREATE TRIGGER decrease_folder_count_on_delete " + @@ -133,7 +144,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Update note's content when insert data with type {@link DataConstants#NOTE} + * 触发器:当插入类型为{@link DataConstants#NOTE}的数据时,更新笔记内容 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER = "CREATE TRIGGER update_note_content_on_insert " + @@ -146,7 +157,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Update note's content when data with {@link DataConstants#NOTE} type has changed + * 触发器:当类型为{@link DataConstants#NOTE}的数据更新时,更新笔记内容 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER = "CREATE TRIGGER update_note_content_on_update " + @@ -159,7 +170,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Update note's content when data with {@link DataConstants#NOTE} type has deleted + * 触发器:当类型为{@link DataConstants#NOTE}的数据删除时,更新笔记内容 */ private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER = "CREATE TRIGGER update_note_content_on_delete " + @@ -172,7 +183,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Delete datas belong to note which has been deleted + * 触发器:当笔记被删除时,删除属于该笔记的所有数据 */ private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER = "CREATE TRIGGER delete_data_on_delete " + @@ -183,7 +194,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Delete notes belong to folder which has been deleted + * 触发器:当文件夹被删除时,删除属于该文件夹的所有笔记 */ private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER = "CREATE TRIGGER folder_delete_notes_on_delete " + @@ -194,7 +205,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " END"; /** - * Move notes belong to folder which has been moved to trash folder + * 触发器:当文件夹被移动到回收站时,将其中的笔记也移动到回收站 */ private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER = "CREATE TRIGGER folder_move_notes_on_trash " + @@ -206,10 +217,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { " WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" + " END"; + /** + * 构造函数 + * @param context 上下文对象 + */ public NotesDatabaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } + /** + * 创建笔记表 + * @param db 数据库对象 + */ public void createNoteTable(SQLiteDatabase db) { db.execSQL(CREATE_NOTE_TABLE_SQL); reCreateNoteTableTriggers(db); @@ -217,6 +236,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "note table has been created"); } + /** + * 重新创建笔记表的触发器 + * @param db 数据库对象 + */ private void reCreateNoteTableTriggers(SQLiteDatabase db) { db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update"); db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update"); @@ -235,18 +258,22 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER); } + /** + * 创建系统文件夹 + * @param db 数据库对象 + */ private void createSystemFolder(SQLiteDatabase db) { ContentValues values = new ContentValues(); /** - * call record foler for call notes + * 创建通话记录文件夹 */ values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER); values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); db.insert(TABLE.NOTE, null, values); /** - * root folder which is default folder + * 创建根文件夹(默认文件夹) */ values.clear(); values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER); @@ -254,7 +281,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); /** - * temporary folder which is used for moving note + * 创建临时文件夹(用于移动笔记) */ values.clear(); values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER); @@ -262,7 +289,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); /** - * create trash folder + * 创建回收站文件夹 */ values.clear(); values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER); @@ -270,6 +297,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.insert(TABLE.NOTE, null, values); } + /** + * 创建数据表 + * @param db 数据库对象 + */ public void createDataTable(SQLiteDatabase db) { db.execSQL(CREATE_DATA_TABLE_SQL); reCreateDataTableTriggers(db); @@ -277,6 +308,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { Log.d(TAG, "data table has been created"); } + /** + * 重新创建数据表的触发器 + * @param db 数据库对象 + */ private void reCreateDataTableTriggers(SQLiteDatabase db) { db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert"); db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update"); @@ -287,6 +322,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER); } + /** + * 获取数据库帮助类的单例实例 + * @param context 上下文对象 + * @return 数据库帮助类实例 + */ static synchronized NotesDatabaseHelper getInstance(Context context) { if (mInstance == null) { mInstance = new NotesDatabaseHelper(context); @@ -294,12 +334,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { 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; @@ -333,6 +379,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { } } + /** + * 升级数据库到版本2 + * @param db 数据库对象 + */ private void upgradeToV2(SQLiteDatabase db) { db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE); db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA); @@ -340,21 +390,29 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { createDataTable(db); } + /** + * 升级数据库到版本3 + * @param db 数据库对象 + */ private void upgradeToV3(SQLiteDatabase db) { - // 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"); - // add a column for gtask id + // 添加gtask_id列 db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''"); - // 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); } + /** + * 升级数据库到版本4 + * @param db 数据库对象 + */ private void upgradeToV4(SQLiteDatabase db) { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0"); diff --git a/src/Notes-master/src/net/micode/notes/data/NotesProvider.java b/src/Notes-master/src/net/micode/notes/data/NotesProvider.java index edb0a60..1b98dc2 100644 --- a/src/Notes-master/src/net/micode/notes/data/NotesProvider.java +++ b/src/Notes-master/src/net/micode/notes/data/NotesProvider.java @@ -34,20 +34,30 @@ import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.NotesDatabaseHelper.TABLE; - +/** + * 笔记内容提供者 + * 提供对笔记数据的CRUD操作和搜索功能 + */ public class NotesProvider extends ContentProvider { private static final UriMatcher mMatcher; + /** 数据库帮助类实例 */ private NotesDatabaseHelper mHelper; private static final String TAG = "NotesProvider"; + /** URI匹配码:笔记列表 */ private static final int URI_NOTE = 1; + /** URI匹配码:单个笔记 */ private static final int URI_NOTE_ITEM = 2; + /** URI匹配码:数据列表 */ private static final int URI_DATA = 3; + /** URI匹配码:单个数据项 */ private static final int URI_DATA_ITEM = 4; + /** URI匹配码:搜索 */ private static final int URI_SEARCH = 5; + /** URI匹配码:搜索建议 */ private static final int URI_SEARCH_SUGGEST = 6; static { @@ -62,8 +72,9 @@ public class NotesProvider extends ContentProvider { } /** - * 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. + * 笔记搜索投影字段 + * x'0A'代表SQLite中的'\n'字符。对于搜索结果中的标题和内容, + * 我们将去除'\n'和空格以便显示更多信息。 */ private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + "," + NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + "," @@ -79,12 +90,18 @@ public class NotesProvider extends ContentProvider { + " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE; + /** + * 初始化ContentProvider + */ @Override public boolean onCreate() { mHelper = NotesDatabaseHelper.getInstance(getContext()); return true; } + /** + * 查询数据 + */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { @@ -147,6 +164,9 @@ public class NotesProvider extends ContentProvider { return c; } + /** + * 插入数据 + */ @Override public Uri insert(Uri uri, ContentValues values) { SQLiteDatabase db = mHelper.getWritableDatabase(); @@ -166,13 +186,13 @@ public class NotesProvider extends ContentProvider { default: throw new IllegalArgumentException("Unknown URI " + uri); } - // Notify the note uri + // 通知笔记URI的变化 if (noteId > 0) { getContext().getContentResolver().notifyChange( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); } - // Notify the data uri + // 通知数据URI的变化 if (dataId > 0) { getContext().getContentResolver().notifyChange( ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null); @@ -181,6 +201,9 @@ public class NotesProvider extends ContentProvider { return ContentUris.withAppendedId(uri, insertedId); } + /** + * 删除数据 + */ @Override public int delete(Uri uri, String selection, String[] selectionArgs) { int count = 0; @@ -195,8 +218,7 @@ public class NotesProvider extends ContentProvider { case URI_NOTE_ITEM: id = uri.getPathSegments().get(1); /** - * ID that smaller than 0 is system folder which is not allowed to - * trash + * ID小于0的是系统文件夹,不允许删除 */ long noteId = Long.valueOf(id); if (noteId <= 0) { @@ -227,6 +249,9 @@ public class NotesProvider extends ContentProvider { return count; } + /** + * 更新数据 + */ @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { int count = 0; @@ -267,10 +292,21 @@ public class NotesProvider extends ContentProvider { return count; } + /** + * 解析选择条件字符串 + * @param selection 选择条件 + * @return 格式化后的选择条件 + */ private String parseSelection(String selection) { return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); } + /** + * 增加笔记版本号 + * @param id 笔记ID,如果小于0则忽略 + * @param selection 选择条件 + * @param selectionArgs 选择参数 + */ private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { StringBuilder sql = new StringBuilder(120); sql.append("UPDATE "); @@ -296,6 +332,9 @@ public class NotesProvider extends ContentProvider { mHelper.getWritableDatabase().execSQL(sql.toString()); } + /** + * 获取URI的MIME类型 + */ @Override public String getType(Uri uri) { // TODO Auto-generated method stub diff --git a/src/Notes-master/src/net/micode/notes/model/Note.java b/src/Notes-master/src/net/micode/notes/model/Note.java index 6706cf6..306b883 100644 --- a/src/Notes-master/src/net/micode/notes/model/Note.java +++ b/src/Notes-master/src/net/micode/notes/model/Note.java @@ -33,16 +33,24 @@ import net.micode.notes.data.Notes.TextNote; import java.util.ArrayList; - +/** + * 笔记模型类 + * 用于表示和操作笔记数据,包括笔记内容和笔记数据 + */ public class Note { + /** 笔记差异值,用于记录笔记的修改 */ private ContentValues mNoteDiffValues; + /** 笔记数据对象 */ private NoteData mNoteData; private static final String TAG = "Note"; /** - * Create a new note id for adding a new note to databases + * 创建新笔记ID,用于向数据库添加新笔记 + * @param context 上下文对象 + * @param folderId 文件夹ID + * @return 新创建的笔记ID */ public static synchronized long getNewNoteId(Context context, long folderId) { - // Create a new note in the database + // 在数据库中创建新笔记 ContentValues values = new ContentValues(); long createdTime = System.currentTimeMillis(); values.put(NoteColumns.CREATED_DATE, createdTime); @@ -65,41 +73,81 @@ public class Note { return noteId; } + /** + * 构造函数 + */ public Note() { mNoteDiffValues = new ContentValues(); mNoteData = new NoteData(); } + /** + * 设置笔记值 + * @param key 列名 + * @param value 值 + */ public void setNoteValue(String key, String value) { mNoteDiffValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } + /** + * 设置文本数据 + * @param key 列名 + * @param value 值 + */ public void setTextData(String key, String value) { mNoteData.setTextData(key, value); } + /** + * 设置文本数据ID + * @param id 数据ID + */ public void setTextDataId(long id) { mNoteData.setTextDataId(id); } + /** + * 获取文本数据ID + * @return 文本数据ID + */ public long getTextDataId() { return mNoteData.mTextDataId; } + /** + * 设置通话数据ID + * @param id 数据ID + */ public void setCallDataId(long id) { mNoteData.setCallDataId(id); } + /** + * 设置通话数据 + * @param key 列名 + * @param value 值 + */ public void setCallData(String key, String value) { mNoteData.setCallData(key, value); } + /** + * 检查是否在本地被修改 + * @return 如果被修改返回true,否则返回false + */ public boolean isLocalModified() { return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); } + /** + * 同步笔记到数据库 + * @param context 上下文对象 + * @param noteId 笔记ID + * @return 同步成功返回true,否则返回false + */ public boolean syncNote(Context context, long noteId) { if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); @@ -110,15 +158,15 @@ public class Note { } /** - * In theory, once data changed, the note should be updated on {@link NoteColumns#LOCAL_MODIFIED} and - * {@link NoteColumns#MODIFIED_DATE}. For data safety, though update note fails, we also update the - * note data info + * 理论上,一旦数据改变,笔记应该在{@link NoteColumns#LOCAL_MODIFIED}和 + * {@link NoteColumns#MODIFIED_DATE}上更新。为了数据安全,即使更新笔记失败, + * 我们也会更新笔记数据信息 */ if (context.getContentResolver().update( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null, null) == 0) { Log.e(TAG, "Update note error, should not happen"); - // Do not return, fall through + // 不返回,继续执行 } mNoteDiffValues.clear(); @@ -130,17 +178,28 @@ public class Note { return true; } + /** + * 笔记数据内部类 + * 用于管理笔记的文本数据和通话数据 + */ private class NoteData { + /** 文本数据ID */ private long mTextDataId; + /** 文本数据值 */ private ContentValues mTextDataValues; + /** 通话数据ID */ private long mCallDataId; + /** 通话数据值 */ private ContentValues mCallDataValues; private static final String TAG = "NoteData"; + /** + * 构造函数 + */ public NoteData() { mTextDataValues = new ContentValues(); mCallDataValues = new ContentValues(); @@ -148,10 +207,18 @@ public class Note { mCallDataId = 0; } + /** + * 检查是否在本地被修改 + * @return 如果被修改返回true + */ boolean isLocalModified() { return mTextDataValues.size() > 0 || mCallDataValues.size() > 0; } + /** + * 设置文本数据ID + * @param id 数据ID + */ void setTextDataId(long id) { if(id <= 0) { throw new IllegalArgumentException("Text data id should larger than 0"); @@ -159,6 +226,10 @@ public class Note { mTextDataId = id; } + /** + * 设置通话数据ID + * @param id 数据ID + */ void setCallDataId(long id) { if (id <= 0) { throw new IllegalArgumentException("Call data id should larger than 0"); @@ -166,21 +237,37 @@ public class Note { mCallDataId = id; } + /** + * 设置通话数据 + * @param key 列名 + * @param value 值 + */ void setCallData(String key, String value) { mCallDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } + /** + * 设置文本数据 + * @param key 列名 + * @param value 值 + */ void setTextData(String key, String value) { mTextDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } + /** + * 将数据推送到ContentResolver + * @param context 上下文对象 + * @param noteId 笔记ID + * @return 操作成功返回URI,失败返回null + */ Uri pushIntoContentResolver(Context context, long noteId) { /** - * Check for safety + * 安全检查 */ if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); diff --git a/src/Notes-master/src/net/micode/notes/model/WorkingNote.java b/src/Notes-master/src/net/micode/notes/model/WorkingNote.java index be081e4..c4d4f2a 100644 --- a/src/Notes-master/src/net/micode/notes/model/WorkingNote.java +++ b/src/Notes-master/src/net/micode/notes/model/WorkingNote.java @@ -31,35 +31,47 @@ import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.TextNote; import net.micode.notes.tool.ResourceParser.NoteBgResources; - +/** + * 工作笔记类 + * 表示正在编辑的笔记,提供笔记的加载、保存和属性设置功能 + */ public class WorkingNote { - // Note for the working note + /** 笔记对象 */ private Note mNote; - // Note Id + /** 笔记ID */ private long mNoteId; - // Note content + /** 笔记内容 */ private String mContent; - // Note mode + /** 笔记模式(普通模式或清单模式) */ private int mMode; + /** 提醒日期 */ private long mAlertDate; + /** 修改日期 */ private long mModifiedDate; + /** 背景颜色ID */ private int mBgColorId; + /** 小部件ID */ private int mWidgetId; + /** 小部件类型 */ private int mWidgetType; + /** 文件夹ID */ private long mFolderId; + /** 上下文对象 */ private Context mContext; private static final String TAG = "WorkingNote"; + /** 是否已删除 */ private boolean mIsDeleted; + /** 笔记设置变化监听器 */ private NoteSettingChangedListener mNoteSettingStatusListener; public static final String[] DATA_PROJECTION = new String[] { @@ -101,7 +113,11 @@ public class WorkingNote { private static final int NOTE_MODIFIED_DATE_COLUMN = 5; - // New note construct + /** + * 新建笔记的构造函数 + * @param context 上下文对象 + * @param folderId 文件夹ID + */ private WorkingNote(Context context, long folderId) { mContext = context; mAlertDate = 0; @@ -114,7 +130,12 @@ public class WorkingNote { mWidgetType = Notes.TYPE_WIDGET_INVALIDE; } - // Existing note construct + /** + * 加载已有笔记的构造函数 + * @param context 上下文对象 + * @param noteId 笔记ID + * @param folderId 文件夹ID + */ private WorkingNote(Context context, long noteId, long folderId) { mContext = context; mNoteId = noteId; @@ -124,6 +145,9 @@ public class WorkingNote { loadNote(); } + /** + * 加载笔记数据 + */ private void loadNote() { Cursor cursor = mContext.getContentResolver().query( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, @@ -146,6 +170,9 @@ public class WorkingNote { loadNoteData(); } + /** + * 加载笔记的数据内容 + */ private void loadNoteData() { Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { @@ -174,6 +201,15 @@ public class WorkingNote { } } + /** + * 创建空笔记 + * @param context 上下文对象 + * @param folderId 文件夹ID + * @param widgetId 小部件ID + * @param widgetType 小部件类型 + * @param defaultBgColorId 默认背景颜色ID + * @return 工作笔记对象 + */ public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { WorkingNote note = new WorkingNote(context, folderId); @@ -183,10 +219,20 @@ public class WorkingNote { return note; } + /** + * 加载笔记 + * @param context 上下文对象 + * @param id 笔记ID + * @return 工作笔记对象 + */ public static WorkingNote load(Context context, long id) { return new WorkingNote(context, id, 0); } + /** + * 保存笔记 + * @return 保存成功返回true,否则返回false + */ public synchronized boolean saveNote() { if (isWorthSaving()) { if (!existInDatabase()) { @@ -199,7 +245,7 @@ public class WorkingNote { mNote.syncNote(mContext, mNoteId); /** - * Update widget content if there exist any widget of this note + * 如果该笔记存在小部件,更新小部件内容 */ if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID && mWidgetType != Notes.TYPE_WIDGET_INVALIDE @@ -212,10 +258,18 @@ public class WorkingNote { } } + /** + * 检查笔记是否存在于数据库中 + * @return 存在返回true + */ public boolean existInDatabase() { return mNoteId > 0; } + /** + * 检查笔记是否值得保存 + * @return 值得保存返回true + */ private boolean isWorthSaving() { if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) || (existInDatabase() && !mNote.isLocalModified())) { @@ -225,10 +279,19 @@ public class WorkingNote { } } + /** + * 设置笔记设置变化监听器 + * @param l 监听器对象 + */ public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; } + /** + * 设置提醒日期 + * @param date 提醒日期时间戳 + * @param set 是否设置提醒 + */ public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { mAlertDate = date; @@ -239,6 +302,10 @@ public class WorkingNote { } } + /** + * 标记笔记为已删除 + * @param mark 是否标记为删除 + */ public void markDeleted(boolean mark) { mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID @@ -247,6 +314,10 @@ public class WorkingNote { } } + /** + * 设置背景颜色ID + * @param id 背景颜色ID + */ public void setBgColorId(int id) { if (id != mBgColorId) { mBgColorId = id; @@ -257,6 +328,10 @@ public class WorkingNote { } } + /** + * 设置清单模式 + * @param mode 模式(0为普通模式,1为清单模式) + */ public void setCheckListMode(int mode) { if (mMode != mode) { if (mNoteSettingStatusListener != null) { @@ -267,6 +342,10 @@ public class WorkingNote { } } + /** + * 设置小部件类型 + * @param type 小部件类型 + */ public void setWidgetType(int type) { if (type != mWidgetType) { mWidgetType = type; @@ -274,6 +353,10 @@ public class WorkingNote { } } + /** + * 设置小部件ID + * @param id 小部件ID + */ public void setWidgetId(int id) { if (id != mWidgetId) { mWidgetId = id; @@ -281,6 +364,10 @@ public class WorkingNote { } } + /** + * 设置工作文本内容 + * @param text 文本内容 + */ public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { mContent = text; @@ -288,12 +375,21 @@ public class WorkingNote { } } + /** + * 转换为通话记录笔记 + * @param phoneNumber 电话号码 + * @param callDate 通话日期 + */ public void convertToCallNote(String phoneNumber, long callDate) { mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate)); mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber); mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER)); } + /** + * 检查是否有时钟提醒 + * @return 有提醒返回true + */ public boolean hasClockAlert() { return (mAlertDate > 0 ? true : false); } @@ -342,26 +438,31 @@ public class WorkingNote { return mWidgetType; } + /** + * 笔记设置变化监听器接口 + */ public interface NoteSettingChangedListener { /** - * Called when the background color of current note has just changed + * 当笔记背景颜色改变时调用 */ void onBackgroundColorChanged(); /** - * Called when user set clock + * 当用户设置时钟提醒时调用 + * @param date 提醒日期 + * @param set 是否设置 */ void onClockAlertChanged(long date, boolean set); /** - * Call when user create note from widget + * 当用户从小部件创建笔记时调用 */ void onWidgetChanged(); /** - * Call when switch between check list mode and normal mode - * @param oldMode is previous mode before change - * @param newMode is new mode + * 当在清单模式和普通模式之间切换时调用 + * @param oldMode 改变前的模式 + * @param newMode 新模式 */ void onCheckListModeChanged(int oldMode, int newMode); } diff --git a/src/Notes-master/src/net/micode/notes/tool/BackupUtils.java b/src/Notes-master/src/net/micode/notes/tool/BackupUtils.java index 39f6ec4..e20f6ba 100644 --- a/src/Notes-master/src/net/micode/notes/tool/BackupUtils.java +++ b/src/Notes-master/src/net/micode/notes/tool/BackupUtils.java @@ -35,12 +35,20 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; - +/** + * 备份工具类 + * 提供笔记的导出和备份功能 + */ public class BackupUtils { private static final String TAG = "BackupUtils"; - // Singleton stuff + /** 单例实例 */ private static BackupUtils sInstance; + /** + * 获取备份工具类的单例实例 + * @param context 上下文对象 + * @return 备份工具类实例 + */ public static synchronized BackupUtils getInstance(Context context) { if (sInstance == null) { sInstance = new BackupUtils(context); @@ -49,42 +57,65 @@ public class BackupUtils { } /** - * Following states are signs to represents backup or restore - * status + * 备份或恢复状态常量 */ - // Currently, the sdcard is not mounted + /** SD卡未挂载 */ public static final int STATE_SD_CARD_UNMOUONTED = 0; - // The backup file not exist + /** 备份文件不存在 */ public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; - // The data is not well formated, may be changed by other programs + /** 数据格式损坏,可能被其他程序修改 */ public static final int STATE_DATA_DESTROIED = 2; - // Some run-time exception which causes restore or backup fails + /** 运行时异常导致恢复或备份失败 */ public static final int STATE_SYSTEM_ERROR = 3; - // Backup or restore success + /** 备份或恢复成功 */ public static final int STATE_SUCCESS = 4; + /** 文本导出对象 */ private TextExport mTextExport; + /** + * 构造函数 + * @param context 上下文对象 + */ private BackupUtils(Context context) { mTextExport = new TextExport(context); } + /** + * 检查外部存储是否可用 + * @return 可用返回true + */ private static boolean externalStorageAvailable() { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); } + /** + * 导出笔记为文本文件 + * @return 导出状态 + */ public int exportToText() { return mTextExport.exportToText(); } + /** + * 获取导出的文本文件名 + * @return 文件名 + */ public String getExportedTextFileName() { return mTextExport.mFileName; } + /** + * 获取导出的文本文件目录 + * @return 文件目录 + */ public String getExportedTextFileDir() { return mTextExport.mFileDirectory; } + /** + * 文本导出内部类 + */ private static class TextExport { private static final String[] NOTE_PROJECTION = { NoteColumns.ID, diff --git a/src/Notes-master/src/net/micode/notes/tool/DataUtils.java b/src/Notes-master/src/net/micode/notes/tool/DataUtils.java index 2a14982..c9eb3bc 100644 --- a/src/Notes-master/src/net/micode/notes/tool/DataUtils.java +++ b/src/Notes-master/src/net/micode/notes/tool/DataUtils.java @@ -34,9 +34,19 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import java.util.ArrayList; import java.util.HashSet; - +/** + * 数据工具类 + * 提供批量删除、移动笔记等数据操作方法 + */ public class DataUtils { public static final String TAG = "DataUtils"; + + /** + * 批量删除笔记 + * @param resolver ContentResolver对象 + * @param ids 要删除的笔记ID集合 + * @return 删除成功返回true,否则返回false + */ public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { if (ids == null) { Log.d(TAG, "the ids is null"); @@ -72,6 +82,13 @@ public class DataUtils { return false; } + /** + * 将笔记移动到文件夹 + * @param resolver ContentResolver对象 + * @param id 笔记ID + * @param srcFolderId 源文件夹ID + * @param desFolderId 目标文件夹ID + */ public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) { ContentValues values = new ContentValues(); values.put(NoteColumns.PARENT_ID, desFolderId); @@ -80,6 +97,13 @@ public class DataUtils { resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); } + /** + * 批量移动笔记到文件夹 + * @param resolver ContentResolver对象 + * @param ids 要移动的笔记ID集合 + * @param folderId 目标文件夹ID + * @return 移动成功返回true,否则返回false + */ public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, long folderId) { if (ids == null) { diff --git a/src/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java b/src/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java index 666b729..091c1ab 100644 --- a/src/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java +++ b/src/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java @@ -16,6 +16,10 @@ package net.micode.notes.tool; +/** + * Google Task字符串工具类 + * 提供Google Task相关的字符串常量定义 + */ public class GTaskStringUtils { public final static String GTASK_JSON_ACTION_ID = "action_id"; diff --git a/src/Notes-master/src/net/micode/notes/tool/ResourceParser.java b/src/Notes-master/src/net/micode/notes/tool/ResourceParser.java index 1ad3ad6..b46643f 100644 --- a/src/Notes-master/src/net/micode/notes/tool/ResourceParser.java +++ b/src/Notes-master/src/net/micode/notes/tool/ResourceParser.java @@ -22,23 +22,41 @@ import android.preference.PreferenceManager; import net.micode.notes.R; import net.micode.notes.ui.NotesPreferenceActivity; +/** + * 资源解析器 + * 提供笔记背景颜色、字体大小等资源的解析和获取功能 + */ public class ResourceParser { + /** 黄色背景 */ public static final int YELLOW = 0; + /** 蓝色背景 */ public static final int BLUE = 1; + /** 白色背景 */ public static final int WHITE = 2; + /** 绿色背景 */ public static final int GREEN = 3; + /** 红色背景 */ public static final int RED = 4; + /** 默认背景颜色 */ public static final int BG_DEFAULT_COLOR = YELLOW; + /** 小字体 */ public static final int TEXT_SMALL = 0; + /** 中等字体 */ public static final int TEXT_MEDIUM = 1; + /** 大字体 */ public static final int TEXT_LARGE = 2; + /** 超大字体 */ public static final int TEXT_SUPER = 3; + /** 默认字体大小 */ public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; + /** + * 笔记背景资源类 + */ public static class NoteBgResources { private final static int [] BG_EDIT_RESOURCES = new int [] { R.drawable.edit_yellow, @@ -56,15 +74,30 @@ public class ResourceParser { R.drawable.edit_title_red }; + /** + * 获取笔记编辑背景资源ID + * @param id 颜色ID + * @return 背景资源ID + */ public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; } + /** + * 获取笔记标题背景资源ID + * @param id 颜色ID + * @return 标题背景资源ID + */ public static int getNoteTitleBgResource(int id) { return BG_EDIT_TITLE_RESOURCES[id]; } } + /** + * 获取默认背景ID + * @param context 上下文对象 + * @return 背景颜色ID + */ public static int getDefaultBgId(Context context) { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { diff --git a/src/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java b/src/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java index 85723be..5240e36 100644 --- a/src/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java +++ b/src/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java @@ -39,7 +39,10 @@ import net.micode.notes.tool.DataUtils; import java.io.IOException; - +/** + * 闹钟提醒活动 + * 当笔记提醒时间到达时显示提醒界面 + */ public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener { private long mNoteId; private String mSnippet; diff --git a/src/Notes-master/src/net/micode/notes/ui/AlarmInitReceiver.java b/src/Notes-master/src/net/micode/notes/ui/AlarmInitReceiver.java index f221202..a1467e8 100644 --- a/src/Notes-master/src/net/micode/notes/ui/AlarmInitReceiver.java +++ b/src/Notes-master/src/net/micode/notes/ui/AlarmInitReceiver.java @@ -27,7 +27,10 @@ import android.database.Cursor; import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; - +/** + * 闹钟初始化接收器 + * 在系统启动时重新设置所有笔记的提醒 + */ public class AlarmInitReceiver extends BroadcastReceiver { private static final String [] PROJECTION = new String [] { diff --git a/src/Notes-master/src/net/micode/notes/ui/AlarmReceiver.java b/src/Notes-master/src/net/micode/notes/ui/AlarmReceiver.java index 54e503b..9884cc3 100644 --- a/src/Notes-master/src/net/micode/notes/ui/AlarmReceiver.java +++ b/src/Notes-master/src/net/micode/notes/ui/AlarmReceiver.java @@ -20,7 +20,16 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +/** + * 闹钟接收器 + * 接收系统闹钟广播,启动闹钟提醒活动 + */ public class AlarmReceiver extends BroadcastReceiver { + /** + * 接收广播 + * @param context 上下文对象 + * @param intent 意图对象 + */ @Override public void onReceive(Context context, Intent intent) { intent.setClass(context, AlarmAlertActivity.class); diff --git a/src/Notes-master/src/net/micode/notes/ui/DateTimePicker.java b/src/Notes-master/src/net/micode/notes/ui/DateTimePicker.java index 496b0cd..644155b 100644 --- a/src/Notes-master/src/net/micode/notes/ui/DateTimePicker.java +++ b/src/Notes-master/src/net/micode/notes/ui/DateTimePicker.java @@ -28,6 +28,10 @@ import android.view.View; import android.widget.FrameLayout; import android.widget.NumberPicker; +/** + * 日期时间选择器 + * 提供日期和时间的选择功能 + */ public class DateTimePicker extends FrameLayout { private static final boolean DEFAULT_ENABLE_STATE = true; diff --git a/src/Notes-master/src/net/micode/notes/ui/DateTimePickerDialog.java b/src/Notes-master/src/net/micode/notes/ui/DateTimePickerDialog.java index 2c47ba4..b45ff7d 100644 --- a/src/Notes-master/src/net/micode/notes/ui/DateTimePickerDialog.java +++ b/src/Notes-master/src/net/micode/notes/ui/DateTimePickerDialog.java @@ -29,6 +29,10 @@ import android.content.DialogInterface.OnClickListener; import android.text.format.DateFormat; import android.text.format.DateUtils; +/** + * 日期时间选择对话框 + * 用于设置笔记的提醒时间 + */ public class DateTimePickerDialog extends AlertDialog implements OnClickListener { private Calendar mDate = Calendar.getInstance(); diff --git a/src/Notes-master/src/net/micode/notes/ui/DropdownMenu.java b/src/Notes-master/src/net/micode/notes/ui/DropdownMenu.java index 613dc74..908f21c 100644 --- a/src/Notes-master/src/net/micode/notes/ui/DropdownMenu.java +++ b/src/Notes-master/src/net/micode/notes/ui/DropdownMenu.java @@ -27,6 +27,10 @@ import android.widget.PopupMenu.OnMenuItemClickListener; import net.micode.notes.R; +/** + * 下拉菜单类 + * 封装下拉菜单的功能 + */ public class DropdownMenu { private Button mButton; private PopupMenu mPopupMenu; diff --git a/src/Notes-master/src/net/micode/notes/ui/FoldersListAdapter.java b/src/Notes-master/src/net/micode/notes/ui/FoldersListAdapter.java index 96b77da..d0db70a 100644 --- a/src/Notes-master/src/net/micode/notes/ui/FoldersListAdapter.java +++ b/src/Notes-master/src/net/micode/notes/ui/FoldersListAdapter.java @@ -28,7 +28,10 @@ import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; - +/** + * 文件夹列表适配器 + * 用于在对话框中显示文件夹列表 + */ public class FoldersListAdapter extends CursorAdapter { public static final String [] PROJECTION = { NoteColumns.ID, diff --git a/src/Notes-master/src/net/micode/notes/ui/NoteEditText.java b/src/Notes-master/src/net/micode/notes/ui/NoteEditText.java index 2afe2a8..964aee0 100644 --- a/src/Notes-master/src/net/micode/notes/ui/NoteEditText.java +++ b/src/Notes-master/src/net/micode/notes/ui/NoteEditText.java @@ -37,6 +37,10 @@ import net.micode.notes.R; import java.util.HashMap; import java.util.Map; +/** + * 笔记编辑文本控件 + * 扩展EditText,支持清单模式、删除、回车等特殊功能 + */ public class NoteEditText extends EditText { private static final String TAG = "NoteEditText"; private int mIndex; diff --git a/src/Notes-master/src/net/micode/notes/ui/NoteItemData.java b/src/Notes-master/src/net/micode/notes/ui/NoteItemData.java index 0f5a878..ff1caf8 100644 --- a/src/Notes-master/src/net/micode/notes/ui/NoteItemData.java +++ b/src/Notes-master/src/net/micode/notes/ui/NoteItemData.java @@ -25,7 +25,10 @@ import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.tool.DataUtils; - +/** + * 笔记项数据类 + * 封装笔记列表项的数据信息 + */ public class NoteItemData { static final String [] PROJECTION = new String [] { NoteColumns.ID, diff --git a/src/Notes-master/src/net/micode/notes/ui/NotesListAdapter.java b/src/Notes-master/src/net/micode/notes/ui/NotesListAdapter.java index 51c9cb9..4a6e519 100644 --- a/src/Notes-master/src/net/micode/notes/ui/NotesListAdapter.java +++ b/src/Notes-master/src/net/micode/notes/ui/NotesListAdapter.java @@ -30,16 +30,28 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; - +/** + * 笔记列表适配器 + * 用于在ListView中显示笔记列表,支持多选模式 + */ public class NotesListAdapter extends CursorAdapter { private static final String TAG = "NotesListAdapter"; + /** 上下文对象 */ private Context mContext; + /** 选中的索引映射 */ private HashMap mSelectedIndex; + /** 笔记数量 */ private int mNotesCount; + /** 是否处于选择模式 */ private boolean mChoiceMode; + /** + * 小部件属性类 + */ public static class AppWidgetAttribute { + /** 小部件ID */ public int widgetId; + /** 小部件类型 */ public int widgetType; }; diff --git a/src/Notes-master/src/net/micode/notes/ui/NotesListItem.java b/src/Notes-master/src/net/micode/notes/ui/NotesListItem.java index 1221e80..112c913 100644 --- a/src/Notes-master/src/net/micode/notes/ui/NotesListItem.java +++ b/src/Notes-master/src/net/micode/notes/ui/NotesListItem.java @@ -29,7 +29,10 @@ import net.micode.notes.data.Notes; import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.ResourceParser.NoteItemBgResources; - +/** + * 笔记列表项视图 + * 用于在列表中显示单个笔记项 + */ public class NotesListItem extends LinearLayout { private ImageView mAlert; private TextView mTitle; diff --git a/src/Notes-master/src/net/micode/notes/ui/NotesPreferenceActivity.java b/src/Notes-master/src/net/micode/notes/ui/NotesPreferenceActivity.java index 07c5f7e..e13e62d 100644 --- a/src/Notes-master/src/net/micode/notes/ui/NotesPreferenceActivity.java +++ b/src/Notes-master/src/net/micode/notes/ui/NotesPreferenceActivity.java @@ -47,7 +47,10 @@ import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.gtask.remote.GTaskSyncService; - +/** + * 笔记设置活动 + * 提供应用的设置界面,包括账户管理、同步等功能 + */ public class NotesPreferenceActivity extends PreferenceActivity { public static final String PREFERENCE_NAME = "notes_preferences"; diff --git a/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java b/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java index ec6f819..7e881aa 100644 --- a/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java +++ b/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java @@ -32,19 +32,32 @@ import net.micode.notes.tool.ResourceParser; import net.micode.notes.ui.NoteEditActivity; import net.micode.notes.ui.NotesListActivity; +/** + * 笔记小部件提供者抽象类 + * 提供笔记桌面小部件的基础功能 + */ public abstract class NoteWidgetProvider extends AppWidgetProvider { + /** 查询投影字段 */ public static final String [] PROJECTION = new String [] { NoteColumns.ID, NoteColumns.BG_COLOR_ID, NoteColumns.SNIPPET }; + /** ID列索引 */ public static final int COLUMN_ID = 0; + /** 背景颜色ID列索引 */ public static final int COLUMN_BG_COLOR_ID = 1; + /** 内容摘要列索引 */ public static final int COLUMN_SNIPPET = 2; private static final String TAG = "NoteWidgetProvider"; + /** + * 当小部件被删除时调用 + * @param context 上下文对象 + * @param appWidgetIds 被删除的小部件ID数组 + */ @Override public void onDeleted(Context context, int[] appWidgetIds) { ContentValues values = new ContentValues(); @@ -57,6 +70,12 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { } } + /** + * 获取笔记小部件信息 + * @param context 上下文对象 + * @param widgetId 小部件ID + * @return 笔记信息游标 + */ private Cursor getNoteWidgetInfo(Context context, int widgetId) { return context.getContentResolver().query(Notes.CONTENT_NOTE_URI, PROJECTION, @@ -65,10 +84,23 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { null); } + /** + * 更新小部件 + * @param context 上下文对象 + * @param appWidgetManager 小部件管理器 + * @param appWidgetIds 小部件ID数组 + */ protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { update(context, appWidgetManager, appWidgetIds, false); } + /** + * 更新小部件(私有方法) + * @param context 上下文对象 + * @param appWidgetManager 小部件管理器 + * @param appWidgetIds 小部件ID数组 + * @param privacyMode 隐私模式 + */ private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, boolean privacyMode) { for (int i = 0; i < appWidgetIds.length; i++) { @@ -104,7 +136,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { rv.setImageViewResource(R.id.widget_bg_image, getBgResourceId(bgId)); intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId); /** - * Generate the pending intent to start host for the widget + * 生成待处理的意图,用于启动小部件的主活动 */ PendingIntent pendingIntent = null; if (privacyMode) { @@ -124,9 +156,22 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { } } + /** + * 获取背景资源ID(抽象方法,由子类实现) + * @param bgId 背景颜色ID + * @return 背景资源ID + */ protected abstract int getBgResourceId(int bgId); + /** + * 获取布局ID(抽象方法,由子类实现) + * @return 布局资源ID + */ protected abstract int getLayoutId(); + /** + * 获取小部件类型(抽象方法,由子类实现) + * @return 小部件类型 + */ protected abstract int getWidgetType(); } diff --git a/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_2x.java b/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_2x.java index adcb2f7..d0728e4 100644 --- a/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_2x.java +++ b/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_2x.java @@ -23,7 +23,10 @@ import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.tool.ResourceParser; - +/** + * 2x2笔记小部件提供者 + * 提供2x2尺寸的桌面笔记小部件 + */ public class NoteWidgetProvider_2x extends NoteWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { diff --git a/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_4x.java b/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_4x.java index c12a02e..285dac2 100644 --- a/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_4x.java +++ b/src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_4x.java @@ -23,7 +23,10 @@ import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.tool.ResourceParser; - +/** + * 4x4笔记小部件提供者 + * 提供4x4尺寸的桌面笔记小部件 + */ public class NoteWidgetProvider_4x extends NoteWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {