diff --git a/doc/model板块用例描述.docx b/doc/model板块用例描述.docx new file mode 100644 index 0000000..374e048 Binary files /dev/null and b/doc/model板块用例描述.docx differ diff --git a/doc/开源代码的泛读报告-苏韬文-202102838008.docx b/doc/开源代码的泛读报告-苏韬文-202102838008.docx new file mode 100644 index 0000000..48ec4fb Binary files /dev/null and b/doc/开源代码的泛读报告-苏韬文-202102838008.docx differ diff --git a/doc/软件工程实验项目泛读报告.docx b/doc/软件工程实验项目泛读报告.docx deleted file mode 100644 index e69de29..0000000 diff --git a/src/model/Note.java b/src/model/Note.java index 6706cf6..f4f5021 100644 --- a/src/model/Note.java +++ b/src/model/Note.java @@ -1,43 +1,21 @@ -/* - * 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; -import android.content.ContentValues; -import android.content.Context; -import android.content.OperationApplicationException; -import android.net.Uri; -import android.os.RemoteException; -import android.util.Log; - -import net.micode.notes.data.Notes; -import net.micode.notes.data.Notes.CallNote; -import net.micode.notes.data.Notes.DataColumns; -import net.micode.notes.data.Notes.NoteColumns; -import net.micode.notes.data.Notes.TextNote; - -import java.util.ArrayList; - - + +import android.content.ContentProviderOperation;//批量的更新、插入、删除数据。 +import android.content.ContentProviderResult;//操作的结果 +import android.content.ContentUris;//用于添加和获取Uri后面的ID +import android.content.ContentValues;//一种用来存储基本数据类型数据的存储机制 +import android.content.Context;//需要用该类来弄清楚调用者的实例 +import android.content.OperationApplicationException;//操作应用程序容错 +import android.net.Uri;//表示待操作的数据 +import android.os.RemoteException;//远程容错 +import android.util.Log;//输出日志,比如说出错、警告等 + public class Note { - private ContentValues mNoteDiffValues; + // private ContentValues mNoteDiffValues; + ContentValues mNoteDiffValues;// private NoteData mNoteData; private static final String TAG = "Note"; + /** * Create a new note id for adding a new note to databases */ @@ -49,66 +27,67 @@ public class Note { values.put(NoteColumns.MODIFIED_DATE, createdTime); values.put(NoteColumns.TYPE, Notes.TYPE_NOTE); values.put(NoteColumns.LOCAL_MODIFIED, 1); - values.put(NoteColumns.PARENT_ID, folderId); + values.put(NoteColumns.PARENT_ID, folderId);//将数据写入数据库表格 Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values); - + //ContentResolver()主要是实现外部应用对ContentProvider中的数据 + //进行添加、删除、修改和查询操作 long noteId = 0; try { noteId = Long.valueOf(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { Log.e(TAG, "Get note id error :" + e.toString()); noteId = 0; - } + }//try-catch异常处理 if (noteId == -1) { throw new IllegalStateException("Wrong note id:" + noteId); } return noteId; } - + public Note() { mNoteDiffValues = new ContentValues(); mNoteData = new NoteData(); - } - + }//定义两个变量用来存储便签的数据,一个是存储便签属性、一个是存储便签内容 + public void setNoteValue(String key, String value) { mNoteDiffValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); - } - + }//设置数据库表格的标签属性数据 + public void setTextData(String key, String value) { mNoteData.setTextData(key, value); - } - + }//设置数据库表格的标签文本内容的数据 + public void setTextDataId(long id) { mNoteData.setTextDataId(id); - } - + }//设置文本数据的ID + public long getTextDataId() { return mNoteData.mTextDataId; - } - + }//得到文本数据的ID + public void setCallDataId(long id) { mNoteData.setCallDataId(id); - } - + }//设置电话号码数据的ID + public void setCallData(String key, String value) { mNoteData.setCallData(key, value); - } - + }//得到电话号码数据的ID + public boolean isLocalModified() { return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); - } - + }//判断是否是本地修改 + public boolean syncNote(Context context, long noteId) { if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); } - + if (!isLocalModified()) { 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 @@ -121,74 +100,74 @@ public class Note { // Do not return, fall through } mNoteDiffValues.clear(); - + if (mNoteData.isLocalModified() && (mNoteData.pushIntoContentResolver(context, noteId) == null)) { return false; } - + return true; - } - - private class NoteData { + }//判断数据是否同步 + + private class NoteData {//定义一个基本的便签内容的数据类,主要包含文本数据和电话号码数据 private long mTextDataId; - - private ContentValues mTextDataValues; - + + private ContentValues mTextDataValues;//文本数据 + private long mCallDataId; - - private ContentValues mCallDataValues; - + + private ContentValues mCallDataValues;//电话号码数据 + private static final String TAG = "NoteData"; - + public NoteData() { mTextDataValues = new ContentValues(); mCallDataValues = new ContentValues(); mTextDataId = 0; 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"); } mTextDataId = id; } - + void setCallDataId(long id) { if (id <= 0) { throw new IllegalArgumentException("Call data id should larger than 0"); } mCallDataId = id; } - + void setCallData(String key, String value) { mCallDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); 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()); } - + //下面函数的作用是将新的数据通过Uri的操作存储到数据库 Uri pushIntoContentResolver(Context context, long noteId) { /** * Check for safety */ if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); - } - + }//判断数据是否合法 + ArrayList operationList = new ArrayList(); - ContentProviderOperation.Builder builder = null; - + ContentProviderOperation.Builder builder = null;//数据库的操作列表 + if(mTextDataValues.size() > 0) { mTextDataValues.put(DataColumns.NOTE_ID, noteId); if (mTextDataId == 0) { @@ -209,8 +188,8 @@ public class Note { operationList.add(builder.build()); } mTextDataValues.clear(); - } - + }//把文本数据存入DataColumns + if(mCallDataValues.size() > 0) { mCallDataValues.put(DataColumns.NOTE_ID, noteId); if (mCallDataId == 0) { @@ -231,8 +210,8 @@ public class Note { operationList.add(builder.build()); } mCallDataValues.clear(); - } - + }//把电话号码数据存入DataColumns + if (operationList.size() > 0) { try { ContentProviderResult[] results = context.getContentResolver().applyBatch( @@ -246,8 +225,8 @@ public class Note { Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); return null; } - } + }//存储过程中的异常处理 return null; } } -} +} \ No newline at end of file diff --git a/src/model/WorkingNote.java b/src/model/WorkingNote.java index be081e4..f67a01f 100644 --- a/src/model/WorkingNote.java +++ b/src/model/WorkingNote.java @@ -1,37 +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.appwidget.AppWidgetManager; -import android.content.ContentUris; -import android.content.Context; -import android.database.Cursor; -import android.text.TextUtils; -import android.util.Log; - -import net.micode.notes.data.Notes; -import net.micode.notes.data.Notes.CallNote; -import net.micode.notes.data.Notes.DataColumns; -import net.micode.notes.data.Notes.DataConstants; -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 private Note mNote; @@ -41,27 +9,22 @@ public class WorkingNote { 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; - + + // 声明 DATA_PROJECTION字符串数组 public static final String[] DATA_PROJECTION = new String[] { DataColumns.ID, DataColumns.CONTENT, @@ -71,7 +34,8 @@ public class WorkingNote { DataColumns.DATA3, DataColumns.DATA4, }; - + + // 声明 NOTE_PROJECTION字符串数组 public static final String[] NOTE_PROJECTION = new String[] { NoteColumns.PARENT_ID, NoteColumns.ALERTED_DATE, @@ -80,29 +44,20 @@ public class WorkingNote { 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) { + public WorkingNote(Context context, long folderId) { mContext = context; mAlertDate = 0; mModifiedDate = System.currentTimeMillis(); @@ -113,7 +68,8 @@ public class WorkingNote { mMode = 0; mWidgetType = Notes.TYPE_WIDGET_INVALIDE; } - + + // WorkingNote的构造函数 // Existing note construct private WorkingNote(Context context, long noteId, long folderId) { mContext = context; @@ -123,12 +79,15 @@ public class WorkingNote { mNote = new Note(); 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,21 +98,24 @@ 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, DataColumns.NOTE_ID + "=?", new String[] { String.valueOf(mNoteId) }, null); - + if (cursor != null) { - if (cursor.moveToFirst()) { + // 查到信息不为空 + if (cursor.moveToFirst()) { // 查看第一项是否存在 do { String type = cursor.getString(DATA_MIME_TYPE_COLUMN); if (DataConstants.NOTE.equals(type)) { @@ -165,7 +127,7 @@ public class WorkingNote { } else { Log.d(TAG, "Wrong note type with type:" + type); } - } while (cursor.moveToNext()); + } while (cursor.moveToNext());//查阅所有项,直到为空 } cursor.close(); } else { @@ -173,31 +135,35 @@ 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); return note; } - + 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; } } - + mNote.syncNote(mContext, mNoteId); - + /** * Update widget content if there exist any widget of this note */ @@ -211,12 +177,15 @@ 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; @@ -224,11 +193,15 @@ public class WorkingNote { return true; } } - + + + // 设置mNoteSettingStatusListener public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; } - + + // 设置AlertDate + // 若 mAlertDate与data不同,则更改mAlertDate并设定NoteValue public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { mAlertDate = date; @@ -238,17 +211,21 @@ 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方法 } } - + + // 设定背景颜色 public void setBgColorId(int id) { - if (id != mBgColorId) { + if (id != mBgColorId) { //设定条件 id != mBgColorId mBgColorId = id; if (mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onBackgroundColorChanged(); @@ -256,9 +233,11 @@ public class WorkingNote { mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id)); } } - + + // 设定检查列表模式 + // 参数:mode public void setCheckListMode(int mode) { - if (mMode != mode) { + if (mMode != mode) { //设定条件 mMode != mode if (mNoteSettingStatusListener != null) { mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode); } @@ -266,98 +245,125 @@ public class WorkingNote { mNote.setTextData(TextNote.MODE, String.valueOf(mMode)); } } - + + + // 设定WidgetType + // 参数:type public void setWidgetType(int type) { - if (type != mWidgetType) { + if (type != mWidgetType) {//设定条件 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) {//设定条件 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)) { + if (!TextUtils.equals(mContent, text)) {//设定条件 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; } - - public interface NoteSettingChangedListener { + + // 创建接口 NoteSettingChangedListener,便签更新监视 + // 为NoteEditActivity提供接口 + // 提供函数有 + 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 @@ -365,4 +371,4 @@ public class WorkingNote { */ void onCheckListModeChanged(int oldMode, int newMode); } -} +} \ No newline at end of file diff --git a/~$del板块用例描述.docx b/~$del板块用例描述.docx new file mode 100644 index 0000000..309ecab Binary files /dev/null and b/~$del板块用例描述.docx differ diff --git a/~$wei.docx b/~$wei.docx new file mode 100644 index 0000000..0d578ed Binary files /dev/null and b/~$wei.docx differ