diff --git a/.idea/workspace.xml b/.idea/workspace.xml index cc5d225..3ab23e1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -11,8 +11,16 @@ + + + + + + + + @@ -436,29 +512,15 @@ - - - - - - - - - - - - - - - - - - - @@ -603,27 +665,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -631,40 +672,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -686,13 +693,6 @@ - - - - - - - @@ -724,13 +724,6 @@ - - - - - - - @@ -795,17 +788,108 @@ + + + + + + + + + + + + + + + + + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/net/micode/notes/gtask/data/MetaData.java b/app/src/main/java/net/micode/notes/gtask/data/MetaData.java index 5348f18..4d70b9d 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/MetaData.java +++ b/app/src/main/java/net/micode/notes/gtask/data/MetaData.java @@ -36,6 +36,7 @@ public class MetaData extends Task { try { //put中第一个元素在tool包中 metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); + //捕获json异常 } catch (JSONException e) { Log.e(TAG, "failed to put related gid"); } @@ -57,6 +58,7 @@ public class MetaData extends Task { @Override public void setContentByRemoteJSON(JSONObject js) { + //super这里就指当前对象 super.setContentByRemoteJSON(js); if (getNotes() != null) { try { @@ -69,7 +71,12 @@ public class MetaData extends Task { } } } - //以下三个函数表示不能在这里调用只能在Task类中调用 + /*override + 重写是子类对父类的允许访问的方法的实现过程进行重新编写, 返回值和形参都不能改变。 + 即外壳不变,核心重写! + 重写的好处在于子类可以根据需要,定义特定于自己的行为。 + 也就是说子类能够根据需要实现父类的方法。 + */ @Override public void setContentByLocalJSON(JSONObject js) { // this function should not be called diff --git a/app/src/main/java/net/micode/notes/gtask/data/Node.java b/app/src/main/java/net/micode/notes/gtask/data/Node.java index f5fbafa..778d76b 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/Node.java +++ b/app/src/main/java/net/micode/notes/gtask/data/Node.java @@ -23,27 +23,27 @@ import org.json.JSONObject; 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; private String mGid; private String mName; - + //记录最后一次修改 private long mLastModified; private boolean mDeleted; @@ -55,9 +55,9 @@ public abstract class Node { mLastModified = 0; mDeleted = false; } - + //创建 public abstract JSONObject getCreateAction(int actionId); - + //更新 public abstract JSONObject getUpdateAction(int actionId); //通过远程JSON设置内容 public abstract void setContentByRemoteJSON(JSONObject js); @@ -67,7 +67,7 @@ public abstract class Node { public abstract JSONObject getLocalJSONFromContent(); //获得同步动作 public abstract int getSyncAction(Cursor c); - //下面是一系列初始化 + //下面是一系列构造初始化 public void setGid(String gid) { this.mGid = gid; } diff --git a/app/src/main/java/net/micode/notes/gtask/data/SqlData.java b/app/src/main/java/net/micode/notes/gtask/data/SqlData.java index 6db398e..3abbac0 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/SqlData.java +++ b/app/src/main/java/net/micode/notes/gtask/data/SqlData.java @@ -39,19 +39,19 @@ import org.json.JSONObject; */ 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_type 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; @@ -71,7 +71,13 @@ public class SqlData { private long mDataContentData1; private String mDataContentData3; - + /*ContentValues + 就是用于保存一些数据(string/boolean/byte/double/float/int/long/short …)信息, + 这些信息可以被数据库操作时方便地使用。 + ContentValues 和 HashTable 类似,都是一种存储的机制, + 但是两者最大的区别就在于:ContentValues 只能存储基本类型的数据, + 像string、int之类的,不能存储对象这种东西,而HashTable却可以存储对象。 + */ private ContentValues mDiffDataValues; //构造函数两种 public SqlData(Context context) { @@ -134,11 +140,13 @@ public class SqlData { } //利用JSON获取内容属性 public JSONObject getContent() throws JSONException { + //记录未在数据库建立 if (mIsCreate) { Log.e(TAG, "it seems that we haven't created this in database yet"); return null; } JSONObject js = new JSONObject(); + //利用JSON将一系列参数添加进来 js.put(DataColumns.ID, mDataId); js.put(DataColumns.MIME_TYPE, mDataMimeType); js.put(DataColumns.CONTENT, mDataContent); @@ -153,11 +161,16 @@ public class SqlData { if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) { mDiffDataValues.remove(DataColumns.ID); } - + //保存信息 mDiffDataValues.put(DataColumns.NOTE_ID, noteId); Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues); try { + /* + Uri的getPathSegments()方法返回的是一个元素为String的List, + 每个元素都是从Uri截取出来的一部分。 + */ 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"); @@ -166,6 +179,10 @@ public class SqlData { if (mDiffDataValues.size() > 0) { int result = 0; if (!validateVersion) { + /* + ContentResolver.update方法ContentValue只更新指定的字段 + .update(Uri arg0,ContentValues arg1,String arg2,String[] arg3) + */ result = mContentResolver.update(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null); } else { @@ -176,12 +193,13 @@ public class SqlData { String.valueOf(noteId), String.valueOf(version) }); } + //未更新 if (result == 0) { Log.w(TAG, "there is no update. maybe user updates note when syncing"); } } } - + //清空记录,建立失败 mDiffDataValues.clear(); mIsCreate = false; } diff --git a/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java b/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java index 672f458..476c307 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java +++ b/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java @@ -51,19 +51,19 @@ public class SqlNote { NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID, 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; public static final int PARENT_ID_COLUMN = 7; @@ -362,13 +362,14 @@ public class SqlNote { public JSONObject getContent() { try { JSONObject js = new JSONObject(); - + //未创建内容加入数据库中 if (mIsCreate) { Log.e(TAG, "it seems that we haven't created this in database yet"); return null; } JSONObject note = new JSONObject(); + //如果便签类型匹配 if (mType == Notes.TYPE_NOTE) { note.put(NoteColumns.ID, mId); note.put(NoteColumns.ALERTED_DATE, mAlertDate); @@ -406,36 +407,36 @@ public class SqlNote { } return null; } - + //设置父ID public void setParentId(long id) { mParentId = id; mDiffNoteValues.put(NoteColumns.PARENT_ID, id); } - //设置同步任务ID + //设置日程同步ID public void setGtaskId(String gid) { mDiffNoteValues.put(NoteColumns.GTASK_ID, gid); } - + //设置同步ID public void setSyncId(long syncId) { mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId); } - + //重新设定本地修改 public void resetLocalModified() { mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0); } - + //获取对象ID public long getId() { return mId; } - + //获取父ID public long getParentId() { return mParentId; } - + //获取对象片段 public String getSnippet() { return mSnippet; } - + //判断是否为便签ID public boolean isNoteType() { return mType == Notes.TYPE_NOTE; } @@ -453,6 +454,7 @@ public class SqlNote { Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); } + //建立线程ID失败 if (mId == 0) { throw new IllegalStateException("Create thread id failed"); } @@ -470,6 +472,7 @@ public class SqlNote { if (mDiffNoteValues.size() > 0) { mVersion ++; int result = 0; + //若有效 if (!validateVersion) { result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?)", new String[] { @@ -482,6 +485,7 @@ public class SqlNote { String.valueOf(mId), String.valueOf(mVersion) }); } + //未更新,可能在同步时更新了 if (result == 0) { Log.w(TAG, "there is no update. maybe user updates note when syncing"); } @@ -494,7 +498,7 @@ public class SqlNote { } } - // refresh local infof + // 刷新本地infof loadFromCursor(mId); if (mType == Notes.TYPE_NOTE) loadDataContent(); diff --git a/app/src/main/java/net/micode/notes/gtask/data/Task.java b/app/src/main/java/net/micode/notes/gtask/data/Task.java index a8ba40e..d03f3bc 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/Task.java +++ b/app/src/main/java/net/micode/notes/gtask/data/Task.java @@ -44,7 +44,7 @@ public class Task extends Node { private Task mPriorSibling; private TaskList mParent; - + //构造函数 public Task() { super(); mCompleted = false; @@ -58,17 +58,17 @@ public class Task extends Node { JSONObject js = new JSONObject(); try { - // action_type + // 动作类型 js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE); - // action_id + // 动作ID js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); - // index + // 索引 js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this)); - // entity_delta + // JSON创建内容 JSONObject entity = new JSONObject(); entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null"); @@ -79,17 +79,17 @@ public class Task extends Node { } js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); - // parent_id + // 父ID js.put(GTaskStringUtils.GTASK_JSON_PARENT_ID, mParent.getGid()); - // dest_parent_type + // 目的父类型 js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_GROUP); - // list_id + // 列表ID js.put(GTaskStringUtils.GTASK_JSON_LIST_ID, mParent.getGid()); - // prior_sibling_id + // 优先同级ID if (mPriorSibling != null) { js.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, mPriorSibling.getGid()); } @@ -107,17 +107,17 @@ public class Task extends Node { JSONObject js = new JSONObject(); try { - // action_type + js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE); - // action_id + js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); // id js.put(GTaskStringUtils.GTASK_JSON_ID, getGid()); - // entity_delta + JSONObject entity = new JSONObject(); entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); if (getNotes() != null) { @@ -143,27 +143,27 @@ public class Task extends Node { setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID)); } - // last_modified + // 最后一次修改 if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) { setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)); } - // name + // 姓名 if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) { setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); } - // notes + // 有便签 if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) { setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES)); } - // deleted + // 删除 if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) { setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED)); } - // completed + // 完成 if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) { setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED)); } @@ -176,6 +176,7 @@ public class Task extends Node { } //通过本地JSON设置内容 public void setContentByLocalJSON(JSONObject js) { + //JSON空消息设置内容失败 if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) || !js.has(GTaskStringUtils.META_HEAD_DATA)) { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); @@ -184,12 +185,12 @@ public class Task extends Node { try { JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); - + //无效类型 if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) { Log.e(TAG, "invalid type"); return; } - + //如果文本备份找到一致就跳出 for (int i = 0; i < dataArray.length(); i++) { JSONObject data = dataArray.getJSONObject(i); if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) { @@ -208,7 +209,7 @@ public class Task extends Node { String name = getName(); try { if (mMetaInfo == null) { - // new task created from web + // 初始为空,从网页创建的新任务 if (name == null) { Log.w(TAG, "the note seems to be an empty one"); return null; @@ -225,7 +226,7 @@ public class Task extends Node { js.put(GTaskStringUtils.META_HEAD_NOTE, note); return js; } else { - // synced task + // 同步任务 JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA); @@ -246,7 +247,7 @@ public class Task extends Node { return null; } } - + //设置元信息 public void setMetaInfo(MetaData metaData) { if (metaData != null && metaData.getNotes() != null) { try { @@ -275,29 +276,29 @@ public class Task extends Node { return SYNC_ACTION_UPDATE_LOCAL; } - // validate the note id now + // 现在验证便签 id if (c.getLong(SqlNote.ID_COLUMN) != noteInfo.getLong(NoteColumns.ID)) { Log.w(TAG, "note id doesn't match"); return SYNC_ACTION_UPDATE_LOCAL; } if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) { - // there is no local update + // 没有本地更新 if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) { // no update both side return SYNC_ACTION_NONE; } else { - // apply remote to local + // 将远程应用到本地 return SYNC_ACTION_UPDATE_LOCAL; } } else { - // validate gtask id + // 验证日程同步 id if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) { Log.e(TAG, "gtask id doesn't match"); return SYNC_ACTION_ERROR; } if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) { - // local modification only + // 只有本地修改 return SYNC_ACTION_UPDATE_REMOTE; } else { return SYNC_ACTION_UPDATE_CONFLICT; @@ -310,36 +311,36 @@ public class Task extends Node { return SYNC_ACTION_ERROR; } - + //值得保留 public boolean isWorthSaving() { return mMetaInfo != null || (getName() != null && getName().trim().length() > 0) || (getNotes() != null && getNotes().trim().length() > 0); } - + //设置完成 public void setCompleted(boolean completed) { this.mCompleted = completed; } - + //设置便签 public void setNotes(String notes) { this.mNotes = notes; } - + //设置优先级 public void setPriorSibling(Task priorSibling) { this.mPriorSibling = priorSibling; } - + //设置父列表 public void setParent(TaskList parent) { this.mParent = parent; } - + //获得完成项 public boolean getCompleted() { return this.mCompleted; } - + //获得便签 public String getNotes() { return this.mNotes; } - + //获得优先级 public Task getPriorSibling() { return this.mPriorSibling; } diff --git a/app/src/main/java/net/micode/notes/gtask/data/TaskList.java b/app/src/main/java/net/micode/notes/gtask/data/TaskList.java index 50b2024..51132db 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/TaskList.java +++ b/app/src/main/java/net/micode/notes/gtask/data/TaskList.java @@ -47,17 +47,17 @@ public class TaskList extends Node { JSONObject js = new JSONObject(); try { - // action_type + // 动作类型 js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE); - // action_id + // 动作ID js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); - // index + // 索引 js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex); - // entity_delta + // JSON设置内容 JSONObject entity = new JSONObject(); entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null"); @@ -78,17 +78,17 @@ public class TaskList extends Node { JSONObject js = new JSONObject(); try { - // action_type + js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE); - // action_id + js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); - // id + js.put(GTaskStringUtils.GTASK_JSON_ID, getGid()); - // entity_delta + JSONObject entity = new JSONObject(); entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted()); @@ -106,17 +106,17 @@ public class TaskList extends Node { public void setContentByRemoteJSON(JSONObject js) { if (js != null) { try { - // id + if (js.has(GTaskStringUtils.GTASK_JSON_ID)) { setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID)); } - // last_modified + // 最后一次修改 if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) { setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)); } - // name + // 姓名 if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) { setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); } @@ -133,19 +133,22 @@ public class TaskList extends Node { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); } - + //建立JSON文件夹加入元头便签 try { JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { String name = folder.getString(NoteColumns.SNIPPET); + //设置姓名 setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name); + //获得类型与便签系统类型一样时 } else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER) setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT); else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER) setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_CALL_NOTE); + //无效系统文件夹 else Log.e(TAG, "invalid system folder"); } else { @@ -156,7 +159,7 @@ public class TaskList extends Node { e.printStackTrace(); } } - + //通过内容获得本地JSON public JSONObject getLocalJSONFromContent() { try { JSONObject js = new JSONObject(); @@ -167,6 +170,7 @@ public class TaskList extends Node { folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(), folderName.length()); folder.put(NoteColumns.SNIPPET, folderName); + //文件夹名和默认文件夹名一致时 if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT) || folderName.equals(GTaskStringUtils.FOLDER_CALL_NOTE)) folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); @@ -186,25 +190,25 @@ public class TaskList extends Node { public int getSyncAction(Cursor c) { try { if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) { - // there is no local update + // t没有本地更新 if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) { - // no update both side + // 双方无更新 return SYNC_ACTION_NONE; } else { - // apply remote to local + // 将远程应用到本地 return SYNC_ACTION_UPDATE_LOCAL; } } else { - // validate gtask id + // 验证日程同步 id if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) { Log.e(TAG, "gtask id doesn't match"); return SYNC_ACTION_ERROR; } if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) { - // local modification only + // 只有本地修改 return SYNC_ACTION_UPDATE_REMOTE; } else { - // for folder conflicts, just apply local modification + // 对于文件夹冲突,只需应用本地修改 return SYNC_ACTION_UPDATE_REMOTE; } } @@ -225,7 +229,7 @@ public class TaskList extends Node { if (task != null && !mChildren.contains(task)) { ret = mChildren.add(task); if (ret) { - // need to set prior sibling and parent + // 需要设置之前的父结点和兄节点 task.setPriorSibling(mChildren.isEmpty() ? null : mChildren .get(mChildren.size() - 1)); task.setParent(this); @@ -244,14 +248,14 @@ public class TaskList extends Node { if (task != null && pos == -1) { mChildren.add(index, task); - // update the task list + // 更新任务列表 Task preTask = null; Task afterTask = null; if (index != 0) preTask = mChildren.get(index - 1); if (index != mChildren.size() - 1) afterTask = mChildren.get(index + 1); - + //设置同级 task.setPriorSibling(preTask); if (afterTask != null) afterTask.setPriorSibling(task); @@ -267,11 +271,11 @@ public class TaskList extends Node { ret = mChildren.remove(task); if (ret) { - // reset prior sibling and parent + task.setPriorSibling(null); task.setParent(null); - // update the task list + // 更新任务列表 if (index != mChildren.size()) { mChildren.get(index).setPriorSibling( index == 0 ? null : mChildren.get(index - 1)); @@ -287,7 +291,7 @@ public class TaskList extends Node { Log.e(TAG, "move child task: invalid index"); return false; } - + //子任务索引位置 int pos = mChildren.indexOf(task); if (pos == -1) { Log.e(TAG, "move child task: the task should in the list"); @@ -332,7 +336,7 @@ public class TaskList extends Node { public ArrayList getChildTaskList() { return this.mChildren; } - + //设置索引 public void setIndex(int index) { this.mIndex = index; } diff --git a/app/src/main/java/net/micode/notes/tool/BackupUtils.java b/app/src/main/java/net/micode/notes/tool/BackupUtils.java index 3ff1d0f..8cc9e1b 100644 --- a/app/src/main/java/net/micode/notes/tool/BackupUtils.java +++ b/app/src/main/java/net/micode/notes/tool/BackupUtils.java @@ -198,11 +198,11 @@ public class BackupUtils { ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), phoneNumber)); } - // Print call date + // 打印调用日期 ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat .format(mContext.getString(R.string.format_datetime_mdhm), callDate))); - // Print call attachment location + // 打印调用位置 if (!TextUtils.isEmpty(location)) { ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), location)); @@ -219,7 +219,7 @@ public class BackupUtils { //及时关闭cursor dataCursor.close(); } - // print a line separator between note + // 在便签之间打印一个行分隔符 try { ps.write(new byte[] { Character.LINE_SEPARATOR, Character.LETTER_NUMBER @@ -229,8 +229,8 @@ public class BackupUtils { } } - /** - * Note will be exported as text which is user readable + /* + 便签将被导出为用户可读的文本 */ public int exportToText() { //判断是否有外部存储空间 @@ -245,7 +245,7 @@ public class BackupUtils { Log.e(TAG, "get print stream error"); return STATE_SYSTEM_ERROR; } - // First export folder and its notes + // 第一个导出文件夹及其注释 Cursor folderCursor = mContext.getContentResolver().query( Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, @@ -256,7 +256,7 @@ public class BackupUtils { if (folderCursor != null) { if (folderCursor.moveToFirst()) { do { - // Print folder's name + // 打印文件夹的名字 String folderName = ""; //若id为最近记录里调用的文件中 if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) { @@ -277,7 +277,7 @@ public class BackupUtils { folderCursor.close(); } - // Export notes in root's folder + // 在根目录下导出注释 Cursor noteCursor = mContext.getContentResolver().query( Notes.CONTENT_NOTE_URI, NOTE_PROJECTION, @@ -291,7 +291,7 @@ public class BackupUtils { ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( mContext.getString(R.string.format_datetime_mdhm), noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); - // Query data belong to this note + // 查询数据属于该便签 String noteId = noteCursor.getString(NOTE_COLUMN_ID); //通过id导出文本 exportNoteToText(noteId, ps); @@ -304,8 +304,8 @@ public class BackupUtils { return STATE_SUCCESS; } - /** - * Get a print stream pointed to the file {@generateExportedTextFile} + /* + 获取指向该文件的打印流 {@generateExportedTextFile} */ private PrintStream getExportToTextPrintStream() { File file = generateFileMountedOnSDcard(mContext, R.string.file_path, @@ -331,8 +331,8 @@ public class BackupUtils { } } - /** - * Generate the text file to store imported data + /* + 生成文本文件来存储导入的数据 */ private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) { StringBuilder sb = new StringBuilder(); @@ -346,15 +346,19 @@ public class BackupUtils { File file = new File(sb.toString()); try { + //目录不存在就创建 if (!filedir.exists()) { filedir.mkdir(); } + //文件不存在也创建 if (!file.exists()) { file.createNewFile(); } return file; + //安全性异常 } catch (SecurityException e) { e.printStackTrace(); + //IO异常 } catch (IOException e) { e.printStackTrace(); } diff --git a/app/src/main/java/net/micode/notes/tool/DataUtils.java b/app/src/main/java/net/micode/notes/tool/DataUtils.java index f723fbe..d6d437a 100644 --- a/app/src/main/java/net/micode/notes/tool/DataUtils.java +++ b/app/src/main/java/net/micode/notes/tool/DataUtils.java @@ -120,8 +120,8 @@ public class DataUtils { return false; } - /** - * Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}} + /* + 获取除系统文件夹外的所有文件夹计数 {@link Notes#TYPE_SYSTEM}} */ public static int getUserFolderCount(ContentResolver resolver) { /* @@ -174,6 +174,7 @@ public class DataUtils { boolean exist = false; if (cursor != null) { + //行数大于0 if (cursor.getCount() > 0) { exist = true; } @@ -233,6 +234,7 @@ public class DataUtils { } catch (IndexOutOfBoundsException e) { Log.e(TAG, e.toString()); } + //这里循环是找到cursor不为空的时候 } while (c.moveToNext()); } c.close(); @@ -251,6 +253,7 @@ public class DataUtils { //获得第一行数据 try { return cursor.getString(0); + //捕捉超界异常 } catch (IndexOutOfBoundsException e) { Log.e(TAG, "Get call number fails " + e.toString()); } finally { @@ -292,14 +295,16 @@ public class DataUtils { if (cursor != null) { String snippet = ""; if (cursor.moveToFirst()) { + //获取第一列字符串 snippet = cursor.getString(0); } cursor.close(); return snippet; } + //抛出无法利用id找到便签的异常 throw new IllegalArgumentException("Note is not found with id: " + noteId); } - //获得格式化的snippet + //获得格式化的snippet(主要是去除无用字符) public static String getFormattedSnippet(String snippet) { if (snippet != null) { snippet = snippet.trim(); diff --git a/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java b/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java index cfb59d2..3ea4d96 100644 --- a/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java +++ b/app/src/main/java/net/micode/notes/tool/GTaskStringUtils.java @@ -19,33 +19,33 @@ package net.micode.notes.tool; 字符工具类 */ public class GTaskStringUtils { - + //日程同步动作ID public final static String GTASK_JSON_ACTION_ID = "action_id"; - + //日程同步动作列表 public final static String GTASK_JSON_ACTION_LIST = "action_list"; - + //日程同步动作类型 public final static String GTASK_JSON_ACTION_TYPE = "action_type"; - + //日程同步动作类型构造 public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create"; - + //返回日程同步动作类型 public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all"; - + //日程同步动作类型移动 public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move"; - + //日程同步动作类型更新 public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update"; - + //日程同步创建id public final static String GTASK_JSON_CREATOR_ID = "creator_id"; - + //日程同步子体 public final static String GTASK_JSON_CHILD_ENTITY = "child_entity"; - + //日程同步用户版本 public final static String GTASK_JSON_CLIENT_VERSION = "client_version"; - + //日程同步已完成 public final static String GTASK_JSON_COMPLETED = "completed"; - + //日程同步当前列表ID public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id"; - + //日程同步默认列表id public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; - + //日程同步删除 public final static String GTASK_JSON_DELETED = "deleted"; public final static String GTASK_JSON_DEST_LIST = "dest_list"; diff --git a/app/src/main/java/net/micode/notes/tool/ResourceParser.java b/app/src/main/java/net/micode/notes/tool/ResourceParser.java index b36cd34..b15dccb 100644 --- a/app/src/main/java/net/micode/notes/tool/ResourceParser.java +++ b/app/src/main/java/net/micode/notes/tool/ResourceParser.java @@ -25,20 +25,20 @@ import net.micode.notes.ui.NotesPreferenceActivity; 界面元素解析工具类 */ public class ResourceParser { - + //定义各种颜色 public static final int YELLOW = 0; public static final int BLUE = 1; public static final int WHITE = 2; public static final int GREEN = 3; public static final int RED = 4; - + //背景默认色 public static final int BG_DEFAULT_COLOR = YELLOW; public static final int TEXT_SMALL = 0; public static final int TEXT_MEDIUM = 1; public static final int TEXT_LARGE = 2; public static final int TEXT_SUPER = 3; - + //背景默认字体大小 public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM; //便签背景源 public static class NoteBgResources { @@ -67,7 +67,7 @@ public class ResourceParser { return BG_EDIT_TITLE_RESOURCES[id]; } } - //获得背景ID默认值颜色 + //获得默认背景颜色ID public static int getDefaultBgId(Context context) { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean( NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) { @@ -109,23 +109,23 @@ public class ResourceParser { R.drawable.list_green_single, R.drawable.list_red_single }; - + //获得便签背景首源 public static int getNoteBgFirstRes(int id) { return BG_FIRST_RESOURCES[id]; } - + //获得便签背景尾源 public static int getNoteBgLastRes(int id) { return BG_LAST_RESOURCES[id]; } - + //获得单个便签源 public static int getNoteBgSingleRes(int id) { return BG_SINGLE_RESOURCES[id]; } - + //获得便签正常源 public static int getNoteBgNormalRes(int id) { return BG_NORMAL_RESOURCES[id]; } - + //获得文件背景源 public static int getFolderBgRes() { return R.drawable.list_folder; }