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.

102 lines
4.1 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.

/*
* 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");
}
}