- android/ 167个模块 (app/content/os/view/widget/graphics/media/hardware/net/telephony/provider等) - java/ 35个模块 (lang/io/util/net/nio/security/crypto/sql/beans/rmi/awt等) - javax/ 4个模块 (net/crypto/security/sql) - org/ 5个模块 (json/w3c_dom/xml_sax/xml_pull/apache_http) - dalvik/ 1个模块 (system) - ~3053个类/接口,方法签名完全对齐Android SDK - 桌面跨平台运行 (Windows/macOS/Linux) - 修复所有导入错误和Python关键字冲突
494 lines
16 KiB
Python
494 lines
16 KiB
Python
"""
|
|
Android app.search 包 — SearchManager, SearchableInfo, SearchView
|
|
方法签名完全对齐 Android SDK
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from typing import Any, Dict, List, Optional, Tuple
|
|
|
|
from .._core import Stub, AndroidOnlyError
|
|
from ..java.lang import RuntimeException
|
|
|
|
IllegalArgumentException = type("IllegalArgumentException", (RuntimeException,), {})
|
|
|
|
__all__ = [
|
|
"SearchManager",
|
|
"SearchableInfo",
|
|
"SearchView",
|
|
"SearchViewSearchAutoComplete",
|
|
"OnQueryTextListener",
|
|
"OnSuggestionListener",
|
|
"OnCloseListener",
|
|
]
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════
|
|
# SearchManager
|
|
# ═══════════════════════════════════════════════════════════════
|
|
|
|
class SearchManager(Stub):
|
|
"""SearchManager — 搜索管理器 (桌面存根)"""
|
|
|
|
INTENT_ACTION_SEARCHABLES_CHANGED = "android.search.action.SEARCHABLES_CHANGED"
|
|
INTENT_ACTION_SEARCH_SETTINGS = "android.search.action.SEARCH_SETTINGS"
|
|
INTENT_ACTION_SEARCH_SETTINGS_CHANGED = "android.search.action.SEARCH_SETTINGS_CHANGED"
|
|
APP_DATA_SEARCH_IS_GLOBAL_SEARCH = "search_is_global_search"
|
|
EXTRA_DATA_KEY = "data_key"
|
|
EXTRA_NEW_SEARCH = "new_search"
|
|
EXTRA_SELECT_QUERY = "select_query"
|
|
EXTRA_WEB_SEARCH_KEY = "web_search_key"
|
|
FLAG_QUERY_REFINEMENT = 0x1
|
|
MENU_KEY = "search"
|
|
MENU_ORDER = 0
|
|
QUERY = "query"
|
|
SUGGEST_COLUMN_FORMAT = "suggest_format"
|
|
SUGGEST_COLUMN_ICON_1 = "suggest_icon_1"
|
|
SUGGEST_COLUMN_ICON_2 = "suggest_icon_2"
|
|
SUGGEST_COLUMN_INTENT_ACTION = "suggest_intent_action"
|
|
SUGGEST_COLUMN_INTENT_DATA = "suggest_intent_data"
|
|
SUGGEST_COLUMN_INTENT_DATA_ID = "suggest_intent_data_id"
|
|
SUGGEST_COLUMN_INTENT_EXTRA_DATA = "suggest_intent_extra_data"
|
|
SUGGEST_COLUMN_QUERY = "suggest_query"
|
|
SUGGEST_COLUMN_SHORTCUT_ID = "suggest_shortcut_id"
|
|
SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING = "suggest_spinner_while_refreshing"
|
|
SUGGEST_COLUMN_TEXT_1 = "suggest_text_1"
|
|
SUGGEST_COLUMN_TEXT_2 = "suggest_text_2"
|
|
SUGGEST_COLUMN_TEXT_2_URL = "suggest_text_2_url"
|
|
SUGGEST_MIME_TYPE = "vnd.android.cursor.dir/vnd.android.search.suggest"
|
|
SUGGEST_NEVER_MAKE_SHORTCUT = "never_make_shortcut"
|
|
SUGGEST_URI_PATH_QUERY = "/search_suggest_query"
|
|
SUGGEST_URI_PATH_SHORTCUT = "/search_suggest_shortcut"
|
|
SUGGEST_URI_PATH_SEARCH = "/search"
|
|
|
|
_instance: Optional["SearchManager"] = None
|
|
|
|
def __init__(self, context: Any = None):
|
|
super().__init__()
|
|
self._context = context
|
|
self._searchable_info: Dict[str, "SearchableInfo"] = {}
|
|
self._global_search_activity: Optional[Any] = None
|
|
self._online_search_enabled = True
|
|
|
|
@staticmethod
|
|
def get(context: Any) -> "SearchManager":
|
|
"""获取搜索管理器"""
|
|
if SearchManager._instance is None:
|
|
SearchManager._instance = SearchManager(context)
|
|
return SearchManager._instance
|
|
|
|
def startSearch(self, initial_query: str, select_init_key: bool, app_search_activity: Any,
|
|
global_search: bool, app_search_data: Any, extra_info: Any) -> None:
|
|
"""开始搜索"""
|
|
pass
|
|
|
|
def triggerSearch(self, query: str, app_search_activity: Any, app_search_data: Any) -> None:
|
|
"""触发搜索"""
|
|
pass
|
|
|
|
def stopSearch(self) -> None:
|
|
"""停止搜索"""
|
|
pass
|
|
|
|
def search(self, query: str) -> None:
|
|
"""执行搜索"""
|
|
pass
|
|
|
|
def setSearchableInfo(self, info: "SearchableInfo") -> None:
|
|
"""设置可搜索信息"""
|
|
self._searchable_info[info.getSearchActivity() or ""] = info
|
|
|
|
def getSearchableInfo(self, component_name: Any) -> Optional["SearchableInfo"]:
|
|
"""获取可搜索信息"""
|
|
return self._searchable_info.get(str(component_name))
|
|
|
|
def getSuggestions(self, query: str, limit: int = 5) -> List[str]:
|
|
"""获取建议"""
|
|
return []
|
|
|
|
def getSearchablesInGlobalSearch(self) -> List["SearchableInfo"]:
|
|
"""获取全局搜索中的可搜索项"""
|
|
return list(self._searchable_info.values())
|
|
|
|
def setGlobalSearch(self, component_name: Any) -> None:
|
|
"""设置全局搜索"""
|
|
pass
|
|
|
|
def getGlobalSearchActivity(self) -> Optional[Any]:
|
|
"""获取全局搜索活动"""
|
|
return self._global_search_activity
|
|
|
|
def launchAssist(self, intent: Any) -> None:
|
|
"""启动辅助"""
|
|
pass
|
|
|
|
def launchQuery(self, query: str, component_name: Any, bundle: Any) -> None:
|
|
"""启动查询"""
|
|
pass
|
|
|
|
def getOnlineSearchEnabled(self) -> bool:
|
|
"""检查在线搜索是否启用"""
|
|
return self._online_search_enabled
|
|
|
|
def setOnlineSearchEnabled(self, enabled: bool) -> None:
|
|
"""设置在线搜索启用"""
|
|
self._online_search_enabled = enabled
|
|
|
|
def onDestroy(self) -> None:
|
|
"""销毁"""
|
|
pass
|
|
|
|
def dismissSearch(self) -> None:
|
|
"""取消搜索"""
|
|
pass
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════
|
|
# SearchableInfo
|
|
# ═══════════════════════════════════════════════════════════════
|
|
|
|
class SearchableInfo(Stub):
|
|
"""SearchableInfo — 可搜索信息 (桌面存根)"""
|
|
|
|
def __init__(self, context: Any = None):
|
|
super().__init__()
|
|
self._context = context
|
|
self._suggest_authority = ""
|
|
self._suggest_package = ""
|
|
self._suggest_intent_action = ""
|
|
self._suggest_intent_data = ""
|
|
self._suggest_path = ""
|
|
self._suggest_selection = ""
|
|
self._suggest_threshold = 1
|
|
self._input_type = 0x0001
|
|
self._ime_options = 0
|
|
self._action_key = 0
|
|
self._action_key_text = ""
|
|
self._action_key_id = 0
|
|
self._voice_search_launch_web_search = False
|
|
self._voice_search_launch_recognizer = False
|
|
self._settings_description = ""
|
|
self._search_activity = ""
|
|
self._search_hint = ""
|
|
self._search_label = ""
|
|
self._search_hint_id = 0
|
|
self._search_label_id = 0
|
|
self._description_id = 0
|
|
self._settings_description_id = 0
|
|
self._icon_id = 0
|
|
self._use_browser_link = False
|
|
self._voice_search_enabled = True
|
|
self._query_after_zero_results = True
|
|
self._is_default = False
|
|
self._search_permissions: List[str] = []
|
|
|
|
def getSuggestAuthority(self) -> str:
|
|
return self._suggest_authority
|
|
|
|
def getSuggestPackage(self) -> str:
|
|
return self._suggest_package
|
|
|
|
def getSuggestIntentAction(self) -> str:
|
|
return self._suggest_intent_action
|
|
|
|
def getSuggestIntentData(self) -> str:
|
|
return self._suggest_intent_data
|
|
|
|
def getSuggestPath(self) -> str:
|
|
return self._suggest_path
|
|
|
|
def getSuggestSelection(self) -> str:
|
|
return self._suggest_selection
|
|
|
|
def getSuggestThreshold(self) -> int:
|
|
return self._suggest_threshold
|
|
|
|
def getInputType(self) -> int:
|
|
return self._input_type
|
|
|
|
def getImeOptions(self) -> int:
|
|
return self._ime_options
|
|
|
|
def getActionKey(self) -> int:
|
|
return self._action_key
|
|
|
|
def getActionKeyText(self) -> str:
|
|
return self._action_key_text
|
|
|
|
def getActionKeyId(self) -> int:
|
|
return self._action_key_id
|
|
|
|
def getVoiceSearchLaunchWebSearch(self) -> bool:
|
|
return self._voice_search_launch_web_search
|
|
|
|
def getVoiceSearchLaunchRecognizer(self) -> bool:
|
|
return self._voice_search_launch_recognizer
|
|
|
|
def getSettingsDescription(self) -> str:
|
|
return self._settings_description
|
|
|
|
def getSearchActivity(self) -> str:
|
|
return self._search_activity
|
|
|
|
def getSearchHint(self) -> str:
|
|
return self._search_hint
|
|
|
|
def getSearchLabel(self) -> str:
|
|
return self._search_label
|
|
|
|
def getSearchHintId(self) -> int:
|
|
return self._search_hint_id
|
|
|
|
def getSearchLabelId(self) -> int:
|
|
return self._search_label_id
|
|
|
|
def getDescriptionId(self) -> int:
|
|
return self._description_id
|
|
|
|
def getSettingsDescriptionId(self) -> int:
|
|
return self._settings_description_id
|
|
|
|
def getIconId(self) -> int:
|
|
return self._icon_id
|
|
|
|
def getUseBrowserLink(self) -> bool:
|
|
return self._use_browser_link
|
|
|
|
def isVoiceSearchEnabled(self) -> bool:
|
|
return self._voice_search_enabled
|
|
|
|
def isQueryAfterZeroResults(self) -> bool:
|
|
return self._query_after_zero_results
|
|
|
|
def isDefault(self) -> bool:
|
|
return self._is_default
|
|
|
|
def getSearchSuggestPermission(self) -> str:
|
|
return "android.permission.SEARCH"
|
|
|
|
def getSearchPermissions(self) -> List[str]:
|
|
return self._search_permissions.copy()
|
|
|
|
def getSearchPermission(self, index: int) -> str:
|
|
if 0 <= index < len(self._search_permissions):
|
|
return self._search_permissions[index]
|
|
return ""
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════
|
|
# SearchView (and inner interfaces / classes)
|
|
# ═══════════════════════════════════════════════════════════════
|
|
|
|
class OnQueryTextListener(Stub):
|
|
"""OnQueryTextListener — 查询文本监听器"""
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def onQueryTextSubmit(self, query: str) -> bool:
|
|
"""查询文本提交"""
|
|
return False
|
|
|
|
def onQueryTextChange(self, new_text: str) -> bool:
|
|
"""查询文本变化"""
|
|
return False
|
|
|
|
|
|
class OnSuggestionListener(Stub):
|
|
"""OnSuggestionListener — 建议监听器"""
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def onSuggestionSelect(self, position: int) -> bool:
|
|
"""建议选中"""
|
|
return False
|
|
|
|
def onSuggestionClick(self, position: int) -> bool:
|
|
"""建议点击"""
|
|
return False
|
|
|
|
|
|
class OnCloseListener(Stub):
|
|
"""OnCloseListener — 关闭监听器"""
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def onClose(self) -> bool:
|
|
"""关闭事件"""
|
|
return False
|
|
|
|
|
|
class SearchViewSearchAutoComplete(Stub):
|
|
"""SearchView.SearchAutoComplete — 搜索自动完成 (桌面存根)"""
|
|
|
|
def __init__(self, context: Any = None):
|
|
super().__init__()
|
|
self._context = context
|
|
self._threshold = 1
|
|
self._text = ""
|
|
|
|
def setThreshold(self, threshold: int) -> None:
|
|
"""设置阈值"""
|
|
self._threshold = threshold
|
|
|
|
def getThreshold(self) -> int:
|
|
"""获取阈值"""
|
|
return self._threshold
|
|
|
|
def enoughToFilter(self) -> bool:
|
|
"""检查是否足够过滤"""
|
|
return len(self._text) >= self._threshold
|
|
|
|
def setText(self, text: str) -> None:
|
|
self._text = text
|
|
|
|
|
|
class SearchView(Stub):
|
|
"""SearchView — 搜索视图 (桌面存根)"""
|
|
|
|
def __init__(self, context: Any = None):
|
|
super().__init__()
|
|
self._context = context
|
|
self._query_hint = ""
|
|
self._query = ""
|
|
self._iconified = True
|
|
self._iconified_by_default = True
|
|
self._submit_button_enabled = True
|
|
self._query_refinement_enabled = True
|
|
self._max_width = 0
|
|
self._input_type = 0x0001
|
|
self._ime_options = 0
|
|
self._searchable_info: Optional[SearchableInfo] = None
|
|
self._auto_complete = SearchViewSearchAutoComplete(context)
|
|
self._query_text_listener: Optional[OnQueryTextListener] = None
|
|
self._suggestion_listener: Optional[OnSuggestionListener] = None
|
|
self._close_listener: Optional[OnCloseListener] = None
|
|
|
|
def setQueryHint(self, hint: str) -> None:
|
|
"""设置查询提示"""
|
|
self._query_hint = hint
|
|
self._auto_complete.setText(hint)
|
|
|
|
def setQuery(self, query: str, submit: bool) -> None:
|
|
"""设置查询"""
|
|
self._query = query
|
|
if self._query_text_listener:
|
|
self._query_text_listener.onQueryTextChange(query)
|
|
if submit and self._query_text_listener:
|
|
self._query_text_listener.onQueryTextSubmit(query)
|
|
|
|
def setIconified(self, iconified: bool) -> None:
|
|
"""设置图标化"""
|
|
self._iconified = iconified
|
|
|
|
def setIconifiedByDefault(self, iconified: bool) -> None:
|
|
"""设置默认图标化"""
|
|
self._iconified_by_default = iconified
|
|
|
|
def isIconifiedByDefault(self) -> bool:
|
|
"""检查是否默认图标化"""
|
|
return self._iconified_by_default
|
|
|
|
def setSubmitButtonEnabled(self, enabled: bool) -> None:
|
|
"""设置提交按钮启用"""
|
|
self._submit_button_enabled = enabled
|
|
|
|
def isSubmitButtonEnabled(self) -> bool:
|
|
"""检查提交按钮是否启用"""
|
|
return self._submit_button_enabled
|
|
|
|
def setQueryRefinementEnabled(self, enabled: bool) -> None:
|
|
"""设置查询细化启用"""
|
|
self._query_refinement_enabled = enabled
|
|
|
|
def isQueryRefinementEnabled(self) -> bool:
|
|
"""检查查询细化是否启用"""
|
|
return self._query_refinement_enabled
|
|
|
|
def setSearchableInfo(self, info: SearchableInfo) -> None:
|
|
"""设置可搜索信息"""
|
|
self._searchable_info = info
|
|
|
|
def onActionViewExpanded(self) -> None:
|
|
"""操作视图展开"""
|
|
pass
|
|
|
|
def onActionViewCollapsed(self) -> None:
|
|
"""操作视图折叠"""
|
|
pass
|
|
|
|
def onClose(self) -> None:
|
|
"""关闭"""
|
|
if self._close_listener:
|
|
self._close_listener.onClose()
|
|
|
|
def onQueryRefine(self, query: str) -> bool:
|
|
"""查询细化"""
|
|
return False
|
|
|
|
def onQueryTextChange(self, new_text: str) -> bool:
|
|
"""查询文本变化"""
|
|
if self._query_text_listener:
|
|
return self._query_text_listener.onQueryTextChange(new_text)
|
|
return False
|
|
|
|
def onQueryTextSubmit(self, query: str) -> bool:
|
|
"""查询文本提交"""
|
|
if self._query_text_listener:
|
|
return self._query_text_listener.onQueryTextSubmit(query)
|
|
return False
|
|
|
|
def onSuggestionSelect(self, position: int) -> bool:
|
|
"""建议选中"""
|
|
if self._suggestion_listener:
|
|
return self._suggestion_listener.onSuggestionSelect(position)
|
|
return False
|
|
|
|
def onSuggestionClick(self, position: int) -> bool:
|
|
"""建议点击"""
|
|
if self._suggestion_listener:
|
|
return self._suggestion_listener.onSuggestionClick(position)
|
|
return False
|
|
|
|
def onSuggestionsDisplayed(self, display: bool) -> None:
|
|
"""建议显示"""
|
|
pass
|
|
|
|
def getQuery(self) -> str:
|
|
"""获取查询"""
|
|
return self._query
|
|
|
|
def getCurrentQuery(self) -> str:
|
|
"""获取当前查询"""
|
|
return self._query
|
|
|
|
def getIconified(self) -> bool:
|
|
"""获取图标化状态"""
|
|
return self._iconified
|
|
|
|
def getMaxWidth(self) -> int:
|
|
"""获取最大宽度"""
|
|
return self._max_width
|
|
|
|
def setMaxWidth(self, max_width: int) -> None:
|
|
"""设置最大宽度"""
|
|
self._max_width = max_width
|
|
|
|
def getInputType(self) -> int:
|
|
"""获取输入类型"""
|
|
return self._input_type
|
|
|
|
def setInputType(self, input_type: int) -> None:
|
|
"""设置输入类型"""
|
|
self._input_type = input_type
|
|
|
|
def getImeOptions(self) -> int:
|
|
"""获取 IME 选项"""
|
|
return self._ime_options
|
|
|
|
def setImeOptions(self, ime_options: int) -> None:
|
|
"""设置 IME 选项"""
|
|
self._ime_options = ime_options |