diff --git a/app/src/main/java/net/micode/notes/model/WorkingNote.java b/app/src/main/java/net/micode/notes/model/WorkingNote.java index 12079de..0ca9379 100644 --- a/app/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/app/src/main/java/net/micode/notes/model/WorkingNote.java @@ -61,7 +61,7 @@ public class WorkingNote { private boolean mIsDeleted; private NoteSettingChangedListener mNoteSettingStatusListener; - + // 声明 DATA_PROJECTION字符串数组 public static final String[] DATA_PROJECTION = new String[]{ DataColumns.ID, DataColumns.CONTENT, @@ -71,7 +71,9 @@ public class WorkingNote { DataColumns.DATA3, DataColumns.DATA4, }; - + /** + * // 声明 NOTE_PROJECTION字符串数组 + */ public static final String[] NOTE_PROJECTION = new String[]{ NoteColumns.PARENT_ID, NoteColumns.ALERTED_DATE, @@ -124,11 +126,17 @@ public class WorkingNote { loadNote(); } + /** + * 加载Note + * 通过数据库调用query函数找到第一个条目 + */ 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()) { mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN); @@ -139,6 +147,9 @@ 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); @@ -146,6 +157,10 @@ public class WorkingNote { loadNoteData(); } + /** + * 加载Notedata + */ + private void loadNoteData() { Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[]{ @@ -153,7 +168,13 @@ public class WorkingNote { }, null); if (cursor != null) { + /** + * 查到信息不为空 + */ if (cursor.moveToFirst()) { + /** + * 查看第一项是否存在 + */ do { String type = cursor.getString(DATA_MIME_TYPE_COLUMN); if (DataConstants.NOTE.equals(type)) { @@ -166,6 +187,9 @@ public class WorkingNote { Log.d(TAG, "Wrong note type with type:" + type); } } while (cursor.moveToNext()); + /** + * 查阅所有项,直到为空 + */ } cursor.close(); } else { @@ -174,9 +198,22 @@ public class WorkingNote { } } + /** + * 创建空的Note + * 传参:context,文件夹id,widget,背景颜色 + * @param context + * @param folderId + * @param widgetId + * @param widgetType + * @param defaultBgColorId + * @return + */ 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); @@ -186,10 +223,19 @@ 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 ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) { Log.e(TAG, "Create new note fail with id:" + mNoteId); return false; @@ -211,12 +257,23 @@ public class WorkingNote { return false; } } + /** + * 是否在数据库中存在 + */ public boolean existInDatabase() { return mNoteId > 0; } + /** + * 是否值得保存 + * @return + */ + private boolean isWorthSaving() { + /** + * 被删除,或(不在数据库中 内容为空),或 本地已保存过 + */ if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) || (existInDatabase() && !mNote.isLocalModified())) { return false; @@ -225,10 +282,22 @@ public class WorkingNote { } } + /** + * 设置mNoteSettingStatusListener + * @param l + */ + public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; } + /** + * 设置AlertDate + * 若 mAlertDate与data不同,则更改mAlertDate并设定NoteValue + * @param date + * @param set + */ + public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { mAlertDate = date; @@ -239,7 +308,15 @@ public class WorkingNote { } } + /** + * 设定删除标记 + * @param mark + */ + public void markDeleted(boolean mark) { + /** + * 设定标记 + */ mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) { @@ -247,6 +324,11 @@ public class WorkingNote { } } + /** + * 设定背景颜色 + * @param id + */ + public void setBgColorId(int id) { if (id != mBgColorId) { mBgColorId = id; @@ -257,6 +339,10 @@ public class WorkingNote { } } + /** + * 设定检查列表模式 + * @param mode + */ public void setCheckListMode(int mode) { if (mMode != mode) { if (mNoteSettingStatusListener != null) { @@ -267,6 +353,12 @@ public class WorkingNote { } } + /** + * // 设定WidgetType + * // 参数:type + * @param type + */ + public void setWidgetType(int type) { if (type != mWidgetType) { mWidgetType = type; @@ -274,6 +366,10 @@ public class WorkingNote { } } + /** + * 设定widgetid + * @param id + */ public void setWidgetId(int id) { if (id != mWidgetId) { mWidgetId = id; @@ -281,12 +377,20 @@ public class WorkingNote { } } + /** + * 调用Note的setNoteValue方法更改WidgetId + * @param text + */ + public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { mContent = text; mNote.setTextData(DataColumns.CONTENT, mContent); } } + /** + * 调用Note的setTextData方法更改WorkingText + */ public void convertToCallNote(String phoneNumber, long callDate) { mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate)); @@ -294,54 +398,115 @@ public class WorkingNote { mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER)); } + /** + * 判断是否有时钟题型 + * @return + */ + public boolean hasClockAlert() { return (mAlertDate > 0 ? true : false); } + /** + * 获取Content + * @return + */ + public String getContent() { return mContent; } + /** + * 获取AlertDate + * @return + */ public long getAlertDate() { return mAlertDate; } + /** + * 获取ModifiedDate + * @return + */ public long getModifiedDate() { return mModifiedDate; } + /** + * 获取背景颜色来源id + * @return + */ public int getBgColorResId() { return NoteBgResources.getNoteBgResource(mBgColorId); } + /** + * 获取背景颜色id + * @return + */ + public int getBgColorId() { return mBgColorId; } + /** + * 获取标题背景颜色id + * @return + */ + public int getTitleBgResId() { return NoteBgResources.getNoteTitleBgResource(mBgColorId); } + /** + * 获取CheckListMode + * @return + */ + public int getCheckListMode() { return mMode; } + /** + * 获取便签id + * @return + */ + public long getNoteId() { return mNoteId; } + /** + * 获取文件夹id + * @return + */ + public long getFolderId() { return mFolderId; } + /** + * 获取文件夹id + * @return + */ + public int getWidgetId() { return mWidgetId; } + /** + * 获取WidgetId + * @return + */ + public int getWidgetType() { return mWidgetType; } + /** + * 获取WidgetType + */ + public interface NoteSettingChangedListener { /** * Called when the background color of current note has just changed diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..41dfb87 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists