From 120dc034e5cf31092912b6648fa8e9bc753e0e10 Mon Sep 17 00:00:00 2001 From: zlj <12288937+zlj1014@user.noreply.gitee.com> Date: Sun, 18 May 2025 18:56:39 +0800 Subject: [PATCH] zhushi --- .../exception/ActionFailureException.java | 43 ++- .../exception/NetworkFailureException.java | 41 ++- src/net/micode/notes/model/Note.java | 70 +++- src/net/micode/notes/model/WorkingNote.java | 326 ++++++++++++------ src/net/micode/notes/tool/BackupUtils.java | 76 ++-- src/net/micode/notes/tool/DataUtils.java | 108 +++++- .../micode/notes/tool/GTaskStringUtils.java | 136 +++++--- src/net/micode/notes/tool/ResourceParser.java | 101 ++++-- .../micode/notes/ui/AlarmAlertActivity.java | 57 ++- .../micode/notes/ui/AlarmInitReceiver.java | 27 +- src/net/micode/notes/ui/AlarmReceiver.java | 24 +- src/net/micode/notes/ui/DateTimePicker.java | 59 +++- .../micode/notes/ui/DateTimePickerDialog.java | 62 +++- src/net/micode/notes/ui/DropdownMenu.java | 41 ++- .../micode/notes/ui/FoldersListAdapter.java | 62 +++- src/net/micode/notes/ui/NoteEditActivity.java | 71 ++-- src/net/micode/notes/ui/NoteEditText.java | 23 +- src/net/micode/notes/ui/NoteItemData.java | 5 + .../micode/notes/ui/NotesListActivity.java | 9 +- src/net/micode/notes/ui/NotesListAdapter.java | 3 +- src/net/micode/notes/ui/NotesListItem.java | 4 +- .../notes/ui/NotesPreferenceActivity.java | 2 + .../notes/widget/NoteWidgetProvider.java | 57 ++- .../notes/widget/NoteWidgetProvider_2x.java | 30 +- .../notes/widget/NoteWidgetProvider_4x.java | 31 +- 25 files changed, 1076 insertions(+), 392 deletions(-) diff --git a/src/net/micode/notes/gtask/exception/ActionFailureException.java b/src/net/micode/notes/gtask/exception/ActionFailureException.java index 15504be..4325cbf 100644 --- a/src/net/micode/notes/gtask/exception/ActionFailureException.java +++ b/src/net/micode/notes/gtask/exception/ActionFailureException.java @@ -15,19 +15,34 @@ */ package net.micode.notes.gtask.exception; - +/** + * ActionFailureException 是一个运行时异常,表示在执行某个操作(如同步、创建、更新)过程中发生失败。 + * 通常用于封装与远程服务器交互时发生的错误信息。 + */ public class ActionFailureException extends RuntimeException { - private static final long serialVersionUID = 4425249765923293627L; - - public ActionFailureException() { - super(); - } - - public ActionFailureException(String paramString) { - super(paramString); - } - - public ActionFailureException(String paramString, Throwable paramThrowable) { - super(paramString, paramThrowable); - } + /** 用于序列化版本控制的唯一标识符 */ +private static final long serialVersionUID = 4425249765923293627L; +/** + * 创建一个无消息的 ActionFailureException 实例。 + */ +public ActionFailureException() { + super(); +} +/** + * 创建带有指定详细消息的 ActionFailureException 实例。 + * + * @param paramString 异常描述信息 + */ +public ActionFailureException(String paramString) { + super(paramString); +} +/** + * 创建带有详细消息和底层异常原因的 ActionFailureException 实例。 + * + * @param paramString 异常描述信息 + * @param paramThrowable 底层异常原因 + */ +public ActionFailureException(String paramString, Throwable paramThrowable) { + super(paramString, paramThrowable); +} } diff --git a/src/net/micode/notes/gtask/exception/NetworkFailureException.java b/src/net/micode/notes/gtask/exception/NetworkFailureException.java index b08cfb1..e84bf34 100644 --- a/src/net/micode/notes/gtask/exception/NetworkFailureException.java +++ b/src/net/micode/notes/gtask/exception/NetworkFailureException.java @@ -15,19 +15,36 @@ */ package net.micode.notes.gtask.exception; - +/** + * NetworkFailureException 是一个异常类,用于表示在网络请求过程中发生的错误。 + * 通常在与远程服务器同步数据时,遇到网络连接问题会抛出此异常。 + */ public class NetworkFailureException extends Exception { - private static final long serialVersionUID = 2107610287180234136L; - - public NetworkFailureException() { - super(); - } +/** 用于序列化版本控制的唯一标识符 */ +private static final long serialVersionUID = 2107610287180234136L; +/** + * 创建一个无消息的 NetworkFailureException 实例。 + */ +public NetworkFailureException() { + super(); +} - public NetworkFailureException(String paramString) { - super(paramString); - } +/** + * 创建带有指定详细消息的 NetworkFailureException 实例。 + * + * @param paramString 异常描述信息 + */ +public NetworkFailureException(String paramString) { + super(paramString); +} - public NetworkFailureException(String paramString, Throwable paramThrowable) { - super(paramString, paramThrowable); - } +/** + * 创建带有详细消息和底层异常原因的 NetworkFailureException 实例。 + * + * @param paramString 异常描述信息 + * @param paramThrowable 底层异常原因 + */ +public NetworkFailureException(String paramString, Throwable paramThrowable) { + super(paramString, paramThrowable); +} } diff --git a/src/net/micode/notes/model/Note.java b/src/net/micode/notes/model/Note.java index 6706cf6..a34d0b2 100644 --- a/src/net/micode/notes/model/Note.java +++ b/src/net/micode/notes/model/Note.java @@ -32,15 +32,26 @@ import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.TextNote; import java.util.ArrayList; +/** + * Note 是用于管理笔记内容的模型类,支持创建、更新文本笔记和通话笔记。 + * 它封装了与 ContentProvider 交互的逻辑,并提供本地修改同步到数据库的功能。 + */ +public class Note { +/** 存储笔记主信息的差异值(如标题、修改时间等) */ +private ContentValues mNoteDiffValues; +/** 封装笔记数据内容(如文本、通话记录)的对象 */ +private NoteData mNoteData; -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 - */ +/** 日志标签 */ +private static final String TAG = "Note"; +/** + * 获取一个新的笔记 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(); @@ -64,18 +75,29 @@ public class Note { } return noteId; } - - public Note() { - mNoteDiffValues = new ContentValues(); - mNoteData = new NoteData(); - } - +/** + * 创建一个新的 Note 实例,初始化笔记差异值和笔记数据对象。 + */ +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); } @@ -88,6 +110,12 @@ public class Note { return mNoteData.mTextDataId; } +/** + * 设置通话笔记的内容字段值。 + * + * @param key 字段名 + * @param value 字段值 + */ public void setCallDataId(long id) { mNoteData.setCallDataId(id); } @@ -121,7 +149,11 @@ public class Note { // Do not return, fall through } mNoteDiffValues.clear(); - +/** + * 判断该笔记是否有本地修改。 + * + * @return 是否有未保存的更改 + */ if (mNoteData.isLocalModified() && (mNoteData.pushIntoContentResolver(context, noteId) == null)) { return false; @@ -177,7 +209,13 @@ public class Note { 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 diff --git a/src/net/micode/notes/model/WorkingNote.java b/src/net/micode/notes/model/WorkingNote.java index be081e4..f19544b 100644 --- a/src/net/micode/notes/model/WorkingNote.java +++ b/src/net/micode/notes/model/WorkingNote.java @@ -31,77 +31,91 @@ import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.TextNote; import net.micode.notes.tool.ResourceParser.NoteBgResources; - +/** + * WorkingNote 是用于编辑和管理单个笔记的核心类,支持新建、加载、保存笔记及其相关数据。 + * 它封装了与 ContentProvider 的交互逻辑,并提供了设置更改监听器以响应用户操作。 + */ public class WorkingNote { - // Note for the working note - private Note mNote; - // Note Id - private long mNoteId; - // Note content - private String mContent; - // Note mode - private int mMode; - - private long mAlertDate; - - private long mModifiedDate; - - private int mBgColorId; - - private int mWidgetId; - - private int mWidgetType; - - 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, - DataColumns.MIME_TYPE, - DataColumns.DATA1, - DataColumns.DATA2, - DataColumns.DATA3, - DataColumns.DATA4, - }; - - public static final String[] NOTE_PROJECTION = new String[] { - NoteColumns.PARENT_ID, - NoteColumns.ALERTED_DATE, - NoteColumns.BG_COLOR_ID, - NoteColumns.WIDGET_ID, - NoteColumns.WIDGET_TYPE, - 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 Note mNote; + +/** 当前笔记的 ID */ +private long mNoteId; + +/** 笔记内容文本 */ +private String mContent; + +/** 编辑模式(如普通笔记、清单等) */ +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, + DataColumns.MIME_TYPE, + DataColumns.DATA1, + DataColumns.DATA2, + DataColumns.DATA3, + DataColumns.DATA4, +}; + +/** 查询笔记表时使用的列投影数组 */ +public static final String[] NOTE_PROJECTION = new String[] { + NoteColumns.PARENT_ID, + NoteColumns.ALERTED_DATE, + NoteColumns.BG_COLOR_ID, + NoteColumns.WIDGET_ID, + NoteColumns.WIDGET_TYPE, + 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; +/** + * 创建一个新的空白笔记实例。 + * + * @param context 上下文对象 + * @param folderId 所属文件夹 ID + */ private WorkingNote(Context context, long folderId) { mContext = context; mAlertDate = 0; @@ -113,8 +127,13 @@ public class WorkingNote { mMode = 0; 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; @@ -123,7 +142,9 @@ public class WorkingNote { mNote = new Note(); loadNote(); } - +/** + * 从数据库加载笔记主信息。 + */ private void loadNote() { Cursor cursor = mContext.getContentResolver().query( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, @@ -145,7 +166,9 @@ public class WorkingNote { } loadNoteData(); } - +/** + * 从数据库加载笔记内容数据(如文本、通话记录)。 + */ private void loadNoteData() { Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { @@ -173,7 +196,16 @@ public class WorkingNote { throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId); } } - +/** + * 创建一个空笔记并设置默认值。 + * + * @param context 上下文对象 + * @param folderId 所属文件夹 ID + * @param widgetId 小部件 ID + * @param widgetType 小部件类型 + * @param defaultBgColorId 默认背景颜色 ID + * @return 新建的 WorkingNote 实例 + */ public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { WorkingNote note = new WorkingNote(context, folderId); @@ -182,11 +214,21 @@ public class WorkingNote { note.setWidgetType(widgetType); return note; } - +/** + * 加载指定 ID 的笔记。 + * + * @param context 上下文对象 + * @param id 笔记 ID + * @return 已加载的 WorkingNote 实例 + */ public static WorkingNote load(Context context, long id) { return new WorkingNote(context, id, 0); } - +/** + * 保存当前笔记到数据库。 + * + * @return 是否保存成功 + */ public synchronized boolean saveNote() { if (isWorthSaving()) { if (!existInDatabase()) { @@ -224,11 +266,20 @@ public class WorkingNote { return true; } } - +/** + * 设置笔记设置更改监听器。 + * + * @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; @@ -238,7 +289,11 @@ public class WorkingNote { mNoteSettingStatusListener.onClockAlertChanged(date, set); } } - +/** + * 标记笔记是否被删除。 + * + * @param mark 是否标记为删除 + */ public void markDeleted(boolean mark) { mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID @@ -246,7 +301,11 @@ public class WorkingNote { mNoteSettingStatusListener.onWidgetChanged(); } } - +/** + * 设置背景颜色 ID。 + * + * @param id 颜色 ID + */ public void setBgColorId(int id) { if (id != mBgColorId) { mBgColorId = id; @@ -256,7 +315,11 @@ public class WorkingNote { mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id)); } } - +/** + * 设置检查列表模式。 + * + * @param mode 模式值 + */ public void setCheckListMode(int mode) { if (mMode != mode) { if (mNoteSettingStatusListener != null) { @@ -266,28 +329,45 @@ public class WorkingNote { mNote.setTextData(TextNote.MODE, String.valueOf(mMode)); } } - +/** + * 设置小部件类型。 + * + * @param type 小部件类型 + */ public void setWidgetType(int type) { if (type != mWidgetType) { mWidgetType = type; mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType)); } } - +/** + * 设置小部件 ID。 + * + * @param id 小部件 ID + */ public void setWidgetId(int id) { if (id != mWidgetId) { mWidgetId = id; mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId)); } } - +/** + * 设置笔记内容文本。 + * + * @param text 内容文本 + */ public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { mContent = text; mNote.setTextData(DataColumns.CONTENT, mContent); } } - +/** + * 将笔记转换为通话记录笔记。 + * + * @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); @@ -297,23 +377,43 @@ public class WorkingNote { 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; } @@ -341,28 +441,32 @@ public class WorkingNote { 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 - */ +/** + * 笔记设置更改监听器接口,用于监听笔记相关的 UI 更新事件。 + */ +public interface NoteSettingChangedListener { + /** + * 当笔记背景颜色发生变化时调用。 + */ + void onBackgroundColorChanged(); + /** + * 当用户设置了闹钟提醒或取消时调用。 + * + * @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 - */ + /** + * 当从小部件创建笔记时调用。 + */ + void onWidgetChanged(); + /** + * 当切换检查列表模式时调用。 + * + * @param oldMode 旧模式 + * @param newMode 新模式 + */ void onCheckListModeChanged(int oldMode, int newMode); } } diff --git a/src/net/micode/notes/tool/BackupUtils.java b/src/net/micode/notes/tool/BackupUtils.java index 39f6ec4..9156f4b 100644 --- a/src/net/micode/notes/tool/BackupUtils.java +++ b/src/net/micode/notes/tool/BackupUtils.java @@ -35,9 +35,14 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; - +/** + * BackupUtils 是一个工具类,用于将笔记数据导出为文本文件以便备份。 + * 它提供了与外部存储相关的操作,并支持单例模式以确保全局访问点。 + */ public class BackupUtils { - private static final String TAG = "BackupUtils"; +/** 日志标签 */ +private static final String TAG = "BackupUtils"; + // Singleton stuff private static BackupUtils sInstance; @@ -52,7 +57,8 @@ public class BackupUtils { * Following states are signs to represents backup or restore * status */ - // Currently, the sdcard is not mounted + +/** 导出/恢复状态码 */ public static final int STATE_SD_CARD_UNMOUONTED = 0; // The backup file not exist public static final int STATE_BACKUP_FILE_NOT_EXIST = 1; @@ -84,7 +90,10 @@ public class BackupUtils { public String getExportedTextFileDir() { return mTextExport.mFileDirectory; } - +/** + * TextExport 是 BackupUtils 的内部类,负责将笔记内容格式化并导出为文本文件。 + * 它封装了查询数据库、生成输出内容等逻辑。 + */ private static class TextExport { private static final String[] NOTE_PROJECTION = { NoteColumns.ID, @@ -124,21 +133,33 @@ public class BackupUtils { private Context mContext; private String mFileName; private String mFileDirectory; - +/** + * 创建 TextExport 实例。 + * + * @param context 上下文对象 + */ public TextExport(Context context) { TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); mContext = context; mFileName = ""; mFileDirectory = ""; } - +/** + * 获取指定索引的格式字符串。 + * + * @param id 格式资源 ID + * @return 对应格式字符串 + */ private String getFormat(int id) { return TEXT_FORMAT[id]; } - /** - * Export the folder identified by folder id to text - */ + /** + * 将指定文件夹中的所有笔记导出到文本流。 + * + * @param folderId 文件夹 ID + * @param ps 输出流 + */ private void exportFolderToText(String folderId, PrintStream ps) { // Query notes belong to this folder Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI, @@ -162,9 +183,12 @@ public class BackupUtils { } } - /** - * Export note identified by id to a print stream - */ + /** + * 将指定笔记导出到文本流。 + * + * @param noteId 笔记 ID + * @param ps 输出流 + */ private void exportNoteToText(String noteId, PrintStream ps) { Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { @@ -215,9 +239,11 @@ public class BackupUtils { } } - /** - * Note will be exported as text which is user readable - */ + /** + * 将所有笔记数据导出为可读文本文件。 + * + * @return 操作结果状态码(STATE_XXX) + */ public int exportToText() { if (!externalStorageAvailable()) { Log.d(TAG, "Media was not mounted"); @@ -282,9 +308,11 @@ public class BackupUtils { return STATE_SUCCESS; } - /** - * Get a print stream pointed to the file {@generateExportedTextFile} - */ +/** + * 获取指向导出文件的 PrintStream。 + * + * @return PrintStream 实例或 null + */ private PrintStream getExportToTextPrintStream() { File file = generateFileMountedOnSDcard(mContext, R.string.file_path, R.string.file_name_txt_format); @@ -308,10 +336,14 @@ public class BackupUtils { return ps; } } - - /** - * Generate the text file to store imported data - */ +/** + * 在 SD 卡上生成用于导出数据的文件。 + * + * @param context 上下文对象 + * @param filePathResId 文件路径资源 ID + * @param fileNameFormatResId 文件名格式资源 ID + * @return 生成的 File 对象 或 null + */ private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { StringBuilder sb = new StringBuilder(); sb.append(Environment.getExternalStorageDirectory()); diff --git a/src/net/micode/notes/tool/DataUtils.java b/src/net/micode/notes/tool/DataUtils.java index 2a14982..8bce8b4 100644 --- a/src/net/micode/notes/tool/DataUtils.java +++ b/src/net/micode/notes/tool/DataUtils.java @@ -34,10 +34,20 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import java.util.ArrayList; import java.util.HashSet; - +/** + * DataUtils 是一个工具类,提供与数据操作相关的通用方法。 + * 主要包括批量删除、移动笔记、查询数据、检查是否存在等数据库操作。 + */ public class DataUtils { - public static final String TAG = "DataUtils"; - public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { +/** 日志标签 */ +public static final String TAG = "DataUtils"; +/** + * 批量删除指定 ID 的笔记。 + * + * @param resolver ContentResolver 实例 + * @param ids 要删除的笔记 ID 集合 + * @return 是否删除成功 + */ public static boolean batchDeleteNotes(ContentResolver resolver, HashSet ids) { if (ids == null) { Log.d(TAG, "the ids is null"); return true; @@ -71,7 +81,14 @@ 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); @@ -79,7 +96,14 @@ public class DataUtils { values.put(NoteColumns.LOCAL_MODIFIED, 1); resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); } - +/** + * 批量将一组笔记移动到指定文件夹。 + * + * @param resolver ContentResolver 实例 + * @param ids 要移动的笔记 ID 集合 + * @param folderId 目标文件夹 ID + * @return 是否移动成功 + */ public static boolean batchMoveToFolder(ContentResolver resolver, HashSet ids, long folderId) { if (ids == null) { @@ -135,7 +159,14 @@ public class DataUtils { } return count; } - +/** + * 判断指定类型的笔记是否存在于数据库中且未被删除。 + * + * @param resolver ContentResolver 实例 + * @param noteId 笔记 ID + * @param type 笔记类型 + * @return 是否存在 + */ public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, @@ -152,7 +183,13 @@ public class DataUtils { } return exist; } - +/** + * 判断指定 ID 的笔记是否存在于数据库中。 + * + * @param resolver ContentResolver 实例 + * @param noteId 笔记 ID + * @return 是否存在 + */ public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, null, null, null); @@ -166,7 +203,13 @@ public class DataUtils { } return exist; } - +/** + * 判断指定 ID 的数据项是否存在于数据表中。 + * + * @param resolver ContentResolver 实例 + * @param dataId 数据项 ID + * @return 是否存在 + */ public static boolean existInDataDatabase(ContentResolver resolver, long dataId) { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null, null, null, null); @@ -180,7 +223,13 @@ public class DataUtils { } return exist; } - +/** + * 检查指定名称的可见文件夹是否已存在。 + * + * @param resolver ContentResolver 实例 + * @param name 文件夹名称 + * @return 是否存在相同名称的文件夹 + */ public static boolean checkVisibleFolderName(ContentResolver resolver, String name) { Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null, NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + @@ -196,7 +245,13 @@ public class DataUtils { } return exist; } - +/** + * 获取指定文件夹中所有笔记关联的小部件信息。 + * + * @param resolver ContentResolver 实例 + * @param folderId 文件夹 ID + * @return 包含小部件属性的集合 + */ public static HashSet getFolderNoteWidget(ContentResolver resolver, long folderId) { Cursor c = resolver.query(Notes.CONTENT_NOTE_URI, new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, @@ -223,7 +278,13 @@ public class DataUtils { } return set; } - +/** + * 根据笔记 ID 获取通话记录中的电话号码。 + * + * @param resolver ContentResolver 实例 + * @param noteId 笔记 ID + * @return 电话号码字符串 + */ public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) { Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, new String [] { CallNote.PHONE_NUMBER }, @@ -242,7 +303,14 @@ public class DataUtils { } return ""; } - +/** + * 根据电话号码和通话时间查找对应的笔记 ID。 + * + * @param resolver ContentResolver 实例 + * @param phoneNumber 电话号码 + * @param callDate 通话时间戳 + * @return 笔记 ID,若未找到则返回 0 + */ public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) { Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, new String [] { CallNote.NOTE_ID }, @@ -263,7 +331,14 @@ public class DataUtils { } return 0; } - +/** + * 根据笔记 ID 获取摘要内容。 + * + * @param resolver ContentResolver 实例 + * @param noteId 笔记 ID + * @return 摘要内容字符串 + * @throws IllegalArgumentException 如果未找到对应笔记 + */ public static String getSnippetById(ContentResolver resolver, long noteId) { Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, new String [] { NoteColumns.SNIPPET }, @@ -281,7 +356,12 @@ public class DataUtils { } throw new IllegalArgumentException("Note is not found with id: " + noteId); } - +/** + * 对原始摘要内容进行格式化处理,去除首尾空格并截取第一行。 + * + * @param snippet 原始摘要内容 + * @return 格式化后的摘要 + */ public static String getFormattedSnippet(String snippet) { if (snippet != null) { snippet = snippet.trim(); diff --git a/src/net/micode/notes/tool/GTaskStringUtils.java b/src/net/micode/notes/tool/GTaskStringUtils.java index 666b729..4a7e435 100644 --- a/src/net/micode/notes/tool/GTaskStringUtils.java +++ b/src/net/micode/notes/tool/GTaskStringUtils.java @@ -15,99 +15,129 @@ */ package net.micode.notes.tool; - +/** + * GTaskStringUtils 是一个常量类,定义了与 Google Tasks 同步相关的 JSON 字段名和特殊字符串。 + * 用于统一管理远程同步时的字段名称、类型标识和元数据结构。 + */ public class GTaskStringUtils { - public final static String GTASK_JSON_ACTION_ID = "action_id"; - - public final static String GTASK_JSON_ACTION_LIST = "action_list"; - - public final static String GTASK_JSON_ACTION_TYPE = "action_type"; - - public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; - - public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; - - public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; - - public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; + /** 操作 ID 字段名 */ +public final static String GTASK_JSON_ACTION_ID = "action_id"; - public final static String GTASK_JSON_CREATOR_ID = "creator_id"; +/** 操作列表字段名 */ +public final static String GTASK_JSON_ACTION_LIST = "action_list"; - public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; +/** 操作类型字段名 */ +public final static String GTASK_JSON_ACTION_TYPE = "action_type"; - public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; +/** 操作类型:创建 */ +public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; - public final static String GTASK_JSON_COMPLETED = "completed"; +/** 操作类型:获取全部 */ +public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; - public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; +/** 操作类型:移动 */ +public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; - public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; +/** 操作类型:更新 */ +public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; - public final static String GTASK_JSON_DELETED = "deleted"; +/** 创建者 ID 字段名 */ +public final static String GTASK_JSON_CREATOR_ID = "creator_id"; - public final static String GTASK_JSON_DEST_LIST = "dest_list"; +/** 子实体字段名 */ +public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; - public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; +/** 客户端版本字段名 */ +public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; - public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; +/** 是否完成字段名 */ +public final static String GTASK_JSON_COMPLETED = "completed"; - public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; +/** 当前任务列表 ID 字段名 */ +public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; - public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; +/** 默认任务列表 ID 字段名 */ +public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; - public final static String GTASK_JSON_GET_DELETED = "get_deleted"; +/** 是否删除字段名 */ +public final static String GTASK_JSON_DELETED = "deleted"; - public final static String GTASK_JSON_ID = "id"; +/** 目标位置字段名 */ +public final static String GTASK_JSON_DEST_LIST = "dest_list"; - public final static String GTASK_JSON_INDEX = "index"; +/** 目标父节点字段名 */ +public final static String GTASK_JSON_DEST_PARENT = "dest_parent"; - public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; +/** 目标父节点类型字段名 */ +public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type"; - public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; +/** 实体差异内容字段名 */ +public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta"; - public final static String GTASK_JSON_LIST_ID = "list_id"; +/** 实体类型字段名 */ +public final static String GTASK_JSON_ENTITY_TYPE = "entity_type"; - public final static String GTASK_JSON_LISTS = "lists"; +/** 获取已删除项字段名 */ +public final static String GTASK_JSON_GET_DELETED = "get_deleted"; - public final static String GTASK_JSON_NAME = "name"; +/** 实体唯一标识字段名 */ +public final static String GTASK_JSON_ID = "id"; - public final static String GTASK_JSON_NEW_ID = "new_id"; +/** 索引字段名 */ +public final static String GTASK_JSON_INDEX = "index"; - public final static String GTASK_JSON_NOTES = "notes"; +/** 最后修改时间字段名 */ +public final static String GTASK_JSON_LAST_MODIFIED = "last_modified"; - public final static String GTASK_JSON_PARENT_ID = "parent_id"; +/** 最新同步点字段名 */ +public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point"; - public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; +/** 列表 ID 字段名 */ +public final static String GTASK_JSON_LIST_ID = "list_id"; - public final static String GTASK_JSON_RESULTS = "results"; +/** 列表集合字段名 */ +public final static String GTASK_JSON_LISTS = "lists"; - public final static String GTASK_JSON_SOURCE_LIST = "source_list"; +/** 名称字段名 */ +public final static String GTASK_JSON_NAME = "name"; - public final static String GTASK_JSON_TASKS = "tasks"; +/** 新 ID 字段名 */ +public final static String GTASK_JSON_NEW_ID = "new_id"; - public final static String GTASK_JSON_TYPE = "type"; +/** 备注字段名 */ +public final static String GTASK_JSON_NOTES = "notes"; - public final static String GTASK_JSON_TYPE_GROUP = "GROUP"; +/** 父节点 ID 字段名 */ +public final static String GTASK_JSON_PARENT_ID = "parent_id"; - public final static String GTASK_JSON_TYPE_TASK = "TASK"; +/** 上一个兄弟节点 ID 字段名 */ +public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id"; - public final static String GTASK_JSON_USER = "user"; +/** - public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; +/** MIUI 笔记文件夹名称前缀 */ +public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]"; - public final static String FOLDER_DEFAULT = "Default"; +/** 默认文件夹名称 */ +public final static String FOLDER_DEFAULT = "Default"; - public final static String FOLDER_CALL_NOTE = "Call_Note"; +/** 通话笔记文件夹名称 */ +public final static String FOLDER_CALL_NOTE = "Call_Note"; - public final static String FOLDER_META = "METADATA"; +/** 元数据标识符 */ +public final static String FOLDER_META = "METADATA"; - public final static String META_HEAD_GTASK_ID = "meta_gid"; +/** 元数据中的 GID 字段名 */ +public final static String META_HEAD_GTASK_ID = "meta_gid"; - public final static String META_HEAD_NOTE = "meta_note"; +/** 元数据中的笔记信息字段名 */ +public final static String META_HEAD_NOTE = "meta_note"; - public final static String META_HEAD_DATA = "meta_data"; +/** 元数据中的内容信息字段名 */ +public final static String META_HEAD_DATA = "meta_data"; - public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; +/** 元数据笔记名称(用于标记元信息) */ +public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";D DELETE"; } diff --git a/src/net/micode/notes/tool/ResourceParser.java b/src/net/micode/notes/tool/ResourceParser.java index 1e54125..4224383 100644 --- a/src/net/micode/notes/tool/ResourceParser.java +++ b/src/net/micode/notes/tool/ResourceParser.java @@ -21,25 +21,35 @@ import android.preference.PreferenceManager; import net.micode.notes.R; import net.micode.notes.ui.NotesPreferenceActivity; - +/** + * ResourceParser 是一个资源解析工具类,用于获取与用户设置相关的 UI 资源(如背景、字体大小等)。 + * 它包含多个静态内部类,分别管理笔记背景、小部件背景和文本样式等资源。 + */ 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 { +/** 笔记颜色常量:黄、蓝、白、绿、红 */ +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; + +/** 默认背景颜色 ID */ +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; +/** + * NoteBgResources 管理笔记编辑界面的背景资源。 + * 提供根据颜色 ID 获取对应背景图片资源的方法。 + */ +public static class NoteBgResources { + // 背景和标题栏资源数组定义 private final static int [] BG_EDIT_RESOURCES = new int [] { R.drawable.edit_yellow, R.drawable.edit_blue, @@ -55,16 +65,32 @@ public class ResourceParser { R.drawable.edit_title_green, R.drawable.edit_title_red }; - + /** + * 获取笔记内容区域的背景资源 ID。 + * + * @param id 颜色 ID + * @return 对应的 drawable 资源 ID + */ public static int getNoteBgResource(int id) { return BG_EDIT_RESOURCES[id]; } - + /** + * 获取笔记标题栏的背景资源 ID。 + * + * @param id 颜色 ID + * @return 对应的 drawable 资源 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)) { @@ -106,23 +132,48 @@ public class ResourceParser { R.drawable.list_green_single, R.drawable.list_red_single }; - + /** + * 获取列表项顶部位置的背景资源 ID。 + * + * @param id 颜色 ID + * @return drawable 资源 ID + */ public static int getNoteBgFirstRes(int id) { return BG_FIRST_RESOURCES[id]; } + /** + * 获取列表项底部位置的背景资源 ID。 + * + * @param id 颜色 ID + * @return drawable 资源 ID + */ public static int getNoteBgLastRes(int id) { return BG_LAST_RESOURCES[id]; } - + /** + * 获取单独显示的列表项背景资源 ID。 + * + * @param id 颜色 ID + * @return drawable 资源 ID + */ public static int getNoteBgSingleRes(int id) { return BG_SINGLE_RESOURCES[id]; } - + /** + * 获取列表项中间位置的背景资源 ID。 + * + * @param id 颜色 ID + * @return drawable 资源 ID + */ public static int getNoteBgNormalRes(int id) { return BG_NORMAL_RESOURCES[id]; } - + /** + * 获取文件夹的背景资源 ID。 + * + * @return drawable 资源 ID + */ public static int getFolderBgRes() { return R.drawable.list_folder; } diff --git a/src/net/micode/notes/ui/AlarmAlertActivity.java b/src/net/micode/notes/ui/AlarmAlertActivity.java index 85723be..4c2ff94 100644 --- a/src/net/micode/notes/ui/AlarmAlertActivity.java +++ b/src/net/micode/notes/ui/AlarmAlertActivity.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.micode.notes.ui; +package net.micode.notess.ui; import android.app.Activity; import android.app.AlertDialog; @@ -39,13 +39,29 @@ import net.micode.notes.tool.DataUtils; import java.io.IOException; +/** + * AlarmAlertActivity 是用于显示闹钟提醒并播放提示音的 Activity。 + * 当用户设置的提醒时间到达时,该 Activity 会弹出对话框并播放默认闹钟铃声。 + */ +public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener { private long mNoteId; + /** 当前提醒对应的笔记 ID */ +private long mNoteId; + +/** 笔记摘要内容(用于显示在对话框中) */ +private String mSnippet; -public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener { - private long mNoteId; - private String mSnippet; - private static final int SNIPPET_PREW_MAX_LEN = 60; - MediaPlayer mPlayer; +/** 最大显示长度限制 */ +private static final int SNIPPET_PREW_MAX_LEN = 60; +/** 媒体播放器实例,用于播放闹钟声音 */ +MediaPlayer mPlayer; +/** + * 初始化 Activity 并准备闹钟提醒。 + * + * - 设置窗口标志以在锁屏界面显示 + * - 获取笔记 ID 和摘要 + * - 播放闹钟声音并显示提醒对话框 + */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -82,12 +98,19 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD finish(); } } - +/** + * 判断当前屏幕是否处于点亮状态。 + * + * @return 是否亮屏 + */ private boolean isScreenOn() { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); return pm.isScreenOn(); } - +/** + * 播放系统默认的闹钟铃声。 + * 根据静音模式调整音频流类型,并循环播放。 + */ private void playAlarmSound() { Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM); @@ -118,7 +141,13 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD e.printStackTrace(); } } - +/** + * 显示闹钟提醒对话框,包含: + * - 应用名称作为标题 + * - 笔记摘要内容 + * - “确定”按钮 + * - 如果屏幕已亮,则显示“查看详情”按钮 + */ private void showActionDialog() { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.app_name); @@ -129,7 +158,11 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD } dialog.show().setOnDismissListener(this); } - +/** + * 对话框按钮点击事件处理。 + * + * - 点击“查看详情”:跳转到 NoteEditActivity 查看笔记 + */ public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_NEGATIVE: @@ -142,7 +175,9 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD break; } } - +/** + * 当对话框被关闭时停止闹钟声音并结束当前 Activity。 + */ public void onDismiss(DialogInterface dialog) { stopAlarmSound(); finish(); diff --git a/src/net/micode/notes/ui/AlarmInitReceiver.java b/src/net/micode/notes/ui/AlarmInitReceiver.java index f221202..9393219 100644 --- a/src/net/micode/notes/ui/AlarmInitReceiver.java +++ b/src/net/micode/notes/ui/AlarmInitReceiver.java @@ -27,17 +27,32 @@ import android.database.Cursor; import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; - +/** + * AlarmInitReceiver 是一个 BroadcastReceiver,用于初始化所有未来提醒的闹钟。 + * 它在系统启动或应用被触发时重新设置已存在的提醒笔记的闹钟。 + */ public class AlarmInitReceiver extends BroadcastReceiver { - - private static final String [] PROJECTION = new String [] { +/** 查询笔记表时使用的列投影(ID 和提醒时间) */ +private static final String[] PROJECTION = new String[] { NoteColumns.ID, NoteColumns.ALERTED_DATE - }; +}; - private static final int COLUMN_ID = 0; - private static final int COLUMN_ALERTED_DATE = 1; +/** 列索引:笔记 ID */ +private static final int COLUMN_ID = 0; +/** 列索引:提醒时间 */ +private static final int COLUMN_ALERTED_DATE = 1; +/** + * 接收到广播后执行的方法,用于初始化所有未来的闹钟提醒。 + * + * - 查询所有设置了提醒时间且未过期的笔记 + * - 为每个笔记设置对应的闹钟 PendingIntent + * - 使用 AlarmManager 设置 RTC_WAKEUP 类型的定时提醒 + * + * @param context 上下文对象 + * @param intent 广播意图 + */ @Override public void onReceive(Context context, Intent intent) { long currentDate = System.currentTimeMillis(); diff --git a/src/net/micode/notes/ui/AlarmReceiver.java b/src/net/micode/notes/ui/AlarmReceiver.java index 54e503b..7f590f7 100644 --- a/src/net/micode/notes/ui/AlarmReceiver.java +++ b/src/net/micode/notes/ui/AlarmReceiver.java @@ -19,12 +19,22 @@ package net.micode.notes.ui; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; - +/** + * AlarmReceiver 是一个 BroadcastReceiver,用于接收系统闹钟事件并启动提醒界面。 + * 当用户设定的笔记提醒时间到达时,会触发此广播并启动 AlarmAlertActivity 显示提醒。 + */ public class AlarmReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - intent.setClass(context, AlarmAlertActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); - } + /** + * 接收到闹钟广播后执行的方法。 + * 启动 AlarmAlertActivity 以显示笔记提醒界面。 + * + * @param context 上下文对象 + * @param intent 广播意图 + */ +@Override +public void onReceive(Context context, Intent intent) { + intent.setClass(context, AlarmAlertActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); +} } diff --git a/src/net/micode/notes/ui/DateTimePicker.java b/src/net/micode/notes/ui/DateTimePicker.java index 496b0cd..f10a2cf 100644 --- a/src/net/micode/notes/ui/DateTimePicker.java +++ b/src/net/micode/notes/ui/DateTimePicker.java @@ -27,14 +27,22 @@ import android.text.format.DateFormat; import android.view.View; import android.widget.FrameLayout; import android.widget.NumberPicker; - +/** + * DateTimePicker 是一个自定义视图组件,用于选择日期和时间。 + * 它由多个 NumberPicker 组成,支持 24 小时制或 AM/PM 模式,并提供日期变化监听器回调。 + */ public class DateTimePicker extends FrameLayout { +/** 默认启用状态 */ +private static final boolean DEFAULT_ENABLE_STATE = true; - private static final boolean DEFAULT_ENABLE_STATE = true; +/** 12 小时制中的小时数 */ +private static final int HOURS_IN_HALF_DAY = 12; - private static final int HOURS_IN_HALF_DAY = 12; - private static final int HOURS_IN_ALL_DAY = 24; - private static final int DAYS_IN_ALL_WEEK = 7; +/** 24 小时制中的最大值 */ +private static final int HOURS_IN_ALL_DAY = 24; + +/** 一周天数 */ +private static final int DAYS_IN_ALL_WEEK = 7; private static final int DATE_SPINNER_MIN_VAL = 0; private static final int DATE_SPINNER_MAX_VAL = DAYS_IN_ALL_WEEK - 1; private static final int HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW = 0; @@ -46,26 +54,41 @@ public class DateTimePicker extends FrameLayout { private static final int AMPM_SPINNER_MIN_VAL = 0; private static final int AMPM_SPINNER_MAX_VAL = 1; - private final NumberPicker mDateSpinner; - private final NumberPicker mHourSpinner; - private final NumberPicker mMinuteSpinner; - private final NumberPicker mAmPmSpinner; - private Calendar mDate; + /** 日期选择器 */ +private final NumberPicker mDateSpinner; - private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK]; +/** 小时选择器 */ +private final NumberPicker mHourSpinner; - private boolean mIsAm; +/** 分钟选择器 */ +private final NumberPicker mMinuteSpinner; - private boolean mIs24HourView; +/** AM/PM 选择器 */ +private final NumberPicker mAmPmSpinner; - private boolean mIsEnabled = DEFAULT_ENABLE_STATE; +/** 当前日期时间(Calendar) */ +private Calendar mDate; - private boolean mInitialising; +/** 显示的日期字符串数组 */ +private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK]; - private OnDateTimeChangedListener mOnDateTimeChangedListener; +/** 是否是 AM(仅在非 24 小时模式下有效) */ +private boolean mIsAm; - private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() { - @Override +/** 是否使用 24 小时制 */ +private boolean mIs24HourView; + +/** 控件是否启用 */ +private boolean mIsEnabled = DEFAULT_ENABLE_STATE; + +/** 是否正在初始化 */ +private boolean mInitialising; + +/** 日期时间变化监听器 */ +/** + * 当日期或时间发生变化时的回调接口。 + */ +private OnDateTimeChangedListener mOnDateTimeChangedListener; @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal); updateDateControl(); diff --git a/src/net/micode/notes/ui/DateTimePickerDialog.java b/src/net/micode/notes/ui/DateTimePickerDialog.java index 2c47ba4..16e762b 100644 --- a/src/net/micode/notes/ui/DateTimePickerDialog.java +++ b/src/net/micode/notes/ui/DateTimePickerDialog.java @@ -28,18 +28,38 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.text.format.DateFormat; import android.text.format.DateUtils; - +/** + * DateTimePickerDialog 是一个基于 AlertDialog 的日期时间选择对话框。 + * 它封装了 DateTimePicker 控件,并提供设置监听器以获取用户选择的时间。 + */ public class DateTimePickerDialog extends AlertDialog implements OnClickListener { +/** 当前选中的日期时间(Calendar) */ +private Calendar mDate = Calendar.getInstance(); - private Calendar mDate = Calendar.getInstance(); - private boolean mIs24HourView; - private OnDateTimeSetListener mOnDateTimeSetListener; - private DateTimePicker mDateTimePicker; +/** 是否使用 24 小时制显示时间 */ +private boolean mIs24HourView; - public interface OnDateTimeSetListener { - void OnDateTimeSet(AlertDialog dialog, long date); - } +/** 日期时间设置完成后的回调接口 */ +private OnDateTimeSetListener mOnDateTimeSetListener; +/** 内部使用的 DateTimePicker 控件实例 */ +/** + * 当用户点击“确定”按钮后触发的回调接口。 + */ +public interface OnDateTimeSetListener { + /** + * 用户选择完日期和时间后调用。 + * + * @param dialog 对话框本身 + * @param date 用户选择的日期时间(毫秒) + */ void OnDateTimeSet(AlertDialog dialog, long date); + } +/** + * 创建一个新的日期时间选择对话框。 + * + * @param context 上下文对象 + * @param date 初始时间(毫秒) + */ public DateTimePickerDialog(Context context, long date) { super(context); mDateTimePicker = new DateTimePicker(context); @@ -63,15 +83,27 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener set24HourView(DateFormat.is24HourFormat(this.getContext())); updateTitle(mDate.getTimeInMillis()); } - +/** + * 设置是否使用 24 小时格式显示时间。 + * + * @param is24HourView true 表示使用 24 小时制 + */ public void set24HourView(boolean is24HourView) { mIs24HourView = is24HourView; } - +/** + * 设置日期时间选择完成后的监听器。 + * + * @param callBack 监听器对象 + */ public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) { mOnDateTimeSetListener = callBack; } - +/** + * 更新对话框标题,显示当前选择的日期和时间。 + * + * @param date 时间戳(毫秒) + */ private void updateTitle(long date) { int flag = DateUtils.FORMAT_SHOW_YEAR | @@ -80,7 +112,13 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR; setTitle(DateUtils.formatDateTime(this.getContext(), date, flag)); } - +/** + * 对话框按钮点击事件处理。 + * 如果设置了 OnDateTimeSetListener,则在点击“确定”按钮时回调。 + * + * @param arg0 对话框界面对象 + * @param arg1 点击的按钮类型 + */ public void onClick(DialogInterface arg0, int arg1) { if (mOnDateTimeSetListener != null) { mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis()); diff --git a/src/net/micode/notes/ui/DropdownMenu.java b/src/net/micode/notes/ui/DropdownMenu.java index 613dc74..271216e 100644 --- a/src/net/micode/notes/ui/DropdownMenu.java +++ b/src/net/micode/notes/ui/DropdownMenu.java @@ -26,12 +26,26 @@ import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; import net.micode.notes.R; - +/** + * DropdownMenu 是一个封装了下拉菜单功能的组件,结合 Button 和 PopupMenu 实现。 + * 用于在 UI 中提供点击按钮弹出菜单的功能,常用于操作菜单或选项选择。 + */ public class DropdownMenu { - private Button mButton; - private PopupMenu mPopupMenu; - private Menu mMenu; +/** 触发菜单显示的按钮对象 */ +private Button mButton; +/** 弹出菜单实例 */ +private PopupMenu mPopupMenu; + +/** 菜单对象,用于管理菜单项 */ +private Menu mMenu; +/** + * 创建并初始化一个下拉菜单。 + * + * @param context 上下文对象 + * @param button 关联的按钮控件 + * @param menuId 菜单资源 ID + */ public DropdownMenu(Context context, Button button, int menuId) { mButton = button; mButton.setBackgroundResource(R.drawable.dropdown_icon); @@ -44,17 +58,30 @@ public class DropdownMenu { } }); } - +/** + * 设置菜单项点击事件监听器。 + * + * @param listener 菜单项点击监听器 + */ public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) { if (mPopupMenu != null) { mPopupMenu.setOnMenuItemClickListener(listener); } } - +/** + * 根据菜单项 ID 查找对应的 MenuItem。 + * + * @param id 菜单项 ID + * @return 找到的 MenuItem 对象 + */ public MenuItem findItem(int id) { return mMenu.findItem(id); } - +/** + * 设置触发按钮的显示文本(即菜单标题)。 + * + * @param title 要设置的标题 + */ public void setTitle(CharSequence title) { mButton.setText(title); } diff --git a/src/net/micode/notes/ui/FoldersListAdapter.java b/src/net/micode/notes/ui/FoldersListAdapter.java index 96b77da..3967153 100644 --- a/src/net/micode/notes/ui/FoldersListAdapter.java +++ b/src/net/micode/notes/ui/FoldersListAdapter.java @@ -27,27 +27,51 @@ import android.widget.TextView; import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; - +/** + * FoldersListAdapter 是一个基于 CursorAdapter 的适配器,用于显示文件夹列表。 + * 它绑定数据库中的笔记文件夹数据到 `FolderListItem` 视图中。 + */ public class FoldersListAdapter extends CursorAdapter { - public static final String [] PROJECTION = { + /** 查询使用的列投影:ID 和 SNIPPET(文件夹名称) */ +public static final String[] PROJECTION = { NoteColumns.ID, NoteColumns.SNIPPET - }; +}; +/** 列索引定义 */ public static final int ID_COLUMN = 0; public static final int NAME_COLUMN = 1; - +/** + * 创建一个新的 FoldersListAdapter 实例。 + * + * @param context 上下文对象 + * @param c 数据游标(需包含 ID 和 SNIPPET 字段) + */ public FoldersListAdapter(Context context, Cursor c) { super(context, c); // TODO Auto-generated constructor stub } - +/** + * 创建一个新的视图项(FolderListItem)。 + * + * @param context 上下文对象 + * @param cursor 当前数据游标位置 + * @param parent 父容器 + * @return 新创建的 View 对象 + */ @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { return new FolderListItem(context); } - +/** + * 将当前游标位置的数据绑定到指定视图。 + * 如果是系统根目录文件夹,则显示特殊名称。 + * + * @param view 要绑定的视图 + * @param context 上下文对象 + * @param cursor 当前数据游标位置 + */ @Override public void bindView(View view, Context context, Cursor cursor) { if (view instanceof FolderListItem) { @@ -56,22 +80,40 @@ public class FoldersListAdapter extends CursorAdapter { ((FolderListItem) view).bind(folderName); } } - +/** + * 获取指定位置的文件夹名称。 + * 如果是系统根目录文件夹,返回本地化的“上级文件夹”字符串。 + * + * @param context 上下文对象 + * @param position 数据位置 + * @return 文件夹名称 + */ public String getFolderName(Context context, int position) { Cursor cursor = (Cursor) getItem(position); return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); } - +/** + * FolderListItem 是一个 LinearLayout 子类,表示文件夹列表中的单个条目。 + * 包含一个 TextView 显示文件夹名称。 + */ private class FolderListItem extends LinearLayout { private TextView mName; - +/** + * 创建一个新的 FolderListItem 实例。 + * + * @param context 上下文对象 + */ public FolderListItem(Context context) { super(context); inflate(context, R.layout.folder_list_item, this); mName = (TextView) findViewById(R.id.tv_folder_name); } - +/** + * 绑定文件夹名称到视图中。 + * + * @param name 文件夹名称 + */ public void bind(String name) { mName.setText(name); } diff --git a/src/net/micode/notes/ui/NoteEditActivity.java b/src/net/micode/notes/ui/NoteEditActivity.java index 96a9ff8..b1e0616 100644 --- a/src/net/micode/notes/ui/NoteEditActivity.java +++ b/src/net/micode/notes/ui/NoteEditActivity.java @@ -71,18 +71,19 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; - +/** + * NoteEditActivity 是用于编辑笔记内容的核心 Activity。 + * 支持文本编辑、设置提醒、更改背景颜色、字体大小、清单模式等,并提供保存、删除、分享等功能。 + */ public class NoteEditActivity extends Activity implements OnClickListener, NoteSettingChangedListener, OnTextViewChangeListener { private class HeadViewHolder { - public TextView tvModified; - - public ImageView ivAlertIcon; - - public TextView tvAlertDate; - - public ImageView ibSetBgColor; + public TextView tvModified; // 最后修改时间 + public ImageView ivAlertIcon; // 提醒图标 + public TextView tvAlertDate; // 提醒日期 + public ImageView ibSetBgColor; // 设置背景按钮 } +/** 背景颜色选择按钮与对应颜色 ID 的映射 */ private static final Map sBgSelectorBtnsMap = new HashMap(); static { @@ -93,6 +94,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE); } +/** 颜色选择器中当前选中状态的图标资源映射 */ private static final Map sBgSelectorSelectionMap = new HashMap(); static { sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select); @@ -101,7 +103,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, sBgSelectorSelectionMap.put(ResourceParser.GREEN, R.id.iv_bg_green_select); sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select); } - +/** 字体大小选择按钮与对应 ID 的映射 */ private static final Map sFontSizeBtnsMap = new HashMap(); static { sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE); @@ -109,7 +111,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, sFontSizeBtnsMap.put(R.id.ll_font_normal, ResourceParser.TEXT_MEDIUM); sFontSizeBtnsMap.put(R.id.ll_font_super, ResourceParser.TEXT_SUPER); } - +/** 字体大小选择器中当前选中状态的图标资源映射 */ private static final Map sFontSelectorSelectionMap = new HashMap(); static { sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select); @@ -120,22 +122,29 @@ public class NoteEditActivity extends Activity implements OnClickListener, private static final String TAG = "NoteEditActivity"; - private HeadViewHolder mNoteHeaderHolder; + /** 顶部标题栏视图容器 */ +private View mHeadViewPanel; - private View mHeadViewPanel; +/** 背景色选择器视图 */ +private View mNoteBgColorSelector; - private View mNoteBgColorSelector; +/** 字体大小选择器视图 */ +private View mFontSizeSelector; - private View mFontSizeSelector; +/** 编辑区域的 EditText */ +private EditText mNoteEditor; - private EditText mNoteEditor; +/** 编辑区域的整体容器 */ +private View mNoteEditorPanel; - private View mNoteEditorPanel; +/** 当前正在编辑的 WorkingNote 对象 */ +private WorkingNote mWorkingNote; - private WorkingNote mWorkingNote; +/** SharedPreferences 实例,用于存储用户偏好 */ +private SharedPreferences mSharedPrefs; - private SharedPreferences mSharedPrefs; - private int mFontSizeId; +/** 当前使用的字体大小 ID(TEXT_SMALL, TEXT_MEDIUM 等) */ +private int mFontSizeId; private static final String PREFERENCE_FONT_SIZE = "pref_font_size"; @@ -148,7 +157,10 @@ public class NoteEditActivity extends Activity implements OnClickListener, private String mUserQuery; private Pattern mPattern; - +/** + * 初始化界面并加载笔记数据。 + * 如果是新建笔记或已有笔记,会根据 Intent 初始化不同状态。 + */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -161,10 +173,9 @@ public class NoteEditActivity extends Activity implements OnClickListener, initResources(); } - /** - * Current activity may be killed when the memory is low. Once it is killed, for another time - * user load this activity, we should restore the former state - */ + /** + * 恢复被销毁前的状态,如从内存不足恢复。 + */ @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); @@ -267,7 +278,13 @@ public class NoteEditActivity extends Activity implements OnClickListener, super.onResume(); initNoteScreen(); } - +/** + * 根据 Intent 初始化 Activity 状态。 + * + * - 加载已有笔记或创建新笔记 + * - 处理来电记录笔记的特殊逻辑 + * - 设置软键盘行为 + */ private void initNoteScreen() { mNoteEditor.setTextAppearance(this, TextAppearanceResources .getTexAppearanceResource(mFontSizeId)); @@ -294,7 +311,9 @@ public class NoteEditActivity extends Activity implements OnClickListener, */ showAlertHeader(); } - +/** + * 根据当前笔记是否有闹钟提醒,更新头部提示信息。 + */ private void showAlertHeader() { if (mWorkingNote.hasClockAlert()) { long time = System.currentTimeMillis(); diff --git a/src/net/micode/notes/ui/NoteEditText.java b/src/net/micode/notes/ui/NoteEditText.java index 2afe2a8..ca40bf8 100644 --- a/src/net/micode/notes/ui/NoteEditText.java +++ b/src/net/micode/notes/ui/NoteEditText.java @@ -36,15 +36,24 @@ import net.micode.notes.R; import java.util.HashMap; import java.util.Map; - +/** + * NoteEditText 是对 EditText 的扩展,用于支持清单模式下的条目管理。 + * 支持按键事件处理(如删除、回车)、上下文菜单链接识别和文本变化监听。 + */ public class NoteEditText extends EditText { - private static final String TAG = "NoteEditText"; + /** 日志标签 */ +private static final String TAG = "NoteEditText"; private int mIndex; private int mSelectionStartBeforeDelete; - private static final String SCHEME_TEL = "tel:" ; - private static final String SCHEME_HTTP = "http:" ; - private static final String SCHEME_EMAIL = "mailto:" ; +/** 电话链接前缀 */ +private static final String SCHEME_TEL = "tel:"; + +/** 网页链接前缀 */ +private static final String SCHEME_HTTP = "http:"; + +/** 邮件链接前缀 */ +private static final String SCHEME_EMAIL = "mailto:"; private static final Map sSchemaActionResMap = new HashMap(); static { @@ -53,9 +62,7 @@ public class NoteEditText extends EditText { sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email); } - /** - * Call by the {@link NoteEditActivity} to delete or add edit text - */ + /** 文本视图变化监听器 */ public interface OnTextViewChangeListener { /** * Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens diff --git a/src/net/micode/notes/ui/NoteItemData.java b/src/net/micode/notes/ui/NoteItemData.java index 0f5a878..47dd3bc 100644 --- a/src/net/micode/notes/ui/NoteItemData.java +++ b/src/net/micode/notes/ui/NoteItemData.java @@ -25,7 +25,12 @@ import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.tool.DataUtils; +/** + * NoteItemData 是用于封装笔记列表项数据的模型类。 + * 从数据库 Cursor 中提取信息并提供结构化访问方法,适用于 UI 显示逻辑。 + */ + /** 查询笔记时使用的列投影 */ public class NoteItemData { static final String [] PROJECTION = new String [] { NoteColumns.ID, diff --git a/src/net/micode/notes/ui/NotesListActivity.java b/src/net/micode/notes/ui/NotesListActivity.java index e843aec..345c807 100644 --- a/src/net/micode/notes/ui/NotesListActivity.java +++ b/src/net/micode/notes/ui/NotesListActivity.java @@ -77,7 +77,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashSet; - +/** + * NotesListActivity 是应用主界面,用于展示笔记列表和文件夹,并支持新建、编辑、删除、同步等操作。 + * 它是用户与笔记系统交互的核心入口。 + */ public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener { private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0; @@ -90,8 +93,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt private static final int MENU_FOLDER_CHANGE_NAME = 2; private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction"; - - private enum ListEditState { +/** 当前处于的列表状态:普通笔记列表、子文件夹、通话记录文件夹 */ +private enum ListEditState { NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER }; diff --git a/src/net/micode/notes/ui/NotesListAdapter.java b/src/net/micode/notes/ui/NotesListAdapter.java index 51c9cb9..a2fae49 100644 --- a/src/net/micode/notes/ui/NotesListAdapter.java +++ b/src/net/micode/notes/ui/NotesListAdapter.java @@ -30,7 +30,8 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; - +// 这是一个继承自 CursorAdapter 的适配器类,用于将笔记数据绑定到 UI 上的列表项。 +// 主要功能包括创建和更新列表项视图、支持选择模式下的多选操作、提供获取已选项目等功能。 public class NotesListAdapter extends CursorAdapter { private static final String TAG = "NotesListAdapter"; private Context mContext; diff --git a/src/net/micode/notes/ui/NotesListItem.java b/src/net/micode/notes/ui/NotesListItem.java index 1221e80..afd3c3a 100644 --- a/src/net/micode/notes/ui/NotesListItem.java +++ b/src/net/micode/notes/ui/NotesListItem.java @@ -30,6 +30,8 @@ import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.ResourceParser.NoteItemBgResources; +// 继承自 LinearLayout,用于表示笔记列表中的一个条目。 +// 负责展示笔记的标题、修改时间、提醒图标等信息,并支持选择模式下的复选框显示。 public class NotesListItem extends LinearLayout { private ImageView mAlert; private TextView mTitle; @@ -98,7 +100,7 @@ public class NotesListItem extends LinearLayout { setBackground(data); } - +// 根据笔记数据设置背景资源。对于不同类型的笔记(如第一个、最后一个、单独项等),应用不同的背景样式;对于文件夹则使用统一的背景样式。 private void setBackground(NoteItemData data) { int id = data.getBgColorId(); if (data.getType() == Notes.TYPE_NOTE) { diff --git a/src/net/micode/notes/ui/NotesPreferenceActivity.java b/src/net/micode/notes/ui/NotesPreferenceActivity.java index 07c5f7e..6c1d8b5 100644 --- a/src/net/micode/notes/ui/NotesPreferenceActivity.java +++ b/src/net/micode/notes/ui/NotesPreferenceActivity.java @@ -48,6 +48,8 @@ import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.gtask.remote.GTaskSyncService; +// 继承自 PreferenceActivity,用于管理笔记应用的设置偏好界面。 +// 提供了同步账户设置、手动同步按钮控制、账户选择对话框等功能,并监听 Google 任务同步服务的状态变化以更新 UI。 public class NotesPreferenceActivity extends PreferenceActivity { public static final String PREFERENCE_NAME = "notes_preferences"; diff --git a/src/net/micode/notes/widget/NoteWidgetProvider.java b/src/net/micode/notes/widget/NoteWidgetProvider.java index ec6f819..132d86c 100644 --- a/src/net/micode/notes/widget/NoteWidgetProvider.java +++ b/src/net/micode/notes/widget/NoteWidgetProvider.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// NoteWidgetProvider 是一个抽象类,作为不同尺寸便签小部件(如 2x、4x)的基础类 package net.micode.notes.widget; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; @@ -32,19 +33,28 @@ import net.micode.notes.tool.ResourceParser; import net.micode.notes.ui.NoteEditActivity; import net.micode.notes.ui.NotesListActivity; +/** + * 所有便签小部件提供者的基类,定义了通用功能并声明了抽象方法供子类实现 + */ public abstract class NoteWidgetProvider extends AppWidgetProvider { + // 查询数据库时使用的投影字段:ID、背景颜色ID、便签内容片段 public static final String [] PROJECTION = new String [] { NoteColumns.ID, NoteColumns.BG_COLOR_ID, NoteColumns.SNIPPET }; - +// 对应PROJECTION数组中各字段的索引 public static final int COLUMN_ID = 0; public static final int COLUMN_BG_COLOR_ID = 1; public static final int COLUMN_SNIPPET = 2; private static final String TAG = "NoteWidgetProvider"; - + /** + * 当小部件被删除时,清除对应数据库中的小部件ID + * + * @param context 应用上下文 + * @param appWidgetIds 被删除的小部件ID数组 + */ @Override public void onDeleted(Context context, int[] appWidgetIds) { ContentValues values = new ContentValues(); @@ -56,7 +66,13 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { new String[] { String.valueOf(appWidgetIds[i])}); } } - + /** + * 获取指定小部件ID对应的便签信息 + * + * @param context 应用上下文 + * @param widgetId 小部件ID + * @return 包含便签信息的Cursor对象 + */ private Cursor getNoteWidgetInfo(Context context, int widgetId) { return context.getContentResolver().query(Notes.CONTENT_NOTE_URI, PROJECTION, @@ -64,11 +80,24 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) }, null); } - + /** + * 更新指定的小部件(调用带隐私模式的重载方法) + * + * @param context 应用上下文 + * @param appWidgetManager 小部件管理器 + * @param appWidgetIds 要更新的小部件ID数组 + */ protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { update(context, appWidgetManager, appWidgetIds, false); } - + /** + * 根据给定的小部件ID更新小部件的内容与样式 + * + * @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++) { @@ -123,10 +152,24 @@ 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/net/micode/notes/widget/NoteWidgetProvider_2x.java b/src/net/micode/notes/widget/NoteWidgetProvider_2x.java index adcb2f7..4648dbb 100644 --- a/src/net/micode/notes/widget/NoteWidgetProvider_2x.java +++ b/src/net/micode/notes/widget/NoteWidgetProvider_2x.java @@ -23,23 +23,45 @@ import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.tool.ResourceParser; - +/** + * 这个类负责管理2x大小便签小部件的行为和外观 + */ public class NoteWidgetProvider_2x extends NoteWidgetProvider { + /** + * 更新指定的2x便签小部件 + * + * @param context 应用上下文 + * @param appWidgetManager 小部件管理器 + * @param appWidgetIds 要更新的小部件ID数组 + */ @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.update(context, appWidgetManager, appWidgetIds); } - + /** + * 获取2x小部件使用的布局资源ID + * + * @return 布局资源ID + */ @Override protected int getLayoutId() { return R.layout.widget_2x; } - + /** + * 根据背景ID获取2x小部件的背景资源 + * + * @param bgId 背景ID + * @return 对应的背景资源ID + */ @Override protected int getBgResourceId(int bgId) { return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId); } - + /** + * 获取小部件类型 + * + * @return 小部件类型(这里是2x类型) + */ @Override protected int getWidgetType() { return Notes.TYPE_WIDGET_2X; diff --git a/src/net/micode/notes/widget/NoteWidgetProvider_4x.java b/src/net/micode/notes/widget/NoteWidgetProvider_4x.java index c12a02e..73003bb 100644 --- a/src/net/micode/notes/widget/NoteWidgetProvider_4x.java +++ b/src/net/micode/notes/widget/NoteWidgetProvider_4x.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// NoteWidgetProvider_4x类继承自NoteWidgetProvider,用于提供4x小部件的具体功能 package net.micode.notes.widget; import android.appwidget.AppWidgetManager; @@ -22,23 +23,45 @@ import android.content.Context; import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.tool.ResourceParser; - +/** + * 这个类负责管理4x大小便签小部件的行为和外观 + */ public class NoteWidgetProvider_4x extends NoteWidgetProvider { + /** + * 更新指定的4x便签小部件 + * + * @param context 应用上下文 + * @param appWidgetManager 小部件管理器 + * @param appWidgetIds 要更新的小部件ID数组 + */ @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.update(context, appWidgetManager, appWidgetIds); } - + /** + * 获取4x小部件使用的布局资源ID + * + * @return 布局资源ID + */ protected int getLayoutId() { return R.layout.widget_4x; } - + /** + * 根据背景ID获取4x小部件的背景资源 + * + * @param bgId 背景ID + * @return 对应的背景资源ID + */ @Override protected int getBgResourceId(int bgId) { return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId); } - + /** + * 获取小部件类型 + * + * @return 小部件类型(这里是4x类型) + */ @Override protected int getWidgetType() { return Notes.TYPE_WIDGET_4X;