|
|
|
@ -31,77 +31,91 @@ import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
import net.micode.notes.data.Notes.TextNote;
|
|
|
|
|
import net.micode.notes.tool.ResourceParser.NoteBgResources;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WorkingNote 是用于编辑和管理单个笔记的核心类,支持新建、加载、保存笔记及其相关数据。
|
|
|
|
|
* 它封装了与 ContentProvider 的交互逻辑,并提供了设置更改监听器以响应用户操作。
|
|
|
|
|
*/
|
|
|
|
|
public class WorkingNote {
|
|
|
|
|
// Note for the working note
|
|
|
|
|
private Note mNote;
|
|
|
|
|
// Note Id
|
|
|
|
|
private long mNoteId;
|
|
|
|
|
// Note content
|
|
|
|
|
private String mContent;
|
|
|
|
|
// Note mode
|
|
|
|
|
private int mMode;
|
|
|
|
|
|
|
|
|
|
private long mAlertDate;
|
|
|
|
|
|
|
|
|
|
private long mModifiedDate;
|
|
|
|
|
|
|
|
|
|
private int mBgColorId;
|
|
|
|
|
|
|
|
|
|
private int mWidgetId;
|
|
|
|
|
|
|
|
|
|
private int mWidgetType;
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
DataColumns.MIME_TYPE,
|
|
|
|
|
DataColumns.DATA1,
|
|
|
|
|
DataColumns.DATA2,
|
|
|
|
|
DataColumns.DATA3,
|
|
|
|
|
DataColumns.DATA4,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static final String[] NOTE_PROJECTION = new String[] {
|
|
|
|
|
NoteColumns.PARENT_ID,
|
|
|
|
|
NoteColumns.ALERTED_DATE,
|
|
|
|
|
NoteColumns.BG_COLOR_ID,
|
|
|
|
|
NoteColumns.WIDGET_ID,
|
|
|
|
|
NoteColumns.WIDGET_TYPE,
|
|
|
|
|
NoteColumns.MODIFIED_DATE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static final int DATA_ID_COLUMN = 0;
|
|
|
|
|
|
|
|
|
|
private static final int DATA_CONTENT_COLUMN = 1;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
|
|
|
|
|
|
|
|
|
|
private static final int NOTE_WIDGET_ID_COLUMN = 3;
|
|
|
|
|
|
|
|
|
|
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
|
|
|
|
|
|
|
|
|
|
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
|
|
|
|
|
|
|
|
|
|
// New note construct
|
|
|
|
|
/** 笔记对象,用于管理主表和内容数据 */
|
|
|
|
|
private Note mNote;
|
|
|
|
|
|
|
|
|
|
/** 当前笔记的 ID */
|
|
|
|
|
private long mNoteId;
|
|
|
|
|
|
|
|
|
|
/** 笔记内容文本 */
|
|
|
|
|
private String mContent;
|
|
|
|
|
|
|
|
|
|
/** 编辑模式(如普通笔记、清单等) */
|
|
|
|
|
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,
|
|
|
|
|
DataColumns.MIME_TYPE,
|
|
|
|
|
DataColumns.DATA1,
|
|
|
|
|
DataColumns.DATA2,
|
|
|
|
|
DataColumns.DATA3,
|
|
|
|
|
DataColumns.DATA4,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** 查询笔记表时使用的列投影数组 */
|
|
|
|
|
public static final String[] NOTE_PROJECTION = new String[] {
|
|
|
|
|
NoteColumns.PARENT_ID,
|
|
|
|
|
NoteColumns.ALERTED_DATE,
|
|
|
|
|
NoteColumns.BG_COLOR_ID,
|
|
|
|
|
NoteColumns.WIDGET_ID,
|
|
|
|
|
NoteColumns.WIDGET_TYPE,
|
|
|
|
|
NoteColumns.MODIFIED_DATE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** 列索引定义 */
|
|
|
|
|
private static final int DATA_ID_COLUMN = 0;
|
|
|
|
|
private static final int DATA_CONTENT_COLUMN = 1;
|
|
|
|
|
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;
|
|
|
|
|
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
|
|
|
|
|
private static final int NOTE_WIDGET_ID_COLUMN = 3;
|
|
|
|
|
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
|
|
|
|
|
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
|
|
|
|
|
/**
|
|
|
|
|
* 创建一个新的空白笔记实例。
|
|
|
|
|
*
|
|
|
|
|
* @param context 上下文对象
|
|
|
|
|
* @param folderId 所属文件夹 ID
|
|
|
|
|
*/
|
|
|
|
|
private WorkingNote(Context context, long folderId) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
mAlertDate = 0;
|
|
|
|
@ -113,8 +127,13 @@ public class WorkingNote {
|
|
|
|
|
mMode = 0;
|
|
|
|
|
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Existing note construct
|
|
|
|
|
/**
|
|
|
|
|
* 加载已存在的笔记实例。
|
|
|
|
|
*
|
|
|
|
|
* @param context 上下文对象
|
|
|
|
|
* @param noteId 笔记 ID
|
|
|
|
|
* @param folderId 所属文件夹 ID(可选)
|
|
|
|
|
*/
|
|
|
|
|
private WorkingNote(Context context, long noteId, long folderId) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
mNoteId = noteId;
|
|
|
|
@ -123,7 +142,9 @@ public class WorkingNote {
|
|
|
|
|
mNote = new Note();
|
|
|
|
|
loadNote();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从数据库加载笔记主信息。
|
|
|
|
|
*/
|
|
|
|
|
private void loadNote() {
|
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(
|
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
|
|
|
|
@ -145,7 +166,9 @@ public class WorkingNote {
|
|
|
|
|
}
|
|
|
|
|
loadNoteData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从数据库加载笔记内容数据(如文本、通话记录)。
|
|
|
|
|
*/
|
|
|
|
|
private void loadNoteData() {
|
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
|
|
|
|
|
DataColumns.NOTE_ID + "=?", new String[] {
|
|
|
|
@ -173,7 +196,16 @@ public class WorkingNote {
|
|
|
|
|
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建一个空笔记并设置默认值。
|
|
|
|
|
*
|
|
|
|
|
* @param context 上下文对象
|
|
|
|
|
* @param folderId 所属文件夹 ID
|
|
|
|
|
* @param widgetId 小部件 ID
|
|
|
|
|
* @param widgetType 小部件类型
|
|
|
|
|
* @param defaultBgColorId 默认背景颜色 ID
|
|
|
|
|
* @return 新建的 WorkingNote 实例
|
|
|
|
|
*/
|
|
|
|
|
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
|
|
|
|
|
int widgetType, int defaultBgColorId) {
|
|
|
|
|
WorkingNote note = new WorkingNote(context, folderId);
|
|
|
|
@ -182,11 +214,21 @@ public class WorkingNote {
|
|
|
|
|
note.setWidgetType(widgetType);
|
|
|
|
|
return note;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载指定 ID 的笔记。
|
|
|
|
|
*
|
|
|
|
|
* @param context 上下文对象
|
|
|
|
|
* @param id 笔记 ID
|
|
|
|
|
* @return 已加载的 WorkingNote 实例
|
|
|
|
|
*/
|
|
|
|
|
public static WorkingNote load(Context context, long id) {
|
|
|
|
|
return new WorkingNote(context, id, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存当前笔记到数据库。
|
|
|
|
|
*
|
|
|
|
|
* @return 是否保存成功
|
|
|
|
|
*/
|
|
|
|
|
public synchronized boolean saveNote() {
|
|
|
|
|
if (isWorthSaving()) {
|
|
|
|
|
if (!existInDatabase()) {
|
|
|
|
@ -224,11 +266,20 @@ public class WorkingNote {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置笔记设置更改监听器。
|
|
|
|
|
*
|
|
|
|
|
* @param l 监听器对象
|
|
|
|
|
*/
|
|
|
|
|
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
|
|
|
|
|
mNoteSettingStatusListener = l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置警告时间。
|
|
|
|
|
*
|
|
|
|
|
* @param date 时间戳
|
|
|
|
|
* @param set 是否设置
|
|
|
|
|
*/
|
|
|
|
|
public void setAlertDate(long date, boolean set) {
|
|
|
|
|
if (date != mAlertDate) {
|
|
|
|
|
mAlertDate = date;
|
|
|
|
@ -238,7 +289,11 @@ public class WorkingNote {
|
|
|
|
|
mNoteSettingStatusListener.onClockAlertChanged(date, set);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 标记笔记是否被删除。
|
|
|
|
|
*
|
|
|
|
|
* @param mark 是否标记为删除
|
|
|
|
|
*/
|
|
|
|
|
public void markDeleted(boolean mark) {
|
|
|
|
|
mIsDeleted = mark;
|
|
|
|
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
@ -246,7 +301,11 @@ public class WorkingNote {
|
|
|
|
|
mNoteSettingStatusListener.onWidgetChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置背景颜色 ID。
|
|
|
|
|
*
|
|
|
|
|
* @param id 颜色 ID
|
|
|
|
|
*/
|
|
|
|
|
public void setBgColorId(int id) {
|
|
|
|
|
if (id != mBgColorId) {
|
|
|
|
|
mBgColorId = id;
|
|
|
|
@ -256,7 +315,11 @@ public class WorkingNote {
|
|
|
|
|
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置检查列表模式。
|
|
|
|
|
*
|
|
|
|
|
* @param mode 模式值
|
|
|
|
|
*/
|
|
|
|
|
public void setCheckListMode(int mode) {
|
|
|
|
|
if (mMode != mode) {
|
|
|
|
|
if (mNoteSettingStatusListener != null) {
|
|
|
|
@ -266,28 +329,45 @@ public class WorkingNote {
|
|
|
|
|
mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置小部件类型。
|
|
|
|
|
*
|
|
|
|
|
* @param type 小部件类型
|
|
|
|
|
*/
|
|
|
|
|
public void setWidgetType(int type) {
|
|
|
|
|
if (type != mWidgetType) {
|
|
|
|
|
mWidgetType = type;
|
|
|
|
|
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置小部件 ID。
|
|
|
|
|
*
|
|
|
|
|
* @param id 小部件 ID
|
|
|
|
|
*/
|
|
|
|
|
public void setWidgetId(int id) {
|
|
|
|
|
if (id != mWidgetId) {
|
|
|
|
|
mWidgetId = id;
|
|
|
|
|
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置笔记内容文本。
|
|
|
|
|
*
|
|
|
|
|
* @param text 内容文本
|
|
|
|
|
*/
|
|
|
|
|
public void setWorkingText(String text) {
|
|
|
|
|
if (!TextUtils.equals(mContent, text)) {
|
|
|
|
|
mContent = text;
|
|
|
|
|
mNote.setTextData(DataColumns.CONTENT, mContent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将笔记转换为通话记录笔记。
|
|
|
|
|
*
|
|
|
|
|
* @param phoneNumber 电话号码
|
|
|
|
|
* @param callDate 通话时间
|
|
|
|
|
*/
|
|
|
|
|
public void convertToCallNote(String phoneNumber, long callDate) {
|
|
|
|
|
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
|
|
|
|
|
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
|
|
|
|
@ -297,23 +377,43 @@ public class WorkingNote {
|
|
|
|
|
public boolean hasClockAlert() {
|
|
|
|
|
return (mAlertDate > 0 ? true : false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取笔记内容。
|
|
|
|
|
*
|
|
|
|
|
* @return 笔记内容字符串
|
|
|
|
|
*/
|
|
|
|
|
public String getContent() {
|
|
|
|
|
return mContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取警报时间。
|
|
|
|
|
*
|
|
|
|
|
* @return 时间戳
|
|
|
|
|
*/
|
|
|
|
|
public long getAlertDate() {
|
|
|
|
|
return mAlertDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取最后修改时间。
|
|
|
|
|
*
|
|
|
|
|
* @return 时间戳
|
|
|
|
|
*/
|
|
|
|
|
public long getModifiedDate() {
|
|
|
|
|
return mModifiedDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取背景颜色资源 ID。
|
|
|
|
|
*
|
|
|
|
|
* @return 资源 ID
|
|
|
|
|
*/
|
|
|
|
|
public int getBgColorResId() {
|
|
|
|
|
return NoteBgResources.getNoteBgResource(mBgColorId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取背景颜色 ID。
|
|
|
|
|
*
|
|
|
|
|
* @return 颜色 ID
|
|
|
|
|
*/
|
|
|
|
|
public int getBgColorId() {
|
|
|
|
|
return mBgColorId;
|
|
|
|
|
}
|
|
|
|
@ -341,28 +441,32 @@ public class WorkingNote {
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* 笔记设置更改监听器接口,用于监听笔记相关的 UI 更新事件。
|
|
|
|
|
*/
|
|
|
|
|
public interface NoteSettingChangedListener {
|
|
|
|
|
/**
|
|
|
|
|
* 当笔记背景颜色发生变化时调用。
|
|
|
|
|
*/
|
|
|
|
|
void onBackgroundColorChanged();
|
|
|
|
|
/**
|
|
|
|
|
* 当用户设置了闹钟提醒或取消时调用。
|
|
|
|
|
*
|
|
|
|
|
* @param date 时间戳
|
|
|
|
|
* @param set 是否设置
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* 当从小部件创建笔记时调用。
|
|
|
|
|
*/
|
|
|
|
|
void onWidgetChanged();
|
|
|
|
|
/**
|
|
|
|
|
* 当切换检查列表模式时调用。
|
|
|
|
|
*
|
|
|
|
|
* @param oldMode 旧模式
|
|
|
|
|
* @param newMode 新模式
|
|
|
|
|
*/
|
|
|
|
|
void onCheckListModeChanged(int oldMode, int newMode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|