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

Source: Internet
Author: User

At 10:46:30 on February 7, Baidu moved the items in the space.

In the previous article, we analyzed the UI loading, and mentioned an important object: RawContactDeltaList mState. As I mentioned earlier, this object is very important and related to the saving of contacts, now let's analyze how the contacts are saved.

1. Thousands of miles tracking mState

The ContactEditorFragment class bindEditorsForNewContact () method creates a RawContactDelta object insert. The Code is as follows:

                    RawContact rawContact =       (newAccount !=       }          RawContactDelta insert =          (mState ==                   mState =     }             }

MState is a RawContactDeltaList object, while insert is a RawContactDelta. In the above Code, mState. add (insert). Next, we will see that in the bindEditors () method:

 RawContactDelta rawContactDelta =  (rawContactDelta !=      editor =          (          (!rawContactDelta.isVisible())                  }

We found that rawContactDelta in createContactEditorView (rawContactDelta) is the first object in mState, that is, the insert created earlier. What is insert?

insert = (Uri=content:    Values==_id, FromTemplate=, data_set=, _id=-2==={})

As you can see, insert is only a RawContactDelta object that only contains account information and Entries is empty. This object is passed as a parameter to the createContactEditorView (rawContactDelta) method, which includes:

 editor.setState(rawContactDelta, type, mViewIdGenerator, isEditingUserProfile());

As we have analyzed earlier, editor is a custom BaseRawContactEditorView with the following parameters:

RawContactDelta: The RawContactDelta object passed in;

Type: Account type. LocalAccountType is used here;

IsEditingUserProfile (): whether to edit the "Myself" entry;

At this time, the rawContactDelta object enters the BaseRawContactEditorView class, which calls the super of the parent class RawContactCommonEditorView. setState (state, type, vig, isProfile); this method has an important else statement block, which has been analyzed as follows:

              (kind.fieldList == )        KindSectionView section = (KindSectionView)mInflater.inflate(R.layout.item_kind_section, mFields,        section.setState(kind, state,   }

RawContactDelta is passed to KindSectionView as a parameter, and enters the KindSectionView class through code section. setState (kind, state, false, vig); In the rebuildFromState () method:

                         (!                                        }

As you can see, here mState. getMimeEntries (mKind. mimeType), the root mKind. mimeType extracts the entry from the mState, and then transmits the entry to the reateEditorView () method, with the following code:

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

It is found that rawContactDelta and the entry generated based on mimetype are transmitted as parameters. By using the editor. setValues () method, we have analyzed that editor is TextFieldsEditorView. The setValue () method is as follows:

  fieldCount = mFieldEditTexts =   ( index = 0; index < fieldCount; index++      EditField field =      EditText fieldView = ...

This method should be very familiar, that is, according to the method of loading EditText in fieldlist in kind, and also registers a TextChangedListener for the generated EditText, as follows:

 fieldView.addTextChangedListener(                   });

As for the transmitted rawContactDelta and entry objects, the setValues () method of the parent class is called and assigned to the mState and mEntry objects of LabeledEditorView respectively. Since TextChangedListener is added to the EditText object, we can think of it as the setting listening method triggered when the content in EditText is changed. Check this listening method:

          (!             }

The onFieldChanged () method is in the LabeledEditorView class, which is in the same class as the mState and mEntry object. Let's look at its saveValue () method:

    }

We found that the user input information is stored in the mEntry. Since the mEntry is generated from the mState, these values are saved to the mState. In the saveValue () method, as follows:

       Log.d("David", "column = " +     Log.d("David", "value = " +      Log.d("David", "mState = " + }

For example, I only input "D" in Name. Let's look at the log:

Column is "StructuredName. GIVEN_NAME" in BaseAccountType. data2 corresponds to the field in the database. For the database, we will analyze it later;

 kind.fieldList.add(                    FLAGS_PERSON_NAME).setNeedFocus());

Value indicates the value entered by the user;

MState is the RawContactDelta object passed in from ContactEditorFragment. It is taken from RawContactDeltaList mState. This mState (in ContactEditorFragment) object is very important because it is used when the user saves the contact. In the second to the last row, mimetype = vnd. android. cursor. item/name, data2 = D. That is to say, the contact information entered by the user is saved in the corresponding mimetype. For example, if this is Name, I will enter the name and number at the same time and check the log again:

 

The Name I entered is David, number = 18611975588.

The above code traces the mState in a thousand miles and shows how the data entered by the user is organized, just because the object and the value contained in the object are used when the user clicks to save the Button.

 

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.