whj 1 year ago
parent 8d1efdc3c7
commit 3a0edf61c0

@ -1,17 +1,16 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* c2010-2011The MiCodewww.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
* Apache2.0
* 使
*
*
* http://www.apache.org/licenses/LICENSE-2.0
* 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.data;
@ -30,12 +29,19 @@ public class Contact {
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 "
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
+ " AND " + Data.RAW_CONTACT_ID + " IN "
+ "(SELECT raw_contact_id "
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
/**
*
*
* @param context
* @param phoneNumber
* @return null
*/
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();

@ -1,3 +1,4 @@
<<<<<<< HEAD
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
@ -12,11 +13,31 @@
* 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.
=======
/*
* c2010-2011The MiCodewww.micode.net
*
* Apache2.0
* 使
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
*
*
>>>>>>> whj_branch
*/
package net.micode.notes.data;
import android.net.Uri;
<<<<<<< HEAD
=======
>>>>>>> whj_branch
public class Notes {
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";
@ -25,10 +46,17 @@ public class Notes {
public static final int TYPE_SYSTEM = 2;
/**
<<<<<<< HEAD
* Following IDs are system folders' identifiers
* {@link Notes#ID_ROOT_FOLDER } is default folder
* {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder
* {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records
=======
* ID
* {@link Notes#ID_ROOT_FOLDER }
* {@link Notes#ID_TEMPARAY_FOLDER } 便
* {@link Notes#ID_CALL_RECORD_FOLDER}
>>>>>>> whj_branch
*/
public static final int ID_ROOT_FOLDER = 0;
public static final int ID_TEMPARAY_FOLDER = -1;
@ -52,115 +80,204 @@ public class Notes {
}
/**
<<<<<<< HEAD
* Uri to query all notes and folders
=======
* 便Uri
>>>>>>> whj_branch
*/
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
/**
<<<<<<< HEAD
* Uri to query data
=======
* Uri
>>>>>>> whj_branch
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
public interface NoteColumns {
/**
<<<<<<< HEAD
* The unique ID for a row
* <P> Type: INTEGER (long) </P>
=======
* ID
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String ID = "_id";
/**
<<<<<<< HEAD
* The parent's id for note or folder
* <P> Type: INTEGER (long) </P>
=======
* 便ID
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String PARENT_ID = "parent_id";
/**
<<<<<<< HEAD
* Created data for note or folder
* <P> Type: INTEGER (long) </P>
=======
* 便
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String CREATED_DATE = "created_date";
/**
<<<<<<< HEAD
* Latest modified date
* <P> Type: INTEGER (long) </P>
=======
*
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String MODIFIED_DATE = "modified_date";
/**
<<<<<<< HEAD
* Alert date
* <P> Type: INTEGER (long) </P>
=======
*
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String ALERTED_DATE = "alert_date";
/**
<<<<<<< HEAD
* Folder's name or text content of note
* <P> Type: TEXT </P>
=======
* 便
* <P> TEXT </P>
>>>>>>> whj_branch
*/
public static final String SNIPPET = "snippet";
/**
<<<<<<< HEAD
* Note's widget id
* <P> Type: INTEGER (long) </P>
=======
* 便ID
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String WIDGET_ID = "widget_id";
/**
<<<<<<< HEAD
* Note's widget type
* <P> Type: INTEGER (long) </P>
=======
* 便
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String WIDGET_TYPE = "widget_type";
/**
<<<<<<< HEAD
* Note's background color's id
* <P> Type: INTEGER (long) </P>
=======
* 便ID
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String BG_COLOR_ID = "bg_color_id";
/**
<<<<<<< HEAD
* For text note, it doesn't has attachment, for multi-media
* note, it has at least one attachment
* <P> Type: INTEGER </P>
=======
* 便便
* <P> INTEGER </P>
>>>>>>> whj_branch
*/
public static final String HAS_ATTACHMENT = "has_attachment";
/**
<<<<<<< HEAD
* Folder's count of notes
* <P> Type: INTEGER (long) </P>
=======
* 便
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String NOTES_COUNT = "notes_count";
/**
<<<<<<< HEAD
* The file type: folder or note
* <P> Type: INTEGER </P>
=======
* 便
* <P> INTEGER </P>
>>>>>>> whj_branch
*/
public static final String TYPE = "type";
/**
<<<<<<< HEAD
* The last sync id
* <P> Type: INTEGER (long) </P>
=======
* ID
* <P> INTEGERlong</P>
>>>>>>> whj_branch
*/
public static final String SYNC_ID = "sync_id";
/**
<<<<<<< HEAD
* Sign to indicate local modified or not
* <P> Type: INTEGER </P>
=======
*
* <P> INTEGER </P>
>>>>>>> whj_branch
*/
public static final String LOCAL_MODIFIED = "local_modified";
/**
<<<<<<< HEAD
* Original parent id before moving into temporary folder
* <P> Type : INTEGER </P>
=======
* ID
* <P> INTEGER </P>
>>>>>>> whj_branch
*/
public static final String ORIGIN_PARENT_ID = "origin_parent_id";
/**
<<<<<<< HEAD
* The gtask id
* <P> Type : TEXT </P>
=======
* GTask ID
* <P> TEXT </P>
>>>>>>> whj_branch
*/
public static final String GTASK_ID = "gtask_id";
/**
<<<<<<< HEAD
* The version code
* <P> Type : INTEGER (long) </P>
*/
@ -276,4 +393,117 @@ public class Notes {
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
}
=======
*
* <P>
* INTEGERlong</P>
*/
public static final String VERSION = "version";
}
public interface DataColumns {
/**
* ID
* <P> INTEGERlong</P>
*/
public static final String ID = "_id";
/**
* MIME
* <P> Text </P>
*/
public static final String MIME_TYPE = "mime_type";
/**
* 便ID便
* <P> INTEGERlong</P>
*/
public static final String NOTE_ID = "note_id";
/**
* 便
* <P> INTEGERlong</P>
*/
public static final String CREATED_DATE = "created_date";
/**
*
* <P> INTEGERlong</P>
*/
public static final String MODIFIED_DATE = "modified_date";
/**
*
* <P> TEXT </P>
*/
public static final String CONTENT = "content";
/**
* {@link #MIMETYPE}
* <P> INTEGER </P>
*/
public static final String DATA1 = "data1";
/**
* {@link #MIMETYPE}
* <P> INTEGER </P>
*/
public static final String DATA2 = "data2";
/**
* {@link #MIMETYPE}TEXT
* <P> TEXT </P>
*/
public static final String DATA3 = "data3";
/**
* {@link #MIMETYPE}TEXT
* <P> TEXT </P>
*/
public static final String DATA4 = "data4";
/**
* {@link #MIMETYPE}TEXT
* <P> TEXT </P>
*/
public static final String DATA5 = "data5";
}
public static final class TextNote implements DataColumns {
/**
*
* <P> Integer 1 0 </P>
*/
public static final String MODE = DATA1;
public static final int MODE_CHECK_LIST = 1;
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
}
public static final class CallNote implements DataColumns {
/**
*
* <P> INTEGERlong</P>
*/
public static final String CALL_DATE = DATA1;
/**
*
* <P> TEXT </P>
*/
public static final String PHONE_NUMBER = DATA3;
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
}
>>>>>>> whj_branch
}

@ -1,22 +1,9 @@
/*
* 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.
*
* CRUD SQLite
*/
package net.micode.notes.data;
import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentUris;
@ -34,22 +21,25 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
public class NotesProvider extends ContentProvider {
// 定义用于 URI 匹配的常量
private static final UriMatcher mMatcher;
// 数据库帮助类实例
private NotesDatabaseHelper mHelper;
// 日志标签
private static final String TAG = "NotesProvider";
// URI 代码
private static final int URI_NOTE = 1;
private static final int URI_NOTE_ITEM = 2;
private static final int URI_DATA = 3;
private static final int URI_DATA_ITEM = 4;
private static final int URI_SEARCH = 5;
private static final int URI_SEARCH_SUGGEST = 6;
// 初始化 UriMatcher
static {
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
@ -61,62 +51,67 @@ public class NotesProvider extends ContentProvider {
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST);
}
/**
* x'0A' represents the '\n' character in sqlite. For title and content in the search result,
* we will trim '\n' and white space in order to show more information.
*/
// 用于搜索建议的投影
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ","
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ","
+ R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + ","
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_1 + ","
+ "TRIM(REPLACE(" + NoteColumns.SNIPPET + ", x'0A','')) AS " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ","
+ R.drawable.search_result + " AS " + SearchManager.SUGGEST_COLUMN_ICON_1 + ","
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
// 用于搜索笔记的 SQL 查询
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
+ " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
+ " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
// onCreate 方法
@Override
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
}
// 查询方法
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
String sortOrder) {
Cursor c = null;
SQLiteDatabase db = mHelper.getReadableDatabase();
String id = null;
switch (mMatcher.match(uri)) {
// 处理笔记的查询
case URI_NOTE:
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
sortOrder);
break;
// 处理特定笔记的查询
case URI_NOTE_ITEM:
id = uri.getPathSegments().get(1);
c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
break;
// 处理数据的查询
case URI_DATA:
c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
sortOrder);
break;
// 处理特定数据项的查询
case URI_DATA_ITEM:
id = uri.getPathSegments().get(1);
c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
break;
// 处理搜索查询
case URI_SEARCH:
case URI_SEARCH_SUGGEST:
if (sortOrder != null || projection != null) {
throw new IllegalArgumentException(
"do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
}
// 提取搜索查询字符串
String searchString = null;
if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
if (uri.getPathSegments().size() > 1) {
@ -125,11 +120,10 @@ public class NotesProvider extends ContentProvider {
} else {
searchString = uri.getQueryParameter("pattern");
}
if (TextUtils.isEmpty(searchString)) {
return null;
}
// 执行搜索查询
try {
searchString = String.format("%%%s%%", searchString);
c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
@ -147,14 +141,17 @@ public class NotesProvider extends ContentProvider {
return c;
}
// 插入方法
@Override
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase db = mHelper.getWritableDatabase();
long dataId = 0, noteId = 0, insertedId = 0;
switch (mMatcher.match(uri)) {
// 处理笔记的插入
case URI_NOTE:
insertedId = noteId = db.insert(TABLE.NOTE, null, values);
break;
// 处理数据的插入
case URI_DATA:
if (values.containsKey(DataColumns.NOTE_ID)) {
noteId = values.getAsLong(DataColumns.NOTE_ID);
@ -166,13 +163,14 @@ public class NotesProvider extends ContentProvider {
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
// Notify the note uri
//
// 通知内容解析器有变化
if (noteId > 0) {
getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
}
// Notify the data uri
// 通知数据 URI 有变化
if (dataId > 0) {
getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
@ -181,6 +179,7 @@ public class NotesProvider extends ContentProvider {
return ContentUris.withAppendedId(uri, insertedId);
}
// 删除方法
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
@ -188,10 +187,12 @@ public class NotesProvider extends ContentProvider {
SQLiteDatabase db = mHelper.getWritableDatabase();
boolean deleteData = false;
switch (mMatcher.match(uri)) {
// 处理笔记的删除
case URI_NOTE:
selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";
count = db.delete(TABLE.NOTE, selection, selectionArgs);
break;
// 处理特定笔记的删除
case URI_NOTE_ITEM:
id = uri.getPathSegments().get(1);
/**
@ -205,10 +206,12 @@ public class NotesProvider extends ContentProvider {
count = db.delete(TABLE.NOTE,
NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
break;
// 处理数据的删除
case URI_DATA:
count = db.delete(TABLE.DATA, selection, selectionArgs);
deleteData = true;
break;
// 处理特定数据项的删除
case URI_DATA_ITEM:
id = uri.getPathSegments().get(1);
count = db.delete(TABLE.DATA,
@ -227,6 +230,7 @@ public class NotesProvider extends ContentProvider {
return count;
}
// 更新方法
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int count = 0;
@ -234,20 +238,24 @@ public class NotesProvider extends ContentProvider {
SQLiteDatabase db = mHelper.getWritableDatabase();
boolean updateData = false;
switch (mMatcher.match(uri)) {
// 处理笔记的更新
case URI_NOTE:
increaseNoteVersion(-1, selection, selectionArgs);
count = db.update(TABLE.NOTE, values, selection, selectionArgs);
break;
// 处理特定笔记的更新
case URI_NOTE_ITEM:
id = uri.getPathSegments().get(1);
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs);
break;
// 处理数据的更新
case URI_DATA:
count = db.update(TABLE.DATA, values, selection, selectionArgs);
updateData = true;
break;
// 处理特定数据项的更新
case URI_DATA_ITEM:
id = uri.getPathSegments().get(1);
count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id
@ -267,10 +275,12 @@ public class NotesProvider extends ContentProvider {
return count;
}
// 解析选择方法
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
// 增加笔记版本方法
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
@ -296,9 +306,10 @@ public class NotesProvider extends ContentProvider {
mHelper.getWritableDatabase().execSQL(sql.toString());
}
// 获取类型方法
@Override
public String getType(Uri uri) {
// TODO Auto-generated method stub
// 暂不实现
return null;
}

@ -1,17 +1,16 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* (c) 2010-2011MiCodewww.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
* Apache2.0;
* 使
*
*
* 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;
@ -65,18 +64,18 @@ public class MetaData extends Task {
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
// 不应调用此函数
throw new IllegalAccessError("MetaData:setContentByLocalJSON不应该被调用");
}
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
throw new IllegalAccessError("MetaData:getLocalJSONFromContent不应该被调用");
}
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
throw new IllegalAccessError("MetaData:getSyncAction不应该被调用");
}
}

@ -1,17 +1,16 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* (c) 2010-2011MiCodewww.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
* Apache2.0;
* 使
*
*
* 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;
@ -20,33 +19,29 @@ import android.database.Cursor;
import org.json.JSONObject;
/**
* NodeGTask
*/
public abstract class Node {
// 同步操作的常量值
public static final int SYNC_ACTION_NONE = 0;
public static final int SYNC_ACTION_ADD_REMOTE = 1;
public static final int SYNC_ACTION_ADD_LOCAL = 2;
public static final int SYNC_ACTION_DEL_REMOTE = 3;
public static final int SYNC_ACTION_DEL_LOCAL = 4;
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
public static final int SYNC_ACTION_ERROR = 8;
private String mGid;
private String mName;
private long mLastModified;
private boolean mDeleted;
private String mGid; // Google任务的ID
private String mName; // 名称
private long mLastModified; // 最后修改时间
private boolean mDeleted; // 是否已删除
/**
*
*/
public Node() {
mGid = null;
mName = "";
@ -54,48 +49,51 @@ public abstract class Node {
mDeleted = false;
}
// 抽象方法,由子类实现具体逻辑
public abstract JSONObject getCreateAction(int actionId);
public abstract JSONObject getUpdateAction(int actionId);
public abstract void setContentByRemoteJSON(JSONObject js);
public abstract void setContentByLocalJSON(JSONObject js);
public abstract JSONObject getLocalJSONFromContent();
public abstract int getSyncAction(Cursor c);
// 设置Google任务ID
public void setGid(String gid) {
this.mGid = gid;
}
// 设置名称
public void setName(String name) {
this.mName = name;
}
// 设置最后修改时间
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
// 设置删除状态
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
// 获取Google任务ID
public String getGid() {
return this.mGid;
}
// 获取名称
public String getName() {
return this.mName;
}
// 获取最后修改时间
public long getLastModified() {
return this.mLastModified;
}
// 获取删除状态
public boolean getDeleted() {
return this.mDeleted;
}
}

@ -1,17 +1,16 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* (c) 2010-2011MiCodewww.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
* Apache2.0;
* 使
*
*
* 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;
@ -34,7 +33,9 @@ import net.micode.notes.gtask.exception.ActionFailureException;
import org.json.JSONException;
import org.json.JSONObject;
/**
* SqlData
*/
public class SqlData {
private static final String TAG = SqlData.class.getSimpleName();
@ -71,6 +72,9 @@ public class SqlData {
private ContentValues mDiffDataValues;
/**
*
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -82,6 +86,9 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/**
* SqlData
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -89,6 +96,9 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/**
*
*/
private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
@ -97,6 +107,9 @@ public class SqlData {
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
/**
*
*/
public void setContent(JSONObject js) throws JSONException {
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
if (mIsCreate || mDataId != dataId) {
@ -130,9 +143,12 @@ public class SqlData {
mDataContentData3 = dataContentData3;
}
/**
*
*/
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
Log.e(TAG, "似乎我们还没有在数据库中创建此数据");
return null;
}
JSONObject js = new JSONObject();
@ -144,20 +160,21 @@ public class SqlData {
return js;
}
/**
*
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
mDiffDataValues.remove(DataColumns.ID);
}
mDiffDataValues.put(DataColumns.NOTE_ID, noteId);
Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);
try {
mDataId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
throw new ActionFailureException("create note failed");
Log.e(TAG, "获取笔记ID错误" + e.toString());
throw new ActionFailureException("创建笔记失败");
}
} else {
if (mDiffDataValues.size() > 0) {
@ -167,23 +184,24 @@ public class SqlData {
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
} else {
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
" ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.VERSION + "=?)", new String[] {
String.valueOf(noteId), String.valueOf(version)
});
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
" ? in (SELECT " + NoteColumns.ID +" FROM " + TABLE.NOTE + " WHERE " + NoteColumns.VERSION + "=?)",
new String[] { String.valueOf(noteId), String.valueOf(version) });
}
if (result == 0) {
Log.w(TAG, "there is no update. maybe user updates note when syncing");
Log.w(TAG, "没有更新。可能是用户在同步时更新了笔记");
}
}
}
mDiffDataValues.clear();
mIsCreate = false;
}
/**
* ID
*/
public long getId() {
return mDataId;
}
}

@ -37,7 +37,7 @@ import org.json.JSONObject;
import java.util.ArrayList;
// SqlData类用于处理与数据库的交互操作包括创建、更新和获取数据等操作。
public class SqlNote {
private static final String TAG = SqlNote.class.getSimpleName();
@ -121,7 +121,7 @@ public class SqlNote {
private ContentValues mDiffNoteValues;
private ArrayList<SqlData> mDataList;
//构造函数、初始化属性
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -142,7 +142,7 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
mDataList = new ArrayList<SqlData>();
}
//通过数据库查询结果构造SqlData对象
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -165,6 +165,7 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
}
//从数据库查询结果中加载数据到对象属性
private void loadFromCursor(long id) {
Cursor c = null;
@ -225,14 +226,15 @@ public class SqlNote {
c.close();
}
}
// 设置数据内容
public boolean setContent(JSONObject js) {
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
// 检查笔记类型,系统文件夹不能被设置
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
Log.w(TAG, "cannot set system folder");
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
// for folder we can only update the snnipet and type
// 对于文件夹,只能更新摘要和类型
String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : "";
if (mIsCreate || !mSnippet.equals(snippet)) {
@ -247,6 +249,7 @@ public class SqlNote {
}
mType = type;
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
// 笔记类型为普通笔记
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
if (mIsCreate || mId != id) {
@ -254,6 +257,7 @@ public class SqlNote {
}
mId = id;
// 提醒日期
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
.getLong(NoteColumns.ALERTED_DATE) : 0;
if (mIsCreate || mAlertDate != alertDate) {
@ -261,6 +265,7 @@ public class SqlNote {
}
mAlertDate = alertDate;
// 背景颜色 ID
int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
if (mIsCreate || mBgColorId != bgColorId) {
@ -268,6 +273,7 @@ public class SqlNote {
}
mBgColorId = bgColorId;
// 创建日期
long createDate = note.has(NoteColumns.CREATED_DATE) ? note
.getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis();
if (mIsCreate || mCreatedDate != createDate) {
@ -275,6 +281,7 @@ public class SqlNote {
}
mCreatedDate = createDate;
// 是否有附件
int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT) ? note
.getInt(NoteColumns.HAS_ATTACHMENT) : 0;
if (mIsCreate || mHasAttachment != hasAttachment) {
@ -282,6 +289,7 @@ public class SqlNote {
}
mHasAttachment = hasAttachment;
// 修改日期
long modifiedDate = note.has(NoteColumns.MODIFIED_DATE) ? note
.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis();
if (mIsCreate || mModifiedDate != modifiedDate) {
@ -289,6 +297,7 @@ public class SqlNote {
}
mModifiedDate = modifiedDate;
// 父笔记 ID
long parentId = note.has(NoteColumns.PARENT_ID) ? note
.getLong(NoteColumns.PARENT_ID) : 0;
if (mIsCreate || mParentId != parentId) {
@ -296,6 +305,7 @@ public class SqlNote {
}
mParentId = parentId;
// 摘要
String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : "";
if (mIsCreate || !mSnippet.equals(snippet)) {
@ -303,6 +313,7 @@ public class SqlNote {
}
mSnippet = snippet;
// 笔记类型
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
: Notes.TYPE_NOTE;
if (mIsCreate || mType != type) {
@ -310,6 +321,7 @@ public class SqlNote {
}
mType = type;
// 小部件 ID
int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID)
: AppWidgetManager.INVALID_APPWIDGET_ID;
if (mIsCreate || mWidgetId != widgetId) {
@ -317,6 +329,7 @@ public class SqlNote {
}
mWidgetId = widgetId;
// 小部件类型
int widgetType = note.has(NoteColumns.WIDGET_TYPE) ? note
.getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE;
if (mIsCreate || mWidgetType != widgetType) {
@ -324,6 +337,7 @@ public class SqlNote {
}
mWidgetType = widgetType;
// 原始父笔记 ID
long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID) ? note
.getLong(NoteColumns.ORIGIN_PARENT_ID) : 0;
if (mIsCreate || mOriginParent != originParent) {
@ -331,6 +345,7 @@ public class SqlNote {
}
mOriginParent = originParent;
// 遍历数据内容数组,设置笔记数据
for (int i = 0; i < dataArray.length(); i++) {
JSONObject data = dataArray.getJSONObject(i);
SqlData sqlData = null;
@ -349,6 +364,7 @@ public class SqlNote {
}
sqlData.setContent(data);
}
}
} catch (JSONException e) {
@ -359,6 +375,7 @@ public class SqlNote {
return true;
}
// 获取笔记内容
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
@ -407,41 +424,51 @@ public class SqlNote {
return null;
}
// 设置父笔记 ID
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
// 设置 Google 任务 ID
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
// 设置同步 ID
public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
}
// 重置本地修改标志
public void resetLocalModified() {
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
}
// 获取笔记 ID
public long getId() {
return mId;
}
// 获取父笔记 ID
public long getParentId() {
return mParentId;
}
// 获取摘要
public String getSnippet() {
return mSnippet;
}
// 判断是否为普通笔记类型
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
// 提交笔记更改
public void commit(boolean validateVersion) {
if (mIsCreate) {
// 创建新笔记
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
mDiffNoteValues.remove(NoteColumns.ID);
}
@ -457,12 +484,14 @@ public class SqlNote {
throw new IllegalStateException("Create thread id failed");
}
// 如果是普通笔记,则提交笔记数据
if (mType == Notes.TYPE_NOTE) {
for (SqlData sqlData : mDataList) {
sqlData.commit(mId, false, -1);
}
}
} else {
// 更新已存在的笔记
if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) {
Log.e(TAG, "No such note");
throw new IllegalStateException("Try to update note with invalid id");
@ -473,11 +502,11 @@ public class SqlNote {
if (!validateVersion) {
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?)", new String[] {
String.valueOf(mId)
String.valueOf(mId)
});
} else {
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
new String[] {
String.valueOf(mId), String.valueOf(mVersion)
});
@ -487,6 +516,7 @@ public class SqlNote {
}
}
// 如果是普通笔记,则提交笔记数据
if (mType == Notes.TYPE_NOTE) {
for (SqlData sqlData : mDataList) {
sqlData.commit(mId, validateVersion, mVersion);
@ -494,7 +524,7 @@ public class SqlNote {
}
}
// refresh local info
// 刷新本地信息
loadFromCursor(mId);
if (mType == Notes.TYPE_NOTE)
loadDataContent();

@ -31,20 +31,30 @@ 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;
// 任务的前一个同级任务
private Task mPriorSibling;
// 任务的父任务列表
private TaskList mParent;
/**
* Task
*/
public Task() {
super();
mCompleted = false;
@ -54,13 +64,15 @@ public class Task extends Node {
mMetaInfo = null;
}
/**
* JSON
*/
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);
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
@ -72,8 +84,7 @@ public class Task extends Node {
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);
entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_TASK);
if (getNotes() != null) {
entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
}
@ -83,8 +94,7 @@ public class Task extends Node {
js.put(GTaskStringUtils.GTASK_JSON_PARENT_ID, mParent.getGid());
// dest_parent_type
js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE,
GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
// list_id
js.put(GTaskStringUtils.GTASK_JSON_LIST_ID, mParent.getGid());
@ -103,13 +113,15 @@ public class Task extends Node {
return js;
}
/**
* JSON
*/
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);
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
@ -135,6 +147,9 @@ public class Task extends Node {
return js;
}
/**
* JSON
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -175,10 +190,12 @@ public class Task extends Node {
}
}
/**
* 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");
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) || !js.has(GTaskStringUtils.META_HEAD_DATA)) {
Log.w(TAG, "setContentByLocalJSON: nothing is available");
}
try {
@ -204,6 +221,9 @@ public class Task extends Node {
}
}
/**
* JSON
*/
public JSONObject getLocalJSONFromContent() {
String name = getName();
try {
@ -247,6 +267,9 @@ public class Task extends Node {
}
}
/**
*
*/
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {
try {
@ -258,6 +281,9 @@ public class Task extends Node {
}
}
/**
*
*/
public int getSyncAction(Cursor c) {
try {
JSONObject noteInfo = null;
@ -311,41 +337,51 @@ public class Task extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
*/
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);
}
// 设置任务是否完成
public void setCompleted(boolean completed) {
this.mCompleted = completed;
}
// 设置任务的备注信息
public void setNotes(String notes) {
this.mNotes = notes;
}
// 设置任务的前一个同级任务
public void setPriorSibling(Task priorSibling) {
this.mPriorSibling = priorSibling;
}
// 设置任务的父任务列表
public void setParent(TaskList parent) {
this.mParent = parent;
}
// 获取任务是否完成
public boolean getCompleted() {
return this.mCompleted;
}
// 获取任务的备注信息
public String getNotes() {
return this.mNotes;
}
// 获取任务的前一个同级任务
public Task getPriorSibling() {
return this.mPriorSibling;
}
// 获取任务的父任务列表
public TaskList getParent() {
return this.mParent;
}
}

@ -1,17 +1,17 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* (c) 2010-2011The MiCode (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
* Apache2.0("许可证");
* 使
*
*
* 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;
@ -43,6 +43,12 @@ public class TaskList extends Node {
mIndex = 1;
}
/**
*
*
* @param actionId ID
* @return JSON
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -74,6 +80,12 @@ public class TaskList extends Node {
return js;
}
/**
*
*
* @param actionId ID
* @return JSON
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -103,6 +115,11 @@ public class TaskList extends Node {
return js;
}
/**
* JSON
*
* @param js JSON
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -129,6 +146,11 @@ public class TaskList extends Node {
}
}
/**
* JSON
*
* @param js JSON
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
@ -157,6 +179,11 @@ public class TaskList extends Node {
}
}
/**
* JSON
*
* @return JSON
*/
public JSONObject getLocalJSONFromContent() {
try {
JSONObject js = new JSONObject();
@ -183,28 +210,34 @@ public class TaskList extends Node {
}
}
/**
*
*
* @param c
* @return
*/
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
if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
Log.e(TAG, "gtask id doesn't match");
Log.e(TAG, "gtask id不匹配");
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;
}
}
@ -216,16 +249,27 @@ public class TaskList extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
*
* @return
*/
public int getChildTaskCount() {
return mChildren.size();
}
/**
*
*
* @param task
* @return
*/
public boolean addChildTask(Task task) {
boolean ret = false;
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);
@ -234,9 +278,16 @@ public class TaskList extends Node {
return ret;
}
/**
*
*
* @param task
* @param index
* @return
*/
public boolean addChildTask(Task task, int index) {
if (index < 0 || index > mChildren.size()) {
Log.e(TAG, "add child task: invalid index");
Log.e(TAG, "添加子任务:无效的索引");
return false;
}
@ -244,7 +295,7 @@ public class TaskList extends Node {
if (task != null && pos == -1) {
mChildren.add(index, task);
// update the task list
// 更新任务列表
Task preTask = null;
Task afterTask = null;
if (index != 0)
@ -260,6 +311,12 @@ public class TaskList extends Node {
return true;
}
/**
*
*
* @param task
* @return
*/
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task);
@ -267,11 +324,11 @@ public class TaskList extends Node {
ret = mChildren.remove(task);
if (ret) {
// reset prior sibling and parent
// 重置前一个兄弟和父对象
task.setPriorSibling(null);
task.setParent(null);
// update the task list
// 更新任务列表
if (index != mChildren.size()) {
mChildren.get(index).setPriorSibling(
index == 0 ? null : mChildren.get(index - 1));
@ -281,16 +338,23 @@ public class TaskList extends Node {
return ret;
}
/**
*
*
* @param task
* @param index
* @return
*/
public boolean moveChildTask(Task task, int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "move child task: invalid index");
Log.e(TAG, "移动子任务:无效的索引");
return false;
}
int pos = mChildren.indexOf(task);
if (pos == -1) {
Log.e(TAG, "move child task: the task should in the list");
Log.e(TAG, "移动子任务:任务应在列表中");
return false;
}
@ -299,6 +363,12 @@ public class TaskList extends Node {
return (removeChildTask(task) && addChildTask(task, index));
}
/**
* GID
*
* @param gid GID
* @return
*/
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
@ -309,18 +379,36 @@ public class TaskList extends Node {
return null;
}
/**
*
*
* @param task
* @return
*/
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
/**
*
*
* @param index
* @return
*/
public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index");
Log.e(TAG, "根据索引获取任务:无效的索引");
return null;
}
return mChildren.get(index);
}
/**
* GID
*
* @param gid GID
* @return
*/
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
if (task.getGid().equals(gid))
@ -329,14 +417,29 @@ public class TaskList extends Node {
return null;
}
/**
*
*
* @return
*/
public ArrayList<Task> getChildTaskList() {
return this.mChildren;
}
/**
*
*
* @param index
*/
public void setIndex(int index) {
this.mIndex = index;
}
/**
*
*
* @return
*/
public int getIndex() {
return this.mIndex;
}

@ -1,4 +1,5 @@
/*
<<<<<<< HEAD
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -12,21 +13,64 @@
* 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.
=======
* (c) 2010-2011The MiCode (www.micode.net)
*
* Apache 2.0
* 使
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
*
*
>>>>>>> whj_branch
*/
package net.micode.notes.gtask.exception;
<<<<<<< HEAD
public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L;
=======
/**
*
*/
public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L;
/**
* ActionFailureException
*/
>>>>>>> whj_branch
public ActionFailureException() {
super();
}
<<<<<<< HEAD
=======
/**
* 使 ActionFailureException
*
* @param paramString
*/
>>>>>>> whj_branch
public ActionFailureException(String paramString) {
super(paramString);
}
<<<<<<< HEAD
=======
/**
* 使 ActionFailureException
*
* @param paramString
* @param paramThrowable
*/
>>>>>>> whj_branch
public ActionFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable);
}

@ -1,4 +1,5 @@
/*
<<<<<<< HEAD
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -12,21 +13,64 @@
* 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.
=======
* (c) 2010-2011The MiCode (www.micode.net)
*
* Apache 2.0
* 使
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
*
*
>>>>>>> whj_branch
*/
package net.micode.notes.gtask.exception;
<<<<<<< HEAD
public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L;
=======
/**
*
*/
public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L;
/**
* NetworkFailureException
*/
>>>>>>> whj_branch
public NetworkFailureException() {
super();
}
<<<<<<< HEAD
=======
/**
* 使 NetworkFailureException
*
* @param paramString
*/
>>>>>>> whj_branch
public NetworkFailureException(String paramString) {
super(paramString);
}
<<<<<<< HEAD
=======
/**
* 使 NetworkFailureException
*
* @param paramString
* @param paramThrowable
*/
>>>>>>> whj_branch
public NetworkFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable);
}

@ -1,3 +1,4 @@
<<<<<<< HEAD
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
@ -13,6 +14,21 @@
* 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.
=======
/*
* (c) 2010-2011The MiCode (www.micode.net)
*
* Apache 2.0
* 使
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
*
*
>>>>>>> whj_branch
*/
package net.micode.notes.gtask.remote;
@ -28,15 +44,26 @@ import net.micode.notes.R;
import net.micode.notes.ui.NotesListActivity;
import net.micode.notes.ui.NotesPreferenceActivity;
<<<<<<< HEAD
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;
=======
// 异步任务用于执行与 GTask 同步相关的操作
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
// GTask 同步通知的 ID
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;
// 定义接口,用于在任务完成时通知调用者
>>>>>>> whj_branch
public interface OnCompleteListener {
void onComplete();
}
<<<<<<< HEAD
private Context mContext;
private NotificationManager mNotifiManager;
@ -53,10 +80,27 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
mTaskManager = GTaskManager.getInstance();
}
=======
private Context mContext; // 上下文对象
private NotificationManager mNotifiManager; // 通知管理器对象
private GTaskManager mTaskManager; // GTask 管理器对象
private OnCompleteListener mOnCompleteListener; // 完成监听器对象
// 构造函数,接收上下文和完成监听器对象作为参数
public GTaskASyncTask(Context context, OnCompleteListener listener) {
mContext = context;
mOnCompleteListener = listener;
mNotifiManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mTaskManager = GTaskManager.getInstance();
}
// 取消同步任务
>>>>>>> whj_branch
public void cancelSync() {
mTaskManager.cancelSync();
}
<<<<<<< HEAD
public void publishProgess(String message) {
publishProgress(new String[] {
message
@ -114,11 +158,55 @@ private void showNotification(int tickerId, String content) {
@Override
protected void onProgressUpdate(String... progress) {
showNotification(R.string.ticker_syncing, progress[0]);
=======
// 更新进度信息
public void publishProgess(String message) {
publishProgress(new String[] { message });
}
// 显示通知
private void showNotification(int tickerId, String content) {
PendingIntent pendingIntent;
if (tickerId != R.string.ticker_success) {
// 如果同步失败,则跳转到偏好设置界面
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, NotesPreferenceActivity.class), PendingIntent.FLAG_IMMUTABLE);
} else {
// 如果同步成功,则跳转到笔记列表界面
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, NotesListActivity.class), PendingIntent.FLAG_IMMUTABLE);
}
Notification.Builder builder = new Notification.Builder(mContext)
.setAutoCancel(true)
.setContentTitle(mContext.getString(R.string.app_name))
.setContentText(content)
.setContentIntent(pendingIntent)
.setWhen(System.currentTimeMillis())
.setOngoing(true);
Notification notification = builder.build();
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
}
// 执行后台任务,进行 GTask 同步
@Override
protected Integer doInBackground(Void... unused) {
// 发布登录进度信息
publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity.getSyncAccountName(mContext)));
// 执行 GTask 同步操作,并返回结果状态码
return mTaskManager.sync(mContext, this);
}
// 更新任务进度
@Override
protected void onProgressUpdate(String... progress) {
// 显示同步通知
showNotification(R.string.ticker_syncing, progress[0]);
// 如果上下文是 GTaskSyncService 类型,则发送广播
>>>>>>> whj_branch
if (mContext instanceof GTaskSyncService) {
((GTaskSyncService) mContext).sendBroadcast(progress[0]);
}
}
<<<<<<< HEAD
@Override
protected void onPostExecute(Integer result) {
if (result == GTaskManager.STATE_SUCCESS) {
@ -136,10 +224,37 @@ private void showNotification(int tickerId, String content) {
if (mOnCompleteListener != null) {
new Thread(new Runnable() {
=======
// 后台任务执行完成后调用,根据结果状态码显示相应的通知,并通知完成监听器
@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() {
>>>>>>> whj_branch
public void run() {
mOnCompleteListener.onComplete();
}
}).start();
}
}
<<<<<<< HEAD
}
=======
}
>>>>>>> whj_branch

Loading…
Cancel
Save