diff --git a/doc/实践模板-开源软件泛读、标注和维护报告文档.docx b/doc/开源软件泛读、标注和维护报告文档.docx similarity index 100% rename from doc/实践模板-开源软件泛读、标注和维护报告文档.docx rename to doc/开源软件泛读、标注和维护报告文档.docx diff --git a/doc/开源软件的质量分析报告文档.docx b/doc/开源软件的质量分析报告文档.docx new file mode 100644 index 0000000..65cd465 Binary files /dev/null and b/doc/开源软件的质量分析报告文档.docx differ diff --git a/src/main/java/net/micode/notes/data/Contact.java b/src/main/java/net/micode/notes/data/Contact.java index e779900..62495e8 100644 --- a/src/main/java/net/micode/notes/data/Contact.java +++ b/src/main/java/net/micode/notes/data/Contact.java @@ -25,6 +25,15 @@ import android.util.Log; import java.util.HashMap; +/** + * + * @ProjectName: minode + * @Package: net.micode.notes.data + * @ClassName: Contact + * @Description: 该类实现建立联系人数据库的功能 + * @Author: 郑鲲鹏 + * @Date: 2023-12-16 17:57 + */ public class Contact { private static HashMap sContactCache; private static final String TAG = "Contact"; @@ -35,18 +44,29 @@ public class Contact { + "(SELECT raw_contact_id " + " FROM phone_lookup" + " WHERE min_match = '+')"; - + /** + * @method getContact + * @description 该方法用于识别电话号码对应的联系人 + * @date: 2023-12-16 19:24 + * @author: 郑鲲鹏 + * @return string + */ public static String getContact(Context context, String phoneNumber) { if(sContactCache == null) { sContactCache = new HashMap(); } + // 查找HashMap中是否有phoneNumber的信息 + // 2023-12-16 19:43 if(sContactCache.containsKey(phoneNumber)) { return sContactCache.get(phoneNumber); } String selection = CALLER_ID_SELECTION.replace("+", PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); + + // 查找数据库中phoneNumber的信息 + // 2023-12-16 19:43 Cursor cursor = context.getContentResolver().query( Data.CONTENT_URI, new String [] { Phone.DISPLAY_NAME }, @@ -54,6 +74,8 @@ public class Contact { new String[] { phoneNumber }, null); + // 检查是否查询到联系人,找到则将相关信息加入HashMap中,未找到则处理异常 + // 2023-12-16 19:41 if (cursor != null && cursor.moveToFirst()) { try { String name = cursor.getString(0); diff --git a/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java b/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java index 25aaebd..9a92a58 100644 --- a/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java +++ b/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java @@ -47,7 +47,15 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map; - +/** + * + * @ProjectName: minode + * @Package: net.micode.notes.gtask.remote + * @ClassName: GTaskManager + * @Description: 该类实现了便签管理者类,提供同步便签内容和文件夹,添加、更新本地和远端节点等功能 + * @Author: 郑鲲鹏 + * @Date: 2023-12-18 0:17 + */ public class GTaskManager { private static final String TAG = GTaskManager.class.getSimpleName(); @@ -247,6 +255,13 @@ public class GTaskManager { } } + /** + * @method syncContent + * @description 该方法实现本地便签文本同步操作 + * @date: 2023-12-18 0:01 + * @author: 郑鲲鹏 + * @return void + */ private void syncContent() throws NetworkFailureException { int syncType; Cursor c = null; @@ -351,6 +366,13 @@ public class GTaskManager { } + /** + * @method syncFolder + * @description 该方法实现本地文件夹同步操作 + * @date: 2023-12-18 0:04 + * @author: 郑鲲鹏 + * @return void + */ private void syncFolder() throws NetworkFailureException { Cursor c = null; String gid; @@ -476,6 +498,13 @@ public class GTaskManager { GTaskClient.getInstance().commitUpdate(); } + /** + * @method doContentSync + * @description 该方法通过接收到不同类型的syncType来进行对应便签内容同步操作 + * @date: 2023-12-18 0:08 + * @author: 郑鲲鹏 + * @return void + */ private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException { if (mCancelled) { return; diff --git a/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java b/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java index 650015b..3d5065e 100644 --- a/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java +++ b/src/main/java/net/micode/notes/gtask/remote/GTaskSyncService.java @@ -22,7 +22,15 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.IBinder; - +/** + * + * @ProjectName: minode + * @Package: net.micode.notes.gtask.remote + * @ClassName: GTaskSyncService + * @Description: 该类实现了Gtask同步服务的功能,提供开启同步服务、发送同步通知等功能 + * @Author: 郑鲲鹏 + * @Date: 2023-12-17 23:38 + */ public class GTaskSyncService extends Service { public final static String ACTION_STRING_NAME = "sync_action_type"; @@ -42,6 +50,13 @@ public class GTaskSyncService extends Service { private static String mSyncProgress = ""; + /** + * @method startSync + * @description 该方法用于开启Gtask备忘录同步工作 + * @date: 2023-12-17 23:42 + * @author: 郑鲲鹏 + * @return void + */ private void startSync() { if (mSyncTask == null) { mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() { @@ -52,10 +67,19 @@ public class GTaskSyncService extends Service { } }); sendBroadcast(""); + // 使同步任务以单线程队列方式开启运行 + // 2023-12-17 23:46 mSyncTask.execute(); } } + /** + * @method cancelSync + * @description 该方法用于取消Gtask备忘录同步工作 + * @date: 2023-12-17 23:49 + * @author: 郑鲲鹏 + * @return void + */ private void cancelSync() { if (mSyncTask != null) { mSyncTask.cancelSync(); @@ -67,11 +91,20 @@ public class GTaskSyncService extends Service { mSyncTask = null; } + /** + * @method onStartCommand + * @description 该方法用于接受其他组件传递的消息使之重启GtaskSyncService + * @date: 2023-12-17 23:53 + * @author: 郑鲲鹏 + * @return int + */ @Override public int onStartCommand(Intent intent, int flags, int startId) { Bundle bundle = intent.getExtras(); if (bundle != null && bundle.containsKey(ACTION_STRING_NAME)) { switch (bundle.getInt(ACTION_STRING_NAME, ACTION_INVALID)) { + // 开始同步或取消同步 + // 2023-12-17 23:52 case ACTION_START_SYNC: startSync(); break; diff --git a/src/main/java/net/micode/notes/model/WorkingNote.java b/src/main/java/net/micode/notes/model/WorkingNote.java index caaed12..427f1e5 100644 --- a/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/src/main/java/net/micode/notes/model/WorkingNote.java @@ -176,6 +176,14 @@ public class WorkingNote { public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { + /** + * @method: createEmptyNote + * @description: 创建一个空的工作便签,根据传入参数,设置好工作便签的背景色、挂件号、挂件类型 + * @date: 2023/12/20 23:55 + * @author: zhoukexing + * @param: [context, folderId, widgetId, widgetType, defaultBgColorId] + * @return: net.micode.notes.model.WorkingNote 返回一个WorkingNote实例 + */ WorkingNote note = new WorkingNote(context, folderId); note.setBgColorId(defaultBgColorId); note.setWidgetId(widgetId); @@ -233,7 +241,16 @@ public class WorkingNote { } } + /** + * @method: setOnSettingStatusChangedListener + * @description: 将工作目录里的NoteEditActivity项设置为NoteSettingChangedListener + * @date: 2023/12/21 0:10 + * @author: zhoukexing + * @param: [l] NoteEditActivity + * @return: void + */ public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { + //Q: 这里的l是怎么获取的。l是NoteEditActivity @zkx 2023/12/21 mNoteSettingStatusListener = l; } @@ -257,7 +274,14 @@ public class WorkingNote { mNoteSettingStatusListener.onClockAlertChanged(date, set); } } - + /** + * @method: markDeleted + * @description: 描述一下方法的作用 + * @date: 2023/12/21 0:50 + * @author: zhoukexing + * @param: [mark] + * @return: void + */ public void markDeleted(boolean mark) { mIsDeleted = mark; if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID diff --git a/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 03aef1b..6615af7 100644 --- a/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -158,20 +158,22 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 /** * @zkx 2023/12/18 复写了Activity类中的onCreate函数,当用户点击创建时,会进入这个函数 */ + /** + * @method: onCreate + * @description: 进入场景:在list页面,点击“写便签”时进入;在挂件页面,生成挂件时不进入,点进挂件时才进入;…… + * allinall:在进入编辑页面前都会进入 + * @date: 2023/12/18 23:22 + * @author: zhoukexing + * @param: [savedInstanceState] + * @return: void + */ @Override protected void onCreate(Bundle savedInstanceState) { - /** - * @method: onCreate - * @description: 描述一下方法的作用 - * @date: 2023/12/18 23:22 - * @author: zhoukexing - * @param: [savedInstanceState] - * @return: void - */ super.onCreate(savedInstanceState); this.setContentView(R.layout.note_edit); if (savedInstanceState == null && !initActivityState(getIntent())) { + // savedInstanceState? @zhoukexing 2023/12/20 23:45 finish(); return; } @@ -211,6 +213,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 */ mWorkingNote = null; if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) { + // 进入场景:点进一个已有便签 @zhoukexing 2023/12/21 0:14 long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0); mUserQuery = ""; @@ -228,7 +231,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 showToast(R.string.error_note_not_exist); finish(); return false; - } else { + } else {// 如果在数据库里存在,就根据noteId从数据库中加载到工作便签里来 @zhoukexing 2023/12/21 0:16 mWorkingNote = WorkingNote.load(this, noteId); if (mWorkingNote == null) { Log.e(TAG, "load note failed with note id" + noteId); @@ -236,20 +239,21 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 return false; } } - getWindow().setSoftInputMode( + getWindow().setSoftInputMode(// 猜:平滑地展示便签内容 @zhoukexing 2023/12/21 0:18 WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) { - // New note + // 进入场景:一个New note long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0); int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, - Notes.TYPE_WIDGET_INVALIDE); + Notes.TYPE_WIDGET_INVALIDE); // widgetType=0: 新建的挂件,空的 @zhoukexing 2023/12/21 0:02 int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, - ResourceParser.getDefaultBgId(this)); + ResourceParser.getDefaultBgId(this));// TODO: 2023/12/21 背景色的设置 - // Parse call-record note + // Parse call-record note todo + // 解析文档,看是否有号码存在,以便展示的时候渲染 @zhoukexing 2023/12/20 23:49 String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0); if (callDate != 0 && phoneNumber != null) { @@ -259,6 +263,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 long noteId = 0; if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(), phoneNumber, callDate)) > 0) { + // TODO: 2023/12/20 mWorkingNote = WorkingNote.load(this, noteId); if (mWorkingNote == null) { Log.e(TAG, "load call note failed with note id" + noteId); @@ -270,7 +275,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 widgetType, bgResId); mWorkingNote.convertToCallNote(phoneNumber, callDate); } - } else { + } else { // 没有要显示的电话 mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType, bgResId); } @@ -284,6 +289,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 return false; } mWorkingNote.setOnSettingStatusChangedListener(this); + // this是WorkingNote @zhoukexing 2023/12/21 0:08 return true; } @@ -456,6 +462,13 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 clearSettingState(); } + /** + * @method updateWidget + * @description 该方法用于实现与桌面小工具同步的功能 + * @date: 2023-12-18 21:37 + * @author: 郑鲲鹏 + * @return void + */ private void updateWidget() { Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) { @@ -570,12 +583,13 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 if (itemId == R.id.menu_new_note) { // 从item到itemid,用itemid导向对应的不同的动作 @zhoukexing 2023/12/19 23:38 createNewNote(); } else if (itemId == R.id.menu_delete) { + // 构建一个警告⚠对话框,让用户确认是否真的要删除便签 @zhoukexing 2023/12/21 0:41 AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.alert_title_delete)); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setMessage(getString(R.string.alert_message_delete_note)); builder.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { + new DialogInterface.OnClickListener() {// TODO: 2023/12/21 传入了一个函数作为参数? public void onClick(DialogInterface dialog, int which) { deleteCurrentNote(); finish(); @@ -624,8 +638,19 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 * Share note to apps that support {@link Intent#ACTION_SEND} action * and {@text/plain} type */ + /** + * @method sendTo + * @description 该方法用于共享便签 + * @date: 2023-12-18 0:57 + * @author: 郑鲲鹏 + * @return void + */ private void sendTo(Context context, String info) { + // 新建intent消息 + // 2023-12-18 1:00 Intent intent = new Intent(Intent.ACTION_SEND); + // 将要分享的便签内容放入intent中 + // 2023-12-18 1:01 intent.putExtra(Intent.EXTRA_TEXT, info); intent.setType("text/plain"); context.startActivity(intent); @@ -652,7 +677,14 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId()); startActivity(intent); } - + /** + * @method: deleteCurrentNote + * @description: 删除当前便签。如果在数据库里,还要进一步判断是否在根目录下,是否为同步模式 + * @date: 2023/12/21 0:48 + * @author: zhoukexing + * @param: [] + * @return: void + */ private void deleteCurrentNote() { if (mWorkingNote.existInDatabase()) { HashSet ids = new HashSet(); @@ -908,6 +940,13 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 return saved; } + /** + * @method sendToDesktop + * @description 该方法用于将便签发送至桌面,创建快捷方式 + * @date: 2023-12-18 17:27 + * @author: 郑鲲鹏 + * @return void + */ private void sendToDesktop() { /** * Before send message to home, we should make sure that current @@ -919,9 +958,13 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 } if (mWorkingNote.getNoteId() > 0) { + // 新建intent消息,为创建桌面快捷方式的连接器 + // 2023-12-18 17:29 Intent sender = new Intent(); Intent shortcutIntent = new Intent(this, NoteEditActivity.class); shortcutIntent.setAction(Intent.ACTION_VIEW); + // 将便签的相关信息添加进intent中 + // 2023-12-18 17:36 shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId()); sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); sender.putExtra(Intent.EXTRA_SHORTCUT_NAME, @@ -931,6 +974,8 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但 sender.putExtra("duplicate", true); sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); showToast(R.string.info_note_enter_desktop); + // 将便签显示于桌面 + // 2023-12-18 17:38 sendBroadcast(sender); } else { /** diff --git a/src/main/java/net/micode/notes/ui/NoteEditText.java b/src/main/java/net/micode/notes/ui/NoteEditText.java index c6b7a10..e6ca80f 100644 --- a/src/main/java/net/micode/notes/ui/NoteEditText.java +++ b/src/main/java/net/micode/notes/ui/NoteEditText.java @@ -137,11 +137,19 @@ public class NoteEditText extends EditText { } return super.onKeyDown(keyCode, event); } - + /** + * @method: onKeyUp + * @description: 处理键盘输入的键。对于delete键和enter键做了异常处理。 + * 编辑时会进入,按返回键退出时也会进入 + * @date: 2023/12/21 0:28 + * @author: zhoukexing + * @param: [keyCode, event] + * @return: boolean + */ @Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch(keyCode) { - case KeyEvent.KEYCODE_DEL: + case KeyEvent.KEYCODE_DEL: // delete键的号为67 @zhoukexing 2023/12/21 0:31 if (mOnTextViewChangeListener != null) { if (0 == mSelectionStartBeforeDelete && mIndex != 0) { mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString()); @@ -151,7 +159,7 @@ public class NoteEditText extends EditText { Log.d(TAG, "OnTextViewChangeListener was not seted"); } break; - case KeyEvent.KEYCODE_ENTER: + case KeyEvent.KEYCODE_ENTER: // enter键的号为66 @zhoukexing 2023/12/21 0:31 if (mOnTextViewChangeListener != null) { int selectionStart = getSelectionStart(); String text = getText().subSequence(selectionStart, length()).toString(); diff --git a/src/main/java/net/micode/notes/ui/NotesListActivity.java b/src/main/java/net/micode/notes/ui/NotesListActivity.java index c743712..ad9b418 100644 --- a/src/main/java/net/micode/notes/ui/NotesListActivity.java +++ b/src/main/java/net/micode/notes/ui/NotesListActivity.java @@ -730,8 +730,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt } } + /** + * @method updateWidget + * @description 该方法用于实现与桌面小工具同步的功能 + * @date: 2023-12-18 21:37 + * @author: 郑鲲鹏 + * @return void + */ private void updateWidget(int appWidgetId, int appWidgetType) { Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); + // 根据不同大小类型的widget更新Widget + // 2023-12-18 21:41 if (appWidgetType == Notes.TYPE_WIDGET_2X) { intent.setClass(this, NoteWidgetProvider_2x.class); } else if (appWidgetType == Notes.TYPE_WIDGET_4X) { diff --git a/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java b/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java index d5a473a..e7ba376 100644 --- a/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java +++ b/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java @@ -32,11 +32,20 @@ import net.micode.notes.tool.ResourceParser; import net.micode.notes.ui.NoteEditActivity; import net.micode.notes.ui.NotesListActivity; +/** + * + * @ProjectName: minode + * @Package: net.micode.notes.widget + * @ClassName: NoteWidgetProvider + * @Description: 该类继承了AppWidgetProvider,实现挂件添加、删除、更新、启用等功能 + * @Author: 郑鲲鹏 + * @Date: 2023-12-18 21:13 + */ public abstract class NoteWidgetProvider extends AppWidgetProvider { public static final String [] PROJECTION = new String [] { - NoteColumns.ID, - NoteColumns.BG_COLOR_ID, - NoteColumns.SNIPPET + NoteColumns.ID, + NoteColumns.BG_COLOR_ID, + NoteColumns.SNIPPET }; public static final int COLUMN_ID = 0; @@ -45,6 +54,13 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { private static final String TAG = "NoteWidgetProvider"; + /** + * @method onDeleted + * @description 该方法用于删除Widget + * @date: 2023-12-18 21:18 + * @author: 郑鲲鹏 + * @return void + */ @Override public void onDeleted(Context context, int[] appWidgetIds) { ContentValues values = new ContentValues(); @@ -65,12 +81,19 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { null); } + /** + * @method update + * @description 该方法用于添加或更新Widget + * @date: 2023-12-18 21:11 + * @author: 郑鲲鹏 + * @return void + */ protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { update(context, appWidgetManager, appWidgetIds, false); } private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, - boolean privacyMode) { + boolean privacyMode) { for (int i = 0; i < appWidgetIds.length; i++) { if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) { int bgId = ResourceParser.getDefaultBgId(context);