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.
rj2201-xiaozuxuexi/gtask.data.txt

97 lines
4.2 KiB

**********************MetaData*********** /* * 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; //处理数据库查询的Cursor类 import android.util.Log; //日志记录类Log import net.micode.notes.tool.GTaskStringUtils; import org.json.JSONException; import org.json.JSONObject; public class MetaData extends Task //声明MetaData类,这个类extends了Task类,即继承了Task类的所有属性和方法 { private final static String TAG = MetaData.class.getSimpleName(); //定义了一个私有静态常量字符串 TAG,用于标识日志记录的来源。TAG 的值是 MetaData 类的简单名称 private String mRelatedGid = null; //声明了一个私有字符串变量 mRelatedGid,用于存储关联的 GID(Google 任务 ID) public void setMeta(String gid, JSONObject metaInfo) { //定义了一个公共方法 setMeta,接受两个参数:一个字符串 gid 和一个 JSONObject metaInfo try { metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); } catch (JSONException e) { Log.e(TAG, "failed to put related gid"); } //通过调用 JSONObject 的 put 方法,将 GID 存储到传入的 metaInfo 中。如果出现 JSON 解析异常,则记录错误日志,failed to put related gid setNotes(metaInfo.toString()); setName(GTaskStringUtils.META_NOTE_NAME); } //然后,将转换后的 metaInfo 对象转换为字符串,并将其设置为任务的注释(notes),同时设置任务的名称为预定义的 META_NOTE_NAME。 public String getRelatedGid() { return mRelatedGid; //定义公共方法 getRelatedGid,用于获取关联的 GID } @Override public boolean isWorthSaving() { return getNotes() != null; } //重写了父类的方法 isWorthSaving,用于判断任务是否值得保存。如果任务的注释不为 null,则返回 true @Override public void setContentByRemoteJSON(JSONObject js) { //重写了父类的方法 setContentByRemoteJSON,用于从远程 JSON 数据设置任务的内容 super.setContentByRemoteJSON(js); //首先调用父类的方法来设置任务的内容 if (getNotes() != null) { try { JSONObject metaInfo = new JSONObject(getNotes().trim()); mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); } catch (JSONException e) { Log.w(TAG, "failed to get related gid"); mRelatedGid = null; } } //然后,从任务的注释中提取关联的 GID,如果提取失败则记录警告日志"failed to get related gid" } @Override public void setContentByLocalJSON(JSONObject js) { // this function should not be called throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); } //重写了父类的方法 setContentByLocalJSON,但是抛出了一个非法访问错误,表示这个方法不应该被调用 @Override public JSONObject getLocalJSONFromContent() { throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); } //重写了父类的方法 getLocalJSONFromContent,也抛出了一个非法访问错误。 @Override public int getSyncAction(Cursor c) { throw new IllegalAccessError("MetaData:getSyncAction should not be called"); } //重写了父类的方法 getSyncAction,同样抛出了一个非法访问错误。 }
1 year ago
**********************MetaData***********
/*
* 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; //处理数据库查询的Cursor类
import android.util.Log; //日志记录类Log
import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
public class MetaData extends Task //声明MetaData类这个类extends了Task类即继承了Task类的所有属性和方法
{
private final static String TAG = MetaData.class.getSimpleName();
//定义了一个私有静态常量字符串 TAG用于标识日志记录的来源。TAG 的值是 MetaData 类的简单名称
private String mRelatedGid = null;
//声明了一个私有字符串变量 mRelatedGid用于存储关联的 GIDGoogle 任务 ID
public void setMeta(String gid, JSONObject metaInfo) {
//定义了一个公共方法 setMeta接受两个参数一个字符串 gid 和一个 JSONObject metaInfo
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
Log.e(TAG, "failed to put related gid");
}
//通过调用 JSONObject 的 put 方法,将 GID 存储到传入的 metaInfo 中。如果出现 JSON 解析异常则记录错误日志failed to put related gid
setNotes(metaInfo.toString());
setName(GTaskStringUtils.META_NOTE_NAME);
}
//然后,将转换后的 metaInfo 对象转换为字符串并将其设置为任务的注释notes同时设置任务的名称为预定义的 META_NOTE_NAME。
public String getRelatedGid() {
return mRelatedGid; //定义公共方法 getRelatedGid用于获取关联的 GID
}
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
//重写了父类的方法 isWorthSaving用于判断任务是否值得保存。如果任务的注释不为 null则返回 true
@Override
public void setContentByRemoteJSON(JSONObject js) {
//重写了父类的方法 setContentByRemoteJSON用于从远程 JSON 数据设置任务的内容
super.setContentByRemoteJSON(js); //首先调用父类的方法来设置任务的内容
if (getNotes() != null) {
try {
JSONObject metaInfo = new JSONObject(getNotes().trim());
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
Log.w(TAG, "failed to get related gid");
mRelatedGid = null;
}
} //然后,从任务的注释中提取关联的 GID如果提取失败则记录警告日志"failed to get related gid"
}
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
//重写了父类的方法 setContentByLocalJSON但是抛出了一个非法访问错误表示这个方法不应该被调用
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
//重写了父类的方法 getLocalJSONFromContent也抛出了一个非法访问错误。
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}
//重写了父类的方法 getSyncAction同样抛出了一个非法访问错误。
}