ICodeLocation structure and related classes
.. \ Packages \ apps \ MMS \ SRC \ com \ Android \ MMS \ UI: stores related classes displayed on the Interface
.. \ Packages \ apps \ MMS \ SRC \ com \ Android \ MMS \ data: storage interface display required data-related classes
Main classes:
Conversationlist: Information dialog interface --> listactivity
Conversationlistadapter: adapter --> cursoradapter
Conversationlistitem: listitem view on the dialog interface --> relativelayout
Conversationlistitemdata: displays the required data in the dialog list.
Conversation: displays all data of all required dialogs
Contactlist: the contact corresponding to each thread Information
Contact: A contact data.
2. interaction process:
The page displays the data acquisition process:
Class Interaction Process:
2. Data Query and update Flowchart
Three-code implementation process analysis
1 conversationlistStart Query
Onstart(){
......
Startasyncquery ();
}
Actually:
Startasyncquery(){
......
// Mqueryhandler --> internal class of threadlistqueryhandler conversationlist
// Ultimately inherited fromAsyncqueryhandler
Conversation.Startqueryforall(Mqueryhandler,Thread_list_query_token);
}
2 conversationCall the asynchronous query thread
Conversation.Startqueryforall-->
Public static voidStartqueryforall(Asyncqueryhandler handler, int token ){
......
FinalAsyncqueryhandlerQueryhandler = handler;
Queryhandler. postdelayed (New runnable (){
// Anonymous internal class
Public void run (){
Queryhandler. startquery(
Querytoken, null, sallthreadsuri,
All_threads_projection, null, null, conversations. default_sort_order );
}
}, 10 );
Conversations. default_sort_order );
}
(AsyncqueryhandlerAsynchronous query composed of a user thread and a working thread
This query is: All threadsInformation;
3 asyncqueryhandlerQuery Process
// Parameter description
Public voidStartquery(INT token, object cookie, Uri,
String [] projection, string selection, string [] selectionargs,
String orderby ){
//Start a worker thread
Mworkerthreadhandler. sendmessage (MSG );
}
-- Return to the caller's thread after the worker thread completes the query;
-- Execute the onquerycomplete function of asyncqueryhandler;
-- Return to the self-implemented onquerycomplete function inherited from the class of asyncqueryhandler;
-- Execute to the onquerycomplete function of threadlistqueryhandler;
-- Notification to conversationlist, so far the process of querying thread information is complete;
Data Query requires contentprovider to interact with the database.
InAsyncqueryhandlerInternal class worker threadWorkerhandlerFunctionsHandlemessage completed;
Asyncqueryhandler:
A helper class to help make handling asynchronous contentresolver queries easier.
Asyncqueryhandler has two handlermessages,
One is based on Logoff of external threads,
One is the Logoff of the new handlerthread implemented based on the internal workerhandler.
External call of startquery will send the query
Workerhandler processing, that is, querying in the new thread,
After workerhandler completes processing, it sends the result to the handlermessage of asyncqueryhandler to call the corresponding onxxxcomplete function.
Here, the query result is returned to the original thread for processing, which achieves message interaction between two threads through two handlermessages.
AsyncqueryhandlerThe principle process of step query is not analyzed in detail here;
It involves threads,Handle,MessageAnd so on
ContentproviderHow to interact with the database is not analyzed in detail here;
4 threadlistqueryhandler
Conversationlist class internal class: inherited from asyncqueryhandler;
Rewrite Abstract Functions to receive feedback from query results;
Let's take a look at this function:
@ Override
Protected void onquerycomplete (INT token, object cookie, cursor ){
Switch (token ){
CaseThread_list_query_token:
......
// Mlistadapter belongsConversationlistadapter
Mlistadapter.Changecursor(Cursor );//UpdateUIData
}
}
-- Now the work will be transferred to conversationlistadapter;
-- Generate the required viewiten and bind the UI to display the required data;
Conversationlistadapter inherits fromCursoradapter;
AboutCursoradapterFunctions and implementation principles are not analyzed in detail here;
5 conversationlistadapter
Inherited from: cursoradapter;
A brief look: the relationship between listview on the adapter and cursor:
The adapter serves as a bridge between the listview interface and data,
When each item in the list is displayed on the page,GetviewMethod returns a view
(The specific functions of cursoradapter are not analyzed in detail here)
Take a lookCursoradapterInGetviewFunction:
@ Override
Public ViewGetview(INT position, view convertview, viewgroup parent ){
......
View V;
//The role here is crucialDecide whether to create a newViewitem
If (convertview = NULL ){
// Create a viewitem
V =Newview(Mcontext, mcursor, parent );
} Else {
//InvolvedRecyclerMechanism Never create unlimitedItem, Reuse
V =Convertview;
}
// Allocate data to the viewitem to be displayed
BindView(V, mcontext, mcursor );
Return V;
}
Abstract
Newview: ReturnsView, CustomViewitem, Which needs to be rewritten;
BindView: Bind data, which must be overwritten;
Next let's take a lookConversationlistadapterImplementation of these two functions:
Newview:
@ Override
Public ViewNewview(Context, cursor, viewgroup parent ){
//LayoutinflaterObtain and instantiate the layout file XML under Res \ Layout;
// Here isListviewitem
Return mfactory. Inflate (R. layout.Conversation_list_item, Parent, false );
}
(DetailsLayoutinflaterIs not analyzed in detail here)
Let's look at the layout of conversation_list_item:
<Com. Android. mms. UI. conversationlistitem xmlns: Android = "http:...">
//Quick contact ID Show a Contact Image Click to bring up the relevant functions:Tell,MSG
<Android. widget. quickcontactbadge Android: Id = "@ + ID/Avatar"/>
// ViewitemControls that can be accommodated
<Imageview Android: Id = "@ + ID/presence"/>
<Textview Android: Id = "@ + ID/from"/>
<Textview Android: Id = "@ + ID/date"/>
<Imageview Android: Id = "@ + ID/error"/>
<Imageview Android: Id = "@ + ID/attachment"/>
<Textview Android: Id = "@ + ID/subject"/>
</COM. Android. mms. UI. conversationlistitem>
BindView:
@ Override
Public voidBindView(View view, context, cursor ){
// Convert the listviewitem to the Information List
Conversationlistitem headerview = (conversationlistitem) view;
//UseCursorBuild dialog information Associate Information Data and contact data
Conversation Conv = conversation.From(Context, cursor );
// Construct a single conversation information data
Conversationlistitemdata CH = new conversationlistitemdata (context, Conv );
// Bind data
Headerview. BIND (context, CH );
}
It is constructed cyclically based on the number of data obtained by cursor;
To be continued next article: add contact data in thread
MMS module conversationlist Process Analysis (2)