添加GTask包中部分注释

dev
Morningstar 12 months ago
parent b23b750335
commit d50957c776

@ -24,31 +24,43 @@ import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
public class MetaData extends Task {
/*
* TAG
* getSimpleName
* */
private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null;
/*
*
* JSONObjectputTasksetNotessetName
* */
public void setMeta(String gid, JSONObject metaInfo) {
try {
// 将这对键值放入metaInfo这个jsonObject对象中
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
// 输出错误信息
Log.e(TAG, "failed to put related gid");
}
setNotes(metaInfo.toString());
setName(GTaskStringUtils.META_NOTE_NAME);
}
// 获取相关联的Gid
public String getRelatedGid() {
return mRelatedGid;
}
// 判断当前数据是否为空,若为空则返回真,即值得保存
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
// 使用远程json数据对象设置元数据内容
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
@ -63,17 +75,20 @@ public class MetaData extends Task {
}
}
// 使用本地json数据对象设置元数据内容一般不会用到若用到则抛出异常
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
// 从元数据内容中获取本地json对象一般不会用到若用到则抛出异常
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
// 获取同步动作状态,一般不会用到,若用到,则抛出异常
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*同步操作的基础数据类型,定义了相关指示同步操作的常量*/
package net.micode.notes.gtask.data;
import android.database.Cursor;
@ -21,31 +21,31 @@ import android.database.Cursor;
import org.json.JSONObject;
public abstract class Node {
public static final int SYNC_ACTION_NONE = 0;
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;

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*用于支持小米便签最底层的数据库相关操作和sqlNode的关系上是子集关系即data是node的子集节点*/
package net.micode.notes.gtask.data;
import android.content.ContentResolver;
@ -36,41 +36,33 @@ import org.json.JSONObject;
public class SqlData {
// 得到类的简写名称存入字符串TAG中
private static final String TAG = SqlData.class.getSimpleName();
private static final int INVALID_ID = -99999;
private static final int INVALID_ID = -99999;// 为nDAtaID置初值-99999
/*来自Notes类中定义的DataColumn中的一些常量*/
public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3
};
public static final int DATA_ID_COLUMN = 0;
public static final int DATA_MIME_TYPE_COLUMN = 1;
public static final int DATA_CONTENT_COLUMN = 2;
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;
private long mDataId;
private String mDataMimeType;
private String mDataContent;
private long mDataContentData1;
private String mDataContentData3;
private ContentValues mDiffDataValues;
public static final int DATA_ID_COLUMN = 0; // 数据ID列索引
public static final int DATA_MIME_TYPE_COLUMN = 1; // 数据MIME类型列索引
public static final int DATA_CONTENT_COLUMN = 2; // 数据内容列索引
public static final int DATA_CONTENT_DATA_1_COLUMN = 3; // 数据内容DATA1列索引
public static final int DATA_CONTENT_DATA_3_COLUMN = 4; // 数据内容DATA3列索引
private ContentResolver mContentResolver; // 内容解析器
private boolean mIsCreate; // 是否为新建数据
private long mDataId; // 数据ID
private String mDataMimeType; // 数据MIME类型
private String mDataContent; // 数据内容
private long mDataContentData1; // 数据内容DATA1
private String mDataContentData3; // 数据内容DATA3
private ContentValues mDiffDataValues; // 记录数据变化的ContentValues
// 构造函数,用于新建数据
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -82,6 +74,7 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
// 构造函数,用于从数据库读取数据
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -89,6 +82,7 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
// 从游标加载数据
private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
@ -97,6 +91,7 @@ public class SqlData {
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
// 设置内容根据JSON对象
public void setContent(JSONObject js) throws JSONException {
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
if (mIsCreate || mDataId != dataId) {
@ -130,9 +125,10 @@ public class SqlData {
mDataContentData3 = dataContentData3;
}
// 获取内容返回JSON对象
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
Log.e(TAG, "看起来我们还没有在数据库中创建这个");
return null;
}
JSONObject js = new JSONObject();
@ -144,8 +140,8 @@ public class SqlData {
return js;
}
// 提交数据到数据库
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
mDiffDataValues.remove(DataColumns.ID);
@ -156,8 +152,8 @@ public class SqlData {
try {
mDataId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
throw new ActionFailureException("create note failed");
Log.e(TAG, "获取便签ID错误" + e.toString());
throw new ActionFailureException("创建便签失败");
}
} else {
if (mDiffDataValues.size() > 0) {
@ -167,14 +163,14 @@ public class SqlData {
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
} else {
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
" ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.VERSION + "=?)", new String[] {
String.valueOf(noteId), String.valueOf(version)
});
}
if (result == 0) {
Log.w(TAG, "there is no update. maybe user updates note when syncing");
Log.w(TAG, "没有更新。可能用户在同步时更新了便签");
}
}
}
@ -183,7 +179,8 @@ public class SqlData {
mIsCreate = false;
}
// 获取数据ID
public long getId() {
return mDataId;
}
}
}

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**/
package net.micode.notes.gtask.data;
import android.appwidget.AppWidgetManager;

Loading…
Cancel
Save