From 4c70348c8239b03b04a4ae902843d011aaa80033 Mon Sep 17 00:00:00 2001 From: qw1ko <2644723863@qq.com> Date: Thu, 11 May 2023 16:14:15 +0800 Subject: [PATCH] =?UTF-8?q?gtask=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/gtask/data/MetaData.java | 38 ++++++--------- .../src/net/micode/notes/gtask/data/Node.java | 40 +++++----------- .../net/micode/notes/gtask/data/SqlData.java | 41 ++++++----------- .../net/micode/notes/gtask/data/SqlNote.java | 46 ++++++------------- 4 files changed, 54 insertions(+), 111 deletions(-) diff --git a/Notes-master2/src/net/micode/notes/gtask/data/MetaData.java b/Notes-master2/src/net/micode/notes/gtask/data/MetaData.java index 3a2050b..8b51954 100644 --- a/Notes-master2/src/net/micode/notes/gtask/data/MetaData.java +++ b/Notes-master2/src/net/micode/notes/gtask/data/MetaData.java @@ -1,19 +1,3 @@ -/* - * 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; @@ -27,36 +11,40 @@ import org.json.JSONObject; public class MetaData extends Task { private final static String TAG = MetaData.class.getSimpleName(); - + // 类的简写名称存入字符串TAG中,通过调用getSimpleName ()函数实现 private String mRelatedGid = null; - + // 设置数据,即生成元数据库 public void setMeta(String gid, JSONObject metaInfo) { - try { + try { //将这对键值放入metaInfo这个jsonobject对象中 metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); - } catch (JSONException e) { + } catch (JSONException e) { //输出错误信息 Log.e(TAG, "failed to put related gid"); } setNotes(metaInfo.toString()); setName(GTaskStringUtils.META_NOTE_NAME); + //调用Task类中的setNotes ()和setName ()函数 } - public String getRelatedGid() { + //getRelatedGid函数定义 return mRelatedGid; } @Override public boolean isWorthSaving() { + //isWorthSaving函数定义 return getNotes() != null; } @Override public void setContentByRemoteJSON(JSONObject js) { + //定义setContentByRemoteJSON函数 super.setContentByRemoteJSON(js); - if (getNotes() != null) { + 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; } @@ -65,17 +53,19 @@ public class MetaData extends Task { @Override public void setContentByLocalJSON(JSONObject js) { - // this function should not be called - throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); + //使用本地json数据对象设置元数据内容,一般不会用到,若用到,则抛出异常 + throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");//传递非法参数异常 } @Override public JSONObject getLocalJSONFromContent() { + //从元数据内容中获取本地json对象,一般不会用到,若用到,则抛出异常 throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); } @Override public int getSyncAction(Cursor c) { + //获取同步动作状态,一般不会用到,若用到,则抛出异常 throw new IllegalAccessError("MetaData:getSyncAction should not be called"); } diff --git a/Notes-master2/src/net/micode/notes/gtask/data/Node.java b/Notes-master2/src/net/micode/notes/gtask/data/Node.java index 63950e0..efa8801 100644 --- a/Notes-master2/src/net/micode/notes/gtask/data/Node.java +++ b/Notes-master2/src/net/micode/notes/gtask/data/Node.java @@ -1,51 +1,35 @@ -/* - * 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; import org.json.JSONObject; -public abstract class Node { - public static final int SYNC_ACTION_NONE = 0; +public abstract class Node {//定义各种常量 + public static final int SYNC_ACTION_NONE = 0;// 本地和云端都无可更新内容 - public static final int SYNC_ACTION_ADD_REMOTE = 1; + public static final int SYNC_ACTION_ADD_REMOTE = 1;// 在远程云端增加内容 - public static final int SYNC_ACTION_ADD_LOCAL = 2; + public static final int SYNC_ACTION_ADD_LOCAL = 2;// 在本地增加内容 - public static final int SYNC_ACTION_DEL_REMOTE = 3; + public static final int SYNC_ACTION_DEL_REMOTE = 3;// 在远程云端删除内容 - public static final int SYNC_ACTION_DEL_LOCAL = 4; + public static final int SYNC_ACTION_DEL_LOCAL = 4;// 在本地删除内容 - public static final int SYNC_ACTION_UPDATE_REMOTE = 5; + public static final int SYNC_ACTION_UPDATE_REMOTE = 5;// 将本地内容更新到远程云端 - public static final int SYNC_ACTION_UPDATE_LOCAL = 6; + public static final int SYNC_ACTION_UPDATE_LOCAL = 6;// 将远程云端内容更新到本地 - public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; + public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;// 同步出现冲突 - public static final int SYNC_ACTION_ERROR = 8; + public static final int SYNC_ACTION_ERROR = 8;// 同步出现错误 private String mGid; private String mName; - private long mLastModified; + private long mLastModified;//记录最后一次修改时间 - private boolean mDeleted; + private boolean mDeleted;//表征是否被删除 public Node() { mGid = null; diff --git a/Notes-master2/src/net/micode/notes/gtask/data/SqlData.java b/Notes-master2/src/net/micode/notes/gtask/data/SqlData.java index d3ec3be..f9fb6b5 100644 --- a/Notes-master2/src/net/micode/notes/gtask/data/SqlData.java +++ b/Notes-master2/src/net/micode/notes/gtask/data/SqlData.java @@ -1,19 +1,3 @@ -/* - * 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.content.ContentResolver; @@ -37,14 +21,13 @@ import org.json.JSONObject; public class SqlData { private static final String TAG = SqlData.class.getSimpleName(); - - private static final int INVALID_ID = -99999; - + //得到类的简写名称存入字符串TAG中,通过调用getSimpleName ()函数实现 + private static final int INVALID_ID = -99999;//将mDataId初始值置为-99999 public static final String[] PROJECTION_DATA = new String[] { DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1, DataColumns.DATA3 }; - + //以下五个变量作为sql表中5列的编号 public static final int DATA_ID_COLUMN = 0; public static final int DATA_MIME_TYPE_COLUMN = 1; @@ -54,7 +37,8 @@ public class SqlData { public static final int DATA_CONTENT_DATA_1_COLUMN = 3; public static final int DATA_CONTENT_DATA_3_COLUMN = 4; - + //定义以下八个变量 + //构造函数,用于初始化数据 private ContentResolver mContentResolver; private boolean mIsCreate; @@ -71,8 +55,8 @@ public class SqlData { private ContentValues mDiffDataValues; - public SqlData(Context context) { - mContentResolver = context.getContentResolver(); + public SqlData(Context context) { //判断是否直接用Content生成,是为true,否则为false + mContentResolver = context.getContentResolver();//mContentResolver用于获取ContentProvider提供的数据 mIsCreate = true; mDataId = INVALID_ID; mDataMimeType = DataConstants.NOTE; @@ -82,7 +66,7 @@ public class SqlData { mDiffDataValues = new ContentValues(); } - public SqlData(Context context, Cursor c) { + public SqlData(Context context, Cursor c) { //判断是否直接用Content生成,是为true,否则为false mContentResolver = context.getContentResolver(); mIsCreate = false; loadFromCursor(c); @@ -98,8 +82,9 @@ public class SqlData { } public void setContent(JSONObject js) throws JSONException { + //如果传入的JSONObject对象中有DataColumns.ID这一项,则设置,否则设为INVALID_ID long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID; - if (mIsCreate || mDataId != dataId) { + if (mIsCreate || mDataId != dataId) { mDiffDataValues.put(DataColumns.ID, dataId); } mDataId = dataId; @@ -130,7 +115,7 @@ public class SqlData { mDataContentData3 = dataContentData3; } - public JSONObject getContent() throws JSONException { + public JSONObject getContent() throws JSONException {//创建JSONObject对象。并将相关数据放入其中,并返回 if (mIsCreate) { Log.e(TAG, "it seems that we haven't created this in database yet"); return null; @@ -144,7 +129,7 @@ public class SqlData { return js; } - public void commit(long noteId, boolean validateVersion, long version) { + public void commit(long noteId, boolean validateVersion, long version) {//commit函数用于把当前造作所做的修改保存到数据库 if (mIsCreate) { if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) { @@ -183,7 +168,7 @@ public class SqlData { mIsCreate = false; } - public long getId() { + public long getId() {//获取当前id return mDataId; } } diff --git a/Notes-master2/src/net/micode/notes/gtask/data/SqlNote.java b/Notes-master2/src/net/micode/notes/gtask/data/SqlNote.java index 79a4095..b1c3f07 100644 --- a/Notes-master2/src/net/micode/notes/gtask/data/SqlNote.java +++ b/Notes-master2/src/net/micode/notes/gtask/data/SqlNote.java @@ -1,19 +1,3 @@ -/* - * 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.appwidget.AppWidgetManager; @@ -41,8 +25,8 @@ import java.util.ArrayList; public class SqlNote { private static final String TAG = SqlNote.class.getSimpleName(); - private static final int INVALID_ID = -99999; - + private static final int INVALID_ID = -99999;//将其初始值-99999 + // 集合了interface NoteColumns中所有SF常量(17个) public static final String[] PROJECTION_NOTE = new String[] { NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE, @@ -51,7 +35,7 @@ public class SqlNote { NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID, NoteColumns.VERSION }; - + //以下设置17个列的编号 public static final int ID_COLUMN = 0; public static final int ALERTED_DATE_COLUMN = 1; @@ -85,7 +69,7 @@ public class SqlNote { public static final int GTASK_ID_COLUMN = 15; public static final int VERSION_COLUMN = 16; - + //定义了17个内部的变量,其中12个可以由content中获得,5个需要初始化为0或者new private Context mContext; private ContentResolver mContentResolver; @@ -122,17 +106,17 @@ public class SqlNote { private ArrayList mDataList; - public SqlNote(Context context) { - mContext = context; + public SqlNote(Context context) {//构造函数只有context,对所有的变量进行初始化 + mContext = context;//变量赋值 mContentResolver = context.getContentResolver(); - mIsCreate = true; + mIsCreate = true;//初始化 mId = INVALID_ID; - mAlertDate = 0; + mAlertDate = 0;//初始化 mBgColorId = ResourceParser.getDefaultBgId(context); - mCreatedDate = System.currentTimeMillis(); + mCreatedDate = System.currentTimeMillis();//调用系统函数获得创建时间 mHasAttachment = 0; - mModifiedDate = System.currentTimeMillis(); - mParentId = 0; + mModifiedDate = System.currentTimeMillis();//最后一次修改时间初始化为创建时间 + mParentId = 0;//初始化 mSnippet = ""; mType = Notes.TYPE_NOTE; mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; @@ -143,7 +127,7 @@ public class SqlNote { mDataList = new ArrayList(); } - public SqlNote(Context context, Cursor c) { + public SqlNote(Context context, Cursor c) {//构造函数有context和一个数据库的cursor,多数变量通过cursor指向的一条记录直接进行初始化 mContext = context; mContentResolver = context.getContentResolver(); mIsCreate = false; @@ -153,8 +137,8 @@ public class SqlNote { loadDataContent(); mDiffNoteValues = new ContentValues(); } - - public SqlNote(Context context, long id) { + //SqlNote(Context context, long id)与SqlNote(Context context, long id)的实现方式基本相同 + public SqlNote(Context context, long id) {//构造函数,对获取的id进行初始化 mContext = context; mContentResolver = context.getContentResolver(); mIsCreate = false; @@ -166,7 +150,7 @@ public class SqlNote { } - private void loadFromCursor(long id) { + private void loadFromCursor(long id) {//通过id获得对应的ContentResolver中的cursor Cursor c = null; try { c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",