From 1743880e1c79bf6c136d940cc39b4ddcd728f7e6 Mon Sep 17 00:00:00 2001 From: pwiz98tyo <1257800485@qq.com> Date: Thu, 12 Jun 2025 17:01:42 +0800 Subject: [PATCH] Update WorkingNote.java --- java/net/micode/notes/model/WorkingNote.java | 65 +++++++++++++------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/java/net/micode/notes/model/WorkingNote.java b/java/net/micode/notes/model/WorkingNote.java index be081e4..15c9e28 100644 --- a/java/net/micode/notes/model/WorkingNote.java +++ b/java/net/micode/notes/model/WorkingNote.java @@ -59,9 +59,9 @@ public class WorkingNote { 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 +72,7 @@ public class WorkingNote { DataColumns.DATA4, }; + //查询笔记的投影 public static final String[] NOTE_PROJECTION = new String[] { NoteColumns.PARENT_ID, NoteColumns.ALERTED_DATE, @@ -81,27 +82,21 @@ 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 + // 新建笔记的构造函数 private WorkingNote(Context context, long folderId) { mContext = context; mAlertDate = 0; @@ -115,6 +110,7 @@ public class WorkingNote { } // Existing note construct + // 加载现有笔记的构造函数 private WorkingNote(Context context, long noteId, long folderId) { mContext = context; mNoteId = noteId; @@ -124,6 +120,7 @@ public class WorkingNote { loadNote(); } + // 加载笔记基本信息 private void loadNote() { Cursor cursor = mContext.getContentResolver().query( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, @@ -145,7 +142,7 @@ 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 +171,7 @@ public class WorkingNote { } } + // 创建空笔记的静态方法 public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { WorkingNote note = new WorkingNote(context, folderId); @@ -183,10 +181,12 @@ public class WorkingNote { return note; } + // 加载现有笔记的静态方法 public static WorkingNote load(Context context, long id) { return new WorkingNote(context, id, 0); } + // 保存笔记 public synchronized boolean saveNote() { if (isWorthSaving()) { if (!existInDatabase()) { @@ -201,6 +201,7 @@ public class WorkingNote { /** * Update widget content if there exist any widget of this note */ + // 如果笔记关联了小部件,更新小部件内容 if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) { @@ -211,11 +212,13 @@ public class WorkingNote { return false; } } - + + // 检查笔记是否存在于数据库中 public boolean existInDatabase() { return mNoteId > 0; } + // 判断笔记是否值得保存 private boolean isWorthSaving() { if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) || (existInDatabase() && !mNote.isLocalModified())) { @@ -225,10 +228,11 @@ public class WorkingNote { } } + // 设置笔记设置变化监听器 public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; } - + // 设置提醒日期 public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { mAlertDate = date; @@ -239,6 +243,7 @@ public class WorkingNote { } } + // 标记笔记为已删除 public void markDeleted(boolean mark) { mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID @@ -247,6 +252,7 @@ public class WorkingNote { } } + // 设置背景颜色 public void setBgColorId(int id) { if (id != mBgColorId) { mBgColorId = id; @@ -257,6 +263,7 @@ public class WorkingNote { } } + // 设置清单模式 public void setCheckListMode(int mode) { if (mMode != mode) { if (mNoteSettingStatusListener != null) { @@ -267,6 +274,7 @@ public class WorkingNote { } } + // 设置小部件类型 public void setWidgetType(int type) { if (type != mWidgetType) { mWidgetType = type; @@ -274,6 +282,7 @@ public class WorkingNote { } } + // 设置小部件ID public void setWidgetId(int id) { if (id != mWidgetId) { mWidgetId = id; @@ -281,87 +290,101 @@ public class WorkingNote { } } + // 设置笔记文本内容 public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { mContent = text; mNote.setTextData(DataColumns.CONTENT, mContent); } } - + // 转换为通话记录笔记 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)); } + // 检查是否有提醒 public boolean hasClockAlert() { return (mAlertDate > 0 ? true : false); } + // 获取内容 public String getContent() { return mContent; } + // 获取提醒日期 public long getAlertDate() { return mAlertDate; } + // 获取修改日期 public long getModifiedDate() { return mModifiedDate; } + // 获取背景颜色资源ID public int getBgColorResId() { return NoteBgResources.getNoteBgResource(mBgColorId); } + // 获取背景颜色ID public int getBgColorId() { return mBgColorId; } + // 获取标题背景资源ID public int getTitleBgResId() { return NoteBgResources.getNoteTitleBgResource(mBgColorId); } + // 获取清单模式 public int getCheckListMode() { return mMode; } + // 获取笔记ID public long getNoteId() { return mNoteId; } + // 获取文件夹ID public long getFolderId() { return mFolderId; } + // 获取小部件ID public int getWidgetId() { return mWidgetId; } + // 获取小部件类型 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); }