You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package net.micode.notes.gtask.data;
// 定义MetaData类它继承自Task类
public class MetaData extends Task {
// 定义一个私有静态常量TAG用于记录类的简单名称通常用于日志输出
private final static String TAG = MetaData.class.getSimpleName();
// 定义一个私有成员变量mRelatedGid用于存储相关的Gid初始化为null
private String mRelatedGid = null;
// 此方法接受一个字符串gid和一个JSONObject类型的metaInfo作为参数
public void setMeta(String gid, JSONObject metaInfo) {
try {
// 尝试将gid放入metaInfo对象中键为GTaskStringUtils.META_HEAD_GTASK_ID
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
// 如果发生JSON异常在日志中记录错误信息表示无法放入相关gid
Log.e(TAG, "failed to put related gid");
}
// 将metaInfo转换为字符串后设置为笔记内容
setNotes(metaInfo.toString());
// 设置名称为GTaskStringUtils.META_NOTE_NAME
setName(GTaskStringUtils.META_NOTE_NAME);
}
// 此方法用于获取相关的Gid
public String getRelatedGid() {
return mRelatedGid;
}
// 重写isWorthSaving方法判断笔记内容是否不为空如果不为空则表示值得保存
@Override
public boolean isWorthSaving() {
return getNotes()!= null;
}
// 重写setContentByRemoteJSON方法
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
if (getNotes()!= null) {
try {
// 如果笔记内容不为空将其转换为JSONObject类型的metaInfo
JSONObject metaInfo = new JSONObject(getNotes().trim());
// 从metaInfo中获取相关的Gid字符串
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
// 如果发生JSON异常在日志中记录警告信息表示无法获取相关gid
Log.w(TAG, "failed to get related gid");
mRelatedGid = null;
}
}
}
// 重写setContentByLocalJSON方法此方法不应该被调用如果调用则抛出IllegalAccessError异常
@Override
public void setContentByLocalJSON(JSONObject js) {
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
// 重写getLocalJSONFromContent方法此方法不应该被调用如果调用则抛出IllegalAccessError异常
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
// 重写getSyncAction方法此方法不应该被调用如果调用则抛出IllegalAccessError异常
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}
}