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.blueoxfords.peacecorpstinder.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    activity = this;

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(this, getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);

    final ActionBar actionBar = getActionBar();

    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(false);
        actionBar.setTitle(getString(R.string.app_name));
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override/*from   ww w  . j ava  2s  .c o m*/
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });
        for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
            actionBar.addTab(
                    actionBar.newTab().setIcon(mAppSectionsPagerAdapter.getPageIcon(i)).setTabListener(this));
        }
    }
}

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

@SuppressWarnings("unchecked")
@Override/*from w ww .  jav a2 s.  c om*/
public void onCreate(Bundle savedInstanceState) {

    //Initialize Context and SharedPreferences.
    mContext = this;
    mApp = (Common) mContext.getApplicationContext();

    //Retrieve the name/icon of the library from the arguments.
    libraryName = getIntent().getExtras().getString("LIBRARY_NAME");
    libraryIconName = getIntent().getExtras().getString("LIBRARY_ICON");

    if (getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET") != null) {
        songDBIdsList = (HashSet<String>) getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET");
    }

    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        setTheme(R.style.AppTheme);
    } else {
        setTheme(R.style.AppThemeLight);
    }
    super.onCreate(savedInstanceState);

    //Initialize the database helper.
    dbHelper = new DBAccessHelper(mContext.getApplicationContext());

    //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.
    int defaultArt = UIElementsHelper.getIcon(mContext, "default_album_art_padded");
    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);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
        int topPadding = Common.getStatusBarHeight(mContext);
        View activityView = (View) findViewById(android.R.id.content);

        //Calculate ActionBar height
        TypedValue tv = new TypedValue();
        int actionBarHeight = 0;
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                    getResources().getDisplayMetrics());
        }

        if (activityView != null) {
            activityView.setPadding(0, topPadding + actionBarHeight, 0, 0);
        }

    }

}

From source file:org.ado.minesync.gui.MineSyncMainActivity.java

/**
 * Called when the activity is first created.
 *
 * @param savedInstanceState If the activity is being re-initialized after
 *                           previously being shut down then this Bundle contains the data it most
 *                           recently supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b>
 *///from  ww  w. j  a v a2  s  . c  o  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ALog.d(TAG, "onCreate. savedInstanceState [" + savedInstanceState + "].");
    setContentView(R.layout.activity_main);

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getApplicationContext(),
            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
        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));
    }

    accountManager = getDropboxAccountManager(getApplicationContext());
    activityTracker = new ActivityTracker(getApplicationContext());
    minecraftDropboxStatus = new MinecraftDropboxStatus(this);
    upgradeManager = new UpgradeManager(getApplicationContext());

    upgradeManager.upgradeIfNeeded();
    startServicesIfNeeded();

    ALog.d(TAG, "var configProcessActive [" + configProcessActive + "]");
}

From source file:com.villetainio.travelcardreminder.activities.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    nfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (nfcAdapter == null) {
        Toast.makeText(this, R.string.error_message_no_nfc_on_device, Toast.LENGTH_LONG).show();
        finish();//from  ww  w.j a va 2 s .  c  o m
    }

    pagerAdapter = new TravelCardPagerAdapter(getSupportFragmentManager());
    pager = (VerticalViewPager) findViewById(R.id.pager);
    pager.setAdapter(pagerAdapter);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        ActionBar.TabListener tabListener = new ActionBar.TabListener() {
            @Override
            public void onTabSelected(ActionBar.Tab tab, android.app.FragmentTransaction ft) {
                pager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(ActionBar.Tab tab, android.app.FragmentTransaction ft) {
                // Unselect
            }

            @Override
            public void onTabReselected(ActionBar.Tab tab, android.app.FragmentTransaction ft) {
                // Reselect
            }
        };

        actionBar.addTab(actionBar.newTab().setText("Status").setTabListener(tabListener));

        actionBar.addTab(actionBar.newTab().setText("Settings").setTabListener(tabListener));
    }
}

From source file:org.tunesremote.LibraryBrowseActivity.java

@SuppressLint("NewApi")
@Override// w  ww.  j a  v  a 2s .  c  om
public void onCreate(Bundle saved) {
    super.onCreate(saved);
    this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (this.prefs.getBoolean(this.getString(R.string.pref_fullscreen), true)
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    setContentView(R.layout.act_browse_library);

    artists = new ArtistsListFragment();
    albums = new AllAlbumsListFragment();
    playlists = new PlaylistsFragment();

    isTablet = findViewById(R.id.frame_artists) != null;

    if (!isTablet) {

        (pager = (ViewPager) findViewById(R.id.view_pager))
                .setAdapter(new LibraryPagerAdapter(getSupportFragmentManager()));
        pager.setOnPageChangeListener(this);
        pager.setOffscreenPageLimit(2);
        findViewById(R.id.tab_artists).setSelected(true);

    } else {

        getSupportFragmentManager().beginTransaction().add(R.id.frame_artists, artists)
                .add(R.id.frame_albums, albums).add(R.id.frame_playlists, playlists).commit();
        registerListener(artists, albums, playlists);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        handler = new TabHandler();
        ActionBar ab = getActionBar();
        ab.setTitle(R.string.control_menu_library);

        if (!isTablet) {
            findViewById(R.id.legacy_tabs).setVisibility(View.GONE);
            ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            Tab artTab = ab.newTab().setText(R.string.control_menu_artists).setTabListener(handler);
            Tab albTab = ab.newTab().setText(R.string.control_menu_albums).setTabListener(handler);
            Tab plyTab = ab.newTab().setText(R.string.control_menu_playlists).setTabListener(handler);
            ab.addTab(artTab);
            ab.addTab(albTab);
            ab.addTab(plyTab);
        }

    }

}

From source file:semanticweb.hws14.movapp.activities.Criteria.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_criteria);
    that = this;/*from  w  ww. j a  v a 2s.  co  m*/
    initCriteriaView();

    //Get the Tabpager
    criteriaPagerAdapter = new CriteriaPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(criteriaPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create a tab listener that is called when the user changes tabs.
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            mViewPager.setCurrentItem(tab.getPosition());
            tabPosition = tab.getPosition();
        }

        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // hide the given tab
        }

        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // probably ignore this event
        }
    };
    //add the two tabs
    actionBar.addTab(actionBar.newTab().setText("Movies").setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText("Actors").setTabListener(tabListener));
}

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

/**
 * Configures the activity tabs of the action bar.
 *//*w  w  w  .j a v a2s.co  m*/
private void configureTabs() {
    ActionBar actionBar = getActionBar();
    if (actionBar == null)
        return;

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    XBeeDeviceTabListener xbeeDeviceTabListener = new XBeeDeviceTabListener();

    Tab infoTab = actionBar.newTab();
    infoTab.setText(getResources().getString(R.string.device_info_fragment_title));
    infoTab.setTabListener(xbeeDeviceTabListener);

    Tab discoverTab;
    discoverTab = actionBar.newTab();
    discoverTab.setText(getResources().getString(R.string.device_discovery_fragment_title));
    discoverTab.setTabListener(xbeeDeviceTabListener);

    Tab framesTab = actionBar.newTab();
    framesTab.setText(getResources().getString(R.string.frames_fragment_title));
    framesTab.setTabListener(xbeeDeviceTabListener);

    actionBar.addTab(infoTab);
    actionBar.addTab(discoverTab);
    actionBar.addTab(framesTab);
}

From source file:eu.chainfire.geolog.ui.MainActivity.java

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

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

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//  w w  w .  j av  a 2s  . c o  m
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
            invalidateOptionsMenu();
        }
    });
    mViewPager.setOffscreenPageLimit(3);

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

    int play = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (play == ConnectionResult.SUCCESS) {
        // Force database creation
        Database.Helper helper = Database.Helper.getInstance(this);
        helper.getReadableDatabase();

        // Force Off profile as default
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        long id = prefs.getLong(SettingsFragment.PREF_CURRENT_PROFILE, 0);
        Database.Profile profile = Database.Profile.getById(helper, id, null);
        if (profile == null)
            id = 0;
        if (id == 0) {
            profile = Database.Profile.getOffProfile(helper);
            id = profile.getId();
            prefs.edit().putLong(SettingsFragment.PREF_CURRENT_PROFILE, id).commit();
        }

        // Start background service
        if (profile.getType() != Database.Profile.Type.OFF)
            BackgroundService.startService(this);
    } else {
        GooglePlayServicesUtil.getErrorDialog(play, this, 0).show();
        finish();
    }
}

From source file:de.ncoder.sensorsystem.android.app.MainActivity.java

private void onCreateTabs() {
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    if (actionBar == null) {
        return;// w  w w.  j  ava2 s .c o m
    }
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return tab fragments
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

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

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

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

From source file:com.piusvelte.cloudset.android.CloudSetMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
    setContentView(R.layout.activity_main);
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(sectionsPagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from w  w w .jav  a  2s. com
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

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

    SharedPreferences sp = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
    account = sp.getString(PREFERENCE_ACCOUNT_NAME, null);
    deviceId = sp.getLong(PREFERENCE_DEVICE_ID, INVALID_DEVICE_ID);
    setCurrentTab();

    // create the loader for registration, deregistration, and loading
    // devices
    LoaderManager loaderManager = getSupportLoaderManager();
    loaderManager.initLoader(0, null, this);

    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_LOADER_IDS)) {
        loaderIds = savedInstanceState.getIntegerArrayList(EXTRA_LOADER_IDS);
    } else {
        loaderIds = new ArrayList<Integer>();
    }

    for (int i = 0, s = loaderIds.size(); i < s; i++) {
        // reconnect to additional loaders for deregistering additional
        // devices
        loaderManager.initLoader(loaderIds.get(i), null, this);
    }
}