コード例 #1
1
  /**
   * 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;
  }
コード例 #2
0
        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
          if (DEBUG) {
            Log.d(TAG, "onTabSelected(). tab: " + tab + ", mDuringSwipe: " + mDuringSwipe);
          }
          // When the user swipes the screen horizontally, this method will be called after
          // ViewPager.SCROLL_STATE_DRAGGING and ViewPager.SCROLL_STATE_SETTLING events, while
          // when the user clicks a tab at the ActionBar at the top, this will be called before
          // them. This logic interprets the order difference as a difference of the user action.
          if (!mDuringSwipe) {
            if (mDialpadFragment != null) {
              if (DEBUG) Log.d(TAG, "Immediately hide fake buttons for tab selection case");
              mDialpadFragment.updateFakeMenuButtonsVisibility(false);
            }
            mUserTabClick = true;
          }

          if (mViewPager.getCurrentItem() != tab.getPosition()) {
            mViewPager.setCurrentItem(tab.getPosition(), true);
          }

          // During the call, we don't remember the tab position.
          if (!DialpadFragment.phoneIsInUse()) {
            // Remember this tab index. This function is also called, if the tab is set
            // automatically in which case the setter (setCurrentTab) has to set this to its old
            // value afterwards
            mLastManuallySelectedFragment = tab.getPosition();
          }
        }
コード例 #3
0
  /** Hides every tab and shows search UI for phone lookup. */
  private void enterSearchUi() {
    if (mSearchFragment == null) {
      // We add the search fragment dynamically in the first onLayoutChange() and
      // mSearchFragment is set sometime later when the fragment transaction is actually
      // executed, which means there's a window when users are able to hit the (physical)
      // search key but mSearchFragment is still null.
      // It's quite hard to handle this case right, so let's just ignore the search key
      // in this case.  Users can just hit it again and it will work this time.
      return;
    }
    if (mSearchView == null) {
      prepareSearchView();
    }

    final ActionBar actionBar = getActionBar();

    final Tab tab = actionBar.getSelectedTab();

    // User can search during the call, but we don't want to remember the status.
    if (tab != null && !DialpadFragment.phoneIsInUse()) {
      mLastManuallySelectedFragment = tab.getPosition();
    }

    mSearchView.setQuery(null, true);

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    sendFragmentVisibilityChange(mViewPager.getCurrentItem(), false);

    // Show the search fragment and hide everything else.
    mSearchFragment.setUserVisibleHint(true);
    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.show(mSearchFragment);
    transaction.commitAllowingStateLoss();
    mViewPager.setVisibility(View.GONE);

    // We need to call this and onActionViewCollapsed() manually, since we are using a custom
    // layout instead of asking the search menu item to take care of SearchView.
    mSearchView.onActionViewExpanded();
    mInSearchUi = true;
  }