From e7ac524263c3e3e4e30ae80dd84cb0ec192f9ccf Mon Sep 17 00:00:00 2001 From: weichunyi <2948523237@qq.com> Date: Tue, 27 May 2025 15:20:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E4=BE=BF=E7=AD=BE=E7=B1=BB?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/model/WorkingNote.java | 196 +++++++++++++++--- 1 file changed, 163 insertions(+), 33 deletions(-) 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..6681b89 100644 --- a/src/Notes-master/src/net/micode/notes/model/WorkingNote.java +++ b/src/Notes-master/src/net/micode/notes/model/WorkingNote.java @@ -31,37 +31,41 @@ 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[] { DataColumns.ID, DataColumns.CONTENT, @@ -72,6 +76,7 @@ public class WorkingNote { DataColumns.DATA4, }; + // 便签查询投影 public static final String[] NOTE_PROJECTION = new String[] { NoteColumns.PARENT_ID, NoteColumns.ALERTED_DATE, @@ -81,27 +86,25 @@ public class WorkingNote { NoteColumns.MODIFIED_DATE }; + // 数据列索引常量 private static final int DATA_ID_COLUMN = 0; - private static final int DATA_CONTENT_COLUMN = 1; - private static final int DATA_MIME_TYPE_COLUMN = 2; - private static final int DATA_MODE_COLUMN = 3; + // 便签列索引常量 private static final int NOTE_PARENT_ID_COLUMN = 0; - private static final int NOTE_ALERTED_DATE_COLUMN = 1; - private static final int NOTE_BG_COLOR_ID_COLUMN = 2; - private static final int NOTE_WIDGET_ID_COLUMN = 3; - private static final int NOTE_WIDGET_TYPE_COLUMN = 4; - 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 +117,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 +132,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 +157,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 +188,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 +206,20 @@ public class WorkingNote { return note; } + /** + * 从数据库加载指定ID的便签 + * @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 +232,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 +245,18 @@ public class WorkingNote { } } + /** + * 判断便签是否已存在于数据库中 + * @return 存在返回true,否则返回false + */ public boolean existInDatabase() { return mNoteId > 0; } + /** + * 判断便签是否值得保存(有实际内容或修改) + * @return 值得保存返回true,否则返回false + */ private boolean isWorthSaving() { if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) || (existInDatabase() && !mNote.isLocalModified())) { @@ -225,10 +266,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 +289,10 @@ public class WorkingNote { } } + /** + * 标记便签为已删除状态 + * @param mark 是否标记为删除 + */ public void markDeleted(boolean mark) { mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID @@ -247,6 +301,10 @@ public class WorkingNote { } } + /** + * 设置便签背景色 + * @param id 背景色ID + */ public void setBgColorId(int id) { if (id != mBgColorId) { mBgColorId = id; @@ -257,6 +315,10 @@ public class WorkingNote { } } + /** + * 设置便签模式(普通文本或待办列表) + * @param mode 模式值 + */ public void setCheckListMode(int mode) { if (mMode != mode) { if (mNoteSettingStatusListener != null) { @@ -267,6 +329,10 @@ public class WorkingNote { } } + /** + * 设置关联的小部件类型 + * @param type 小部件类型 + */ public void setWidgetType(int type) { if (type != mWidgetType) { mWidgetType = type; @@ -274,6 +340,10 @@ public class WorkingNote { } } + /** + * 设置关联的小部件ID + * @param id 小部件ID + */ public void setWidgetId(int id) { if (id != mWidgetId) { mWidgetId = id; @@ -281,6 +351,10 @@ public class WorkingNote { } } + /** + * 设置便签文本内容 + * @param text 文本内容 + */ public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { mContent = text; @@ -288,81 +362,137 @@ 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,否则返回false + */ public boolean hasClockAlert() { return (mAlertDate > 0 ? true : false); } + /** + * 获取便签内容 + * @return 便签内容字符串 + */ public String getContent() { return mContent; } + /** + * 获取提醒日期 + * @return 提醒日期时间戳 + */ public long getAlertDate() { return mAlertDate; } + /** + * 获取修改日期 + * @return 修改日期时间戳 + */ public long getModifiedDate() { return mModifiedDate; } + /** + * 获取背景色资源ID + * @return 背景色资源ID + */ public int getBgColorResId() { return NoteBgResources.getNoteBgResource(mBgColorId); } + /** + * 获取背景色ID + * @return 背景色ID + */ public int getBgColorId() { return mBgColorId; } + /** + * 获取便签标题背景资源ID + * @return 标题背景资源ID + */ public int getTitleBgResId() { return NoteBgResources.getNoteTitleBgResource(mBgColorId); } + /** + * 获取便签模式 + * @return 便签模式值 + */ public int getCheckListMode() { return mMode; } + /** + * 获取便签ID + * @return 便签ID + */ public long getNoteId() { return mNoteId; } + /** + * 获取所属文件夹ID + * @return 文件夹ID + */ public long getFolderId() { return mFolderId; } + /** + * 获取关联的小部件ID + * @return 小部件ID + */ public int getWidgetId() { return mWidgetId; } + /** + * 获取关联的小部件类型 + * @return 小部件类型 + */ public int getWidgetType() { return mWidgetType; } + /** + * 便签设置变更监听器接口 + */ public interface NoteSettingChangedListener { /** - * Called when the background color of current note has just changed + * 当便签背景色变更时调用 */ void onBackgroundColorChanged(); /** - * Called when user set clock + * 当用户设置提醒时钟时调用 */ 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); } -} +} \ No newline at end of file