|
|
/*
|
|
|
* 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.
|
|
|
*/
|
|
|
|
|
|
// 声明MetaData类,它继承自Task类
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
|
import android.database.Cursor; // 导入Cursor类,用于数据库操作
|
|
|
import android.util.Log; // 导入Log类,用于日志输出
|
|
|
|
|
|
import net.micode.notes.tool.GTaskStringUtils; // 导入工具类,用于处理字符串
|
|
|
|
|
|
import org.json.JSONException; // 导入JSONException类,用于处理JSON异常
|
|
|
import org.json.JSONObject; // 导入JSONObject类,用于处理JSON对象
|
|
|
|
|
|
// MetaData类的定义开始
|
|
|
public class MetaData extends Task {
|
|
|
// 定义日志标签
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
|
|
|
// 定义与MetaData相关的Gid(可能是Google Tasks中的任务ID)
|
|
|
private String mRelatedGid = null;
|
|
|
|
|
|
// 设置MetaData的gid和metaInfo
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
try {
|
|
|
// 在metaInfo中添加gid信息
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果添加失败,则记录错误日志
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
}
|
|
|
// 将metaInfo转换为字符串并设置为任务的备注
|
|
|
setNotes(metaInfo.toString());
|
|
|
// 设置任务名称为特定的Meta任务名称
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
}
|
|
|
|
|
|
// 获取与MetaData相关的Gid
|
|
|
public String getRelatedGid() {
|
|
|
return mRelatedGid;
|
|
|
}
|
|
|
|
|
|
// 判断MetaData是否值得保存(基于备注是否非空)
|
|
|
@Override
|
|
|
public boolean isWorthSaving() {
|
|
|
return getNotes() != null;
|
|
|
}
|
|
|
|
|
|
// 根据远程JSON对象设置MetaData的内容
|
|
|
@Override
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
// 调用父类的方法设置内容
|
|
|
super.setContentByRemoteJSON(js);
|
|
|
// 如果备注不为空,则尝试解析并获取相关的Gid
|
|
|
if (getNotes() != null) {
|
|
|
try {
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果解析失败,则记录警告日志,并将Gid设置为null
|
|
|
Log.w(TAG, "failed to get related gid");
|
|
|
mRelatedGid = null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 根据本地JSON对象设置MetaData的内容(不应被调用)
|
|
|
@Override
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
// 抛出异常,表示这个方法不应该被调用
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
}
|
|
|
|
|
|
// 从MetaData的内容获取本地JSON对象(不应被调用)
|
|
|
@Override
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
// 抛出异常,表示这个方法不应该被调用
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
}
|
|
|
|
|
|
// 根据Cursor获取同步操作(不应被调用)
|
|
|
@Override
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
// 抛出异常,表示这个方法不应该被调用
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
}
|
|
|
} |