add comments

zhengkunpeng_branch
parent 4067865c54
commit 5fc15752f5

@ -175,6 +175,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
if (savedInstanceState == null && !initActivityState(getIntent())) { if (savedInstanceState == null && !initActivityState(getIntent())) {
// savedInstanceState? @zhoukexing 2023/12/20 23:45 // savedInstanceState? @zhoukexing 2023/12/20 23:45
// 表示之前保存的状态,用于还原数据 @lzk 2024/1/3 23:33
finish(); finish();
return; return;
} }
@ -219,10 +220,10 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
/** /**
* Starting from the searched result * Starting from the searched result
*/ */
// 高亮搜索内容 @lzk 2024/1/3 10:10
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) { if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY)); noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY); mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
// 高亮搜索内容 @lzk 2024/1/3 10:10
} }
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) { if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
@ -366,6 +367,7 @@ public class NoteEditActivity extends Activity //NOTE: extends--单继承,但
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
// 若为搜索事件则设置高亮
if (Intent.ACTION_SEARCH.equals(intent.getAction())) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
mUserQuery = intent.getStringExtra(SearchManager.QUERY); mUserQuery = intent.getStringExtra(SearchManager.QUERY);
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)); mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));

@ -148,6 +148,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
*/ */
setAppInfoFromRawRes(); setAppInfoFromRawRes();
Intent intent = getIntent(); Intent intent = getIntent();
// 搜索页面
if (Intent.ACTION_SEARCH.equals(intent.getAction())) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY); String query = intent.getStringExtra(SearchManager.QUERY);
mNotesListAdapter.setmQuery(query); mNotesListAdapter.setmQuery(query);

@ -40,7 +40,7 @@ public class NotesListAdapter extends CursorAdapter {
private HashMap<Integer, String> mSnippetPosition; private HashMap<Integer, String> mSnippetPosition;
private int mNotesCount; private int mNotesCount;
private boolean mChoiceMode; private boolean mChoiceMode;
private String mQuery; private String mQuery; // 搜索串
public static class AppWidgetAttribute { public static class AppWidgetAttribute {
public int widgetId; public int widgetId;
@ -59,6 +59,7 @@ public class NotesListAdapter extends CursorAdapter {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent); View view = super.getView(position, convertView, parent);
// 仅显示便签项中包含搜索串的便签
if(!TextUtils.isEmpty(mQuery) && !mSnippetPosition.get(position).contains(mQuery)) { if(!TextUtils.isEmpty(mQuery) && !mSnippetPosition.get(position).contains(mQuery)) {
view.setVisibility(View.GONE); view.setVisibility(View.GONE);
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(0,1); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(0,1);
@ -180,13 +181,14 @@ public class NotesListAdapter extends CursorAdapter {
protected void onContentChanged() { protected void onContentChanged() {
super.onContentChanged(); super.onContentChanged();
calcNotesCount(); calcNotesCount();
updateSnippetMap(); // 在数据发生改变时更新 Snippet 到 Position 的映射
} }
@Override @Override
public void changeCursor(Cursor cursor) { public void changeCursor(Cursor cursor) {
super.changeCursor(cursor); super.changeCursor(cursor);
calcNotesCount(); calcNotesCount();
updateSnippetMap(); updateSnippetMap(); // 在数据发生改变时更新 Snippet 到 Position 的映射
} }
private void updateSnippetMap() { private void updateSnippetMap() {

Loading…
Cancel
Save