|
|
|
@ -124,11 +124,14 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
loadNote();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载Note
|
|
|
|
|
private void loadNote() {
|
|
|
|
|
// 通过数据库调用query函数找到第一个条目
|
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(
|
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
|
|
|
|
|
null, null);
|
|
|
|
|
|
|
|
|
|
// 若存在,储存相应信息
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
|
|
|
|
@ -139,21 +142,26 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
|
|
|
|
|
}
|
|
|
|
|
cursor.close();
|
|
|
|
|
// 若不存在,报错
|
|
|
|
|
} else {
|
|
|
|
|
Log.e(TAG, "No note with id:" + mNoteId);
|
|
|
|
|
throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
|
|
|
|
|
}
|
|
|
|
|
// 加载NoteData
|
|
|
|
|
loadNoteData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载NoteData
|
|
|
|
|
private void loadNoteData() {
|
|
|
|
|
// 通过数据库调用query函数找到第一个条目
|
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
|
|
|
|
|
DataColumns.NOTE_ID + "=?", new String[] {
|
|
|
|
|
String.valueOf(mNoteId)
|
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
|
|
// 查到信息不为空
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
if (cursor.moveToFirst()) {// 查看第一项是否存在
|
|
|
|
|
do {
|
|
|
|
|
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
|
|
|
|
|
if (DataConstants.NOTE.equals(type)) {
|
|
|
|
@ -165,15 +173,18 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
} else {
|
|
|
|
|
Log.d(TAG, "Wrong note type with type:" + type);
|
|
|
|
|
}
|
|
|
|
|
} while (cursor.moveToNext());
|
|
|
|
|
} while (cursor.moveToNext());//查阅所有项,直到为空
|
|
|
|
|
}
|
|
|
|
|
cursor.close();
|
|
|
|
|
// 若不存在,报错
|
|
|
|
|
} else {
|
|
|
|
|
Log.e(TAG, "No data with id:" + mNoteId);
|
|
|
|
|
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建空的Note
|
|
|
|
|
// 传参:context,文件夹id,小部件ID,背景颜色
|
|
|
|
|
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
|
|
|
|
|
int widgetType, int defaultBgColorId) {
|
|
|
|
|
WorkingNote note = new WorkingNote(context, folderId);
|
|
|
|
@ -183,13 +194,15 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
return note;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//构造函数是私有的。用load函数调用构造函数
|
|
|
|
|
public static WorkingNote load(Context context, long id) {
|
|
|
|
|
return new WorkingNote(context, id, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存Note
|
|
|
|
|
public synchronized boolean saveNote() {
|
|
|
|
|
if (isWorthSaving()) {
|
|
|
|
|
if (!existInDatabase()) {
|
|
|
|
|
if (isWorthSaving()) {//是否值得保存
|
|
|
|
|
if (!existInDatabase()) { // 是否存在数据库中
|
|
|
|
|
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
|
|
|
|
|
Log.e(TAG, "Create new note fail with id:" + mNoteId);
|
|
|
|
|
return false;
|
|
|
|
@ -200,6 +213,7 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update widget content if there exist any widget of this note
|
|
|
|
|
* 存在则更新
|
|
|
|
|
*/
|
|
|
|
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
|
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
|
|
|
|
@ -212,11 +226,14 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否在数据库中存在
|
|
|
|
|
public boolean existInDatabase() {
|
|
|
|
|
return mNoteId > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否值得保存
|
|
|
|
|
private boolean isWorthSaving() {
|
|
|
|
|
// 被删除,或(不在数据库中 内容为空),或本地已保存过
|
|
|
|
|
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|
|
|
|
|
|| (existInDatabase() && !mNote.isLocalModified())) {
|
|
|
|
|
return false;
|
|
|
|
@ -225,6 +242,7 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 便签更新监视
|
|
|
|
|
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
|
|
|
|
|
mNoteSettingStatusListener = l;
|
|
|
|
|
}
|
|
|
|
@ -239,6 +257,7 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除标记
|
|
|
|
|
public void markDeleted(boolean mark) {
|
|
|
|
|
mIsDeleted = mark;
|
|
|
|
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
@ -247,6 +266,7 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//背景颜色
|
|
|
|
|
public void setBgColorId(int id) {
|
|
|
|
|
if (id != mBgColorId) {
|
|
|
|
|
mBgColorId = id;
|
|
|
|
@ -267,6 +287,7 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//小部件类型
|
|
|
|
|
public void setWidgetType(int type) {
|
|
|
|
|
if (type != mWidgetType) {
|
|
|
|
|
mWidgetType = type;
|
|
|
|
@ -274,6 +295,7 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//小部件ID
|
|
|
|
|
public void setWidgetId(int id) {
|
|
|
|
|
if (id != mWidgetId) {
|
|
|
|
|
mWidgetId = id;
|
|
|
|
@ -342,6 +364,8 @@ public class WorkingNote {//当前活动便签项
|
|
|
|
|
return mWidgetType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建接口 NoteSettingChangedListener,便签更新监视
|
|
|
|
|
// 为NoteEditActivity提供接口
|
|
|
|
|
public interface NoteSettingChangedListener {
|
|
|
|
|
/**
|
|
|
|
|
* Called when the background color of current note has just changed
|
|
|
|
|