Android Phonebook contact UI loading and contact storage process (4)

Source: Internet
Author: User

At 10:23:22 on February 7, Baidu moved the items in the space.

5. KindSectionView

Where is KindSectionView sacred? How is it bound to a DataKind and RawContactDelta? Continue to look at the KindSectionView. In fact, KindSectionView is a common custom View. Its function is to convert the data contained in DataKind into a UI display. What is this View? It has its own xml file: item_kind_section.xml:

 <     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_marginBottom="@dimen/raw_contact_sect_fields_margin_bottom"     android:orientation="vertical">         <         android:id="@+id/kind_title_layout"         layout="@layout/edit_kind_title" />         <         android:id="@+id/kind_editors"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical" />         <         android:id="@+id/add_text"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="start"         android:text="@string/add_new_entry_for_section"         android:drawableStart="@drawable/spb_plus_icn" />     </com.android.contacts.editor.KindSectionView>

We will analyze this image as follows:

Kind_title_layout: the View of the Phone in;

Add_text: "Add new" Button;

Kind_editors: the part between the two. Of course, the add_text click event processing is also in the KindSectionView class, as shown below:

        setDrawingCacheEnabled(     setAlwaysDrawnWithCacheEnabled(         mInflater =         mTitle =     mEditors =     mAddFieldFooter =     mAddFieldFooter.setOnClickListener(                     }

However, we continue to analyze the data following the setState () method of the KindSectionView class. The rebuildFromState () --> createEditorView () and createEditorView () Methods load each DataKind. The Code is as follows:

                    view = mInflater.inflate(mKind.editorLayoutResourceId, mEditors,      }                 (view          Editor editor =         editor.setDeletable(          editor.setEditorListener(        }

The first is mKind. The value is section. setState (kind, state, false, vig) is passed over. It extracts editorLayoutResourceId, parses it into View, binds it to mEditors, and then operates on it. What is editorLayoutResourceId? Let's look back at DataKind:

      editorLayoutResourceId =     maxLinesForDisplay = 1       DataKind(String mimeType,  titleRes,  weight,               .mimeType =     .titleRes =     .weight =     .editable =     .typeOverallMax = -1     .editorLayoutResourceId =     maxLinesForDisplay = 1 }

DataKind has two default constructor, and the default text_fields_editor_view is set for the non-parameter constructor. Take LocalAccountType as an example:

      Context context)      DataKind kind = addKind(             R.string.nameLabelsGroup, -1,              R.layout.structured_name_editor_view));

When adding Name, use R. layout. structured_name_editor_view:

      Context context)      DataKind kind = addKind(                 R.string.nicknameLabelsGroup, 115,                  R.layout.text_fields_editor_view));

When adding NickName, Phone, Email, etc., all are R. layout. text_fields_editor_view. Go back and check the createEditorView () method,

EditorLayoutResourceId is available, and the rest is to display the layout corresponding to this id.

Editor. setValues (mKind, entry, mState, mReadOnly, mViewIdGenerator); view two xml files:

Structured_name_editor_view.xml this is specifically for Name. Later, let's look at text_fields_editor_view.xml:

 <     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical">         <         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="1"         android:orientation="horizontal"         android:gravity="center_vertical"         android:focusable="true"         android:clickable="true">             <             layout="@layout/edit_spinner"             android:layout_width="@dimen/editor_type_label_width"             android:layout_height="@dimen/editor_min_line_item_height"             android:layout_gravity="top"             android:layout_marginEnd="@dimen/raw_contact_edit_spinner_margin_end"             android:visibility="gone" />             <             layout="@layout/edit_field_list_with_anchor_view" />             <             android:layout_width="wrap_content"             android:layout_height="match_parent">                 <                 android:id="@+id/expansion_view_container"                 layout="@layout/edit_expansion_view"                 android:visibility="gone" />                 <                 android:id="@+id/delete_button_container"                 layout="@layout/edit_delete_button"                 android:visibility="gone" />             </FrameLayout>         </LinearLayout>     </com.android.contacts.editor.TextFieldsEditorView>

Edit_spinner: Center "Home" Spinner;

Expansion_view_container: Expand or collapse the Button, which is only used in Postal Address and Name;

Delete_button_container: the cross in;

Inheritance relationship of TextFieldsEditorView class

Let's go to the setValues () method of TextFieldsEditorView:

    setValues(DataKind kind, ValuesDelta entry, RawContactDelta state,            fieldCount =     mFieldEditTexts =       ( index = 0; index < fieldCount; index++          EditField field =          EditText fieldView =          mFieldEditTexts[index] =                 fieldView.addTextChangedListener(                                                  }

First, the setValues () method of the parent class is called. In the setValues () method of the parent class, some UI values are assigned, such as the Spinner mLabel, and an Adapter is set for it. The value is kind. content contained in typeList, as mentioned earlier.

Let's continue to look at the setValues () method of TextFieldsEditorView. There is a for loop that converts kind. obtain all fields in fieldList, create an EditText fieldView, and add them to mFields, mFields = (ViewGroup) findViewById (R. id. editors), from text_fields_editor_view.xml --> edit_field_list_with_anchor_view.xml, as follows:

 <     android:layout_width="0dip"     android:layout_height="wrap_content"     android:layout_weight="1"         android:orientation="vertical">     <          android:id="@+id/editors"          android:layout_width="match_parent"          android:layout_height="wrap_content"          android:orientation="vertical"          android:focusable="true"          android:focusableInTouchMode="true"          android:descendantFocusability="afterDescendants" />     <          android:id="@+id/anchor_view"          android:layout_width="match_parent"          android:layout_height="0px" /> </LinearLayout>

To put it bluntly, the View corresponding to the editors id is used to add an EditText.

Summary:

The most important thing is the RawContactCommonEditorView class setState () method. The for loop is used to retrieve every kind in the account, generate a KindSectionView, and display it. Each KindSectionView may contain multiple fields, depending on the number of editfields added to fieldlist in kind. For example, it contains two editfields.

At this point, the display of Phone UI is complete. You have to carefully read the code for details, such as click events and click events of the Spinner, as mentioned in this Article. However, you have to study the code for details, as for the function of TextChangedListener added to EditText, this design is used to Save contact. We should first remember that each EditText has a TextChangedListener, which should be discussed when analyzing the Save Contact process.

6. Add Name UI

As mentioned above, Name UI is analyzed carefully here.

In raw_contact_editor_view.xml, there is a layout dedicated to adding Name-related UIS:

 <     android:id="@+id/edit_name"     layout="@layout/structured_name_editor_view" />

Enter structured_name_editor_view.xml:

 <     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:minHeight="@dimen/editor_min_line_item_height"     android:orientation="vertical">         <         layout="@layout/edit_spinner"         android:layout_width="@dimen/editor_type_label_width"         android:layout_height="@dimen/editor_min_line_item_height"         android:layout_gravity="top"         android:visibility="gone" />         <         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal"         android:clickable="true">             <             layout="@layout/edit_field_list_with_anchor_view"/>             <             android:id="@+id/expansion_view_container"             layout="@layout/edit_expansion_view"             android:visibility="gone" />             <             android:id="@+id/delete_button_container"             layout="@layout/edit_delete_button"             android:visibility="gone" />     </LinearLayout>     </com.android.contacts.editor.StructuredNameEditorView>

I found this file is very similar to the pipeline. Of course, looking at the inheritance diagram of the StructuredNameEditorView class, I found that StructuredNameEditorView inherits from TextFieldsEditorView. So, his logic is actually in TextFieldsEditorView, just like Phone, it is only because StructedName is special, for example, there is no previous Title, "Add new", and "Spinner. When I used to customize the UI, I needed to change the effects of all edittexts on the page, especially the expanded effects of multiple edittexts, such as Name and Address, in fact, the changes are still made in the setValues () method of TextFieldsEditorView to set the background and other attributes of EditText to meet the customization requirements.

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.