|
|
/*
|
|
|
* 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; // 导入android数据库Cursor类
|
|
|
import android.util.Log; // 导入android日志工具类Log
|
|
|
|
|
|
import net.micode.notes.tool.GTaskStringUtils; // 导入net.micode.notes.tool.GTaskStringUtils工具类
|
|
|
|
|
|
import org.json.JSONException; // 导入org.json.JSONException类
|
|
|
import org.json.JSONObject; // 导入org.json.JSONObject类
|
|
|
|
|
|
// MetaData类继承自Task类
|
|
|
public class MetaData extends Task {
|
|
|
private final static String TAG = MetaData.class.getSimpleName(); // 声明私有静态常量TAG,用于记录日志信息,值为当前类的简单名称
|
|
|
|
|
|
private String mRelatedGid = null; // 声明私有属性mRelatedGid,初始值为null
|
|
|
|
|
|
// 设置meta信息的方法,接受gid和metaInfo作为参数
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
try {
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); // 尝试将GTask ID放入metaInfo中
|
|
|
} catch (JSONException e) {
|
|
|
Log.e(TAG, "failed to put related gid"); // 捕获JSONException异常,记录错误日志
|
|
|
}
|
|
|
setNotes(metaInfo.toString()); // 将metaInfo转换为字符串后设置为笔记内容
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME); // 设置名称为META_NOTE_NAME
|
|
|
}
|
|
|
|
|
|
// 获取相关GTask ID的方法
|
|
|
public String getRelatedGid() {
|
|
|
return mRelatedGid; // 返回mRelatedGid属性的值
|
|
|
}
|
|
|
|
|
|
// 判断是否值得保存的方法
|
|
|
@Override
|
|
|
public boolean isWorthSaving() {
|
|
|
return getNotes() != null; // 返回笔记内容是否不为null
|
|
|
}
|
|
|
|
|
|
// 根据远程JSON内容设置对象内容的方法
|
|
|
@Override
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
super.setContentByRemoteJSON(js); // 调用父类的setContentByRemoteJSON方法
|
|
|
if (getNotes() != null) { // 如果笔记内容不为null
|
|
|
try {
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim()); // 创建新的JSONObject对象,内容为去除空格后的笔记内容
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); // 获取metaInfo中的GTask ID并赋值给mRelatedGid
|
|
|
} catch (JSONException e) {
|
|
|
Log.w(TAG, "failed to get related gid"); // 捕获JSONException异常,记录警告日志
|
|
|
mRelatedGid = null; // 将mRelatedGid置为null
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 根据本地JSON内容设置对象内容的方法
|
|
|
@Override
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
// this function should not be called
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); // 抛出非法访问错误,表明不应调用该方法
|
|
|
}
|
|
|
|
|
|
// 从内容获取本地JSON对象的方法
|
|
|
@Override
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); // 抛出非法访问错误,表明不应调用该方法
|
|
|
}
|
|
|
|
|
|
// 获取同步操作类型的方法
|
|
|
@Override
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called"); // 抛出非法访问错误,表明不应调用该方法
|
|
|
}
|
|
|
}
|