/** * Sets the current tab based on the intent's request type * * @param intent Intent that contains information about which tab should be selected */ private void setCurrentTab(Intent intent) { // If we got here by hitting send and we're in call forward along to the in-call activity final boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.getType()); if (isSendKeyWhileInCall(intent, recentCallsRequest)) { finish(); return; } // Remember the old manually selected tab index so that it can be restored if it is // overwritten by one of the programmatic tab selections final int savedTabIndex = mLastManuallySelectedFragment; final int tabIndex; if (DialpadFragment.phoneIsInUse() || isDialIntent(intent)) { tabIndex = TAB_INDEX_DIALER; } else if (recentCallsRequest) { tabIndex = TAB_INDEX_CALL_LOG; } else { tabIndex = mLastManuallySelectedFragment; } final int previousItemIndex = mViewPager.getCurrentItem(); mViewPager.setCurrentItem(tabIndex, false /* smoothScroll */); if (previousItemIndex != tabIndex) { sendFragmentVisibilityChange(previousItemIndex, false); } mPageChangeListener.setCurrentPosition(tabIndex); sendFragmentVisibilityChange(tabIndex, true); // Restore to the previous manual selection mLastManuallySelectedFragment = savedTabIndex; mDuringSwipe = false; mUserTabClick = false; }
public void setmViewPager(ViewPager mViewPager, int count, int... colors) { if (mViewPager.getAdapter() == null) { throw new IllegalStateException("ViewPager does not have adapter instance."); } mPageChangeListener.setViewPagerChildCount(count); mViewPager.setOnPageChangeListener(mPageChangeListener); if (colors.length == 0) { createDefaultAnimation(); } else { createAnimation(colors); } }
/** * @requires none * @modifies all subscribing page change listeners * @effects notifies all observers of Page Changed events to update themselves */ public static void notifyListeners() { for (PageChangeListener l : observers) { l.update(); } }