Example usage for android.app ActionBar NAVIGATION_MODE_TABS

List of usage examples for android.app ActionBar NAVIGATION_MODE_TABS

Introduction

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

Prototype

int NAVIGATION_MODE_TABS

To view the source code for android.app ActionBar NAVIGATION_MODE_TABS.

Click Source Link

Document

Tab navigation mode.

Usage

From source file:com.core.vmfiveadnetwork.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.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager(), this);

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

    if (actionBar != null) {
        // Specify that the Home/Up button should not be enabled, since there is no hierarchical
        // parent.
        actionBar.setHomeButtonEnabled(false);

        // Specify that we will be displaying tabs in the action bar.
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    }//from   ww  w  .  ja v a2  s.  c om

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.

            if (actionBar != null)
                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++) {
        // 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
        // listener for when this tab is selected.

        if (actionBar != null)
            actionBar.addTab(
                    actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    // check permissions for M, if some permission denied, it would shut down activity
    checkRequiredPermissions();

    // need to enable app scan in backend, and prompt this dialog to notice user
    //ADN.showAppScanDialog(this, "???App?");
}

From source file:es.farfuteam.vncpp.controller.ActivityTabs.java

/**
 * @param savedInstanceState//from  w w w  . j ava2 s  .  c  o m
 * @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:edu.pdx.cecs.orcycle.TabsConfig.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {// w  ww.j  a  v  a 2s  .c  om
        myApp = MyApplication.getInstance();
        myApp.setRunning(true);
        myApp.clearReminderNotifications();

        setContentView(R.layout.tabs_config);

        Log.v(MODULE_TAG, "Cycle: TabsConfig onCreate");

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        // Toast.makeText(this, "Tab Created", Toast.LENGTH_LONG).show();

        fragment1 = new FragmentMainInput();
        fragment2 = new FragmentSavedTripsSection();
        fragment3 = new FragmentSavedNotesSection();
        //fragment4 = new FragmentUserInfo();
        fragment4 = new FragmentSettings();

        // Set up the action bar.
        final ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.psu_green));

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

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

        // 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.
        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            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 < mSectionsPagerAdapter.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(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
        }

        mViewPager.setOffscreenPageLimit(4);

        Intent intent;
        Bundle bundle;
        if (null != (intent = getIntent())) {
            if (null != (bundle = intent.getExtras())) {
                fragmentToShow = bundle.getInt(TabsConfig.EXTRA_SHOW_FRAGMENT, FRAG_INDEX_MAIN_INPUT);
            }
        }
    } catch (Exception ex) {
        Log.e(MODULE_TAG, ex.getMessage());
    }
}

From source file:com.kay.regg.deskclock.DeskClock.java

private void createTabs(int selectedIndex) {
    mActionBar = getActionBar();//from   ww  w .  j a  v a 2  s  .c o m

    mActionBar.setDisplayOptions(0);
    if (mActionBar != null) {
        mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        mTimerTab = mActionBar.newTab();
        mTimerTab.setIcon(R.drawable.timer_tab);
        mTimerTab.setContentDescription(R.string.menu_timer);
        mTabsAdapter.addTab(mTimerTab, TimerFragment.class, TIMER_TAB_INDEX);

        mClockTab = mActionBar.newTab();
        mClockTab.setIcon(R.drawable.clock_tab);
        mClockTab.setContentDescription(R.string.menu_clock);
        mTabsAdapter.addTab(mClockTab, ClockFragment.class, CLOCK_TAB_INDEX);
        mStopwatchTab = mActionBar.newTab();
        mStopwatchTab.setIcon(R.drawable.stopwatch_tab);
        mStopwatchTab.setContentDescription(R.string.menu_stopwatch);
        mTabsAdapter.addTab(mStopwatchTab, StopwatchFragment.class, STOPWATCH_TAB_INDEX);
        mActionBar.setSelectedNavigationItem(selectedIndex);
        mTabsAdapter.notifySelectedPage(selectedIndex);
    }
}

From source file:ch.ethz.twimight.activities.HomeScreenActivity.java

/**
 * Called when the activity is first created.
 *//*from w w w.  ja  v  a  2s .co m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
    setContentView(R.layout.main);

    // reduces overdraw of whole screen by 1
    getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.transparent));

    //      // statistics
    //      locDBHelper = new StatisticsDBHelper(getApplicationContext());
    //      locDBHelper.open();

    cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    timestamp = System.currentTimeMillis();

    //      locHelper = LocationHelper.getInstance(this);
    //      locHelper.registerLocationListener();
    //
    //      handler = new Handler();
    //      checkLocation = new CheckLocation();
    //      handler.postDelayed(checkLocation, 1 * 60 * 1000L);

    getActionBar().setSubtitle("@" + LoginActivity.getTwitterScreenname(this));
    mFragmentTitles = new String[] { getString(R.string.timeline), getString(R.string.favorites),
            getString(R.string.mentions) };

    mPagerAdapter = new FragmentListPagerAdapter(getFragmentManager());
    mPagerAdapter.addFragment(new TimelineFragment());
    mPagerAdapter.addFragment(new FavoritesFragment());
    mPagerAdapter.addFragment(new MentionsFragment());

    mViewPager = (ViewPager) findViewById(R.id.viewpager);

    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between pages, select the
            // corresponding tab.
            setFragment(position);
        }
    });

    // action bar
    actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    Tab timelineTab = actionBar.newTab().setIcon(R.drawable.ic_timeline)
            .setTabListener(new TabListener(mViewPager));
    actionBar.addTab(timelineTab);

    Tab favoritesTab = actionBar.newTab().setIcon(R.drawable.ic_favorites)
            .setTabListener(new TabListener(mViewPager));
    actionBar.addTab(favoritesTab);

    Tab mentionsTab = actionBar.newTab().setIcon(R.drawable.ic_mentions)
            .setTabListener(new TabListener(mViewPager));
    actionBar.addTab(mentionsTab);
    setSelectedTab(getIntent());

}

From source file:no.invisibleink.app.MainActivity.java

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

    /* -------------------------------- Init ---------------- */
    serverManager = new ServerManager();
    locationManager = new LocationManager(this);
    locationManager.onCreate();/*from   ww  w .j  a  v  a  2 s . c  o  m*/

    /* -------------------------------- Swipe view with taps ---------------- */
    fragmentManager = getSupportFragmentManager();

    listSectionFragment = new ListViewFragment();
    mapSectionFragment = new MapViewFragment();
    postSectionFragment = new PostViewFragment();

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(fragmentManager);

    // 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.
    actionBar.setHomeButtonEnabled(false);

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

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });
    /*
     * Set the number of pages that should be retained to either side of the
     * current page in the view hierarchy in an idle state. Pages beyond
     * this limit will be recreated from the adapter when needed.
     */
    mViewPager.setOffscreenPageLimit(3);

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.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
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    try {
        MapsInitializer.initialize(getApplicationContext());
    } catch (GooglePlayServicesNotAvailableException e) {
        Log.e(TAG, "Google play services is not available.");
    }
}

From source file:com.first3.viz.ui.ActivityDelegate.java

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

    Bundle b = getIntent().getExtras();/*  w  w w.  java2s . c  om*/
    if (b != null) {
        mIntentTab = b.getInt(BUNDLE_LOAD_TAB);
    }

    if (BuildConfig.DEBUG) {
        Log.d("Viz running in debug mode");
    }

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    setContentView(R.layout.main);
    Log.d();

    mActionBar = this.getActionBar();
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mActionBar.setDisplayShowTitleEnabled(true);
    mActionBar.setDisplayShowHomeEnabled(true);

    mBrowserTab = mActionBar.newTab().setIcon(R.drawable.ic_action_tab_browser);
    mDownloadsTab = mActionBar.newTab().setIcon(R.drawable.ic_action_tab_downloads);
    mFavoritesTab = mActionBar.newTab().setIcon(R.drawable.ic_action_tab_favorites);
    mFileManagerTab = mActionBar.newTab().setIcon(R.drawable.ic_action_tab_filemanager);
    mSettingsTab = mActionBar.newTab().setIcon(R.drawable.ic_action_tab_settings);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mTabsAdapter = new TabsAdapter(this, mActionBar, mViewPager);
    mTabsAdapter.addTab(mFileManagerTab, FileManager.class, null);
    mTabsAdapter.addTab(mFavoritesTab, Favorites.class, null);
    mTabsAdapter.addTab(mBrowserTab, Browser.class, null);
    mTabsAdapter.addTab(mDownloadsTab, Downloads.class, null);
    mTabsAdapter.addTab(mSettingsTab, Settings.class, null);

    getVideoPlayerFragment().addEventListener(new VideoPlayer.EventListener() {
        @Override
        public void onVideoCompleted() {
            switchToTabView();
        }

        @Override
        public void onVideoPaused() {
        }
    });

    updateUI();
    createDefaultDirectories();
    VersionChangeNotifier.getInstance().start(this);
}

From source file:com.fitme.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Init db scheme
    DbHelper dbh = new DbHelper(this);
    dbh.createDataBase();/*  ww  w . j  a v a  2  s . c om*/
    ActiveProgramDAO apd = new ActiveProgramDAO(this);
    activeProgram = apd.getActiveProgramName();
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(this);
    // Refresh trainings section data
    TrainingsSectionFragment tsf = (TrainingsSectionFragment) mAppSectionsPagerAdapter
            .getItem(AppSectionsPagerAdapter.SECTION_TRAININGS);
    tsf.onNewProgramSelected();

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

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            if (actionBar != null)
                actionBar.setSelectedNavigationItem(position);
        }
    });

    if (actionBar != null) {
        // Specify that the Home/Up button should not be enabled, since there is no hierarchical
        // parent.
        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.
        for (int i = 0; i < mAppSectionsPagerAdapter.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
            // listener for when this tab is selected.
            actionBar.addTab(
                    actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
        }

        actionBar.getTabAt(WorkoutsSectionFragment.WORKOUTS_SECTION_ID).setIcon(R.drawable.ic_section_workouts);
        actionBar.getTabAt(TrainingsSectionFragment.TRAININGS_SECTION_ID)
                .setIcon(R.drawable.ic_section_trainings);
        actionBar.getTabAt(DummySectionFragment.DUMMY_SECTION_ID).setIcon(R.drawable.ic_section_charts);
        // Additional fake tab for the future development
        actionBar.getTabAt(DummySectionFragment.DUMMY_SECTION_ID + 1).setIcon(R.drawable.ic_section_photo);
    }

}

From source file:it.durip_app.SensorPlot.java

/** Called when the activity is first created. */
@Override/* ww w .  java  2 s  . c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sensors);
    managerSensor = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
    textCharge = (TextView) findViewById(R.id.textvalueConsumption);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(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.
    actionBar.setHomeButtonEnabled(true);

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

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    managerSensor = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    List<Sensor> list = managerSensor.getSensorList(Sensor.TYPE_ALL);
    for (Sensor sensor : list) {
        System.out.println("NAME " + sensor.getName());
    }

    // For each of the sections in the app, add a tab to the action bar.
    for (int ii = 1; ii <= mAppSectionsPagerAdapter.getCount(); ii++) {
        // 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
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(ii)).setTabListener(this));

    }
    // Show the Up button in the action bar.        

    //        System.out.println("OnCreate \n");

}

From source file:org.imdea.panel.MainActivity.java

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

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override//from   w w w .j a  va 2 s  .  com
        public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
            Log.e("Alert", "UNCAUGHT EXCEPTION", paramThrowable);
            System.exit(1);
        }
    });
    Thread.setDefaultUncaughtExceptionHandler(onRuntimeError);

    /*
    ParseObject testObject = new ParseObject("TestObject");
    testObject.put("foo", "bar");
    testObject.saveInBackground();*/

    SP = PreferenceManager.getDefaultSharedPreferences(this);

    //Abrimos la base de datos 'DBUsuarios' en modo escritura
    DBHelper msg_database = new DBHelper(this, "messages.db", null, 1);
    Global.db = msg_database.getWritableDatabase();

    enableBt();

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    setContentView(R.layout.activity_main);

    // Initilization
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionbar = getActionBar();

    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }
    checkUsername();

    TabsPagerAdapter mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    fm = getSupportFragmentManager();

    viewPager.setAdapter(mAdapter);
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionbar.addTab(actionbar.newTab().setText("General").setTabListener(this));
    actionbar.addTab(actionbar.newTab().setText("Tags").setTabListener(this));

    /**
     * on swiping the viewpager make respective tab selected
     * */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            actionbar.setSelectedNavigationItem(position);
        }

        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        public void onPageScrollStateChanged(int arg0) {
        }
    });

    /* EXPERIMENTAL SERVICES */

    //this.startService(new Intent(this, WifiService.class));
    //this.startService(new Intent(this, BtWizService.class));
    //this.startService(new Intent(this, MeshService.class));
    this.startService(new Intent(this, commService.class));
    //if (Global.mqtt) this.startService(new Intent(this, mqttService.class));
    //else this.startService(new Intent(this, BtService.class));
    //this.startService(new Intent(this, smoothService.class));

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            handleSendText(intent); // Handle text being sent
        } else if (type.startsWith("image/")) {
            handleSendImage(intent); // Handle single image being sent
        }

    }

}