diff --git a/doc/小米便签开源代码的泛读报告 - 副本.docx b/doc/小米便签开源代码的泛读报告 - 副本.docx deleted file mode 100644 index 92cdf69..0000000 Binary files a/doc/小米便签开源代码的泛读报告 - 副本.docx and /dev/null differ diff --git a/doc/示例:小米便签开源代码的质量分析报告 - 副本.docx b/doc/示例:小米便签开源代码的质量分析报告 - 副本.docx deleted file mode 100644 index 45f911a..0000000 Binary files a/doc/示例:小米便签开源代码的质量分析报告 - 副本.docx and /dev/null differ 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 166444b..da15e51 100644 --- a/src/Notes-master/src/net/micode/notes/data/Notes.java +++ b/src/Notes-master/src/net/micode/notes/data/Notes.java @@ -17,263 +17,288 @@ package net.micode.notes.data; import android.net.Uri; +// 定义一个名为Notes的公共类,用于管理笔记相关的常量和接口 public class Notes { + // 内容提供者的权限名称,用于在应用内标识该内容提供者 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; + // 表示笔记类型的常量 + 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; + // 用于在Intent中传递提醒日期的额外字段名称 public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date"; + // 用于在Intent中传递背景颜色ID的额外字段名称 public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id"; + // 用于在Intent中传递小部件ID的额外字段名称 public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_id"; + // 用于在Intent中传递小部件类型的额外字段名称 public static final String INTENT_EXTRA_WIDGET_TYPE = "net.micode.notes.widget_type"; + // 用于在Intent中传递文件夹ID的额外字段名称 public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id"; + // 用于在Intent中传递通话日期的额外字段名称 public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date"; - public static final int TYPE_WIDGET_INVALIDE = -1; - public static final int TYPE_WIDGET_2X = 0; - public static final int TYPE_WIDGET_4X = 1; + // 无效的小部件类型 + public static final int TYPE_WIDGET_INVALIDE = -1; + // 2x尺寸的小部件类型 + public static final int TYPE_WIDGET_2X = 0; + // 4x尺寸的小部件类型 + public static final int TYPE_WIDGET_4X = 1; + // 数据常量的内部类,用于存储不同类型数据的相关常量 public static class DataConstants { + // 文本笔记的内容类型 public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; + // 通话笔记的内容类型 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

+ * gtask的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

+ * 通用数据列,含义与{@link #MIMETYPE}相关,用于整数数据类型 + *

类型: INTEGER

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

Type: INTEGER

+ * 通用数据列,含义与{@link #MIMETYPE}相关,用于整数数据类型 + *

类型: INTEGER

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

Type: TEXT

+ * 通用数据列,含义与{@link #MIMETYPE}相关,用于文本数据类型 + *

类型: TEXT

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

Type: TEXT

+ * 通用数据列,含义与{@link #MIMETYPE}相关,用于文本数据类型 + *

类型: TEXT

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

Type: TEXT

+ * 通用数据列,含义与{@link #MIMETYPE}相关,用于文本数据类型 + *

类型: TEXT

*/ public static final String DATA5 = "data5"; } + // 文本笔记的静态内部类,实现了DataColumns接口,定义了文本笔记相关的常量 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; + // 文本笔记的内容类型(目录类型) public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note"; + // 文本笔记的内容类型(项目类型) 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"); } + // 通话笔记的静态内部类,实现了DataColumns接口,定义了通话笔记相关的常量 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; + // 通话笔记的内容类型(目录类型) public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note"; + // 通话笔记的内容类型(项目类型) 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/gtask/data/SqlNote.java b/src/Notes-master/src/net/micode/notes/gtask/data/SqlNote.java index a8b4da9..68fe0a6 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/data/SqlNote.java +++ b/src/Notes-master/src/net/micode/notes/gtask/data/SqlNote.java @@ -38,11 +38,37 @@ import org.json.JSONObject; import java.util.ArrayList; -public class SqlNote {//sqlnot用法修改 +import android.content.ContentResolver; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; +import android.widget.RemoteViews; + +import com.google.gson.JsonObject; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatDrawableManager; +import androidx.cursoradapter.widget.SimpleCursorAdapter; + +// SqlNote类用于处理与笔记数据的SQL相关操作,包括从数据库加载、保存、更新笔记信息等 +public class SqlNote { + // 日志标签,用于标识该类相关的日志信息 private static final String TAG = SqlNote.class.getSimpleName(); + // 无效的ID值 private static final int INVALID_ID = -99999; + // 用于查询笔记时的投影列,指定要从数据库中获取的列 public static final String[] PROJECTION_NOTE = new String[] { NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE, @@ -52,76 +78,79 @@ public class SqlNote {//sqlnot用法修改 NoteColumns.VERSION }; + // 投影列中ID列的索引 public static final int ID_COLUMN = 0; - + // 投影列中提醒日期列的索引 public static final int ALERTED_DATE_COLUMN = 1; - + // 投影列中背景颜色ID列的索引 public static final int BG_COLOR_ID_COLUMN = 2; - + // 投影列中创建日期列的索引 public static final int CREATED_DATE_COLUMN = 3; - + // 投影列中是否有附件列的索引 public static final int HAS_ATTACHMENT_COLUMN = 4; - + // 投影列中修改日期列的索引 public static final int MODIFIED_DATE_COLUMN = 5; - + // 投影列中文件夹内笔记数量列的索引 public static final int NOTES_COUNT_COLUMN = 6; - + // 投影列中父级ID列的索引 public static final int PARENT_ID_COLUMN = 7; - + // 投影列中文本内容或文件夹名称列的索引 public static final int SNIPPET_COLUMN = 8; - + // 投影列中类型列的索引 public static final int TYPE_COLUMN = 9; - + // 投影列中小部件ID列的索引 public static final int WIDGET_ID_COLUMN = 10; - + // 投影列中小部件类型列的索引 public static final int WIDGET_TYPE_COLUMN = 11; - + // 投影列中同步ID列的索引 public static final int SYNC_ID_COLUMN = 12; - + // 投影列中本地修改标志列的索引 public static final int LOCAL_MODIFIED_COLUMN = 13; - + // 投影列中原始父级ID列的索引 public static final int ORIGIN_PARENT_ID_COLUMN = 14; - + // 投影列中gtask ID列的索引 public static final int GTASK_ID_COLUMN = 15; - + // 投影列中版本号列的索引 public static final int VERSION_COLUMN = 16; + // 应用上下文 private Context mContext; - + // 内容解析器,用于与内容提供者进行交互 private ContentResolver mContentResolver; - + // 标识该笔记是否为新创建的 private boolean mIsCreate; - + // 笔记的ID private long mId; - + // 提醒日期 private long mAlertDate; - + // 背景颜色ID private int mBgColorId; - + // 创建日期 private long mCreatedDate; - + // 是否有附件的标志 private int mHasAttachment; - + // 修改日期 private long mModifiedDate; - + // 父级ID private long mParentId; - + // 文本内容或文件夹名称 private String mSnippet; - + // 类型(笔记、文件夹或系统类型) private int mType; - + // 小部件ID private int mWidgetId; - + // 小部件类型 private int mWidgetType; - + // 原始父级ID private long mOriginParent; - + // 版本号 private long mVersion; - + // 用于存储笔记数据差异的ContentValues,用于更新操作 private ContentValues mDiffNoteValues; - + // 存储与该笔记相关的SqlData对象列表 private ArrayList mDataList; + // 构造函数,用于创建一个新的SqlNote对象,通常用于新笔记的创建 public SqlNote(Context context) { mContext = context; mContentResolver = context.getContentResolver(); @@ -143,6 +172,7 @@ public class SqlNote {//sqlnot用法修改 mDataList = new ArrayList(); } + // 构造函数,通过Cursor对象初始化SqlNote对象,通常用于从数据库加载现有笔记 public SqlNote(Context context, Cursor c) { mContext = context; mContentResolver = context.getContentResolver(); @@ -154,6 +184,7 @@ public class SqlNote {//sqlnot用法修改 mDiffNoteValues = new ContentValues(); } + // 构造函数,通过笔记ID从数据库加载笔记并初始化SqlNote对象 public SqlNote(Context context, long id) { mContext = context; mContentResolver = context.getContentResolver(); @@ -163,28 +194,31 @@ public class SqlNote {//sqlnot用法修改 if (mType == Notes.TYPE_NOTE) loadDataContent(); mDiffNoteValues = new ContentValues(); - } + // 根据给定的ID从数据库加载笔记数据 private void loadFromCursor(long id) { Cursor c = null; try { + // 使用内容解析器查询笔记数据 c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)", new String[] { - String.valueOf(id) + String.valueOf(id) }, null); - if (c != null) { + if (c!= null) { c.moveToNext(); + // 从Cursor中加载数据 loadFromCursor(c); } else { Log.w(TAG, "loadFromCursor: cursor = null"); } } finally { - if (c != null) + if (c!= null) c.close(); } } + // 从Cursor中加载笔记数据到当前对象的属性中 private void loadFromCursor(Cursor c) { mId = c.getLong(ID_COLUMN); mAlertDate = c.getLong(ALERTED_DATE_COLUMN); @@ -200,20 +234,23 @@ public class SqlNote {//sqlnot用法修改 mVersion = c.getLong(VERSION_COLUMN); } + // 加载与该笔记相关的数据内容(例如文本笔记的具体内容等) private void loadDataContent() { Cursor c = null; mDataList.clear(); try { + // 使用内容解析器查询与该笔记相关的数据 c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA, "(note_id=?)", new String[] { - String.valueOf(mId) + String.valueOf(mId) }, null); - if (c != null) { + if (c!= null) { if (c.getCount() == 0) { Log.w(TAG, "it seems that the note has not data"); return; } while (c.moveToNext()) { + // 创建SqlData对象并添加到列表中 SqlData data = new SqlData(mContext, c); mDataList.add(data); } @@ -221,112 +258,113 @@ public class SqlNote {//sqlnot用法修改 Log.w(TAG, "loadDataContent: cursor = null"); } } finally { - if (c != null) + if (c!= null) c.close(); } } + // 根据JSONObject设置笔记的内容 public boolean setContent(JSONObject js) { try { JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { Log.w(TAG, "cannot set system folder"); } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { - // for folder we can only update the snnipet and type - String snippet = note.has(NoteColumns.SNIPPET) ? note + // 对于文件夹,只能更新文本内容和类型 + String snippet = note.has(NoteColumns.SNIPPET)? note .getString(NoteColumns.SNIPPET) : ""; - if (mIsCreate || !mSnippet.equals(snippet)) { + if (mIsCreate ||!mSnippet.equals(snippet)) { mDiffNoteValues.put(NoteColumns.SNIPPET, snippet); } mSnippet = snippet; - int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) + int type = note.has(NoteColumns.TYPE)? note.getInt(NoteColumns.TYPE) : Notes.TYPE_NOTE; - if (mIsCreate || mType != type) { + if (mIsCreate || mType!= type) { mDiffNoteValues.put(NoteColumns.TYPE, type); } mType = type; } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); - long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID; - if (mIsCreate || mId != id) { + long id = note.has(NoteColumns.ID)? note.getLong(NoteColumns.ID) : INVALID_ID; + if (mIsCreate || mId!= id) { mDiffNoteValues.put(NoteColumns.ID, id); } mId = id; - long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note + long alertDate = note.has(NoteColumns.ALERTED_DATE)? note .getLong(NoteColumns.ALERTED_DATE) : 0; - if (mIsCreate || mAlertDate != alertDate) { + if (mIsCreate || mAlertDate!= alertDate) { mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate); } mAlertDate = alertDate; - int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note + int bgColorId = note.has(NoteColumns.BG_COLOR_ID)? note .getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext); - if (mIsCreate || mBgColorId != bgColorId) { + if (mIsCreate || mBgColorId!= bgColorId) { mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId); } mBgColorId = bgColorId; - long createDate = note.has(NoteColumns.CREATED_DATE) ? note + long createDate = note.has(NoteColumns.CREATED_DATE)? note .getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis(); - if (mIsCreate || mCreatedDate != createDate) { + if (mIsCreate || mCreatedDate!= createDate) { mDiffNoteValues.put(NoteColumns.CREATED_DATE, createDate); } mCreatedDate = createDate; - int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT) ? note + int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT)? note .getInt(NoteColumns.HAS_ATTACHMENT) : 0; - if (mIsCreate || mHasAttachment != hasAttachment) { + if (mIsCreate || mHasAttachment!= hasAttachment) { mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment); } mHasAttachment = hasAttachment; - long modifiedDate = note.has(NoteColumns.MODIFIED_DATE) ? note + long modifiedDate = note.has(NoteColumns.MODIFIED_DATE)? note .getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis(); - if (mIsCreate || mModifiedDate != modifiedDate) { + if (mIsCreate || mModifiedDate!= modifiedDate) { mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate); } mModifiedDate = modifiedDate; - long parentId = note.has(NoteColumns.PARENT_ID) ? note + long parentId = note.has(NoteColumns.PARENT_ID)? note .getLong(NoteColumns.PARENT_ID) : 0; - if (mIsCreate || mParentId != parentId) { + if (mIsCreate || mParentId!= parentId) { mDiffNoteValues.put(NoteColumns.PARENT_ID, parentId); } mParentId = parentId; - String snippet = note.has(NoteColumns.SNIPPET) ? note + String snippet = note.has(NoteColumns.SNIPPET)? note .getString(NoteColumns.SNIPPET) : ""; - if (mIsCreate || !mSnippet.equals(snippet)) { + if (mIsCreate ||!mSnippet.equals(snippet)) { mDiffNoteValues.put(NoteColumns.SNIPPET, snippet); } mSnippet = snippet; - int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) + int type = note.has(NoteColumns.TYPE)? note.getInt(NoteColumns.TYPE) : Notes.TYPE_NOTE; - if (mIsCreate || mType != type) { + if (mIsCreate || mType!= type) { mDiffNoteValues.put(NoteColumns.TYPE, type); } mType = type; - int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID) + int widgetId = note.has(NoteColumns.WIDGET_ID)? note.getInt(NoteColumns.WIDGET_ID) : AppWidgetManager.INVALID_APPWIDGET_ID; - if (mIsCreate || mWidgetId != widgetId) { + if (mIsCreate || mWidgetId!= widgetId) { mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId); } mWidgetId = widgetId; - int widgetType = note.has(NoteColumns.WIDGET_TYPE) ? note + int widgetType = note.has(NoteColumns.WIDGET_TYPE)? note .getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE; - if (mIsCreate || mWidgetType != widgetType) { + if (mIsCreate || mWidgetType!= widgetType) { mDiffNoteValues.put(NoteColumns.WIDGET_TYPE, widgetType); } mWidgetType = widgetType; - long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID) ? note + long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID)? note .getLong(NoteColumns.ORIGIN_PARENT_ID) : 0; - if (mIsCreate || mOriginParent != originParent) { + if (mIsCreate || mOriginParent!= originParent) { mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent); } mOriginParent = originParent; @@ -359,6 +397,7 @@ public class SqlNote {//sqlnot用法修改 return true; } + // 获取当前笔记的内容,以JSONObject形式返回 public JSONObject getContent() { try { JSONObject js = new JSONObject(); @@ -387,7 +426,7 @@ public class SqlNote {//sqlnot用法修改 JSONArray dataArray = new JSONArray(); for (SqlData sqlData : mDataList) { JSONObject data = sqlData.getContent(); - if (data != null) { + if (data!= null) { dataArray.put(data); } } diff --git a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java index 15e5cd8..823b40a 100644 --- a/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java +++ b/src/Notes-master/src/net/micode/notes/gtask/remote/GTaskManager.java @@ -73,18 +73,29 @@ public class GTaskManager { private HashMap mNidToGid; + // GTaskManager类用于管理与Google任务相关的同步操作 private GTaskManager() { + // 初始化同步状态为未同步 mSyncing = false; + // 初始化取消状态为未取消 mCancelled = false; + // 初始化用于存储Google任务列表的HashMap mGTaskListHashMap = new HashMap(); + // 初始化用于存储Google任务的HashMap mGTaskHashMap = new HashMap(); + // 初始化用于存储元数据的HashMap mMetaHashMap = new HashMap(); + // 初始化元数据列表为null mMetaList = null; + // 初始化用于存储本地已删除任务ID的HashSet mLocalDeleteIdMap = new HashSet(); + // 初始化用于映射Google任务ID到本地笔记ID的HashMap mGidToNid = new HashMap(); + // 初始化用于映射本地笔记ID到Google任务ID的HashMap mNidToGid = new HashMap(); } + // 获取GTaskManager单例实例的方法 public static synchronized GTaskManager getInstance() { if (mInstance == null) { mInstance = new GTaskManager(); @@ -92,56 +103,76 @@ public class GTaskManager { return mInstance; } + // 设置Activity上下文的方法,用于获取认证令牌 public synchronized void setActivityContext(Activity activity) { - // used for getting authtoken + // 存储Activity上下文,用于后续获取认证令牌等操作 mActivity = activity; } + // 执行同步操作的方法 public int sync(Context context, GTaskASyncTask asyncTask) { + // 如果当前正在同步,则返回同步中状态 if (mSyncing) { Log.d(TAG, "Sync is in progress"); return STATE_SYNC_IN_PROGRESS; } + // 设置应用上下文 mContext = context; + // 获取内容解析器 mContentResolver = mContext.getContentResolver(); + // 设置同步状态为正在同步 mSyncing = true; + // 设置取消状态为未取消 mCancelled = false; + // 清空Google任务列表HashMap mGTaskListHashMap.clear(); + // 清空Google任务HashMap mGTaskHashMap.clear(); + // 清空元数据HashMap mMetaHashMap.clear(); + // 清空本地已删除任务ID的HashSet mLocalDeleteIdMap.clear(); + // 清空Google任务ID到本地笔记ID的映射HashMap mGidToNid.clear(); + // 清空本地笔记ID到Google任务ID的映射HashMap mNidToGid.clear(); try { + // 获取GTaskClient实例 GTaskClient client = GTaskClient.getInstance(); + // 重置更新数组 client.resetUpdateArray(); - // login google task + // 登录Google任务 if (!mCancelled) { if (!client.login(mActivity)) { + // 登录失败则抛出网络失败异常 throw new NetworkFailureException("login google task failed"); } } - // get the task list from google + // 从Google获取任务列表,并在异步任务中更新进度 asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list)); initGTaskList(); - // do content sync work + // 执行内容同步工作,并在异步任务中更新进度 asyncTask.publishProgess(mContext.getString(R.string.sync_progress_syncing)); syncContent(); } catch (NetworkFailureException e) { + // 捕获网络失败异常,记录错误日志并返回网络错误状态 Log.e(TAG, e.toString()); return STATE_NETWORK_ERROR; } catch (ActionFailureException e) { + // 捕获操作失败异常,记录错误日志并返回内部错误状态 Log.e(TAG, e.toString()); return STATE_INTERNAL_ERROR; } catch (Exception e) { + // 捕获其他异常,记录错误日志并返回内部错误状态 Log.e(TAG, e.toString()); e.printStackTrace(); return STATE_INTERNAL_ERROR; } finally { + // 无论同步过程是否成功,最终都清空相关数据结构,并设置同步状态为未同步 mGTaskListHashMap.clear(); mGTaskHashMap.clear(); mMetaHashMap.clear(); @@ -151,44 +182,62 @@ public class GTaskManager { mSyncing = false; } - return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS; + // 根据是否取消同步,返回相应的同步状态 + return mCancelled? STATE_SYNC_CANCELLED : STATE_SUCCESS; } + // 初始化Google任务列表的方法 private void initGTaskList() throws NetworkFailureException { + // 如果同步已取消,则直接返回 if (mCancelled) return; + // 获取GTaskClient实例 GTaskClient client = GTaskClient.getInstance(); try { + // 从Google获取任务列表的JSON数组 JSONArray jsTaskLists = client.getTaskLists(); - // init meta list first + // 首先初始化元数据列表 mMetaList = null; for (int i = 0; i < jsTaskLists.length(); i++) { + // 获取当前任务列表的JSONObject JSONObject object = jsTaskLists.getJSONObject(i); + // 获取任务列表的Google ID String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); + // 获取任务列表的名称 String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME); - if (name - .equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) { + // 如果任务列表名称符合特定格式,说明是元数据相关的任务列表 + if (name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) { + // 创建元数据任务列表对象,并根据远程JSON数据设置其内容 mMetaList = new TaskList(); mMetaList.setContentByRemoteJSON(object); - // load meta data + // 加载元数据 JSONArray jsMetas = client.getTaskList(gid); for (int j = 0; j < jsMetas.length(); j++) { + // 获取当前元数据的JSONObject object = (JSONObject) jsMetas.getJSONObject(j); + // 创建元数据对象,并根据远程JSON数据设置其内容 MetaData metaData = new MetaData(); metaData.setContentByRemoteJSON(object); + // 如果元数据值得保存 if (metaData.isWorthSaving()) { + // 将元数据添加到元数据任务列表中 mMetaList.addChildTask(metaData); - if (metaData.getGid() != null) { + // 如果元数据有相关的Google ID,则添加到元数据HashMap中 + if (metaData.getGid()!= null) { mMetaHashMap.put(metaData.getRelatedGid(), metaData); } } } } } - + } catch (JSONException e) { + // 捕获JSON解析异常,抛出网络失败异常 + throw new NetworkFailureException("Error getting task lists from Google"); + } + } // create meta list if not existed if (mMetaList == null) { mMetaList = new TaskList();