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.
2Q1/MetaData.java

84 lines
5.3 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;//“导入安卓数据库游标类;”。
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 calledMetaData 的 setContentByLocalJSON 不应被调用)。”
}
@Override
public JSONObject getLocalJSONFromContent() {//“重写父类方法。公共方法 getLocalJSONFromContent返回一个 JSON 对象。”
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");//“抛出非法访问错误信息为MetaData:getLocalJSONFromContent should not be calledMetaData 的 getLocalJSONFromContent 不应被调用)。”
}
@Override
public int getSyncAction(Cursor c) {//“重写父类方法。公共方法 getSyncAction接收一个游标 c返回一个整数。”
throw new IllegalAccessError("MetaData:getSyncAction should not be called");//抛出非法访问错误信息为MetaData:getSyncAction should not be calledMetaData 的 getSyncAction 不应被调用)。”
}
}