|
|
@ -52,7 +52,7 @@ public class WorkingNote {
|
|
|
|
// Note for the working note
|
|
|
|
// Note for the working note
|
|
|
|
|
|
|
|
|
|
|
|
private String mPassword;
|
|
|
|
private String mPassword;
|
|
|
|
private Note mNote;//这个在Note里面定义了Note类的基本类型,
|
|
|
|
//这个在Note里面定义了Note类的基本类型,
|
|
|
|
// Note Id
|
|
|
|
// Note Id
|
|
|
|
private long mNoteId;
|
|
|
|
private long mNoteId;
|
|
|
|
// Note content
|
|
|
|
// Note content
|
|
|
@ -134,6 +134,14 @@ public class WorkingNote {
|
|
|
|
|
|
|
|
|
|
|
|
// New note construct
|
|
|
|
// New note construct
|
|
|
|
//初始化一个新的操作的Note
|
|
|
|
//初始化一个新的操作的Note
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method: WorkingNote
|
|
|
|
|
|
|
|
* @description: 初始化一个新的操作的Note
|
|
|
|
|
|
|
|
* @date: 2024/1/6 11:28
|
|
|
|
|
|
|
|
* @author: 周石宇
|
|
|
|
|
|
|
|
* @param: [android.content.Context, long]:[context, folderId]
|
|
|
|
|
|
|
|
* @return:
|
|
|
|
|
|
|
|
*/
|
|
|
|
private WorkingNote(Context context, long folderId) {
|
|
|
|
private WorkingNote(Context context, long folderId) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mAlertDate = 0;//这里为什么是0还存疑
|
|
|
|
mAlertDate = 0;//这里为什么是0还存疑
|
|
|
@ -191,7 +199,14 @@ public class WorkingNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadNoteData();
|
|
|
|
loadNoteData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//基本同上一个函数。值得注意的是这里对数据进行了筛选(通过selection),还对MIME进行了判断后加载
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method: loadNoteData
|
|
|
|
|
|
|
|
* @description: 基本同上一个函数。值得注意的是这里对数据进行了筛选(通过selection),还对MIME进行了判断后加载
|
|
|
|
|
|
|
|
* @date: 2024/1/6 11:29
|
|
|
|
|
|
|
|
* @author: 周石宇
|
|
|
|
|
|
|
|
* @param: []:[]
|
|
|
|
|
|
|
|
* @return: void
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void loadNoteData() {
|
|
|
|
private void loadNoteData() {
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
|
|
|
|
DataColumns.NOTE_ID + "=?", new String[] {
|
|
|
|
DataColumns.NOTE_ID + "=?", new String[] {
|
|
|
@ -199,15 +214,21 @@ public class WorkingNote {
|
|
|
|
}, null);
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
|
|
|
|
if (cursor != null) {
|
|
|
|
if (cursor != null) {
|
|
|
|
|
|
|
|
// 检查是否有数据
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
|
|
|
|
// 获取类型
|
|
|
|
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
|
|
|
|
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
|
|
|
|
if (DataConstants.NOTE.equals(type)) {
|
|
|
|
if (DataConstants.NOTE.equals(type)) {
|
|
|
|
|
|
|
|
// 获取内容
|
|
|
|
mContent = cursor.getString(DATA_CONTENT_COLUMN);
|
|
|
|
mContent = cursor.getString(DATA_CONTENT_COLUMN);
|
|
|
|
|
|
|
|
// 获取模式
|
|
|
|
mMode = cursor.getInt(DATA_MODE_COLUMN);
|
|
|
|
mMode = cursor.getInt(DATA_MODE_COLUMN);
|
|
|
|
|
|
|
|
// 获取ID
|
|
|
|
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
|
|
|
|
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
} else if (DataConstants.CALL_NOTE.equals(type)) {
|
|
|
|
} else if (DataConstants.CALL_NOTE.equals(type)) {
|
|
|
|
|
|
|
|
// 设置通话ID
|
|
|
|
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
|
|
|
|
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Log.d(TAG, "Wrong note type with type:" + type);
|
|
|
|
Log.d(TAG, "Wrong note type with type:" + type);
|
|
|
@ -221,12 +242,27 @@ public class WorkingNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//简单的初始化函数,一会看一下用法
|
|
|
|
//简单的初始化函数,一会看一下用法
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method: createEmptyNote
|
|
|
|
|
|
|
|
* @description: 创建一个空的笔记
|
|
|
|
|
|
|
|
* @date: 2024/1/2 10:21
|
|
|
|
|
|
|
|
* @author: 周石宇
|
|
|
|
|
|
|
|
* @param: [android.content.Context, long, int, int, int]:[context, folderId, widgetId, widgetType, defaultBgColorId]
|
|
|
|
|
|
|
|
* @return: net.micode.notes.model.WorkingNote
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
|
|
|
|
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
|
|
|
|
int widgetType, int defaultBgColorId) {
|
|
|
|
int widgetType, int defaultBgColorId) {
|
|
|
|
|
|
|
|
// 创建一个新的WorkingNote实例
|
|
|
|
WorkingNote note = new WorkingNote(context, folderId);
|
|
|
|
WorkingNote note = new WorkingNote(context, folderId);
|
|
|
|
|
|
|
|
// 设置笔记的背景颜色
|
|
|
|
note.setBgColorId(defaultBgColorId);
|
|
|
|
note.setBgColorId(defaultBgColorId);
|
|
|
|
|
|
|
|
// 设置笔记的widgetId
|
|
|
|
note.setWidgetId(widgetId);
|
|
|
|
note.setWidgetId(widgetId);
|
|
|
|
|
|
|
|
// 设置笔记的widgetType
|
|
|
|
note.setWidgetType(widgetType);
|
|
|
|
note.setWidgetType(widgetType);
|
|
|
|
|
|
|
|
// 返回新的WorkingNote实例
|
|
|
|
return note;
|
|
|
|
return note;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -234,9 +270,21 @@ public class WorkingNote {
|
|
|
|
return new WorkingNote(context, id, 0);
|
|
|
|
return new WorkingNote(context, id, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//这里涉及了多线程的操作。
|
|
|
|
//这里涉及了多线程的操作。
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method: saveNote
|
|
|
|
|
|
|
|
* @description: 保存笔记
|
|
|
|
|
|
|
|
* @date: 2024/1/2 10:23
|
|
|
|
|
|
|
|
* @author: 周石宇
|
|
|
|
|
|
|
|
* @param: []:[]
|
|
|
|
|
|
|
|
* @return: boolean
|
|
|
|
|
|
|
|
*/
|
|
|
|
public synchronized boolean saveNote() {
|
|
|
|
public synchronized boolean saveNote() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果笔记 worth saving
|
|
|
|
if (isWorthSaving()) {
|
|
|
|
if (isWorthSaving()) {
|
|
|
|
|
|
|
|
// 如果笔记不存在数据库中
|
|
|
|
if (!existInDatabase()) {
|
|
|
|
if (!existInDatabase()) {
|
|
|
|
|
|
|
|
// 获取新笔记id
|
|
|
|
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
|
|
|
|
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
|
|
|
|
Log.e(TAG, "Create new note fail with id:" + mNoteId);
|
|
|
|
Log.e(TAG, "Create new note fail with id:" + mNoteId);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -269,6 +317,14 @@ public class WorkingNote {
|
|
|
|
return mNoteId > 0;
|
|
|
|
return mNoteId > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method: isWorthSaving
|
|
|
|
|
|
|
|
* @description: 判断是否值得保存,即判断是否需要保存到数据库
|
|
|
|
|
|
|
|
* @date: 2024/1/2 10:24
|
|
|
|
|
|
|
|
* @author: 周石宇
|
|
|
|
|
|
|
|
* @param: []:[]
|
|
|
|
|
|
|
|
* @return: boolean
|
|
|
|
|
|
|
|
*/
|
|
|
|
private boolean isWorthSaving() {
|
|
|
|
private boolean isWorthSaving() {
|
|
|
|
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|
|
|
|
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|
|
|
|
|| (existInDatabase() && !mNote.isLocalModified())) {
|
|
|
|
|| (existInDatabase() && !mNote.isLocalModified())) {
|
|
|
@ -277,7 +333,15 @@ public class WorkingNote {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//这个变量设置是用来记录状态设定是否有发生过更改。
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method: setOnSettingStatusChangedListener
|
|
|
|
|
|
|
|
* @description: 用来记录状态设定是否有发生过更改。
|
|
|
|
|
|
|
|
* @date: 2024/1/2 10:24
|
|
|
|
|
|
|
|
* @author: 周石宇
|
|
|
|
|
|
|
|
* @param: [net.micode.notes.model.WorkingNote.NoteSettingChangedListener]:[l]
|
|
|
|
|
|
|
|
* @return: void
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
|
|
|
|
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
|
|
|
|
mNoteSettingStatusListener = l;
|
|
|
|
mNoteSettingStatusListener = l;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -309,7 +373,14 @@ public class WorkingNote {
|
|
|
|
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
|
|
|
|
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//在EditActivities中使用,用来设定在list时的状态
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @method: setCheckListMode
|
|
|
|
|
|
|
|
* @description: 在EditActivities中使用,用来设定在list时的状态
|
|
|
|
|
|
|
|
* @date: 2024/1/6 11:30
|
|
|
|
|
|
|
|
* @author: 周石宇
|
|
|
|
|
|
|
|
* @param: [int]:[mode]
|
|
|
|
|
|
|
|
* @return: void
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void setCheckListMode(int mode) {
|
|
|
|
public void setCheckListMode(int mode) {
|
|
|
|
if (mMode != mode) {
|
|
|
|
if (mMode != mode) {
|
|
|
|
if (mNoteSettingStatusListener != null) {
|
|
|
|
if (mNoteSettingStatusListener != null) {
|
|
|
|