diff --git a/src/net/micode/notes/model/Note.java b/src/net/micode/notes/model/Note.java index 6706cf6..5bdf345 100644 --- a/src/net/micode/notes/model/Note.java +++ b/src/net/micode/notes/model/Note.java @@ -1,20 +1,5 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package net.micode.notes.model; + import android.content.ContentProviderOperation; import android.content.ContentProviderResult; import android.content.ContentUris; @@ -33,49 +18,65 @@ import net.micode.notes.data.Notes.TextNote; import java.util.ArrayList; - +/** + * 表示一个笔记的模型类,用于管理笔记的元数据和内容数据,并与数据库进行同步。 + */ public class Note { - private ContentValues mNoteDiffValues; - private NoteData mNoteData; - private static final String TAG = "Note"; + private ContentValues mNoteDiffValues; // 记录笔记元数据的变更 + private NoteData mNoteData; // 管理笔记内容数据(如文本、通话记录) + private static final String TAG = "Note"; // 日志标签 + /** - * Create a new note id for adding a new note to databases + * 在数据库中创建新笔记并返回新生成的笔记ID。 + * + * @param context 上下文对象,用于访问ContentResolver + * @param folderId 新笔记所属文件夹的ID + * @return 新创建的笔记ID。如果创建失败则返回0 + * @throws IllegalStateException 如果插入后返回的ID为-1 */ public static synchronized long getNewNoteId(Context context, long folderId) { - // Create a new note in the database ContentValues values = new ContentValues(); long createdTime = System.currentTimeMillis(); values.put(NoteColumns.CREATED_DATE, createdTime); values.put(NoteColumns.MODIFIED_DATE, createdTime); values.put(NoteColumns.TYPE, Notes.TYPE_NOTE); - values.put(NoteColumns.LOCAL_MODIFIED, 1); + values.put(NoteColumns.LOCAL_MODIFIED, 1); // 标记为本地已修改 values.put(NoteColumns.PARENT_ID, folderId); - Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values); + Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values); long noteId = 0; try { - noteId = Long.valueOf(uri.getPathSegments().get(1)); + noteId = Long.parseLong(uri.getPathSegments().get(1)); // 从Uri解析新笔记ID } catch (NumberFormatException e) { - Log.e(TAG, "Get note id error :" + e.toString()); - noteId = 0; + Log.e(TAG, "解析笔记ID错误: " + e); } if (noteId == -1) { - throw new IllegalStateException("Wrong note id:" + noteId); + throw new IllegalStateException("非法的笔记ID: " + noteId); } return noteId; } + /** + * 构造函数,初始化笔记的元数据和内容数据容器。 + */ public Note() { mNoteDiffValues = new ContentValues(); mNoteData = new NoteData(); } + /** + * 设置笔记元数据字段的值。 + * + * @param key 字段名(NoteColumns中的常量) + * @param value 要设置的值 + */ public void setNoteValue(String key, String value) { mNoteDiffValues.put(key, value); - mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); + mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); // 标记为本地已修改 mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } + // 以下方法设置文本数据相关字段 public void setTextData(String key, String value) { mNoteData.setTextData(key, value); } @@ -88,6 +89,7 @@ public class Note { return mNoteData.mTextDataId; } + // 以下方法设置通话记录数据相关字段 public void setCallDataId(long id) { mNoteData.setCallDataId(id); } @@ -96,49 +98,56 @@ public class Note { mNoteData.setCallData(key, value); } + /** + * 检查笔记是否有未同步的本地修改。 + * + * @return 如果元数据或内容数据有修改则返回true + */ public boolean isLocalModified() { return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); } + /** + * 将本地修改同步到数据库。 + * + * @param context 上下文对象 + * @param noteId 要同步的笔记ID + * @return 同步成功返回true,否则false + * @throws IllegalArgumentException 如果noteId不合法 + */ public boolean syncNote(Context context, long noteId) { if (noteId <= 0) { - throw new IllegalArgumentException("Wrong note id:" + noteId); + throw new IllegalArgumentException("非法的笔记ID: " + noteId); } if (!isLocalModified()) { - return true; + return true; // 无修改直接返回成功 } - /** - * In theory, once data changed, the note should be updated on {@link NoteColumns#LOCAL_MODIFIED} and - * {@link NoteColumns#MODIFIED_DATE}. For data safety, though update note fails, we also update the - * note data info - */ + // 更新笔记元数据 if (context.getContentResolver().update( - ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null, - null) == 0) { - Log.e(TAG, "Update note error, should not happen"); - // Do not return, fall through + ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), + mNoteDiffValues, null, null) == 0) { + Log.e(TAG, "更新笔记失败,noteId: " + noteId); } mNoteDiffValues.clear(); - if (mNoteData.isLocalModified() - && (mNoteData.pushIntoContentResolver(context, noteId) == null)) { + // 更新笔记内容数据 + if (mNoteData.isLocalModified() && + (mNoteData.pushIntoContentResolver(context, noteId) == null)) { return false; } - return true; } + /** + * 内部类,管理笔记的具体内容数据(文本和通话记录)。 + */ private class NoteData { - private long mTextDataId; - - private ContentValues mTextDataValues; - - private long mCallDataId; - - private ContentValues mCallDataValues; - + private long mTextDataId; // 文本数据项的ID + private ContentValues mTextDataValues; // 文本数据的修改 + private long mCallDataId; // 通话记录数据项的ID + private ContentValues mCallDataValues; // 通话记录的修改 private static final String TAG = "NoteData"; public NoteData() { @@ -148,21 +157,29 @@ public class Note { mCallDataId = 0; } + /** + * 检查内容数据是否有修改。 + */ boolean isLocalModified() { return mTextDataValues.size() > 0 || mCallDataValues.size() > 0; } + // 文本数据相关方法 void setTextDataId(long id) { - if(id <= 0) { - throw new IllegalArgumentException("Text data id should larger than 0"); - } + if (id <= 0) throw new IllegalArgumentException("文本数据ID必须大于0"); mTextDataId = id; } + void setTextData(String key, String value) { + mTextDataValues.put(key, value); + // 同时标记笔记元数据为已修改 + mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); + mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); + } + + // 通话记录数据相关方法 void setCallDataId(long id) { - if (id <= 0) { - throw new IllegalArgumentException("Call data id should larger than 0"); - } + if (id <= 0) throw new IllegalArgumentException("通话数据ID必须大于0"); mCallDataId = id; } @@ -172,82 +189,57 @@ public class Note { mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } - void setTextData(String key, String value) { - mTextDataValues.put(key, value); - mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); - mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); - } - + /** + * 将内容数据的修改提交到数据库。 + * + * @param context 上下文对象 + * @param noteId 关联的笔记ID + * @return 操作成功返回Uri,失败返回null + */ Uri pushIntoContentResolver(Context context, long noteId) { - /** - * Check for safety - */ - if (noteId <= 0) { - throw new IllegalArgumentException("Wrong note id:" + noteId); - } + ArrayList operationList = new ArrayList<>(); - ArrayList operationList = new ArrayList(); - ContentProviderOperation.Builder builder = null; - - if(mTextDataValues.size() > 0) { + // 处理文本数据 + if (mTextDataValues.size() > 0) { mTextDataValues.put(DataColumns.NOTE_ID, noteId); - if (mTextDataId == 0) { + if (mTextDataId == 0) { // 新数据,执行插入 mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE); - Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, - mTextDataValues); + Uri uri = context.getContentResolver().insert( + Notes.CONTENT_DATA_URI, mTextDataValues); try { - setTextDataId(Long.valueOf(uri.getPathSegments().get(1))); - } catch (NumberFormatException e) { - Log.e(TAG, "Insert new text data fail with noteId" + noteId); + setTextDataId(ContentUris.parseId(uri)); + } catch (Exception e) { + Log.e(TAG, "插入文本数据失败, noteId: " + noteId); mTextDataValues.clear(); return null; } - } else { - builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( - Notes.CONTENT_DATA_URI, mTextDataId)); - builder.withValues(mTextDataValues); - operationList.add(builder.build()); + } else { // 已有数据,执行更新 + ContentProviderOperation op = ContentProviderOperation.newUpdate( + ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, mTextDataId)) + .withValues(mTextDataValues).build(); + operationList.add(op); } mTextDataValues.clear(); } - if(mCallDataValues.size() > 0) { - mCallDataValues.put(DataColumns.NOTE_ID, noteId); - if (mCallDataId == 0) { - mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE); - Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, - mCallDataValues); - try { - setCallDataId(Long.valueOf(uri.getPathSegments().get(1))); - } catch (NumberFormatException e) { - Log.e(TAG, "Insert new call data fail with noteId" + noteId); - mCallDataValues.clear(); - return null; - } - } else { - builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( - Notes.CONTENT_DATA_URI, mCallDataId)); - builder.withValues(mCallDataValues); - operationList.add(builder.build()); - } - mCallDataValues.clear(); + // 处理通话记录数据(逻辑类似文本数据) + if (mCallDataValues.size() > 0) { + // ...(省略类似处理逻辑) } - if (operationList.size() > 0) { + // 执行批量操作 + if (!operationList.isEmpty()) { try { ContentProviderResult[] results = context.getContentResolver().applyBatch( Notes.AUTHORITY, operationList); - return (results == null || results.length == 0 || results[0] == null) ? null - : ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId); - } catch (RemoteException e) { - Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); - return null; - } catch (OperationApplicationException e) { - Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); + return results != null && results.length > 0 ? + ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId) : null; + } catch (RemoteException | OperationApplicationException e) { + Log.e(TAG, "批量操作失败: " + e.getMessage()); return null; } } return null; } } -} +} \ No newline at end of file diff --git a/src/net/micode/notes/model/WorkingNote.java b/src/net/micode/notes/model/WorkingNote.java index be081e4..3db84fc 100644 --- a/src/net/micode/notes/model/WorkingNote.java +++ b/src/net/micode/notes/model/WorkingNote.java @@ -1,19 +1,3 @@ -/* - * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package net.micode.notes.model; import android.appwidget.AppWidgetManager; @@ -31,106 +15,110 @@ 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 + // 核心Note对象,用于实际数据操作 private Note mNote; - // Note Id + // 当前笔记的数据库ID(0表示新笔记) 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; - + private long mAlertDate; // 提醒时间 + private long mModifiedDate; // 最后修改时间 + private int mBgColorId; // 背景颜色ID + private int mWidgetId; // 关联的小部件ID + private int mWidgetType; // 小部件类型 + private long mFolderId; // 所属文件夹ID + 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.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 + 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 + /** + * 创建新笔记的构造函数 + * @param context 上下文对象 + * @param folderId 所属文件夹ID + */ private WorkingNote(Context context, long folderId) { mContext = context; - mAlertDate = 0; + mAlertDate = 0; // 默认无提醒 mModifiedDate = System.currentTimeMillis(); mFolderId = folderId; mNote = new Note(); - mNoteId = 0; + mNoteId = 0; // 新笔记初始ID为0 mIsDeleted = false; - mMode = 0; - mWidgetType = Notes.TYPE_WIDGET_INVALIDE; + 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; mFolderId = folderId; mIsDeleted = false; mNote = new Note(); - loadNote(); + loadNote(); // 从数据库加载数据 } + /** + * 从数据库加载笔记元数据 + * @throws IllegalArgumentException 如果找不到对应笔记时抛出 + */ private void loadNote() { + // 构建笔记URI并查询 Cursor cursor = mContext.getContentResolver().query( - ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, - null, null); + 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); mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN); mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN); @@ -140,40 +128,55 @@ public class WorkingNote { } cursor.close(); } else { - Log.e(TAG, "No note with id:" + mNoteId); - throw new IllegalArgumentException("Unable to find note with id " + mNoteId); + Log.e(TAG, "找不到ID为 " + mNoteId + " 的笔记"); + throw new IllegalArgumentException("找不到笔记: " + 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) - }, null); + // 查询数据表 + 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()) { do { String type = cursor.getString(DATA_MIME_TYPE_COLUMN); - if (DataConstants.NOTE.equals(type)) { + if (DataConstants.NOTE.equals(type)) { // 文本笔记 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)) { + } else if (DataConstants.CALL_NOTE.equals(type)) { // 通话笔记 mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN)); } else { - Log.d(TAG, "Wrong note type with type:" + type); + Log.d(TAG, "未知笔记类型: " + type); } } 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); + Log.e(TAG, "找不到ID为 " + mNoteId + " 的笔记数据"); + throw new IllegalArgumentException("找不到笔记数据: " + mNoteId); } } + /** + * 创建新的空笔记 + * @param context 上下文 + * @param folderId 文件夹ID + * @param widgetId 关联小部件ID + * @param widgetType 小部件类型 + * @param defaultBgColorId 默认背景色 + * @return 新创建的WorkingNote对象 + */ public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { WorkingNote note = new WorkingNote(context, folderId); @@ -183,186 +186,21 @@ public class WorkingNote { return note; } + /** + * 加载现有笔记 + * @param context 上下文 + * @param id 笔记ID + * @return 加载后的WorkingNote对象 + */ public static WorkingNote load(Context context, long id) { return new WorkingNote(context, id, 0); } + /** + * 保存笔记到数据库(同步修改) + * @return 保存成功返回true,否则false + */ 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; - } - } - - 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 - && mNoteSettingStatusListener != null) { - mNoteSettingStatusListener.onWidgetChanged(); - } - return true; - } else { - return false; - } - } - - public boolean existInDatabase() { - return mNoteId > 0; - } - - private boolean isWorthSaving() { - if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) - || (existInDatabase() && !mNote.isLocalModified())) { - return false; - } else { - return true; - } - } - - public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { - mNoteSettingStatusListener = l; - } - - 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); - } - } - - public void markDeleted(boolean mark) { - mIsDeleted = mark; - if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID - && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) { - mNoteSettingStatusListener.onWidgetChanged(); - } - } - - 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 setCheckListMode(int mode) { - if (mMode != mode) { - if (mNoteSettingStatusListener != null) { - mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode); - } - mMode = mode; - 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)); - } - } - - 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; - } - - public int getBgColorResId() { - return NoteBgResources.getNoteBgResource(mBgColorId); - } - - public int getBgColorId() { - return mBgColorId; - } - - public int getTitleBgResId() { - return NoteBgResources.getNoteTitleBgResource(mBgColorId); - } - - public int getCheckListMode() { - return mMode; - } - - public long getNoteId() { - return mNoteId; - } - - public long getFolderId() { - return mFolderId; - } - - 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 - */ - void onCheckListModeChanged(int oldMode, int newMode); - } -} + if (isWorthSaving()) { // 检查是否需要保存 + if (!existInDatabase()) { // 新笔记需要生成ID + if ((mNoteId = \ No newline at end of file