Example usage for android.app ActionBar addTab

List of usage examples for android.app ActionBar addTab

Introduction

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

Prototype

@Deprecated
public abstract void addTab(Tab tab);

Source Link

Document

Add a tab for use in tabbed navigation mode.

Usage

From source file:com.groksolutions.grok.mobile.HourDayWeekActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getResourceView());/* www  . j a v  a2  s.c om*/

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);

    Locale l = Locale.getDefault();

    // For each of the sections in the app, add a tab to the action bar.
    // Add the "Fragment" class to the tab's tag. The tab's "Fragment" will
    // be created using this class

    // Hour Page
    actionBar.addTab(actionBar.newTab().setText(getString(R.string.title_tab_hour).toUpperCase(l))
            .setTabListener(this).setTag(AggregationType.Hour));

    // Day Page
    actionBar.addTab(actionBar.newTab().setText(getString(R.string.title_tab_day).toUpperCase(l))
            .setTabListener(this).setTag(AggregationType.Day));

    // Week Page
    actionBar.addTab(actionBar.newTab().setText(getString(R.string.title_tab_week).toUpperCase(l))
            .setTabListener(this).setTag(AggregationType.Week));

    // Create the fragment adapter that will return a fragment based on the
    // Fragment class attached to the tab's tag object
    final FragmentPagerAdapter pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        final Fragment[] _fragments = new Fragment[3];

        @Override
        public Fragment getItem(int position) {
            Tab tab = actionBar.getTabAt(position);
            if (tab != null) {
                if (_fragments[position] == null) {
                    _fragments[position] = createTabFragment(tab);
                }
            }
            return _fragments[position];
        }

        @Override
        public int getCount() {
            return actionBar.getTabCount();
        }
    };

    // Set up the ViewPager with the sections adapter.
    _viewPager = (ViewPager) findViewById(R.id.pager);
    _viewPager.setAdapter(pagerAdapter);

    // Keep all pages in memory
    _viewPager.setOffscreenPageLimit(2);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    _viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });
}

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

private void setupActionBarTabs() {
    ActionBar actionBar = getActivity().getActionBar();

    int tabCount = actionBar.getTabCount();
    int pageCount = mAdapter.getCount();

    // replace titles and listeners of existing tabs
    int i = 0;//from  w w w.ja  v  a 2 s.  c  om
    for (; i < tabCount && i < pageCount; ++i) {
        final Tab tab = actionBar.getTabAt(i);
        tab.setText(mAdapter.getPageTitle(i));
        tab.setTabListener(this);
    }

    // add missing tabs
    for (; i < pageCount; ++i) {
        actionBar.addTab(actionBar.newTab().setText(mAdapter.getPageTitle(i)).setTabListener(this));
    }

    // remove remaining tabs
    for (; i < tabCount; --tabCount) {
        actionBar.removeTabAt(i);
    }
    if (pageCount > 1) {
        int selection = mSelectedTab;
        // changing the navigation mode might trigger a call to onTabSelected, overriding mSelectedTab with a wrong value, so save it
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        mSelectedTab = selection;
        if (selection < pageCount) {
            mViewPager.setCurrentItem(selection, false);
        }

    } else {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    }
}

From source file:org.kanbansalad.scanner.client.android.ScanActivity.java

private void addTabsTo(final ActionBar actionBar) {
    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < tabPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(tabPagerAdapter.getPageTitle(i)).setTabListener(this));
    }//w ww .ja va2  s .c  o m
}

From source file:com.android.dialer.calllog.CallLogActivity.java

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

    setContentView(R.layout.call_log_activity);

    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);

    final Tab allTab = actionBar.newTab();
    final String allTitle = getString(R.string.call_log_all_title);
    allTab.setContentDescription(allTitle);
    allTab.setText(allTitle);//from w  ww.j av  a2s  .co m
    allTab.setTabListener(mTabListener);
    actionBar.addTab(allTab);

    final Tab missedTab = actionBar.newTab();
    final String missedTitle = getString(R.string.call_log_missed_title);
    missedTab.setContentDescription(missedTitle);
    missedTab.setText(missedTitle);
    missedTab.setTabListener(mTabListener);
    actionBar.addTab(missedTab);

    mViewPager = (ViewPager) findViewById(R.id.call_log_pager);
    mViewPagerAdapter = new ViewPagerAdapter(getFragmentManager());
    mViewPager.setAdapter(mViewPagerAdapter);
    mViewPager.setOnPageChangeListener(mOnPageChangeListener);
    mViewPager.setOffscreenPageLimit(1);
}

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/*  w w  w.  j  ava 2 s.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.bignerdranch.android.fragmentbasics.NewsReaderActivity.java

/** Sets up Action Bar (if present).
 *
 * @param showTabs whether to show tabs (if false, will show list).
 * @param selTab the selected tab or list item.
 *//*w w  w.  ja  v a2s. co  m*/
public void setUpActionBar(boolean showTabs, int selTab) {
    if (Build.VERSION.SDK_INT < 11) {
        // No action bar for you!
        // But do not despair. In this case the layout includes a bar across the
        // top that looks and feels like an action bar, but is made up of regular views.
        return;
    }

    android.app.ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);

    // Set up a CompatActionBarNavHandler to deliver us the Action Bar nagivation events
    CompatActionBarNavHandler handler = new CompatActionBarNavHandler(this);
    if (showTabs) {
        actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS);
        int i;
        for (i = 0; i < CATEGORIES.length; i++) {
            actionBar.addTab(actionBar.newTab().setText(CATEGORIES[i]).setTabListener(handler));
        }
        actionBar.setSelectedNavigationItem(selTab);
    } else {
        actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_LIST);
        SpinnerAdapter adap = new ArrayAdapter<String>(this, R.layout.actionbar_list_item, CATEGORIES);
        actionBar.setListNavigationCallbacks(adap, handler);
    }

    // Show logo instead of icon+title.
    actionBar.setDisplayUseLogoEnabled(true);
}

From source file:org.monospace.smsfilter.MainActivity.java

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

    mTabs = new TabSet(NUM_TABS);
    mTabs.add(TAB_SMS, R.string.tab_sms_list, SMSListFragment.class);
    mTabs.add(TAB_FILTER, R.string.tab_filter_list, FilterListFragment.class);

    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);

    ViewPager pager = new ViewPager(this);
    pager.setId(R.id.main_pager);// w  w  w. j a va 2s.  c o  m

    TabHelper helper = new TabHelper(this, pager);
    pager.setAdapter(helper);
    pager.setOnPageChangeListener(helper);

    for (TabSet.Tab t : mTabs) {
        Tab tab = actionBar.newTab().setText(t.textId).setTabListener(helper);
        actionBar.addTab(tab);
    }

    setContentView(pager);

    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            SMSListFragment fragment = (SMSListFragment) mTabs.getItem(TAB_SMS);
            fragment.refresh();
        }
    };

    registerReceiver(mReceiver, new IntentFilter("org.monospace.smsfilter.NEW_BLOCKED_SMS"));
}

From source file:com.project.binbinfu.the_city.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.

    //mHotPagerAdapter = new HotPagerAdapter(getSupportFragmentManager());
    fragmentmanager = getSupportFragmentManager();
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.//from   w w w.  ja  va  2s.  com
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // For each of the sections in the app, add a tab to the action bar.

    actionBar.addTab(actionBar.newTab().setText(R.string.title_section1).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(R.string.title_section2).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(R.string.title_section3).setTabListener(this));
}

From source file:fm.krui.kruifm.DJInfoActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dj_info_container_layout);
    showLoadingScreen(true);/*from  www  . ja  va 2  s.  c  o  m*/

    // Allow custom home button actions
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);

    /* For each component, create a tab for navigation */
    // Stream
    ActionBar.Tab bioTab = actionBar.newTab().setText(getResources().getString(R.string.dj_bio_tab))
            .setTabListener(this);
    // Extended Playlist
    ActionBar.Tab twitterTab = actionBar.newTab().setText(getResources().getString(R.string.dj_twitter_tab))
            .setTabListener(this);

    // Then apply the tabs to the ActionBar.
    actionBar.addTab(bioTab);
    actionBar.addTab(twitterTab);

    // Download DJ object attached to the last played song to display information.
    Log.v(TAG, "Grabbing DJ information...");
    DJInfoFetcher fetcher = new DJInfoFetcher(this, this);
    fetcher.execute();
}

From source file:com.aniruddhc.acemusic.player.PlaylistEditorActivity.PlaylistEditorActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    //Initialize Context and SharedPreferences.
    mContext = this;
    mApp = (Common) this.getApplicationContext();
    sharedPreferences = mContext.getSharedPreferences("com.aniruddhc.acemusic.player", Context.MODE_PRIVATE);

    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        setTheme(R.style.AppTheme);/*from   ww  w .  ja  v a  2s  .com*/
    } else {
        setTheme(R.style.AppThemeLight);
    }
    super.onCreate(savedInstanceState);

    //Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;

    //Display Image Options.
    displayImageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.default_album_art)
            .showImageOnFail(R.drawable.default_album_art).showStubImage(R.drawable.transparent_drawable)
            .cacheInMemory(false).cacheOnDisc(true).decodingOptions(options)
            .imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(400)).delayBeforeLoading(100).build();

    //Attach tabs to the ActionBar.
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    //Add the artists tab.
    String artistsLabel = getResources().getString(R.string.artists);
    Tab tab = actionBar.newTab();
    tab.setText(artistsLabel);
    TabListener<ArtistsPickerFragment> artistsTabListener = new TabListener<ArtistsPickerFragment>(this,
            artistsLabel, ArtistsPickerFragment.class);

    tab.setTabListener(artistsTabListener);
    actionBar.addTab(tab);

    //Add the albums tab.
    String albumsLabel = getResources().getString(R.string.albums);
    tab = actionBar.newTab();
    tab.setText(albumsLabel);
    TabListener<AlbumsPickerFragment> albumsTabListener = new TabListener<AlbumsPickerFragment>(this,
            albumsLabel, AlbumsPickerFragment.class);

    tab.setTabListener(albumsTabListener);
    actionBar.addTab(tab);

    //Add the songs tab.
    String songsLabel = getResources().getString(R.string.songs);
    tab = actionBar.newTab();
    tab.setText(songsLabel);
    TabListener<SongsPickerFragment> songsTabListener = new TabListener<SongsPickerFragment>(this, songsLabel,
            SongsPickerFragment.class);

    tab.setTabListener(songsTabListener);
    actionBar.addTab(tab);

}