1. 程式人生 > >android手機原始碼聯絡人頁面新增緊急電話模組

android手機原始碼聯絡人頁面新增緊急電話模組

根據讀原始碼可知,所有顯示聯絡人頁面是在DefaultContactBrowseListFragment類,在其類中我們可一發現 private void addEmptyUserProfileHeader(LayoutInflater inflater)這樣一個方法,其方法的作用就是動態的新增ListView(顯示聯絡人)以上的控制元件,所以我們想要在聯絡人以上新增模組就要了解,其方法裡動態新增模組的流程,
     方法的裡  ListView list = getListView();
        // Put a header with the "ME" name and a view for the number of contacts
        // The view is embedded in a frame view since you cannot change the visibility of a
        // view in a ListView without having a parent view.
        mProfileHeaderContainer = new FrameLayout(inflater.getContext());
        mProfileHeaderContainerCall = new FrameLayout(inflater.getContext());
        mProfileHeader = inflater.inflate(R.layout.user_profile_header, null, false);
        mProfileHeaderCall = inflater.inflate(R.layout.user_profile_header_call, null, false);
        mCounterHeaderView = (TextView) mProfileHeader.findViewById(R.id.contacts_count);
        mProfileTitle = (TextView) mProfileHeader.findViewById(R.id.profile_title);
        mProfileHeaderContainer.addView(mProfileHeader);
        mProfileHeaderContainerCall.addView(mProfileHeaderCall);
        list.addHeaderView(mProfileHeaderContainer, null, false); 是新增頭控制元件的標題所以我們可以在這個地方新增我們自己想要的模組
mMessageContainer = new FrameLayout(inflater.getContext());
        mMessageContainerCall = new FrameLayout(inflater.getContext());
        mMessageContainerFire = new FrameLayout(inflater.getContext());
        mProfileMessage = (Button)inflater.inflate(R.layout.user_profile_button, null, false);
        mProfileMessageCall = (Button)inflater.inflate(R.layout.user_profile_button_call, null, false);
        mProfileMessageFire = (Button)inflater.inflate(R.layout.user_profile_button_fire, null, false);
        mMessageContainer.addView(mProfileMessage);
        mMessageContainerCall.addView(mProfileMessageCall);
        mMessageContainerFire.addView(mProfileMessageFire);
        list.addHeaderView(mMessageContainer, null, true);
        list.addHeaderView(mProfileHeaderContainerCall, null, false);
        list.addHeaderView(mMessageContainerCall, null, true);
        list.addHeaderView(mMessageContainerFire, null, true);

        mProfileMessage.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
                intent.putExtra(ContactEditorFragment.INTENT_EXTRA_NEW_LOCAL_PROFILE, true);
                startActivity(intent);
            }
        });
        mProfileMessageCall.setOnClickListener(new View.OnClickListener(){
            public void onClick(View arg0) {
                Uri uri = Uri.parse("tel:110");
                Intent intent = new Intent(Intent.ACTION_DIAL,uri);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  startActivity(intent);
            }
        }); 再有就是可以新增其他的控制元件還有事件監聽,來完成自己的需求。