Compare commits

..

No commits in common. 'master' and 'ranhao_branch' have entirely different histories.

@ -21,5 +21,4 @@ public class MainActivity extends AppCompatActivity {
return insets;
});
}
}
}

@ -25,17 +25,10 @@ import android.util.Log;
import java.util.HashMap;
/**
*
**/
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 "
@ -43,52 +36,38 @@ public class Contact {
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
/**
*
* @param context
* @param phoneNumber
* @return null
*/
public static String getContact(Context context, String phoneNumber) {
if( sContactCache == null) {
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
// 先从缓存中查找,如果存在则直接返回,避免重复查询数据库
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
// 如果缓存中不存在,则执行数据库查询
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
// 执行查询操作,返回一个游标对象
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI, // 查询的URI
new String [] { Phone.DISPLAY_NAME }, // 返回的列名:联系人显示名称
selection, // 查询条件
new String[] { phoneNumber }, // 查询参数
null); // 排序方式
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
selection,
new String[] { phoneNumber },
null);
// 处理查询结果
if (cursor != null && cursor.moveToFirst()) {
try {
// 获取查询结果中的联系人姓名
String name = cursor.getString(0);
// 将结果存入缓存,供下次查询使用
sContactCache.put(phoneNumber, name);
return name;
} catch (IndexOutOfBoundsException e) {
// 处理索引越界异常,记录错误日志
Log.e(TAG, " Cursor get string error " + e.toString());
return null;
} finally {
// 确保游标被正确关闭,释放资源
cursor.close();
}
} else {
// 未查询到匹配的联系人,记录调试日志
Log.d(TAG, "No contact matched with number:" + phoneNumber);
return null;
}
}
}
}

@ -17,142 +17,50 @@
package net.micode.notes.data;
import android.net.Uri;
/**
* 便URI
* 广
*/
public class Notes {
/**
* ContentProviderURI
*/
public static final String AUTHORITY = "micode_notes";
/**
*
*/
public static final String TAG = "Notes";
/**
*
*/
public static final int TYPE_NOTE = 0;
/**
*
*/
public static final int TYPE_FOLDER = 1;
/**
*
*/
public static final int TYPE_SYSTEM = 2;
/**
* ID
*/
/**
* ID
* 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
*/
public static final int ID_ROOT_FOLDER = 0;
/**
* ID
*/
public static final int ID_TEMPARAY_FOLDER = -1;
/**
* ID
*/
public static final int ID_CALL_RECORD_FOLDER = -2;
/**
* ID
*/
public static final int ID_TRASH_FOLER = -3;
/**
* Intent
*/
/**
*
*/
public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date";
/**
* ID
*/
public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id";
/**
* ID
*/
public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_id";
/**
*
*/
public static final String INTENT_EXTRA_WIDGET_TYPE = "net.micode.notes.widget_type";
/**
* ID
*/
public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id";
/**
*
*/
public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date";
/**
*
*/
/**
*
*/
public static final int TYPE_WIDGET_INVALIDE = -1;
/**
* 2x
*/
public static final int TYPE_WIDGET_2X = 0;
/**
* 4x
*/
public static final int TYPE_WIDGET_4X = 1;
/**
* MIME
*/
public static class DataConstants {
/**
* MIME
*/
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
/**
* MIME
*/
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
}
/**
* Uri
* Uri to query all notes and folders
*/
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
/**
* Uri
* Uri to query data
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
/**
*
*/
public interface NoteColumns {
/**
* The unique ID for a row
@ -259,9 +167,6 @@ public class Notes {
public static final String VERSION = "version";
}
/**
*
*/
public interface DataColumns {
/**
* The unique ID for a row
@ -336,9 +241,6 @@ public class Notes {
public static final String DATA5 = "data5";
}
/**
* DataColumns
*/
public static final class TextNote implements DataColumns {
/**
* Mode to indicate the text in check list mode or not
@ -354,10 +256,7 @@ public class Notes {
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
}
/**
* DataColumns
*/
public static final class CallNote implements DataColumns {
/**
* Call date for this record

@ -27,44 +27,19 @@ import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
/**
*
*
*/
public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
*
*/
private static final String DB_NAME = "note.db";
/**
*
*/
private static final int DB_VERSION = 4;
/**
*
*/
public interface TABLE {
/**
*
*/
public static final String NOTE = "note";
/**
*
*/
public static final String DATA = "data";
}
/**
*
*/
private static final String TAG = "NotesDatabaseHelper";
/**
*
*/
private static NotesDatabaseHelper mInstance;
private static final String CREATE_NOTE_TABLE_SQL =
@ -231,34 +206,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";
/**
*
* @param context
*/
public NotesDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
/**
*
* @param db
*/
public void createNoteTable(SQLiteDatabase db) {
// 执行创建表SQL
db.execSQL(CREATE_NOTE_TABLE_SQL);
// 重新创建笔记表相关触发器
reCreateNoteTableTriggers(db);
// 创建系统文件夹
createSystemFolder(db);
Log.d(TAG, "note table has been created");
}
/**
*
* @param db
*/
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
// 删除旧触发器(如果存在)
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_delete");
@ -267,7 +226,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete");
db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash");
// 创建新触发器
db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);
db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);
db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER);
@ -277,10 +235,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
}
/**
*
* @param db
*/
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
@ -316,24 +270,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
}
/**
*
* @param db
*/
public void createDataTable(SQLiteDatabase db) {
// 执行创建表SQL
db.execSQL(CREATE_DATA_TABLE_SQL);
// 重新创建数据表相关触发器
reCreateDataTableTriggers(db);
// 创建note_id索引
db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);
Log.d(TAG, "data table has been created");
}
/**
*
* @param db
*/
private void reCreateDataTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update");
@ -344,11 +287,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
}
/**
*
* @param context
* @return
*/
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
@ -356,24 +294,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
return mInstance;
}
/**
*
* @param db
*/
@Override
public void onCreate(SQLiteDatabase db) {
// 创建笔记表
createNoteTable(db);
// 创建数据表
createDataTable(db);
}
/**
*
* @param db
* @param oldVersion
* @param newVersion
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
boolean reCreateTriggers = false;
@ -407,10 +333,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
}
/**
* 2
* @param db
*/
private void upgradeToV2(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA);
@ -418,10 +340,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
createDataTable(db);
}
/**
* 3
* @param db
*/
private void upgradeToV3(SQLiteDatabase db) {
// drop unused triggers
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert");
@ -437,10 +355,6 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
}
/**
* 4
* @param db
*/
private void upgradeToV4(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
+ " INTEGER NOT NULL DEFAULT 0");

@ -35,74 +35,35 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
/**
* ContentProvider
* CRUD使UriMatcherURI
* ContentResolver
*/
public class NotesProvider extends ContentProvider {
/**
* UriURI
*/
private static final UriMatcher mMatcher;
/**
*
*/
private NotesDatabaseHelper mHelper;
/**
*
*/
private static final String TAG = "NotesProvider";
/**
* URI
*/
private static final int URI_NOTE = 1;
/**
* URI
*/
private static final int URI_NOTE_ITEM = 2;
/**
* URI
*/
private static final int URI_DATA = 3;
/**
* URI
*/
private static final int URI_DATA_ITEM = 4;
/**
* URI
*/
private static final int URI_SEARCH = 5;
/**
* URI
*/
private static final int URI_SEARCH_SUGGEST = 6;
/**
* UriMatcher
*/
static {
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
// 添加URI匹配规则
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE); // content://micode_notes/note
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM); // content://micode_notes/note/1
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA); // content://micode_notes/data
mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM); // content://micode_notes/data/1
mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH); // content://micode_notes/search
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST); // 搜索建议
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST); // 带参数的搜索建议
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);
mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH);
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST);
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 + ","
@ -112,35 +73,18 @@ public class NotesProvider extends ContentProvider {
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
/**
*
*/
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;
/**
* ContentProvider
* @return
*/
@Override
public boolean onCreate() {
// 获取数据库帮助类实例
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
}
/**
*
* @param uri URI
* @param projection
* @param selection
* @param selectionArgs
* @param sortOrder
* @return
*/
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
@ -203,12 +147,6 @@ public class NotesProvider extends ContentProvider {
return c;
}
/**
*
* @param uri URI
* @param values
* @return URI
*/
@Override
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase db = mHelper.getWritableDatabase();
@ -243,13 +181,6 @@ public class NotesProvider extends ContentProvider {
return ContentUris.withAppendedId(uri, insertedId);
}
/**
*
* @param uri URI
* @param selection
* @param selectionArgs
* @return
*/
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
@ -296,14 +227,6 @@ public class NotesProvider extends ContentProvider {
return count;
}
/**
*
* @param uri URI
* @param values
* @param selection
* @param selectionArgs
* @return
*/
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int count = 0;
@ -344,21 +267,10 @@ public class NotesProvider extends ContentProvider {
return count;
}
/**
*
* @param selection
* @return
*/
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
/**
*
* @param id ID
* @param selection
* @param selectionArgs
*/
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
@ -384,11 +296,6 @@ public class NotesProvider extends ContentProvider {
mHelper.getWritableDatabase().execSQL(sql.toString());
}
/**
* MIME
* @param uri URI
* @return MIME
*/
@Override
public String getType(Uri uri) {
// TODO Auto-generated method stub

@ -25,65 +25,33 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
* MetaData - TaskGTask
*
* GTaskGTaskID
* Task
*/
public class MetaData extends Task {
private final static String TAG = MetaData.class.getSimpleName();
// 与当前元数据关联的GTask ID
private String mRelatedGid = null;
/**
*
*
* @param gid GTask ID
* @param metaInfo JSON
*/
public void setMeta(String gid, JSONObject metaInfo) {
try {
// 将GTask ID添加到元数据中
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
Log.e(TAG, "failed to put related gid");
}
// 将元数据以字符串形式存储到Task的notes字段中
setNotes(metaInfo.toString());
// 设置元数据任务的名称
setName(GTaskStringUtils.META_NOTE_NAME);
}
/**
* GTask ID
*
* @return GTask ID
*/
public String getRelatedGid() {
return mRelatedGid;
}
/**
*
*
* @return notestruefalse
*/
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
/**
* JSON
*
* @param js JSON
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
// 如果有notes内容则解析获取关联的GTask ID
if (getNotes() != null) {
try {
JSONObject metaInfo = new JSONObject(getNotes().trim());
@ -95,40 +63,19 @@ public class MetaData extends Task {
}
}
/**
* JSON -
*
* @param js JSON
* @throws IllegalAccessError
*/
@Override
public void setContentByLocalJSON(JSONObject js) {
// 元数据不支持从本地JSON设置内容
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
/**
* JSON -
*
* @return JSON
* @throws IllegalAccessError
*/
@Override
public JSONObject getLocalJSONFromContent() {
// 元数据不支持获取本地JSON对象
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
/**
* -
*
* @param c
* @return
* @throws IllegalAccessError
*/
@Override
public int getSyncAction(Cursor c) {
// 元数据不支持获取同步操作类型
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}

@ -20,81 +20,33 @@ import android.database.Cursor;
import org.json.JSONObject;
/**
* Node - GTask
*
* TaskListTaskMetaData
* GTask
*/
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;
/**
* Google TasksID
*/
private String mGid;
/**
*
*/
private String mName;
/**
*
*/
private long mLastModified;
/**
*
*/
private boolean mDeleted;
/**
* -
*/
public Node() {
mGid = null;
mName = "";
@ -102,119 +54,46 @@ public abstract class Node {
mDeleted = false;
}
/**
* JSON
*
* @param actionId ID
* @return JSON
*/
public abstract JSONObject getCreateAction(int actionId);
/**
* JSON
*
* @param actionId ID
* @return JSON
*/
public abstract JSONObject getUpdateAction(int actionId);
/**
* JSON
*
* @param js Google TasksJSON
*/
public abstract void setContentByRemoteJSON(JSONObject js);
/**
* JSON
*
* @param js JSON
*/
public abstract void setContentByLocalJSON(JSONObject js);
/**
* JSON
*
* @return JSON
*/
public abstract JSONObject getLocalJSONFromContent();
/**
*
*
* @param c
* @return 使SYNC_ACTION_*
*/
public abstract int getSyncAction(Cursor c);
/**
* Google TasksID
*
* @param gid ID
*/
public void setGid(String gid) {
this.mGid = gid;
}
/**
*
*
* @param name
*/
public void setName(String name) {
this.mName = name;
}
/**
*
*
* @param lastModified
*/
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
/**
*
*
* @param deleted
*/
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
/**
* Google TasksID
*
* @return ID
*/
public String getGid() {
return this.mGid;
}
/**
*
*
* @return
*/
public String getName() {
return this.mName;
}
/**
*
*
* @return
*/
public long getLastModified() {
return this.mLastModified;
}
/**
*
*
* @return
*/
public boolean getDeleted() {
return this.mDeleted;
}

@ -35,101 +35,42 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
* SqlData - SQLNotes
*
*
* 1. IDMIME
* 2. CursorJSON
* 3. 使ContentValues
* 4.
*/
public class SqlData {
private static final String TAG = SqlData.class.getSimpleName();
/**
* IDID
*/
private static final int INVALID_ID = -99999;
/**
*
*/
public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3
};
/**
* PROJECTION_DATAID
*/
public static final int DATA_ID_COLUMN = 0;
/**
* PROJECTION_DATAMIME
*/
public static final int DATA_MIME_TYPE_COLUMN = 1;
/**
* PROJECTION_DATA
*/
public static final int DATA_CONTENT_COLUMN = 2;
/**
* PROJECTION_DATADATA1
*/
public static final int DATA_CONTENT_DATA_1_COLUMN = 3;
/**
* PROJECTION_DATADATA3
*/
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
/**
* 访Android ContentProviderContentResolver
*/
private ContentResolver mContentResolver;
/**
*
*/
private boolean mIsCreate;
/**
*
*/
private long mDataId;
/**
* MIME
*/
private String mDataMimeType;
/**
*
*/
private String mDataContent;
/**
* 1
*/
private long mDataContentData1;
/**
* 3
*/
private String mDataContentData3;
/**
* ContentValues
*/
private ContentValues mDiffDataValues;
/**
* - SqlData
*
* @param context ContentResolver
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -141,12 +82,6 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/**
* - CursorSqlData
*
* @param context ContentResolver
* @param c Cursor
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -154,11 +89,6 @@ public class SqlData {
mDiffDataValues = new ContentValues();
}
/**
* Cursor
*
* @param c Cursor
*/
private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
@ -167,12 +97,6 @@ public class SqlData {
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
/**
* JSON
*
* @param js JSON
* @throws JSONException JSON
*/
public void setContent(JSONObject js) throws JSONException {
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
if (mIsCreate || mDataId != dataId) {
@ -206,12 +130,6 @@ public class SqlData {
mDataContentData3 = dataContentData3;
}
/**
* JSON
*
* @return JSON
* @throws JSONException JSON
*/
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
@ -226,14 +144,6 @@ public class SqlData {
return js;
}
/**
*
*
* @param noteId ID
* @param validateVersion
* @param version
* @throws ActionFailureException
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
@ -273,11 +183,6 @@ public class SqlData {
mIsCreate = false;
}
/**
* ID
*
* @return
*/
public long getId() {
return mDataId;
}

@ -38,19 +38,11 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* SqlNote -
*
* GTask
* CursorJSON
*/
public class SqlNote {
private static final String TAG = SqlNote.class.getSimpleName();
// 无效ID常量用于初始化和验证
private static final int INVALID_ID = -99999;
// 笔记查询投影数组,定义了从数据库查询笔记时返回的列
public static final String[] PROJECTION_NOTE = new String[] {
NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE,
@ -60,154 +52,139 @@ public class SqlNote {
NoteColumns.VERSION
};
// 投影数组中各列的索引常量定义
public static final int ID_COLUMN = 0;
public static final int ALERTED_DATE_COLUMN = 1;
public static final int BG_COLOR_ID_COLUMN = 2;
public static final int CREATED_DATE_COLUMN = 3;
public static final int HAS_ATTACHMENT_COLUMN = 4;
public static final int MODIFIED_DATE_COLUMN = 5;
public static final int NOTES_COUNT_COLUMN = 6;
public static final int PARENT_ID_COLUMN = 7;
public static final int SNIPPET_COLUMN = 8;
public static final int TYPE_COLUMN = 9;
public static final int WIDGET_ID_COLUMN = 10;
public static final int WIDGET_TYPE_COLUMN = 11;
public static final int SYNC_ID_COLUMN = 12;
public static final int LOCAL_MODIFIED_COLUMN = 13;
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
public static final int GTASK_ID_COLUMN = 15;
public static final int VERSION_COLUMN = 16;
// 上下文对象,用于访问系统服务
private Context mContext;
// 内容解析器用于与ContentProvider交互
private ContentResolver mContentResolver;
// 是否为新创建的笔记
private boolean mIsCreate;
// 笔记ID
private long mId;
// 提醒日期
private long mAlertDate;
// 背景颜色ID
private int mBgColorId;
// 创建日期
private long mCreatedDate;
// 是否有附件
private int mHasAttachment;
// 修改日期
private long mModifiedDate;
// 父文件夹ID
private long mParentId;
// 笔记摘要
private String mSnippet;
// 笔记类型(普通笔记、文件夹等)
private int mType;
// 小部件ID
private int mWidgetId;
// 小部件类型
private int mWidgetType;
// 原始父文件夹ID
private long mOriginParent;
// 版本号,用于并发控制
private long mVersion;
// 差异内容值,用于记录需要更新的字段
private ContentValues mDiffNoteValues;
// 私有成员变量用于存储SqlData类型的数据列表
// 使用ArrayList作为数据结构可以动态存储SqlData对象
private ArrayList<SqlData> mDataList;
/**
*
*
* @param context 访
*/
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = true; // 标记为新创建的笔记
mId = INVALID_ID; // 初始化为无效ID
mAlertDate = 0; // 无提醒日期
mBgColorId = ResourceParser.getDefaultBgId(context); // 使用默认背景颜色
mCreatedDate = System.currentTimeMillis(); // 创建日期设为当前时间
mHasAttachment = 0; // 初始没有附件
mModifiedDate = System.currentTimeMillis(); // 修改日期设为当前时间
mParentId = 0; // 默认父文件夹ID为0
mSnippet = ""; // 摘要为空
mType = Notes.TYPE_NOTE; // 默认类型为普通笔记
mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; // 无效小部件ID
mWidgetType = Notes.TYPE_WIDGET_INVALIDE; // 无效小部件类型
mOriginParent = 0; // 原始父文件夹ID
mVersion = 0; // 初始版本号
mDiffNoteValues = new ContentValues(); // 用于记录差异的内容值
mDataList = new ArrayList<SqlData>(); // 初始化数据列表
mIsCreate = true;
mId = INVALID_ID;
mAlertDate = 0;
mBgColorId = ResourceParser.getDefaultBgId(context);
mCreatedDate = System.currentTimeMillis();
mHasAttachment = 0;
mModifiedDate = System.currentTimeMillis();
mParentId = 0;
mSnippet = "";
mType = Notes.TYPE_NOTE;
mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
mOriginParent = 0;
mVersion = 0;
mDiffNoteValues = new ContentValues();
mDataList = new ArrayList<SqlData>();
}
/**
* CursorSqlNote
*
* @param context
* @param c Cursor
*/
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = false; // 标记为已存在的笔记
loadFromCursor(c); // 从Cursor加载数据
mDataList = new ArrayList<SqlData>(); // 初始化数据列表
if (mType == Notes.TYPE_NOTE) // 如果是普通笔记,加载其数据内容
mIsCreate = false;
loadFromCursor(c);
mDataList = new ArrayList<SqlData>();
if (mType == Notes.TYPE_NOTE)
loadDataContent();
mDiffNoteValues = new ContentValues(); // 用于记录差异的内容值
mDiffNoteValues = new ContentValues();
}
/**
* IDSqlNote
*
* @param context
* @param id ID
*/
public SqlNote(Context context, long id) {
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = false; // 标记为已存在的笔记
loadFromCursor(id); // 根据ID从数据库加载数据
mDataList = new ArrayList<SqlData>(); // 初始化数据列表
if (mType == Notes.TYPE_NOTE) // 如果是普通笔记,加载其数据内容
mIsCreate = false;
loadFromCursor(id);
mDataList = new ArrayList<SqlData>();
if (mType == Notes.TYPE_NOTE)
loadDataContent();
mDiffNoteValues = new ContentValues(); // 用于记录差异的内容值
mDiffNoteValues = new ContentValues();
}
/**
* ID
*
* @param id ID
*/
private void loadFromCursor(long id) {
Cursor c = null;
try {
// 查询指定ID的笔记数据
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
new String[] {
String.valueOf(id)
}, null);
if (c != null) {
c.moveToNext();
loadFromCursor(c); // 调用Cursor版本的loadFromCursor方法
loadFromCursor(c);
} else {
Log.w(TAG, "loadFromCursor: cursor = null");
}
} finally {
if (c != null)
c.close(); // 确保Cursor被关闭
c.close();
}
}
/**
* Cursor
*
* @param c Cursor
*/
private void loadFromCursor(Cursor c) {
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
@ -223,16 +200,10 @@ public class SqlNote {
mVersion = c.getLong(VERSION_COLUMN);
}
/**
*
*
* mDataList
*/
private void loadDataContent() {
Cursor c = null;
mDataList.clear(); // 清空现有数据列表
mDataList.clear();
try {
// 查询与当前笔记ID关联的所有数据项
c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
"(note_id=?)", new String[] {
String.valueOf(mId)
@ -242,7 +213,6 @@ public class SqlNote {
Log.w(TAG, "it seems that the note has not data");
return;
}
// 遍历Cursor创建SqlData对象并添加到数据列表
while (c.moveToNext()) {
SqlData data = new SqlData(mContext, c);
mDataList.add(data);
@ -252,25 +222,17 @@ public class SqlNote {
}
} finally {
if (c != null)
c.close(); // 确保Cursor被关闭
c.close();
}
}
/**
* JSON
*
* @param js JSON
* @return
*/
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)) {
@ -285,10 +247,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) {
mDiffNoteValues.put(NoteColumns.ID, id);
@ -372,12 +331,9 @@ public class SqlNote {
}
mOriginParent = originParent;
// 处理笔记关联的数据项
for (int i = 0; i < dataArray.length(); i++) {
JSONObject data = dataArray.getJSONObject(i);
SqlData sqlData = null;
// 尝试在现有数据列表中找到匹配的SqlData对象
if (data.has(DataColumns.ID)) {
long dataId = data.getLong(DataColumns.ID);
for (SqlData temp : mDataList) {
@ -387,13 +343,11 @@ public class SqlNote {
}
}
// 如果找不到匹配的SqlData对象则创建新的
if (sqlData == null) {
sqlData = new SqlData(mContext);
mDataList.add(sqlData);
}
// 设置SqlData的内容
sqlData.setContent(data);
}
}
@ -405,26 +359,17 @@ public class SqlNote {
return true;
}
/**
* JSON
*
* @return JSONnull
*/
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
// 如果是新创建的笔记(尚未保存到数据库),则无法获取内容
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
return null;
}
JSONObject note = new JSONObject();
// 根据笔记类型构建不同的JSON结构
if (mType == Notes.TYPE_NOTE) {
// 普通笔记类型,包含完整的笔记信息和关联数据
note.put(NoteColumns.ID, mId);
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
note.put(NoteColumns.BG_COLOR_ID, mBgColorId);
@ -439,7 +384,6 @@ public class SqlNote {
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
// 添加关联的数据项
JSONArray dataArray = new JSONArray();
for (SqlData sqlData : mDataList) {
JSONObject data = sqlData.getContent();
@ -449,7 +393,6 @@ public class SqlNote {
}
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {
// 文件夹或系统类型,只包含基本信息
note.put(NoteColumns.ID, mId);
note.put(NoteColumns.TYPE, mType);
note.put(NoteColumns.SNIPPET, mSnippet);
@ -464,97 +407,48 @@ public class SqlNote {
return null;
}
/**
* ID
*
* @param id ID
*/
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
/**
* GTask ID
*
* @param gid GTask ID
*/
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
/**
* ID
*
* @param syncId ID
*/
public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
}
/**
*
*
* 0
*/
public void resetLocalModified() {
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
}
/**
* ID
*
* @return ID
*/
public long getId() {
return mId;
}
/**
* ID
*
* @return ID
*/
public long getParentId() {
return mParentId;
}
/**
*
*
* @return
*/
public String getSnippet() {
return mSnippet;
}
/**
*
*
* @return
*/
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
/**
*
*
* @param validateVersion
* @throws ActionFailureException
* @throws IllegalStateException ID
*/
public void commit(boolean validateVersion) {
if (mIsCreate) {
// 新创建的笔记,执行插入操作
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
mDiffNoteValues.remove(NoteColumns.ID); // 移除无效ID
mDiffNoteValues.remove(NoteColumns.ID);
}
// 插入笔记到数据库
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
try {
mId = Long.valueOf(uri.getPathSegments().get(1)); // 获取自动生成的ID
mId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
throw new ActionFailureException("create note failed");
@ -563,29 +457,27 @@ 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");
}
if (mDiffNoteValues.size() > 0) {
mVersion ++; // 版本号递增
mVersion ++;
int result = 0;
if (!validateVersion) {
// 不验证版本,直接更新
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?)", new String[] {
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?)", new String[] {
String.valueOf(mId)
});
} else {
// 验证版本,防止并发更新冲突
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
new String[] {
String.valueOf(mId), String.valueOf(mVersion)
});
@ -595,7 +487,6 @@ public class SqlNote {
}
}
// 如果是普通笔记,提交其关联的数据
if (mType == Notes.TYPE_NOTE) {
for (SqlData sqlData : mDataList) {
sqlData.commit(mId, validateVersion, mVersion);
@ -603,12 +494,11 @@ public class SqlNote {
}
}
// 刷新本地信息,确保与数据库一致
// refresh local info
loadFromCursor(mId);
if (mType == Notes.TYPE_NOTE)
loadDataContent();
// 清空差异内容值并标记为已存在
mDiffNoteValues.clear();
mIsCreate = false;
}

@ -32,47 +32,19 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
* Task - NodeGTask
*
*
* 1.
* 2.
* 3. GTask
* 4. JSON
* 5.
*/
public class Task extends Node {
private static final String TAG = Task.class.getSimpleName();
/**
*
*/
private boolean mCompleted;
/**
*
*/
private String mNotes;
/**
* JSON
*/
private JSONObject mMetaInfo;
/**
*
*/
private Task mPriorSibling;
/**
*
*/
private TaskList mParent;
/**
* -
*/
public Task() {
super();
mCompleted = false;
@ -82,13 +54,6 @@ public class Task extends Node {
mMetaInfo = null;
}
/**
* JSON
*
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -138,13 +103,6 @@ public class Task extends Node {
return js;
}
/**
* JSON
*
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -177,12 +135,6 @@ public class Task extends Node {
return js;
}
/**
* JSON
*
* @param js Google TasksJSON
* @throws ActionFailureException JSON
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -223,11 +175,6 @@ public class Task extends Node {
}
}
/**
* JSON
*
* @param js JSON
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
@ -257,11 +204,6 @@ public class Task extends Node {
}
}
/**
* JSON
*
* @return JSONnull
*/
public JSONObject getLocalJSONFromContent() {
String name = getName();
try {
@ -305,11 +247,6 @@ public class Task extends Node {
}
}
/**
*
*
* @param metaData MetaData
*/
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {
try {
@ -321,17 +258,6 @@ public class Task extends Node {
}
}
/**
*
*
* @param c
* @return
* - SYNC_ACTION_NONE:
* - SYNC_ACTION_UPDATE_LOCAL:
* - SYNC_ACTION_UPDATE_REMOTE:
* - SYNC_ACTION_UPDATE_CONFLICT:
* - SYNC_ACTION_ERROR:
*/
public int getSyncAction(Cursor c) {
try {
JSONObject noteInfo = null;
@ -385,84 +311,39 @@ public class Task extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
*
* @return truefalse
*/
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);
}
/**
*
*
* @param completed
*/
public void setCompleted(boolean completed) {
this.mCompleted = completed;
}
/**
*
*
* @param notes
*/
public void setNotes(String notes) {
this.mNotes = notes;
}
/**
*
*
* @param priorSibling
*/
public void setPriorSibling(Task priorSibling) {
this.mPriorSibling = priorSibling;
}
/**
*
*
* @param parent
*/
public void setParent(TaskList parent) {
this.mParent = parent;
}
/**
*
*
* @return
*/
public boolean getCompleted() {
return this.mCompleted;
}
/**
*
*
* @return
*/
public String getNotes() {
return this.mNotes;
}
/**
*
*
* @return
*/
public Task getPriorSibling() {
return this.mPriorSibling;
}
/**
*
*
* @return
*/
public TaskList getParent() {
return this.mParent;
}

@ -30,44 +30,19 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* TaskList - NodeTask
*
*
* 1. ID
* 2. Task
* 3. GTask
* 4. JSON
*/
public class TaskList extends Node {
private static final String TAG = TaskList.class.getSimpleName();
/**
* Google Tasks
*/
private int mIndex;
/**
* Task
*/
private ArrayList<Task> mChildren;
/**
* - Task1
*/
public TaskList() {
super();
mChildren = new ArrayList<Task>();
mIndex = 1;
}
/**
* JSON
*
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -99,13 +74,6 @@ public class TaskList extends Node {
return js;
}
/**
* JSON
*
* @param actionId ID
* @return JSON
* @throws ActionFailureException JSON
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -135,12 +103,6 @@ public class TaskList extends Node {
return js;
}
/**
* JSON
*
* @param js Google TasksJSON
* @throws ActionFailureException JSON
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -167,11 +129,6 @@ 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");
@ -200,11 +157,6 @@ public class TaskList extends Node {
}
}
/**
* JSON
*
* @return JSONnull
*/
public JSONObject getLocalJSONFromContent() {
try {
JSONObject js = new JSONObject();
@ -231,16 +183,6 @@ public class TaskList extends Node {
}
}
/**
*
*
* @param c
* @return
* - SYNC_ACTION_NONE:
* - SYNC_ACTION_UPDATE_LOCAL:
* - SYNC_ACTION_UPDATE_REMOTE:
* - SYNC_ACTION_ERROR:
*/
public int getSyncAction(Cursor c) {
try {
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
@ -274,21 +216,10 @@ 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)) {
@ -303,13 +234,6 @@ 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");
@ -336,12 +260,6 @@ public class TaskList extends Node {
return true;
}
/**
*
*
* @param task
* @return
*/
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task);
@ -363,13 +281,6 @@ 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()) {
@ -388,12 +299,6 @@ public class TaskList extends Node {
return (removeChildTask(task) && addChildTask(task, index));
}
/**
* Gid
*
* @param gid Gid
* @return Tasknull
*/
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
@ -404,22 +309,10 @@ public class TaskList extends Node {
return null;
}
/**
*
*
* @param task
* @return -1
*/
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
/**
*
*
* @param index
* @return Tasknull
*/
public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index");
@ -428,12 +321,6 @@ public class TaskList extends Node {
return mChildren.get(index);
}
/**
* GidfindChildTaskByGid
*
* @param gid Gid
* @return Tasknull
*/
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
if (task.getGid().equals(gid))
@ -442,29 +329,14 @@ public class TaskList extends Node {
return null;
}
/**
*
*
* @return ArrayList
*/
public ArrayList<Task> getChildTaskList() {
return this.mChildren;
}
/**
*
*
* @param index
*/
public void setIndex(int index) {
this.mIndex = index;
}
/**
*
*
* @return
*/
public int getIndex() {
return this.mIndex;
}

@ -16,39 +16,17 @@
package net.micode.notes.gtask.exception;
/**
* ActionFailureException - RuntimeExceptionGTask
*
* GTask
*
*
* @author MiCode Open Source Community
*/
public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L;
/**
* ActionFailureException
*/
public ActionFailureException() {
super();
}
/**
* ActionFailureException
*
* @param paramString
*/
public ActionFailureException(String paramString) {
super(paramString);
}
/**
* ActionFailureException
*
* @param paramString
* @param paramThrowable
*/
public ActionFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable);
}

@ -16,39 +16,17 @@
package net.micode.notes.gtask.exception;
/**
* NetworkFailureException - ExceptionGTask
*
* GTaskGoogle Tasks
*
*
* @author MiCode Open Source Community
*/
public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L;
/**
* NetworkFailureException
*/
public NetworkFailureException() {
super();
}
/**
* NetworkFailureException
*
* @param paramString
*/
public NetworkFailureException(String paramString) {
super(paramString);
}
/**
* NetworkFailureException
*
* @param paramString
* @param paramThrowable IOException
*/
public NetworkFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable);
}

@ -29,35 +29,11 @@ import net.micode.notes.ui.NotesListActivity;
import net.micode.notes.ui.NotesPreferenceActivity;
/**
* GTaskASyncTask - AsyncTaskGoogle Tasks
*
* 线Google TasksUI线
*
* -
* -
* - 广
* -
* -
*
* @author MiCode Open Source Community
*/
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
/**
*
*/
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;
/**
* OnCompleteListener -
*
*
*/
public interface OnCompleteListener {
/**
*
*/
void onComplete();
}
@ -69,12 +45,6 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
private OnCompleteListener mOnCompleteListener;
/**
* GTaskASyncTask
*
* @param context
* @param listener
*/
public GTaskASyncTask(Context context, OnCompleteListener listener) {
mContext = context;
mOnCompleteListener = listener;
@ -83,36 +53,16 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
mTaskManager = GTaskManager.getInstance();
}
/**
*
*
* GTaskManagercancelSync
*/
public void cancelSync() {
mTaskManager.cancelSync();
}
/**
*
*
* UI线
*
* @param message
*/
public void publishProgess(String message) {
publishProgress(new String[] {
message
});
}
/**
*
*
*
*
* @param tickerId ID
* @param content
*/
private void showNotification(int tickerId, String content) {
// 1. 创建通知构建器(替代旧构造函数)
Notification.Builder builder = new Notification.Builder(mContext)
@ -144,14 +94,6 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
}
/**
* 线
*
* AsyncTask线Google Tasks
*
* @param unused 使
* @return GTaskManager
*/
@Override
protected Integer doInBackground(Void... unused) {
publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity
@ -159,13 +101,6 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
return mTaskManager.sync(mContext, this);
}
/**
* UI线
*
* 线publishProgressUI线
*
* @param progress
*/
@Override
protected void onProgressUpdate(String... progress) {
showNotification(R.string.ticker_syncing, progress[0]);
@ -174,13 +109,6 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
}
}
/**
* UI线
*
* 线doInBackgroundUI线
*
* @param result GTaskManager
*/
@Override
protected void onPostExecute(Integer result) {
if (result == GTaskManager.STATE_SUCCESS) {

@ -61,14 +61,6 @@ import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
/**
* GTaskClient - Google Tasks使
*
* Google Tasks
* HTTPJSONGoogle Tasks API
*
* @author MiCode Open Source Community
*/
public class GTaskClient {
private static final String TAG = GTaskClient.class.getSimpleName();
@ -110,14 +102,6 @@ public class GTaskClient {
mUpdateArray = null;
}
/**
* GTaskClient
*
* 线GTaskClient
*
*
* @return GTaskClient
*/
public static synchronized GTaskClient getInstance() {
if (mInstance == null) {
mInstance = new GTaskClient();
@ -125,16 +109,6 @@ public class GTaskClient {
return mInstance;
}
/**
* Google Tasks
*
* Googlecookie
*
*
*
* @param activity Activity
* @return truefalse
*/
public boolean login(Activity activity) {
// we suppose that the cookie would expire after 5 minutes
// then we need to re-login
@ -386,16 +360,6 @@ public class GTaskClient {
}
}
/**
* Google Tasks
*
* Google Tasks
* IDGID
*
* @param task
* @throws NetworkFailureException
* @throws ActionFailureException
*/
public void createTask(Task task) throws NetworkFailureException {
commitUpdate();
try {
@ -422,16 +386,6 @@ public class GTaskClient {
}
}
/**
* Google Tasks
*
* Google Tasks
* IDGID
*
* @param tasklist
* @throws NetworkFailureException
* @throws ActionFailureException
*/
public void createTaskList(TaskList tasklist) throws NetworkFailureException {
commitUpdate();
try {
@ -458,15 +412,6 @@ public class GTaskClient {
}
}
/**
*
*
* Google Tasks
*
*
* @throws NetworkFailureException
* @throws ActionFailureException
*/
public void commitUpdate() throws NetworkFailureException {
if (mUpdateArray != null) {
try {
@ -488,16 +433,6 @@ public class GTaskClient {
}
}
/**
*
*
* 10
*
*
* @param node
* @throws NetworkFailureException
* @throws ActionFailureException
*/
public void addUpdateNode(Node node) throws NetworkFailureException {
if (node != null) {
// too many update items may result in an error
@ -512,19 +447,6 @@ public class GTaskClient {
}
}
/**
*
*
*
* 1.
* 2.
*
* @param task
* @param preParent
* @param curParent
* @throws NetworkFailureException
* @throws ActionFailureException
*/
public void moveTask(Task task, TaskList preParent, TaskList curParent)
throws NetworkFailureException {
commitUpdate();
@ -564,15 +486,6 @@ public class GTaskClient {
}
}
/**
*
*
* Google Tasks
*
* @param node
* @throws NetworkFailureException
* @throws ActionFailureException
*/
public void deleteNode(Node node) throws NetworkFailureException {
commitUpdate();
try {
@ -596,15 +509,6 @@ public class GTaskClient {
}
}
/**
*
*
* Google Tasks
*
* @return JSONArray
* @throws NetworkFailureException
* @throws ActionFailureException
*/
public JSONArray getTaskLists() throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
@ -643,16 +547,6 @@ public class GTaskClient {
}
}
/**
*
*
* Google Tasks
*
* @param listGid ID
* @return JSONArray
* @throws NetworkFailureException
* @throws ActionFailureException
*/
public JSONArray getTaskList(String listGid) throws NetworkFailureException {
commitUpdate();
try {
@ -681,20 +575,10 @@ public class GTaskClient {
}
}
/**
* 使Google
*
* @return 使Google
*/
public Account getSyncAccount() {
return mAccount;
}
/**
*
*
*
*/
public void resetUpdateArray() {
mUpdateArray = null;
}

@ -48,45 +48,17 @@ import java.util.Iterator;
import java.util.Map;
/**
* GTaskManager - Google Tasks使
*
* Google Tasks
*
* -
* -
* -
* -
* -
*
* @author MiCode Open Source Community
*/
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;
@ -127,14 +99,6 @@ public class GTaskManager {
mNidToGid = new HashMap<Long, String>();
}
/**
* GTaskManager
*
* 线GTaskManager
*
*
* @return GTaskManager
*/
public static synchronized GTaskManager getInstance() {
if (mInstance == null) {
mInstance = new GTaskManager();
@ -142,36 +106,11 @@ public class GTaskManager {
return mInstance;
}
/**
* Activity
*
* GoogleActivity
*
* @param activity Activity
*/
public synchronized void setActivityContext(Activity activity) {
// used for getting authtoken
mActivity = activity;
}
/**
* Google Tasks
*
*
* 1. Google Tasks
* 2.
* 3.
* 4.
*
* @param context
* @param asyncTask
* @return
* - STATE_SUCCESS
* - STATE_NETWORK_ERROR
* - STATE_INTERNAL_ERROR
* - STATE_SYNC_IN_PROGRESS
* - STATE_SYNC_CANCELLED
*/
public int sync(Context context, GTaskASyncTask asyncTask) {
if (mSyncing) {
Log.d(TAG, "Sync is in progress");
@ -851,20 +790,10 @@ public class GTaskManager {
}
}
/**
* 使Google
*
* @return 使Google
*/
public String getSyncAccount() {
return GTaskClient.getInstance().getSyncAccount().name;
}
/**
*
*
* 使
*/
public void cancelSync() {
mCancelled = true;
}

@ -23,66 +23,25 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
/**
* GTaskSyncService - Android ServiceGoogle Tasks
*
* Google Tasks广
* GTaskASyncTask广UI
*
* @author MiCode Open Source Community
*/
public class GTaskSyncService extends Service {
/**
* Intent
*/
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;
/**
* 广Action
*/
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 = "";
/**
*
*
* GTaskASyncTask
*
*/
private void startSync() {
if (mSyncTask == null) {
mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() {
@ -97,11 +56,6 @@ public class GTaskSyncService extends Service {
}
}
/**
*
*
* cancelSync
*/
private void cancelSync() {
if (mSyncTask != null) {
mSyncTask.cancelSync();
@ -113,16 +67,6 @@ public class GTaskSyncService extends Service {
mSyncTask = null;
}
/**
*
*
* Intent
*
* @param intent Intent
* @param flags
* @param startId ID
* @return START_STICKY
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle bundle = intent.getExtras();
@ -142,11 +86,6 @@ public class GTaskSyncService extends Service {
return super.onStartCommand(intent, flags, startId);
}
/**
*
*
*
*/
@Override
public void onLowMemory() {
if (mSyncTask != null) {
@ -154,25 +93,10 @@ public class GTaskSyncService extends Service {
}
}
/**
*
*
* null
*
* @param intent Intent
* @return IBindernull
*/
public IBinder onBind(Intent intent) {
return null;
}
/**
* 广
*
* 广广
*
* @param msg
*/
public void sendBroadcast(String msg) {
mSyncProgress = msg;
Intent intent = new Intent(GTASK_SERVICE_BROADCAST_NAME);
@ -181,13 +105,6 @@ public class GTaskSyncService extends Service {
sendBroadcast(intent);
}
/**
*
*
* ActivityGTaskSyncService
*
* @param activity Activity
*/
public static void startSync(Activity activity) {
GTaskManager.getInstance().setActivityContext(activity);
Intent intent = new Intent(activity, GTaskSyncService.class);
@ -195,37 +112,16 @@ public class GTaskSyncService extends Service {
activity.startService(intent);
}
/**
*
*
* ContextGTaskSyncService
*
* @param context
*/
public static void cancelSync(Context context) {
Intent intent = new Intent(context, GTaskSyncService.class);
intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_CANCEL_SYNC);
context.startService(intent);
}
/**
*
*
*
*
* @return truefalse
*/
public static boolean isSyncing() {
return mSyncTask != null;
}
/**
*
*
*
*
* @return
*/
public static String getProgressString() {
return mSyncProgress;
}

@ -34,38 +34,12 @@ import net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList;
/**
* Note -
*
*
*
* ContentResolverContentProvider
*
* @author MiCode Open Source Community
*/
public class Note {
/**
*
*/
private ContentValues mNoteDiffValues;
/**
*
*/
private NoteData mNoteData;
/**
*
*/
private static final String TAG = "Note";
/**
* ID
*
* ID
*
*
* @param context ContentResolver
* @param folderId ID
* @return ID
* @throws IllegalStateException
* Create a new note id for adding a new note to databases
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// Create a new note in the database
@ -91,92 +65,41 @@ public class Note {
return noteId;
}
/**
*
*
*
*/
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
}
/**
*
*
* @param key
* @param value
*/
public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
*
*
* @param key
* @param value
*/
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
}
/**
* ID
*
* @param id ID
*/
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
}
/**
* ID
*
* @return ID
*/
public long getTextDataId() {
return mNoteData.mTextDataId;
}
/**
* ID
*
* @param id ID
*/
public void setCallDataId(long id) {
mNoteData.setCallDataId(id);
}
/**
*
*
* @param key
* @param value
*/
public void setCallData(String key, String value) {
mNoteData.setCallData(key, value);
}
/**
*
*
* @return truefalse
*/
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
}
/**
*
*
* @param context ContentResolver
* @param noteId ID
* @return truefalse
* @throws IllegalArgumentException ID
*/
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
@ -207,43 +130,17 @@ public class Note {
return true;
}
/**
* NoteData -
*
*
* ContentResolver
*/
private class NoteData {
/**
* ID
*/
private long mTextDataId;
/**
*
*/
private ContentValues mTextDataValues;
/**
* ID
*/
private long mCallDataId;
/**
*
*/
private ContentValues mCallDataValues;
/**
*
*/
private static final String TAG = "NoteData";
/**
*
*
*
*/
public NoteData() {
mTextDataValues = new ContentValues();
mCallDataValues = new ContentValues();
@ -251,21 +148,10 @@ public class Note {
mCallDataId = 0;
}
/**
*
*
* @return truefalse
*/
boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
}
/**
* ID
*
* @param id ID
* @throws IllegalArgumentException ID
*/
void setTextDataId(long id) {
if(id <= 0) {
throw new IllegalArgumentException("Text data id should larger than 0");
@ -273,12 +159,6 @@ public class Note {
mTextDataId = id;
}
/**
* ID
*
* @param id ID
* @throws IllegalArgumentException ID
*/
void setCallDataId(long id) {
if (id <= 0) {
throw new IllegalArgumentException("Call data id should larger than 0");
@ -286,38 +166,18 @@ public class Note {
mCallDataId = id;
}
/**
*
*
* @param key
* @param value
*/
void setCallData(String key, String value) {
mCallDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
*
*
* @param key
* @param value
*/
void setTextData(String key, String value) {
mTextDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
* ContentResolver
*
* @param context ContentResolver
* @param noteId ID
* @return URInull
* @throws IllegalArgumentException ID
*/
Uri pushIntoContentResolver(Context context, long noteId) {
/**
* Check for safety

@ -32,71 +32,34 @@ import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
/**
* WorkingNote - 使
*
* Note便
*
*
*
* @author MiCode Open Source Community
*/
public class WorkingNote {
/**
* Note
*/
// Note for the working note
private Note mNote;
/**
* ID
*/
// Note Id
private long mNoteId;
/**
*
*/
// Note content
private String mContent;
/**
*
*/
// Note mode
private int mMode;
/**
*
*/
private long mAlertDate;
/**
*
*/
private long mModifiedDate;
/**
* ID
*/
private int mBgColorId;
/**
* ID
*/
private int mWidgetId;
/**
*
*/
private int mWidgetType;
/**
* ID
*/
private long mFolderId;
/**
*
*/
private Context mContext;
/**
*
*/
private static final String TAG = "WorkingNote";
/**
*
*/
private boolean mIsDeleted;
/**
*
*/
private NoteSettingChangedListener mNoteSettingStatusListener;
public static final String[] DATA_PROJECTION = new String[] {

@ -92,7 +92,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
=======
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
// 修复:兼容 Android 13+ 的广播注册方式
// 修复:兼容 Android 13+ 的广播注册方式(无需 if/else
ContextCompat.registerReceiver(
this,
mReceiver,

Loading…
Cancel
Save