List of usage examples for android.app ActionBar getTabCount
@Deprecated public abstract int getTabCount();
From source file:com.android.cts.uiautomator.Test4DetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { View rootView = inflater.inflate(R.layout.test4_detail_fragment, container, false); // Set up the action bar. final ActionBar actionBar = getActivity().getActionBar(); if (actionBar.getTabCount() > 0) { return rootView; }//ww w . j a v a 2 s .c o m actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity().getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) rootView.findViewById(R.id.test_4_detail_container); 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 listener for when this tab is // selected. actionBar .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } return rootView; }
From source file:org.dmfs.webcal.fragments.MyCalendarsFragment.java
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;/*from w ww .ja va2s . co m*/ 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:com.groksolutions.grok.mobile.HourDayWeekActivity.java
void restoreTabSelection() { AggregationType aggregation = HTMITApplication.getAggregation(); final ActionBar actionBar = getActionBar(); if (actionBar == null) { return;//ww w .j a v a2 s . co m } for (int i = 0; i < actionBar.getTabCount(); i++) { Tab tab = actionBar.getTabAt(i); if (aggregation.equals(tab.getTag())) { actionBar.selectTab(tab); break; } } }
From source file:com.YOMPsolutions.YOMP.mobile.HourDayWeekActivity.java
void restoreTabSelection() { AggregationType aggregation = YOMPApplication.getAggregation(); final ActionBar actionBar = getActionBar(); if (actionBar == null) { return;/*w ww . j a va 2s . c om*/ } for (int i = 0; i < actionBar.getTabCount(); i++) { Tab tab = actionBar.getTabAt(i); if (aggregation.equals(tab.getTag())) { actionBar.selectTab(tab); break; } } }
From source file:com.ape.filemanager.FileExplorerTabActivityOld.java
public void switchToPage(int whichTab) { ActionBar bar = getActionBar(); if (bar != null && whichTab < bar.getTabCount()) { bar.setSelectedNavigationItem(whichTab); }//from www .j a va2s. c om }
From source file:org.dmfs.webcal.fragments.PagerFragment.java
/** * Configures the tabs on the action bar. *///from w w w.j a va 2 s . co 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:com.github.wakhub.monodict.activity.FlashcardActivity.java
@UiThread void reloadTabs() { Map<Integer, Integer> countsForBoxes; try {//from w w w . java 2 s . co m countsForBoxes = databaseHelper.getCountsForBoxes(); } catch (SQLException e) { activityHelper.showError(e); return; } ActionBar actionBar = getActionBar(); for (int i = 0; i < Card.BOX_MAX; i++) { ActionBar.Tab tab; if (actionBar.getTabCount() > i) { tab = actionBar.getTabAt(i); } else { tab = actionBar.newTab().setTag(i).setTabListener(this); actionBar.addTab(tab); } int box = i + 1; String label = String.format("BOX%d", box); if (i == 0) { label = "INBOX"; } if (countsForBoxes.keySet().contains(box)) { label += String.format("(%d)", countsForBoxes.get(box)); } tab.setText(label); } if (!isTabInitialized || isReloadRequired) { isTabInitialized = true; isReloadRequired = false; // TODO: not working int index = state.getBox() - 1; if (index < 0 || actionBar.getTabCount() < index) { index = 0; } actionBar.getTabAt(index).select(); loadContents(); } }
From source file:com.groksolutions.grok.mobile.HourDayWeekActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getResourceView());/*from w w w .j a v a 2s.c om*/ // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayShowTitleEnabled(false); Locale l = Locale.getDefault(); // For each of the sections in the app, add a tab to the action bar. // Add the "Fragment" class to the tab's tag. The tab's "Fragment" will // be created using this class // Hour Page actionBar.addTab(actionBar.newTab().setText(getString(R.string.title_tab_hour).toUpperCase(l)) .setTabListener(this).setTag(AggregationType.Hour)); // Day Page actionBar.addTab(actionBar.newTab().setText(getString(R.string.title_tab_day).toUpperCase(l)) .setTabListener(this).setTag(AggregationType.Day)); // Week Page actionBar.addTab(actionBar.newTab().setText(getString(R.string.title_tab_week).toUpperCase(l)) .setTabListener(this).setTag(AggregationType.Week)); // Create the fragment adapter that will return a fragment based on the // Fragment class attached to the tab's tag object final FragmentPagerAdapter pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { final Fragment[] _fragments = new Fragment[3]; @Override public Fragment getItem(int position) { Tab tab = actionBar.getTabAt(position); if (tab != null) { if (_fragments[position] == null) { _fragments[position] = createTabFragment(tab); } } return _fragments[position]; } @Override public int getCount() { return actionBar.getTabCount(); } }; // Set up the ViewPager with the sections adapter. _viewPager = (ViewPager) findViewById(R.id.pager); _viewPager.setAdapter(pagerAdapter); // Keep all pages in memory _viewPager.setOffscreenPageLimit(2); // 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. _viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); }
From source file:com.native5.plugins.ActionBarPlugin.java
@Override public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException { if (!plugin_actions.contains(action)) { return false; }/*from w ww.ja va 2 s . co m*/ final Activity ctx = (Activity) cordova; if ("isAvailable".equals(action)) { JSONObject result = new JSONObject(); result.put("value", ctx.getWindow().hasFeature(Window.FEATURE_ACTION_BAR)); callbackContext.success(result); return true; } final ActionBar bar = ctx.getActionBar(); if (bar == null) { Window window = ctx.getWindow(); if (!window.hasFeature(Window.FEATURE_ACTION_BAR)) { callbackContext .error("ActionBar feature not available, Window.FEATURE_ACTION_BAR must be enabled!"); } else { callbackContext.error("Failed to get ActionBar"); } return true; } if (menu == null) { callbackContext.error("Options menu not initialised"); return true; } final StringBuffer error = new StringBuffer(); JSONObject result = new JSONObject(); if ("isShowing".equals(action)) { result.put("value", bar.isShowing()); } else if ("getHeight".equals(action)) { result.put("value", bar.getHeight()); } else if ("getDisplayOptions".equals(action)) { result.put("value", bar.getDisplayOptions()); } else if ("getNavigationMode".equals(action)) { result.put("value", bar.getNavigationMode()); } else if ("getSelectedNavigationItem".equals(action)) { result.put("value", bar.getSelectedNavigationIndex()); } else if ("getSubtitle".equals(action)) { result.put("value", bar.getSubtitle()); } else if ("getTitle".equals(action)) { result.put("value", bar.getTitle()); } else { try { JSONException exception = new Runnable() { public JSONException exception = null; public void run() { try { // This is a bit of a hack (should be specific to the request, not global) bases = new String[] { removeFilename(webView.getOriginalUrl()), removeFilename(webView.getUrl()) }; if ("show".equals(action)) { LOG.d("native5-action-bar", "Showing Action Bar"); bar.show(); } else if ("hide".equals(action)) { bar.hide(); } else if ("setMenu".equals(action)) { if (args.isNull(0)) { error.append("menu can not be null"); return; } menu_definition = args.getJSONArray(0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ctx.invalidateOptionsMenu(); } } else if ("setTabs".equals(action)) { if (args.isNull(0)) { error.append("menu can not be null"); return; } bar.removeAllTabs(); tab_callbacks.clear(); if (!buildTabs(bar, args.getJSONArray(0))) { error.append("Invalid tab bar definition"); } } else if ("setDisplayHomeAsUpEnabled".equals(action)) { if (args.isNull(0)) { error.append("showHomeAsUp can not be null"); return; } bar.setDisplayHomeAsUpEnabled(args.getBoolean(0)); } else if ("setDisplayOptions".equals(action)) { if (args.isNull(0)) { error.append("options can not be null"); return; } final int options = args.getInt(0); bar.setDisplayOptions(options); } else if ("setDisplayShowHomeEnabled".equals(action)) { if (args.isNull(0)) { error.append("showHome can not be null"); return; } bar.setDisplayShowHomeEnabled(args.getBoolean(0)); } else if ("setDisplayShowTitleEnabled".equals(action)) { if (args.isNull(0)) { error.append("showTitle can not be null"); return; } bar.setDisplayShowTitleEnabled(args.getBoolean(0)); } else if ("setDisplayUseLogoEnabled".equals(action)) { if (args.isNull(0)) { error.append("useLogo can not be null"); return; } bar.setDisplayUseLogoEnabled(args.getBoolean(0)); } else if ("setHomeButtonEnabled".equals(action)) { if (args.isNull(0)) { error.append("enabled can not be null"); return; } bar.setHomeButtonEnabled(args.getBoolean(0)); } else if ("setIcon".equals(action)) { if (args.isNull(0)) { error.append("icon can not be null"); return; } Drawable drawable = getDrawableForURI(args.getString(0)); bar.setIcon(drawable); } else if ("setListNavigation".equals(action)) { JSONArray items = null; if (args.isNull(0) == false) { items = args.getJSONArray(0); } navigation_adapter.setItems(items); bar.setListNavigationCallbacks(navigation_adapter, navigation_listener); } else if ("setLogo".equals(action)) { String uri = args.getString(0); if (args.isNull(0)) { error.append("logo can not be null"); return; } // try { // InputStream ims = ctx.getAssets().open(uri); Drawable drawable = getDrawableForURI(uri); // Drawable.createFromStream(ims, null); bar.setLogo(drawable); bar.setBackgroundDrawable(getDrawableForURI("images/logo-bg.png")); // } catch (IOException e) { // e.printStackTrace(); // } } else if ("setNavigationMode".equals(action)) { if (args.isNull(0)) { error.append("mode can not be null"); return; } final int mode = args.getInt(0); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } else if ("setSelectedNavigationItem".equals(action)) { if (args.isNull(0)) { error.append("position can not be null"); return; } bar.setSelectedNavigationItem(args.getInt(0)); } else if ("setSelectedTab".equals(action)) { if (args.isNull(0)) { error.append("position can not be null"); return; } LOG.d("setSelectedTab", bar.getTabCount() + ""); bar.selectTab(bar.getTabAt(args.getInt(0))); } else if ("setSubtitle".equals(action)) { if (args.isNull(0)) { error.append("subtitle can not be null"); return; } bar.setSubtitle(args.getString(0)); } else if ("setTitle".equals(action)) { if (args.isNull(0)) { error.append("title can not be null"); return; } bar.setTitle(args.getString(0)); } } catch (JSONException e) { exception = e; } finally { synchronized (this) { this.notify(); } } } // Run task synchronously { synchronized (this) { ctx.runOnUiThread(this); this.wait(); } } }.exception; if (exception != null) { throw exception; } } catch (InterruptedException e) { error.append("Function interrupted on UI thread"); } } if (error.length() == 0) { if (result.length() > 0) { callbackContext.success(result); } else { callbackContext.success(); } } else { callbackContext.error(error.toString()); } return true; }