diff --git a/src/net/micode/notes/gtask/data/MetaData.java b/src/net/micode/notes/gtask/data/MetaData.java index 3a2050b..1fb7334 100644 --- a/src/net/micode/notes/gtask/data/MetaData.java +++ b/src/net/micode/notes/gtask/data/MetaData.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.micode.notes.gtask.data; +package net.micode.notes.gtask.data;/*MetaData类继承自Task类,代表了一条元数据,用于存储与任务相关的信息。*/ import android.database.Cursor; import android.util.Log; @@ -40,6 +40,18 @@ public class MetaData extends Task { setName(GTaskStringUtils.META_NOTE_NAME); } + private String mRelatedGid = null;//用于存储任务的Google ID + + public void setMeta(String gid, JSONObject metaInfo) {//设置元数据(1) @param gid 任务的Google ID(2)@param metaInfo 和任务相关的信息 + try { + metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);//将任务的Google ID存入和任务相关的信息中 + } catch (JSONException e) { + Log.e(TAG, "failed to put related gid"); + } + setNotes(metaInfo.toString());//将和任务相关的信息存储到笔记内容中 + setName(GTaskStringUtils.META_NOTE_NAME);//设置元数据的名称为META_NOTE_NAME + } +/* 返回与元数据相关的GID*/ public String getRelatedGid() { return mRelatedGid; } @@ -56,6 +68,14 @@ public class MetaData extends Task { try { JSONObject metaInfo = new JSONObject(getNotes().trim()); mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); +/**从远程服务器的JSON对象中设置元数据的内容 */ + @Override + public void setContentByRemoteJSON(JSONObject js) { + super.setContentByRemoteJSON(js);//调用父类的setContentByRemoteJSON方法 + if (getNotes() != null) {//如果笔记内容不为空 + try { + JSONObject metaInfo = new JSONObject(getNotes().trim());//将笔记内容转换为JSONObject + mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);//获取和任务相关的信息的Google ID } catch (JSONException e) { Log.w(TAG, "failed to get related gid"); mRelatedGid = null; @@ -63,17 +83,21 @@ public class MetaData extends Task { } } + +/**该方法不应被调用*/ @Override public void setContentByLocalJSON(JSONObject js) { // this function should not be called throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); } +/**该方法不应被调用*/ @Override public JSONObject getLocalJSONFromContent() { throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); } +/**该方法不应被调用*/ @Override public int getSyncAction(Cursor c) { throw new IllegalAccessError("MetaData:getSyncAction should not be called"); diff --git a/src/net/micode/notes/gtask/data/Node.java b/src/net/micode/notes/gtask/data/Node.java index 63950e0..608a17c 100644 --- a/src/net/micode/notes/gtask/data/Node.java +++ b/src/net/micode/notes/gtask/data/Node.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package net.micode.notes.gtask.data; +package net.micode.notes.gtask.data;// 定义了一个抽象类 Node import android.database.Cursor; import org.json.JSONObject; -public abstract class Node { +public abstract class Node {// 定义了一些静态变量 public static final int SYNC_ACTION_NONE = 0; public static final int SYNC_ACTION_ADD_REMOTE = 1; @@ -38,7 +38,7 @@ public abstract class Node { public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; public static final int SYNC_ACTION_ERROR = 8; - + // 定义了一些实例变量 private String mGid; private String mName; @@ -47,38 +47,38 @@ public abstract class Node { private boolean mDeleted; - public Node() { + public Node() {// 构造函数,初始化实例变量 mGid = null; mName = ""; mLastModified = 0; mDeleted = false; } - public abstract JSONObject getCreateAction(int actionId); + public abstract JSONObject getCreateAction(int actionId);// 抽象方法,获取创建操作的 JSONObject 对象 - public abstract JSONObject getUpdateAction(int actionId); + public abstract JSONObject getUpdateAction(int actionId);// 抽象方法,获取更新操作的 JSONObject 对象 - public abstract void setContentByRemoteJSON(JSONObject js); + public abstract void setContentByRemoteJSON(JSONObject js);// 抽象方法,根据远程服务器上的 JSON 对象设置节点的内容 - public abstract void setContentByLocalJSON(JSONObject js); + public abstract void setContentByLocalJSON(JSONObject js);// 抽象方法,根据本地 JSON 对象设置节点的内容 - public abstract JSONObject getLocalJSONFromContent(); + public abstract JSONObject getLocalJSONFromContent();// 抽象方法,从内容中获取本地 JSON 对象 - public abstract int getSyncAction(Cursor c); + public abstract int getSyncAction(Cursor c);// 抽象方法,获取同步操作类型 - public void setGid(String gid) { + public void setGid(String gid) {// 设置、获取实例变量 mGid this.mGid = gid; } - public void setName(String name) { + public void setName(String name) {// 设置、获取实例变量 mName this.mName = name; } - public void setLastModified(long lastModified) { + public void setLastModified(long lastModified) {// 设置、获取实例变量 mLastModified this.mLastModified = lastModified; } - public void setDeleted(boolean deleted) { + public void setDeleted(boolean deleted) {// 设置、获取实例变量 mDeleted this.mDeleted = deleted; } diff --git a/src/net/micode/notes/gtask/data/SqlData.java b/src/net/micode/notes/gtask/data/SqlData.java index d3ec3be..b5303cb 100644 --- a/src/net/micode/notes/gtask/data/SqlData.java +++ b/src/net/micode/notes/gtask/data/SqlData.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +// 该类定义了访问本地 SQLite 数据库中笔记数据表的方法 package net.micode.notes.gtask.data; import android.content.ContentResolver; @@ -36,11 +36,11 @@ import org.json.JSONObject; public class SqlData { - private static final String TAG = SqlData.class.getSimpleName(); + private static final String TAG = SqlData.class.getSimpleName();// 日志 TAG - private static final int INVALID_ID = -99999; + private static final int INVALID_ID = -99999;// 无效的数据 ID - public static final String[] PROJECTION_DATA = new String[] { + public static final String[] PROJECTION_DATA = new String[] {// 数据表中常用的列 DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1, DataColumns.DATA3 }; @@ -55,10 +55,10 @@ public class SqlData { public static final int DATA_CONTENT_DATA_3_COLUMN = 4; - private ContentResolver mContentResolver; - - private boolean mIsCreate; + private ContentResolver mContentResolver;// ContentResolver 用于访问本地数据库 + private boolean mIsCreate;// 是否为新建的数据 + // 数据的各个列的值 private long mDataId; private String mDataMimeType; @@ -69,9 +69,9 @@ public class SqlData { private String mDataContentData3; - private ContentValues mDiffDataValues; + private ContentValues mDiffDataValues; // 修改时的差异数据 - public SqlData(Context context) { + public SqlData(Context context) {// 构造方法1:用于新建数据 mContentResolver = context.getContentResolver(); mIsCreate = true; mDataId = INVALID_ID; @@ -82,14 +82,14 @@ public class SqlData { mDiffDataValues = new ContentValues(); } - public SqlData(Context context, Cursor c) { + public SqlData(Context context, Cursor c) {// 构造方法2:用于从数据库中读取数据 mContentResolver = context.getContentResolver(); mIsCreate = false; loadFromCursor(c); mDiffDataValues = new ContentValues(); } - private void loadFromCursor(Cursor c) { + private void loadFromCursor(Cursor c) {// 从 Cursor 中读取数据 mDataId = c.getLong(DATA_ID_COLUMN); mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN); mDataContent = c.getString(DATA_CONTENT_COLUMN); @@ -97,11 +97,11 @@ public class SqlData { mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN); } +<<<<<<< HEAD public void setContent(JSONObject js) throws JSONException { - long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID; - if (mIsCreate || mDataId != dataId) { +======= + public void setContent(JSONObject js) throws JSONException {//建立连接 mDiffDataValues.put(DataColumns.ID, dataId); - } mDataId = dataId; String dataMimeType = js.has(DataColumns.MIME_TYPE) ? js.getString(DataColumns.MIME_TYPE) @@ -144,8 +144,18 @@ public class SqlData { return js; } +<<<<<<< HEAD public void commit(long noteId, boolean validateVersion, long version) { +======= + public void commit(long noteId, boolean validateVersion, long version) {//提交数据更改 + /* 如果 mIsCreate 为 true,表示正在创建新的笔记。 + 在这种情况下,首先会检查 mDataId 是否为无效值, + 如果是,并且 mDiffDataValues 中包含了 DataColumns.ID, + 则会将其移除。然后将 noteId 放入 mDiffDataValues 中, + 并通过 mContentResolver 根据 mDiffDataValues 插入数据到 Notes.CONTENT_DATA_URI 中, + 并获取插入数据的路径信息。最后将路径中的第二个片段转换为 Long 值存储到 mDataId */ +>>>>>>> develop if (mIsCreate) { if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) { mDiffDataValues.remove(DataColumns.ID); @@ -159,7 +169,19 @@ public class SqlData { Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); } +<<<<<<< HEAD } else { +======= + } + /*如果 mIsCreate 不为 true,表示正在更新现有笔记。 + 首先判断 mDiffDataValues 的大小是否大于 0,如果是, + 根据是否需要验证版本号通过 mContentResolver 更新数据。如果不需要验证版本号, + 则直接根据 mDataId 更新数据;如果需要验证版本号, + 则使用 NoteColumns.ID 和 NoteColumns.VERSION 字段进行联合查询, + 并以 noteId 和 version 的值作为参数,通过 mContentResolver 更新数据。 + 更新完成后,如果结果为 0,表示没有更新成功 */ + else { +>>>>>>> develop if (mDiffDataValues.size() > 0) { int result = 0; if (!validateVersion) { @@ -183,7 +205,11 @@ public class SqlData { mIsCreate = false; } +<<<<<<< HEAD public long getId() { +======= + public long getId() {//获取ID +>>>>>>> develop return mDataId; } } diff --git a/src/net/micode/notes/gtask/data/SqlNote.java b/src/net/micode/notes/gtask/data/SqlNote.java index 79a4095..f6937f7 100644 --- a/src/net/micode/notes/gtask/data/SqlNote.java +++ b/src/net/micode/notes/gtask/data/SqlNote.java @@ -123,34 +123,35 @@ public class SqlNote { private ArrayList mDataList; public SqlNote(Context context) { - mContext = context; - mContentResolver = context.getContentResolver(); - mIsCreate = true; - mId = INVALID_ID; - mAlertDate = 0; - mBgColorId = ResourceParser.getDefaultBgId(context); - mCreatedDate = System.currentTimeMillis(); - mHasAttachment = 0; - mModifiedDate = System.currentTimeMillis(); - mParentId = 0; - mSnippet = ""; - mType = Notes.TYPE_NOTE; - mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; - mWidgetType = Notes.TYPE_WIDGET_INVALIDE; - mOriginParent = 0; - mVersion = 0; - mDiffNoteValues = new ContentValues(); - mDataList = new ArrayList(); + //初始化成员变量 + mContext = context;// 上下文 + mContentResolver = context.getContentResolver();// 获取内容解析器 + mIsCreate = true; // 是否为新建笔记 + mId = INVALID_ID; // 笔记ID + mAlertDate = 0; // 提醒时间 + mBgColorId = ResourceParser.getDefaultBgId(context); // 背景颜色ID + mCreatedDate = System.currentTimeMillis(); // 创建时间 + mHasAttachment = 0; // 是否有附件 + mModifiedDate = System.currentTimeMillis(); // 修改时间 + mParentId = 0; // 所属父笔记ID + mSnippet = ""; // 笔记摘要 + mType = Notes.TYPE_NOTE; // 笔记类型 + mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; // 小部件ID + mWidgetType = Notes.TYPE_WIDGET_INVALIDE; // 小部件类型 + mOriginParent = 0; // 原始的父笔记ID + mVersion = 0; // 笔记版本 + mDiffNoteValues = new ContentValues(); // 存储笔记差异内容的 ContentValues 对象 + mDataList = new ArrayList(); // 存储笔记数据的 ArrayList } public SqlNote(Context context, Cursor c) { mContext = context; mContentResolver = context.getContentResolver(); mIsCreate = false; - loadFromCursor(c); + loadFromCursor(c); // 从Cursor加载笔记数据 mDataList = new ArrayList(); if (mType == Notes.TYPE_NOTE) - loadDataContent(); + loadDataContent(); // 加载笔记内容 mDiffNoteValues = new ContentValues(); } @@ -158,10 +159,10 @@ public class SqlNote { mContext = context; mContentResolver = context.getContentResolver(); mIsCreate = false; - loadFromCursor(id); + loadFromCursor(id); // 根据ID从数据库中加载笔记数据 mDataList = new ArrayList(); if (mType == Notes.TYPE_NOTE) - loadDataContent(); + loadDataContent(); // 加载笔记内容 mDiffNoteValues = new ContentValues(); } @@ -175,7 +176,7 @@ public class SqlNote { }, null); if (c != null) { c.moveToNext(); - loadFromCursor(c); + loadFromCursor(c);// 从Cursor加载笔记数据 } else { Log.w(TAG, "loadFromCursor: cursor = null"); } @@ -186,43 +187,45 @@ public class SqlNote { } private void loadFromCursor(Cursor c) { - mId = c.getLong(ID_COLUMN); - mAlertDate = c.getLong(ALERTED_DATE_COLUMN); - mBgColorId = c.getInt(BG_COLOR_ID_COLUMN); - mCreatedDate = c.getLong(CREATED_DATE_COLUMN); - mHasAttachment = c.getInt(HAS_ATTACHMENT_COLUMN); - mModifiedDate = c.getLong(MODIFIED_DATE_COLUMN); - mParentId = c.getLong(PARENT_ID_COLUMN); - mSnippet = c.getString(SNIPPET_COLUMN); - mType = c.getInt(TYPE_COLUMN); - mWidgetId = c.getInt(WIDGET_ID_COLUMN); - mWidgetType = c.getInt(WIDGET_TYPE_COLUMN); - mVersion = c.getLong(VERSION_COLUMN); + mId = c.getLong(ID_COLUMN); // 加载ID数据 + mAlertDate = c.getLong(ALERTED_DATE_COLUMN); // 加载提醒日期数据 + mBgColorId = c.getInt(BG_COLOR_ID_COLUMN); // 加载背景颜色ID数据 + mCreatedDate = c.getLong(CREATED_DATE_COLUMN); // 加载创建日期数据 + mHasAttachment = c.getInt(HAS_ATTACHMENT_COLUMN); // 加载附件存在标记数据 + mModifiedDate = c.getLong(MODIFIED_DATE_COLUMN); // 加载修改日期数据 + mParentId = c.getLong(PARENT_ID_COLUMN); // 加载父级ID数据 + mSnippet = c.getString(SNIPPET_COLUMN); // 加载摘要数据 + mType = c.getInt(TYPE_COLUMN); // 加载类型数据 + mWidgetId = c.getInt(WIDGET_ID_COLUMN); // 加载小部件ID数据 + mWidgetType = c.getInt(WIDGET_TYPE_COLUMN); // 加载小部件类型数据 + mVersion = c.getLong(VERSION_COLUMN); // 加载版本号数据 } private void loadDataContent() { Cursor c = null; - mDataList.clear(); + mDataList.clear();// 清空数据列表 try { + // 通过ContentResolver从Content Provider查询数据内容 c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA, "(note_id=?)", new String[] { String.valueOf(mId) }, null); if (c != null) { if (c.getCount() == 0) { + // 数据内容为空 Log.w(TAG, "it seems that the note has not data"); return; } - while (c.moveToNext()) { + while (c.moveToNext()) {// 遍历Cursor,创建SqlData对象并添加到数据列表中 SqlData data = new SqlData(mContext, c); mDataList.add(data); } } else { Log.w(TAG, "loadDataContent: cursor = null"); } - } finally { + } finally { // Cursor为空 if (c != null) - c.close(); + c.close();// 关闭Cursor } } @@ -441,22 +444,25 @@ public class SqlNote { } public void commit(boolean validateVersion) { - if (mIsCreate) { + if (mIsCreate) {// 判断当前对象是否为新建对象。如果是,则执行以下代码块。 if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) { + // 如果当前对象的id为无效id,并且mDiffNoteValues中包含NoteColumns.ID这个键,则移除该键值对。 mDiffNoteValues.remove(NoteColumns.ID); } - + // 通过ContentResolver向Notes表中插入一条记录,第一部分是插入的uri。 Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues); - try { + try {// 试图从uri的路径段中获取note的id。 + // 将获取到的id转换为long类型并赋值给mId。如果转换失败,会抛出NumberFormatException异常。 mId = Long.valueOf(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { + // 记录错误日志,创建note失败。抛出ActionFailureException异常,异常信息为create note failed。 Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); } - if (mId == 0) { + if (mId == 0) {// 如果mId仍然为0,抛出一个IllegalStateException异常,创建thread id失败。 throw new IllegalStateException("Create thread id failed"); } - + // 如果mType等于Notes.TYPE_NOTE,执行以下代码块。 if (mType == Notes.TYPE_NOTE) { for (SqlData sqlData : mDataList) { sqlData.commit(mId, false, -1); @@ -464,24 +470,28 @@ public class SqlNote { } } else { if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) { - Log.e(TAG, "No such note"); + Log.e(TAG, "No such note");// 打印错误日志"No such note + // 抛出异常IllegalStateException throw new IllegalStateException("Try to update note with invalid id"); } if (mDiffNoteValues.size() > 0) { mVersion ++; int result = 0; if (!validateVersion) { + //更新Notes表中的记录,将mDiffNoteValues中的键值对更新到Notes表中 result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?)", new String[] { String.valueOf(mId) }); } else { + // 更新Notes表中的记录,将mDiffNoteValues中的键值对更新到Notes表中 result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)", new String[] { String.valueOf(mId), String.valueOf(mVersion) }); } + // 如果result为0,即没有更新记录,则打印警告日志 if (result == 0) { Log.w(TAG, "there is no update. maybe user updates note when syncing"); } diff --git a/src/net/micode/notes/gtask/data/Task.java b/src/net/micode/notes/gtask/data/Task.java index 6a19454..2f56369 100644 --- a/src/net/micode/notes/gtask/data/Task.java +++ b/src/net/micode/notes/gtask/data/Task.java @@ -176,25 +176,27 @@ public class Task extends Node { } public void setContentByLocalJSON(JSONObject js) { + // 检查传入的js对象是否为空,或者js对象中是否包含GTaskStringUtils.META_HEAD_NOTE和GTaskStringUtils.META_HEAD_DATA键 if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) || !js.has(GTaskStringUtils.META_HEAD_DATA)) { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); } +<<<<<<< HEAD try { JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); - JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); - + / 检查note对象的NoteColumns.TYPE的值是否等于Notes.TYPE_NOTE +>>>>>>> develop if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) { Log.e(TAG, "invalid type"); - return; } - + // 遍历dataArray中的每个元素,获取每个元素的值 for (int i = 0; i < dataArray.length(); i++) { JSONObject data = dataArray.getJSONObject(i); if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) { + // 如果DataColumns.MIME_TYPE的值等于DataConstants.NOTE,则从data对象中获取DataColumns.CONTENT的值,并设置给setName方法 setName(data.getString(DataColumns.CONTENT)); - break; + break;// 找到后跳出循环,防止继续遍历其他元素 } } @@ -206,18 +208,19 @@ public class Task extends Node { public JSONObject getLocalJSONFromContent() { String name = getName(); - try { + try {// 判断是否存在元信息,如果不存在则认为是新创建的任务 if (mMetaInfo == null) { // new task created from web if (name == null) { Log.w(TAG, "the note seems to be an empty one"); return null; } - + //创建对象 JSONObject js = new JSONObject(); JSONObject note = new JSONObject(); JSONArray dataArray = new JSONArray(); JSONObject data = new JSONObject(); + //将对象加入不同方法中 data.put(DataColumns.CONTENT, name); dataArray.put(data); js.put(GTaskStringUtils.META_HEAD_DATA, dataArray); @@ -226,22 +229,38 @@ public class Task extends Node { return js; } else { // synced task - JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); +<<<<<<< HEAD +======= + // 同步任务,获取元信息中的note和dataArray对象 JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA); - for (int i = 0; i < dataArray.length(); i++) { +<<<<<<< HEAD + JSONObject data = dataArray.getJSONObject(i); + if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) { +======= + // 获取当前元素的值,并判断其类型是否为笔记类型 JSONObject data = dataArray.getJSONObject(i); if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) { + // 如果类型为笔记类型,则将名称放入该data对象的CONTENT键中,并跳出循环 +>>>>>>> develop data.put(DataColumns.CONTENT, getName()); break; } } +<<<<<<< HEAD +======= + // 将note的TYPE键的值设置为笔记类型,并返回元信息对象mMetaInfo +>>>>>>> develop note.put(NoteColumns.TYPE, Notes.TYPE_NOTE); return mMetaInfo; } } catch (JSONException e) { Log.e(TAG, e.toString()); +<<<<<<< HEAD +======= + // 如果在处理过程中出现JSON解析异常,打印错误日志并输出异常堆栈信息,最后返回空对象 +>>>>>>> develop e.printStackTrace(); return null; } diff --git a/src/net/micode/notes/gtask/data/TaskList.java b/src/net/micode/notes/gtask/data/TaskList.java index 4ea21c5..a7d39fc 100644 --- a/src/net/micode/notes/gtask/data/TaskList.java +++ b/src/net/micode/notes/gtask/data/TaskList.java @@ -33,16 +33,16 @@ import java.util.ArrayList; public class TaskList extends Node { private static final String TAG = TaskList.class.getSimpleName(); - private int mIndex; + private int mIndex;// 索引 - private ArrayList mChildren; + private ArrayList mChildren;// 子任务列表 - public TaskList() { + public TaskList() { // 默认构造函数 super(); mChildren = new ArrayList(); mIndex = 1; } - + // 创建操作的方法,返回一个JSONObject对象 public JSONObject getCreateAction(int actionId) { JSONObject js = new JSONObject(); @@ -64,10 +64,11 @@ public class TaskList extends Node { entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_GROUP); js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); - + } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); + // 如果生成JSONObject失败,则抛出ActionFailureException异常 throw new ActionFailureException("fail to generate tasklist-create jsonobject"); } @@ -121,9 +122,10 @@ public class TaskList extends Node { setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); } - } catch (JSONException e) { + } catch (JSONException e) {// 当出现JSON解析异常时,捕获该异常 Log.e(TAG, e.toString()); - e.printStackTrace(); + e.printStackTrace(); // 打印异常的堆栈跟踪信息,有助于开发人员定位问题 + // 抛出一个新的ActionFailureException异常,并附带错误信息 throw new ActionFailureException("fail to get tasklist content from jsonobject"); } } @@ -152,8 +154,8 @@ public class TaskList extends Node { Log.e(TAG, "error type"); } } catch (JSONException e) { - Log.e(TAG, e.toString()); - e.printStackTrace(); + Log.e(TAG, e.toString());// 当出现JSON解析异常时,捕获该异常 + e.printStackTrace();// 打印异常的堆栈跟踪信息,有助于开发人员定位问题 } } @@ -162,26 +164,22 @@ public class TaskList extends Node { JSONObject js = new JSONObject(); JSONObject folder = new JSONObject(); - String folderName = getName(); + String folderName = getName();// 获取当前文件夹的名称,并赋值给folderName变量 if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX)) folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(), folderName.length()); folder.put(NoteColumns.SNIPPET, folderName); if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT) || folderName.equals(GTaskStringUtils.FOLDER_CALL_NOTE)) - folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); - else + folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); // 在folder对象中添加键值对 + else// 否则,在folder对象中添加键值对,键为NoteColumns.TYPE,值为Notes.TYPE_FOLDER folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER); js.put(GTaskStringUtils.META_HEAD_NOTE, folder); return js; - } catch (JSONException e) { - Log.e(TAG, e.toString()); - e.printStackTrace(); - return null; + } catch (JSONException e) {// 如果在处理过程中出现JSONException异常,将异常信息记录到日志中,并打印异常堆栈信息 } - } public int getSyncAction(Cursor c) { try { diff --git a/实践模板-开源软件泛读、标注和维护报告文档、.docx b/实践模板-开源软件泛读、标注和维护报告文档、.docx new file mode 100644 index 0000000..f3c0d81 Binary files /dev/null and b/实践模板-开源软件泛读、标注和维护报告文档、.docx differ