|  |  | @ -37,12 +37,18 @@ import org.json.JSONObject; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.ArrayList; |  |  |  | import java.util.ArrayList; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | /** | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |  * SqlNote类用于处理笔记的数据库操作,包括创建、读取、更新和删除操作 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |  * 支持与JSON格式数据的相互转换,方便与Google Tasks等外部服务同步 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |  * 同时管理笔记的基本信息和相关数据项 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |  */ | 
			
		
	
		
		
			
				
					
					|  |  |  | public class SqlNote { |  |  |  | public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static final String TAG = SqlNote.class.getSimpleName(); |  |  |  |     private static final String TAG = SqlNote.class.getSimpleName(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 无效ID,用于标识尚未创建的笔记
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static final int INVALID_ID = -99999; |  |  |  |     private static final int INVALID_ID = -99999; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 查询笔记时使用的列投影
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final String[] PROJECTION_NOTE = new String[] { |  |  |  |     public static final String[] PROJECTION_NOTE = new String[] { | 
			
		
	
		
		
			
				
					
					|  |  |  |             NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, |  |  |  |             NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, | 
			
		
	
		
		
			
				
					
					|  |  |  |             NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE, |  |  |  |             NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE, | 
			
		
	
	
		
		
			
				
					|  |  | @ -52,76 +58,83 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |             NoteColumns.VERSION |  |  |  |             NoteColumns.VERSION | 
			
		
	
		
		
			
				
					
					|  |  |  |     }; |  |  |  |     }; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 各列在投影中的索引位置
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int ID_COLUMN = 0; |  |  |  |     public static final int ID_COLUMN = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int ALERTED_DATE_COLUMN = 1; |  |  |  |     public static final int ALERTED_DATE_COLUMN = 1; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int BG_COLOR_ID_COLUMN = 2; |  |  |  |     public static final int BG_COLOR_ID_COLUMN = 2; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int CREATED_DATE_COLUMN = 3; |  |  |  |     public static final int CREATED_DATE_COLUMN = 3; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int HAS_ATTACHMENT_COLUMN = 4; |  |  |  |     public static final int HAS_ATTACHMENT_COLUMN = 4; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int MODIFIED_DATE_COLUMN = 5; |  |  |  |     public static final int MODIFIED_DATE_COLUMN = 5; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int NOTES_COUNT_COLUMN = 6; |  |  |  |     public static final int NOTES_COUNT_COLUMN = 6; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int PARENT_ID_COLUMN = 7; |  |  |  |     public static final int PARENT_ID_COLUMN = 7; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int SNIPPET_COLUMN = 8; |  |  |  |     public static final int SNIPPET_COLUMN = 8; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int TYPE_COLUMN = 9; |  |  |  |     public static final int TYPE_COLUMN = 9; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int WIDGET_ID_COLUMN = 10; |  |  |  |     public static final int WIDGET_ID_COLUMN = 10; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int WIDGET_TYPE_COLUMN = 11; |  |  |  |     public static final int WIDGET_TYPE_COLUMN = 11; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int SYNC_ID_COLUMN = 12; |  |  |  |     public static final int SYNC_ID_COLUMN = 12; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int LOCAL_MODIFIED_COLUMN = 13; |  |  |  |     public static final int LOCAL_MODIFIED_COLUMN = 13; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int ORIGIN_PARENT_ID_COLUMN = 14; |  |  |  |     public static final int ORIGIN_PARENT_ID_COLUMN = 14; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int GTASK_ID_COLUMN = 15; |  |  |  |     public static final int GTASK_ID_COLUMN = 15; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final int VERSION_COLUMN = 16; |  |  |  |     public static final int VERSION_COLUMN = 16; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 应用上下文
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private Context mContext; |  |  |  |     private Context mContext; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 内容解析器,用于与内容提供者通信
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private ContentResolver mContentResolver; |  |  |  |     private ContentResolver mContentResolver; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 是否为新建笔记的标志
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private boolean mIsCreate; |  |  |  |     private boolean mIsCreate; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 笔记ID
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private long mId; |  |  |  |     private long mId; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 提醒日期
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private long mAlertDate; |  |  |  |     private long mAlertDate; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 背景颜色ID
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private int mBgColorId; |  |  |  |     private int mBgColorId; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 创建日期
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private long mCreatedDate; |  |  |  |     private long mCreatedDate; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 是否有附件的标志
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private int mHasAttachment; |  |  |  |     private int mHasAttachment; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 修改日期
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private long mModifiedDate; |  |  |  |     private long mModifiedDate; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 父文件夹ID
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private long mParentId; |  |  |  |     private long mParentId; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 摘要内容
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private String mSnippet; |  |  |  |     private String mSnippet; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 笔记类型(普通笔记、文件夹、系统文件夹)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private int mType; |  |  |  |     private int mType; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 桌面小部件ID
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private int mWidgetId; |  |  |  |     private int mWidgetId; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 桌面小部件类型
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private int mWidgetType; |  |  |  |     private int mWidgetType; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 原始父文件夹ID
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private long mOriginParent; |  |  |  |     private long mOriginParent; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 版本号
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private long mVersion; |  |  |  |     private long mVersion; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 记录笔记变更的ContentValues
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private ContentValues mDiffNoteValues; |  |  |  |     private ContentValues mDiffNoteValues; | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // 笔记关联的数据列表
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private ArrayList<SqlData> mDataList; |  |  |  |     private ArrayList<SqlData> mDataList; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 构造函数,创建一个新的空笔记 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param context 应用上下文 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public SqlNote(Context context) { |  |  |  |     public SqlNote(Context context) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mContext = context; |  |  |  |         mContext = context; | 
			
		
	
		
		
			
				
					
					|  |  |  |         mContentResolver = context.getContentResolver(); |  |  |  |         mContentResolver = context.getContentResolver(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -143,6 +156,11 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mDataList = new ArrayList<SqlData>(); |  |  |  |         mDataList = new ArrayList<SqlData>(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 构造函数,从Cursor加载现有笔记 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param context 应用上下文 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param c 包含笔记数据的Cursor | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public SqlNote(Context context, Cursor c) { |  |  |  |     public SqlNote(Context context, Cursor c) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mContext = context; |  |  |  |         mContext = context; | 
			
		
	
		
		
			
				
					
					|  |  |  |         mContentResolver = context.getContentResolver(); |  |  |  |         mContentResolver = context.getContentResolver(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -154,6 +172,11 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mDiffNoteValues = new ContentValues(); |  |  |  |         mDiffNoteValues = new ContentValues(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 构造函数,根据ID从数据库加载笔记 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param context 应用上下文 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param id 笔记ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public SqlNote(Context context, long id) { |  |  |  |     public SqlNote(Context context, long id) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mContext = context; |  |  |  |         mContext = context; | 
			
		
	
		
		
			
				
					
					|  |  |  |         mContentResolver = context.getContentResolver(); |  |  |  |         mContentResolver = context.getContentResolver(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -163,9 +186,12 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (mType == Notes.TYPE_NOTE) |  |  |  |         if (mType == Notes.TYPE_NOTE) | 
			
		
	
		
		
			
				
					
					|  |  |  |             loadDataContent(); |  |  |  |             loadDataContent(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         mDiffNoteValues = new ContentValues(); |  |  |  |         mDiffNoteValues = new ContentValues(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 从数据库根据ID加载笔记数据 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param id 笔记ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     private void loadFromCursor(long id) { |  |  |  |     private void loadFromCursor(long id) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         Cursor c = null; |  |  |  |         Cursor c = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
	
		
		
			
				
					|  |  | @ -185,6 +211,10 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 从Cursor加载笔记数据到对象中 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param c 包含笔记数据的Cursor | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     private void loadFromCursor(Cursor c) { |  |  |  |     private void loadFromCursor(Cursor c) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mId = c.getLong(ID_COLUMN); |  |  |  |         mId = c.getLong(ID_COLUMN); | 
			
		
	
		
		
			
				
					
					|  |  |  |         mAlertDate = c.getLong(ALERTED_DATE_COLUMN); |  |  |  |         mAlertDate = c.getLong(ALERTED_DATE_COLUMN); | 
			
		
	
	
		
		
			
				
					|  |  | @ -200,6 +230,9 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mVersion = c.getLong(VERSION_COLUMN); |  |  |  |         mVersion = c.getLong(VERSION_COLUMN); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 加载与笔记关联的数据内容 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     private void loadDataContent() { |  |  |  |     private void loadDataContent() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         Cursor c = null; |  |  |  |         Cursor c = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |         mDataList.clear(); |  |  |  |         mDataList.clear(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -226,13 +259,22 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 从JSON对象设置笔记内容 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param js 包含笔记内容的JSON对象 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return 设置成功返回true,失败返回false | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public boolean setContent(JSONObject js) { |  |  |  |     public boolean setContent(JSONObject js) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 获取笔记元数据
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); |  |  |  |             JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 系统文件夹不可修改
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { |  |  |  |             if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 Log.w(TAG, "cannot set system folder"); |  |  |  |                 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
 |  |  |  |             // 文件夹类型只能更新摘要和类型
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String snippet = note.has(NoteColumns.SNIPPET) ? note |  |  |  |                 String snippet = note.has(NoteColumns.SNIPPET) ? note | 
			
		
	
		
		
			
				
					
					|  |  |  |                         .getString(NoteColumns.SNIPPET) : ""; |  |  |  |                         .getString(NoteColumns.SNIPPET) : ""; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (mIsCreate || !mSnippet.equals(snippet)) { |  |  |  |                 if (mIsCreate || !mSnippet.equals(snippet)) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -246,8 +288,12 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     mDiffNoteValues.put(NoteColumns.TYPE, type); |  |  |  |                     mDiffNoteValues.put(NoteColumns.TYPE, type); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mType = type; |  |  |  |                 mType = type; | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { |  |  |  |             }  | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 普通笔记类型可以更新全部属性
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); |  |  |  |                 JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                  | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 从JSON中提取笔记各属性值,并与当前值比较,记录差异
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID; |  |  |  |                 long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (mIsCreate || mId != id) { |  |  |  |                 if (mIsCreate || mId != id) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     mDiffNoteValues.put(NoteColumns.ID, id); |  |  |  |                     mDiffNoteValues.put(NoteColumns.ID, id); | 
			
		
	
	
		
		
			
				
					|  |  | @ -331,9 +377,12 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mOriginParent = originParent; |  |  |  |                 mOriginParent = originParent; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 处理笔记关联的数据项
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 for (int i = 0; i < dataArray.length(); i++) { |  |  |  |                 for (int i = 0; i < dataArray.length(); i++) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     JSONObject data = dataArray.getJSONObject(i); |  |  |  |                     JSONObject data = dataArray.getJSONObject(i); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     SqlData sqlData = null; |  |  |  |                     SqlData sqlData = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                      | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 如果数据项已存在,则获取它
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (data.has(DataColumns.ID)) { |  |  |  |                     if (data.has(DataColumns.ID)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         long dataId = data.getLong(DataColumns.ID); |  |  |  |                         long dataId = data.getLong(DataColumns.ID); | 
			
		
	
		
		
			
				
					
					|  |  |  |                         for (SqlData temp : mDataList) { |  |  |  |                         for (SqlData temp : mDataList) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -343,11 +392,13 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         } |  |  |  |                         } | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 如果数据项不存在,则创建新的
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (sqlData == null) { |  |  |  |                     if (sqlData == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         sqlData = new SqlData(mContext); |  |  |  |                         sqlData = new SqlData(mContext); | 
			
		
	
		
		
			
				
					
					|  |  |  |                         mDataList.add(sqlData); |  |  |  |                         mDataList.add(sqlData); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 设置数据项内容
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     sqlData.setContent(data); |  |  |  |                     sqlData.setContent(data); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
	
		
		
			
				
					|  |  | @ -359,6 +410,10 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return true; |  |  |  |         return true; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 将笔记内容转换为JSON对象 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return 包含笔记内容的JSON对象 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public JSONObject getContent() { |  |  |  |     public JSONObject getContent() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject js = new JSONObject(); |  |  |  |             JSONObject js = new JSONObject(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -370,6 +425,7 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject note = new JSONObject(); |  |  |  |             JSONObject note = new JSONObject(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (mType == Notes.TYPE_NOTE) { |  |  |  |             if (mType == Notes.TYPE_NOTE) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 将笔记各属性添加到JSON对象
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 note.put(NoteColumns.ID, mId); |  |  |  |                 note.put(NoteColumns.ID, mId); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 note.put(NoteColumns.ALERTED_DATE, mAlertDate); |  |  |  |                 note.put(NoteColumns.ALERTED_DATE, mAlertDate); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 note.put(NoteColumns.BG_COLOR_ID, mBgColorId); |  |  |  |                 note.put(NoteColumns.BG_COLOR_ID, mBgColorId); | 
			
		
	
	
		
		
			
				
					|  |  | @ -384,6 +440,7 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent); |  |  |  |                 note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 js.put(GTaskStringUtils.META_HEAD_NOTE, note); |  |  |  |                 js.put(GTaskStringUtils.META_HEAD_NOTE, note); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 添加关联的数据项
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 JSONArray dataArray = new JSONArray(); |  |  |  |                 JSONArray dataArray = new JSONArray(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 for (SqlData sqlData : mDataList) { |  |  |  |                 for (SqlData sqlData : mDataList) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     JSONObject data = sqlData.getContent(); |  |  |  |                     JSONObject data = sqlData.getContent(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -393,6 +450,7 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 js.put(GTaskStringUtils.META_HEAD_DATA, dataArray); |  |  |  |                 js.put(GTaskStringUtils.META_HEAD_DATA, dataArray); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) { |  |  |  |             } else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 // 文件夹类型只需要基本信息
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 note.put(NoteColumns.ID, mId); |  |  |  |                 note.put(NoteColumns.ID, mId); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 note.put(NoteColumns.TYPE, mType); |  |  |  |                 note.put(NoteColumns.TYPE, mType); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 note.put(NoteColumns.SNIPPET, mSnippet); |  |  |  |                 note.put(NoteColumns.SNIPPET, mSnippet); | 
			
		
	
	
		
		
			
				
					|  |  | @ -407,45 +465,82 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return null; |  |  |  |         return null; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 设置笔记的父文件夹ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param id 父文件夹ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void setParentId(long id) { |  |  |  |     public void setParentId(long id) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mParentId = id; |  |  |  |         mParentId = id; | 
			
		
	
		
		
			
				
					
					|  |  |  |         mDiffNoteValues.put(NoteColumns.PARENT_ID, id); |  |  |  |         mDiffNoteValues.put(NoteColumns.PARENT_ID, id); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 设置Google Tasks ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param gid Google Tasks ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void setGtaskId(String gid) { |  |  |  |     public void setGtaskId(String gid) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mDiffNoteValues.put(NoteColumns.GTASK_ID, gid); |  |  |  |         mDiffNoteValues.put(NoteColumns.GTASK_ID, gid); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 设置同步ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param syncId 同步ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void setSyncId(long syncId) { |  |  |  |     public void setSyncId(long syncId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId); |  |  |  |         mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 重置本地修改标志 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void resetLocalModified() { |  |  |  |     public void resetLocalModified() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0); |  |  |  |         mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 获取笔记ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return 笔记ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public long getId() { |  |  |  |     public long getId() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return mId; |  |  |  |         return mId; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 获取父文件夹ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return 父文件夹ID | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public long getParentId() { |  |  |  |     public long getParentId() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return mParentId; |  |  |  |         return mParentId; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 获取笔记摘要 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return 笔记摘要 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public String getSnippet() { |  |  |  |     public String getSnippet() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return mSnippet; |  |  |  |         return mSnippet; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 判断是否为普通笔记类型 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return 是普通笔记返回true,否则返回false | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public boolean isNoteType() { |  |  |  |     public boolean isNoteType() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return mType == Notes.TYPE_NOTE; |  |  |  |         return mType == Notes.TYPE_NOTE; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 将笔记变更提交到数据库 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param validateVersion 是否验证版本,防止并发修改冲突 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void commit(boolean validateVersion) { |  |  |  |     public void commit(boolean validateVersion) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (mIsCreate) { |  |  |  |         if (mIsCreate) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 创建新笔记
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) { |  |  |  |             if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mDiffNoteValues.remove(NoteColumns.ID); |  |  |  |                 mDiffNoteValues.remove(NoteColumns.ID); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 插入新笔记
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues); |  |  |  |             Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues); | 
			
		
	
		
		
			
				
					
					|  |  |  |             try { |  |  |  |             try { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mId = Long.valueOf(uri.getPathSegments().get(1)); |  |  |  |                 mId = Long.valueOf(uri.getPathSegments().get(1)); | 
			
		
	
	
		
		
			
				
					|  |  | @ -457,12 +552,14 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 throw new IllegalStateException("Create thread id failed"); |  |  |  |                 throw new IllegalStateException("Create thread id failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 如果是普通笔记,提交关联的数据项
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (mType == Notes.TYPE_NOTE) { |  |  |  |             if (mType == Notes.TYPE_NOTE) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 for (SqlData sqlData : mDataList) { |  |  |  |                 for (SqlData sqlData : mDataList) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     sqlData.commit(mId, false, -1); |  |  |  |                     sqlData.commit(mId, false, -1); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 更新现有笔记
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) { |  |  |  |             if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 Log.e(TAG, "No such note"); |  |  |  |                 Log.e(TAG, "No such note"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 throw new IllegalStateException("Try to update note with invalid id"); |  |  |  |                 throw new IllegalStateException("Try to update note with invalid id"); | 
			
		
	
	
		
		
			
				
					|  |  | @ -471,11 +568,13 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mVersion ++; |  |  |  |                 mVersion ++; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 int result = 0; |  |  |  |                 int result = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (!validateVersion) { |  |  |  |                 if (!validateVersion) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 不验证版本直接更新
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" |  |  |  |                     result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" | 
			
		
	
		
		
			
				
					
					|  |  |  |                             + NoteColumns.ID + "=?)", new String[] { |  |  |  |                             + NoteColumns.ID + "=?)", new String[] { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         String.valueOf(mId) |  |  |  |                         String.valueOf(mId) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     }); |  |  |  |                     }); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } else { |  |  |  |                 } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     // 验证版本,确保只更新版本号小于等于当前版本的记录
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" |  |  |  |                     result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" | 
			
		
	
		
		
			
				
					
					|  |  |  |                             + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)", |  |  |  |                             + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)", | 
			
		
	
		
		
			
				
					
					|  |  |  |                             new String[] { |  |  |  |                             new String[] { | 
			
		
	
	
		
		
			
				
					|  |  | @ -487,6 +586,7 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // 如果是普通笔记,提交关联的数据项
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (mType == Notes.TYPE_NOTE) { |  |  |  |             if (mType == Notes.TYPE_NOTE) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 for (SqlData sqlData : mDataList) { |  |  |  |                 for (SqlData sqlData : mDataList) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     sqlData.commit(mId, validateVersion, mVersion); |  |  |  |                     sqlData.commit(mId, validateVersion, mVersion); | 
			
		
	
	
		
		
			
				
					|  |  | @ -494,11 +594,12 @@ public class SqlNote { | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         // refresh local info
 |  |  |  |         // 提交后刷新本地信息
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         loadFromCursor(mId); |  |  |  |         loadFromCursor(mId); | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (mType == Notes.TYPE_NOTE) |  |  |  |         if (mType == Notes.TYPE_NOTE) | 
			
		
	
		
		
			
				
					
					|  |  |  |             loadDataContent(); |  |  |  |             loadDataContent(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 清除变更记录
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         mDiffNoteValues.clear(); |  |  |  |         mDiffNoteValues.clear(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         mIsCreate = false; |  |  |  |         mIsCreate = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |