Example usage for android.app ActionBar newTab

List of usage examples for android.app ActionBar newTab

Introduction

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

Prototype

@Deprecated
public abstract Tab newTab();

Source Link

Document

Create and return a new Tab .

Usage

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

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set View//from w w w . java2  s. co  m
    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: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 w  ww .j  a v  a 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: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 w  w w .j  a v  a 2s .  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.ja  v  a  2  s  . c  om*/
    }

    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:es.farfuteam.vncpp.controller.ActivityTabs.java

/**
 * @param savedInstanceState/*from  w  ww . j av a 2 s .  c  om*/
 * @brief This is the onCreate method
 * @details The onCreate method adds an actionBar to the activity with two tabs (recent and favorites).
 * It also load the preferences file into the prefs attribute and sets the rememeberExit attribute.
 */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_host);

    final ActionBar actionBar = getActionBar();

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);

    final String recents = getString(R.string.recents);
    final String favorites = getString(R.string.favoritesTab);

    // add tabs
    Tab tab1 = actionBar.newTab().setText(recents)
            .setTabListener(new TabListener<ListFragmentTab>(this, "tab1", ListFragmentTab.class));
    actionBar.addTab(tab1);

    Tab tab2 = actionBar.newTab().setText(favorites)
            .setTabListener(new TabListener<ListFragmentTabFav>(this, "tab2", ListFragmentTabFav.class));

    actionBar.addTab(tab2);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    //accedemos a fichero preferencias
    (Configuration.getInstance()).setPrefs(getSharedPreferences("PreferencesFile", Context.MODE_PRIVATE));

    (Configuration.getInstance()).readPrefs();

    // Orientation Change Occurred
    if (savedInstanceState != null) {
        int currentTabIndex = savedInstanceState.getInt("tab_index");
        actionBar.setSelectedNavigationItem(currentTabIndex);
    }

    //nombre en la activity bar
    final String title = getString(R.string.connections);
    setTitle(title);

}

From source file:com.indragie.cmput301as1.ExpenseClaimListActivity.java

/**
 * Set up fragments to display expense claim data.
 */// w  w w .j  a v  a  2  s . c  o  m
private void setupFragments() {
    User user = userManager.getActiveUser();
    Session session = new Session(this, user);
    Session.setSharedSession(session);

    pagerAdapter = new ExpenseClaimPagerAdapter(this, getSupportFragmentManager(), user);
    pager.setAdapter(pagerAdapter);

    // From http://developer.android.com/training/implementing-navigation/lateral.html
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

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

        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
        }

        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
        }
    };

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

    Tab ownedTab = actionBar.newTab().setText(R.string.tab_owned).setTabListener(tabListener);
    Tab reviewalTab = actionBar.newTab().setText(R.string.tab_reviewal).setTabListener(tabListener);

    actionBar.addTab(ownedTab);
    actionBar.addTab(reviewalTab);
}

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 w w.  j a va  2 s .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.ibm.msg.android.ConnectionDetails.java

/**
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 *//*from  ww  w.  j  ava 2s.  co m*/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    clientHandle = getIntent().getStringExtra("handle");

    setContentView(R.layout.activity_connection_details);
    // Create the adapter that will return a fragment for each of the pages
    sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

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

    // add the sectionsPagerAdapter
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(sectionsPagerAdapter);

    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // select the tab that represents the current page
            actionBar.setSelectedNavigationItem(position);

        }
    });

    // Create the tabs for the screen
    for (int i = 0; i < sectionsPagerAdapter.getCount(); i++) {
        ActionBar.Tab tab = actionBar.newTab();
        tab.setText(sectionsPagerAdapter.getPageTitle(i));
        tab.setTabListener(this);
        actionBar.addTab(tab);
    }

    connection = Connections.getInstance(this).getConnection(clientHandle);
    changeListener = new ChangeListener();
    connection.registerChangeListener(changeListener);
}

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/*from w w  w  .  j  a  v  a 2  s. co  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:com.example.office.ui.Office365DemoActivity.java

/**
 * Initializes activity UI elements.//ww w . j  a  va 2  s .c  o m
 */
private void initUi() {
    if (!mIsInitialized) {
        setContentView(R.layout.main_activity);

        mTitle = mDrawerTitle = getTitle();

        // Setting up Action Bar and Tabs.
        ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setLogo(R.drawable.ic_action_mail);

        Tab tab = actionBar.newTab().setText(UI.Screen.CONTACTS.getName(this))
                .setTag(UI.Screen.CONTACTS.getName(this)).setTabListener(new TabListener<ContactsFragment>(this,
                        UI.Screen.CONTACTS.getName(this), ContactsFragment.class));
        actionBar.addTab(tab);

        tab = actionBar.newTab().setText(UI.Screen.MAILBOX.getName(this))
                .setTag(UI.Screen.MAILBOX.getName(this)).setTabListener(new TabListener<DraftsFragment>(this,
                        UI.Screen.MAILBOX.getName(this), DraftsFragment.class));
        actionBar.addTab(tab, true);

        tab = actionBar.newTab().setText(UI.Screen.CALENDAR.getName(this))
                .setTag(UI.Screen.CALENDAR.getName(this)).setTabListener(new TabListener<CalendarFragment>(this,
                        UI.Screen.CALENDAR.getName(this), CalendarFragment.class));
        actionBar.addTab(tab);

        // Setting up sliding drawer.
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);

        SlidingDrawerAdapter drawerAdapter = new SlidingDrawerAdapter(OfficeApplication.getContext(),
                R.layout.drawer_list_item, R.layout.drawer_delimiter);
        mDrawerList.setAdapter(drawerAdapter);

        mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                try {
                    Screen[] drawerScreens = ScreenGroup.DRAWER.getMembers().toArray(new Screen[0]);
                    Screen currentScreen = DEFAULT_SCREEN;

                    // use id instead of position here because some positions used by delimiters, id contains real index of clicked item
                    if (drawerScreens != null && drawerScreens.length - 1 >= id) {
                        currentScreen = drawerScreens[(int) id];
                    }
                    switchScreen(currentScreen);
                } catch (Exception e) {
                    Logger.logApplicationException(e, getClass().getSimpleName() + "onItemClick(): Error.");
                }
            }
        });

        actionBar.setHomeButtonEnabled(true);

        // ActionBarDrawerToggle ties together the the proper interactions
        // between the sliding drawer and the action bar app icon
        mDrawerToggle = new ActionBarDrawerToggle(this,
                /* host Activity */mDrawerLayout, /* DrawerLayout object */
                R.drawable.ic_drawer, /* drawer navigation image replacing '<' */
                R.string.drawer_open, R.string.drawer_close) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mIsInitialized = true;
    }

    if (mSavedFragmentTag == null) {
        switchScreen(DEFAULT_SCREEN);
    } else {
        // This is not used mostly as we're going back to this activity when it
        // is at the top of the back stack. So (as it does have 'singleTop' in parameters) it is
        // simply restored and onNewIntent() is called instead of onCreate().
        // So savedInstanceState will usually be null. This is added to anticipate other future use cases.
        switchScreen(Screen.getByTag(mSavedFragmentTag, this));
    }
}