diff --git a/doc/泛读报告.docx b/doc/泛读报告.docx index 946c023..8dbe8b1 100644 Binary files a/doc/泛读报告.docx and b/doc/泛读报告.docx differ diff --git a/src/Notes-master3/.gradle/7.5/executionHistory/executionHistory.bin b/src/Notes-master3/.gradle/7.5/executionHistory/executionHistory.bin index fc7274f..1841f40 100644 Binary files a/src/Notes-master3/.gradle/7.5/executionHistory/executionHistory.bin and b/src/Notes-master3/.gradle/7.5/executionHistory/executionHistory.bin differ diff --git a/src/Notes-master3/.gradle/7.5/executionHistory/executionHistory.lock b/src/Notes-master3/.gradle/7.5/executionHistory/executionHistory.lock index 9a73260..ad030cc 100644 Binary files a/src/Notes-master3/.gradle/7.5/executionHistory/executionHistory.lock and b/src/Notes-master3/.gradle/7.5/executionHistory/executionHistory.lock differ diff --git a/src/Notes-master3/.gradle/7.5/fileHashes/fileHashes.bin b/src/Notes-master3/.gradle/7.5/fileHashes/fileHashes.bin index fd4de21..3bdf21e 100644 Binary files a/src/Notes-master3/.gradle/7.5/fileHashes/fileHashes.bin and b/src/Notes-master3/.gradle/7.5/fileHashes/fileHashes.bin differ diff --git a/src/Notes-master3/.gradle/7.5/fileHashes/fileHashes.lock b/src/Notes-master3/.gradle/7.5/fileHashes/fileHashes.lock index fc6b7b9..56555ec 100644 Binary files a/src/Notes-master3/.gradle/7.5/fileHashes/fileHashes.lock and b/src/Notes-master3/.gradle/7.5/fileHashes/fileHashes.lock differ diff --git a/src/Notes-master3/.gradle/7.5/fileHashes/resourceHashesCache.bin b/src/Notes-master3/.gradle/7.5/fileHashes/resourceHashesCache.bin index 6a30a96..b05f006 100644 Binary files a/src/Notes-master3/.gradle/7.5/fileHashes/resourceHashesCache.bin and b/src/Notes-master3/.gradle/7.5/fileHashes/resourceHashesCache.bin differ diff --git a/src/Notes-master3/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/src/Notes-master3/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 4ff5ade..3c9cb72 100644 Binary files a/src/Notes-master3/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/src/Notes-master3/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/Notes-master3/.gradle/file-system.probe b/src/Notes-master3/.gradle/file-system.probe index 43c30ca..ddd756d 100644 Binary files a/src/Notes-master3/.gradle/file-system.probe and b/src/Notes-master3/.gradle/file-system.probe differ diff --git a/src/Notes-master3/app/build/intermediates/dex/debug/mergeDexDebug/classes.dex b/src/Notes-master3/app/build/intermediates/dex/debug/mergeDexDebug/classes.dex index 0d31429..70b0a85 100644 Binary files a/src/Notes-master3/app/build/intermediates/dex/debug/mergeDexDebug/classes.dex and b/src/Notes-master3/app/build/intermediates/dex/debug/mergeDexDebug/classes.dex differ diff --git a/src/Notes-master3/app/build/intermediates/incremental/packageDebug/tmp/debug/dex-renamer-state.txt b/src/Notes-master3/app/build/intermediates/incremental/packageDebug/tmp/debug/dex-renamer-state.txt index a74dc84..4064df9 100644 --- a/src/Notes-master3/app/build/intermediates/incremental/packageDebug/tmp/debug/dex-renamer-state.txt +++ b/src/Notes-master3/app/build/intermediates/incremental/packageDebug/tmp/debug/dex-renamer-state.txt @@ -1,4 +1,4 @@ -#Tue Apr 11 11:53:51 CST 2023 +#Fri Apr 14 15:34:06 CST 2023 base.0=C\:\\Users\\13293\\Desktop\\Git\\gitProject\\src\\Notes-master3\\app\\build\\intermediates\\dex\\debug\\mergeDexDebug\\classes.dex renamed.0=classes.dex path.0=classes.dex diff --git a/src/Notes-master3/app/build/intermediates/javac/debug/classes/net/micode/notes/model/Note$NoteData.class b/src/Notes-master3/app/build/intermediates/javac/debug/classes/net/micode/notes/model/Note$NoteData.class index 30318fc..d5ea178 100644 Binary files a/src/Notes-master3/app/build/intermediates/javac/debug/classes/net/micode/notes/model/Note$NoteData.class and b/src/Notes-master3/app/build/intermediates/javac/debug/classes/net/micode/notes/model/Note$NoteData.class differ diff --git a/src/Notes-master3/app/build/intermediates/javac/debug/classes/net/micode/notes/model/Note.class b/src/Notes-master3/app/build/intermediates/javac/debug/classes/net/micode/notes/model/Note.class index bbbea2e..cbe5883 100644 Binary files a/src/Notes-master3/app/build/intermediates/javac/debug/classes/net/micode/notes/model/Note.class and b/src/Notes-master3/app/build/intermediates/javac/debug/classes/net/micode/notes/model/Note.class differ diff --git a/src/Notes-master3/app/build/intermediates/project_dex_archive/debug/out/net/micode/notes/model/Note$NoteData.dex b/src/Notes-master3/app/build/intermediates/project_dex_archive/debug/out/net/micode/notes/model/Note$NoteData.dex index 0139b42..3d83623 100644 Binary files a/src/Notes-master3/app/build/intermediates/project_dex_archive/debug/out/net/micode/notes/model/Note$NoteData.dex and b/src/Notes-master3/app/build/intermediates/project_dex_archive/debug/out/net/micode/notes/model/Note$NoteData.dex differ diff --git a/src/Notes-master3/app/build/intermediates/project_dex_archive/debug/out/net/micode/notes/model/Note.dex b/src/Notes-master3/app/build/intermediates/project_dex_archive/debug/out/net/micode/notes/model/Note.dex index 452e2d0..a65b062 100644 Binary files a/src/Notes-master3/app/build/intermediates/project_dex_archive/debug/out/net/micode/notes/model/Note.dex and b/src/Notes-master3/app/build/intermediates/project_dex_archive/debug/out/net/micode/notes/model/Note.dex differ diff --git a/src/Notes-master3/app/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin b/src/Notes-master3/app/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin index 26037e0..0d0e5fa 100644 Binary files a/src/Notes-master3/app/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin and b/src/Notes-master3/app/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin differ diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java b/src/Notes-master3/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java index a8c1f2a..73c80f0 100644 --- a/src/Notes-master3/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java +++ b/src/Notes-master3/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java @@ -1,73 +1,119 @@ +/* + * 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.remote; +import android.app.Activity; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.util.Log; + +import net.micode.notes.R; +import net.micode.notes.data.Notes; +import net.micode.notes.data.Notes.DataColumns; +import net.micode.notes.data.Notes.NoteColumns; +import net.micode.notes.gtask.data.MetaData; +import net.micode.notes.gtask.data.Node; +import net.micode.notes.gtask.data.SqlNote; +import net.micode.notes.gtask.data.Task; +import net.micode.notes.gtask.data.TaskList; +import net.micode.notes.gtask.exception.ActionFailureException; +import net.micode.notes.gtask.exception.NetworkFailureException; +import net.micode.notes.tool.DataUtils; +import net.micode.notes.tool.GTaskStringUtils; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; + + public class GTaskManager { private static final String TAG = GTaskManager.class.getSimpleName(); + public static final int STATE_SUCCESS = 0; + public static final int STATE_NETWORK_ERROR = 1; + public static final int STATE_INTERNAL_ERROR = 2; + public static final int STATE_SYNC_IN_PROGRESS = 3; + public static final int STATE_SYNC_CANCELLED = 4; + private static GTaskManager mInstance = null; private Activity mActivity; + private Context mContext; + private ContentResolver mContentResolver; + private boolean mSyncing; + private boolean mCancelled; + private HashMap mGTaskListHashMap; + private HashMap mGTaskHashMap; + private HashMap mMetaHashMap; + private TaskList mMetaList; + private HashSet mLocalDeleteIdMap; + private HashMap mGidToNid; + private HashMap mNidToGid; - private GTaskManager() { //对象初始化函数 - mSyncing = false; //正在同步,flase代表未执行 - mCancelled = false; //全局标识,flase代表可以执行 - mGTaskListHashMap = new HashMap(); //<>代表Java的泛型,就是创建一个用类型作为参数的类。 + private GTaskManager() { + mSyncing = false; + mCancelled = false; + mGTaskListHashMap = new HashMap(); mGTaskHashMap = new HashMap(); mMetaHashMap = new HashMap(); mMetaList = null; mLocalDeleteIdMap = new HashSet(); - mGidToNid = new HashMap(); //GoogleID to NodeID?? - mNidToGid = new HashMap(); //NodeID to GoogleID???通过hashmap散列表建立映射 + mGidToNid = new HashMap(); + mNidToGid = new HashMap(); } - /** - * 包含关键字synchronized,语言级同步,指明该函数可能运行在多线程的环境下。 - * 功能:类初始化函数 - * @author TTS - * @return GtaskManger - */ - public static synchronized GTaskManager getInstance() { //可能运行在多线程环境下,使用语言级同步--synchronized + public static synchronized GTaskManager getInstance() { if (mInstance == null) { mInstance = new GTaskManager(); } return mInstance; } - /** - * 包含关键字synchronized,语言级同步,指明该函数可能运行在多线程的环境下。 - * @author TTS - * @param activity - */ public synchronized void setActivityContext(Activity activity) { - // used for getting auth token + // used for getting authtoken mActivity = activity; } - /** - * 核心函数 - * 功能:实现了本地同步操作和远端同步操作 - * @author TTS - * @param context-----获取上下文 - * @param asyncTask-------用于同步的异步操作类 - * @return int - */ - public int sync(Context context, GTaskASyncTask asyncTask) { //核心函数 + public int sync(Context context, GTaskASyncTask asyncTask) { if (mSyncing) { - Log.d(TAG, "Sync is in progress"); //创建日志文件(调试信息),debug + Log.d(TAG, "Sync is in progress"); return STATE_SYNC_IN_PROGRESS; } mContext = context; @@ -82,8 +128,8 @@ public class GTaskManager { mNidToGid.clear(); try { - GTaskClient client = GTaskClient.getInstance(); //getInstance即为创建一个实例,client--客户机 - client.resetUpdateArray(); //JSONArray类型,reset即置为NULL + GTaskClient client = GTaskClient.getInstance(); + client.resetUpdateArray(); // login google task if (!mCancelled) { @@ -94,15 +140,15 @@ public class GTaskManager { // get the task list from google asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list)); - initGTaskList(); //获取Google上的JSONtasklist转为本地TaskList + initGTaskList(); // do content sync work asyncTask.publishProgess(mContext.getString(R.string.sync_progress_syncing)); syncContent(); - } catch (NetworkFailureException e) { //分为两种异常,此类异常为网络异常 - Log.e(TAG, e.toString()); //创建日志文件(调试信息),error + } catch (NetworkFailureException e) { + Log.e(TAG, e.toString()); return STATE_NETWORK_ERROR; - } catch (ActionFailureException e) { //此类异常为操作异常 + } catch (ActionFailureException e) { Log.e(TAG, e.toString()); return STATE_INTERNAL_ERROR; } catch (Exception e) { @@ -122,41 +168,32 @@ public class GTaskManager { return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS; } - /** - *功能:初始化GtaskList,获取Google上的JSONtasklist转为本地TaskList。 - *获得的数据存储在mMetaList,mGTaskListHashMap,mGTaskHashMap - *@author TTS - *@exception NetworkFailureException - *@return void - */ private void initGTaskList() throws NetworkFailureException { if (mCancelled) return; - GTaskClient client = GTaskClient.getInstance(); //getInstance即为创建一个实例,client应指远端客户机 + GTaskClient client = GTaskClient.getInstance(); try { - //Json对象是Name Value对(即子元素)的无序集合,相当于一个Map对象。JsonObject类是bantouyan-json库对Json对象的抽象,提供操纵Json对象的各种方法。 - //其格式为{"key1":value1,"key2",value2....};key 必须是字符串。 - //因为ajax请求不刷新页面,但配合js可以实现局部刷新,因此json常常被用来作为异步请求的返回对象使用。 - JSONArray jsTaskLists = client.getTaskLists(); //原注释为get task list------lists??? + JSONArray jsTaskLists = client.getTaskLists(); // init meta list first - mMetaList = null; //TaskList类型 + mMetaList = null; for (int i = 0; i < jsTaskLists.length(); i++) { - JSONObject object = jsTaskLists.getJSONObject(i); //JSONObject与JSONArray一个为对象,一个为数组。此处取出单个JASONObject + JSONObject object = jsTaskLists.getJSONObject(i); String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME); - if (name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) { - mMetaList = new TaskList(); //MetaList意为元表,Tasklist类型,此处为初始化 - mMetaList.setContentByRemoteJSON(object); //将JSON中部分数据复制到自己定义的对象中相对应的数据:name->mname... + if (name + .equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) { + mMetaList = new TaskList(); + mMetaList.setContentByRemoteJSON(object); // load meta data - JSONArray jsMetas = client.getTaskList(gid); //原注释为get action_list------list??? + JSONArray jsMetas = client.getTaskList(gid); for (int j = 0; j < jsMetas.length(); j++) { object = (JSONObject) jsMetas.getJSONObject(j); - MetaData metaData = new MetaData(); //继承自Node + MetaData metaData = new MetaData(); metaData.setContentByRemoteJSON(object); - if (metaData.isWorthSaving()) { //if not worth to save,metadata将不加入mMetaList + if (metaData.isWorthSaving()) { mMetaList.addChildTask(metaData); if (metaData.getGid() != null) { mMetaHashMap.put(metaData.getRelatedGid(), metaData); @@ -177,16 +214,16 @@ public class GTaskManager { // init task list for (int i = 0; i < jsTaskLists.length(); i++) { JSONObject object = jsTaskLists.getJSONObject(i); - String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); //通过getString函数传入本地某个标志数据的名称,获取其在远端的名称。 + String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME); if (name.startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX) && !name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) { - TaskList tasklist = new TaskList(); //继承自Node + TaskList tasklist = new TaskList(); tasklist.setContentByRemoteJSON(object); mGTaskListHashMap.put(gid, tasklist); - mGTaskHashMap.put(gid, tasklist); //为什么加两遍??? + mGTaskHashMap.put(gid, tasklist); // load tasks JSONArray jsTasks = client.getTaskList(gid); @@ -210,18 +247,13 @@ public class GTaskManager { } } - /** - * 功能:本地内容同步操作 - * @throws NetworkFailureException - * @return 无返回值 - */ - private void syncContent() throws NetworkFailureException { //本地内容同步操作 + private void syncContent() throws NetworkFailureException { int syncType; - Cursor c = null; //数据库指针 - String gid; //GoogleID?? - Node node; //Node包含Sync_Action的不同类型 + Cursor c = null; + String gid; + Node node; - mLocalDeleteIdMap.clear(); //HashSet类型 + mLocalDeleteIdMap.clear(); if (mCancelled) { return; @@ -269,8 +301,8 @@ public class GTaskManager { node = mGTaskHashMap.get(gid); if (node != null) { mGTaskHashMap.remove(gid); - mGidToNid.put(gid, c.getLong(SqlNote.ID_COLUMN)); //通过hashmap建立联系 - mNidToGid.put(c.getLong(SqlNote.ID_COLUMN), gid); //通过hashmap建立联系 + mGidToNid.put(gid, c.getLong(SqlNote.ID_COLUMN)); + mNidToGid.put(c.getLong(SqlNote.ID_COLUMN), gid); syncType = node.getSyncAction(c); } else { if (c.getString(SqlNote.GTASK_ID_COLUMN).trim().length() == 0) { @@ -295,14 +327,14 @@ public class GTaskManager { } // go through remaining items - Iterator> iter = mGTaskHashMap.entrySet().iterator(); //Iterator迭代器 + Iterator> iter = mGTaskHashMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = iter.next(); node = entry.getValue(); doContentSync(Node.SYNC_ACTION_ADD_LOCAL, node, null); } - // mCancelled can be set by another thread, so we neet to check one by //thread----线程 + // mCancelled can be set by another thread, so we neet to check one by // one // clear local delete table if (!mCancelled) { @@ -319,11 +351,6 @@ public class GTaskManager { } - /** - * 功能: - * @author TTS - * @throws NetworkFailureException - */ private void syncFolder() throws NetworkFailureException { Cursor c = null; String gid; @@ -449,14 +476,6 @@ public class GTaskManager { GTaskClient.getInstance().commitUpdate(); } - /** - * 功能:syncType分类,addLocalNode,addRemoteNode,deleteNode,updateLocalNode,updateRemoteNode - * @author TTS - * @param syncType - * @param node - * @param c - * @throws NetworkFailureException - */ private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException { if (mCancelled) { return; @@ -503,12 +522,6 @@ public class GTaskManager { } } - /** - * 功能:本地增加Node - * @author TTS - * @param node - * @throws NetworkFailureException - */ private void addLocalNode(Node node) throws NetworkFailureException { if (mCancelled) { return; @@ -583,15 +596,6 @@ public class GTaskManager { updateRemoteMeta(node.getGid(), sqlNote); } - /** - * 功能:update本地node - * @author TTS - * @param node - * ----同步操作的基础数据类型 - * @param c - * ----Cursor - * @throws NetworkFailureException - */ private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException { if (mCancelled) { return; @@ -615,22 +619,12 @@ public class GTaskManager { updateRemoteMeta(node.getGid(), sqlNote); } - /** - * 功能:远程增加Node - * 需要updateRemoteMeta - * @author TTS - * @param node - * ----同步操作的基础数据类型 - * @param c - * --Cursor - * @throws NetworkFailureException - */ private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException { if (mCancelled) { return; } - SqlNote sqlNote = new SqlNote(mContext, c); //从本地mContext中获取内容 + SqlNote sqlNote = new SqlNote(mContext, c); Node n; // update remotely @@ -640,12 +634,11 @@ public class GTaskManager { String parentGid = mNidToGid.get(sqlNote.getParentId()); if (parentGid == null) { - Log.e(TAG, "cannot find task's parent tasklist"); //调试信息 + Log.e(TAG, "cannot find task's parent tasklist"); throw new ActionFailureException("cannot add remote task"); } - mGTaskListHashMap.get(parentGid).addChildTask(task); //在本地生成的GTaskList中增加子结点 + mGTaskListHashMap.get(parentGid).addChildTask(task); - //登录远程服务器,创建Task GTaskClient.getInstance().createTask(task); n = (Node) task; @@ -663,7 +656,6 @@ public class GTaskManager { else folderName += sqlNote.getSnippet(); - //iterator迭代器,通过统一的接口迭代所有的map元素 Iterator> iter = mGTaskListHashMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = iter.next(); @@ -695,20 +687,11 @@ public class GTaskManager { sqlNote.resetLocalModified(); sqlNote.commit(true); - // gid-id mapping //创建id间的映射 + // gid-id mapping mGidToNid.put(n.getGid(), sqlNote.getId()); mNidToGid.put(sqlNote.getId(), n.getGid()); } - /** - * 功能:更新远端的Node,包含meta更新(updateRemoteMeta) - * @author TTS - * @param node - * ----同步操作的基础数据类型 - * @param c - * --Cursor - * @throws NetworkFailureException - */ private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException { if (mCancelled) { return; @@ -718,7 +701,7 @@ public class GTaskManager { // update remotely node.setContentByLocalJSON(sqlNote.getContent()); - GTaskClient.getInstance().addUpdateNode(node); //GTaskClient用途为从本地登陆远端服务器 + GTaskClient.getInstance().addUpdateNode(node); // update meta updateRemoteMeta(node.getGid(), sqlNote); @@ -727,19 +710,15 @@ public class GTaskManager { if (sqlNote.isNoteType()) { Task task = (Task) node; TaskList preParentList = task.getParent(); - //preParentList为通过node获取的父节点列表 String curParentGid = mNidToGid.get(sqlNote.getParentId()); - //curParentGid为通过光标在数据库中找到sqlNote的mParentId,再通过mNidToGid由long类型转为String类型的Gid - if (curParentGid == null) { Log.e(TAG, "cannot find task's parent tasklist"); throw new ActionFailureException("cannot update remote task"); } TaskList curParentList = mGTaskListHashMap.get(curParentGid); - //通过HashMap找到对应Gid的TaskList - if (preParentList != curParentList) { //????????????? + if (preParentList != curParentList) { preParentList.removeChildTask(task); curParentList.addChildTask(task); GTaskClient.getInstance().moveTask(task, preParentList, curParentList); @@ -748,19 +727,9 @@ public class GTaskManager { // clear local modified flag sqlNote.resetLocalModified(); - //commit到本地数据库 sqlNote.commit(true); } - /** - * 功能:升级远程meta。 meta---元数据----计算机文件系统管理数据---管理数据的数据。 - * @author TTS - * @param gid - * ---GoogleID为String类型 - * @param sqlNote - * ---同步前的数据库操作,故使用类SqlNote - * @throws NetworkFailureException - */ private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException { if (sqlNote != null && sqlNote.isNoteType()) { MetaData metaData = mMetaHashMap.get(gid); @@ -777,18 +746,12 @@ public class GTaskManager { } } - /** - * 功能:刷新本地,给sync的ID对应上最后更改过的对象 - * @author TTS - * @return void - * @throws NetworkFailureException - */ private void refreshLocalSyncId() throws NetworkFailureException { if (mCancelled) { return; } - // get the latest gtask list //获取最近的(最晚的)gtask list + // get the latest gtask list mGTaskHashMap.clear(); mGTaskListHashMap.clear(); mMetaHashMap.clear(); @@ -799,16 +762,16 @@ public class GTaskManager { c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE, "(type<>? AND parent_id<>?)", new String[] { String.valueOf(Notes.TYPE_SYSTEM), String.valueOf(Notes.ID_TRASH_FOLER) - }, NoteColumns.TYPE + " DESC"); //query语句:五个参数,NoteColumns.TYPE + " DESC"-----为按类型递减顺序返回查询结果。new String[] {String.valueOf(Notes.TYPE_SYSTEM), String.valueOf(Notes.ID_TRASH_FOLER)}------为选择参数。"(type<>? AND parent_id<>?)"-------指明返回行过滤器。SqlNote.PROJECTION_NOTE--------应返回的数据列的名字。Notes.CONTENT_NOTE_URI--------contentProvider包含所有数据集所对应的uri + }, NoteColumns.TYPE + " DESC"); if (c != null) { while (c.moveToNext()) { String gid = c.getString(SqlNote.GTASK_ID_COLUMN); Node node = mGTaskHashMap.get(gid); if (node != null) { mGTaskHashMap.remove(gid); - ContentValues values = new ContentValues(); //在ContentValues中创建键值对。准备通过contentResolver写入数据 + ContentValues values = new ContentValues(); values.put(NoteColumns.SYNC_ID, node.getLastModified()); - mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, //进行批量更改,选择参数为NULL,应该可以用insert替换,参数分别为表名和需要更新的value对象。 + mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(SqlNote.ID_COLUMN)), values, null, null); } else { Log.e(TAG, "something is missed"); @@ -827,20 +790,11 @@ public class GTaskManager { } } - /** - * 功能:获取同步账号,mAccount.name - * @author TTS - * @return String - */ public String getSyncAccount() { return GTaskClient.getInstance().getSyncAccount().name; } - /** - * 功能:取消同步,置mCancelled为true - * @author TTS - */ public void cancelSync() { mCancelled = true; } -} \ No newline at end of file +} diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/model/Note.java b/src/Notes-master3/app/src/main/java/net/micode/notes/model/Note.java index d1f1de4..a59dcf4 100644 --- a/src/Notes-master3/app/src/main/java/net/micode/notes/model/Note.java +++ b/src/Notes-master3/app/src/main/java/net/micode/notes/model/Note.java @@ -1,14 +1,39 @@ +/* + * 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.model; +import android.content.ContentProviderOperation; +import android.content.ContentProviderResult; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Context; +import android.content.OperationApplicationException; +import android.net.Uri; +import android.os.RemoteException; +import android.util.Log; + +import net.micode.notes.data.Notes; +import net.micode.notes.data.Notes.CallNote; +import net.micode.notes.data.Notes.DataColumns; +import net.micode.notes.data.Notes.NoteColumns; +import net.micode.notes.data.Notes.TextNote; + +import java.util.ArrayList; + -import android.content.ContentProviderOperation;//批量的更新、插入、删除数据。 -import android.content.ContentProviderResult;//操作的结果 -import android.content.ContentUris;//用于添加和获取Uri后面的ID -import android.content.ContentValues;//一种用来存储基本数据类型数据的存储机制 -import android.content.Context;//需要用该类来弄清楚调用者的实例 -import android.content.OperationApplicationException;//操作应用程序容错 -import android.net.Uri;//表示待操作的数据 -import android.os.RemoteException;//远程容错 -import android.util.Log;//输出日志,比如说出错、警告等 public class Note { // private ContentValues mNoteDiffValues; @@ -229,4 +254,4 @@ public class Note { return null; } } -} \ No newline at end of file +} diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/model/WorkingNote.java b/src/Notes-master3/app/src/main/java/net/micode/notes/model/WorkingNote.java index cbb0754..2655aaf 100644 --- a/src/Notes-master3/app/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/src/Notes-master3/app/src/main/java/net/micode/notes/model/WorkingNote.java @@ -1,5 +1,37 @@ +/* + * 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.model; +import android.appwidget.AppWidgetManager; +import android.content.ContentUris; +import android.content.Context; +import android.database.Cursor; +import android.text.TextUtils; +import android.util.Log; + +import net.micode.notes.data.Notes; +import net.micode.notes.data.Notes.CallNote; +import net.micode.notes.data.Notes.DataColumns; +import net.micode.notes.data.Notes.DataConstants; +import net.micode.notes.data.Notes.NoteColumns; +import net.micode.notes.data.Notes.TextNote; +import net.micode.notes.tool.ResourceParser.NoteBgResources; + + public class WorkingNote { // Note for the working note private Note mNote; @@ -11,11 +43,17 @@ public class WorkingNote { private int mMode; private long mAlertDate; + private long mModifiedDate; + private int mBgColorId; + private int mWidgetId; + private int mWidgetType; + private long mFolderId; + private Context mContext; private static final String TAG = "WorkingNote"; @@ -24,7 +62,6 @@ public class WorkingNote { private NoteSettingChangedListener mNoteSettingStatusListener; - // 声明 DATA_PROJECTION字符串数组 public static final String[] DATA_PROJECTION = new String[] { DataColumns.ID, DataColumns.CONTENT, @@ -35,7 +72,6 @@ public class WorkingNote { DataColumns.DATA4, }; - // 声明 NOTE_PROJECTION字符串数组 public static final String[] NOTE_PROJECTION = new String[] { NoteColumns.PARENT_ID, NoteColumns.ALERTED_DATE, @@ -46,18 +82,27 @@ public class WorkingNote { }; private static final int DATA_ID_COLUMN = 0; + private static final int DATA_CONTENT_COLUMN = 1; + private static final int DATA_MIME_TYPE_COLUMN = 2; + private static final int DATA_MODE_COLUMN = 3; + private static final int NOTE_PARENT_ID_COLUMN = 0; + private static final int NOTE_ALERTED_DATE_COLUMN = 1; + private static final int NOTE_BG_COLOR_ID_COLUMN = 2; + private static final int NOTE_WIDGET_ID_COLUMN = 3; + private static final int NOTE_WIDGET_TYPE_COLUMN = 4; + private static final int NOTE_MODIFIED_DATE_COLUMN = 5; // New note construct - public WorkingNote(Context context, long folderId) { + private WorkingNote(Context context, long folderId) { mContext = context; mAlertDate = 0; mModifiedDate = System.currentTimeMillis(); @@ -69,9 +114,7 @@ public class WorkingNote { mWidgetType = Notes.TYPE_WIDGET_INVALIDE; } - // WorkingNote的构造函数 // Existing note construct - private WorkingNote(Context context, long noteId, long folderId) { mContext = context; mNoteId = noteId; @@ -81,14 +124,11 @@ public class WorkingNote { loadNote(); } - // 加载Note - // 通过数据库调用query函数找到第一个条目 private void loadNote() { Cursor cursor = mContext.getContentResolver().query( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, null, null); - // 若存在,储存相应信息 if (cursor != null) { if (cursor.moveToFirst()) { mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN); @@ -99,7 +139,6 @@ public class WorkingNote { mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN); } cursor.close(); - // 若不存在,报错 } else { Log.e(TAG, "No note with id:" + mNoteId); throw new IllegalArgumentException("Unable to find note with id " + mNoteId); @@ -107,7 +146,6 @@ public class WorkingNote { loadNoteData(); } - // 加载NoteData private void loadNoteData() { Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { @@ -115,8 +153,7 @@ public class WorkingNote { }, null); if (cursor != null) { - // 查到信息不为空 - if (cursor.moveToFirst()) { // 查看第一项是否存在 + if (cursor.moveToFirst()) { do { String type = cursor.getString(DATA_MIME_TYPE_COLUMN); if (DataConstants.NOTE.equals(type)) { @@ -128,7 +165,7 @@ public class WorkingNote { } else { Log.d(TAG, "Wrong note type with type:" + type); } - } while (cursor.moveToNext());//查阅所有项,直到为空 + } while (cursor.moveToNext()); } cursor.close(); } else { @@ -137,12 +174,9 @@ public class WorkingNote { } } - // 创建空的Note - // 传参:context,文件夹id,widget,背景颜色 public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { WorkingNote note = new WorkingNote(context, folderId); - // 设定相关属性 note.setBgColorId(defaultBgColorId); note.setWidgetId(widgetId); note.setWidgetType(widgetType); @@ -153,10 +187,9 @@ public class WorkingNote { return new WorkingNote(context, id, 0); } - // 保存Note public synchronized boolean saveNote() { - if (isWorthSaving()) { //是否值得保存 - if (!existInDatabase()) { // 是否存在数据库中 + if (isWorthSaving()) { + if (!existInDatabase()) { if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { Log.e(TAG, "Create new note fail with id:" + mNoteId); return false; @@ -179,14 +212,11 @@ public class WorkingNote { } } - // 是否在数据库中存在 public boolean existInDatabase() { return mNoteId > 0; } - // 是否值得保存 private boolean isWorthSaving() { - // 被删除,或(不在数据库中 内容为空),或 本地已保存过 if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) || (existInDatabase() && !mNote.isLocalModified())) { return false; @@ -195,14 +225,10 @@ public class WorkingNote { } } - - // 设置mNoteSettingStatusListener public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; } - // 设置AlertDate - // 若 mAlertDate与data不同,则更改mAlertDate并设定NoteValue public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { mAlertDate = date; @@ -213,20 +239,16 @@ public class WorkingNote { } } - // 设定删除标记 public void markDeleted(boolean mark) { - // 设定标记 mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onWidgetChanged(); - // 调用mNoteSettingStatusListener的 onWidgetChanged方法 } } - // 设定背景颜色 public void setBgColorId(int id) { - if (id != mBgColorId) { //设定条件 id != mBgColorId + if (id != mBgColorId) { mBgColorId = id; if (mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onBackgroundColorChanged(); @@ -235,10 +257,8 @@ public class WorkingNote { } } - // 设定检查列表模式 - // 参数:mode public void setCheckListMode(int mode) { - if (mMode != mode) { //设定条件 mMode != mode + if (mMode != mode) { if (mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode); } @@ -247,108 +267,81 @@ public class WorkingNote { } } - - // 设定WidgetType - // 参数:type public void setWidgetType(int type) { - if (type != mWidgetType) {//设定条件 type != mWidgetType + if (type != mWidgetType) { mWidgetType = type; mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType)); - // 调用Note的setNoteValue方法更改WidgetType } } - // 设定WidgetId - // 参数:id public void setWidgetId(int id) { - if (id != mWidgetId) {//设定条件 id != mWidgetId + if (id != mWidgetId) { mWidgetId = id; mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId)); - // 调用Note的setNoteValue方法更改WidgetId } } - // 设定WorkingTex - // 参数:更改的text public void setWorkingText(String text) { - if (!TextUtils.equals(mContent, text)) {//设定条件 mContent, text内容不同 + if (!TextUtils.equals(mContent, text)) { mContent = text; mNote.setTextData(DataColumns.CONTENT, mContent); - // 调用Note的setTextData方法更改WorkingText } } - // 转变mNote的CallData及CallNote信息 - // 参数:String phoneNumber, long callDate public void convertToCallNote(String phoneNumber, long callDate) { mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate)); mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber); mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER)); } - // 判断是否有时钟题型 public boolean hasClockAlert() { return (mAlertDate > 0 ? true : false); } - // 获取Content public String getContent() { return mContent; } - // 获取AlertDate public long getAlertDate() { return mAlertDate; } - // 获取ModifiedDate public long getModifiedDate() { return mModifiedDate; } - // 获取背景颜色来源id public int getBgColorResId() { return NoteBgResources.getNoteBgResource(mBgColorId); } - // 获取背景颜色id public int getBgColorId() { return mBgColorId; } - // 获取标题背景颜色id public int getTitleBgResId() { return NoteBgResources.getNoteTitleBgResource(mBgColorId); } - // 获取CheckListMode public int getCheckListMode() { return mMode; } - // 获取便签id public long getNoteId() { return mNoteId; } - // 获取文件夹id public long getFolderId() { return mFolderId; } - // 获取WidgetId public int getWidgetId() { return mWidgetId; } - // 获取WidgetType public int getWidgetType() { return mWidgetType; } - // 创建接口 NoteSettingChangedListener,便签更新监视 - // 为NoteEditActivity提供接口 - // 提供函数有 public interface NoteSettingChangedListener { /** * Called when the background color of current note has just changed @@ -372,4 +365,4 @@ public class WorkingNote { */ void onCheckListModeChanged(int oldMode, int newMode); } -} \ No newline at end of file +}