/* * 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;//“导入安卓数据库游标类;”。 import android.util.Log;//导入安卓工具类 Log;”。 import net.micode.notes.tool.GTaskStringUtils;//翻译为“导入来自 net.micode.notes.tool 包下的 GTaskStringUtils 类;”。 import org.json.JSONException;//导入来自 org.json 包下的 JSON 异常类;”。 import org.json.JSONObject;//导入来自 org.json 包下的 JSON 对象类;”。. public class MetaData extends Task {//公共类 MetaData 继承自 Task 类。” private final static String TAG = MetaData.class.getSimpleName();//“私有最终静态字符串变量 TAG 被赋值为 MetaData 类的简单名称。” private String mRelatedGid = null;//私有字符串变量 mRelatedGid 初始化为 null。” public void setMeta(String gid, JSONObject metaInfo) {//“公共方法 setMeta,接收一个字符串 gid 和一个 JSON 对象 metaInfo。” try {//“尝试执行以下代码块。” metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);//“将 gid 放入 metaInfo 的键为 GTaskStringUtils.META_HEAD_GTASK_ID 的位置。 } catch (JSONException e) {//“将 gid 放入 metaInfo 的键为 GTaskStringUtils.META_HEAD_GTASK_ID 的位置。 Log.e(TAG, "failed to put related gid");//“使用错误级别记录日志,TAG 为标识,信息为‘failed to put related gid’(未能放入相关的 gid)。” } setNotes(metaInfo.toString());//“设置注释为 metaInfo 的字符串形式。” setName(GTaskStringUtils.META_NOTE_NAME);//“设置注释为 metaInfo 的字符串形式。”v } public String getRelatedGid() {//“公共方法 getRelatedGid,返回一个字符串。” return mRelatedGid;//“返回 mRelatedGid 的值。” } @Override public boolean isWorthSaving() {//翻译为“重写父类方法。公共方法 isWorthSaving,返回一个布尔值。” return getNotes() != null;//“返回获取到的注释不为 null 的结果。” } @Override public void setContentByRemoteJSON(JSONObject js) {//“重写父类方法。公共方法 setContentByRemoteJSON,接收一个 JSON 对象 js。” super.setContentByRemoteJSON(js);//“重写父类方法。公共方法 setContentByRemoteJSON,接收一个 JSON 对象 js。” if (getNotes() != null) {//“重写父类方法。公共方法 setContentByRemoteJSON,接收一个 JSON 对象 js。” try {//“重写父类方法。公共方法 setContentByRemoteJSON,接收一个 JSON 对象 js。” JSONObject metaInfo = new JSONObject(getNotes().trim());//“创建一个新的 JSON 对象 metaInfo,参数为去除首尾空白的获取到的注释。” mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);//将 metaInfo 中键为 GTaskStringUtils.META_HEAD_GTASK_ID 的值赋给 mRelatedGid。” } catch (JSONException e) {//“捕获 JSON 异常,如果发生异常执行以下代码块。” Log.w(TAG, "failed to get related gid");//“使用警告级别记录日志,TAG 为标识,信息为‘failed to get related gid’(未能获取到相关的 gid)。” mRelatedGid = null;//“将 mRelatedGid 赋值为 null。” } } } @Override public void setContentByLocalJSON(JSONObject js) {//“重写父类方法。公共方法 setContentByLocalJSON,接收一个 JSON 对象 js。” // this function should not be called //此函数不应被调用。” throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");//“抛出非法访问错误,信息为‘MetaData:setContentByLocalJSON should not be called’(MetaData 的 setContentByLocalJSON 不应被调用)。” } @Override public JSONObject getLocalJSONFromContent() {//“重写父类方法。公共方法 getLocalJSONFromContent,返回一个 JSON 对象。” throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");//“抛出非法访问错误,信息为‘MetaData:getLocalJSONFromContent should not be called’(MetaData 的 getLocalJSONFromContent 不应被调用)。” } @Override public int getSyncAction(Cursor c) {//“重写父类方法。公共方法 getSyncAction,接收一个游标 c,返回一个整数。” throw new IllegalAccessError("MetaData:getSyncAction should not be called");//抛出非法访问错误,信息为‘MetaData:getSyncAction should not be called’(MetaData 的 getSyncAction 不应被调用)。” } }