|
|
|
|
@ -42,6 +42,7 @@ import android.view.ContextMenu;
|
|
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
|
|
|
|
import android.view.Display;
|
|
|
|
|
import android.view.HapticFeedbackConstants;
|
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
@ -51,6 +52,8 @@ import android.view.View;
|
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
|
import android.view.View.OnCreateContextMenuListener;
|
|
|
|
|
import android.view.View.OnTouchListener;
|
|
|
|
|
import android.widget.TextView.OnEditorActionListener;
|
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
import android.widget.AdapterView.OnItemClickListener;
|
|
|
|
|
@ -333,8 +336,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
mSearchRunnable = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
// 执行搜索查询
|
|
|
|
|
setSearchMode(!TextUtils.isEmpty(mSearchQuery), mSearchQuery);
|
|
|
|
|
// 执行搜索查询:如果已经处于搜索模式,只更新搜索结果,不退出搜索模式
|
|
|
|
|
// 这样可以确保搜索栏在用户输入时保持可见
|
|
|
|
|
if (mIsSearchMode) {
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
} else if (!TextUtils.isEmpty(mSearchQuery)) {
|
|
|
|
|
// 如果不在搜索模式但有搜索字符串,进入搜索模式
|
|
|
|
|
setSearchMode(true, mSearchQuery);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -349,9 +358,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
// 文本变化时的处理
|
|
|
|
|
mSearchQuery = s.toString();
|
|
|
|
|
Log.d(TAG, "Search text changed: '" + mSearchQuery + "'");
|
|
|
|
|
// 移除之前的搜索任务
|
|
|
|
|
mSearchEditText.removeCallbacks(mSearchRunnable);
|
|
|
|
|
// 延迟执行搜索任务
|
|
|
|
|
Log.d(TAG, "Posting search runnable with delay: " + SEARCH_DEBOUNCE_DELAY + "ms");
|
|
|
|
|
mSearchEditText.postDelayed(mSearchRunnable, SEARCH_DEBOUNCE_DELAY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -361,6 +372,28 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 搜索输入框编辑器动作监听器(处理虚拟键盘上的搜索按钮)
|
|
|
|
|
mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
|
|
// 检查是否是搜索动作
|
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
|
|
|
|
// 获取搜索查询
|
|
|
|
|
String query = mSearchEditText.getText().toString().trim();
|
|
|
|
|
if (!TextUtils.isEmpty(query)) {
|
|
|
|
|
// 设置搜索模式并执行搜索
|
|
|
|
|
setSearchMode(true, query);
|
|
|
|
|
// 保存搜索历史
|
|
|
|
|
saveSearchHistory(query);
|
|
|
|
|
// 隐藏软键盘
|
|
|
|
|
hideSoftInput(mSearchEditText);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 清除搜索按钮点击监听器
|
|
|
|
|
mClearSearchButton.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
@ -789,9 +822,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
|
|
|
|
|
Log.d(TAG, "onQueryComplete called with token: " + token + ", cursor: " + cursor + ", count: " + (cursor != null ? cursor.getCount() : -1));
|
|
|
|
|
|
|
|
|
|
switch (token) {
|
|
|
|
|
case FOLDER_NOTE_LIST_QUERY_TOKEN:
|
|
|
|
|
// 查询笔记列表完成,更新适配器
|
|
|
|
|
Log.d(TAG, "Updating notes list adapter with cursor, count: " + (cursor != null ? cursor.getCount() : -1));
|
|
|
|
|
mNotesListAdapter.changeCursor(cursor);
|
|
|
|
|
break;
|
|
|
|
|
case FOLDER_LIST_QUERY_TOKEN:
|
|
|
|
|
@ -1462,6 +1498,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
private void setSearchMode(boolean isSearchMode, String searchQuery) {
|
|
|
|
|
mIsSearchMode = isSearchMode;
|
|
|
|
|
mSearchQuery = searchQuery;
|
|
|
|
|
|
|
|
|
|
// 移除任何待执行的搜索任务,避免状态冲突
|
|
|
|
|
mSearchEditText.removeCallbacks(mSearchRunnable);
|
|
|
|
|
|
|
|
|
|
startAsyncNotesListQuery();
|
|
|
|
|
|
|
|
|
|
// 更新UI,显示或隐藏搜索相关控件
|
|
|
|
|
@ -1496,6 +1536,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
* OMO
|
|
|
|
|
*/
|
|
|
|
|
public void handleSearchClick(View view) {
|
|
|
|
|
Log.d(TAG, "Search button clicked, showing search bar");
|
|
|
|
|
// 显示搜索栏并聚焦到搜索输入框
|
|
|
|
|
setSearchMode(true, mSearchQuery != null ? mSearchQuery : "");
|
|
|
|
|
mSearchEditText.requestFocus();
|
|
|
|
|
@ -1504,6 +1545,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
|
|
|
|
|
if (imm != null) {
|
|
|
|
|
imm.showSoftInput(mSearchEditText, InputMethodManager.SHOW_IMPLICIT);
|
|
|
|
|
}
|
|
|
|
|
Log.d(TAG, "Search bar displayed, search mode: " + mIsSearchMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|