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.example.office.ui.Office365DemoActivity.java
/** * Initializes activity UI elements.//w w w. j a v a2s. co 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)); } }
From source file:systems.orca.mobile.openweather.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TabAdapter = new TabPagerAdapter(getSupportFragmentManager()); Tab = (ViewPager) findViewById(R.id.pager); Tab.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override//w ww . j a v a 2s .c om public void onPageSelected(int position) { actionBar = getActionBar(); actionBar.setSelectedNavigationItem(position); } }); Tab.setAdapter(TabAdapter); actionBar = getActionBar(); //Enable Tabs on Action Bar actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabReselected(android.app.ActionBar.Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { Tab.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(android.app.ActionBar.Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } }; //Add New Tab actionBar.addTab(actionBar.newTab().setText("Android").setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("iOS").setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("Windows").setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("Position").setTabListener(tabListener)); //test GEO OpenWeatherGeo gps = new OpenWeatherGeo(this); if (gps.canGetLocation()) { double latitude = gps.getLatitude(); double longitude = gps.getLongitude(); // \n is for new line Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show(); } else { // can't get location // GPS or Network is not enabled // Ask user to enable GPS/network in settings gps.showSettingsAlert(); } (new OpenWeatherNotification(001, "Open Weather Notification", "Hello World", R.drawable.ic_launcher, this)) .start(); }
From source file:com.dsdar.thosearoundme.TeamViewActivity.java
/** * Method to initialize the components used in team activity *//*from w w w. ja va2 s . co m*/ @SuppressLint("NewApi") private void initializeComponents() { itsActionBar = getActionBar(); itsActionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); // itsActionBar.setDisplayShowTitleEnabled(false); itsActionBar.setDisplayShowTitleEnabled(true); itsActionBar.setTitle("Those Around Me"); // itsActionBar.setCustomView(R.layout.invitation_count); // itsInvitationcount = (TextView) findViewById(R.id.text2); itsActionBar.setDisplayShowCustomEnabled(true); itsActionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor(ACTION_BAR_COLOR))); // LayoutInflater inflator = (LayoutInflater) this // .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // // View v = inflator.inflate(R.layout.invitation_count, null); itsActionBar.setCustomView(R.layout.invitation_count); itsInvitationcount = (TextView) findViewById(R.id.text2); itsActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); startRefreshTimer(); // if (invite_count != null || invite_count != "") { // itsInvitationcount.setText(invite_count); // } else { // itsInvitationcount.setText(""); // } itsNormalMapView = (TextView) findViewById(R.id.tvMainPageMapMap); itsSatelliteMapView = (TextView) findViewById(R.id.tvMainPageMapSatellite); itsHybridMapView = (TextView) findViewById(R.id.tvMainPageMapHybrid); itsTeamView = (TextView) findViewById(R.id.tvTeamActTeam); itsTeamView.setText("Team"); itsHomeView = (TextView) findViewById(R.id.tvTeamActHome); itsFollowersView = (TextView) findViewById(R.id.tvTeamActFollowers); itsHomeImgBlack = getResources().getDrawable(R.drawable.home_icon_black); itsHomeImgBlack.setBounds(0, 0, imgBounds, imgBounds); itsHomeImgGreen = getResources().getDrawable(R.drawable.home_icon_green); itsHomeImgGreen.setBounds(0, 0, imgBounds, imgBounds); itsTeamImgGreen = getResources().getDrawable(R.drawable.team_icon_green); itsTeamImgGreen.setBounds(0, 0, imgBounds, imgBounds); itsTeamImgBlack = getResources().getDrawable(R.drawable.team_icon_black); itsTeamImgBlack.setBounds(0, 0, imgBounds, imgBounds); itsFollowerImgGreen = getResources().getDrawable(R.drawable.followers_icon_green); itsFollowerImgGreen.setBounds(0, 0, imgBounds, imgBounds); itsFollowerImgBlack = getResources().getDrawable(R.drawable.followers_icon_black); itsFollowerImgBlack.setBounds(0, 0, imgBounds, imgBounds); itsShowAllButton = (Button) findViewById(R.id.tvMainPageShowAllMembers); itsAddTeam = (Button) findViewById(R.id.tvAddTeam); itsAddTeamMember = (Button) findViewById(R.id.tvAddMember); itsTvMan = (Button) findViewById(R.id.tvMan); itsMyLoc = (Button) findViewById(R.id.btnMyLoc); itsStickyMarker = (Button) findViewById(R.id.btnStickyMarker); itsTvMan.setBackgroundResource(R.drawable.map_follow_me_no); itsGPSAlert = (TextView) findViewById(R.id.tvGpsAlert); SupportMapFragment aSupportMapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.TeamViewMap); itsGoogleMap = aSupportMapFragment.getMap(); enableMapsPreference(); // itsGoogleMap.setMyLocationEnabled(true); itsGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); itsGoogleMap.setOnMarkerClickListener(this); itsGoogleMap.setOnMarkerDragListener(this); // itsGoogleMap.setOnMapClickListener(this); itsGoogleMap.setOnMapLongClickListener(this); itsGoogleMap.clear(); }
From source file:app.sunstreak.yourpisd.MainActivity.java
private void setUpTabs() { final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.main_section_0_title)) .setTabListener(this)); actionBar.addTab(//from w ww . j a va 2 s. co m actionBar.newTab().setText(TermFinder.Term.values()[CURRENT_TERM_INDEX].name).setTabListener(this)); actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.main_section_2_title)) .setTabListener(this)); // actionBar.addTab(actionBar.newTab().setText(getResources().getString(R.string.main_section_3_title)) // .setTabListener(this)); // mViewPager // .setOnPageChangeListener(new ViewPager.OnPageChangeListener() { // @Override // public void onPageSelected(int position) { // // on changing the page // // make respected tab selected // actionBar.setSelectedNavigationItem(position); // } // // @Override // public void onPageScrolled(int arg0, float arg1, int arg2) { // } // // @Override // public void onPageScrollStateChanged(int arg0) { // } // }); }
From source file:com.nks.nksmod.otaupdater.OTAUpdaterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = getApplicationContext(); cfg = Config.getInstance(context);//from ww w . j ava 2 s.c o m final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 0; if (ContextCompat.checkSelfPermission(OTAUpdaterActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(OTAUpdaterActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_permission_storage); builder.setMessage(R.string.alert_permission_storage_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setNeutralButton(R.string.enable_permission, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); ActivityCompat.requestPermissions(OTAUpdaterActivity.this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } else { ActivityCompat.requestPermissions(OTAUpdaterActivity.this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); if (ActivityCompat.shouldShowRequestPermissionRationale(OTAUpdaterActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_permission_storage); builder.setMessage(R.string.alert_permission_storage_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } } } boolean data = Utils.dataAvailable(this); boolean wifi = Utils.wifiConnected(this); if (!data || !wifi) { final boolean nodata = !data && !wifi; if ((nodata && !cfg.getIgnoredDataWarn()) || (!nodata && !cfg.getIgnoredWifiWarn())) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(nodata ? R.string.alert_nodata_title : R.string.alert_nowifi_title); builder.setMessage(nodata ? R.string.alert_nodata_message : R.string.alert_nowifi_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setNeutralButton(R.string.alert_wifi_settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS); startActivity(i); } }); builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (nodata) { cfg.setIgnoredDataWarn(true); } else { cfg.setIgnoredWifiWarn(true); } dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } } Utils.updateDeviceRegistration(this); CheckinReceiver.setDailyAlarm(this); setContentView(R.layout.main); ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); bar = getActionBar(); assert bar != null; bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); bar.setTitle(R.string.app_name); TabsAdapter mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class); ActionBar.Tab romTab = bar.newTab().setText(R.string.main_rom); if (cfg.hasStoredRomUpdate()) romTab.setIcon(R.drawable.ic_action_warning); romTabIdx = mTabsAdapter.addTab(romTab, ROMTab.class); /* ActionBar.Tab kernelTab = bar.newTab().setText(R.string.main_kernel); if (cfg.hasStoredKernelUpdate()) kernelTab.setIcon(R.drawable.ic_action_warning); kernelTabIdx = mTabsAdapter.addTab(kernelTab, KernelTab.class); */ if (!handleNotifAction(getIntent())) { if (cfg.hasStoredRomUpdate() && !cfg.isDownloadingRom()) { cfg.getStoredRomUpdate().showUpdateNotif(this); } /* if (cfg.hasStoredKernelUpdate() && !cfg.isDownloadingKernel()) { cfg.getStoredKernelUpdate().showUpdateNotif(this); } */ if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt(KEY_TAB, 0)); } } }
From source file:com.example.android.lightcontrol.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getApplicationContext();/* w w w . ja va 2 s .c om*/ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } if (mBluetoothAdapter.isEnabled()) { mChatService = new BluetoothChatService(this, mHandler); } mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); final ActionBar actionBar = getActionBar(); assert actionBar != null; 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) { if (B) { B = false; Toast.makeText(MainActivity.this, "Round theme cancelled", Toast.LENGTH_SHORT).show(); } if (position == 0) { } if (position == 1) { updatespinner(); setupChat(); } if (position == 2) { } if (position == 3) { setupGroupMode(); } actionBar.setSelectedNavigationItem(position); } }); /*for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { actionBar.addTab(actionBar.newTab() .setText(mAppSectionsPagerAdapter.getPageTitle(i)) .setTabListener(this)); }*/ actionBar.addTab(actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(0)).setTabListener(this) .setIcon(R.drawable.btn_group_control_icon)); actionBar.addTab(actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(1)).setTabListener(this) .setIcon(R.drawable.btn_light_control_icon)); actionBar.addTab(actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(2)).setTabListener(this) .setIcon(R.drawable.btn_group_configure_icon)); actionBar.addTab(actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(3)).setTabListener(this) .setIcon(R.drawable.btn_sceario_control_icon)); }
From source file:com.otaupdater.OTAUpdaterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = getApplicationContext(); cfg = Config.getInstance(context);//from w ww . j a v a 2 s.c om if (!cfg.hasProKey()) { bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), billingSrvConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { billingSrvConn = null; } @Override public void onServiceConnected(ComponentName name, IBinder binder) { IInAppBillingService service = IInAppBillingService.Stub.asInterface(binder); try { Bundle owned = service.getPurchases(3, getPackageName(), "inapp", null); ArrayList<String> ownedItems = owned.getStringArrayList("INAPP_PURCHASE_ITEM_LIST"); ArrayList<String> ownedItemData = owned .getStringArrayList("INAPP_PURCHASE_DATA_LIST"); if (ownedItems != null && ownedItemData != null) { for (int q = 0; q < ownedItems.size(); q++) { if (ownedItems.get(q).equals(Config.PROKEY_SKU)) { JSONObject itemData = new JSONObject(ownedItemData.get(q)); cfg.setKeyPurchaseToken(itemData.getString("purchaseToken")); break; } } } } catch (RemoteException ignored) { } catch (JSONException e) { e.printStackTrace(); } unbindService(this); billingSrvConn = null; } }, Context.BIND_AUTO_CREATE); } boolean data = Utils.dataAvailable(this); boolean wifi = Utils.wifiConnected(this); if (!data || !wifi) { final boolean nodata = !data && !wifi; if ((nodata && !cfg.getIgnoredDataWarn()) || (!nodata && !cfg.getIgnoredWifiWarn())) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(nodata ? R.string.alert_nodata_title : R.string.alert_nowifi_title); builder.setMessage(nodata ? R.string.alert_nodata_message : R.string.alert_nowifi_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setNeutralButton(R.string.alert_wifi_settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS); startActivity(i); } }); builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (nodata) { cfg.setIgnoredDataWarn(true); } else { cfg.setIgnoredWifiWarn(true); } dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } } Utils.updateDeviceRegistration(this); CheckinReceiver.setDailyAlarm(this); if (!PropUtils.isRomOtaEnabled() && !PropUtils.isKernelOtaEnabled() && !cfg.getIgnoredUnsupportedWarn()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_unsupported_title); builder.setMessage(R.string.alert_unsupported_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cfg.setIgnoredUnsupportedWarn(true); dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); } setContentView(R.layout.main); Fragment adFragment = getFragmentManager().findFragmentById(R.id.ads); if (adFragment != null) getFragmentManager().beginTransaction().hide(adFragment).commit(); ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); bar = getActionBar(); assert bar != null; bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE); bar.setTitle(R.string.app_name); TabsAdapter mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class); ActionBar.Tab romTab = bar.newTab().setText(R.string.main_rom); if (cfg.hasStoredRomUpdate()) romTab.setIcon(R.drawable.ic_action_warning); romTabIdx = mTabsAdapter.addTab(romTab, ROMTab.class); ActionBar.Tab kernelTab = bar.newTab().setText(R.string.main_kernel); if (cfg.hasStoredKernelUpdate()) kernelTab.setIcon(R.drawable.ic_action_warning); kernelTabIdx = mTabsAdapter.addTab(kernelTab, KernelTab.class); if (!handleNotifAction(getIntent())) { if (cfg.hasStoredRomUpdate() && !cfg.isDownloadingRom()) { cfg.getStoredRomUpdate().showUpdateNotif(this); } if (cfg.hasStoredKernelUpdate() && !cfg.isDownloadingKernel()) { cfg.getStoredKernelUpdate().showUpdateNotif(this); } if (savedInstanceState != null) { bar.setSelectedNavigationItem(savedInstanceState.getInt(KEY_TAB, 0)); } } }
From source file:org.dmfs.webcal.fragments.PagerFragment.java
/** * Configures the tabs on the action bar. *//*from ww w . j av a 2 s . c om*/ 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:uk.bowdlerize.MainActivity.java
private void configureTabs() { // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); // 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/*from w w w . ja va 2s . co m*/ 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)); } }
From source file:org.apache.cordova.plugins.Actionable.java
private void updateTabs(final JSONArray tabs) { for (int i = 0; i < tabs.length(); i++) { try {// www . ja va 2 s .c o m JSONObject mi = tabs.getJSONObject(i); final Actionable action = Actionable.fromJSON(mi); final TabListener self = this; mDroidGap.runOnUiThread(new Runnable() { @Override public void run() { Tab t = mBar.newTab(); t.setText(action.getTitle()); t.setTabListener(self); t.setTag(action.getCallbackId()); if (action.getIcon() != null) { t.setIcon(action.getIcon()); } mBar.addTab(t); if (action.isSelected()) { mBar.selectTab(t); } } }); } catch (Exception e) { Log.v("Cambie", Log.getStackTraceString(e)); } } if (tabs.length() > 0) { mDroidGap.runOnUiThread(new Runnable() { @Override public void run() { mBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } }); } }