From 4fa8b57f09efbf0f88c7661ac908bd53d3d36fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E6=9D=A1=E9=B1=BC=E5=92=8Cxiao?= <15185717938@163.com> Date: Wed, 14 May 2025 19:39:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/net/micode/notes/model/WorkingNote.java | 192 ++++++++++---------- 1 file changed, 101 insertions(+), 91 deletions(-) diff --git a/src/net/micode/notes/model/WorkingNote.java b/src/net/micode/notes/model/WorkingNote.java index be081e4..99e7d33 100644 --- a/src/net/micode/notes/model/WorkingNote.java +++ b/src/net/micode/notes/model/WorkingNote.java @@ -31,37 +31,40 @@ 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 +75,7 @@ public class WorkingNote { DataColumns.DATA4, }; + // 笔记查询投影 public static final String[] NOTE_PROJECTION = new String[] { NoteColumns.PARENT_ID, NoteColumns.ALERTED_DATE, @@ -81,27 +85,23 @@ 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; @@ -114,7 +114,9 @@ public class WorkingNote { mWidgetType = Notes.TYPE_WIDGET_INVALIDE; } - // Existing note construct + /** + * 加载现有笔记的构造函数 + */ private WorkingNote(Context context, long noteId, long folderId) { mContext = context; mNoteId = noteId; @@ -124,6 +126,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 +151,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 +182,9 @@ 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 +194,16 @@ 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()) { @@ -198,9 +215,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 && mNoteSettingStatusListener != null) { @@ -212,10 +227,16 @@ public class WorkingNote { } } + /** + * 检查笔记是否已存在于数据库 + */ public boolean existInDatabase() { return mNoteId > 0; } + /** + * 判断笔记是否值得保存 + */ private boolean isWorthSaving() { if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) || (existInDatabase() && !mNote.isLocalModified())) { @@ -225,10 +246,16 @@ public class WorkingNote { } } + /** + * 设置笔记设置变更监听器 + */ public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; } + /** + * 设置提醒日期 + */ public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { mAlertDate = date; @@ -239,6 +266,9 @@ public class WorkingNote { } } + /** + * 标记笔记为已删除 + */ public void markDeleted(boolean mark) { mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID @@ -247,6 +277,9 @@ public class WorkingNote { } } + /** + * 设置背景颜色 + */ public void setBgColorId(int id) { if (id != mBgColorId) { mBgColorId = id; @@ -257,6 +290,9 @@ public class WorkingNote { } } + /** + * 设置清单模式 + */ public void setCheckListMode(int mode) { if (mMode != mode) { if (mNoteSettingStatusListener != null) { @@ -267,6 +303,9 @@ public class WorkingNote { } } + /** + * 设置小部件类型 + */ public void setWidgetType(int type) { if (type != mWidgetType) { mWidgetType = type; @@ -274,6 +313,9 @@ public class WorkingNote { } } + /** + * 设置小部件ID + */ public void setWidgetId(int id) { if (id != mWidgetId) { mWidgetId = id; @@ -281,6 +323,9 @@ public class WorkingNote { } } + /** + * 设置笔记文本内容 + */ public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { mContent = text; @@ -288,81 +333,46 @@ public class WorkingNote { } } + /** + * 转换为通话笔记 + */ 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; - } - - public int getBgColorResId() { - return NoteBgResources.getNoteBgResource(mBgColorId); - } - - public int getBgColorId() { - return mBgColorId; - } - - public int getTitleBgResId() { - return NoteBgResources.getNoteTitleBgResource(mBgColorId); - } - - public int getCheckListMode() { - return mMode; - } - - public long getNoteId() { - return mNoteId; - } - - public long getFolderId() { - return mFolderId; - } - - public int getWidgetId() { - return mWidgetId; - } - - public int getWidgetType() { - return mWidgetType; - } - + // 各种获取属性的方法 + public String getContent() { return mContent; } + public long getAlertDate() { return mAlertDate; } + public long getModifiedDate() { return mModifiedDate; } + public int getBgColorResId() { return NoteBgResources.getNoteBgResource(mBgColorId); } + public int getBgColorId() { return mBgColorId; } + public int getTitleBgResId() { return NoteBgResources.getNoteTitleBgResource(mBgColorId); } + public int getCheckListMode() { return mMode; } + public long getNoteId() { return mNoteId; } + public long getFolderId() { return mFolderId; } + 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 - */ + // 清单模式变更回调 void onCheckListModeChanged(int oldMode, int newMode); } -} +} \ No newline at end of file