|
|
@ -176,25 +176,27 @@ public class Task extends Node {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
|
|
|
|
// 检查传入的js对象是否为空,或者js对象中是否包含GTaskStringUtils.META_HEAD_NOTE和GTaskStringUtils.META_HEAD_DATA键
|
|
|
|
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|
|
|
|
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|
|
|
|
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
|
|
|
|
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
|
|
|
|
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
|
|
|
|
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {// 从js对象中获取note对象
|
|
|
|
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
|
|
|
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
|
|
|
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
|
|
|
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
|
|
|
|
|
|
|
/ 检查note对象的NoteColumns.TYPE的值是否等于Notes.TYPE_NOTE
|
|
|
|
if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {
|
|
|
|
if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {
|
|
|
|
Log.e(TAG, "invalid type");
|
|
|
|
Log.e(TAG, "invalid type");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 遍历dataArray中的每个元素,获取每个元素的值
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
|
|
|
|
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
|
|
|
|
|
|
|
|
// 如果DataColumns.MIME_TYPE的值等于DataConstants.NOTE,则从data对象中获取DataColumns.CONTENT的值,并设置给setName方法
|
|
|
|
setName(data.getString(DataColumns.CONTENT));
|
|
|
|
setName(data.getString(DataColumns.CONTENT));
|
|
|
|
break;
|
|
|
|
break;// 找到后跳出循环,防止继续遍历其他元素
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -206,18 +208,19 @@ public class Task extends Node {
|
|
|
|
|
|
|
|
|
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
|
String name = getName();
|
|
|
|
String name = getName();
|
|
|
|
try {
|
|
|
|
try {// 判断是否存在元信息,如果不存在则认为是新创建的任务
|
|
|
|
if (mMetaInfo == null) {
|
|
|
|
if (mMetaInfo == null) {
|
|
|
|
// new task created from web
|
|
|
|
// new task created from web
|
|
|
|
if (name == null) {
|
|
|
|
if (name == null) {
|
|
|
|
Log.w(TAG, "the note seems to be an empty one");
|
|
|
|
Log.w(TAG, "the note seems to be an empty one");
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//创建对象
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
JSONObject note = new JSONObject();
|
|
|
|
JSONObject note = new JSONObject();
|
|
|
|
JSONArray dataArray = new JSONArray();
|
|
|
|
JSONArray dataArray = new JSONArray();
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
|
|
|
|
//将对象加入不同方法中
|
|
|
|
data.put(DataColumns.CONTENT, name);
|
|
|
|
data.put(DataColumns.CONTENT, name);
|
|
|
|
dataArray.put(data);
|
|
|
|
dataArray.put(data);
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
|
|
@ -226,22 +229,26 @@ public class Task extends Node {
|
|
|
|
return js;
|
|
|
|
return js;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// synced task
|
|
|
|
// synced task
|
|
|
|
|
|
|
|
// 同步任务,获取元信息中的note和dataArray对象
|
|
|
|
JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
|
|
|
JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
|
|
|
JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
|
|
|
JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
|
|
|
|
// 获取当前元素的值,并判断其类型是否为笔记类型
|
|
|
|
JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
|
|
|
|
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
|
|
|
|
|
|
|
|
// 如果类型为笔记类型,则将名称放入该data对象的CONTENT键中,并跳出循环
|
|
|
|
data.put(DataColumns.CONTENT, getName());
|
|
|
|
data.put(DataColumns.CONTENT, getName());
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 将note的TYPE键的值设置为笔记类型,并返回元信息对象mMetaInfo
|
|
|
|
note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
|
|
|
|
note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
|
|
|
|
return mMetaInfo;
|
|
|
|
return mMetaInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
|
|
|
|
// 如果在处理过程中出现JSON解析异常,打印错误日志并输出异常堆栈信息,最后返回空对象
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|