Merge branch 'develop'

# Conflicts:
#	.gradle/8.0/executionHistory/executionHistory.bin
#	.gradle/8.0/executionHistory/executionHistory.lock
#	.gradle/8.0/fileHashes/fileHashes.bin
#	.gradle/8.0/fileHashes/fileHashes.lock
#	.gradle/buildOutputCleanup/buildOutputCleanup.lock
#	.gradle/buildOutputCleanup/outputFiles.bin
#	.gradle/file-system.probe
#	app/build/intermediates/apk/debug/app-debug.apk
#	app/build/intermediates/dex_archive_input_jar_hashes/debug/out
#	app/build/intermediates/incremental/debug/mergeDebugResources/compile-file-map.properties
#	app/build/intermediates/incremental/debug/mergeDebugResources/merger.xml
#	app/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties
#	app/build/intermediates/incremental/debug/packageDebugResources/merger.xml
#	app/build/intermediates/incremental/mergeDebugAssets/merger.xml
#	app/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml
#	app/build/intermediates/incremental/mergeDebugShaders/merger.xml
#	app/build/intermediates/incremental/packageDebug/tmp/debug/dex-renamer-state.txt
#	app/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt
#	app/build/intermediates/merged_res_blame_folder/debug/out/multi-v2/debug.json
#	app/build/intermediates/merged_res_blame_folder/debug/out/multi-v2/values-zh-rCN.json
#	app/build/intermediates/merged_res_blame_folder/debug/out/multi-v2/values-zh-rTW.json
#	app/build/intermediates/merged_res_blame_folder/debug/out/multi-v2/values.json
#	app/build/intermediates/source_set_path_map/debug/file-map.txt
#	app/build/outputs/logs/manifest-merger-debug-report.txt
#	app/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin
#	res/values/styles.xml
#	src/net/micode/notes/gtask/data/MetaData.java
#	src/net/micode/notes/gtask/data/Node.java
#	src/net/micode/notes/gtask/data/SqlData.java
#	src/net/micode/notes/gtask/data/SqlNote.java
#	src/net/micode/notes/gtask/data/Task.java
#	src/net/micode/notes/gtask/data/TaskList.java
pull/2/head
ZYP 12 months ago
commit 876b8c145e

@ -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");

@ -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;
}

@ -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;
}
}

@ -123,34 +123,35 @@ public class SqlNote {
private ArrayList<SqlData> 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<SqlData>();
//初始化成员变量
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<SqlData>(); // 存储笔记数据的 ArrayList
}
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = false;
loadFromCursor(c);
loadFromCursor(c); // 从Cursor加载笔记数据
mDataList = new ArrayList<SqlData>();
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<SqlData>();
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");
}

@ -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);
/ noteNoteColumns.TYPENotes.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;
}

@ -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<Task> mChildren;
private ArrayList<Task> mChildren;// 子任务列表
public TaskList() {
public TaskList() { // 默认构造函数
super();
mChildren = new ArrayList<Task>();
mIndex = 1;
}
// 创建操作的方法返回一个JSONObject对象
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -68,6 +68,7 @@ public class TaskList extends Node {
} 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 {

Loading…
Cancel
Save