对部分类进行了注释分析 #8

Merged
pjao9fvxr merged 1 commits from zhouzexin_branch into master 3 weeks ago

@ -25,11 +25,22 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
* Task
* Google Task
*/
public class MetaData extends Task {
// 日志标签
private final static String TAG = MetaData.class.getSimpleName();
// 关联的Google Task ID
private String mRelatedGid = null;
/**
*
* @param gid Google Task ID
* @param metaInfo JSON
*/
public void setMeta(String gid, JSONObject metaInfo) {
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
@ -40,15 +51,27 @@ public class MetaData extends Task {
setName(GTaskStringUtils.META_NOTE_NAME);
}
/**
* Google Task ID
* @return Google Task ID
*/
public String getRelatedGid() {
return mRelatedGid;
}
/**
*
* @return nulltrue
*/
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
/**
* JSON
* @param js JSON
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
@ -63,17 +86,33 @@ public class MetaData extends Task {
}
}
/**
* JSON
* @param js JSON
* @throws IllegalAccessError
*/
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
/**
* JSON
* @return JSON
* @throws IllegalAccessError
*/
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
/**
*
* @param c
* @return
* @throws IllegalAccessError
*/
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");

@ -20,33 +20,53 @@ import android.database.Cursor;
import org.json.JSONObject;
/**
*
* TaskTaskListGoogle Tasks
*/
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_LOCAL = 2;
// 从远程删除数据
public static final int SYNC_ACTION_DEL_REMOTE = 3;
// 从本地删除数据
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_LOCAL = 6;
// 同步冲突
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
// 同步错误
public static final int SYNC_ACTION_ERROR = 8;
// Google Task唯一标识符
private String mGid;
// 节点名称
private String mName;
// 最后修改时间
private long mLastModified;
// 是否已删除
private boolean mDeleted;
/**
*
*/
public Node() {
mGid = null;
mName = "";
@ -54,46 +74,105 @@ public abstract class Node {
mDeleted = false;
}
/**
* JSON
* @param actionId ID
* @return JSON
*/
public abstract JSONObject getCreateAction(int actionId);
/**
* JSON
* @param actionId ID
* @return JSON
*/
public abstract JSONObject getUpdateAction(int actionId);
/**
* JSON
* @param js JSON
*/
public abstract void setContentByRemoteJSON(JSONObject js);
/**
* JSON
* @param js JSON
*/
public abstract void setContentByLocalJSON(JSONObject js);
/**
* JSON
* @return JSON
*/
public abstract JSONObject getLocalJSONFromContent();
/**
*
* @param c
* @return
*/
public abstract int getSyncAction(Cursor c);
/**
* Google Task
* @param gid Google Task ID
*/
public void setGid(String gid) {
this.mGid = gid;
}
/**
*
* @param name
*/
public void setName(String name) {
this.mName = name;
}
/**
*
* @param lastModified
*/
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
/**
*
* @param deleted
*/
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
/**
* Google Task
* @return Google Task ID
*/
public String getGid() {
return this.mGid;
}
/**
*
* @return
*/
public String getName() {
return this.mName;
}
/**
*
* @return
*/
public long getLastModified() {
return this.mLastModified;
}
/**
*
* @return
*/
public boolean getDeleted() {
return this.mDeleted;
}

@ -35,42 +35,66 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
*
* ContentResolver
*/
public class SqlData {
// 日志标签
private static final String TAG = SqlData.class.getSimpleName();
// 无效ID常量
private static final int INVALID_ID = -99999;
// 数据查询投影数组
public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3
};
// 投影数组中ID列的索引
public static final int DATA_ID_COLUMN = 0;
// 投影数组中MIME类型列的索引
public static final int DATA_MIME_TYPE_COLUMN = 1;
// 投影数组中内容列的索引
public static final int DATA_CONTENT_COLUMN = 2;
// 投影数组中DATA1列的索引
public static final int DATA_CONTENT_DATA_1_COLUMN = 3;
// 投影数组中DATA3列的索引
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
// 内容解析器
private ContentResolver mContentResolver;
// 是否为创建操作
private boolean mIsCreate;
// 数据ID
private long mDataId;
// 数据MIME类型
private String mDataMimeType;
// 数据内容
private String mDataContent;
// 数据内容DATA1字段
private long mDataContentData1;
// 数据内容DATA3字段
private String mDataContentData3;
// 差异数据值,用于记录需要更新的字段
private ContentValues mDiffDataValues;
/**
*
* @param context
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -82,6 +106,11 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/**
*
* @param context
* @param c
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -89,6 +118,10 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/**
*
* @param c
*/
private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
@ -97,6 +130,11 @@ public class SqlData {
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
/**
* JSON
* @param js JSON
* @throws JSONException 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,6 +168,11 @@ public class SqlData {
mDataContentData3 = dataContentData3;
}
/**
* JSON
* @return JSON
* @throws JSONException JSON
*/
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
@ -144,6 +187,13 @@ public class SqlData {
return js;
}
/**
*
* @param noteId ID
* @param validateVersion
* @param version
* @throws ActionFailureException
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
@ -183,6 +233,10 @@ public class SqlData {
mIsCreate = false;
}
/**
* ID
* @return ID
*/
public long getId() {
return mDataId;
}

@ -38,11 +38,18 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
*
* ContentResolver
*/
public class SqlNote {
// 日志标签
private static final String TAG = SqlNote.class.getSimpleName();
// 无效ID常量
private static final int INVALID_ID = -99999;
// 笔记查询投影数组
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,
@ -52,76 +59,115 @@ public class SqlNote {
NoteColumns.VERSION
};
// 投影数组中ID列的索引
public static final int ID_COLUMN = 0;
// 投影数组中提醒日期列的索引
public static final int ALERTED_DATE_COLUMN = 1;
// 投影数组中背景颜色ID列的索引
public static final int BG_COLOR_ID_COLUMN = 2;
// 投影数组中创建日期列的索引
public static final int CREATED_DATE_COLUMN = 3;
// 投影数组中是否有附件列的索引
public static final int HAS_ATTACHMENT_COLUMN = 4;
// 投影数组中修改日期列的索引
public static final int MODIFIED_DATE_COLUMN = 5;
// 投影数组中笔记数量列的索引
public static final int NOTES_COUNT_COLUMN = 6;
// 投影数组中父ID列的索引
public static final int PARENT_ID_COLUMN = 7;
// 投影数组中摘要列的索引
public static final int SNIPPET_COLUMN = 8;
// 投影数组中类型列的索引
public static final int TYPE_COLUMN = 9;
// 投影数组中小组件ID列的索引
public static final int WIDGET_ID_COLUMN = 10;
// 投影数组中小组件类型列的索引
public static final int WIDGET_TYPE_COLUMN = 11;
// 投影数组中同步ID列的索引
public static final int SYNC_ID_COLUMN = 12;
// 投影数组中本地修改标记列的索引
public static final int LOCAL_MODIFIED_COLUMN = 13;
// 投影数组中原始父ID列的索引
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
// 投影数组中Google Task ID列的索引
public static final int GTASK_ID_COLUMN = 15;
// 投影数组中版本列的索引
public static final int VERSION_COLUMN = 16;
// 上下文对象
private Context mContext;
// 内容解析器
private ContentResolver mContentResolver;
// 是否为创建操作
private boolean mIsCreate;
// 笔记ID
private long mId;
// 提醒日期
private long mAlertDate;
// 背景颜色ID
private int mBgColorId;
// 创建日期
private long mCreatedDate;
// 是否有附件01
private int mHasAttachment;
// 修改日期
private long mModifiedDate;
// 父文件夹ID
private long mParentId;
// 笔记摘要
private String mSnippet;
// 笔记类型(文件夹或笔记)
private int mType;
// 小组件ID
private int mWidgetId;
// 小组件类型
private int mWidgetType;
// 原始父文件夹ID
private long mOriginParent;
// 版本号
private long mVersion;
// 差异笔记值,用于记录需要更新的字段
private ContentValues mDiffNoteValues;
// 数据内容列表
private ArrayList<SqlData> mDataList;
/**
*
* @param context
*/
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -143,6 +189,11 @@ public class SqlNote {
mDataList = new ArrayList<SqlData>();
}
/**
*
* @param context
* @param c
*/
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -154,6 +205,11 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
}
/**
* ID
* @param context
* @param id ID
*/
public SqlNote(Context context, long id) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -163,9 +219,12 @@ public class SqlNote {
if (mType == Notes.TYPE_NOTE)
loadDataContent();
mDiffNoteValues = new ContentValues();
}
/**
* ID
* @param id ID
*/
private void loadFromCursor(long id) {
Cursor c = null;
try {
@ -185,6 +244,10 @@ public class SqlNote {
}
}
/**
*
* @param c
*/
private void loadFromCursor(Cursor c) {
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
@ -200,6 +263,9 @@ public class SqlNote {
mVersion = c.getLong(VERSION_COLUMN);
}
/**
*
*/
private void loadDataContent() {
Cursor c = null;
mDataList.clear();
@ -226,6 +292,11 @@ public class SqlNote {
}
}
/**
* JSON
* @param js JSON
* @return
*/
public boolean setContent(JSONObject js) {
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
@ -359,6 +430,10 @@ public class SqlNote {
return true;
}
/**
* JSON
* @return JSONnull
*/
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
@ -407,39 +482,76 @@ public class SqlNote {
return null;
}
/**
* ID
* @param id ID
*/
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
/**
* Google Task ID
* @param gid Google Task ID
*/
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
/**
* ID
* @param syncId ID
*/
public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
}
/**
*
*/
public void resetLocalModified() {
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
}
/**
* ID
* @return ID
*/
public long getId() {
return mId;
}
/**
* ID
* @return ID
*/
public long getParentId() {
return mParentId;
}
/**
*
* @return
*/
public String getSnippet() {
return mSnippet;
}
/**
*
* @return
*/
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
/**
*
* @param validateVersion
* @throws ActionFailureException
* @throws IllegalStateException ID
*/
public void commit(boolean validateVersion) {
if (mIsCreate) {
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {

@ -32,19 +32,32 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
* Google TasksNode
*
*/
public class Task extends Node {
// 日志标签
private static final String TAG = Task.class.getSimpleName();
// 任务是否已完成
private boolean mCompleted;
// 任务的详细说明
private String mNotes;
// 任务的元信息JSON对象
private JSONObject mMetaInfo;
// 前一个兄弟任务(用于排序)
private Task mPriorSibling;
// 父任务列表
private TaskList mParent;
/**
*
*/
public Task() {
super();
mCompleted = false;
@ -54,6 +67,12 @@ public class Task extends Node {
mMetaInfo = null;
}
/**
* JSON
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -103,6 +122,12 @@ public class Task extends Node {
return js;
}
/**
* JSON
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -135,6 +160,11 @@ public class Task extends Node {
return js;
}
/**
* JSON
* @param js JSON
* @throws ActionFailureException JSON
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -175,6 +205,10 @@ public class Task extends Node {
}
}
/**
* JSON
* @param js JSON
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
@ -204,6 +238,10 @@ public class Task extends Node {
}
}
/**
* JSON
* @return JSONnull
*/
public JSONObject getLocalJSONFromContent() {
String name = getName();
try {
@ -247,6 +285,10 @@ public class Task extends Node {
}
}
/**
*
* @param metaData
*/
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {
try {
@ -258,6 +300,11 @@ public class Task extends Node {
}
}
/**
*
* @param c
* @return SYNC_ACTION_NONESYNC_ACTION_UPDATE_REMOTE
*/
public int getSyncAction(Cursor c) {
try {
JSONObject noteInfo = null;
@ -311,39 +358,75 @@ public class Task extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
* @return
*/
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);
}
/**
*
* @param completed
*/
public void setCompleted(boolean completed) {
this.mCompleted = completed;
}
/**
*
* @param notes
*/
public void setNotes(String notes) {
this.mNotes = notes;
}
/**
*
* @param priorSibling
*/
public void setPriorSibling(Task priorSibling) {
this.mPriorSibling = priorSibling;
}
/**
*
* @param parent
*/
public void setParent(TaskList parent) {
this.mParent = parent;
}
/**
*
* @return
*/
public boolean getCompleted() {
return this.mCompleted;
}
/**
*
* @return
*/
public String getNotes() {
return this.mNotes;
}
/**
*
* @return
*/
public Task getPriorSibling() {
return this.mPriorSibling;
}
/**
*
* @return
*/
public TaskList getParent() {
return this.mParent;
}

Loading…
Cancel
Save