|
|
|
@ -31,37 +31,37 @@ import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
import net.micode.notes.data.Notes.TextNote;
|
|
|
|
|
import net.micode.notes.tool.ResourceParser.NoteBgResources;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 表示正在编辑或处理的笔记的类
|
|
|
|
|
public class WorkingNote {
|
|
|
|
|
// Note for the working note
|
|
|
|
|
// 笔记对象
|
|
|
|
|
private Note mNote;
|
|
|
|
|
// Note Id
|
|
|
|
|
// 笔记的 ID
|
|
|
|
|
private long mNoteId;
|
|
|
|
|
// Note content
|
|
|
|
|
// 笔记的内容
|
|
|
|
|
private String mContent;
|
|
|
|
|
// Note mode
|
|
|
|
|
// 笔记的模式
|
|
|
|
|
private int mMode;
|
|
|
|
|
|
|
|
|
|
// 提醒日期
|
|
|
|
|
private long mAlertDate;
|
|
|
|
|
|
|
|
|
|
// 最后修改日期
|
|
|
|
|
private long mModifiedDate;
|
|
|
|
|
|
|
|
|
|
// 背景颜色 ID
|
|
|
|
|
private int mBgColorId;
|
|
|
|
|
|
|
|
|
|
// 小部件的 ID
|
|
|
|
|
private int mWidgetId;
|
|
|
|
|
|
|
|
|
|
// 小部件的类型
|
|
|
|
|
private int mWidgetType;
|
|
|
|
|
|
|
|
|
|
// 笔记所在的文件夹 ID
|
|
|
|
|
private long mFolderId;
|
|
|
|
|
|
|
|
|
|
// 上下文对象
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
|
|
// 日志标记
|
|
|
|
|
private static final String TAG = "WorkingNote";
|
|
|
|
|
|
|
|
|
|
// 笔记是否已删除
|
|
|
|
|
private boolean mIsDeleted;
|
|
|
|
|
|
|
|
|
|
// 笔记设置变更监听器
|
|
|
|
|
private NoteSettingChangedListener mNoteSettingStatusListener;
|
|
|
|
|
|
|
|
|
|
// 数据投影,用于查询笔记数据时指定要查询的列
|
|
|
|
|
public static final String[] DATA_PROJECTION = new String[] {
|
|
|
|
|
DataColumns.ID,
|
|
|
|
|
DataColumns.CONTENT,
|
|
|
|
@ -71,7 +71,7 @@ public class WorkingNote {
|
|
|
|
|
DataColumns.DATA3,
|
|
|
|
|
DataColumns.DATA4,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 笔记投影,用于查询笔记时指定要查询的列
|
|
|
|
|
public static final String[] NOTE_PROJECTION = new String[] {
|
|
|
|
|
NoteColumns.PARENT_ID,
|
|
|
|
|
NoteColumns.ALERTED_DATE,
|
|
|
|
@ -80,7 +80,7 @@ public class WorkingNote {
|
|
|
|
|
NoteColumns.WIDGET_TYPE,
|
|
|
|
|
NoteColumns.MODIFIED_DATE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 数据投影中各列的索引
|
|
|
|
|
private static final int DATA_ID_COLUMN = 0;
|
|
|
|
|
|
|
|
|
|
private static final int DATA_CONTENT_COLUMN = 1;
|
|
|
|
@ -88,7 +88,7 @@ public class WorkingNote {
|
|
|
|
|
private static final int DATA_MIME_TYPE_COLUMN = 2;
|
|
|
|
|
|
|
|
|
|
private static final int DATA_MODE_COLUMN = 3;
|
|
|
|
|
|
|
|
|
|
// 笔记投影中各列的索引
|
|
|
|
|
private static final int NOTE_PARENT_ID_COLUMN = 0;
|
|
|
|
|
|
|
|
|
|
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
|
|
|
|
@ -101,20 +101,22 @@ public class WorkingNote {
|
|
|
|
|
|
|
|
|
|
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
|
|
|
|
|
|
|
|
|
|
// New note construct
|
|
|
|
|
// 创建新笔记的构造函数
|
|
|
|
|
private WorkingNote(Context context, long folderId) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
mAlertDate = 0;
|
|
|
|
|
//初始化修改日期为当前系统时间
|
|
|
|
|
mModifiedDate = System.currentTimeMillis();
|
|
|
|
|
mFolderId = folderId;
|
|
|
|
|
mNote = new Note();
|
|
|
|
|
mNoteId = 0;
|
|
|
|
|
// 标记笔记未删除
|
|
|
|
|
mIsDeleted = false;
|
|
|
|
|
mMode = 0;
|
|
|
|
|
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Existing note construct
|
|
|
|
|
// 加载现有笔记的构造函数
|
|
|
|
|
private WorkingNote(Context context, long noteId, long folderId) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
mNoteId = noteId;
|
|
|
|
@ -123,18 +125,25 @@ public class WorkingNote {
|
|
|
|
|
mNote = new Note();
|
|
|
|
|
loadNote();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载笔记的方法,从数据库中查询笔记的基本信息
|
|
|
|
|
private void loadNote() {
|
|
|
|
|
// 1. 通过 ContentResolver 查询笔记信息,使用 NOTE_PROJECTION 投影指定要查询的列
|
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(
|
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
|
|
|
|
|
null, null);
|
|
|
|
|
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
// 2. 将游标移动到第一个结果
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
// 3. 从游标中读取并存储父文件夹 ID
|
|
|
|
|
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
|
|
|
|
|
// 4. 从游标中读取并存储背景颜色 ID
|
|
|
|
|
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
|
|
|
|
|
// 5. 从游标中读取并存储小部件 ID
|
|
|
|
|
mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
|
|
|
|
|
// 6. 从游标中读取并存储小部件类型
|
|
|
|
|
mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
|
|
|
|
|
// 7. 从游标中读取并存储提醒日期
|
|
|
|
|
mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
|
|
|
|
|
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
|
|
|
|
|
}
|
|
|
|
@ -145,24 +154,30 @@ public class WorkingNote {
|
|
|
|
|
}
|
|
|
|
|
loadNoteData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载笔记的数据,从数据库中查询笔记的数据信息
|
|
|
|
|
private void loadNoteData() {
|
|
|
|
|
// 1. 通过 ContentResolver 查询笔记数据,使用 DATA_PROJECTION 投影指定要查询的列,并通过 NOTE_ID 筛选
|
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
|
|
|
|
|
DataColumns.NOTE_ID + "=?", new String[] {
|
|
|
|
|
String.valueOf(mNoteId)
|
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
// 2. 将游标移动到第一个结果
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
do {
|
|
|
|
|
// 3. 读取数据的 MIME 类型
|
|
|
|
|
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
|
|
|
|
|
if (DataConstants.NOTE.equals(type)) {
|
|
|
|
|
// 4. 如果是普通笔记,存储内容和模式,并设置文本数据的 ID
|
|
|
|
|
mContent = cursor.getString(DATA_CONTENT_COLUMN);
|
|
|
|
|
mMode = cursor.getInt(DATA_MODE_COLUMN);
|
|
|
|
|
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
|
|
|
|
|
} else if (DataConstants.CALL_NOTE.equals(type)) {
|
|
|
|
|
// 5. 如果是通话笔记,设置通话数据的 ID
|
|
|
|
|
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
|
|
|
|
|
} else {
|
|
|
|
|
// 6. 对于不识别的类型,打印调试日志
|
|
|
|
|
Log.d(TAG, "Wrong note type with type:" + type);
|
|
|
|
|
}
|
|
|
|
|
} while (cursor.moveToNext());
|
|
|
|
@ -173,7 +188,7 @@ public class WorkingNote {
|
|
|
|
|
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建一个空的笔记
|
|
|
|
|
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
|
|
|
|
|
int widgetType, int defaultBgColorId) {
|
|
|
|
|
WorkingNote note = new WorkingNote(context, folderId);
|
|
|
|
@ -182,24 +197,25 @@ public class WorkingNote {
|
|
|
|
|
note.setWidgetType(widgetType);
|
|
|
|
|
return note;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从数据库加载一个笔记
|
|
|
|
|
public static WorkingNote load(Context context, long id) {
|
|
|
|
|
return new WorkingNote(context, id, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存笔记到数据库
|
|
|
|
|
public synchronized boolean saveNote() {
|
|
|
|
|
if (isWorthSaving()) {
|
|
|
|
|
if (!existInDatabase()) {
|
|
|
|
|
// 如果笔记不存在于数据库中,创建一个新的笔记 ID
|
|
|
|
|
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
|
|
|
|
|
Log.e(TAG, "Create new note fail with id:" + mNoteId);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 调用 Note 对象的 syncNote 方法同步笔记信息
|
|
|
|
|
mNote.syncNote(mContext, mNoteId);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update widget content if there exist any widget of this note
|
|
|
|
|
/**
|
|
|
|
|
* 如果笔记有小部件,更新小部件的内容
|
|
|
|
|
*/
|
|
|
|
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
|
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
|
|
|
|
@ -212,11 +228,13 @@ public class WorkingNote {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查笔记是否存在于数据库中
|
|
|
|
|
public boolean existInDatabase() {
|
|
|
|
|
return mNoteId > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断笔记是否值得保存
|
|
|
|
|
private boolean isWorthSaving() {
|
|
|
|
|
// 1. 判断笔记是否已删除,或者如果笔记不存在且内容为空,或者笔记存在但未被本地修改,则不值得保存
|
|
|
|
|
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|
|
|
|
|
|| (existInDatabase() && !mNote.isLocalModified())) {
|
|
|
|
|
return false;
|
|
|
|
@ -224,11 +242,11 @@ public class WorkingNote {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置笔记设置变更监听器
|
|
|
|
|
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
|
|
|
|
|
mNoteSettingStatusListener = l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置提醒日期
|
|
|
|
|
public void setAlertDate(long date, boolean set) {
|
|
|
|
|
if (date != mAlertDate) {
|
|
|
|
|
mAlertDate = date;
|
|
|
|
@ -238,7 +256,7 @@ public class WorkingNote {
|
|
|
|
|
mNoteSettingStatusListener.onClockAlertChanged(date, set);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 标记笔记是否已删除
|
|
|
|
|
public void markDeleted(boolean mark) {
|
|
|
|
|
mIsDeleted = mark;
|
|
|
|
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
@ -246,7 +264,7 @@ public class WorkingNote {
|
|
|
|
|
mNoteSettingStatusListener.onWidgetChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置背景颜色 ID
|
|
|
|
|
public void setBgColorId(int id) {
|
|
|
|
|
if (id != mBgColorId) {
|
|
|
|
|
mBgColorId = id;
|
|
|
|
@ -256,7 +274,7 @@ public class WorkingNote {
|
|
|
|
|
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置检查列表模式
|
|
|
|
|
public void setCheckListMode(int mode) {
|
|
|
|
|
if (mMode != mode) {
|
|
|
|
|
if (mNoteSettingStatusListener != null) {
|
|
|
|
@ -266,102 +284,102 @@ public class WorkingNote {
|
|
|
|
|
mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置小部件类型
|
|
|
|
|
public void setWidgetType(int type) {
|
|
|
|
|
if (type != mWidgetType) {
|
|
|
|
|
mWidgetType = type;
|
|
|
|
|
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置小部件 ID
|
|
|
|
|
public void setWidgetId(int id) {
|
|
|
|
|
if (id != mWidgetId) {
|
|
|
|
|
mWidgetId = id;
|
|
|
|
|
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置笔记的工作文本
|
|
|
|
|
public void setWorkingText(String text) {
|
|
|
|
|
if (!TextUtils.equals(mContent, text)) {
|
|
|
|
|
mContent = text;
|
|
|
|
|
mNote.setTextData(DataColumns.CONTENT, mContent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将笔记转换为通话笔记
|
|
|
|
|
public void convertToCallNote(String phoneNumber, long callDate) {
|
|
|
|
|
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
|
|
|
|
|
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
|
|
|
|
|
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查是否有闹钟提醒
|
|
|
|
|
public boolean hasClockAlert() {
|
|
|
|
|
return (mAlertDate > 0 ? true : false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取笔记内容
|
|
|
|
|
public String getContent() {
|
|
|
|
|
return mContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取提醒日期
|
|
|
|
|
public long getAlertDate() {
|
|
|
|
|
return mAlertDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取最后修改日期
|
|
|
|
|
public long getModifiedDate() {
|
|
|
|
|
return mModifiedDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取背景颜色的资源 ID
|
|
|
|
|
public int getBgColorResId() {
|
|
|
|
|
return NoteBgResources.getNoteBgResource(mBgColorId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取背景颜色 ID
|
|
|
|
|
public int getBgColorId() {
|
|
|
|
|
return mBgColorId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取标题背景的资源 ID
|
|
|
|
|
public int getTitleBgResId() {
|
|
|
|
|
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取检查列表模式
|
|
|
|
|
public int getCheckListMode() {
|
|
|
|
|
return mMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取笔记 ID
|
|
|
|
|
public long getNoteId() {
|
|
|
|
|
return mNoteId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取文件夹 ID
|
|
|
|
|
public long getFolderId() {
|
|
|
|
|
return mFolderId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取小部件 ID
|
|
|
|
|
public int getWidgetId() {
|
|
|
|
|
return mWidgetId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取小部件类型
|
|
|
|
|
public int getWidgetType() {
|
|
|
|
|
return mWidgetType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 笔记设置变更监听器接口
|
|
|
|
|
public interface NoteSettingChangedListener {
|
|
|
|
|
/**
|
|
|
|
|
* Called when the background color of current note has just changed
|
|
|
|
|
/**
|
|
|
|
|
* 当笔记的背景颜色发生变化时调用
|
|
|
|
|
*/
|
|
|
|
|
void onBackgroundColorChanged();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when user set clock
|
|
|
|
|
/**
|
|
|
|
|
* 当用户设置闹钟时调用
|
|
|
|
|
*/
|
|
|
|
|
void onClockAlertChanged(long date, boolean set);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call when user create note from widget
|
|
|
|
|
* 当用户从小部件创建笔记时调用
|
|
|
|
|
*/
|
|
|
|
|
void onWidgetChanged();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call when switch between check list mode and normal mode
|
|
|
|
|
* @param oldMode is previous mode before change
|
|
|
|
|
* @param newMode is new mode
|
|
|
|
|
/**
|
|
|
|
|
* 当在检查列表模式和普通模式之间切换时调用
|
|
|
|
|
* @param oldMode 切换前的模式
|
|
|
|
|
* @param newMode 切换后的模式
|
|
|
|
|
*/
|
|
|
|
|
void onCheckListModeChanged(int oldMode, int newMode);
|
|
|
|
|
}
|
|
|
|
|