|
|
|
@ -14,48 +14,51 @@
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
package net.micode.notes.gtask.data;//包名声明:路径"net.micode.notes.gtask.data",文件中定义的类和接口都归属于这个包
|
|
|
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.database.Cursor;//导入Android平台的数据库Cursor类的语句
|
|
|
|
|
import android.util.Log;//引入工具类Log来存放一些通用的、与业务逻辑无关的工具方法
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.tool.GTaskStringUtils;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import org.json.JSONException; //引入"org.json.JSONException"类,用于处理JSON格式数据的异常
|
|
|
|
|
import org.json.JSONObject; //表示和操作JSON对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MetaData extends Task {
|
|
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
|
|
private final static String TAG = MetaData.class.getSimpleName(); //用于在日志中标识当前类的名称
|
|
|
|
|
|
|
|
|
|
private String mRelatedGid = null;
|
|
|
|
|
|
|
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
|
|
try {
|
|
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
try {
|
|
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
|
|
} catch (JSONException e) { //如果出现 JSONException 异常,则会捕获并记录日志
|
|
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
|
|
}
|
|
|
|
|
// try-catch 块中,将键值对 (GTaskStringUtils.META_HEAD_GTASK_ID, gid) 添加到传入的 metaInfo JSON 对象中。
|
|
|
|
|
|
|
|
|
|
setNotes(metaInfo.toString());
|
|
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getRelatedGid() {
|
|
|
|
|
return mRelatedGid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//是一个Java注解,用于告诉编译器该方法是重写父类或接口中的方法。
|
|
|
|
|
public boolean isWorthSaving() {
|
|
|
|
|
return getNotes() != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
|
|
super.setContentByRemoteJSON(js);
|
|
|
|
|
super.setContentByRemoteJSON(js); //调用父类的方法,传入参数js
|
|
|
|
|
if (getNotes() != null) {
|
|
|
|
|
try {
|
|
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());//转化为JSONObject对象
|
|
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); //提取特征字段
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
Log.w(TAG, "failed to get related gid");
|
|
|
|
|
mRelatedGid = null;
|
|
|
|
@ -63,6 +66,7 @@ public class MetaData extends Task {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//以下三段表示不应该被调用,如果调用了,抛出了一个IllegalAccessError异常,并提供了错误消息
|
|
|
|
|
@Override
|
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
|
// this function should not be called
|
|
|
|
|