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.Duo.music.player.PlaylistEditorActivity.PlaylistEditorActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

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

    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        setTheme(R.style.AppTheme);/* w w w. ja  va2  s .c  o  m*/
    } 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);

}

From source file:com.schedule.ScheduleActivity.java

/**
 * Sets up Action Bar (if present)./*from  w  w w.  ja v a  2 s . com*/
 * 
 * @param showTabs
 *            whether to show tabs (if false, will show list).
 * @param selTab
 *            the selected tab or list item.
 */
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 < MENUS.length; i++) {
            actionBar.addTab(actionBar.newTab().setText(MENUS[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, MENUS);
        actionBar.setListNavigationCallbacks(adap, handler);
    }

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

From source file:ca.cmput301f13t03.adventure_datetime.view.BrowseView.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewpager);/*from   w  w  w  .  j a  va 2 s .  co m*/

    /* Set up View Pager */
    _adapter = new ViewPagerAdapter(getSupportFragmentManager());
    _viewPager = (ViewPager) findViewById(R.id.pager);
    _viewPager.setAdapter(_adapter);

    /* Set up Tabs */
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            _viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        }
    };

    actionBar.addTab(actionBar.newTab().setText("Saved").setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText("My Stories").setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText("Online").setTabListener(tabListener));

    /* Change tabs when View Pager swiped */
    _viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

}

From source file:com.bionx.res.about.InformationCenter.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.information_center);

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());
    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*ww  w . j  a  v a 2 s .c o  m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.example.ll.llsdktest.MainActivity.java

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

    //configuring SDK
    Setting.configureLimelightSettings("https://staging-api.lvp.llnw.net/rest",
            "https://staging-wlp.lvp.llnw.net/license", "limelight");
    LoggerUtil.setLogLevelByString("Debug", this);
    Setting.SetAnalyticsEndPoint(//  www  .j  a  v  a2 s. co  m
            "https://staging-mcs.lvp.llnw.net/r/MetricsCollectionService/recordMetricsEvent");

    setContentView(R.layout.activity_main);

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

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(0)).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(1)).setTabListener(this));
}

From source file:com.prolificcoder.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//  ww  w . j  a v  a 2s . c  om
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}

From source file:com.example.llsdktest2.MainActivity.java

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

    //configuring SDK
    Setting.configureLimelightSettings("https://staging-api.lvp.llnw.net/rest",
            "https://staging-wlp.lvp.llnw.net/license", "limelight");
    LoggerUtil.setLogLevelByString("Debug", this);
    Setting.SetAnalyticsEndPoint(//w  w w.  j a  v  a 2  s. c  o  m
            "https://staging-mcs.lvp.llnw.net/r/MetricsCollectionService/recordMetricsEvent");

    setContentView(R.layout.activity_main);

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

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);

    actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(0)).setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(1)).setTabListener(this));

}

From source file:com.matze5800.paupdater.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set View/*ww  w .j ava 2s . c  om*/
    setContentView(R.layout.activity_main);
    context = this;
    // Get SharedPreferences
    prefs = PreferenceManager.getDefaultSharedPreferences(context);

    // ActionBar / PagerAdapter
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getFragmentManager());

    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    // Finishes Activity if device is not supported
    device = Functions.detectDevice(context);
    if (device.equals("unsupported")) {
        finish();
    }
}

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

/**
 * Configures the tabs on the action bar.
 *///from   w w  w  . j  a v a 2s  . c o m
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;
    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:ca.cmput301f13t03.adventure_datetime.view.AuthorEdit.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewpager);/*from   w  w w .j av a2s  . co m*/

    /* Set up View Pager */
    _adapter = new ViewPagerAdapter(getSupportFragmentManager());
    _viewPager = (ViewPager) findViewById(R.id.pager);
    _viewPager.setAdapter(_adapter);

    /* Set up Tabs */
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            _viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        }
    };

    actionBar.addTab(actionBar.newTab().setText("Edit").setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText("Overview").setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText("Preview").setTabListener(tabListener));

    /* Change tabs when View Pager swiped */
    _viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    // Select 'Overview' at start
    getActionBar().setSelectedNavigationItem(1);

}