Contacts dial source code learning

Source: Internet
Author: User
Tags addall

Address: http://blog.csdn.net/setsail_wu/article/details/7533982

Contacts dial source code learning
  • 1. The contacts dial opens an instance of dialerphoneactivity type and switches through intent in launcher.

Search Method: Use the hotseat_phone_normal.png image displayed in launcherto find the hotseat_phone button Android: Id = "@ + ID/hotseat_left". In the launchhotseat method (Index = 0), run the following code to open the corresponding activity.

if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {Intent intent = mHotseats[index];startActivitySafely(mHotseats[index],"hotseat");}

The content of mhotseats is loaded using the loadhotseats method.

In lanucher/RES/values/arrays. XML, you can find the specific URL of the intent that opens the dial.

  • 2. Rewrite the oncreate method in the dialerphoneactivity class.

Setcontentview (R. layout. dialer_key); // load the layout of the interface. The controls are as follows:

  • Listview Android: Id = "@ + ID/contact_list" is used to display the phone book and call history,
  • Imagebutton Android: Id = "@ + ID/hide_button" is used to hide the keyboard,
  • Imagebutton Android: Id = "@ + ID/delete_button" is used to delete the entered phone number,
  • Edittext Android: Id = "@ + ID/dialer_digits" is used as the phone number input box,
  • Layout = "@ layout/dialer_dialpad" is used for the layout of various numeric buttons,
  • Layout = "@ layout/dialer_dialbutton" contains sim1/sim2/Voice Dialing,
  • Layout = "@ layout/emergency_button" is used for emergency dialing buttons.

Initviews (); // initializes various controls on the interface and adds listener events.

Updatecontactandcallloglist (); // update contact & calllog list.

Registerobserver (); // registerobserver to contactdb changed. The value of miscontactchanged is changed when the data in the phone book database changes. This variable is used to reload records if the data in the telephone database changes when the interface is returned from other interfaces.

  • 3. Method updatecontactandcallloglist ()

This method opens the thread of the testthread class. This thread reads the call record and the record in the phone book, adds the record in the mcustomarraylist, and then sends the redraw message [mhandler. sendemptymessage (redraw)], and then update it to the listview object through the following code in the handlemessage method.

if (null != mAdapter) {mAdapter.mList.clear();mAdapter.mList.addAll(mCustomArrayList);mAdapter.notifyDataSetChanged();} else {mAdapter = new ContactAdapter(mCustomArrayList);mContactList.setAdapter(mAdapter);}

Aftertextchanged (mdigits. gettext () calls madapter. Filter to filter data based on input. Call the binsearch method of the contactadapter class to match the phone number and name.

  • 4. When the keyboard has buttons

Call The onclick method to call the keypressed method and execute the onkeydown method of mdigits. When the string in the edit box is changed, the frameworks layer calls the aftertextchanged method of each textwatcher in the sendtexthaschanged method of the spannablestringbuilder class, And the aftertextchanged method of the dialerphoneactivity class is filtered by input. the filtered results are reloaded by the MList object. Call the notifydatasetchanged method to notify the observer that the basic data has changed and any reflected data set should be refreshed.

  • 5. When you click an item in the search result list on the page, run the onitemclick method. Set the data of the mdigits object to the phone number of the selected item and hide the dial.
  • 6. When you click the dial button, run the dialbuttonpressed method to obtain the phone number of the mdigits object. Run the following code to open the call interface.

    intent.setData(Uri.fromParts("tel", number, null));intent.putExtra(DIALER_SIM,true);intent.putExtra(Phone.PHONE_ID, phoneId);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent);

Note: If the above analysis is incorrect, please correct it.

Contacts dial source code learning
  • 1. The contacts dial opens an instance of dialerphoneactivity type and switches through intent in launcher.

Search Method: Use the hotseat_phone_normal.png image displayed in launcherto find the hotseat_phone button Android: Id = "@ + ID/hotseat_left". In the launchhotseat method (Index = 0), run the following code to open the corresponding activity.

if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {Intent intent = mHotseats[index];startActivitySafely(mHotseats[index],"hotseat");}

The content of mhotseats is loaded using the loadhotseats method.

In lanucher/RES/values/arrays. XML, you can find the specific URL of the intent that opens the dial.

  • 2. Rewrite the oncreate method in the dialerphoneactivity class.

Setcontentview (R. layout. dialer_key); // load the layout of the interface. The controls are as follows:

  • Listview Android: Id = "@ + ID/contact_list" is used to display the phone book and call history,
  • Imagebutton Android: Id = "@ + ID/hide_button" is used to hide the keyboard,
  • Imagebutton Android: Id = "@ + ID/delete_button" is used to delete the entered phone number,
  • Edittext Android: Id = "@ + ID/dialer_digits" is used as the phone number input box,
  • Layout = "@ layout/dialer_dialpad" is used for the layout of various numeric buttons,
  • Layout = "@ layout/dialer_dialbutton" contains sim1/sim2/Voice Dialing,
  • Layout = "@ layout/emergency_button" is used for emergency dialing buttons.

Initviews (); // initializes various controls on the interface and adds listener events.

Updatecontactandcallloglist (); // update contact & calllog list.

Registerobserver (); // registerobserver to contactdb changed. The value of miscontactchanged is changed when the data in the phone book database changes. This variable is used to reload records if the data in the telephone database changes when the interface is returned from other interfaces.

  • 3. Method updatecontactandcallloglist ()

This method opens the thread of the testthread class. This thread reads the call record and the record in the phone book, adds the record in the mcustomarraylist, and then sends the redraw message [mhandler. sendemptymessage (redraw)], and then update it to the listview object through the following code in the handlemessage method.

if (null != mAdapter) {mAdapter.mList.clear();mAdapter.mList.addAll(mCustomArrayList);mAdapter.notifyDataSetChanged();} else {mAdapter = new ContactAdapter(mCustomArrayList);mContactList.setAdapter(mAdapter);}

Aftertextchanged (mdigits. gettext () calls madapter. Filter to filter data based on input. Call the binsearch method of the contactadapter class to match the phone number and name.

  • 4. When the keyboard has buttons

Call The onclick method to call the keypressed method and execute the onkeydown method of mdigits. When the string in the edit box is changed, the frameworks layer calls the aftertextchanged method of each textwatcher in the sendtexthaschanged method of the spannablestringbuilder class, And the aftertextchanged method of the dialerphoneactivity class is filtered by input. the filtered results are reloaded by the MList object. Call the notifydatasetchanged method to notify the observer that the basic data has changed and any reflected data set should be refreshed.

  • 5. When you click an item in the search result list on the page, run the onitemclick method. Set the data of the mdigits object to the phone number of the selected item and hide the dial.
  • 6. When you click the dial button, run the dialbuttonpressed method to obtain the phone number of the mdigits object. Run the following code to open the call interface.

    intent.setData(Uri.fromParts("tel", number, null));intent.putExtra(DIALER_SIM,true);intent.putExtra(Phone.PHONE_ID, phoneId);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent);

Note: If the above analysis is incorrect, please correct it.

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.