|
|
|
@ -14,8 +14,10 @@
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 定义包名,表示该类属于 net.micode.notes.model 包
|
|
|
|
|
package net.micode.notes.model;
|
|
|
|
|
|
|
|
|
|
// 导入 Android 系统提供的相关类
|
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
|
|
import android.content.ContentUris;
|
|
|
|
|
import android.content.Context;
|
|
|
|
@ -23,6 +25,7 @@ import android.database.Cursor;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
// 导入自定义的 Notes 数据模型类和工具类
|
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
|
import net.micode.notes.data.Notes.CallNote;
|
|
|
|
|
import net.micode.notes.data.Notes.DataColumns;
|
|
|
|
@ -31,106 +34,114 @@ import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
import net.micode.notes.data.Notes.TextNote;
|
|
|
|
|
import net.micode.notes.tool.ResourceParser.NoteBgResources;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义一个名为 WorkingNote 的类,用于表示一个正在编辑的笔记
|
|
|
|
|
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,
|
|
|
|
|
DataColumns.MIME_TYPE,
|
|
|
|
|
DataColumns.DATA1,
|
|
|
|
|
DataColumns.DATA2,
|
|
|
|
|
DataColumns.DATA3,
|
|
|
|
|
DataColumns.DATA4,
|
|
|
|
|
DataColumns.ID, // 数据 ID
|
|
|
|
|
DataColumns.CONTENT, // 数据内容
|
|
|
|
|
DataColumns.MIME_TYPE, // 数据的 MIME 类型
|
|
|
|
|
DataColumns.DATA1, // 数据的附加字段 1
|
|
|
|
|
DataColumns.DATA2, // 数据的附加字段 2
|
|
|
|
|
DataColumns.DATA3, // 数据的附加字段 3
|
|
|
|
|
DataColumns.DATA4, // 数据的附加字段 4
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 定义查询笔记基本信息时需要的列
|
|
|
|
|
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
|
|
|
|
|
NoteColumns.PARENT_ID, // 父文件夹 ID
|
|
|
|
|
NoteColumns.ALERTED_DATE, // 提醒时间
|
|
|
|
|
NoteColumns.BG_COLOR_ID, // 背景颜色 ID
|
|
|
|
|
NoteColumns.WIDGET_ID, // 小部件 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 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;
|
|
|
|
|
mContext = context; // 设置上下文
|
|
|
|
|
mAlertDate = 0; // 初始化提醒时间为 0
|
|
|
|
|
mModifiedDate = System.currentTimeMillis(); // 设置当前时间为修改时间
|
|
|
|
|
mFolderId = folderId; // 设置父文件夹 ID
|
|
|
|
|
mNote = new Note(); // 创建一个新的笔记对象
|
|
|
|
|
mNoteId = 0; // 初始化笔记 ID 为 0
|
|
|
|
|
mIsDeleted = false; // 初始化删除标志为 false
|
|
|
|
|
mMode = 0; // 初始化模式为 0
|
|
|
|
|
mWidgetType = Notes.TYPE_WIDGET_INVALIDE; // 初始化小部件类型为无效值
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Existing note construct
|
|
|
|
|
// 现有笔记的构造方法
|
|
|
|
|
private WorkingNote(Context context, long noteId, long folderId) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
mNoteId = noteId;
|
|
|
|
|
mFolderId = folderId;
|
|
|
|
|
mIsDeleted = false;
|
|
|
|
|
mNote = new Note();
|
|
|
|
|
loadNote();
|
|
|
|
|
mContext = context; // 设置上下文
|
|
|
|
|
mNoteId = noteId; // 设置笔记 ID
|
|
|
|
|
mFolderId = folderId; // 设置父文件夹 ID
|
|
|
|
|
mIsDeleted = false; // 初始化删除标志为 false
|
|
|
|
|
mNote = new Note(); // 创建一个新的笔记对象
|
|
|
|
|
loadNote(); // 加载笔记数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载笔记基本信息的方法
|
|
|
|
|
private void loadNote() {
|
|
|
|
|
// 查询笔记基本信息
|
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(
|
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
|
|
|
|
|
null, null);
|
|
|
|
|
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
// 从查询结果中获取笔记的父文件夹 ID、背景颜色 ID、小部件 ID、小部件类型、提醒时间和修改时间
|
|
|
|
|
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
|
|
|
|
|
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
|
|
|
|
|
mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
|
|
|
|
@ -138,15 +149,18 @@ public class WorkingNote {
|
|
|
|
|
mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
|
|
|
|
|
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
|
|
|
|
|
}
|
|
|
|
|
cursor.close();
|
|
|
|
|
cursor.close(); // 关闭游标
|
|
|
|
|
} else {
|
|
|
|
|
// 如果查询结果为空,记录日志并抛出异常
|
|
|
|
|
Log.e(TAG, "No note with id:" + mNoteId);
|
|
|
|
|
throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
|
|
|
|
|
}
|
|
|
|
|
loadNoteData();
|
|
|
|
|
loadNoteData(); // 加载笔记的详细数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载笔记详细数据的方法
|
|
|
|
|
private void loadNoteData() {
|
|
|
|
|
// 查询笔记的详细数据
|
|
|
|
|
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
|
|
|
|
|
DataColumns.NOTE_ID + "=?", new String[] {
|
|
|
|
|
String.valueOf(mNoteId)
|
|
|
|
@ -155,214 +169,242 @@ public class WorkingNote {
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
do {
|
|
|
|
|
// 获取数据的 MIME 类型
|
|
|
|
|
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
|
|
|
|
|
if (DataConstants.NOTE.equals(type)) {
|
|
|
|
|
// 如果是普通笔记类型,获取内容、模式,并设置文本数据 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)) {
|
|
|
|
|
// 如果是通话笔记类型,设置通话数据 ID
|
|
|
|
|
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
|
|
|
|
|
} else {
|
|
|
|
|
// 如果是未知类型,记录日志
|
|
|
|
|
Log.d(TAG, "Wrong note type with type:" + type);
|
|
|
|
|
}
|
|
|
|
|
} while (cursor.moveToNext());
|
|
|
|
|
} while (cursor.moveToNext()); // 遍历所有结果
|
|
|
|
|
}
|
|
|
|
|
cursor.close();
|
|
|
|
|
cursor.close(); // 关闭游标
|
|
|
|
|
} else {
|
|
|
|
|
// 如果查询结果为空,记录日志并抛出异常
|
|
|
|
|
Log.e(TAG, "No data with id:" + mNoteId);
|
|
|
|
|
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);
|
|
|
|
|
note.setBgColorId(defaultBgColorId);
|
|
|
|
|
note.setWidgetId(widgetId);
|
|
|
|
|
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()) {
|
|
|
|
|
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
|
|
|
|
|
Log.e(TAG, "Create new note fail with id:" + mNoteId);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 创建一个空的笔记对象
|
|
|
|
|
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
|
|
|
|
|
int widgetType, int defaultBgColorId) {
|
|
|
|
|
WorkingNote note = new WorkingNote(context, folderId); // 创建一个新的 WorkingNote 对象
|
|
|
|
|
note.setBgColorId(defaultBgColorId); // 设置默认背景颜色 ID
|
|
|
|
|
note.setWidgetId(widgetId); // 设置小部件 ID
|
|
|
|
|
note.setWidgetType(widgetType); // 设置小部件类型
|
|
|
|
|
return note; // 返回创建的笔记对象
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mNote.syncNote(mContext, mNoteId);
|
|
|
|
|
// 加载一个已存在的笔记
|
|
|
|
|
public static WorkingNote load(Context context, long id) {
|
|
|
|
|
return new WorkingNote(context, id, 0); // 创建一个新的 WorkingNote 对象,并加载指定 ID 的笔记
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update widget content if there exist any widget of this note
|
|
|
|
|
*/
|
|
|
|
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
|
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
|
|
|
|
|
&& mNoteSettingStatusListener != null) {
|
|
|
|
|
mNoteSettingStatusListener.onWidgetChanged();
|
|
|
|
|
// 保存笔记到数据库
|
|
|
|
|
public synchronized boolean saveNote() {
|
|
|
|
|
if (isWorthSaving()) { // 检查笔记是否值得保存
|
|
|
|
|
if (!existInDatabase()) { // 如果笔记不在数据库中
|
|
|
|
|
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { // 创建一个新的笔记 ID
|
|
|
|
|
Log.e(TAG, "Create new note fail with id:" + mNoteId); // 如果创建失败,记录日志
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean existInDatabase() {
|
|
|
|
|
return mNoteId > 0;
|
|
|
|
|
}
|
|
|
|
|
mNote.syncNote(mContext, mNoteId); // 同步笔记到数据库
|
|
|
|
|
|
|
|
|
|
private boolean isWorthSaving() {
|
|
|
|
|
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|
|
|
|
|
|| (existInDatabase() && !mNote.isLocalModified())) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
/**
|
|
|
|
|
* 如果笔记关联了小部件,更新小部件内容
|
|
|
|
|
*/
|
|
|
|
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID // 检查小部件 ID 是否有效
|
|
|
|
|
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE // 检查小部件类型是否有效
|
|
|
|
|
&& mNoteSettingStatusListener != null) { // 检查是否设置了监听器
|
|
|
|
|
mNoteSettingStatusListener.onWidgetChanged(); // 通知监听器小部件内容已更改
|
|
|
|
|
}
|
|
|
|
|
return true; // 返回保存成功
|
|
|
|
|
} else {
|
|
|
|
|
return false; // 如果笔记不值得保存,返回失败
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
|
|
|
|
|
mNoteSettingStatusListener = l;
|
|
|
|
|
}
|
|
|
|
|
// 检查笔记是否存在于数据库中
|
|
|
|
|
public boolean existInDatabase() {
|
|
|
|
|
return mNoteId > 0; // 如果笔记 ID 大于 0,表示笔记已存在于数据库中
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAlertDate(long date, boolean set) {
|
|
|
|
|
if (date != mAlertDate) {
|
|
|
|
|
mAlertDate = date;
|
|
|
|
|
mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate));
|
|
|
|
|
}
|
|
|
|
|
if (mNoteSettingStatusListener != null) {
|
|
|
|
|
mNoteSettingStatusListener.onClockAlertChanged(date, set);
|
|
|
|
|
}
|
|
|
|
|
// 检查笔记是否值得保存
|
|
|
|
|
private boolean isWorthSaving() {
|
|
|
|
|
if (mIsDeleted // 如果笔记已被标记为删除
|
|
|
|
|
|| (!existInDatabase() && TextUtils.isEmpty(mContent)) // 如果笔记不在数据库中且内容为空
|
|
|
|
|
|| (existInDatabase() && !mNote.isLocalModified())) { // 如果笔记在数据库中但没有本地修改
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void markDeleted(boolean mark) {
|
|
|
|
|
mIsDeleted = mark;
|
|
|
|
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
|
|
|
|
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
|
|
|
|
|
mNoteSettingStatusListener.onWidgetChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 设置笔记设置变更监听器
|
|
|
|
|
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
|
|
|
|
|
mNoteSettingStatusListener = l; // 设置监听器对象
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setBgColorId(int id) {
|
|
|
|
|
if (id != mBgColorId) {
|
|
|
|
|
mBgColorId = id;
|
|
|
|
|
if (mNoteSettingStatusListener != null) {
|
|
|
|
|
mNoteSettingStatusListener.onBackgroundColorChanged();
|
|
|
|
|
}
|
|
|
|
|
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
|
|
|
|
|
}
|
|
|
|
|
// 设置笔记的提醒时间
|
|
|
|
|
public void setAlertDate(long date, boolean set) {
|
|
|
|
|
if (date != mAlertDate) { // 如果新提醒时间与当前提醒时间不同
|
|
|
|
|
mAlertDate = date; // 更新提醒时间
|
|
|
|
|
mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate)); // 更新笔记的提醒时间字段
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setCheckListMode(int mode) {
|
|
|
|
|
if (mMode != mode) {
|
|
|
|
|
if (mNoteSettingStatusListener != null) {
|
|
|
|
|
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
|
|
|
|
|
}
|
|
|
|
|
mMode = mode;
|
|
|
|
|
mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
|
|
|
|
|
}
|
|
|
|
|
if (mNoteSettingStatusListener != null) { // 如果设置了监听器
|
|
|
|
|
mNoteSettingStatusListener.onClockAlertChanged(date, set); // 通知监听器提醒时间已更改
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setWidgetType(int type) {
|
|
|
|
|
if (type != mWidgetType) {
|
|
|
|
|
mWidgetType = type;
|
|
|
|
|
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
|
|
|
|
|
}
|
|
|
|
|
// 标记笔记为删除或取消删除
|
|
|
|
|
public void markDeleted(boolean mark) {
|
|
|
|
|
mIsDeleted = mark; // 更新删除标志
|
|
|
|
|
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID // 检查小部件 ID 是否有效
|
|
|
|
|
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE // 检查小部件类型是否有效
|
|
|
|
|
&& mNoteSettingStatusListener != null) { // 检查是否设置了监听器
|
|
|
|
|
mNoteSettingStatusListener.onWidgetChanged(); // 通知监听器小部件内容已更改
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setWidgetId(int id) {
|
|
|
|
|
if (id != mWidgetId) {
|
|
|
|
|
mWidgetId = id;
|
|
|
|
|
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
|
|
|
|
|
// 设置笔记的背景颜色 ID
|
|
|
|
|
public void setBgColorId(int id) {
|
|
|
|
|
if (id != mBgColorId) { // 如果新背景颜色 ID 与当前背景颜色 ID 不同
|
|
|
|
|
mBgColorId = id; // 更新背景颜色 ID
|
|
|
|
|
if (mNoteSettingStatusListener != null) { // 如果设置了监听器
|
|
|
|
|
mNoteSettingStatusListener.onBackgroundColorChanged(); // 通知监听器背景颜色已更改
|
|
|
|
|
}
|
|
|
|
|
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id)); // 更新笔记的背景颜色字段
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setWorkingText(String text) {
|
|
|
|
|
if (!TextUtils.equals(mContent, text)) {
|
|
|
|
|
mContent = text;
|
|
|
|
|
mNote.setTextData(DataColumns.CONTENT, mContent);
|
|
|
|
|
// 设置笔记的清单模式
|
|
|
|
|
public void setCheckListMode(int mode) {
|
|
|
|
|
if (mMode != mode) { // 如果新模式与当前模式不同
|
|
|
|
|
if (mNoteSettingStatusListener != null) { // 如果设置了监听器
|
|
|
|
|
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode); // 通知监听器清单模式已更改
|
|
|
|
|
}
|
|
|
|
|
mMode = mode; // 更新模式
|
|
|
|
|
mNote.setTextData(TextNote.MODE, String.valueOf(mMode)); // 更新笔记的模式字段
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 void setWidgetType(int type) {
|
|
|
|
|
if (type != mWidgetType) { // 如果新小部件类型与当前小部件类型不同
|
|
|
|
|
mWidgetType = type; // 更新小部件类型
|
|
|
|
|
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType)); // 更新笔记的小部件类型字段
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getAlertDate() {
|
|
|
|
|
return mAlertDate;
|
|
|
|
|
// 设置笔记的小部件 ID
|
|
|
|
|
public void setWidgetId(int id) {
|
|
|
|
|
if (id != mWidgetId) { // 如果新小部件 ID 与当前小部件 ID 不同
|
|
|
|
|
mWidgetId = id; // 更新小部件 ID
|
|
|
|
|
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId)); // 更新笔记的小部件 ID 字段
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getModifiedDate() {
|
|
|
|
|
return mModifiedDate;
|
|
|
|
|
// 设置笔记的内容
|
|
|
|
|
public void setWorkingText(String text) {
|
|
|
|
|
if (!TextUtils.equals(mContent, text)) { // 如果新内容与当前内容不同
|
|
|
|
|
mContent = text; // 更新内容
|
|
|
|
|
mNote.setTextData(DataColumns.CONTENT, mContent); // 更新笔记的内容字段
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getBgColorResId() {
|
|
|
|
|
return NoteBgResources.getNoteBgResource(mBgColorId);
|
|
|
|
|
}
|
|
|
|
|
// 将笔记转换为通话笔记
|
|
|
|
|
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 int getBgColorId() {
|
|
|
|
|
return mBgColorId;
|
|
|
|
|
}
|
|
|
|
|
// 检查笔记是否有提醒
|
|
|
|
|
public boolean hasClockAlert() {
|
|
|
|
|
return (mAlertDate > 0 ? true : false); // 如果提醒时间大于 0,表示有提醒
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getTitleBgResId() {
|
|
|
|
|
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
|
|
|
|
|
}
|
|
|
|
|
// 获取笔记的内容
|
|
|
|
|
public String getContent() {
|
|
|
|
|
return mContent; // 返回笔记内容
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getCheckListMode() {
|
|
|
|
|
return mMode;
|
|
|
|
|
}
|
|
|
|
|
// 获取笔记的提醒时间
|
|
|
|
|
public long getAlertDate() {
|
|
|
|
|
return mAlertDate; // 返回提醒时间
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getNoteId() {
|
|
|
|
|
return mNoteId;
|
|
|
|
|
}
|
|
|
|
|
// 获取笔记的最后修改时间
|
|
|
|
|
public long getModifiedDate() {
|
|
|
|
|
return mModifiedDate; // 返回最后修改时间
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getFolderId() {
|
|
|
|
|
return mFolderId;
|
|
|
|
|
}
|
|
|
|
|
// 获取笔记的背景颜色资源 ID
|
|
|
|
|
public int getBgColorResId() {
|
|
|
|
|
return NoteBgResources.getNoteBgResource(mBgColorId); // 根据背景颜色 ID 获取背景颜色资源 ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getWidgetId() {
|
|
|
|
|
return mWidgetId;
|
|
|
|
|
}
|
|
|
|
|
// 获取笔记的背景颜色 ID
|
|
|
|
|
public int getBgColorId() {
|
|
|
|
|
return mBgColorId; // 返回背景颜色 ID
|
|
|
|
|
}// 获取笔记标题的背景资源 ID
|
|
|
|
|
public int getTitleBgResId() {
|
|
|
|
|
return NoteBgResources.getNoteTitleBgResource(mBgColorId); // 根据背景颜色 ID 获取标题背景资源 ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getWidgetType() {
|
|
|
|
|
return mWidgetType;
|
|
|
|
|
}
|
|
|
|
|
// 获取笔记的清单模式
|
|
|
|
|
public int getCheckListMode() {
|
|
|
|
|
return mMode; // 返回当前的清单模式
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface NoteSettingChangedListener {
|
|
|
|
|
/**
|
|
|
|
|
* Called when the background color of current note has just changed
|
|
|
|
|
*/
|
|
|
|
|
void onBackgroundColorChanged();
|
|
|
|
|
// 获取笔记的 ID
|
|
|
|
|
public long getNoteId() {
|
|
|
|
|
return mNoteId; // 返回笔记的 ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when user set clock
|
|
|
|
|
*/
|
|
|
|
|
void onClockAlertChanged(long date, boolean set);
|
|
|
|
|
// 获取笔记所属文件夹的 ID
|
|
|
|
|
public long getFolderId() {
|
|
|
|
|
return mFolderId; // 返回笔记所属文件夹的 ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call when user create note from widget
|
|
|
|
|
*/
|
|
|
|
|
void onWidgetChanged();
|
|
|
|
|
// 获取笔记的小部件 ID
|
|
|
|
|
public int getWidgetId() {
|
|
|
|
|
return mWidgetId; // 返回笔记的小部件 ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call when switch between check list mode and normal mode
|
|
|
|
|
* @param oldMode is previous mode before change
|
|
|
|
|
* @param newMode is new mode
|
|
|
|
|
*/
|
|
|
|
|
void onCheckListModeChanged(int oldMode, int newMode);
|
|
|
|
|
}
|
|
|
|
|
// 获取笔记的小部件类型
|
|
|
|
|
public int getWidgetType() {
|
|
|
|
|
return mWidgetType; // 返回笔记的小部件类型
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 定义一个接口 NoteSettingChangedListener,用于监听笔记设置的变更
|
|
|
|
|
public interface NoteSettingChangedListener {
|
|
|
|
|
/**
|
|
|
|
|
* 当笔记的背景颜色发生变化时调用
|
|
|
|
|
*/
|
|
|
|
|
void onBackgroundColorChanged();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当用户设置提醒时调用
|
|
|
|
|
* @param date 提醒时间
|
|
|
|
|
* @param set 是否设置了提醒
|
|
|
|
|
*/
|
|
|
|
|
void onClockAlertChanged(long date, boolean set);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当用户从小部件创建笔记时调用
|
|
|
|
|
*/
|
|
|
|
|
void onWidgetChanged();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当用户在清单模式和普通模式之间切换时
|
|
|
|
|