From cd33eef82958003cf79b2d85abc3082feb38c74f Mon Sep 17 00:00:00 2001 From: LZ <2929718516@qq.com> Date: Sat, 28 Dec 2024 22:03:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=99=E6=AE=B5=E4=BB=A3=E7=A0=81=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E4=BA=86=E4=B8=80=E4=B8=AAMetaData=E7=B1=BB=EF=BC=8C?= =?UTF-8?q?=E5=AE=83=E7=BB=A7=E6=89=BF=E8=87=AATask=E7=B1=BB=E3=80=82MetaD?= =?UTF-8?q?ata=E7=B1=BB=E7=94=A8=E4=BA=8E=E5=A4=84=E7=90=86=E4=B8=8EGoogle?= =?UTF-8?q?=20Tasks=E7=9B=B8=E5=85=B3=E7=9A=84=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=EF=BC=8C=E5=8C=85=E6=8B=AC=E8=AE=BE=E7=BD=AE=E5=92=8C=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8E=E5=85=83=E6=95=B0=E6=8D=AE=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84Gid=EF=BC=88=E5=8F=AF=E8=83=BD=E6=98=AFGoogle=20Tasks?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E4=BB=BB=E5=8A=A1ID=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E6=A0=B9=E6=8D=AEJSON=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=92=8C=E8=8E=B7=E5=8F=96MetaData=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E3=80=82=E4=BB=A3=E7=A0=81=E4=B8=AD=E8=BF=98?= =?UTF-8?q?=E5=8C=85=E6=8B=AC=E4=BA=86=E4=B8=80=E4=BA=9B=E4=B8=8D=E5=BA=94?= =?UTF-8?q?=E8=AF=A5=E8=A2=AB=E8=B0=83=E7=94=A8=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E8=BF=99=E4=BA=9B=E6=96=B9=E6=B3=95=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E6=8A=9B=E5=87=BAIllegalAccessError=E5=BC=82=E5=B8=B8=E6=9D=A5?= =?UTF-8?q?=E8=A1=A8=E6=98=8E=E5=AE=83=E4=BB=AC=E4=B8=8D=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E5=9C=A8MetaData=E7=B1=BB=E7=9A=84=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E4=B8=AD=E8=A2=AB=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MetaData.java | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 MetaData.java diff --git a/MetaData.java b/MetaData.java new file mode 100644 index 0000000..646d9ff --- /dev/null +++ b/MetaData.java @@ -0,0 +1,100 @@ +/* + * 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. + */ + +// 声明MetaData类,它继承自Task类 +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; // 导入JSONException类,用于处理JSON异常 +import org.json.JSONObject; // 导入JSONObject类,用于处理JSON对象 + +// MetaData类的定义开始 +public class MetaData extends Task { + // 定义日志标签 + private final static String TAG = MetaData.class.getSimpleName(); + + // 定义与MetaData相关的Gid(可能是Google Tasks中的任务ID) + private String mRelatedGid = null; + + // 设置MetaData的gid和metaInfo + public void setMeta(String gid, JSONObject metaInfo) { + try { + // 在metaInfo中添加gid信息 + metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); + } catch (JSONException e) { + // 如果添加失败,则记录错误日志 + Log.e(TAG, "failed to put related gid"); + } + // 将metaInfo转换为字符串并设置为任务的备注 + setNotes(metaInfo.toString()); + // 设置任务名称为特定的Meta任务名称 + setName(GTaskStringUtils.META_NOTE_NAME); + } + + // 获取与MetaData相关的Gid + public String getRelatedGid() { + return mRelatedGid; + } + + // 判断MetaData是否值得保存(基于备注是否非空) + @Override + public boolean isWorthSaving() { + return getNotes() != null; + } + + // 根据远程JSON对象设置MetaData的内容 + @Override + public void setContentByRemoteJSON(JSONObject js) { + // 调用父类的方法设置内容 + super.setContentByRemoteJSON(js); + // 如果备注不为空,则尝试解析并获取相关的Gid + if (getNotes() != null) { + try { + JSONObject metaInfo = new JSONObject(getNotes().trim()); + mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); + } catch (JSONException e) { + // 如果解析失败,则记录警告日志,并将Gid设置为null + Log.w(TAG, "failed to get related gid"); + mRelatedGid = null; + } + } + } + + // 根据本地JSON对象设置MetaData的内容(不应被调用) + @Override + public void setContentByLocalJSON(JSONObject js) { + // 抛出异常,表示这个方法不应该被调用 + throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); + } + + // 从MetaData的内容获取本地JSON对象(不应被调用) + @Override + public JSONObject getLocalJSONFromContent() { + // 抛出异常,表示这个方法不应该被调用 + throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); + } + + // 根据Cursor获取同步操作(不应被调用) + @Override + public int getSyncAction(Cursor c) { + // 抛出异常,表示这个方法不应该被调用 + throw new IllegalAccessError("MetaData:getSyncAction should not be called"); + } +} \ No newline at end of file