List of usage examples for android.app ActionBar NAVIGATION_MODE_TABS
int NAVIGATION_MODE_TABS
To view the source code for android.app ActionBar NAVIGATION_MODE_TABS.
Click Source Link
From source file:com.wbrenna.gtfsoffline.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set up the action bar. final ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); }//from ww w .java 2s. c om mProgress = (ProgressBar) findViewById(R.id.progress); //read in the preferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Set<String> emptyString = new HashSet<String>(); emptyString.clear(); Set<String> initial_preferences = mPrefs.getStringSet(getString(R.string.pref_dbs), emptyString); mDBListPrefsOld = initial_preferences; //this is the list of currently checked databases String[] tmpDBActive = initial_preferences.toArray(new String[initial_preferences.size()]); //we have to be careful to exclude databases that aren't in our directory dbHelper = new DatabaseHelper(this); dbHelper.gatherFiles(); mDBList = dbHelper.GetListofDB(); List<String> workingDBList = new ArrayList<String>(); for (int i = 0; i < tmpDBActive.length; i++) { if (mDBList.contains(tmpDBActive[i])) { workingDBList.add(tmpDBActive[i]); } else { initial_preferences.remove(tmpDBActive[i]); } } if (workingDBList.size() == 0) { mDBActive = null; } else { mDBActive = workingDBList.toArray(new String[workingDBList.size()]); } Editor prefsDBEditor = mPrefs.edit(); prefsDBEditor.putStringSet(getString(R.string.pref_dbs), initial_preferences); prefsDBEditor.commit(); //Set up the location management mLocationHelper = new LocationHelper(this); mLocation = mLocationHelper.startLocationManager(); // Define a listener that responds to location updates locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { if (mLocationHelper.isBetterLocation(location, mLocation)) { mLocation = location; if (mLocation != null) { //new ProcessBusStops().execute(); mSectionsPagerAdapter.notifyDataSetChanged(); } else { Toast.makeText(getBaseContext(), R.string.last_location_fix, Toast.LENGTH_LONG).show(); //Log.e(TAG, "No more location fixes "); } } } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; //TODO: eventually add automated downloading of databases... // Create the adapter that will return a fragment for each of the // 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); 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++) { actionBar .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:com.witmob.nocollapsetabs.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()); // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent./*from ww w .jav a 2 s . co m*/ actionBar.setHomeButtonEnabled(false); // Specify that we will be displaying tabs in the action bar. // 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); } }); // 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.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); }
From source file:app.screen.MyActivity.java
/** * For more info on using view pager and tabs and action bar, <a href="http://goo.gl/7CsM9">checkout this article</a> * in the Android developer site's "Training" section. * <p/>// ww w .ja v a 2 s .c o m * For more info on ViewPager, <a href="http://goo.gl/NgCUO">read this article</a>. */ private void _setupFragments() { // set up the action bar final ActionBar actionBar = getActionBar(); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // create the FragmentPagerAdapter FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { try { return Fragments.values()[position].aClass.getConstructor(MyActivity.class) .newInstance(MyActivity.this); } catch (Exception e) { AndroidUtils.logErr(IconPaths.MyApp, "MyActivity - problem creating fragments", e); // something has gone wrong - this shouldn't happen return new Fragment() { /** make a fragment to house {@link R.layout#error_fragment} */ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return super.onCreateView(inflater, container, savedInstanceState); } }; } } @Override public int getCount() { return Fragments.values().length; } public CharSequence getPageTitle(int position) { try { return Fragments.values()[position].title; } catch (Exception e) { return "N/A"; } } }; // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setOffscreenPageLimit(Fragments.values().length); // keep all the pages in memory viewPager.setAdapter(fragmentPagerAdapter); viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { /** * 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. */ @Override public void onPageSelected(int position) { super.onPageSelected(position); actionBar.setSelectedNavigationItem(position); } }); // create TabListener ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction transaction) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction transaction) { } @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction transaction) { } }; // setup tabs for (int i = 0; i < fragmentPagerAdapter.getCount(); i++) { actionBar.addTab( actionBar.newTab().setText(fragmentPagerAdapter.getPageTitle(i)).setTabListener(tabListener)); } }
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 w w. j a va 2 s . 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: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 ww w .jav a 2s . c om*/ 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); } }
From source file:com.shinobicontrols.transitions.StoryDetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_story_detail); if (savedInstanceState == null) { // Load the data from the intent on first pass Intent intent = getIntent();//from w w w .j av a2 s.c om String story_id = intent.getStringExtra(ARG_STORY_ID); mItem = StoryContent.STORY_MAP.get(story_id); } // Get hold of some relevant content final ViewGroup container = (ViewGroup) findViewById(R.id.container); // What are the layouts we should be able to transition between List<Integer> sceneLayouts = Arrays.asList(R.layout.content_scene_00, R.layout.content_scene_01, R.layout.content_scene_02); // Create the scenes sceneList = new ArrayList<Scene>(); for (int layout : sceneLayouts) { // Create the scene Scene scene = Scene.getSceneForLayout(container, layout, this); // Just before the transition starts, ensure that the content has been loaded scene.setEnterAction(new Runnable() { @Override public void run() { addContentToViewGroup(container); } }); // Save the scene into sceneList.add(scene); } // Build the transition manager TransitionInflater transitionInflater = TransitionInflater.from(this); mTransitionManager = transitionInflater.inflateTransitionManager(R.transition.story_transition_manager, container); // Show the Up button in the action bar. final ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); // Specify we want some tabs actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create a listener to cope with tab changes ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { // If there's a scene for this tab index, then transition to it if (tab.getPosition() <= sceneList.size()) { performTransitionToScene(sceneList.get(tab.getPosition())); } } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { // Can ignore this event } @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { // Can ignore this event } private void performTransitionToScene(Scene scene) { mTransitionManager.transitionTo(scene); } }; // Add some tabs for (int i = 0; i < sceneList.size(); i++) { actionBar.addTab(actionBar.newTab().setText("Scene " + i).setTabListener(tabListener)); } } // Load the first scene sceneList.get(0).enter(); }
From source file:com.example.android.tabbedroombookingtimetabledisplay.MainFragmentActivity.java
public void tabSettings(ActionBar actionBar) { try {//from w w w.java2 s . c om actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); final Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class); setHasEmbeddedTabsMethod.setAccessible(true); setHasEmbeddedTabsMethod.invoke(actionBar, false); } catch (final Exception e) { // Handle issues as needed: log, warn user, fallback etc // This error is safe to ignore, standard tabs will appear. } }
From source file:edu.tcfsh.arrivinglaterecordapp.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); getBundle();//from www . j a v a 2 s.co m arrivingLateRecordFragment = new ArrivingLateRecordFragment(dayOfMonth, month, year); // Create the adapter that will return a fragment for each of the three // primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); leavingActivityDialog = new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT); leavingActivityDialog.setTitle("??"); leavingActivityDialog.setMessage("?"); leavingActivityDialog.setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { savingFileAlertDialog.show(); } }); leavingActivityDialog.setNegativeButton("?", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { } }); savingFileAlertDialog = new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT); savingFileAlertDialog.setTitle("??"); savingFileAlertDialog.setMessage("?????"); savingFileAlertDialog.setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { arrivingLateRecordFragment.saveArrivingLateRecordFile(); finish(); } }); savingFileAlertDialog.setNegativeButton("?", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { finish(); } }); // 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); } }); // 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)); } }
From source file:com.indragie.cmput301as1.ExpenseClaimListActivity.java
/** * Set up fragments to display expense claim data. *//*from w ww . j av a2 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:lth.pontus.getResults.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = getApplicationContext();//from ww w . java2 s . co m // 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(); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayUseLogoEnabled(false); // 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); exercisel = new ExerciseProvider(); DateHelper = new DateProvider(); openDB(); // 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); } }); // 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. Tab a = actionBar.newTab().setIcon(mAppSectionsPagerAdapter.getPageICon(i)); a.setTabListener(this); actionBar.addTab(a); } }