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 a1a2455..78cce9f 100644 --- a/app/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/app/src/main/java/net/micode/notes/model/WorkingNote.java @@ -70,7 +70,7 @@ public class WorkingNote { DataColumns.DATA2, DataColumns.DATA3, DataColumns.DATA4, - }; + };//创建并为字符串DATA分配空间 public static final String[] NOTE_PROJECTION = new String[] { NoteColumns.PARENT_ID, @@ -112,7 +112,7 @@ public class WorkingNote { mIsDeleted = false; mMode = 0; mWidgetType = Notes.TYPE_WIDGET_INVALIDE; - } + }//构造函数 // Existing note construct private WorkingNote(Context context, long noteId, long folderId) { @@ -122,12 +122,12 @@ public class WorkingNote { mIsDeleted = 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); + null, null);//回到第一条目 if (cursor != null) { if (cursor.moveToFirst()) { @@ -137,14 +137,14 @@ public class WorkingNote { mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN); mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN); 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); - } + }//没有相应ID,抛出异常 loadNoteData(); - } + }//载入便签 private void loadNoteData() { Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, @@ -165,14 +165,14 @@ public class WorkingNote { } else { Log.d(TAG, "Wrong note type with type:" + type); } - } while (cursor.moveToNext()); - } + } 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); } - } + }//加载便签数据 public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { @@ -181,7 +181,7 @@ public class WorkingNote { note.setWidgetId(widgetId); note.setWidgetType(widgetType); return note; - } + }//创建便签时赋予的属性 public static WorkingNote load(Context context, long id) { return new WorkingNote(context, id, 0); @@ -194,7 +194,7 @@ public class WorkingNote { Log.e(TAG, "Create new note fail with id:" + mNoteId); return false; } - } + }//存在数据库,该方法在下面定义 mNote.syncNote(mContext, mNoteId); @@ -207,14 +207,15 @@ public class WorkingNote { mNoteSettingStatusListener.onWidgetChanged(); } return true; - } else { + }//优先判断价值,该方法在下面定义 + else { return false; } - } + }//保存便签 public boolean existInDatabase() { return mNoteId > 0; - } + }//上面使用到的方法 private boolean isWorthSaving() { if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) @@ -223,21 +224,21 @@ public class WorkingNote { } else { return true; } - } + }//上面使用到的方法 public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; - } + }//设置mNoteSettingStatusListener 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); } - } + }//设置AlertDate public void markDeleted(boolean mark) { mIsDeleted = mark; @@ -245,7 +246,7 @@ public class WorkingNote { && mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onWidgetChanged(); } - } + }//标记删除 public void setBgColorId(int id) { if (id != mBgColorId) { @@ -255,7 +256,7 @@ public class WorkingNote { } mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id)); } - } + }//设置颜色 public void setCheckListMode(int mode) { if (mMode != mode) { @@ -265,28 +266,28 @@ public class WorkingNote { 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)); } - } + }//设置窗口ID 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)); @@ -296,11 +297,11 @@ public class WorkingNote { public boolean hasClockAlert() { return (mAlertDate > 0 ? true : false); - } + }//有无时钟 public String getContent() { return mContent; - } + }//get内容 public long getAlertDate() { return mAlertDate; @@ -341,6 +342,7 @@ public class WorkingNote { public int getWidgetType() { return mWidgetType; } + //定义获取的方法 public interface NoteSettingChangedListener { /** @@ -364,5 +366,5 @@ public class WorkingNote { * @param newMode is new mode */ void onCheckListModeChanged(int oldMode, int newMode); - } + }//定义文本改变接口 }