Sms ui-session editing page (3) History

Source: Internet
Author: User
Tags what interface
Session editing page (3) History 1. Preface The previous article has a simple understanding of the receiver UI. Let's take a look at the loading of SMS history records and interface updates. For example, when we send a text message, the page displays "sending", "sent", "sent", and the receiving time of the received text message, it is explained in a separate article, mainly considering the importance of the UI. 2. Function Analysis 2.1 the initialization of the SMS history page is still in the oncreate method of composemessageactivity by calling the initmessagelist method:
    private void initMessageList() {        if (mMsgListAdapter != null) {            return;        }        String highlightString = getIntent().getStringExtra("highlight");        Pattern highlight = highlightString == null            ? null            : Pattern.compile("\\b" + Pattern.quote(highlightString), Pattern.CASE_INSENSITIVE);        // Initialize the list adapter with a null cursor.        mMsgListAdapter = new MessageListAdapter(this, null, mMsgListView, true, highlight);        mMsgListAdapter.setOnDataSetChangedListener(mDataSetChangedListener);        mMsgListAdapter.setMsgListItemHandler(mMessageListItemHandler);        mMsgListView.setAdapter(mMsgListAdapter);        mMsgListView.setItemsCanFocus(false);        mMsgListView.setVisibility(View.VISIBLE);        mMsgListView.setOnCreateContextMenuListener(mMsgListMenuCreateListener);        mMsgListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {                if (view != null) {                    ((MessageListItem) view).onMessageListItemClick();                }            }        });    }

This method is initialized to display the listview in the historical record list, and to fill in the listview adapter, and set the listener and long press menu.

2.2 UI analysis 2.2.1 The following is a brief introduction to the UI. Let's take a look at what the history is like and what interface elements are made up to get a preliminary idea of this interface. Is the UI of the SMS history,
The History history UI contains at least the following UI components: Contact Profile, contact number or name, content, receipt, and sending time, for MMS, the corresponding attachments and themes are displayed. Of course, in addition to these, there are some error display UIS and so on. 2.2.2 UI layout analysis: to check how the UI is laid out, first let's take a look at how the messagelistadapter class binds the UI? This class has two important methods to bind the UI and data to BindView and newview. newview is used to load the layout file and define a text message UI, bindView is used to set the data obtained from the SMS database to the UI on newview. Let's take a look at how the system defines this UI
    @Override    public View newView(Context context, Cursor cursor, ViewGroup parent) {        return mInflater.inflate(R.layout.message_list_item, parent, false);    }

The UI is defined in the layout file. Here, the android UI is very clever. Some people who have worked on the development of j2s may be impressed by the XML layout of Android, it is estimated that many people have doubts about why the XML layout is not introduced by the j2's UI. The implementation of the j2's UI relies entirely on a line of code, which is complex and lengthy. Let's take a look at the mysterious layout file.

<COM. android. MMS. UI. messagelistitem xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Id = "@ + ID/msg_list_item" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: background = "@ drawable/listitem_background" Android: Orientation = "horizontal"> <linearlayout Android: Id = "@ + ID/mms_layout_view_parent" Android: paddingleft = "5dip" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: layout_weight = "1" Android: Orientation = "vertical"> <viewstub Android: id = "@ + ID/mms_layout_view_stub" Android: Layout = "@ layout/mms_layout_view"MMS attachment UI, which also has its own layout file. You can view the UI of the MMS attachment, which contains an iamgeviewAndroid: layout_width = "match_parent"There is also a playbutton.Android: layout_height = "wrap_content"/> <relativelayout Android: layout_width = "match_parent" Android: layout_height = "wrap_content"> <android. widget. quickcontactbadge Android: layout_marginleft = "0dip" Android: layout_marginright = "5dip" Android: layout_margintop = "5dip" Android: layout_marginbottom = "5dip" Android: id = "@ + ID/Avatar" style = "? Android: ATTR/quickcontactbadgestylewindowsmall "/>Used to display the contact icon<View Android: layout_width = "match_parent" Android: layout_height = "0dip" Android: layout_below = "@ ID/Avatar"/> <linearlayout Android: id = "@ + ID/status_icons" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_alignbottom = "@ ID/text_view"Text message content, subject, timeAndroid: layout_alignparentright = "true" Android: layout_marginbottom = "8dip" Android: Orientation = "horizontal"> <imageview Android: Id = "@ + ID/locked_indicator" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/ic_lock_message_sms"This function is used to lock the image and icon of a text message. When you lock a text message, delete the session.Android: paddingright = "3dip"Other messages are deleted, but locked messages are not deleted. This prevents accidental deletion.Android: visibility = "gone"/> <imageview Android: Id = "@ + ID/delivered_indicator" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"The text message transfer report may be the Fail icon and a transfer icon after the transfer report is opened.Android: paddingright = "3dip" Android: visibility = "gone"/> <imageview Android: Id = "@ + ID/details_indicator" Android: layout_width = "wrap_content"Unclear for the momentAndroid: layout_height = "wrap_content" Android: src = "@ drawable/ic_sms_mms_details" Android: visibility = "gone"/> </linearlayout> </relativelayout> </linearlayout> <viewstub Android: Id = "@ + ID/mms_downloading_view_stub" Android: layout = "@ layout/mms_downloading_view"If the MMS is not downloaded, the UI is displayed. The UI has a Download button and a textview. When you click the buttonAndroid: layout_gravity = "center_vertical"Status updated to being downloadedAndroid: layout_width = "wrap_content" Android: layout_height = "wrap_content"/> </COM. Android. mms. UI. messagelistitem>

The preceding figure shows the UI contained in the last short MMS Message. The corresponding UI value is set based on the current status of the short MMS Message and displayed to the user. As for how to set the value, the next response is decomposed. 2.2.3 BindView Method for binding data. The core code is as follows:

@ Override public void BindView (view, context, cursor) {If (view instanceof messagelistitem) {string type = cursor. getstring (mcolumnsmap. mcolumnmsgtype); long msgid = cursor. getlong (mcolumnsmap. mcolumnmsgid); messageitem msgitem = getcachedmessageitem (type, msgid, cursor); If (msgitem! = NULL) {messagelistitem MLI = (messagelistitem) view; messageitem oldmessageitem = MLI. getmessageitem (); If (oldmessageitem! = NULL) {string oldaddress = oldmessageitem. maddress; If (oldaddress! = NULL) {hashset <messagelistitem> set = maddresstomessagelistitems. Get (oldaddress); If (set! = NULL) {set. Remove (MLI) ;}} MLI. BIND (mavatarcache, msgitem); important
The above code is very simple. It binds the queried text message to the UI. The binding here involves the bind method of messagelistitem. The setting of each field is not parsed here. If you are interested, you can check the code, which is very simple. The 2.4 long-press button sets a long-press event for each text message and provides the following functions for users. It is not completely displayed here, but we can know the specific functions through the code. Mmsglistmenucreatelistener this variable is used to create a menu. The Listener event of the menu is handled by msglistmenuclicklistener. The following code processes each menu
Private final class msglistmenuclicklistener implements menuitem. onmenuitemclicklistener {public Boolean onmenuitemclick (menuitem item) {If (! Iscursorvalid () {return false;} cursor = mmsglistadapter. getcursor (); string type = cursor. getstring (column_msg_type); long msgid = cursor. getlong (column_id); messageitem msgitem = getmessageitem (type, msgid, true); If (msgitem = NULL) {return false;} switch (item. getitemid () {Case menu_edit_message: edit the SMS editmessageitem (msgitem); drawbottompanel (); Return true; Case menu_copy_messag E_text: copy the text copytoclipboard (msgitem. mbody); Return true; Case menu_forward_message: Forward the message forwardmessage (msgitem); Return true; Case menu_view_slideshow: view the slide messageutils. viewmmsmessageattachment (composemessageactivity. this, contenturis. withappendedid (MMs. content_uri, msgid), null); Return true; Case menu_view_message_details: {view SMS information: contains the SMS size, sending and receiving time string messagedetails = messageutils. getme Ssagedetails (composemessageactivity. this, cursor, msgitem. mmessagesize); New alertdialog. builder (composemessageactivity. this ). settitle (R. string. message_details_title ). setmessage (messagedetails ). setpositivebutton (Android. r. string. OK, null ). setcancelable (true ). show (); Return true;} case menu_delete_message: {Delete SMS deletemessagelistener L = new deletemessagelistener (msgitem. mmessageuri, msgite M. mlocked); confirmdeletedialog (L, msgitem. mlocked); Return true;} case menu_delivery_report: SMS delivery report showdeliveryreport (msgid, type); Return true; Case menu_copy_to_sdcard: {copy SMS to sdcard string successmessage = getresources (). getstring (R. string. copy_to_sdcard_success, saved_attachment_dir); string resultmessage = copymedia (msgid )? Successmessage: getresources (). getstring (R. string. copy_to_sdcard_fail); toast. maketext (composemessageactivity. this, resultmessage, toast. length_short ). show (); Return true;} case menu_copy_to_drm_provider: {int resid = getdrmmimesavedstringrsrc (msgid, copytodrmprovider (msgid); toast. maketext (composemessageactivity. this, resid, toast. length_short ). show (); Return true;} case menu_lock_message: {lock SMS lockmessage (msgitem, true); Return true;} case menu_unlock_message: {unlock lockmessage (msgitem, false ); return true;} case menu_copy_to_sim: {copy the SMS to the SIM card if (hasicccardcount ()> 1) {string [] items = new string [telephonymanager. getphonecount ()]; for (INT I = 0; I <items. length; I ++) {items [I] = getmultisimname (I);} copytosimselectlistener listener = new copytosimselectlistener (msgitem); New alertdialog. builder (composemessageactivity. this ). settitle (R. string. copy_to_sim ). seticon (Android. r. drawable. ic_dialog_info ). setpositivebutton (Android. r. string. OK, listener ). setsinglechoiceitems (items, 0, listener ). setcancelable (true ). show () ;}else {copytosimwithtoast (msgitem) ;}return true ;}default: Return false ;}}}
3. Summary
Here is a brief introduction to the UI. As for some specific small details, you can see the code.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.