|
|
/*
|
|
|
* 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.
|
|
|
*/
|
|
|
// 这段注释是文件的版权声明,表明该文件由MiCode开源社区编写,并遵循Apache License 2.0。
|
|
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import net.micode.notes.tool.GTaskStringUtils;
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
// 定义了一个名为MetaData的类,它继承自Task类,用于处理与Google任务相关的元数据。
|
|
|
public class MetaData extends Task {
|
|
|
// 类的标签,用于日志记录。
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
// 用于存储与Google任务相关的全局ID。
|
|
|
private String mRelatedGid = null;
|
|
|
|
|
|
// 设置元数据信息的方法。
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
try {
|
|
|
// 将全局ID添加到元信息对象中。
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果在添加全局ID时发生错误,记录错误日志。
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
}
|
|
|
// 将元信息对象转换为字符串,并设置为笔记内容。
|
|
|
setNotes(metaInfo.toString());
|
|
|
// 设置元数据的名称。
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
}
|
|
|
|
|
|
// 获取与Google任务相关的全局ID。
|
|
|
public String getRelatedGid() {
|
|
|
return mRelatedGid;
|
|
|
}
|
|
|
|
|
|
// 重写isWorthSaving方法,判断是否有值得保存的笔记内容。
|
|
|
@Override
|
|
|
public boolean isWorthSaving() {
|
|
|
return getNotes() != null;
|
|
|
}
|
|
|
|
|
|
// 重写setContentByRemoteJSON方法,从远程JSON设置内容。
|
|
|
@Override
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
super.setContentByRemoteJSON(js);
|
|
|
if (getNotes() != null) {
|
|
|
try {
|
|
|
// 从笔记内容中解析出元信息对象。
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
// 获取并设置与Google任务相关的全局ID。
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果解析元信息对象失败,记录警告日志,并设置全局ID为null。
|
|
|
Log.w(TAG, "failed to get related gid");
|
|
|
mRelatedGid = null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 重写setContentByLocalJSON方法,但由于MetaData类的特殊性,此方法不应该被调用。
|
|
|
@Override
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
// 抛出异常,表明此方法不应该被调用。
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
}
|
|
|
|
|
|
// 重写getLocalJSONFromContent方法,但由于MetaData类的特殊性,此方法不应该被调用。
|
|
|
@Override
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
// 抛出异常,表明此方法不应该被调用。
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
}
|
|
|
|
|
|
// 重写getSyncAction方法,但由于MetaData类的特殊性,此方法不应该被调用。
|
|
|
@Override
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
// 抛出异常,表明此方法不应该被调用。
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
}
|
|
|
} |