Compare commits

...

2 Commits

@ -25,10 +25,14 @@ import android.util.Log;
import java.util.HashMap;
// Contact类用于查询联系人信息
public class Contact {
// 用于缓存已查询到的联系人名称
private static HashMap<String, String> sContactCache;
// 日志标签
private static final String TAG = "Contact";
// 查询联系人的选择条件
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
+ " AND " + Data.RAW_CONTACT_ID + " IN "
@ -36,17 +40,22 @@ public class Contact {
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
// 根据电话号码获取联系人名称的方法
public static String getContact(Context context, String phoneNumber) {
// 如果缓存为空则创建一个新的HashMap
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
// 如果缓存中已存在该电话号码的联系人,则直接返回其名称
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
// 替换CALLER_ID_SELECTION中的"+"为phoneNumber的最小匹配形式
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
// 查询联系人信息
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
@ -54,20 +63,27 @@ public class Contact {
new String[] { phoneNumber },
null);
// 如果查询结果不为空且有结果,则获取联系人名称
if (cursor != null && cursor.moveToFirst()) {
try {
String name = cursor.getString(0);
// 将联系人名称存入缓存
sContactCache.put(phoneNumber, name);
// 返回联系人名称
return name;
} catch (IndexOutOfBoundsException e) {
// 获取联系人名称出错记录日志并返回null
Log.e(TAG, " Cursor get string error " + e.toString());
return null;
} finally {
// 关闭游标
cursor.close();
}
} else {
// 查询结果为空记录日志并返回null
Log.d(TAG, "No contact matched with number:" + phoneNumber);
return null;
}
}
}
/*这个类主要用于根据电话号码查询联系人名称。在查询过程中会将查询到的联系人名称缓存在一个HashMap中以便于下次查询时直接从缓存中获取。*/

@ -35,15 +35,15 @@ import org.json.JSONObject;
public class Task extends Node {
private static final String TAG = Task.class.getSimpleName();
private boolean mCompleted;//表示任务是否完成
private boolean mCompleted;
private String mNotes;//表示任务备注的字符串
private String mNotes;
private JSONObject mMetaInfo;//表示任务元信息的JSONObject对象
private JSONObject mMetaInfo;
private Task mPriorSibling;//表示任务前一个兄弟任务的Task对象
private Task mPriorSibling;
private TaskList mParent;//表示任务所属任务列表的TaskList对象
private TaskList mParent;
public Task() {
super();
@ -52,23 +52,23 @@ public class Task extends Node {
mPriorSibling = null;
mParent = null;
mMetaInfo = null;
}//初始化
}
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type 表示动作类型为“创建”
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
// action_id 表示该动作ID
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// index 表示Task在所属TaskList的位置
// index
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this));
// entity_delta 表示创建的Task的具体信息包括名称创建者ID类型笔记等
// entity_delta
JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
@ -79,17 +79,17 @@ public class Task extends Node {
}
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
// parent_id 表示所属TaskList的ID
// parent_id
js.put(GTaskStringUtils.GTASK_JSON_PARENT_ID, mParent.getGid());
// dest_parent_type 表示所属TaskList的类型
// dest_parent_type
js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE,
GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
// list_id 表示所属TaskList的ID
// list_id
js.put(GTaskStringUtils.GTASK_JSON_LIST_ID, mParent.getGid());
// prior_sibling_id 表示排在该Task之前的兄弟Task的ID
// prior_sibling_id
if (mPriorSibling != null) {
js.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, mPriorSibling.getGid());
}
@ -101,23 +101,23 @@ public class Task extends Node {
}
return js;
}//返回JSONObject对象表示用于创建该Task的动作
}
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type 操作类型(更新操作)
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
// action_id 操作ID
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// id 要更新的任务的ID
// id
js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
// entity_delta 更新的内容。包含了任务的名称、备注、是否已删除等信息。
// entity_delta
JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
if (getNotes() != null) {
@ -133,62 +133,62 @@ public class Task extends Node {
}
return js;
}//返回JSONObject对象包含更新Google Task的相关数据
}
public void setContentByRemoteJSON(JSONObject js) {
if (js != null){
if (js != null) {
try {
// id 检查"JSON"对象是否包含id属性
// id
if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
}//如果是则将其值设置为任务对象的gid属性
}
// last_modified 检查JSON对象是否包含last_modified属性
// last_modified
if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
}//如果是将其值设置为任务对象的lastModified属性
}
// name 检查JSON对象是否包含name属性
// name
if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
}//如果是则将其值设置为任务对象的name属性
}
// notes 它检查JSON对象是否包含notes属性
// notes
if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
}//如果是则将其值设置为任务对象的notes属性
}
// deleted 检查JSON对象是否包含deleted属性
// deleted
if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
}//如果是则将其值设置为任务对象的deleted属性
}
// completed 检查JSON对象是否包含completed属性
// 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异常
throw new ActionFailureException("fail to get task content from jsonobject");
}
}
}//从远程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);
@ -196,23 +196,24 @@ public class Task extends Node {
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 对象
String name = getName();
try {
if (mMetaInfo == null) {
// new task created from web 不存在,则说明任务对象是从 Web 创建的
// new task created from 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();
@ -224,7 +225,7 @@ public class Task extends Node {
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
return js;
} else {
// synced task 如果存在 mMetaInfo JSON 对象,则说明任务对象是同步
// synced task
JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
@ -235,7 +236,7 @@ public class Task extends Node {
break;
}
}
//从现有的 JSON 对象中更新数据并返回。
note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
return mMetaInfo;
}
@ -244,18 +245,18 @@ public class Task extends Node {
e.printStackTrace();
return null;
}
}//将任务对象的内容转换为本地 JSON 对象
}
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {//检查metaData是否为空且其notes属性是否存在
if (metaData != null && metaData.getNotes() != null) {
try {
mMetaInfo = new JSONObject(metaData.getNotes());//尝试将notes属性的值转换为一个JSONObject对象并将其赋值给类成员变量mMetaInfo
mMetaInfo = new JSONObject(metaData.getNotes());
} catch (JSONException e) {
Log.w(TAG, e.toString());
mMetaInfo = null;//记录一个警告日志并将mMetaInfo设置为null
mMetaInfo = null;
}
}
}//检查metaData
}
public int getSyncAction(Cursor c) {
try {
@ -284,22 +285,22 @@ public class Task extends Node {
// there is no local update
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// no update both side
return SYNC_ACTION_NONE;//本地和远程都没有更新,无需同步
return SYNC_ACTION_NONE;
} else {
// apply remote to local
return SYNC_ACTION_UPDATE_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;//发生异常
return SYNC_ACTION_ERROR;
}
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// local modification only
return SYNC_ACTION_UPDATE_REMOTE;//本地有更新,需要将本地的更新同步到远程
return SYNC_ACTION_UPDATE_REMOTE;
} else {
return SYNC_ACTION_UPDATE_CONFLICT;//本地和远程都有更新,需要解决冲突并同步更新
return SYNC_ACTION_UPDATE_CONFLICT;
}
}
} catch (Exception e) {
@ -308,43 +309,43 @@ public class Task extends Node {
}
return SYNC_ACTION_ERROR;
}//获取同步操作
}
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);
}//判断任务是否值得保存
}
public void setCompleted(boolean completed) {
this.mCompleted = completed;
}//// 设置任务的完成状态
}
public void setNotes(String notes) {
this.mNotes = notes;
}//将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对结点内容进行设置获取同步信息进行本地和远程的同步
}

@ -32,37 +32,37 @@ import java.util.ArrayList;
public class TaskList extends Node {
private static final String TAG = TaskList.class.getSimpleName();
private int mIndex;
//表示TaskList在其父节点下的索引位置。
private ArrayList<Task> mChildren;
//表示TaskList的子任务列表
public TaskList() {
super();
mChildren = new ArrayList<Task>();
mIndex = 1;
}//初始化
}
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type 操作类型为 "create"
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
// action_id 由参数 actionId 指定的操作 ID
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// index Google 任务清单的索引值
// index
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex);
// entity_delta 实体数据的 JSON 对象
// entity_delta
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_NAME, getName());
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE,
GTaskStringUtils.GTASK_JSON_TYPE_GROUP);//任务清单
GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
} catch (JSONException e) {
@ -72,26 +72,26 @@ public class TaskList extends Node {
}
return js;
}//创建Google任务清单的JSON对象
}
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type 动作类型此处为“update”表示更新操作
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
// action_id 动作ID用于标识此次操作
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// id 任务列表ID
// id
js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
// entity_delta 实体增量,即更新的具体内容
// entity_delta
JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());//name任务列表名称
entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());//deleted是否已删除
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
} catch (JSONException e) {
@ -101,7 +101,7 @@ public class TaskList extends Node {
}
return js;
}//生成一个Google任务列表的更新操作的JSON对象
}
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
@ -120,19 +120,19 @@ public class TaskList extends Node {
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);
@ -140,8 +140,7 @@ public class TaskList extends Node {
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) {
} 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)
@ -149,31 +148,30 @@ public class TaskList extends Node {
+ GTaskStringUtils.FOLDER_CALL_NOTE);
else
Log.e(TAG, "invalid system folder");
}//是系统类型的笔记,则根据笔记的 ID 判断是默认文件夹还是通话记录文件夹,并设置相应的名称
else {
} 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开头
String folderName = getName();
if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX))
folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(),
folderName.length());//是,则将前缀截去,得到真正的名称
folderName.length());
folder.put(NoteColumns.SNIPPET, folderName);
if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT)//名称为默认名称
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
folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
else
folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
js.put(GTaskStringUtils.META_HEAD_NOTE, folder);
@ -182,31 +180,31 @@ public class TaskList extends Node {
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.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
// there is no local update
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// no update both side 没有任何更新
// no update both side
return SYNC_ACTION_NONE;
} else {
// apply remote to local 表示需要将远程的更新应用到本地
// apply remote to local
return SYNC_ACTION_UPDATE_LOCAL;
}
} else {
// validate gtask id 验证 GTASK_ID_COLUMN 列的值是否等于 getGid() 方法返回的值
// validate gtask id
if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
Log.e(TAG, "gtask id doesn't match");
return SYNC_ACTION_ERROR;//异常
return SYNC_ACTION_ERROR;
}
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// local modification only 表示只有本地有修改,需要将其同步到远程
// local modification only
return SYNC_ACTION_UPDATE_REMOTE;
} else {
// for folder conflicts, just apply local modification 需要优先应用本地的修改
// for folder conflicts, just apply local modification
return SYNC_ACTION_UPDATE_REMOTE;
}
}
@ -216,37 +214,37 @@ public class TaskList extends Node {
}
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 (task != null && !mChildren.contains(task)) {
ret = mChildren.add(task);
if (ret) {
// need to set prior sibling and parent
task.setPriorSibling(mChildren.isEmpty() ? null : mChildren
.get(mChildren.size() - 1));
task.setParent(this);
}//若添加成功,则需要对该任务进行设置其前一个同级任务和父级任务。
}
}
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 指定的位置
int pos = mChildren.indexOf(task);
if (task != null && pos == -1) {
mChildren.add(index, task);
// update the task list 更新插入任务的前一个同级任务和后一个同级任务的引用
// update the task list
Task preTask = null;
Task afterTask = null;
if (index != 0)
@ -257,89 +255,89 @@ public class TaskList extends Node {
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);//移除该任务
int index = mChildren.indexOf(task);
if (index != -1) {
ret = mChildren.remove(task);
if (ret) {
// reset prior sibling and parent 更新被移除任务的前一个同级任务和父级任务的引用
// reset prior sibling and parent
task.setPriorSibling(null);
task.setParent(null);
// update the task list
if (index != mChildren.size()) {//该任务不是子任务列表的最后一个任务
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
if (pos == index)
return true;
return (removeChildTask(task) && addChildTask(task, index));
}//表示将当前对象子任务列表中的一个任务移动到指定位置的操作是否成功
}
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {//遍历当前对象子任务列表中的所有任务
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
if (t.getGid().equals(gid)) {//任务的 gid 属性与传入的 gid 相同
if (t.getGid().equals(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 是否在合法范围内
if (index < 0 || index >= mChildren.size()) {
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 相同,则返回该任务对象
for (Task task : mChildren) {
if (task.getGid().equals(gid))
return task;
}
return null;
}//表示根据传入的 gid 在当前对象的子任务列表中查找并返回相应的任务对象
}
public ArrayList<Task> getChildTaskList() {
return this.mChildren;
}//表示当前对象的子任务列表
}
public void setIndex(int index) {
this.mIndex = index;
}//设置当前任务的索引位置
}
public int getIndex() {
return this.mIndex;
}//返回当前任务在其父任务中的索引位置
}
}

@ -77,8 +77,8 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
NotesListActivity.class), 0);
}
notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
pendingIntent);
/*notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
pendingIntent);*/
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
}

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#88555555" />
<item android:state_selected="true" android:color="#ff999999" />
<item android:color="#ff000000" />
</selector>

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#50000000" />
</selector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 554 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save