From 32fe48f1c6f31eda12b8e63c573e13edefff8043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E8=B6=8A?= <1435603762@qq.com> Date: Wed, 14 Jun 2023 12:38:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- other/210340051 何越/gtask/data/Task.java | 350 +++++++ .../210340051 何越/gtask/data/TaskList.java | 345 +++++++ .../exception/ActionFailureException.java | 34 + .../exception/NetworkFailureException.java | 36 + .../gtask/remote/GTaskASyncTask.java | 117 +++ .../gtask/remote/GTaskClient.java | 671 +++++++++++++ .../gtask/remote/GTaskManager.java | 929 ++++++++++++++++++ .../gtask/remote/GTaskSyncService.java | 129 +++ other/210340051何越-实践总结报告.docx | Bin 0 -> 13078 bytes 9 files changed, 2611 insertions(+) create mode 100644 other/210340051 何越/gtask/data/Task.java create mode 100644 other/210340051 何越/gtask/data/TaskList.java create mode 100644 other/210340051 何越/gtask/exception/ActionFailureException.java create mode 100644 other/210340051 何越/gtask/exception/NetworkFailureException.java create mode 100644 other/210340051 何越/gtask/remote/GTaskASyncTask.java create mode 100644 other/210340051 何越/gtask/remote/GTaskClient.java create mode 100644 other/210340051 何越/gtask/remote/GTaskManager.java create mode 100644 other/210340051 何越/gtask/remote/GTaskSyncService.java create mode 100644 other/210340051何越-实践总结报告.docx diff --git a/other/210340051 何越/gtask/data/Task.java b/other/210340051 何越/gtask/data/Task.java new file mode 100644 index 0000000..3b87056 --- /dev/null +++ b/other/210340051 何越/gtask/data/Task.java @@ -0,0 +1,350 @@ +/* + * 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 android.text.TextUtils; +import android.util.Log; + +import net.micode.notes.data.Notes; +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.gtask.exception.ActionFailureException; +import net.micode.notes.tool.GTaskStringUtils; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + + +public class Task extends Node { + private static final String TAG = Task.class.getSimpleName(); + + private boolean mCompleted;//表示任务是否完成 + + private String mNotes;//表示任务备注的字符串 + + private JSONObject mMetaInfo;//表示任务元信息的JSONObject对象 + + private Task mPriorSibling;//表示任务前一个兄弟任务的Task对象 + + private TaskList mParent;//表示任务所属任务列表的TaskList对象 + + public Task() { + super(); + mCompleted = false; + mNotes = null; + mPriorSibling = null; + mParent = null; + mMetaInfo = null; + }//初始化 + + public JSONObject getCreateAction(int actionId) { + 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 表示Task在所属TaskList的位置 + js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this)); + + // entity_delta 表示创建的Task的具体信息,包括名称,创建者ID,类型,笔记等 + JSONObject entity = new JSONObject(); + entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); + entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null"); + entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, + GTaskStringUtils.GTASK_JSON_TYPE_TASK); + if (getNotes() != null) { + entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes()); + } + js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); + + // parent_id 表示所属TaskList的ID + js.put(GTaskStringUtils.GTASK_JSON_PARENT_ID, mParent.getGid()); + + // dest_parent_type 表示所属TaskList的类型 + js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE, + GTaskStringUtils.GTASK_JSON_TYPE_GROUP); + + // list_id 表示所属TaskList的ID + js.put(GTaskStringUtils.GTASK_JSON_LIST_ID, mParent.getGid()); + + // prior_sibling_id 表示排在该Task之前的兄弟Task的ID + if (mPriorSibling != null) { + js.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, mPriorSibling.getGid()); + } + + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("fail to generate task-create jsonobject"); + } + + return js; + }//返回JSONObject对象,表示用于创建该Task的动作 + + public JSONObject getUpdateAction(int actionId) { + JSONObject js = new JSONObject(); + + try { + // action_type 操作类型(更新操作) + js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, + GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE); + + // action_id 操作ID + js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); + + // id 要更新的任务的ID + js.put(GTaskStringUtils.GTASK_JSON_ID, getGid()); + + // entity_delta 更新的内容。包含了任务的名称、备注、是否已删除等信息。 + JSONObject entity = new JSONObject(); + entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); + if (getNotes() != null) { + entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes()); + } + entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted()); + js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); + + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("fail to generate task-update jsonobject"); + } + + return js; + }//返回JSONObject对象,包含更新Google Task的相关数据 + + public void setContentByRemoteJSON(JSONObject js) { + if (js != null){ + try { + // id 检查"JSON"对象是否包含id属性 + if (js.has(GTaskStringUtils.GTASK_JSON_ID)) { + setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID)); + }//如果是,则将其值设置为任务对象的gid属性 + + // last_modified 检查JSON对象是否包含last_modified属性 + if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) { + setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)); + }//如果是,将其值设置为任务对象的lastModified属性 + + // name 检查JSON对象是否包含name属性 + if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) { + setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); + }//如果是,则将其值设置为任务对象的name属性 + + // notes 它检查JSON对象是否包含notes属性 + if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) { + setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES)); + }//如果是,则将其值设置为任务对象的notes属性 + + // deleted 检查JSON对象是否包含deleted属性 + if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) { + setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED)); + }//如果是,则将其值设置为任务对象的deleted属性 + + // completed 检查JSON对象是否包含completed属性 + if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) { + setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED)); + }//如果是,则将其值设置为任务对象的completed属性 + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("fail to get task content from jsonobject");//如果解析JSON对象时出现异常,将会抛出一个ActionFailureException异常 + } + } + }//从远程JSON对象中获取任务的各种属性并将其设置到任务对象中 + + public void setContentByLocalJSON(JSONObject js) { + if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) + || !js.has(GTaskStringUtils.META_HEAD_DATA)) { + Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); + }//判断传入的JSONObject对象是否为空以及是否包含所需的键名,如果不包含,则打印警告日志并直接返回 + + try { + JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); + JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); + //从META_HEAD_NOTE键对应的JSON对象中获取类型 + if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) { + Log.e(TAG, "invalid type"); + return; + }//类型不为Notes.TYPE_NOTE,则打印错误日志并返回 + + for (int i = 0; i < dataArray.length(); i++) { + JSONObject data = dataArray.getJSONObject(i); + if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) { + setName(data.getString(DataColumns.CONTENT)); + break; + } + }//遍历元素,若MIME_TYPE键值为DataConstants.NOTE,将其CONTENT设置为该对象的name属性值。 + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + } + }//从本地存储的JSON对象中读取内容,并设置到该对象的属性中 + + public JSONObject getLocalJSONFromContent() { + String name = getName();//从任务对象中获取名称,检查是否存在 mMetaInfo JSON 对象 + try { + if (mMetaInfo == null) { + // new task created from web 不存在,则说明任务对象是从 Web 创建的 + if (name == null) { + Log.w(TAG, "the note seems to be an empty one"); + return null; + } + //创建一个新的 JSON 对象并返回 + JSONObject js = new JSONObject(); + JSONObject note = new JSONObject(); + JSONArray dataArray = new JSONArray(); + JSONObject data = new JSONObject(); + data.put(DataColumns.CONTENT, name); + dataArray.put(data); + js.put(GTaskStringUtils.META_HEAD_DATA, dataArray); + note.put(NoteColumns.TYPE, Notes.TYPE_NOTE); + js.put(GTaskStringUtils.META_HEAD_NOTE, note); + return js; + } else { + // synced task 如果存在 mMetaInfo JSON 对象,则说明任务对象是同步 + JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); + JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA); + + for (int i = 0; i < dataArray.length(); i++) { + JSONObject data = dataArray.getJSONObject(i); + if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) { + data.put(DataColumns.CONTENT, getName()); + break; + } + } + //从现有的 JSON 对象中更新数据并返回。 + note.put(NoteColumns.TYPE, Notes.TYPE_NOTE); + return mMetaInfo; + } + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + return null; + } + }//将任务对象的内容转换为本地 JSON 对象 + + public void setMetaInfo(MetaData metaData) { + if (metaData != null && metaData.getNotes() != null) {//检查metaData是否为空且其notes属性是否存在 + try { + mMetaInfo = new JSONObject(metaData.getNotes());//尝试将notes属性的值转换为一个JSONObject对象,并将其赋值给类成员变量mMetaInfo + } catch (JSONException e) { + Log.w(TAG, e.toString()); + mMetaInfo = null;//记录一个警告日志,并将mMetaInfo设置为null + } + } + }//检查metaData + + public int getSyncAction(Cursor c) { + try { + JSONObject noteInfo = null; + if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) { + noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); + } + + if (noteInfo == null) { + Log.w(TAG, "it seems that note meta has been deleted"); + return SYNC_ACTION_UPDATE_REMOTE; + } + + if (!noteInfo.has(NoteColumns.ID)) { + Log.w(TAG, "remote note id seems to be deleted"); + return SYNC_ACTION_UPDATE_LOCAL; + } + + // validate the note id now + 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 + 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;//本地和远程都有更新,需要解决冲突并同步更新 + } + } + } catch (Exception e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + } + + 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; + }//将note赋值给该待办事项的mNotes成员变量 + + public void setPriorSibling(Task priorSibling) { + this.mPriorSibling = priorSibling; + }//给定一个Task对象作为参数,设置它作为当前Task对象的前一个兄弟节点 + + public void setParent(TaskList parent) { + this.mParent = parent; + }//设置当前Task的父任务列表 + + public boolean getCompleted() { + return this.mCompleted; + }//获取任务的“完成”状态 + + public String getNotes() { + return this.mNotes; + }//获取任务的备注信息 + + public Task getPriorSibling() { + return this.mPriorSibling; + }//返回当前任务的前一个兄弟任务 + + public TaskList getParent() { + return this.mParent; + }//表示当前任务的父任务列表。该方法并未接收任何参数 + +}//同步任务,将创建、更新和同步动作包装成JSON对象,用本地和远程的JSON对结点内容进行设置获取同步信息,进行本地和远程的同步 diff --git a/other/210340051 何越/gtask/data/TaskList.java b/other/210340051 何越/gtask/data/TaskList.java new file mode 100644 index 0000000..b2fb382 --- /dev/null +++ b/other/210340051 何越/gtask/data/TaskList.java @@ -0,0 +1,345 @@ +/* + * 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 android.util.Log; + +import net.micode.notes.data.Notes; +import net.micode.notes.data.Notes.NoteColumns; +import net.micode.notes.gtask.exception.ActionFailureException; +import net.micode.notes.tool.GTaskStringUtils; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; + + +public class TaskList extends Node { + private static final String TAG = TaskList.class.getSimpleName(); + + private int mIndex; + //表示TaskList在其父节点下的索引位置。 + private ArrayList mChildren; + //表示TaskList的子任务列表 + public TaskList() { + super(); + mChildren = new ArrayList(); + mIndex = 1; + }//初始化 + + public JSONObject getCreateAction(int actionId) { + JSONObject js = new JSONObject(); + + try { + // action_type 操作类型为 "create" + js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, + GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE); + + // action_id 由参数 actionId 指定的操作 ID + js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); + + // index Google 任务清单的索引值 + js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex); + + // entity_delta 实体数据的 JSON 对象 + JSONObject entity = new JSONObject(); + entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());//Google 任务清单的名称 + entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");//创建该清单的用户的 ID + entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, + GTaskStringUtils.GTASK_JSON_TYPE_GROUP);//任务清单 + js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); + + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("fail to generate tasklist-create jsonobject"); + } + + return js; + }//创建Google任务清单的JSON对象 + + public JSONObject getUpdateAction(int actionId) { + JSONObject js = new JSONObject(); + + try { + // action_type 动作类型,此处为“update”表示更新操作 + js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, + GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE); + + // action_id 动作ID,用于标识此次操作 + js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); + + // id 任务列表ID + js.put(GTaskStringUtils.GTASK_JSON_ID, getGid()); + + // entity_delta 实体增量,即更新的具体内容 + JSONObject entity = new JSONObject(); + entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());//name:任务列表名称 + entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());//deleted:是否已删除 + js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); + + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("fail to generate tasklist-update jsonobject"); + } + + return js; + }//生成一个Google任务列表的更新操作的JSON对象 + + 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)); + } + //尝试解析其id、last_modified和name属性,相应地设置任务列表的gid、lastModified和name属性 + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("fail to get tasklist content from jsonobject"); + }//发生异常,则记录错误日志并抛出ActionFailureException异常 + } + }//解析从服务器返回的JSON对象并设置相应的任务列表属性 + + public void setContentByLocalJSON(JSONObject js) { + 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"); + }//是系统类型的笔记,则根据笔记的 ID 判断是默认文件夹还是通话记录文件夹,并设置相应的名称 + else { + Log.e(TAG, "error type"); + }//不是文件夹也不是系统类型,则打印错误日志 + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + } + }//解析其中的笔记信息,并设置到当前对象中 + + public JSONObject getLocalJSONFromContent() { + try { + JSONObject js = new JSONObject(); + JSONObject folder = new JSONObject(); + + String folderName = getName();//获取TaskList对象的名称 + if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX))//判断是否以指定前缀GTaskStringUtils.MIUI_FOLDER_PREFFIX开头 + 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);//置folder对象的类型为Notes.TYPE_SYSTEM + else//为来电记事本名称 + folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);//设置folder对象的类型为Notes.TYPE_FOLDER + + js.put(GTaskStringUtils.META_HEAD_NOTE, folder); + + return js; + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + return null; + }//有异常发生,会打印错误日志并返回null + }//将TaskList对象的名称转换成本地JSON格式 + + public int getSyncAction(Cursor c) { + try { + 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 验证 GTASK_ID_COLUMN 列的值是否等于 getGid() 方法返回的值 + 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; + } + } + } catch (Exception e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + } + + return SYNC_ACTION_ERROR; + }//检查了 Cursor 对象中的某些属性值,以确定需要执行哪些同步操作 + + public int getChildTaskCount() { + return mChildren.size(); + }//返回私有变量 mChildren 列表的大小。 + + public boolean addChildTask(Task task) { + boolean ret = false; + if (task != null && !mChildren.contains(task)) {//判断传入的任务对象 task 是否为空,以及当前对象的子任务列表 mChildren 是否已包含该任务 + ret = mChildren.add(task);//将该任务添加到 mChildren 列表中 + if (ret) { + // need to set prior sibling and parent + task.setPriorSibling(mChildren.isEmpty() ? null : mChildren + .get(mChildren.size() - 1)); + task.setParent(this); + }//若添加成功,则需要对该任务进行设置其前一个同级任务和父级任务。 + } + return ret; + }//向当前对象添加一个子任务的操作是否成功 + + public boolean addChildTask(Task task, int index) { + if (index < 0 || index > mChildren.size()) { + Log.e(TAG, "add child task: invalid index"); + return false; + }//判断传入的 index 是否在合法范围内 + + int pos = mChildren.indexOf(task);//查找任务列表中是否已包含传入的任务对象 task + if (task != null && pos == -1) {//未包含该任务 + mChildren.add(index, task);//将其插入到 index 指定的位置 + + // 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); + }//返回 true 表示添加任务成功,否则返回 false。 + + return true; + }//表示向当前对象的子任务列表指定位置添加一个任务的操作是否成功 + + public boolean removeChildTask(Task task) { + boolean ret = false; + int index = mChildren.indexOf(task);//查找传入的任务对象 task 在子任务列表中的索引位置 + if (index != -1) {//该任务在子任务列表中存在 + 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)); + }//更新其后一个同级任务的前一个同级任务的引用 + } + } + return ret; + }//表示从当前对象的子任务列表中移除一个指定任务的操作是否成功 + + public boolean moveChildTask(Task task, int index) { + + if (index < 0 || index >= mChildren.size()) { + Log.e(TAG, "move child task: invalid index"); + return false; + }//判断传入的 index 是否在合法范围内 + + int pos = mChildren.indexOf(task); + if (pos == -1) { + Log.e(TAG, "move child task: the task should in the list"); + return false; + }//查找子任务列表中是否包含传入的任务对象 task + + if (pos == index)//任务在子任务列表中的位置已经是 index + return true; + return (removeChildTask(task) && addChildTask(task, index)); + }//表示将当前对象子任务列表中的一个任务移动到指定位置的操作是否成功 + + public Task findChildTaskByGid(String gid) { + for (int i = 0; i < mChildren.size(); i++) {//遍历当前对象子任务列表中的所有任务 + Task t = mChildren.get(i); + if (t.getGid().equals(gid)) {//任务的 gid 属性与传入的 gid 相同 + return t; + } + } + return null; + }//根据传入的 gid 在当前对象的子任务列表中查找并返回相应的任务对象 + + public int getChildTaskIndex(Task task) { + return mChildren.indexOf(task); + }//表示当前对象子任务列表中传入任务对象 task 的索引位置 + + public Task getChildTaskByIndex(int index) { + if (index < 0 || index >= mChildren.size()) {//判断传入的 index 是否在合法范围内 + Log.e(TAG, "getTaskByIndex: invalid index"); + return null; + } + return mChildren.get(index); + }//表示当前对象子任务列表中指定索引位置 index 的任务对象 + + public Task getChilTaskByGid(String gid) { + for (Task task : mChildren) {//遍历 + if (task.getGid().equals(gid))//若任务的 gid 属性与传入的 gid 相同,则返回该任务对象 + return task; + } + return null; + }//表示根据传入的 gid 在当前对象的子任务列表中查找并返回相应的任务对象 + + public ArrayList getChildTaskList() { + return this.mChildren; + }//表示当前对象的子任务列表 + + public void setIndex(int index) { + this.mIndex = index; + }//设置当前任务的索引位置 + + public int getIndex() { + return this.mIndex; + }//返回当前任务在其父任务中的索引位置 +} diff --git a/other/210340051 何越/gtask/exception/ActionFailureException.java b/other/210340051 何越/gtask/exception/ActionFailureException.java new file mode 100644 index 0000000..0da5f17 --- /dev/null +++ b/other/210340051 何越/gtask/exception/ActionFailureException.java @@ -0,0 +1,34 @@ +/* + * 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.exception; // 定义了一个异常类,位于 net.micode.notes.gtask.exception 包下 + +public class ActionFailureException extends RuntimeException { // 定义了一个继承自 RuntimeException 的异常类 + + private static final long serialVersionUID = 4425249765923293627L; // 定义一个序列化 ID,用于版本控制 + + public ActionFailureException() { // 无参构造函数 + super(); // 调用父类 RuntimeException 的无参构造函数 + } + + public ActionFailureException(String paramString) { // 带参数构造函数,传入异常信息 + super(paramString); // 调用父类 RuntimeException 的带参数构造函数,将异常信息传给父类 + } + + public ActionFailureException(String paramString, Throwable paramThrowable) { // 带参数构造函数,传入异常信息和原始异常 + super(paramString, paramThrowable); // 调用父类 RuntimeException 的带参数构造函数,将异常信息和原始异常都传给父类 + } +} diff --git a/other/210340051 何越/gtask/exception/NetworkFailureException.java b/other/210340051 何越/gtask/exception/NetworkFailureException.java new file mode 100644 index 0000000..702c07f --- /dev/null +++ b/other/210340051 何越/gtask/exception/NetworkFailureException.java @@ -0,0 +1,36 @@ +/* + * 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.exception; + +public class NetworkFailureException extends Exception { + private static final long serialVersionUID = 2107610287180234136L; + + // 无参构造函数 + public NetworkFailureException() { + super(); + } + + // 构造函数,接受一个字符串消息作为参数 + public NetworkFailureException(String paramString) { + super(paramString); + } + + // 构造函数,接受一个字符串消息和一个可抛出对象作为参数 + public NetworkFailureException(String paramString, Throwable paramThrowable) { + super(paramString, paramThrowable); + } +} diff --git a/other/210340051 何越/gtask/remote/GTaskASyncTask.java b/other/210340051 何越/gtask/remote/GTaskASyncTask.java new file mode 100644 index 0000000..f4665f9 --- /dev/null +++ b/other/210340051 何越/gtask/remote/GTaskASyncTask.java @@ -0,0 +1,117 @@ + +/* + * 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. + */ + +public class GTaskASyncTask extends AsyncTask { + + private static int GTASK_SYNC_NOTIFICATION_ID = 5234235; + + // 定义回调接口 OnCompleteListener + public interface OnCompleteListener { + void onComplete(); + } + + private Context mContext; + + private NotificationManager mNotifiManager; + + private GTaskManager mTaskManager; + + private OnCompleteListener mOnCompleteListener; + + // 构造函数,初始化成员变量 + public GTaskASyncTask(Context context, OnCompleteListener listener) { + mContext = context; + mOnCompleteListener = listener; + mNotifiManager = (NotificationManager) mContext + .getSystemService(Context.NOTIFICATION_SERVICE); + mTaskManager = GTaskManager.getInstance(); + } + + // 取消同步 + public void cancelSync() { + mTaskManager.cancelSync(); + } + + // 发布进度 + public void publishProgess(String message) { + publishProgress(new String[] { + message + }); + } + + // 显示通知 + private void showNotification(int tickerId, String content) { + Notification notification = new Notification(R.drawable.notification, mContext + .getString(tickerId), System.currentTimeMillis()); + notification.defaults = Notification.DEFAULT_LIGHTS; + notification.flags = Notification.FLAG_AUTO_CANCEL; + PendingIntent pendingIntent; + if (tickerId != R.string.ticker_success) { + pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, + NotesPreferenceActivity.class), 0); + + } else { + pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, + NotesListActivity.class), 0); + } + //notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content, + // pendingIntent); + mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); + } + + @Override + protected Integer doInBackground(Void... unused) { + publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity + .getSyncAccountName(mContext))); + // 执行同步任务,返回状态码 + return mTaskManager.sync(mContext, this); + } + + @Override + protected void onProgressUpdate(String... progress) { + showNotification(R.string.ticker_syncing, progress[0]); + if (mContext instanceof GTaskSyncService) { + ((GTaskSyncService) mContext).sendBroadcast(progress[0]); + } + } + + @Override + protected void onPostExecute(Integer result) { + // 根据状态码显示通知 + if (result == GTaskManager.STATE_SUCCESS) { + showNotification(R.string.ticker_success, mContext.getString( + R.string.success_sync_account, mTaskManager.getSyncAccount())); + NotesPreferenceActivity.setLastSyncTime(mContext, System.currentTimeMillis()); + } else if (result == GTaskManager.STATE_NETWORK_ERROR) { + showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_network)); + } else if (result == GTaskManager.STATE_INTERNAL_ERROR) { + showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_internal)); + } else if (result == GTaskManager.STATE_SYNC_CANCELLED) { + showNotification(R.string.ticker_cancel, mContext + .getString(R.string.error_sync_cancelled)); + } + + if (mOnCompleteListener != null) { + new Thread(new Runnable() { + + public void run() { + mOnCompleteListener.onComplete(); + } + }).start(); + } + } +} diff --git a/other/210340051 何越/gtask/remote/GTaskClient.java b/other/210340051 何越/gtask/remote/GTaskClient.java new file mode 100644 index 0000000..3fb1e33 --- /dev/null +++ b/other/210340051 何越/gtask/remote/GTaskClient.java @@ -0,0 +1,671 @@ +/* + * 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.accounts.Account; +import android.accounts.AccountManager; +import android.accounts.AccountManagerFuture; +import android.app.Activity; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; + +import net.micode.notes.gtask.data.Node; +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.GTaskStringUtils; +import net.micode.notes.ui.NotesPreferenceActivity; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.cookie.Cookie; +import org.apache.http.impl.client.BasicCookieStore; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.params.BasicHttpParams; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; +import org.apache.http.params.HttpProtocolParams; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.List; +import java.util.zip.GZIPInputStream; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; + + +public class GTaskClient { + private static final String TAG = GTaskClient.class.getSimpleName(); + + private static final String GTASK_URL = "https://mail.google.com/tasks/"; + + private static final String GTASK_GET_URL = "https://mail.google.com/tasks/ig"; + + private static final String GTASK_POST_URL = "https://mail.google.com/tasks/r/ig"; + + private static GTaskClient mInstance = null; + + private DefaultHttpClient mHttpClient; + + private String mGetUrl; + + private String mPostUrl; + + private long mClientVersion; + + private boolean mLoggedin; + + private long mLastLoginTime; + + private int mActionId; + + private Account mAccount; + + private JSONArray mUpdateArray; + +// 定义一个GTaskClient类,用于管理Google任务API +public class GTaskClient { + + // 初始化GTaskClient类的私有构造函数 + private GTaskClient() { + mHttpClient = null; + mGetUrl = GTASK_GET_URL; + mPostUrl = GTASK_POST_URL; + mClientVersion = -1; + mLoggedin = false; + mLastLoginTime = 0; + mActionId = 1; + mAccount = null; + mUpdateArray = null; + } + + // 创建一个静态的GTaskClient实例,确保线程安全 + public static synchronized GTaskClient getInstance() { + if (mInstance == null) { + mInstance = new GTaskClient(); + } + return mInstance; + } + + public boolean login(Activity activity) { + // 假设cookie在5分钟后会过期,所以需要重新登录 + final long interval = 1000 * 60 * 5; + if (mLastLoginTime + interval < System.currentTimeMillis()) { + mLoggedin = false; + } + + // 如果帐户发生变化,则需要重新登录 + if (mLoggedin && !TextUtils.equals(getSyncAccount().name, NotesPreferenceActivity.getSyncAccountName(activity))) { + mLoggedin = false; + } + + if (mLoggedin) { + Log.d(TAG, "already logged in"); + return true; + } + + mLastLoginTime = System.currentTimeMillis(); + String authToken = loginGoogleAccount(activity, false); + if (authToken == null) { + Log.e(TAG, "login google account failed"); + return false; + } + + // 如果需要,使用自定义域名进行登录 + if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase().endsWith("googlemail.com"))) { + StringBuilder url = new StringBuilder(GTASK_URL).append("a/"); + int index = mAccount.name.indexOf('@') + 1; + String suffix = mAccount.name.substring(index); + url.append(suffix + "/"); + mGetUrl = url.toString() + "ig"; + mPostUrl = url.toString() + "r/ig"; + + if (tryToLoginGtask(activity, authToken)) { + mLoggedin = true; + } + } + + // 尝试使用Google官方URL进行登录 + if (!mLoggedin) { + mGetUrl = GTASK_GET_URL; + mPostUrl = GTASK_POST_URL; + if (!tryToLoginGtask(activity, authToken)) { + return false; + } + } + + mLoggedin = true; + return true; + } + + // 登录Google账户,获取授权令牌 + private String loginGoogleAccount(Activity activity, boolean invalidateToken) { + String authToken; + AccountManager accountManager = AccountManager.get(activity); + Account[] accounts = accountManager.getAccountsByType("com.google"); + + if (accounts.length == 0) { + Log.e(TAG, "there is no available google account"); + return null; + } + + String accountName = NotesPreferenceActivity.getSyncAccountName(activity); + Account account = null; + for (Account a : accounts) { + if (a.name.equals(accountName)) { + account = a; + break; + } + } + if (account != null) { + mAccount = account; + } else { + Log.e(TAG, "unable to get an account with the same name in the settings"); + return null; + } + + // 获取授权令牌 + AccountManagerFuture accountManagerFuture = accountManager.getAuthToken(account, + "goanna_mobile", null, activity, null, null); + try { + Bundle authTokenBundle = accountManagerFuture.getResult(); + authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN); + if (invalidateToken) { + // 使令牌无效,并重新获取令牌 + accountManager.invalidateAuthToken("com.google", authToken); + loginGoogleAccount(activity, false); + } + } catch (Exception e) { + Log.e(TAG, "get auth token failed"); + authToken = null; + } + + return authToken; + } + + // 尝试使用授权令牌进行Gtask登录 +/** + * 尝试使用指定的身份验证令牌登录到 Gtask 服务。 + * + * @param activity 调用此方法的 Activity + * @param authToken Gtask 服务的身份验证令牌 + * @return 如果登录成功,则返回 true;否则返回 false。 + */ + private boolean tryToLoginGtask(Activity activity, String authToken) { + // 如果无法成功登录 Gtask 服务,则进行以下处理。 + if (!loginGtask(authToken)) { + // 可能是身份验证令牌过期了,现在我们需要将令牌作废并再次尝试登录。 + authToken = loginGoogleAccount(activity, true); + // 如果登录谷歌帐号失败,则返回 false。 + if (authToken == null) { + Log.e(TAG, "login google account failed"); + return false; + } + + // 如果仍然无法成功登录 Gtask 服务,则返回 false。 + if (!loginGtask(authToken)) { + Log.e(TAG, "login gtask failed"); + return false; + } + } + // 如果登录成功,则返回 true。 + return true; + } + + /** + * 使用给定的身份验证令牌登录到 Gtask 服务。 + * + * @param authToken Gtask 服务的身份验证令牌 + * @return 如果登录成功,则返回 true;否则返回 false。 + */ +private boolean loginGtask(String authToken) { + // 配置 HTTP 连接参数。 + int timeoutConnection = 10000; + int timeoutSocket = 15000; + HttpParams httpParameters = new BasicHttpParams(); + HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); + HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); + + // 创建 HTTP 客户端。 + mHttpClient = new DefaultHttpClient(httpParameters); + BasicCookieStore localBasicCookieStore = new BasicCookieStore(); + mHttpClient.setCookieStore(localBasicCookieStore); + HttpProtocolParams.setUseExpectContinue(mHttpClient.getParams(), false); + + // 使用身份验证令牌登录 Gtask 服务。 + try { + String loginUrl = mGetUrl + "?auth=" + authToken; + HttpGet httpGet = new HttpGet(loginUrl); + HttpResponse response = mHttpClient.execute(httpGet); + + // 获取 Cookie。 + List cookies = mHttpClient.getCookieStore().getCookies(); + boolean hasAuthCookie = false; + for (Cookie cookie : cookies) { + if (cookie.getName().contains("GTL")) { + hasAuthCookie = true; + } + } + if (!hasAuthCookie) { + Log.w(TAG, "it seems that there is no auth cookie"); + } + + // 获取客户端版本。 + String resString = getResponseContent(response.getEntity()); + String jsBegin = "_setup("; + String jsEnd = ")}"; + int begin = resString.indexOf(jsBegin); + int end = resString.lastIndexOf(jsEnd); + String jsString = null; + if (begin != -1 && end != -1 && begin < end) { + jsString = resString.substring(begin + jsBegin.length(), end); + } + JSONObject js = new JSONObject(jsString); + mClientVersion = js.getLong("v"); + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + return false; + } catch (Exception e) { + Log.e(TAG, "httpget gtask_url failed"); + return false; + } + + return true; +} + +/** + * 获取下一个操作 ID。 + * + * @return 下一个操作 ID。 + */ +private int getActionId() { + return mActionId++; +} + +/** + * 创建 HTTP POST 请求。 + * + * @return 新的 HTTP POST 请求。 + */ +private HttpPost createHttpPost() { + HttpPost httpPost = new HttpPost(mPostUrl); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); + httpPost.setHeader("AT", "1"); + return httpPost; +} + + +/** + * 从HttpEntity中获取响应内容 + * @param entity HttpEntity对象 + * @return 响应内容 + * @throws IOException + */ +private String getResponseContent(HttpEntity entity) throws IOException { + String contentEncoding = null; + // 获取响应编码方式 + if (entity.getContentEncoding() != null) { + contentEncoding = entity.getContentEncoding().getValue(); + Log.d(TAG, "encoding: " + contentEncoding); + } + + InputStream input = entity.getContent(); + // 根据编码方式设置InputStream + if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) { + input = new GZIPInputStream(entity.getContent()); + } else if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) { + Inflater inflater = new Inflater(true); + input = new InflaterInputStream(entity.getContent(), inflater); + } + + try { + // 将InputStream转为字符流,并读取响应内容 + InputStreamReader isr = new InputStreamReader(input); + BufferedReader br = new BufferedReader(isr); + StringBuilder sb = new StringBuilder(); + + while (true) { + String buff = br.readLine(); + if (buff == null) { + return sb.toString(); + } + sb = sb.append(buff); + } + } finally { + // 关闭InputStream + input.close(); + } +} + +/** + * 发送HttpPost请求,并返回JSONObject格式的响应内容 + * @param js JSONObject格式的请求内容 + * @return JSONObject格式的响应内容 + * @throws NetworkFailureException + */ +private JSONObject postRequest(JSONObject js) throws NetworkFailureException { + if (!mLoggedin) { + Log.e(TAG, "please login first"); + throw new ActionFailureException("not logged in"); + } + + HttpPost httpPost = createHttpPost(); + try { + // 创建请求参数并设置到HttpPost对象中 + LinkedList list = new LinkedList(); + list.add(new BasicNameValuePair("r", js.toString())); + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8"); + httpPost.setEntity(entity); + + // 执行HttpPost请求 + HttpResponse response = mHttpClient.execute(httpPost); + // 获取响应内容,并将其转为JSONObject对象 + String jsString = getResponseContent(response.getEntity()); + return new JSONObject(jsString); + + } catch (ClientProtocolException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new NetworkFailureException("postRequest failed"); + } catch (IOException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new NetworkFailureException("postRequest failed"); + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("unable to convert response content to jsonobject"); + } catch (Exception e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("error occurs when posting request"); + } +} + +public void createTask(Task task) throws NetworkFailureException { + commitUpdate(); // 提交更新 + try { + JSONObject jsPost = new JSONObject(); // 创建一个JSON对象 + JSONArray actionList = new JSONArray(); // 创建一个JSON数组 + + // action_list + // 将Task对象的创建操作添加到JSON数组中 + actionList.put(task.getCreateAction(getActionId())); + // 将JSON数组添加到JSON对象中 + jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); + + // client_version + // 将客户端版本添加到JSON对象中 + jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); + + // post + // 发送post请求并接收响应 + JSONObject jsResponse = postRequest(jsPost); + // 获取响应中的结果数组并获取第一个结果对象 + JSONObject jsResult = (JSONObject) jsResponse.getJSONArray( + GTaskStringUtils.GTASK_JSON_RESULTS).get(0); + // 将新任务的ID设置为响应中的新ID + task.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID)); + + } catch (JSONException e) { + Log.e(TAG, e.toString()); // 输出异常日志 + e.printStackTrace(); // 打印异常堆栈信息 + throw new ActionFailureException("create task: handing jsonobject failed"); // 抛出自定义异常 + } +} + +public void createTaskList(TaskList tasklist) throws NetworkFailureException { + commitUpdate(); // 提交更新 + try { + JSONObject jsPost = new JSONObject(); // 创建一个JSON对象 + JSONArray actionList = new JSONArray(); // 创建一个JSON数组 + + // action_list + // 将TaskList对象的创建操作添加到JSON数组中 + actionList.put(tasklist.getCreateAction(getActionId())); + // 将JSON数组添加到JSON对象中 + jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); + + // client version + // 将客户端版本添加到JSON对象中 + jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); + + // post + // 发送post请求并接收响应 + JSONObject jsResponse = postRequest(jsPost); + // 获取响应中的结果数组并获取第一个结果对象 + JSONObject jsResult = (JSONObject) jsResponse.getJSONArray( + GTaskStringUtils.GTASK_JSON_RESULTS).get(0); + // 将新任务列表的ID设置为响应中的新ID + tasklist.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID)); + + } catch (JSONException e) { + Log.e(TAG, e.toString()); // 输出异常日志 + e.printStackTrace(); // 打印异常堆栈信息 + throw new ActionFailureException("create tasklist: handing jsonobject failed"); // 抛出自定义异常 + } +} + +public void commitUpdate() throws NetworkFailureException { + // 如果 mUpdateArray 不为空 + if (mUpdateArray != null) { + try { + // 新建一个 JSON 对象 + JSONObject jsPost = new JSONObject(); + + // 将 mUpdateArray 放入 JSON 对象中的 action_list 字段 + jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, mUpdateArray); + + // 将 mClientVersion 放入 JSON 对象中的 client_version 字段 + jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); + + // 发送 POST 请求 + postRequest(jsPost); + + // 清空 mUpdateArray + mUpdateArray = null; + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + + // 抛出异常 + throw new ActionFailureException("commit update: handing jsonobject failed"); + } + } +} + +public void addUpdateNode(Node node) throws NetworkFailureException { + // 如果 node 不为空 + if (node != null) { + // 如果 mUpdateArray 不为空且长度超过 10,提交更新 + if (mUpdateArray != null && mUpdateArray.length() > 10) { + commitUpdate(); + } + + // 如果 mUpdateArray 为空,新建一个 JSON 数组 + if (mUpdateArray == null) + mUpdateArray = new JSONArray(); + + // 将 node 对象的更新操作添加到 mUpdateArray 中 + mUpdateArray.put(node.getUpdateAction(getActionId())); + } +} + + +public void moveTask(Task task, TaskList preParent, TaskList curParent) +throws NetworkFailureException { +commitUpdate(); // 提交之前所有的更新操作 + +try { +JSONObject jsPost = new JSONObject(); // 创建一个 JSON 对象 +JSONArray actionList = new JSONArray(); // 创建一个 JSON 数组,用于存放操作列表 +JSONObject action = new JSONObject(); // 创建一个操作对象 + +// action_list +action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, // 设置操作类型 + GTaskStringUtils.GTASK_JSON_ACTION_TYPE_MOVE); +action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId()); // 设置操作 ID +action.put(GTaskStringUtils.GTASK_JSON_ID, task.getGid()); // 设置要移动的任务 ID + +if (preParent == curParent && task.getPriorSibling() != null) { + // 如果任务在同一个任务列表中移动且不是第一个任务,则添加其前一个任务的 ID + action.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, task.getPriorSibling()); +} + +action.put(GTaskStringUtils.GTASK_JSON_SOURCE_LIST, preParent.getGid()); // 设置原任务列表的 ID +action.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT, curParent.getGid()); // 设置目标任务列表的 ID + +if (preParent != curParent) { + // 如果任务在不同的任务列表中移动,则添加目标任务列表的 ID + action.put(GTaskStringUtils.GTASK_JSON_DEST_LIST, curParent.getGid()); +} + +actionList.put(action); // 将操作添加到操作列表中 +jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // 将操作列表添加到 JSON 对象中 + +// client_version +jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // 添加客户端版本信息 + +postRequest(jsPost); // 发送请求 +} catch (JSONException e) { +Log.e(TAG, e.toString()); +e.printStackTrace(); +throw new ActionFailureException("move task: handing jsonobject failed"); +} +} + +public void deleteNode(Node node) throws NetworkFailureException { +commitUpdate(); // 提交之前所有的更新操作 + +try { +JSONObject jsPost = new JSONObject(); // 创建一个 JSON 对象 +JSONArray actionList = new JSONArray(); // 创建一个 JSON 数组,用于存放操作列表 + +// action_list +node.setDeleted(true); // 将节点标记为已删除 +actionList.put(node.getUpdateAction(getActionId())); // 将更新操作添加到操作列表中 +jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // 将操作列表添加到 JSON 对象中 + +// client_version +jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // 添加客户端版本信息 + +postRequest(jsPost); // 发送请求 +mUpdateArray = null; // 重置更新操作数组 +} catch (JSONException e) { +Log.e(TAG, e.toString()); +e.printStackTrace(); +throw new ActionFailureException("delete node: handing jsonobject failed"); +} +} + + +public JSONArray getTaskLists() throws NetworkFailureException { + // 如果用户没有登录,则抛出异常 + if (!mLoggedin) { + Log.e(TAG, "please login first"); + throw new ActionFailureException("not logged in"); + } + + try { + // 发送 HTTP GET 请求,获取任务列表 + HttpGet httpGet = new HttpGet(mGetUrl); + HttpResponse response = null; + response = mHttpClient.execute(httpGet); + + // 从响应中提取 JSON 字符串 + String resString = getResponseContent(response.getEntity()); + String jsBegin = "_setup("; + String jsEnd = ")}"; + int begin = resString.indexOf(jsBegin); + int end = resString.lastIndexOf(jsEnd); + String jsString = null; + if (begin != -1 && end != -1 && begin < end) { + jsString = resString.substring(begin + jsBegin.length(), end); + } + + // 解析 JSON 字符串,返回任务列表 + JSONObject js = new JSONObject(jsString); + return js.getJSONObject("t").getJSONArray(GTaskStringUtils.GTASK_JSON_LISTS); + } catch (ClientProtocolException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new NetworkFailureException("gettasklists: httpget failed"); + } catch (IOException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new NetworkFailureException("gettasklists: httpget failed"); + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("get task lists: handing jasonobject failed"); + } +} + +public JSONArray getTaskList(String listGid) throws NetworkFailureException { + // 提交未提交的更改 + commitUpdate(); + try { + JSONObject jsPost = new JSONObject(); + JSONArray actionList = new JSONArray(); + JSONObject action = new JSONObject(); + + // action_list + action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, + GTaskStringUtils.GTASK_JSON_ACTION_TYPE_GETALL); + action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId()); + action.put(GTaskStringUtils.GTASK_JSON_LIST_ID, listGid); + action.put(GTaskStringUtils.GTASK_JSON_GET_DELETED, false); + actionList.put(action); + jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); + + // client_version + jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); + + // 发送 POST 请求,获取指定任务列表的任务 + JSONObject jsResponse = postRequest(jsPost); + return jsResponse.getJSONArray(GTaskStringUtils.GTASK_JSON_TASKS); + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("get task list: handing jsonobject failed"); + } +} + +public Account getSyncAccount() { + // 获取同步账户 + return mAccount; +} + +public void resetUpdateArray() { + // 重置未提交的更改 + mUpdateArray = null; +} + diff --git a/other/210340051 何越/gtask/remote/GTaskManager.java b/other/210340051 何越/gtask/remote/GTaskManager.java new file mode 100644 index 0000000..c10fc10 --- /dev/null +++ b/other/210340051 何越/gtask/remote/GTaskManager.java @@ -0,0 +1,929 @@ +/* + * 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; + + // 定义了一个名为 GTaskManager 的私有类 +private GTaskManager() { + // 初始化一些变量 + mSyncing = false; // 当前不在同步状态 + mCancelled = false; // 当前没有取消 + mGTaskListHashMap = new HashMap(); // 存储多个任务列表的 HashMap + mGTaskHashMap = new HashMap(); // 存储任务的 HashMap + mMetaHashMap = new HashMap(); // 存储元数据的 HashMap + mMetaList = null; // 初始化元数据列表为空 + mLocalDeleteIdMap = new HashSet(); // 存储本地删除的任务的 ID 集合 + mGidToNid = new HashMap(); // 存储 GTask ID 到 Node ID 的映射 + mNidToGid = new HashMap(); // 存储 Node ID 到 GTask ID 的映射 +} + + + // 定义了一个名为 getInstance 的静态方法,返回一个 GTaskManager 对象 +public static synchronized GTaskManager getInstance() { + // 如果当前 GTaskManager 对象为空,就创建一个新的 GTaskManager 对象 + if (mInstance == null) { + mInstance = new GTaskManager(); + } + // 返回 GTaskManager 对象 + return mInstance; +} + + // 定义了一个名为 setActivityContext 的方法,用于设置 Activity 的上下文 +public synchronized void setActivityContext(Activity activity) { + // 用于获取授权令牌(authtoken)的 Activity 上下文 + mActivity = activity; +} + + + // 定义了一个名为 sync 的方法,用于同步 Google 任务列表 +public int sync(Context context, GTaskASyncTask asyncTask) { + // 如果正在同步,则返回“同步进行中”状态 + if (mSyncing) { + Log.d(TAG, "Sync is in progress"); + return STATE_SYNC_IN_PROGRESS; + } + // 重置相关变量 + mContext = context; + mContentResolver = mContext.getContentResolver(); + mSyncing = true; + mCancelled = false; + mGTaskListHashMap.clear(); + mGTaskHashMap.clear(); + mMetaHashMap.clear(); + mLocalDeleteIdMap.clear(); + mGidToNid.clear(); + mNidToGid.clear(); + + try { + // 获取 GTaskClient 的单例对象 + GTaskClient client = GTaskClient.getInstance(); + // 重置更新数组 + client.resetUpdateArray(); + + // 登录 Google 任务列表 + if (!mCancelled) { + if (!client.login(mActivity)) { + throw new NetworkFailureException("login google task failed"); + } + } + + // 从 Google 获取任务列表 + asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list)); + initGTaskList(); + + // 进行内容同步工作 + asyncTask.publishProgess(mContext.getString(R.string.sync_progress_syncing)); + syncContent(); + } catch (NetworkFailureException e) { + Log.e(TAG, e.toString()); + return STATE_NETWORK_ERROR; + } catch (ActionFailureException e) { + Log.e(TAG, e.toString()); + return STATE_INTERNAL_ERROR; + } catch (Exception e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + return STATE_INTERNAL_ERROR; + } finally { + // 清空相关变量 + mGTaskListHashMap.clear(); + mGTaskHashMap.clear(); + mMetaHashMap.clear(); + mLocalDeleteIdMap.clear(); + mGidToNid.clear(); + mNidToGid.clear(); + mSyncing = false; + } + + // 如果已取消,则返回“同步已取消”状态;否则返回“成功”状态 + return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS; +} + + // 初始化 GTask 列表 + + private void initGTaskList() throws NetworkFailureException { + // 检查是否已取消 + if (mCancelled) + return; + // 获取 GTask 客户端 + GTaskClient client = GTaskClient.getInstance(); + try { + // 获取任务列表的 JSON 数据 + JSONArray jsTaskLists = client.getTaskLists(); + + // 先初始化元列表 + mMetaList = null; + for (int i = 0; i < jsTaskLists.length(); i++) { + // 获取 JSON 数据中的任务列表对象 + JSONObject object = jsTaskLists.getJSONObject(i); + String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); + String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME); + // 如果任务列表名称为“MIUI_FOLDER_PREFFIX + FOLDER_META”,则表示为元列表 + if (name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) { + // 初始化元列表 + mMetaList = new TaskList(); + mMetaList.setContentByRemoteJSON(object); + + // 加载元数据 + JSONArray jsMetas = client.getTaskList(gid); + for (int j = 0; j < jsMetas.length(); j++) { + object = (JSONObject) jsMetas.getJSONObject(j); + MetaData metaData = new MetaData(); + metaData.setContentByRemoteJSON(object); + // 如果元数据值得保存,将其添加到元列表中 + if (metaData.isWorthSaving()) { + mMetaList.addChildTask(metaData); + // 将元数据关联的 GID 和元数据存储在哈希映射表中 + if (metaData.getGid() != null) { + mMetaHashMap.put(metaData.getRelatedGid(), metaData); + } + } + } + } + } + + // 如果元列表不存在,则创建元列表 + if (mMetaList == null) { + mMetaList = new TaskList(); + mMetaList.setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + + GTaskStringUtils.FOLDER_META); + GTaskClient.getInstance().createTaskList(mMetaList); + } + + // 初始化任务列表 + for (int i = 0; i < jsTaskLists.length(); i++) { + // 获取 JSON 数据中的任务列表对象 + JSONObject object = jsTaskLists.getJSONObject(i); + String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); + String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME); + // 如果任务列表名称以“MIUI_FOLDER_PREFFIX”开头且不是元列表,则为任务列表 + if (name.startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX) + && !name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + + GTaskStringUtils.FOLDER_META)) { + // 初始化任务列表 + TaskList tasklist = new TaskList(); + tasklist.setContentByRemoteJSON(object); + mGTaskListHashMap.put(gid, tasklist); + mGTaskHashMap.put(gid, tasklist); + + // 加载任务 + JSONArray jsTasks = client.getTaskList(gid); + for (int j = 0; j < jsTasks.length(); j++) { + object = (JSONObject) jsTasks.getJSONObject(j); + gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); + Task task = new Task(); + task.setContentByRemoteJSON(object); + // 如果任务值得保存,将其添加 + if (task.isWorthSaving()) { + task.setMetaInfo(mMetaHashMap.get(gid));// 设置任务元信息 + tasklist.addChildTask(task);// 将任务添加到任务列表的子任务中 + mGTaskHashMap.put(gid, task); // 在哈希表中添加任务的ID和任务对象 + } + } + } + } + } catch (JSONException e) { + Log.e(TAG, e.toString()); + e.printStackTrace(); + throw new ActionFailureException("initGTaskList: handing JSONObject failed"); + } + } + // 同步笔记内容 + private void syncContent() throws NetworkFailureException { + int syncType; + Cursor c = null; + String gid; + Node node; + + mLocalDeleteIdMap.clear(); + if (mCancelled) {// 如果已取消,直接返回 + return; + } + + // 处理本地已删除笔记 + try { + // 查询非系统类型且父级 ID 不是回收站的笔记 + 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) + }, null); + if (c != null) { + while (c.moveToNext()) { + gid = c.getString(SqlNote.GTASK_ID_COLUMN); + node = mGTaskHashMap.get(gid); + if (node != null) { + mGTaskHashMap.remove(gid); + doContentSync(Node.SYNC_ACTION_DEL_REMOTE, node, c); + } + + mLocalDeleteIdMap.add(c.getLong(SqlNote.ID_COLUMN)); + } + } else { + Log.w(TAG, "failed to query trash folder"); + } + } finally { + if (c != null) { + c.close(); + c = null; + } + } + + // 先同步文件夹 + syncFolder(); + + // 处理已存在于数据库中的笔记 + try { + // 查询类型为笔记且父级 ID 不是回收站的笔记,按类型倒序排序 + c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE, + "(type=? AND parent_id<>?)", new String[] { + String.valueOf(Notes.TYPE_NOTE), String.valueOf(Notes.ID_TRASH_FOLER) + }, NoteColumns.TYPE + " DESC"); + if (c != null) { + while (c.moveToNext()) { + gid = c.getString(SqlNote.GTASK_ID_COLUMN); + node = mGTaskHashMap.get(gid); + if (node != null) { + mGTaskHashMap.remove(gid); + 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) { + // 本地新增 + syncType = Node.SYNC_ACTION_ADD_REMOTE; + } else { + // 远程删除 + syncType = Node.SYNC_ACTION_DEL_LOCAL; + } + } + doContentSync(syncType, node, c); + } + } else { + Log.w(TAG, "failed to query existing note in database"); + } + + } finally { + if (c != null) { + c.close(); + c = null; + } + } + + // 处理剩余项 + Iterator> iter = mGTaskHashMap.entrySet().iterator(); + while (iter.hasNext()) {// 如果还有下一个键值对 + Map.Entry entry = iter.next();// 获取下一个键值对 + node = entry.getValue();// 获取键值对中的value并将其赋值给node + doContentSync(Node.SYNC_ACTION_ADD_LOCAL, node, null);// 将node添加到本地同步 + } + + // mCancelled 可能会被另一个线程设置,因此我们需要逐个检查 + // 清除本地删除表 + if (!mCancelled) {// 如果未被取消 + if (!DataUtils.batchDeleteNotes(mContentResolver, mLocalDeleteIdMap)) {// 批量删除本地删除表中的笔记 + throw new ActionFailureException("failed to batch-delete local deleted notes"); + }// 如果删除失败则抛出异常 + } + + // 刷新本地同步id + if (!mCancelled) { + GTaskClient.getInstance().commitUpdate(); + refreshLocalSyncId(); + } + + } + + private void syncFolder() throws NetworkFailureException { + Cursor c = null;// 游标对象,用于访问数据 + String gid;// GTask任务列表的ID + Node node;// GTask任务列表对应的本地节点 + int syncType;// 本地与远程数据同步的类型 + + if (mCancelled) {// 如果同步已被取消,则直接返回 + return; + } + + // for root folder + try { + // 查询根目录的数据 + c = mContentResolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, + Notes.ID_ROOT_FOLDER), SqlNote.PROJECTION_NOTE, null, null, null); + if (c != null) { + c.moveToNext();// 将游标移动到下一个记录 + gid = c.getString(SqlNote.GTASK_ID_COLUMN);// 获取GTask任务列表ID + node = mGTaskHashMap.get(gid);// 从GTask任务列表映射中获取对应本地节点 + if (node != null) { + mGTaskHashMap.remove(gid);// 从映射中移除该节点 + mGidToNid.put(gid, (long) Notes.ID_ROOT_FOLDER);// 将GTask ID映射到本地ID + mNidToGid.put((long) Notes.ID_ROOT_FOLDER, gid);// 将本地ID映射到GTask ID + // 仅当名称不是默认值时,才更新远程名称 + if (!node.getName().equals( + GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT)) + doContentSync(Node.SYNC_ACTION_UPDATE_REMOTE, node, c);// 同步本地和远程数据 + } else { + doContentSync(Node.SYNC_ACTION_ADD_REMOTE, node, c);// 将本地数据同步到远程 + } + } else { + Log.w(TAG, "failed to query root folder");// 记录警告信息 + } + } finally { + if (c != null) { + c.close();// 关闭游标 + c = null;// 将游标对象设置为null + } + } + + // for call-note folder + try { + // 查询通话记录文件夹的数据 + c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE, "(_id=?)", + new String[] { + String.valueOf(Notes.ID_CALL_RECORD_FOLDER) + }, null); + if (c != null) { + if (c.moveToNext()) { + gid = c.getString(SqlNote.GTASK_ID_COLUMN);// 获取GTask任务列表ID + node = mGTaskHashMap.get(gid);// 从GTask任务列表映射中获取对应本地节点 + if (node != null) { + mGTaskHashMap.remove(gid);// 从映射中移除该节点 + mGidToNid.put(gid, (long) Notes.ID_CALL_RECORD_FOLDER);// 将GTask ID映射到本地ID + mNidToGid.put((long) Notes.ID_CALL_RECORD_FOLDER, gid);// 将本地ID映射到GTask ID + // 仅当名称不是默认值时,才更新远端 + if (!node.getName().equals( + GTaskStringUtils.MIUI_FOLDER_PREFFIX + + GTaskStringUtils.FOLDER_CALL_NOTE)) + doContentSync(Node.SYNC_ACTION_UPDATE_REMOTE, node, c); + } else { + doContentSync(Node.SYNC_ACTION_ADD_REMOTE, node, c); + } + } + } else { + Log.w(TAG, "failed to query call note folder"); + } + } finally { + if (c != null) { + c.close(); + c = null; + } + } + + // 处理本地现有文件夹 + try { + c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE, + "(type=? AND parent_id<>?)", new String[] { + String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER) + }, NoteColumns.TYPE + " DESC"); + if (c != null) { + while (c.moveToNext()) { + gid = c.getString(SqlNote.GTASK_ID_COLUMN); + node = mGTaskHashMap.get(gid); + if (node != null) { + mGTaskHashMap.remove(gid); + 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) { + // 本地新增 + syncType = Node.SYNC_ACTION_ADD_REMOTE; + } else { + // 远端删除 + syncType = Node.SYNC_ACTION_DEL_LOCAL; + } + } + doContentSync(syncType, node, c); + } + } else { + Log.w(TAG, "failed to query existing folder"); + } + } finally { + if (c != null) { + c.close(); + c = null; + } + } + + // 处理远端新增文件夹 + Iterator> iter = mGTaskListHashMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + gid = entry.getKey(); + node = entry.getValue(); + if (mGTaskHashMap.containsKey(gid)) { + mGTaskHashMap.remove(gid); + doContentSync(Node.SYNC_ACTION_ADD_LOCAL, node, null); + } + } + + if (!mCancelled) + GTaskClient.getInstance().commitUpdate(); + } + + private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException { + // 如果取消了同步,则直接返回 + if (mCancelled) { + return; + } + // 元数据对象 + MetaData meta; + // 根据同步类型执行相应的操作 + switch (syncType) { + // 本地添加节点 + case Node.SYNC_ACTION_ADD_LOCAL: + addLocalNode(node); + break; + // 远程添加节点 + case Node.SYNC_ACTION_ADD_REMOTE: + addRemoteNode(node, c); + break; + // 本地删除节点 + case Node.SYNC_ACTION_DEL_LOCAL: + // 获取需要删除的节点的元数据 + meta = mMetaHashMap.get(c.getString(SqlNote.GTASK_ID_COLUMN)); + if (meta != null) { + // 使用 GTaskClient 删除节点 + GTaskClient.getInstance().deleteNode(meta); + } + // 将节点 ID 添加到本地删除 ID 映射表中 + mLocalDeleteIdMap.add(c.getLong(SqlNote.ID_COLUMN)); + break; + // 远程删除节点 + case Node.SYNC_ACTION_DEL_REMOTE: + // 获取需要删除的节点的元数据 + meta = mMetaHashMap.get(node.getGid()); + if (meta != null) { + // 使用 GTaskClient 删除节点 + GTaskClient.getInstance().deleteNode(meta); + } + // 使用 GTaskClient 删除节点 + GTaskClient.getInstance().deleteNode(node); + break; + // 本地更新节点 + case Node.SYNC_ACTION_UPDATE_LOCAL: + updateLocalNode(node, c); + break; + // 远程更新节点 + case Node.SYNC_ACTION_UPDATE_REMOTE: + updateRemoteNode(node, c); + break; + // 更新冲突 + case Node.SYNC_ACTION_UPDATE_CONFLICT: + // 可以考虑合并两个修改 + // 现在先简单地使用本地更新 + updateRemoteNode(node, c); + break; + // 不执行任何操作 + case Node.SYNC_ACTION_NONE: + break; + // 同步操作失败 + case Node.SYNC_ACTION_ERROR: + default: + // 抛出异常 + throw new ActionFailureException("unkown sync action type"); + } + } + + private void addLocalNode(Node node) throws NetworkFailureException { + // 如果取消了操作,直接返回 + if (mCancelled) { + return; + } + // 声明一个 SqlNote 对象 + SqlNote sqlNote; + // 如果是 TaskList,判断是哪种文件夹 + if (node instanceof TaskList) { + // 如果是默认文件夹 + if (node.getName().equals( + GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT)) { + // 新建一个根文件夹的 SqlNote 对象 + sqlNote = new SqlNote(mContext, Notes.ID_ROOT_FOLDER); + } + // 如果是通话记录文件夹 + else if (node.getName().equals( + GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_CALL_NOTE)) { + // 新建一个通话记录文件夹的 SqlNote 对象 + sqlNote = new SqlNote(mContext, Notes.ID_CALL_RECORD_FOLDER); + } + // 如果是其他类型的文件夹 + else { + // 新建一个普通的 SqlNote 对象,并设置其内容和父文件夹 ID + sqlNote = new SqlNote(mContext); + sqlNote.setContent(node.getLocalJSONFromContent()); + sqlNote.setParentId(Notes.ID_ROOT_FOLDER); + } + } + // 如果是 Task + else { + // 新建一个普通的 SqlNote 对象 + sqlNote = new SqlNote(mContext); + // 从 Task 中获取其内容的 JSON 对象 + JSONObject js = node.getLocalJSONFromContent(); + try { + // 如果 JSON 对象中包含元数据头部信息 + if (js.has(GTaskStringUtils.META_HEAD_NOTE)) { + // 获取元数据头部信息中的 Note 对象 + JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); + // 如果 Note 对象中包含 ID + if (note.has(NoteColumns.ID)) { + // 获取 Note 的 ID + long id = note.getLong(NoteColumns.ID); + // 如果该 ID 在 Note 数据库中已经存在 + if (DataUtils.existInNoteDatabase(mContentResolver, id)) { + // 该 ID 已经被占用,需要新建一个 ID + note.remove(NoteColumns.ID); + } + } + } + // 如果 JSON 对象中包含元数据数据部分 + if (js.has(GTaskStringUtils.META_HEAD_DATA)) { + // 获取元数据数据部分的 JSON 数组 + JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); + // 遍历该 JSON 数组 + for (int i = 0; i < dataArray.length(); i++) { + // 获取数组中的 JSON 对象 + JSONObject data = dataArray.getJSONObject(i); + // 如果该 JSON 对象中包含 ID + if (data.has(DataColumns.ID)) { + // 获取该数据的 ID + long dataId = data.getLong(DataColumns.ID); + // 如果该 ID 在数据数据库中已经存在 + if (DataUtils.existInDataDatabase(mContentResolver, dataId)) { + // 该 ID 已经被占用,需要新建一个 ID + data.remove(DataColumns.ID); + } + } + } + + } + } catch (JSONException e) {// 捕获 JSON 解析异常 + Log.w(TAG, e.toString());// 记录警告日志 + e.printStackTrace();// 打印异常堆栈信息 + } + sqlNote.setContent(js);// 设置 SQLNote 的内容为解析出的 js + + Long parentId = mGidToNid.get(((Task) node).getParent().getGid());// 获取 Task 节点的父节点的 GID 对应的 NID + // 如果获取到的 NID 为空 + if (parentId == null) { + Log.e(TAG, "cannot find task's parent id locally");// 记录错误日志 + throw new ActionFailureException("cannot add local node");// 抛出 ActionFailureException 异常 + } + sqlNote.setParentId(parentId.longValue());// 将 SQLNote 的父节点 ID 设置为获取到的 NID + } + + // 创建本地节点 + sqlNote.setGtaskId(node.getGid());// 设置 SQLNote 的 GTask ID 为节点的 GID + sqlNote.commit(false);// 将 SQLNote 提交到本地数据库,不需要立即同步到远程服务器 + + // 更新 GID-NID 映射 + mGidToNid.put(node.getGid(), sqlNote.getId());// 将节点的 GID 映射为 SQLNote 的 ID + mNidToGid.put(sqlNote.getId(), node.getGid());// 将 SQLNote 的 ID 映射为节点的 GID + + // 更新元数据 + updateRemoteMeta(node.getGid(), sqlNote);// 同步 SQLNote 的元数据到远程服务器 + } + + private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException { + // 如果操作已经被取消,则不进行任何操作 + if (mCancelled) { + return; + } + + SqlNote sqlNote; + // 将数据库查询结果保存到 SqlNote 对象中 + sqlNote = new SqlNote(mContext, c); + // 将节点内容转换为 JSON 格式并保存到 SqlNote 对象中 + sqlNote.setContent(node.getLocalJSONFromContent()); + + // 如果节点是任务类型,则将其父节点的 ID 设置为对应的本地 ID, + // 否则将其父节点的 ID 设置为根文件夹的 ID + Long parentId = (node instanceof Task) ? mGidToNid.get(((Task) node).getParent().getGid()) + : new Long(Notes.ID_ROOT_FOLDER); + // 如果 parentId 为 null,则说明无法在本地找到该任务的父节点 ID, + // 此时抛出一个异常 + if (parentId == null) { + Log.e(TAG, "cannot find task's parent id locally"); + throw new ActionFailureException("cannot update local node"); + } + // 将父节点 ID 设置为 sqlNote 对象的 parentId 属性 + sqlNote.setParentId(parentId.longValue()); + // 将 sqlNote 对象的属性保存到数据库中 + sqlNote.commit(true); + + // 更新远程节点的元信息 + updateRemoteMeta(node.getGid(), sqlNote); + } + + private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException { + // 如果任务已经被取消,直接返回 + if (mCancelled) { + return; + } + // 通过Cursor获取SqlNote对象 + SqlNote sqlNote = new SqlNote(mContext, c); + Node n; + + // 如果SqlNote是任务类型,进行以下操作 + if (sqlNote.isNoteType()) { + // 创建一个Task对象并用SqlNote的内容更新它 + Task task = new Task(); + task.setContentByLocalJSON(sqlNote.getContent()); + + // 获取Task对象的父任务列表的gid + String parentGid = mNidToGid.get(sqlNote.getParentId()); + // 如果无法找到父任务列表的gid,抛出ActionFailureException异常 + if (parentGid == null) { + Log.e(TAG, "cannot find task's parent tasklist"); + throw new ActionFailureException("cannot add remote task"); + } + // 在父任务列表中添加子任务 + mGTaskListHashMap.get(parentGid).addChildTask(task); + // 通过GTaskClient实例创建Task任务 + GTaskClient.getInstance().createTask(task); + n = (Node) task; + + // 添加元数据 + updateRemoteMeta(task.getGid(), sqlNote); + } else { + TaskList tasklist = null; + // 如果SqlNote是文件夹类型,进行以下操作 + // 如果是根文件夹,设置文件夹名为默认文件夹 + String folderName = GTaskStringUtils.MIUI_FOLDER_PREFFIX; + if (sqlNote.getId() == Notes.ID_ROOT_FOLDER) + folderName += GTaskStringUtils.FOLDER_DEFAULT; + // 如果是通话记录文件夹,设置文件夹名为通话记录文件夹 + else if (sqlNote.getId() == Notes.ID_CALL_RECORD_FOLDER) + folderName += GTaskStringUtils.FOLDER_CALL_NOTE; + // 否则,将文件夹名设置为SqlNote对象的片段内容 + else + folderName += sqlNote.getSnippet(); + // 遍历mGTaskListHashMap查找是否存在与SqlNote对象匹配的TaskList对象 + Iterator> iter = mGTaskListHashMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + String gid = entry.getKey(); + TaskList list = entry.getValue(); + // 如果存在匹配的TaskList对象,则将tasklist设置为该对象 + if (list.getName().equals(folderName)) { + tasklist = list; + // 如果mGTaskHashMap包含gid,将其从中移除 + if (mGTaskHashMap.containsKey(gid)) { + mGTaskHashMap.remove(gid); + } + break; + } + } + + // 如果未找到匹配的TaskList对象,新建一个TaskList对象 + if (tasklist == null) { + tasklist = new TaskList(); + tasklist.setContentByLocalJSON(sqlNote.getContent()); + GTaskClient.getInstance().createTaskList(tasklist); + mGTaskListHashMap.put(tasklist.getGid(), tasklist); + } + n = (Node) tasklist; + } + + // 更新SqlNote对象的GTaskId,并将其提交到本地数据库 + sqlNote.setGtaskId(n.getGid()); + sqlNote.commit(false); + sqlNote.resetLocalModified(); + sqlNote.commit(true); + + // gid-id 映射表 + mGidToNid.put(n.getGid(), sqlNote.getId()); + mNidToGid.put(sqlNote.getId(), n.getGid()); + } + + private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException { + if (mCancelled) { + return; // 如果任务已取消,则退出此方法 + } + + SqlNote sqlNote = new SqlNote(mContext, c); // 创建 SqlNote 实例 + + // 更新远程服务器的节点内容 + node.setContentByLocalJSON(sqlNote.getContent()); + GTaskClient.getInstance().addUpdateNode(node); + + // 更新节点的元数据 + updateRemoteMeta(node.getGid(), sqlNote); + + // 如果是笔记类型,则移动任务(子任务)到另一个任务列表中 + if (sqlNote.isNoteType()) { + Task task = (Task) node; + TaskList preParentList = task.getParent(); // 获取任务当前的父任务列表 + + // 查找新的父任务列表的 GID + String curParentGid = mNidToGid.get(sqlNote.getParentId()); + if (curParentGid == null) { + Log.e(TAG, "cannot find task's parent tasklist"); // 找不到新父任务列表,记录错误并抛出异常 + throw new ActionFailureException("cannot update remote task"); + } + TaskList curParentList = mGTaskListHashMap.get(curParentGid); // 获取新父任务列表的 TaskList 实例 + + // 如果新旧父任务列表不同,则移动任务到新的父任务列表 + if (preParentList != curParentList) { + preParentList.removeChildTask(task); // 从旧父任务列表中移除该任务 + curParentList.addChildTask(task); // 添加该任务到新的父任务列表中 + GTaskClient.getInstance().moveTask(task, preParentList, curParentList); // 移动任务到新父任务列表 + } + } + + sqlNote.resetLocalModified(); // 重置本地修改标记 + sqlNote.commit(true); // 将 SqlNote 中的修改提交到本地 SQLite 数据库中 + } + + private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException { + // 如果 sqlNote 不为空且为笔记类型,则执行以下代码 + if (sqlNote != null && sqlNote.isNoteType()) { + // 获取 gid 对应的 metaData + MetaData metaData = mMetaHashMap.get(gid); + if (metaData != null) { + // 设置 gid 对应的 metaData 的内容为 sqlNote 的内容 + metaData.setMeta(gid, sqlNote.getContent()); + // 将 metaData 添加到更新队列中 + GTaskClient.getInstance().addUpdateNode(metaData); + } else { + // 如果 metaData 为空,则创建新的 metaData,并设置其内容为 sqlNote 的内容 + metaData = new MetaData(); + metaData.setMeta(gid, sqlNote.getContent()); + // 将 metaData 添加到 mMetaList 的子任务列表中 + mMetaList.addChildTask(metaData); + // 将 metaData 添加到 mMetaHashMap 中 + mMetaHashMap.put(gid, metaData); + // 创建任务并将其添加到 GTaskClient 的任务列表中 + GTaskClient.getInstance().createTask(metaData); + } + } + } + + + // 声明一个方法,用于更新本地同步 ID,如果网络故障则抛出 NetworkFailureException 异常 + private void refreshLocalSyncId() throws NetworkFailureException { + // 如果已取消,则直接返回 + if (mCancelled) { + return; + } + + // 清空哈希表 + mGTaskHashMap.clear(); + mGTaskListHashMap.clear(); + mMetaHashMap.clear(); + // 初始化 GTask 列表 + initGTaskList(); + + // 声明一个游标,用于查询本地便签 + Cursor c = null; + try { + // 查询不属于系统类型和垃圾桶类型的所有便签 + 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" + ); + + // 如果查询结果不为空 + if (c != null) { + // 遍历查询结果 + while (c.moveToNext()) { + // 获取当前便签的 GTask ID + String gid = c.getString(SqlNote.GTASK_ID_COLUMN); + // 根据 GTask ID 从 GTask 哈希表中获取节点信息 + Node node = mGTaskHashMap.get(gid); + // 如果节点信息不为空 + if (node != null) { + // 从 GTask 哈希表中移除当前 GTask ID 对应的节点 + mGTaskHashMap.remove(gid); + // 创建一个 ContentValues 对象,用于更新本地便签的同步 ID + ContentValues values = new ContentValues(); + values.put(NoteColumns.SYNC_ID, node.getLastModified()); + // 更新本地便签的同步 ID + mContentResolver.update( + ContentUris.withAppendedId( + Notes.CONTENT_NOTE_URI, + c.getLong(SqlNote.ID_COLUMN) + ), + values, + null, + null + ); + } else { + // 如果节点信息为空,打印日志并抛出 ActionFailureException 异常 + Log.e(TAG, "something is missed"); + throw new ActionFailureException( + "some local items don't have gid after sync" + ); + } + } + } else { + // 如果查询结果为空,打印警告日志 + Log.w(TAG, "failed to query local note to refresh sync id"); + } + } finally { + // 关闭游标 + if (c != null) { + c.close(); + c = null; + } + } + } + + + public String getSyncAccount() { + return GTaskClient.getInstance().getSyncAccount().name; + } + + public void cancelSync() { + mCancelled = true; + } + } + \ No newline at end of file diff --git a/other/210340051 何越/gtask/remote/GTaskSyncService.java b/other/210340051 何越/gtask/remote/GTaskSyncService.java new file mode 100644 index 0000000..0db5471 --- /dev/null +++ b/other/210340051 何越/gtask/remote/GTaskSyncService.java @@ -0,0 +1,129 @@ +/* + * 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.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.IBinder; + +public class GTaskSyncService extends Service { + // 同步动作的广播名称,ACTION_START_SYNC 表示开始同步,ACTION_CANCEL_SYNC 表示取消同步,ACTION_INVALID 表示无效 + public final static String ACTION_STRING_NAME = "sync_action_type"; + + public final static int ACTION_START_SYNC = 0; + + public final static int ACTION_CANCEL_SYNC = 1; + + public final static int ACTION_INVALID = 2; + // 广播名称和广播消息 + public final static String GTASK_SERVICE_BROADCAST_NAME = "net.micode.notes.gtask.remote.gtask_sync_service"; + + public final static String GTASK_SERVICE_BROADCAST_IS_SYNCING = "isSyncing"; + + public final static String GTASK_SERVICE_BROADCAST_PROGRESS_MSG = "progressMsg"; + // 同步任务和同步进度 + private static GTaskASyncTask mSyncTask = null; + + private static String mSyncProgress = ""; + // 开始同步 + private void startSync() { + if (mSyncTask == null) { + mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() { + public void onComplete() { + mSyncTask = null; + sendBroadcast(""); + stopSelf(); + } + }); + sendBroadcast(""); + mSyncTask.execute(); + } + } + // 取消同步 + private void cancelSync() { + if (mSyncTask != null) { + mSyncTask.cancelSync(); + } + } + + @Override + public void onCreate() { + mSyncTask = null; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Bundle bundle = intent.getExtras(); + if (bundle != null && bundle.containsKey(ACTION_STRING_NAME)) { + switch (bundle.getInt(ACTION_STRING_NAME, ACTION_INVALID)) { + case ACTION_START_SYNC: + startSync(); + break; + case ACTION_CANCEL_SYNC: + cancelSync(); + break; + default: + break; + } + return START_STICKY; + } + return super.onStartCommand(intent, flags, startId); + } + + @Override + public void onLowMemory() { + if (mSyncTask != null) { + mSyncTask.cancelSync(); + } + } + // 不支持绑定 + public IBinder onBind(Intent intent) { + return null; + } + // 发送同步进度广播 + public void sendBroadcast(String msg) { + mSyncProgress = msg; + Intent intent = new Intent(GTASK_SERVICE_BROADCAST_NAME); + intent.putExtra(GTASK_SERVICE_BROADCAST_IS_SYNCING, mSyncTask != null); + intent.putExtra(GTASK_SERVICE_BROADCAST_PROGRESS_MSG, msg); + sendBroadcast(intent); + } + // 静态方法,开始同步任务 + public static void startSync(Activity activity) { + GTaskManager.getInstance().setActivityContext(activity); + Intent intent = new Intent(activity, GTaskSyncService.class); + intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_START_SYNC); + activity.startService(intent); + } + // 静态方法,取消同步任务 + public static void cancelSync(Context context) { + Intent intent = new Intent(context, GTaskSyncService.class);// 创建一个新的意图Intent,指向GTaskSyncService类,传入context参数 + intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_CANCEL_SYNC);// 给Intent添加一个ACTION_CANCEL_SYNC的字符串Extra参数 + context.startService(intent); + } + + public static boolean isSyncing() {// 定义一个公共的静态方法isSyncing,返回值为布尔类型 + return mSyncTask != null; + } + + public static String getProgressString() {// 定义一个公共的静态方法getProgressString,返回值为字符串类型 + return mSyncProgress; + } +} diff --git a/other/210340051何越-实践总结报告.docx b/other/210340051何越-实践总结报告.docx new file mode 100644 index 0000000000000000000000000000000000000000..c879760ba73fe4e7eca2511a5e4ca948152c07c1 GIT binary patch literal 13078 zcmb7r19WA})^2Qf*s*Qfwr!gobZm8O+qP|Y+_5`m$9%~-_ug|(|M!36y&7ZhwRWwk znzPniwPt-=P7)Xd3gDv!%WU&~9RJ-Q-%pHe4donc?Hp<4-pP>PJ0Sibo1-<*Hv|L# za0CJXK=?bEzMUP7tF=`|Opi<-9fHug*t1}~y9KFr4!@=9mPmPHu&)P2-LXO6D#L#VY=!nn0^2 zPMc4!YmokxnyYQOGV+4=sp}_zZJA-4y#k`VI>IdNfgZ5rK1YR7{@{Rfhj?bErrX3X z#ChIPQbV22^?jF}?Z?K^u(H}wk{$Cn>R;wDm*&hF7a04(4InI1K&4;&kJgS|5w5#) z^1HZ`C_4fE8IYTbD}0mpfCRh;1o7_yF|>6s{)mWYtmH>Tg6_mt@vnGlGL%r%#3^u& z!X(6yeSfIm);EM?46}Hq1K2}1gKcvpuz`uE1`!~PT|WPs;LQ{lwbTZYtd>b25o97D z10a+r8RrsgnzeWJ1KMwiX(xjdm%V0n+@2=@>yUHMmnqiBWe;iC~$YCb3!P&2x9 z{m=5x6*qbfPj%T7SY!=XX{DJZb?(E721zILmPKE;EE>X8#4Yn~WiMZLj|#Dwl?opy z0m) zgJsd4uk1I8Eb_8)k~jZ~`|8OEdgT$9C0_B(Vck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