List of usage examples for android.app ActionBar addTab
@Deprecated public abstract void addTab(Tab tab);
From source file:com.inc.playground.playground.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); globalVariables = ((GlobalVariables) getApplication()); // Set up the action bar. final ActionBar actionBar = getActionBar(); setPlayGroundActionBar();/*from w w w . ja v a2s .c o m*/ //set actionBar color actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor))); actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor))); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent. //actionBar.setHomeButtonEnabled(false); actionBar.setDisplayShowHomeEnabled(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().setTabListener(this)); } actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view); actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view); actionBar.getTabAt(2).setIcon(R.drawable.pg_calendar_view); //NavigationDrawer handling (e.g the list from leftside): mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); getActionBar().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getActionBar().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.closeDrawers(); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // all linear layout from slider menu /*Home button */ LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home); ll_Home.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); /*Login button */ LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login); ll_Login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes LinearLayout ll_Login = (LinearLayout) v; TextView loginTxt = (TextView) findViewById(R.id.login_txt); if (loginTxt.getText().equals("Login")) { Intent iv = new Intent(MainActivity.this, Login.class); startActivity(iv); finish(); } else if (loginTxt.getText().equals("Logout")) { final Dialog alertDialog = new Dialog(MainActivity.this); alertDialog.setContentView(R.layout.logout_dilaog); alertDialog.setTitle("Logout"); alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.clear(); editor.commit(); ImageView loginImg = (ImageView) findViewById(R.id.login_img); TextView loginTxt = (TextView) findViewById(R.id.login_txt); loginTxt.setText("Login"); loginImg.setImageResource(R.drawable.pg_action_lock_open); globalVariables = ((GlobalVariables) getApplication()); globalVariables.SetCurrentUser(null); globalVariables.SetUserPictureBitMap(null); globalVariables.SetUsersList(null); globalVariables.SetUsersImagesMap(null); Util.clearCookies(getApplicationContext()); Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.show(); //<-- See This! } } }); /*Setting button*/ LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings); ll_Setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, com.inc.playground.playground.upLeft3StripesButton.SettingsActivity.class); startActivity(iv); finish(); } }); /*My profile button*/ LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile); ll_my_profile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // new changes globalVariables = ((GlobalVariables) getApplication()); User currentUser = globalVariables.GetCurrentUser(); if (currentUser == null) { Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show(); } else { Intent iv = new Intent(MainActivity.this, com.inc.playground.playground.upLeft3StripesButton.MyProfile.class); //for my profile iv.putExtra("name", currentUser.getName()); iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents()); //pass events iv.putExtra("events", currentUser.getEvents()); iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval()); iv.putExtra("events_decline", currentUser.getEvents_decline()); iv.putExtra("photoUrl", currentUser.getPhotoUrl()); startActivity(iv); // } } }); LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about); ll_aboutUs.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, AboutUs.class); startActivity(iv); finish(); } }); }
From source file:com.codingrhemes.steamsalesmobile.GameSaleActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gamesaleactivity); // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); if (savedInstanceState == null) { // Setting up bundle to keep values Bundle mostPopGames = new Bundle(); mostPopGames.putBoolean("isMostPopular", true); dailyDealFragment = new DealOfTheDayFragment(); gamesFragment = new GamesFragment(); mostPopularFragment = new MostPopularGamesFragment(); // set them to the fragment mostPopularFragment.setArguments(mostPopGames); }//from w ww .j a v a2 s. co m // Create the adapter that will return a fragment for each of the three // 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)); } }
From source file:com.lambdal.railgun.PInfo.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the activity PInfo.activity = this; int packageCount = PInfo.getPackages().size(); // Hide the status bar. Window w = getWindow();//from w w w.j a va 2s . c o m w.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); w.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); setContentView(R.layout.activity_main); // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.hide(); // getActionBar().setBackgroundDrawable(new // ColorDrawable(Color.argb(128, 0, 0, 0))); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mSectionsPagerAdapter.pageCount = packageCount; // 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); } }); mViewPager.setOnClickListener(new ViewPager.OnClickListener() { @Override public void onClick(View view) { // When swiping between pages, select the // corresponding tab. int currentAppIndex = DummySectionFragment.currentAppIndex; ArrayList<PInfo> appList = PInfo.getInstalledApps(false); PInfo app = appList.get(currentSelectedTabIndex.intValue()); // Open the app: Intent launchIntent = getPackageManager().getLaunchIntentForPackage(app.pname); try { startActivity(launchIntent); } catch (Exception e) { Log.v("We ran into an exception when launching intent: " + app.pname, e.toString()); } Log.v("We have a tap event which happened at index: ", app.toString() + " " + currentSelectedTabIndex.toString()); } }); for (int i = 0; i < PInfo.getPackages().size(); i++) { actionBar .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } }
From source file:co.nerdart.ourss.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); setContentView(activity_main);// ww w . ja v a2s. c om // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Hack to always show the tabs under the actionbar try { Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class); setHasEmbeddedTabsMethod.setAccessible(true); setHasEmbeddedTabsMethod.invoke(actionBar, false); } catch (Exception ignored) { } // Create the adapter that will return a fragment for each of the three // primary sections of the app. /* * The {@link android.support.v4.view.PagerAdapter} that will provide fragments for each of the sections. We use a {@link * android.support.v4.app.FragmentPagerAdapter} derivative, which will keep every loaded fragment in memory. If this becomes too memory * intensive, it may be best to switch to a {@link android.support.v4.app.FragmentStatePagerAdapter}. */ SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(id.pager); mViewPager.setAdapter(sectionsPagerAdapter); // 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); invalidateOptionsMenu(); // Do not do it into onTabSelected()! } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < sectionsPagerAdapter.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(sectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } if (PrefUtils.getBoolean(PrefUtils.REFRESH_ENABLED, true)) { // starts the service independent to this activity startService(new Intent(this, RefreshService.class)); } else { stopService(new Intent(this, RefreshService.class)); } if (PrefUtils.getBoolean(PrefUtils.REFRESH_ON_OPEN_ENABLED, false)) { if (!FetcherService.isRefreshingFeeds) { startService(new Intent(MainActivity.this, FetcherService.class) .setAction(Constants.ACTION_REFRESH_FEEDS)); } } getSupportLoaderManager().initLoader(loaderId, null, this); }
From source file:lth.pontus.getResults.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = getApplicationContext();/*from w ww .jav a 2s . 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); } }
From source file:org.catnut.ui.PluginsActivity.java
private void injectPager(ActionBar bar, Bundle savedInstanceState) { // not show the bar, but not hide, u known what i mean? bar.setDisplayHomeAsUpEnabled(false); bar.setDisplayShowHomeEnabled(false); bar.setDisplayShowTitleEnabled(false); setContentView(R.layout.pager);/* w ww .j av a 2s. c om*/ mIds = getIntent().getIntegerArrayListExtra(PLUGINS); if (savedInstanceState == null) { mIds.add(0); // add an alt one... } Collections.shuffle(mIds); // shuffle it :-) mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setOffscreenPageLimit(2); mViewPager.setPageMargin(10); mViewPager.setPageMarginDrawable(new ColorDrawable(getResources().getColor(R.color.tab_selected))); mViewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) { @Override public Fragment getItem(int position) { Fragment fragment; switch (mIds.get(position)) { case PluginsPrefFragment.ZHIHU: fragment = ZhihuItemsFragment.getFragment(); break; case PluginsPrefFragment.FANTASY: fragment = FantasyFallFragment.getFragment(); break; default: fragment = new PlaceHolderFragment(); break; } return fragment; } @Override public int getCount() { return mIds.size(); } @Override public CharSequence getPageTitle(int position) { switch (mIds.get(position)) { case PluginsPrefFragment.ZHIHU: return getString(R.string.read_zhihu); case PluginsPrefFragment.FANTASY: return getString(R.string.fantasy); default: return "more plugins..."; } } }); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { getActionBar().setSelectedNavigationItem(position); } }); for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) { bar.addTab(bar.newTab().setText(mViewPager.getAdapter().getPageTitle(i)).setTabListener(this)); } }
From source file:ca.mimic.apphangar.Settings.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mInstance = this; setContentView(R.layout.activity_settings); prefs = new PrefsGet(getSharedPreferences(getPackageName(), Context.MODE_MULTI_PROCESS)); mContext = this; if (showChangelog(prefs)) { launchChangelog();//from w w w .j a va2 s . co m } display = getWindowManager().getDefaultDisplay(); updateDisplayWidth(); myService = new ServiceCall(mContext); myService.setConnection(mConnection); // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setTitle(R.string.title_activity_settings); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setCustomView(R.layout.action_spinner); setUpSpinner((Spinner) actionBar.getCustomView().findViewById(R.id.config_spinner)); actionBar.setDisplayShowCustomEnabled(true); mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOffscreenPageLimit(4); mGetFragments = new GetFragments(); mGetFragments.setFm(getFragmentManager()); mGetFragments.setVp(mViewPager); ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }; mViewPager.setOnPageChangeListener(pageChangeListener); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } pageChangeListener.onPageSelected(GENERAL_TAB); }
From source file:com.networksaremadeofstring.anonionooid.RelayDetailsSwipe.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_relay_details_swipe); // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mContext = this; if (null == lc) lc = new LocalCache(mContext); lc.open();/*w w w .j a v a 2 s. c o m*/ isFavourite = lc.isAFavourite(getIntent().getStringExtra(Ooo.ARG_ITEM_ID)); lc.close(); // Show the Up button in the action bar. actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setIcon(R.drawable.ab_icon); try { //fingerprint = actionBar.setSubtitle(getIntent().getStringExtra(Ooo.ARG_ITEM_ID)); } catch (Exception e) { e.printStackTrace(); } if (savedInstanceState == null) { // Create the detail fragment and add it to the activity // using a fragment transaction. arguments = new Bundle(); arguments.putString(Ooo.ARG_ITEM_ID, getIntent().getStringExtra(Ooo.ARG_ITEM_ID)); /*RelayDetailFragment fragment = new RelayDetailFragment(); fragment.setArguments(arguments); getFragmentManager().beginTransaction() .add(R.id.relay_detail_container, fragment) .commit();*/ } // 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 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:com.owo.android.mtPlease.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set up the action bar final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayShowTitleEnabled(false); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); // setting for the sidedrawer // set the content view setBehindContentView(R.layout.drawer_search); getSlidingMenu().setFadeEnabled(true); getSlidingMenu().setShadowWidthRes(R.dimen.shadow_width); getSlidingMenu().setShadowDrawable(R.drawable.shadow); getSlidingMenu().setFadeDegree(0.90f); searchDrawerCloseButton = (ImageButton) findViewById(R.id.button_search_drawer_close); searchDrawerCloseButton.setOnClickListener(new OnClickListener() { @Override// w w w . ja v a 2s . c o m public void onClick(View v) { // TODO Auto-generated method stub getSlidingMenu().showContent(); } }); // 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 public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); // mViewPager.setOffscreenPageLimit(3); // 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)); } locationSelectSpinner = (Spinner) findViewById(R.id.spinner_location); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.location_array, R.layout.spinner_text); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); locationSelectSpinner.setAdapter(adapter); datePickerButton = (Button) findViewById(R.id.button_datepicker); datePickerButton.setText(modifiedDate); datePickerButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub FragmentManager dialogManager = getFragmentManager(); CalendarDialogFragment calendarDialogFragment = new CalendarDialogFragment(); calendarDialogFragment.setParentCaller(CalendarDialogFragment.PARENT_IS_ACTIVITY); calendarDialogFragment.show(dialogManager, "calendar_dialog_popped"); } }); // Activity emailAddress(SESSION_ID) MyPageFragment // . // searchButton = (ImageButton) findViewById(R.id.imageButton_search); searchButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub try { String region = locationSelectSpinner.getSelectedItem().toString(); if (region.equals("")) { region = "1"; } else if (region.equals("")) { region = "2"; } else { region = "3"; } String people = ((EditText) findViewById(R.id.editText_numberPeople)).getText().toString(); String[] tmp = (datePickerButton.getText().toString()).split(" "); String date = tmp[0].substring(0, 4) + "-" + tmp[1].split("")[0] + "-" + tmp[2].split("")[0]; String query = "?region=" + region + "&people=" + people + "&date=" + date + "&flag=1"; sendInfoToFragment(people, 2); sendInfoToFragment(query, 0); getSlidingMenu().showContent(); } catch (Exception e) { // TODO Auto-generated catch block Toast.makeText(getApplicationContext(), " ", Toast.LENGTH_SHORT); e.printStackTrace(); } } }); }
From source file:com.univ.helsinki.app.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (FeedResource.getInstance().getSharedPrefs().getBoolean(Constant.SHARED_PREFS_KEY_ISFIRST_LAUNCH, false)) {//from w w w .j a va 2 s . c om getWindow().requestFeature(Window.FEATURE_ACTION_BAR); getActionBar().hide(); hideTitle(); } setContentView(R.layout.activity_main); splashLayout = (ViewGroup) findViewById(R.id.splashLayout); if (FeedResource.getInstance().getSharedPrefs().getBoolean(Constant.SHARED_PREFS_KEY_ISFIRST_LAUNCH, false)) { // record the fact that the app has been started at least once FeedResource.getInstance().getSharedPrefs().edit() .putBoolean(Constant.SHARED_PREFS_KEY_ISFIRST_LAUNCH, false).commit(); final ViewGroup splashLayout = (ViewGroup) findViewById(R.id.splashLayout); new Handler().postDelayed(new Runnable() { @Override public void run() { activateSplashScreen(splashLayout); } }, Constant.SPLASH_SCREEN_TIME_OUT); } else { splashLayout.setVisibility(View.GONE); } FeedResource.getInstance().inti(this); // 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(); mSensorFeedAdapter = new SensorFeedAdapter(this); // 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); switch (position) { case 0: { // on focus when first fragment //Toast.makeText(getApplicationContext(), "onPageSelected :" + position, Toast.LENGTH_SHORT).show(); List<SensorFeed> mtempAllowedSensorFeedList = new ArrayList<SensorFeed>(); // update the list over here.. to avoid empty shell for (SensorFeed sensor : FeedResource.getInstance().getSensorFeedList()) { boolean isChecked = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getBoolean(sensor.getSensorKey(), false); if (isChecked) mtempAllowedSensorFeedList.add(sensor); } // update the list with new created list mSensorFeedAdapter.setFeedList(mtempAllowedSensorFeedList); } break; }// switch ends } }); // 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)); } }