public void setupActionListener() { if (mListFragment instanceof ContactPickerFragment) { ((ContactPickerFragment) mListFragment) .setOnContactPickerActionListener(new ContactPickerActionListener()); } else if (mListFragment instanceof PhoneNumberPickerFragment) { ((PhoneNumberPickerFragment) mListFragment) .setOnPhoneNumberPickerActionListener(new PhoneNumberPickerActionListener()); } // else if (mListFragment instanceof PostalAddressPickerFragment) { // ((PostalAddressPickerFragment) // mListFragment).setOnPostalAddressPickerActionListener( // new PostalAddressPickerActionListener()); // } else if (mListFragment instanceof EmailAddressPickerFragment) { ((EmailAddressPickerFragment) mListFragment) .setOnEmailAddressPickerActionListener(new EmailAddressPickerActionListener()); } else { throw new IllegalStateException("Unsupported list fragment type: " + mListFragment); } }
/** Creates the fragment based on the current request. */ public void configureListFragment() { switch (mActionCode) { case ContactsRequest.ACTION_INSERT_OR_EDIT_CONTACT: { ContactPickerFragment fragment = new ContactPickerFragment(); fragment.setEditMode(true); fragment.setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_NONE); mListFragment = fragment; break; } case ContactsRequest.ACTION_PICK_CONTACT: { ContactPickerFragment fragment = new ContactPickerFragment(); fragment.setIncludeProfile(mRequest.shouldIncludeProfile()); mListFragment = fragment; break; } case ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT: { mListFragment = new ContactPickerFragment(); break; } case ContactsRequest.ACTION_CREATE_SHORTCUT_CONTACT: { ContactPickerFragment fragment = new ContactPickerFragment(); fragment.setShortcutRequested(true); mListFragment = fragment; break; } case ContactsRequest.ACTION_PICK_PHONE: { PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment(); fragment.setUseCallableUri(true); mListFragment = fragment; break; } case ContactsRequest.ACTION_PICK_EMAIL: { mListFragment = new EmailAddressPickerFragment(); break; } case ContactsRequest.ACTION_CREATE_SHORTCUT_CALL: { PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment(); fragment.setShortcutAction(Intent.ACTION_CALL); mListFragment = fragment; break; } case ContactsRequest.ACTION_CREATE_SHORTCUT_SMS: { PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment(); fragment.setShortcutAction(Intent.ACTION_SENDTO); mListFragment = fragment; break; } // case ContactsRequest.ACTION_PICK_POSTAL: { // PostalAddressPickerFragment fragment = new PostalAddressPickerFragment(); // mListFragment = fragment; // break; // } default: throw new IllegalStateException("Invalid action code: " + mActionCode); } mListFragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode()); mListFragment.setDirectoryResultLimit(DEFAULT_DIRECTORY_RESULT_LIMIT); getFragmentManager() .beginTransaction() .replace(R.id.list_container, mListFragment) .commitAllowingStateLoss(); }