|
|
|
@ -13,7 +13,7 @@ RANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//sqlNote代码注释
|
|
|
|
|
/* sqlNote:用于支持软件最底层的数据库的相关操作,note是data的子父集。
|
|
|
|
|
用来实现数据库中管理便签的数据,
|
|
|
|
|
方法包括提取便签内容、从数据库中获取便签数据、设置便签内容、向数据库提交便签。
|
|
|
|
@ -43,8 +43,12 @@ import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class SqlNote {
|
|
|
|
|
/*
|
|
|
|
|
* 功能描述:得到类的简写名称存入字符串TAG中
|
|
|
|
|
* 实现过程:调用getSimpleName ()函数
|
|
|
|
|
*/
|
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
//定义一个标识便于后面数据的输入输出
|
|
|
|
|
private static final int INVALID_ID = -99999;
|
|
|
|
|
|
|
|
|
|
public static final String[] PROJECTION_NOTE = new String[] {
|
|
|
|
@ -55,7 +59,7 @@ public class SqlNote {
|
|
|
|
|
NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID,
|
|
|
|
|
NoteColumns.VERSION
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//设置17个列的编号
|
|
|
|
|
public static final int ID_COLUMN = 0;
|
|
|
|
|
|
|
|
|
|
public static final int ALERTED_DATE_COLUMN = 1;
|
|
|
|
@ -89,12 +93,12 @@ public class SqlNote {
|
|
|
|
|
public static final int GTASK_ID_COLUMN = 15;
|
|
|
|
|
|
|
|
|
|
public static final int VERSION_COLUMN = 16;
|
|
|
|
|
|
|
|
|
|
//定义了17个内部变量。12个可以从content中获得,5个需要初始化为0或new
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
private ContentResolver mContentResolver; //定义了一个私有全局变量
|
|
|
|
|
|
|
|
|
|
private boolean mIsCreate;
|
|
|
|
|
private boolean mIsCreate; //后续选择生成
|
|
|
|
|
|
|
|
|
|
private long mId;
|
|
|
|
|
|
|
|
|
@ -126,16 +130,21 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
|
|
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
|
/*
|
|
|
|
|
* 功能描述:构造函数
|
|
|
|
|
* 参数注解: mIsCreate用于标示构造方式
|
|
|
|
|
*/
|
|
|
|
|
//构造函数只有context,对所有的变量进行初始化
|
|
|
|
|
public SqlNote(Context context) { //构造函数进行初始化
|
|
|
|
|
mContext = context;
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
|
mIsCreate = true;
|
|
|
|
|
mId = INVALID_ID;
|
|
|
|
|
mContentResolver = context.getContentResolver(); //获取对象或直接查询数据
|
|
|
|
|
mIsCreate = true; //当前数据的创建
|
|
|
|
|
mId = INVALID_ID; //初始值定义
|
|
|
|
|
mAlertDate = 0;
|
|
|
|
|
mBgColorId = ResourceParser.getDefaultBgId(context);
|
|
|
|
|
mCreatedDate = System.currentTimeMillis();
|
|
|
|
|
mCreatedDate = System.currentTimeMillis();//调用系统函数获取创建时间
|
|
|
|
|
mHasAttachment = 0;
|
|
|
|
|
mModifiedDate = System.currentTimeMillis();
|
|
|
|
|
mModifiedDate = System.currentTimeMillis();//最后一次修改时间初始化为创建时间
|
|
|
|
|
mParentId = 0;
|
|
|
|
|
mSnippet = "";
|
|
|
|
|
mType = Notes.TYPE_NOTE;
|
|
|
|
@ -143,21 +152,32 @@ public class SqlNote {
|
|
|
|
|
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
|
|
|
|
|
mOriginParent = 0;
|
|
|
|
|
mVersion = 0;
|
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
|
mDiffNoteValues = new ContentValues(); //创建内容
|
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 功能描述:构造函数
|
|
|
|
|
* 参数注解: mIsCreate用于标示构造方式
|
|
|
|
|
*/
|
|
|
|
|
//构造函数有context和一个数据库的cursor,多数变量通过cursor指向的一条记录直接进行初始化
|
|
|
|
|
|
|
|
|
|
public SqlNote(Context context, Cursor c) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
|
mIsCreate = false;
|
|
|
|
|
loadFromCursor(c);
|
|
|
|
|
mContentResolver = context.getContentResolver(); //获取程序之间的数据共享
|
|
|
|
|
mIsCreate = false; //记录当前数据创建方式
|
|
|
|
|
loadFromCursor(c); //从光标处载入数据
|
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
|
loadDataContent();
|
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 功能描述:构造函数
|
|
|
|
|
* 参数注解: mIsCreate用于标示构造方式
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public SqlNote(Context context, long id) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
@ -170,16 +190,21 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*功能描述:通过id从光标处加载数据
|
|
|
|
|
*/
|
|
|
|
|
private void loadFromCursor(long id) {
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
try {
|
|
|
|
|
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
|
|
|
|
|
new String[] {
|
|
|
|
|
String.valueOf(id)
|
|
|
|
|
}, null);
|
|
|
|
|
}, null);//通过id获取对应的ContentResolver中的cursor
|
|
|
|
|
if (c != null) {
|
|
|
|
|
c.moveToNext();
|
|
|
|
|
loadFromCursor(c);
|
|
|
|
|
//加载数据进行初始化
|
|
|
|
|
//使函数SqlNote(Context context, long id)与SqlNote(Context context, long id)的实现方式基本相同
|
|
|
|
|
} else {
|
|
|
|
|
Log.w(TAG, "loadFromCursor: cursor = null");
|
|
|
|
|
}
|
|
|
|
@ -189,7 +214,9 @@ public class SqlNote {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:通过游标从光标处加载数据
|
|
|
|
|
private void loadFromCursor(Cursor c) {
|
|
|
|
|
//直接从一条记录中的获得以下变量的初始值
|
|
|
|
|
mId = c.getLong(ID_COLUMN);
|
|
|
|
|
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
|
|
|
|
|
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
|
|
|
|
@ -204,6 +231,7 @@ public class SqlNote {
|
|
|
|
|
mVersion = c.getLong(VERSION_COLUMN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:通过content机制获取共享数据并加载到数据库当前游标处
|
|
|
|
|
private void loadDataContent() {
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
mDataList.clear();
|
|
|
|
@ -230,67 +258,69 @@ public class SqlNote {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:通过设置content机制用于共享的数据信息
|
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
|
try {
|
|
|
|
|
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
|
|
|
|
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); //创建一个JSONObject对象
|
|
|
|
|
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
|
|
|
|
|
//对于文件夹,只能更新snnipet并键入
|
|
|
|
|
String snippet = note.has(NoteColumns.SNIPPET) ? note
|
|
|
|
|
.getString(NoteColumns.SNIPPET) : "";
|
|
|
|
|
.getString(NoteColumns.SNIPPET) : ""; //如果共享数据存在摘要,需要将其赋给声明的snippct变量,否则变量为空
|
|
|
|
|
if (mIsCreate || !mSnippet.equals(snippet)) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
|
|
|
|
|
}
|
|
|
|
|
} //如果SQLNote采用的是第一种构造方式,或snippet为空,则将snippet键值存入contenttvalue中
|
|
|
|
|
mSnippet = snippet;
|
|
|
|
|
|
|
|
|
|
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
|
|
|
|
|
: Notes.TYPE_NOTE;
|
|
|
|
|
if (mIsCreate || mType != type) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.TYPE, type);
|
|
|
|
|
}
|
|
|
|
|
} //判断类型是否匹配
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
} //判断id是否匹配
|
|
|
|
|
mId = id;
|
|
|
|
|
|
|
|
|
|
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
|
|
|
|
|
.getLong(NoteColumns.ALERTED_DATE) : 0;
|
|
|
|
|
if (mIsCreate || mAlertDate != alertDate) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate);
|
|
|
|
|
}
|
|
|
|
|
} //如果仅通过上下文对Note进行数据库修改,或该标记日与原标记日不同
|
|
|
|
|
mAlertDate = alertDate;
|
|
|
|
|
|
|
|
|
|
int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note
|
|
|
|
|
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
|
|
|
|
|
if (mIsCreate || mBgColorId != bgColorId) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId);
|
|
|
|
|
}
|
|
|
|
|
} //判断背景颜色是否一致
|
|
|
|
|
mBgColorId = bgColorId;
|
|
|
|
|
|
|
|
|
|
long createDate = note.has(NoteColumns.CREATED_DATE) ? note
|
|
|
|
|
.getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis();
|
|
|
|
|
if (mIsCreate || mCreatedDate != createDate) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.CREATED_DATE, createDate);
|
|
|
|
|
}
|
|
|
|
|
} //判断日期是否一致
|
|
|
|
|
mCreatedDate = createDate;
|
|
|
|
|
|
|
|
|
|
int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT) ? note
|
|
|
|
|
.getInt(NoteColumns.HAS_ATTACHMENT) : 0;
|
|
|
|
|
.getInt(NoteColumns.HAS_ATTACHMENT) : 0; //修改附件
|
|
|
|
|
if (mIsCreate || mHasAttachment != hasAttachment) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment);
|
|
|
|
|
}
|
|
|
|
|
} //判断附件是否一致
|
|
|
|
|
mHasAttachment = hasAttachment;
|
|
|
|
|
|
|
|
|
|
long modifiedDate = note.has(NoteColumns.MODIFIED_DATE) ? note
|
|
|
|
|
.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis();
|
|
|
|
|
.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis(); //修改日期
|
|
|
|
|
if (mIsCreate || mModifiedDate != modifiedDate) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate);
|
|
|
|
|
}
|
|
|
|
|
} //判断修改的日期是否一致
|
|
|
|
|
mModifiedDate = modifiedDate;
|
|
|
|
|
|
|
|
|
|
long parentId = note.has(NoteColumns.PARENT_ID) ? note
|
|
|
|
@ -301,24 +331,24 @@ public class SqlNote {
|
|
|
|
|
mParentId = parentId;
|
|
|
|
|
|
|
|
|
|
String snippet = note.has(NoteColumns.SNIPPET) ? note
|
|
|
|
|
.getString(NoteColumns.SNIPPET) : "";
|
|
|
|
|
.getString(NoteColumns.SNIPPET) : ""; //定义小部件
|
|
|
|
|
if (mIsCreate || !mSnippet.equals(snippet)) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
|
|
|
|
|
}
|
|
|
|
|
} //判断小部件是否一致
|
|
|
|
|
mSnippet = snippet;
|
|
|
|
|
|
|
|
|
|
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
|
|
|
|
|
: Notes.TYPE_NOTE;
|
|
|
|
|
if (mIsCreate || mType != type) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.TYPE, type);
|
|
|
|
|
}
|
|
|
|
|
} //判断类型是否一致
|
|
|
|
|
mType = type;
|
|
|
|
|
|
|
|
|
|
int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID)
|
|
|
|
|
: AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
|
|
|
if (mIsCreate || mWidgetId != widgetId) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId);
|
|
|
|
|
}
|
|
|
|
|
} //判断控件id是否一致
|
|
|
|
|
mWidgetId = widgetId;
|
|
|
|
|
|
|
|
|
|
int widgetType = note.has(NoteColumns.WIDGET_TYPE) ? note
|
|
|
|
@ -363,30 +393,33 @@ public class SqlNote {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JSONObject getContent() {
|
|
|
|
|
//功能描述:获取content机制提供的数据并加载到note中
|
|
|
|
|
|
|
|
|
|
public JSONObject getContent() { //获取content机制提供的数据并加载到note中
|
|
|
|
|
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();
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
|
note.put(NoteColumns.ID, mId);
|
|
|
|
|
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
|
|
|
|
|
note.put(NoteColumns.BG_COLOR_ID, mBgColorId);
|
|
|
|
|
note.put(NoteColumns.CREATED_DATE, mCreatedDate);
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) { //类型为note时//判断类型是否note类型
|
|
|
|
|
note.put(NoteColumns.ID, mId); //设置以下12个内部变量
|
|
|
|
|
note.put(NoteColumns.ALERTED_DATE, mAlertDate);//提醒时间
|
|
|
|
|
note.put(NoteColumns.BG_COLOR_ID, mBgColorId);//背景颜色
|
|
|
|
|
note.put(NoteColumns.CREATED_DATE, mCreatedDate);//创建日期
|
|
|
|
|
note.put(NoteColumns.HAS_ATTACHMENT, mHasAttachment);
|
|
|
|
|
note.put(NoteColumns.MODIFIED_DATE, mModifiedDate);
|
|
|
|
|
note.put(NoteColumns.MODIFIED_DATE, mModifiedDate);//修改日期
|
|
|
|
|
note.put(NoteColumns.PARENT_ID, mParentId);
|
|
|
|
|
note.put(NoteColumns.SNIPPET, mSnippet);
|
|
|
|
|
note.put(NoteColumns.TYPE, mType);
|
|
|
|
|
note.put(NoteColumns.SNIPPET, mSnippet);//摘要
|
|
|
|
|
note.put(NoteColumns.TYPE, mType);//类型
|
|
|
|
|
note.put(NoteColumns.WIDGET_ID, mWidgetId);
|
|
|
|
|
note.put(NoteColumns.WIDGET_TYPE, mWidgetType);
|
|
|
|
|
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
|
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
|
|
|
|
note.put(NoteColumns.WIDGET_TYPE, mWidgetType);//小部件类型
|
|
|
|
|
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);//最初的父类
|
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);;//将这个便签存入元数据中
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray dataArray = new JSONArray();
|
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
@ -396,12 +429,13 @@ public class SqlNote {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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.TYPE, mType);
|
|
|
|
|
note.put(NoteColumns.SNIPPET, mSnippet);
|
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
|
|
|
|
}
|
|
|
|
|
//对于文件夹类型或者系统文件夹类型,将id,类型,以及摘要,存入jsonobject,然后对应META_HEAD_NOTE键,存入共享,其实也只有那么多可以传输
|
|
|
|
|
|
|
|
|
|
return js;
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
@ -411,70 +445,88 @@ public class SqlNote {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:给当前id设置父id
|
|
|
|
|
|
|
|
|
|
public void setParentId(long id) {
|
|
|
|
|
mParentId = id;
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:给当前id设置Gtaskid
|
|
|
|
|
|
|
|
|
|
public void setGtaskId(String gid) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:给当前id设置同步id
|
|
|
|
|
|
|
|
|
|
public void setSyncId(long syncId) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:将本地修改初始化,即撤销当前所有修改
|
|
|
|
|
|
|
|
|
|
public void resetLocalModified() {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:获得当前id
|
|
|
|
|
|
|
|
|
|
public long getId() {
|
|
|
|
|
return mId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:获得当前id的父id
|
|
|
|
|
public long getParentId() {
|
|
|
|
|
return mParentId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:获取小片段,即用于显示的部分便签内容
|
|
|
|
|
public String getSnippet() {
|
|
|
|
|
return mSnippet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:判断是否为便签类型
|
|
|
|
|
public boolean isNoteType() {
|
|
|
|
|
return mType == Notes.TYPE_NOTE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//功能描述:commit函数,作用于把当前所做的修改传送并保存在数据库中
|
|
|
|
|
public void commit(boolean validateVersion) {
|
|
|
|
|
if (mIsCreate) {
|
|
|
|
|
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
|
|
|
|
|
mDiffNoteValues.remove(NoteColumns.ID);
|
|
|
|
|
//如果是一个无效的id并且还含有这个id,就将它移除
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
|
|
|
|
|
//插入便签的uri
|
|
|
|
|
try {
|
|
|
|
|
mId = Long.valueOf(uri.getPathSegments().get(1));
|
|
|
|
|
//强制转换path为id ,Long型
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
Log.e(TAG, "Get note id error :" + e.toString());
|
|
|
|
|
throw new ActionFailureException("create note failed");
|
|
|
|
|
}
|
|
|
|
|
} //捕获异常,转换出错,显示错误“获取note的id出现错误”
|
|
|
|
|
if (mId == 0) {
|
|
|
|
|
throw new IllegalStateException("Create thread id failed");
|
|
|
|
|
}
|
|
|
|
|
} //创建线程 id 失败
|
|
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) { //对于note类型,引用sqlData.commit
|
|
|
|
|
for (SqlData sqlData : mDataList) { //直接使用sqldata中实现
|
|
|
|
|
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");
|
|
|
|
|
Log.e(TAG, "No such note"); //判断是否含有这个便签
|
|
|
|
|
throw new IllegalStateException("Try to update note with invalid id");
|
|
|
|
|
//如果没有就是无效id
|
|
|
|
|
}
|
|
|
|
|
if (mDiffNoteValues.size() > 0) {
|
|
|
|
|
mVersion ++;
|
|
|
|
|
int result = 0;
|
|
|
|
|
if (!validateVersion) {
|
|
|
|
|
if (!validateVersion) { //构造字符串
|
|
|
|
|
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
|
|
|
|
|
+ NoteColumns.ID + "=?)", new String[] {
|
|
|
|
|
String.valueOf(mId)
|
|
|
|
@ -488,22 +540,23 @@ public class SqlNote {
|
|
|
|
|
}
|
|
|
|
|
if (result == 0) {
|
|
|
|
|
Log.w(TAG, "there is no update. maybe user updates note when syncing");
|
|
|
|
|
}
|
|
|
|
|
} //如果没有更新,可能是用户在同步的时候更新了
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
|
sqlData.commit(mId, validateVersion, mVersion);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} //对note类型,还是对其中的data引用commit,从而实现目的
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// refresh local info
|
|
|
|
|
//刷新本地信息
|
|
|
|
|
loadFromCursor(mId);
|
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
|
loadDataContent();
|
|
|
|
|
loadDataContent(); //如果是便签类型,获取共享数据并加载到数据库
|
|
|
|
|
|
|
|
|
|
mDiffNoteValues.clear();
|
|
|
|
|
mIsCreate = false;
|
|
|
|
|
mDiffNoteValues.clear(); //清空共享数据
|
|
|
|
|
mIsCreate = false; //重置
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|