main
branch_chen
Branch_05
branch01
branch03
branch02
Branch_chao
${ noResults }
1 Commits (0f631b2f78bfac8ec437a0d6ead3744a33e90a1a)
Author | SHA1 | Message | Date |
---|---|---|---|
|
0f631b2f78 |
**********************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 |