From cc25020aeaac71cb3120539b372a22eb9f749634 Mon Sep 17 00:00:00 2001 From: fang <2453662706@qq.com> Date: Sat, 23 Mar 2024 20:18:25 +0800 Subject: [PATCH] day02 --- model-WorkingNote.txt | 93 +++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/model-WorkingNote.txt b/model-WorkingNote.txt index 6afcc45..f817517 100644 --- a/model-WorkingNote.txt +++ b/model-WorkingNote.txt @@ -124,7 +124,7 @@ public class WorkingNote { mNote = new Note(); loadNote(); } - + // 加载Note // 通过数据库调用query函数找到第一个条目 private void loadNote() { @@ -142,14 +142,14 @@ public class WorkingNote { mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN); } cursor.close(); - //若不存在,报错 + //若不存在,报错 } else { Log.e(TAG, "No note with id:" + mNoteId); throw new IllegalArgumentException("Unable to find note with id " + mNoteId); } loadNoteData(); } - + //加载NoteData private void loadNoteData() { Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, @@ -158,7 +158,8 @@ public class WorkingNote { }, null); if (cursor != null) { - if (cursor.moveToFirst()) { + //查到信息不为空 + if (cursor.moveToFirst()) {//查看第一项是否存在 do { String type = cursor.getString(DATA_MIME_TYPE_COLUMN); if (DataConstants.NOTE.equals(type)) { @@ -170,7 +171,7 @@ public class WorkingNote { } else { Log.d(TAG, "Wrong note type with type:" + type); } - } while (cursor.moveToNext()); + } while (cursor.moveToNext());//查询所有项,直到为空 } cursor.close(); } else { @@ -178,10 +179,12 @@ public class WorkingNote { throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId); } } - + //创建空的Note + //传参:context,文件夹id,widget,背景颜色 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); @@ -191,10 +194,10 @@ public class WorkingNote { public static WorkingNote load(Context context, long id) { return new WorkingNote(context, id, 0); } - + //保存Note public synchronized boolean saveNote() { - if (isWorthSaving()) { - if (!existInDatabase()) { + if (isWorthSaving()) {//是否值得保存 + if (!existInDatabase()) {//是否存在数据库中 if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { Log.e(TAG, "Create new note fail with id:" + mNoteId); return false; @@ -216,12 +219,13 @@ public class WorkingNote { return false; } } - + //是否存在数据库中 public boolean existInDatabase() { return mNoteId > 0; } - + //是否值得保存 private boolean isWorthSaving() { + //被删除,或(不在数据库中 内容为空) ,或本地已经保存过 if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) || (existInDatabase() && !mNote.isLocalModified())) { return false; @@ -229,11 +233,12 @@ public class WorkingNote { return true; } } - + //设置mNoteSettingStatuListener public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; } - + //设置AlertDate + //若mAlertDate与data不同,则更改mAlertDate并设定NoteValue public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { mAlertDate = date; @@ -243,17 +248,18 @@ public class WorkingNote { 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(); + mNoteSettingStatusListener.onWidgetChanged();//调用mNoteSettingStatusListener的 onWidgetChanged方法 } } - + //设定背景颜色 public void setBgColorId(int id) { - if (id != mBgColorId) { + if (id != mBgColorId) {//设定条件id!=mBgColorId mBgColorId = id; if (mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onBackgroundColorChanged(); @@ -261,9 +267,10 @@ public class WorkingNote { mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id)); } } - + // 设定检查列表模式 + // 参数:mode public void setCheckListMode(int mode) { - if (mMode != mode) { + if (mMode != mode) {//设定条件 if (mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode); } @@ -271,82 +278,92 @@ public class WorkingNote { mNote.setTextData(TextNote.MODE, String.valueOf(mMode)); } } - + // 设定WidgetType + // 参数:type public void setWidgetType(int type) { - if (type != mWidgetType) { + if (type != mWidgetType) {//设定条件 mWidgetType = type; mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType)); + // 调用Note的setNoteValue方法更改WidgetType + } } - + // 设定WidgetId + // 参数:id public void setWidgetId(int id) { - if (id != mWidgetId) { + if (id != mWidgetId) {//设定条件 mWidgetId = id; mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId)); + // 调用Note的setNoteValue方法更改WidgetId } } - + // 设定WorkingTex + // 参数:更改的text public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { mContent = text; mNote.setTextData(DataColumns.CONTENT, mContent); + // 调用Note的setTextData方法更改WorkingText } } - + // 转变mNote的CallData及CallNote信息 + // 参数:String phoneNumber, long callDate 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); } - + //获取Content public String getContent() { return mContent; } - + //获取AlertDate public long getAlertDate() { return mAlertDate; } - + //获取ModifiedDate 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); } - + //获取CheckListMode public int getCheckListMode() { return mMode; } - + //获取便签id public long getNoteId() { return mNoteId; } - + //获取文件夹id public long getFolderId() { return mFolderId; } - + //获取WidgetId public int getWidgetId() { return mWidgetId; } - + //获取WidgetType public int getWidgetType() { return mWidgetType; } - + // 创建接口 NoteSettingChangedListener,便签更新监视 + // 为NoteEditActivity提供接口 + // 提供函数有 public interface NoteSettingChangedListener { /** * Called when the background color of current note has just changed