@Override public void onAttachFragment(Fragment fragment) { // This method can be called before onCreate(), at which point we cannot rely on ViewPager. // In that case, we will setup the "current position" soon after the ViewPager is ready. final int currentPosition = mViewPager != null ? mViewPager.getCurrentItem() : -1; if (fragment instanceof DialpadFragment) { mDialpadFragment = (DialpadFragment) fragment; mDialpadFragment.setListener(mDialpadListener); if (currentPosition == TAB_INDEX_DIALER) { mDialpadFragment.onVisibilityChanged(true); } } else if (fragment instanceof CallLogFragment) { mCallLogFragment = (CallLogFragment) fragment; if (currentPosition == TAB_INDEX_CALL_LOG) { mCallLogFragment.onVisibilityChanged(true); } } else if (fragment instanceof PhoneFavoriteFragment) { mPhoneFavoriteFragment = (PhoneFavoriteFragment) fragment; mPhoneFavoriteFragment.setListener(mPhoneFavoriteListener); if (mContactListFilterController != null && mContactListFilterController.getFilter() != null) { mPhoneFavoriteFragment.setFilter(mContactListFilterController.getFilter()); } } else if (fragment instanceof PhoneNumberPickerFragment) { mSearchFragment = (PhoneNumberPickerFragment) fragment; mSearchFragment.setOnPhoneNumberPickerActionListener(mPhoneNumberPickerActionListener); mSearchFragment.setQuickContactEnabled(true); mSearchFragment.setDarkTheme(true); mSearchFragment.setPhotoPosition(ContactListItemView.PhotoPosition.LEFT); if (mContactListFilterController != null && mContactListFilterController.getFilter() != null) { mSearchFragment.setFilter(mContactListFilterController.getFilter()); } // Here we assume that we're not on the search mode, so let's hide the fragment. // // We get here either when the fragment is created (normal case), or after configuration // changes. In the former case, we're not in search mode because we can only // enter search mode if the fragment is created. (see enterSearchUi()) // In the latter case we're not in search mode either because we don't retain // mInSearchUi -- ideally we should but at this point it's not supported. mSearchFragment.setUserVisibleHint(false); // After configuration changes fragments will forget their "hidden" state, so make // sure to hide it. if (!mSearchFragment.isHidden()) { final FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.hide(mSearchFragment); transaction.commitAllowingStateLoss(); } } }
@Override public void onStart() { super.onStart(); if (mPhoneFavoriteFragment != null) { mPhoneFavoriteFragment.setFilter(mContactListFilterController.getFilter()); } if (mSearchFragment != null) { mSearchFragment.setFilter(mContactListFilterController.getFilter()); } if (mDuringSwipe || mUserTabClick) { if (DEBUG) Log.d(TAG, "reset buggy flag state.."); mDuringSwipe = false; mUserTabClick = false; } }
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); final Intent intent = getIntent(); fixIntent(intent); setContentView(R.layout.dialtacts_activity); mContactListFilterController = ContactListFilterController.getInstance(this); mContactListFilterController.addListener(mContactListFilterListener); findViewById(R.id.dialtacts_frame).addOnLayoutChangeListener(mFirstLayoutListener); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(new ViewPagerAdapter(getFragmentManager())); mViewPager.setOnPageChangeListener(mPageChangeListener); // Setup the ActionBar tabs (the order matches the tab-index contants TAB_INDEX_*) setupDialer(); setupCallLog(); setupFavorites(); getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); getActionBar().setDisplayShowTitleEnabled(false); getActionBar().setDisplayShowHomeEnabled(false); // Load the last manually loaded tab mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mLastManuallySelectedFragment = mPrefs.getInt(PREF_LAST_MANUALLY_SELECTED_TAB, PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT); if (mLastManuallySelectedFragment >= TAB_INDEX_COUNT) { // Stored value may have exceeded the number of current tabs. Reset it. mLastManuallySelectedFragment = PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT; } setCurrentTab(intent); if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction()) && icicle == null) { setupFilterText(intent); } }
@Override public void onDestroy() { super.onDestroy(); mContactListFilterController.removeListener(mContactListFilterListener); }