|
|
/*
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
* You may obtain a copy of the License at
|
|
|
*
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
*
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
|
|
|
// 导入所需的包
|
|
|
package net.micode.notes.gtask.data; // 声明该类属于 net.micode.notes.gtask.data 包
|
|
|
|
|
|
import android.database.Cursor; // 导入Cursor类,用于数据库查询结果
|
|
|
import android.util.Log; // 导入Log类,用于日志记录
|
|
|
|
|
|
import net.micode.notes.tool.GTaskStringUtils; // 导入GTaskStringUtils工具类
|
|
|
|
|
|
import org.json.JSONException; // 导入JSONException,用于捕获JSON相关异常
|
|
|
import org.json.JSONObject; // 导入JSONObject类,用于JSON数据处理
|
|
|
|
|
|
|
|
|
// 定义MetaData类,继承自Task类
|
|
|
public class MetaData extends Task {
|
|
|
private final static String TAG = MetaData.class.getSimpleName(); // 定义TAG常量,表示该类的简短名称,用于日志打印
|
|
|
|
|
|
private String mRelatedGid = null; // 声明mRelatedGid变量,用于存储相关的Gid
|
|
|
|
|
|
// 设置Meta数据的方法,接受gid和meta信息(JSON对象)
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
try {
|
|
|
// 向metaInfo对象中添加一个名为META_HEAD_GTASK_ID的字段,值为传入的gid
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果发生JSON异常,记录错误日志
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
}
|
|
|
// 将metaInfo转为字符串并设置到notes字段中
|
|
|
setNotes(metaInfo.toString());
|
|
|
// 设置任务的名称为META_NOTE_NAME
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
}
|
|
|
|
|
|
// 获取相关的Gid
|
|
|
public String getRelatedGid() {
|
|
|
return mRelatedGid; // 返回mRelatedGid的值
|
|
|
}
|
|
|
|
|
|
// 重写isWorthSaving方法,判断该任务是否值得保存
|
|
|
@Override
|
|
|
public boolean isWorthSaving() {
|
|
|
// 如果notes不为null,返回true;否则返回false
|
|
|
return getNotes() != null;
|
|
|
}
|
|
|
|
|
|
// 重写setContentByRemoteJSON方法,从远程JSON对象设置内容
|
|
|
@Override
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
super.setContentByRemoteJSON(js); // 调用父类的setContentByRemoteJSON方法
|
|
|
if (getNotes() != null) {
|
|
|
try {
|
|
|
// 尝试将notes字段转为JSONObject对象
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
// 从metaInfo中提取Gid并赋值给mRelatedGid
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果发生JSON异常,记录警告日志,并将mRelatedGid设置为null
|
|
|
Log.w(TAG, "failed to get related gid");
|
|
|
mRelatedGid = null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 重写setContentByLocalJSON方法,禁止调用此方法
|
|
|
@Override
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
// 抛出IllegalAccessError,表示该方法不应被调用
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
}
|
|
|
|
|
|
// 重写getLocalJSONFromContent方法,禁止调用此方法
|
|
|
@Override
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
// 抛出IllegalAccessError,表示该方法不应被调用
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
}
|
|
|
|
|
|
// 重写getSyncAction方法,禁止调用此方法
|
|
|
@Override
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
// 抛出IllegalAccessError,表示该方法不应被调用
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
}
|
|
|
|
|
|
}
|