Example usage for android.app ActionBar setSelectedNavigationItem

List of usage examples for android.app ActionBar setSelectedNavigationItem

Introduction

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

Prototype

@Deprecated
public abstract void setSelectedNavigationItem(int position);

Source Link

Document

Set the selected navigation item in list or tabbed navigation modes.

Usage

From source file:com.yohpapa.overlaymusicplayer.activity.MainActivity.java

private void setupViewPager() {
    ViewPager pager = (ViewPager) findViewById(R.id.fragment_pager);
    pager.setAdapter(new TabPagerAdapter(getFragmentManager()));
    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override//from   w  ww.  ja v  a2 s.c  o m
        public void onPageSelected(int position) {
            ActionBar bar = getActionBar();
            bar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            Log.d(TAG, String.format("onPageScrolled(%d, %f, %d)", position, positionOffset,
                    positionOffsetPixels));
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            Log.d(TAG, String.format("onPageScrollStateChanged(%d)", state));
        }
    });
}

From source file:com.digi.android.sample.xbeemanager.XBeeTabsActivity.java

/**
 * Configures the view pager that will be used to display the different
 * activity fragments./*w w  w. jav a  2  s.  c  o m*/
 */
private void setupViewPager() {
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        /*
         * (non-Javadoc)
         * @see android.support.v4.view.ViewPager.SimpleOnPageChangeListener#onPageSelected(int)
         */
        public void onPageSelected(int position) {
            // When swiping between pages, select the corresponding tab.
            ActionBar actionBar = getActionBar();
            if (actionBar != null)
                actionBar.setSelectedNavigationItem(position);
        }
    });
    viewPager.setOffscreenPageLimit(2);
    XBeeDevicePagerAdapter xbeePagerAdapter = new XBeeDevicePagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(xbeePagerAdapter);
}

From source file:org.dmfs.webcal.fragments.MyCalendarsFragment.java

@Override
public void onPageSelected(int position) {
    ActionBar actionBar = getActivity().getActionBar();
    if (position != actionBar.getSelectedNavigationIndex()) {
        mSelectedTab = position;/* w w w.j  a  va2s .c om*/
        actionBar.setSelectedNavigationItem(position);
    }
}

From source file:com.ape.filemanager.FileExplorerTabActivityOld.java

private void setDefaultTabView() {
    if (mIsFromSearch && mSearchPath != null) {
        ActionBar bar = getActionBar();

        bar.setSelectedNavigationItem(Util.SDCARD_TAB_INDEX);

        Log.i(TAG, "setDefaultTabIndex, fromSearch:" + mIsFromSearch + ", path: " + mSearchPath);
        FileViewActivity fileView = (FileViewActivity) getFragment(Util.SDCARD_TAB_INDEX);
        if (fileView.getContext() != null) {
            fileView.setPath(mSearchPath);
        }//from   w  w w .ja  v  a2s .c o  m
        mIsFromSearch = false;
        mSearchPath = null;
    }
}

From source file:com.ape.filemanager.FileExplorerTabActivityOld.java

public void switchToPage(int whichTab) {
    ActionBar bar = getActionBar();
    if (bar != null && whichTab < bar.getTabCount()) {
        bar.setSelectedNavigationItem(whichTab);
    }/* www . ja v a 2  s. c  o m*/
}

From source file:org.dmfs.webcal.fragments.PagerFragment.java

@Override
public void onPageSelected(int position) {
    Activity activity = getActivity();/*from   w w  w .  j a  v a 2 s  .  c o m*/
    if (activity == null) {
        // nothing to do
        return;
    }

    ActionBar actionBar = activity.getActionBar();

    if (actionBar != null && position != actionBar.getSelectedNavigationIndex()) {
        mSelectedTab = position;
        actionBar.setSelectedNavigationItem(position);
    }
}

From source file:co.edu.uniajc.vtf.content.SwipeContentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_swipe_content);

    //get the pager
    this.coAppSectionsPagerAdapter = new AppSectionsPagerAdapter(this.getSupportFragmentManager(), this);
    this.coViewPager = (ViewPager) findViewById(R.id.pagPagerContainer);
    this.coViewPager.setAdapter(coAppSectionsPagerAdapter);

    //get the action bar
    final ActionBar actionBar = this.getActionBar();
    coViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from ww  w . ja va  2s.c  o m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.list48));
    actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.map48));
    actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.ra48));
    actionBar.addTab(actionBar.newTab().setTabListener(this).setIcon(R.drawable.options48));

    //get the google api client 
    this.coApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_PROFILE).build();
}

From source file:com.cyanogenmod.settings.device.DisplaySettings.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.viewPager);/*w ww  .jav a  2 s .c  o  m*/
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setTitle(R.string.app_name);
    bar.setDisplayHomeAsUpEnabled(true);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.category_screen_title), ScreenFragmentActivity.class,
            null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}

From source file:com.klowerbase.test.ViewpagerAnimationActivity.java

@SuppressWarnings("deprecation")
@Override/*  www.  j av  a 2s. c o  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int selectedPage = 0;
    if (savedInstanceState != null) {
        mSelectedItem = savedInstanceState.getInt(KEY_SELECTED_CLASS);
        selectedPage = savedInstanceState.getInt(KEY_SELECTED_PAGE);
    }

    final ArrayAdapter<TransformerItem> actionBarAdapter = new ArrayAdapter<TransformerItem>(
            getApplicationContext(), android.R.layout.simple_expandable_list_item_1, android.R.id.text1,
            TRANSFORM_CLASSES);

    setContentView(R.layout.viewpageranimation);

    mAdapter = new PageAdapter(getSupportFragmentManager());

    mPager = (ViewPager) findViewById(R.id.container);
    mPager.setAdapter(mAdapter);
    mPager.setCurrentItem(selectedPage);

    final ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setListNavigationCallbacks(actionBarAdapter, this);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        //noinspection ResourceType
        actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);

        actionBar.setSelectedNavigationItem(mSelectedItem);
    }

}

From source file:com.ToxicBakery.viewpager.transforms.example.MainActivity.java

@SuppressWarnings("deprecation")
@Override/* ww w.j  ava  2  s .  co  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int selectedPage = 0;
    if (savedInstanceState != null) {
        mSelectedItem = savedInstanceState.getInt(KEY_SELECTED_CLASS);
        selectedPage = savedInstanceState.getInt(KEY_SELECTED_PAGE);
    }

    final ArrayAdapter<TransformerItem> actionBarAdapter = new ArrayAdapter<TransformerItem>(
            getApplicationContext(), android.R.layout.simple_list_item_1, android.R.id.text1,
            TRANSFORM_CLASSES);

    setContentView(R.layout.activity_main);

    mAdapter = new PageAdapter(getFragmentManager());

    mPager = (ViewPager) findViewById(R.id.container);
    mPager.setAdapter(mAdapter);
    mPager.setCurrentItem(selectedPage);

    final ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setListNavigationCallbacks(actionBarAdapter, this);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        //noinspection ResourceType
        actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);

        actionBar.setSelectedNavigationItem(mSelectedItem);
    }

}