Android自带Contacts代码分析 1
Target: Find out the codes for search contacts and move it to the keyboard.
Based on the code of Android 2.3.7
- When user press the search key in the Contacts, an search box will pop up for user, and “ldh” will get “Liu Dehua” or 刘德华. contacts_search_content.xml is the layout for searching contacts, it only used in ContactsListActivity.java.
-
Function ContactsListActivity.setupSearchView will set the change listener which will carry out searching task when user changed the characters
-
Find function ContactsListActivity.onSearchTextChanged
Comes to this function, nearly everything is in your hand.
Continue:
Now we know that the filter (such as “ldh”) is set to mAdapter, then adapter will filter the correct result automatically. In fact the mAdapter is a CursorAdapter, it holds a cursor and the filter is set to the cursor. When the result get, function ContactItemListAdapter.changeCursor will be called.
Print the function call stack with changeCursor as below:
D/DBG ( 1899): com.android.contacts.ContactsListActivity.startQuery(ContactsListActivity.java:3346)
D/DBG ( 1899): com.android.contacts.ContactsListActivity.onResume(ContactsListActivity.java:1194)
D/DBG ( 1899): android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
The first change is by onResume; and the rest changes are triggered by filter, in function onSearchTextChanged. Refer to codes .CursorFilter.publishResults for detail.
By now, the way how Android Contacts searches contacts is cleared, to get more detailed information, you have to look into the codes.
标签集合/Tag clouds
C++
Symbain
轻松汇编
算法
论文学习
资治通鉴
Delphi
编程之美
Poco
MFC
Linux
IFC
知乎
汇编
数据分析
交叉编译
poco
j2me
android
XML
Java
DTD
飞信
零宽断言
诺基亚
联系人
编程
真值表
池西木
正则表达式
多线程
命令行
优化
stream
configure
cmake
VIM
UiAutomator
TDD
Symbian
Sqlite
SourceInsight
Python
MPAndroidChart
Kotlin
Flutter
Dokka
Chatgpt