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

99 lines
3.9 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.
*/
// 这段注释是文件的版权声明表明该文件由MiCode开源社区编写并遵循Apache License 2.0。
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类用于处理与Google任务相关的元数据。
public class MetaData extends Task {
// 类的标签,用于日志记录。
private final static String TAG = MetaData.class.getSimpleName();
// 用于存储与Google任务相关的全局ID。
private String mRelatedGid = null;
// 设置元数据信息的方法。
public void setMeta(String gid, JSONObject metaInfo) {
try {
// 将全局ID添加到元信息对象中。
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
// 如果在添加全局ID时发生错误记录错误日志。
Log.e(TAG, "failed to put related gid");
}
// 将元信息对象转换为字符串,并设置为笔记内容。
setNotes(metaInfo.toString());
// 设置元数据的名称。
setName(GTaskStringUtils.META_NOTE_NAME);
}
// 获取与Google任务相关的全局ID。
public String getRelatedGid() {
return mRelatedGid;
}
// 重写isWorthSaving方法判断是否有值得保存的笔记内容。
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
// 重写setContentByRemoteJSON方法从远程JSON设置内容。
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
if (getNotes() != null) {
try {
// 从笔记内容中解析出元信息对象。
JSONObject metaInfo = new JSONObject(getNotes().trim());
// 获取并设置与Google任务相关的全局ID。
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
// 如果解析元信息对象失败记录警告日志并设置全局ID为null。
Log.w(TAG, "failed to get related gid");
mRelatedGid = null;
}
}
}
// 重写setContentByLocalJSON方法但由于MetaData类的特殊性此方法不应该被调用。
@Override
public void setContentByLocalJSON(JSONObject js) {
// 抛出异常,表明此方法不应该被调用。
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
// 重写getLocalJSONFromContent方法但由于MetaData类的特殊性此方法不应该被调用。
@Override
public JSONObject getLocalJSONFromContent() {
// 抛出异常,表明此方法不应该被调用。
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
// 重写getSyncAction方法但由于MetaData类的特殊性此方法不应该被调用。
@Override
public int getSyncAction(Cursor c) {
// 抛出异常,表明此方法不应该被调用。
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}
}