|
|
|
@ -122,7 +122,7 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
|
|
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
|
public SqlNote(Context context) {//定义数据单元存储数据
|
|
|
|
|
mContext = context;
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
|
mIsCreate = true;
|
|
|
|
@ -135,7 +135,7 @@ public class SqlNote {
|
|
|
|
|
mParentId = 0;
|
|
|
|
|
mSnippet = "";
|
|
|
|
|
mType = Notes.TYPE_NOTE;
|
|
|
|
|
mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
|
|
|
mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;//直接从设置的属性中获取值
|
|
|
|
|
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
|
|
|
|
|
mOriginParent = 0;
|
|
|
|
|
mVersion = 0;
|
|
|
|
@ -147,14 +147,14 @@ public class SqlNote {
|
|
|
|
|
mContext = context;
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
|
mIsCreate = false;
|
|
|
|
|
loadFromCursor(c);
|
|
|
|
|
loadFromCursor(c);//从cursor中直接获取变量值
|
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
|
loadDataContent();
|
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SqlNote(Context context, long id) {
|
|
|
|
|
public SqlNote(Context context, long id) {//根据id初始化数据单元
|
|
|
|
|
mContext = context;
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
|
mIsCreate = false;
|
|
|
|
@ -175,7 +175,7 @@ public class SqlNote {
|
|
|
|
|
}, null);
|
|
|
|
|
if (c != null) {
|
|
|
|
|
c.moveToNext();
|
|
|
|
|
loadFromCursor(c);
|
|
|
|
|
loadFromCursor(c);//通过调用减少重复代码编写
|
|
|
|
|
} else {
|
|
|
|
|
Log.w(TAG, "loadFromCursor: cursor = null");
|
|
|
|
|
}
|
|
|
|
@ -185,7 +185,7 @@ public class SqlNote {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadFromCursor(Cursor c) {
|
|
|
|
|
private void loadFromCursor(Cursor c) {//直接使用get获得变量值
|
|
|
|
|
mId = c.getLong(ID_COLUMN);
|
|
|
|
|
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
|
|
|
|
|
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
|
|
|
|
@ -200,7 +200,7 @@ public class SqlNote {
|
|
|
|
|
mVersion = c.getLong(VERSION_COLUMN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadDataContent() {
|
|
|
|
|
private void loadDataContent() {//这个函数判别查询的数据是否存在,并且读取到数据列表中存储
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
mDataList.clear();
|
|
|
|
|
try {
|
|
|
|
@ -210,12 +210,12 @@ public class SqlNote {
|
|
|
|
|
}, null);
|
|
|
|
|
if (c != null) {
|
|
|
|
|
if (c.getCount() == 0) {
|
|
|
|
|
Log.w(TAG, "it seems that the note has not data");
|
|
|
|
|
Log.w(TAG, "it seems that the note has not data");//遇到文件为空抛出对应的异常
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while (c.moveToNext()) {
|
|
|
|
|
SqlData data = new SqlData(mContext, c);
|
|
|
|
|
mDataList.add(data);
|
|
|
|
|
mDataList.add(data);//向Datalist中加入读取到的数据
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Log.w(TAG, "loadDataContent: cursor = null");
|
|
|
|
@ -226,7 +226,8 @@ public class SqlNote {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
|
public boolean setContent(JSONObject js) {//设置数据单元中变量的值
|
|
|
|
|
//如果所需的值存在,直接赋值使用,否则再先进行一步读取
|
|
|
|
|
try {
|
|
|
|
|
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
|
|
|
|
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
|
|
|
|
@ -359,7 +360,7 @@ public class SqlNote {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JSONObject getContent() {
|
|
|
|
|
public JSONObject getContent() {//直接读取的方式将所需的数据读到对应变量
|
|
|
|
|
try {
|
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
|
|
|
|
@ -412,6 +413,7 @@ public class SqlNote {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//定义一些简单的获取取值的方法
|
|
|
|
|
public void setGtaskId(String gid) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
|
|
|
|
}
|
|
|
|
@ -440,7 +442,7 @@ public class SqlNote {
|
|
|
|
|
return mType == Notes.TYPE_NOTE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void commit(boolean validateVersion) {
|
|
|
|
|
public void commit(boolean validateVersion) {//将数据做一定修改提交
|
|
|
|
|
if (mIsCreate) {
|
|
|
|
|
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
|
|
|
|
|
mDiffNoteValues.remove(NoteColumns.ID);
|
|
|
|
|