Example usage for android.app ActionBar getSelectedTab

List of usage examples for android.app ActionBar getSelectedTab

Introduction

In this page you can find the example usage for android.app ActionBar getSelectedTab.

Prototype

@Deprecated
public abstract Tab getSelectedTab();

Source Link

Document

Returns the currently selected tab if in tabbed navigation mode and there is at least one tab present.

Usage

From source file:com.android.contacts.activities.DialtactsActivity.java

/**
 * Hides every tab and shows search UI for phone lookup.
 *///from  w ww .ja v  a  2  s  . com
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);

    updateFakeMenuButtonsVisibility(false);

    for (int i = 0; i < TAB_INDEX_COUNT; i++) {
        sendFragmentVisibilityChange(i, false /* not visible */ );
    }

    // 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;
}