diff --git a/README.md b/README.md index 31d3d09..4490cf1 100644 --- a/README.md +++ b/README.md @@ -1 +1,14 @@ -seminote +# 2023年秋软件工程实践任务一--1 + +小组成员:郑鲲鹏,李泽锴,周柯杏 + +实践内容:小米便签代码的阅读、标注和分析 + +实践时间:2023.11.20- + +实践记录: + +1. 2023.11.23 zkp加入分支管理 +2. 2023.11.23 18:37 OK all of us are in the correct project +3. 2023.11.26 22:30 creat new zhengkunpeng_branch +4. 2023.11.27 9:19 creat new zhoukexing_branch diff --git a/doc/实践模板-开源软件泛读、标注和维护报告文档.docx b/doc/实践模板-开源软件泛读、标注和维护报告文档.docx index 41612d9..3e73494 100644 Binary files a/doc/实践模板-开源软件泛读、标注和维护报告文档.docx and b/doc/实践模板-开源软件泛读、标注和维护报告文档.docx differ diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index de1ef09..6219318 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -40,8 +40,7 @@ android:label="@string/app_name" android:launchMode="singleTop" android:theme="@style/NoteTheme" - android:uiOptions="splitActionBarWhenNarrow"> - + android:windowSoftInputMode="adjustPan" > diff --git a/src/main/java/net/micode/notes/data/NotesProvider.java b/src/main/java/net/micode/notes/data/NotesProvider.java index f8a2cc5..6f95a92 100644 --- a/src/main/java/net/micode/notes/data/NotesProvider.java +++ b/src/main/java/net/micode/notes/data/NotesProvider.java @@ -48,6 +48,7 @@ public class NotesProvider extends ContentProvider { private static final int URI_DATA_ITEM = 4; private static final int URI_SEARCH = 5; + private static final int URI_SEARCH_SUGGEST = 6; static { diff --git a/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java b/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java index 4bdd6c6..d28af4d 100644 --- a/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java +++ b/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java @@ -15,7 +15,6 @@ */ package net.micode.notes.gtask.exception; - public class NetworkFailureException extends Exception { private static final long serialVersionUID = 2107610287180234136L; @@ -26,8 +25,7 @@ public class NetworkFailureException extends Exception { public NetworkFailureException(String paramString) { super(paramString); } - public NetworkFailureException(String paramString, Throwable paramThrowable) { super(paramString, paramThrowable); } -} +} \ No newline at end of file diff --git a/src/main/java/net/micode/notes/model/WorkingNote.java b/src/main/java/net/micode/notes/model/WorkingNote.java index 6b83f06..4e5a4e7 100644 --- a/src/main/java/net/micode/notes/model/WorkingNote.java +++ b/src/main/java/net/micode/notes/model/WorkingNote.java @@ -229,11 +229,22 @@ public class WorkingNote { mNoteSettingStatusListener = l; } + /** + * @Method setAlertDate + * @Date 2023/12/13 11:43 + * @param date 提醒日期 + * @param set 动作(关闭或开启) + * @Author lenovo + * @Return void + * @Description 设置一个提醒时间 + */ 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); } diff --git a/src/main/java/net/micode/notes/tool/DataUtils.java b/src/main/java/net/micode/notes/tool/DataUtils.java index e918390..7ef3485 100644 --- a/src/main/java/net/micode/notes/tool/DataUtils.java +++ b/src/main/java/net/micode/notes/tool/DataUtils.java @@ -135,8 +135,22 @@ public class DataUtils { } return count; } - + /** + * @Method visibleInNoteDatabase + * @Date 2023/12/13 9:08 + * @param resolver + * @param noteId + * @param type + * @Author lenovo + * @Return boolean + * @Description 访问数据库中是否有 noteId 对应的便签 + */ public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) { + /** + * withAppendedId 将 URI 和 ID 连接成一个新的URI + * query 返回 Uri 中符合 selection 的表格 + * lenovo 2023/12/13 9:06 + */ Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, diff --git a/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java b/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java index 8ad2de7..156cc8a 100644 --- a/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java +++ b/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java @@ -47,13 +47,28 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD MediaPlayer mPlayer; @Override + /** + * @Method onCreate + * @Date 2023/12/13 8:15 + * @param savedInstanceState + * @Author lenovo + * @Return void + * @Description + */ protected void onCreate(Bundle savedInstanceState) { + /** + * Bundel 类似于 map,key-value存储 + * super 代表父类, 调用 onCreate 用于恢复上次结束的状态 + * lenovo 2023/12/13 8:39 + */ super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); final Window win = getWindow(); + // 在屏幕锁定时显示 win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); + // 锁屏时到闹钟提示时间后,点亮屏幕 if (!isScreenOn()) { win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON @@ -66,6 +81,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD try { mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1)); mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId); + // 超出长度则变为 substr + "..." mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0, SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info) : mSnippet; @@ -75,6 +91,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD } mPlayer = new MediaPlayer(); + // 查找数据库中有没有 mNoteId 的便签, 如果有则激发对话框 + 闹钟提示音 if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) { showActionDialog(); playAlarmSound(); diff --git a/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 3e0ead6..619e70b 100644 --- a/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -72,8 +72,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class NoteEditActivity extends Activity implements OnClickListener, - NoteSettingChangedListener, OnTextViewChangeListener { +public class NoteEditActivity extends Activity //NOTE: extends--单继承,但可多重继承 @zhoukexing 2023/12/17 23:29 + implements OnClickListener, NoteSettingChangedListener, OnTextViewChangeListener { //NOTE: implements--实现接口 @zhoukexing 2023/12/17 23:24 + /** NOTE: + * + * @zhoukexing 2023/12/17 23:39 + */ private class HeadViewHolder { public TextView tvModified; @@ -149,8 +153,21 @@ public class NoteEditActivity extends Activity implements OnClickListener, private String mUserQuery; private Pattern mPattern; + /*--- 以上是此类中的数据区,以下是方法区 ---*/ + + /** + * @zkx 2023/12/18 复写了Activity类中的onCreate函数,当用户点击创建时,会进入这个函数 + */ @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); @@ -180,6 +197,14 @@ public class NoteEditActivity extends Activity implements OnClickListener, } private boolean initActivityState(Intent intent) { + /** + * @method: initActivityState + * @description: 根据intent(Key-Value)内容,初始化一个便签编辑活动 + * @date: 2023/12/18 23:31 + * @author: zhoukexing + * @param: [intent] + * @return: boolean 为真则初始化成功,为假则失败。失败原因:不存在、(call)load失败、intent内容错误 + */ /** * If the user specified the {@link Intent#ACTION_VIEW} but not provided with id, * then jump to the NotesListActivity @@ -295,15 +320,32 @@ public class NoteEditActivity extends Activity implements OnClickListener, showAlertHeader(); } + /** + * @Method showAlertHeader + * @Date 2023/12/13 11:32 + * @Author lenovo + * @Return void + * @Description 在便签页面的上方栏显示提醒信息 + */ private void showAlertHeader() { if (mWorkingNote.hasClockAlert()) { long time = System.currentTimeMillis(); if (time > mWorkingNote.getAlertDate()) { + // 闹钟时间大于当前时间, 显示 "Expired", 闹钟失效 mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired); } else { + // 显示正常闹钟信息 mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString( mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS)); } + /** + * setVisibility() + * 用于设置空间的可见性 + * VISIBLE 可见 + * INVISIBLE 不可见,但是占用一个位置 + * GNONE 不可见且不占用位置 + * lenovo 2023/12/13 11:28 + */ mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE); mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE); } else { @@ -364,6 +406,14 @@ public class NoteEditActivity extends Activity implements OnClickListener, } private void initResources() { + /** + * @method: initResources + * @description: 初始化资源。被onCreate唯一调用 + * @date: 2023/12/18 23:36 + * @author: zhoukexing + * @param: [] + * @return: void + */ mHeadViewPanel = findViewById(R.id.note_title); mNoteHeaderHolder = new HeadViewHolder(); mNoteHeaderHolder.tvModified = (TextView) findViewById(R.id.tv_modified_date); @@ -430,7 +480,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, if (id == R.id.btn_set_bg_color) { mNoteBgColorSelector.setVisibility(View.VISIBLE); findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( - - View.VISIBLE); + View.VISIBLE); } else if (sBgSelectorBtnsMap.containsKey(id)) { findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( View.GONE); @@ -543,8 +593,16 @@ public class NoteEditActivity extends Activity implements OnClickListener, return true; } + /** + * @Method setReminder + * @Date 2023/12/13 12:52 + * @Author lenovo + * @Return void + * @Description 显示时间选择器,默认时间为当前时间 + */ private void setReminder() { DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis()); + // 设置时间选择器的监听事件,当选中 date 之后调用 setAlertDate 设置提醒时间 d.setOnDateTimeSetListener(new OnDateTimeSetListener() { public void OnDateTimeSet(AlertDialog dialog, long date) { mWorkingNote.setAlertDate(date , true); @@ -570,7 +628,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, // For safety, start a new NoteEditActivity finish(); - Intent intent = new Intent(this, NoteEditActivity.class); + Intent intent = new Intent(this, NoteEditActivity.class); //Q: 在类的内部,还没有实现完全时,启动这个类自己?@zkx 2023/12/17 intent.setAction(Intent.ACTION_INSERT_OR_EDIT); intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId()); startActivity(intent); @@ -602,6 +660,15 @@ public class NoteEditActivity extends Activity implements OnClickListener, return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0; } + /** + * @Method onClockAlertChanged + * @Date 2023/12/13 9:52 + * @param date + * @param set 0 取消 1 设置 + * @Author lenovo + * @Return void + * @Description 设置提醒的监听事件 + */ public void onClockAlertChanged(long date, boolean set) { /** * User could set clock to an unsaved note, so before setting the @@ -617,8 +684,10 @@ public class NoteEditActivity extends Activity implements OnClickListener, AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE)); showAlertHeader(); if(!set) { + // 取消监听事件 alarmManager.cancel(pendingIntent); } else { + // 设置监听事件,到时间启动提醒 alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); } } else { @@ -860,4 +929,4 @@ public class NoteEditActivity extends Activity implements OnClickListener, private void showToast(int resId, int duration) { Toast.makeText(this, resId, duration).show(); } -} +} //NOTE: 这一整个文件就是这一个类 @zhoukexing 2023/12/17 23:41 diff --git a/src/main/java/net/micode/notes/ui/NotesListActivity.java b/src/main/java/net/micode/notes/ui/NotesListActivity.java index c488a0b..ab29bfa 100644 --- a/src/main/java/net/micode/notes/ui/NotesListActivity.java +++ b/src/main/java/net/micode/notes/ui/NotesListActivity.java @@ -406,6 +406,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt }; + //TODO add comments of this method private void startAsyncNotesListQuery() { String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION : NORMAL_SELECTION; @@ -504,6 +505,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt }.execute(); } + // TODO add comments of this method private void deleteFolder(long folderId) { if (folderId == Notes.ID_ROOT_FOLDER) { Log.e(TAG, "Wrong folder id, should not happen " + folderId); @@ -538,6 +540,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE); } + // TODO add comments of this method private void openFolder(NoteItemData data) { mCurrentFolderId = data.getId(); startAsyncNotesListQuery(); @@ -839,12 +842,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt return true; } + //TODO add comments of this method @Override public boolean onSearchRequested() { startSearch(null, false, null /* appData */, false); return true; } + //TODO add comments of this method private void exportNoteToText() { final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this); new AsyncTask() { @@ -938,6 +943,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt } + // TODO add comments of this method private void startQueryDestinationFolders() { String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?"; selection = (mState == ListEditState.NOTE_LIST) ? selection: diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml index fb8bb04..21e7620 100644 --- a/src/main/res/values/styles.xml +++ b/src/main/res/values/styles.xml @@ -63,7 +63,7 @@ \ No newline at end of file