2013年9月24日星期二

Android system comes APP analysis - SMS app

 

Android operating system itself is a huge open-source software repository can understand familiar with both Android system design framework , you can also get efficient applications written. Instead, an analysis of the source code from Google official AOSP source 4.0.1_r1, my Android version is CM 4.2.2. The Android system analysis, the phone's operating system version and some inconsistencies in the source version will not have much impact, but if you need to install the source code modifications to the phone inside the case, the least likely to encounter the problem is Keep the phone in the system version and source version is completely in agreement.

 

1. program entry found

 

Each application should have its own entrance , use of JAVA Android applications are no exception. Confirm Apply to confirm the entry corresponding to the application source code in the system the first step in the analysis is the first step in the application . My approach is used to analyze the SMS app will run up through the Android comes with a tool to get the current name of the activity that occupies the main interface .

 

Stackoverflow answer in http://stackoverflow.com/questions/13193592/adb-android-getting-the-name-of-the-current-activity gives three solutions to this problem way :

 

1) play Hierarchy View (Window-> Open Perspective-> Other-> Hierarchy View), the Windows bar shows the current occupy bold screen activity and package, as shown below. Which com.android.mms is the application package name , com.adnroid.mms.ui.ConversationList is a specific Activity name.

 

 

 

2) can also be viewed directly open the Windows bar . (Window-> Show View-> Others-> Windows), consistent with results on the map .

 

3) Use dumpsys command : adb shell "dumpsys window windows | grep-E 'mCurrentFocus | mFocusedApp'", the results are as follows :

 

dumpsys use see : http://stackoverflow. com/questions/11201659/whats-android-adb-shell-dumpsys-tool-and-its-benefits

 

 

2. procedures Functional Analysis

 

determine SMS app registration and the main Activity , you can search through software ( here is everything) to determine SMS app position in the source packages \ apps \ Mms \ src \ com \ android \ mms \ ui, and SMS app startup activity is inherited from ListActivity 's ConversationList.

 

1) ActionBar constructor

 

in onCreateOptionsMenu function by importing conversation_list_menu loading menu items.

 
  
    public boolean onCreateOptionsMenu(Menu menu) { 
getMenuInflater().inflate(R.menu.conversation_list_menu, menu);
 
 
conversation_list_menu.xml中设置了:发送、搜索、设置、删除所有等5个按钮。
 
  
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

<item android:id="@+id/action_compose_new"
android:title
="@string/new_message"
android:icon
="@drawable/ic_menu_msg_compose_holo_dark"
android:showAsAction
="always|withText" />

<item android:id="@+id/search"
android:title
="@string/menu_search"
android:icon
="@drawable/ic_menu_search_holo_dark"
android:showAsAction
="ifRoom|collapseActionView"
android:actionViewClass
="android.widget.SearchView" />

<item android:id="@+id/action_settings"
android:title
="@string/menu_preferences"
android:icon
="@android:drawable/ic_menu_preferences" />

<item android:id="@+id/action_delete_all"
android:title
="@string/menu_delete_all"
android:icon
="@drawable/ic_menu_trash_holo_dark" />

<item android:id="@+id/action_debug_dump"
android:title
="@string/menu_debug_dump" />
</menu>
 
 

oncreate function of setupActionBar (), from a functional point of view is used to set Actionbar , and can display the number of unread messages , but in the CM on the phone did not see a corresponding view.

 
  
    private void setupActionBar() { 
ActionBar actionBar
= getActionBar();

ViewGroup v
= (ViewGroup)LayoutInflater.from(this)
.inflate(R.layout.conversation_list_actionbar,
null);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(v,
new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_VERTICAL
| Gravity.RIGHT));

mUnreadConvCount
= (TextView)v.findViewById(R.id.unread_conv_count);
}
 
 

2) listview structure

 

in oncreate () to set the properties listview which setOnCreateContextMenuListener set ContextMenu, through the setting of this option , the user clicks on a listview column , call onContextItemSelected function of MENU_VIEW: {openThread (threadId); break; }. can jump to the SMS interface .

 
  
        mQueryHandler = new ThreadListQueryHandler(getContentResolver()); 

ListView listView
= getListView();
listView.setOnCreateContextMenuListener(mConvListOnCreateContextMenuListener);
listView.setOnKeyListener(mThreadListKeyListener);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(
new ModeCallback());

// Tell the list view which view to display when the list is empty
View emptyView = findViewById(R.id.empty);
listView.setEmptyView(emptyView);

        initListAdapter();
 
 

listview initialization , oncreate function of initListAdapter () as follows : < br />

 
  
    private void initListAdapter() { 
mListAdapter
= new ConversationListAdapter(this, null);
mListAdapter.setOnContentChangedListener(mContentChangedListener);
setListAdapter(mListAdapter);
getListView().setRecyclerListener(mListAdapter);
}
 
 

没有评论:

发表评论