|
|
/*
|
|
|
* 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;
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import net.micode.notes.tool.GTaskStringUtils;
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
// MetaData类继承自Task类,从命名来看可能是用于处理任务相关的元数据信息
|
|
|
public class MetaData extends Task {
|
|
|
// 用于日志输出的标签,取类的简单名称,方便在日志中识别该类相关的日志信息
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
|
|
|
// 用于存储相关的Gid(可能是某种任务的唯一标识符之类的,具体要看业务逻辑),初始化为null
|
|
|
private String mRelatedGid = null;
|
|
|
|
|
|
// 设置元数据的方法,接收一个任务的gid和包含元数据信息的JSONObject对象
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
try {
|
|
|
// 尝试将给定的gid放入到metaInfo这个JSONObject中,键由GTaskStringUtils.META_HEAD_GTASK_ID指定
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果在放入gid到JSONObject时出现JSON解析异常,则记录错误日志
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
}
|
|
|
// 将更新后的metaInfo转换为字符串后设置为该对象的笔记内容(可能在Task类中有对应的处理逻辑)
|
|
|
setNotes(metaInfo.toString());
|
|
|
// 设置该对象的名称,名称由GTaskStringUtils.META_NOTE_NAME指定(具体值需看对应的工具类)
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
}
|
|
|
|
|
|
// 获取相关的Gid的方法
|
|
|
public String getRelatedGid() {
|
|
|
return mRelatedGid;
|
|
|
}
|
|
|
|
|
|
// 重写父类(Task类)的方法,用于判断该元数据对象是否值得保存,判断依据是笔记内容是否为null
|
|
|
@Override
|
|
|
public boolean isWorthSaving() {
|
|
|
return getNotes()!= null;
|
|
|
}
|
|
|
|
|
|
// 重写父类(Task类)的方法,根据远程的JSON对象来设置该对象的内容,同时尝试从设置后的笔记内容中提取相关的Gid
|
|
|
@Override
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
super.setContentByRemoteJSON(js);
|
|
|
if (getNotes()!= null) {
|
|
|
try {
|
|
|
// 将笔记内容字符串转换为JSONObject对象,以便提取其中的信息
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
// 从metaInfo中获取相关的Gid,并赋值给成员变量mRelatedGid
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果在获取Gid时出现JSON解析异常,则记录警告日志,并将mRelatedGid设置为null
|
|
|
Log.w(TAG, "failed to get related gid");
|
|
|
mRelatedGid = null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 重写父类(Task类)的方法,这里明确表示该方法不应该被调用,如果调用会抛出非法访问错误
|
|
|
@Override
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
// 抛出非法访问错误,并给出相应提示说明该方法不应被调用
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
}
|
|
|
|
|
|
// 重写父类(Task类)的方法,同样明确表示该方法不应该被调用,如果调用会抛出非法访问错误
|
|
|
@Override
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
}
|
|
|
|
|
|
// 重写父类(Task类)的方法,也明确表示该方法不应该被调用,如果调用会抛出非法访问错误
|
|
|
@Override
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
}
|
|
|
} |