List of usage examples for android.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:com.android.eventspace.MainActivity.java
private void selectItem(int position) { Toast.makeText(getApplicationContext(), "number" + position, Toast.LENGTH_SHORT).show(); FrameLayout f;//w ww .j av a2s . co m Fragment fragment; Bundle args; FragmentManager fragmentManager; switch (position) { case (3): f = (FrameLayout) findViewById(R.id.map_frame); f.setVisibility(View.GONE); final LatLng SITTERSON = new LatLng(35.910057, -79.053470); final LatLng OLDWELL = new LatLng(35.912045, -79.051181); GoogleMap googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); if (googleMap == null) { Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); } else { Marker hamburg = googleMap .addMarker(new MarkerOptions().position(SITTERSON).title("My Second Home")); Marker kiel = googleMap .addMarker(new MarkerOptions().position(OLDWELL).title("Oldwell").snippet("The Old Well") .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))); googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SITTERSON, 2)); // Zoom in, animating the camera. googleMap.animateCamera(CameraUpdateFactory.zoomTo(21), 15000, null); } break; case 1: f = (FrameLayout) findViewById(R.id.map_frame); f.setVisibility(View.VISIBLE); // update the main content by replacing fragments fragment = new OptionFragment(position); args = new Bundle(); args.putInt(OptionFragment.ARG_OPTION_NUMBER, position); fragment.setArguments(args); fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); break; case 2: f = (FrameLayout) findViewById(R.id.map_frame); f.setVisibility(View.VISIBLE); // update the main content by replacing fragments fragment = new OptionFragment(position); args = new Bundle(); args.putInt(OptionFragment.ARG_OPTION_NUMBER, position); fragment.setArguments(args); fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); break; } // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(optionTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.google.samples.apps.iosched.ui.BaseActivity.java
/** * Adds a {@link com.google.samples.apps.iosched.framework.PresenterFragmentImpl} to the * Activity if required, and sets it up with the {@code model}, {@code queries}, * {@code actions} and the {@link com.google.samples.apps.iosched.framework.UpdatableView} * corresponding to the {@code updatableViewResId}. * * @return the {@link com.google.samples.apps.iosched.framework.PresenterFragmentImpl}, *///from w w w .jav a 2 s . c om public PresenterFragmentImpl addPresenterFragment(int updatableViewResId, Model model, QueryEnum[] queries, UserActionEnum[] actions) { FragmentManager fragmentManager = getFragmentManager(); //Check if the presenter fragment is already present (ie if the activity is recreated due // to orientation change). PresenterFragmentImpl presenter = (PresenterFragmentImpl) fragmentManager.findFragmentByTag(PRESENTER_TAG); if (presenter == null) { //Create, set up and add the presenter. presenter = new PresenterFragmentImpl(); setUpPresenter(presenter, fragmentManager, updatableViewResId, model, queries, actions); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(presenter, PRESENTER_TAG); fragmentTransaction.commit(); } else { //Set up the presenter. setUpPresenter(presenter, fragmentManager, updatableViewResId, model, queries, actions); } return presenter; }
From source file:com.adafruit.bluefruit.le.connect.app.MainActivity.java
private void restoreRetainedDataFragment() { // find the retained fragment FragmentManager fm = getFragmentManager(); mRetainedDataFragment = (DataFragment) fm.findFragmentByTag(TAG); if (mRetainedDataFragment == null) { // Create mRetainedDataFragment = new DataFragment(); fm.beginTransaction().add(mRetainedDataFragment, TAG).commitAllowingStateLoss(); // http://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-h mScannedDevices = new ArrayList<>(); // mPeripheralList = new PeripheralList(); } else {/*w w w .j ava2 s . c o m*/ // Restore status mScannedDevices = mRetainedDataFragment.mScannedDevices; mComponentToStartWhenConnected = mRetainedDataFragment.mComponentToStartWhenConnected; mShouldEnableWifiOnQuit = mRetainedDataFragment.mShouldEnableWifiOnQuit; mFirmwareUpdater = mRetainedDataFragment.mFirmwareUpdater; mLatestCheckedDeviceAddress = mRetainedDataFragment.mLatestCheckedDeviceAddress; mSelectedDeviceData = mRetainedDataFragment.mSelectedDeviceData; //mPeripheralList = mRetainedDataFragment.mPeripheralList; if (mFirmwareUpdater != null) { mFirmwareUpdater.changedParentActivity(this); // set the new activity } } }
From source file:com.plusapp.pocketbiceps.app.MainActivity.java
@SuppressWarnings("StatementWithEmptyBody") @Override//from w w w .j a va 2 s . c om public boolean onNavigationItemSelected(MenuItem item) { FragmentManager fm = getFragmentManager(); // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_camera) { Intent intent = new Intent(MainActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else if (id == R.id.nav_gallery) { // Create intent to Open Image applications like Gallery, Google Photos Intent galleryIntent = new Intent(Intent.ACTION_PICK); galleryIntent.setType("image/*"); galleryIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivityForResult(galleryIntent, RESULT_LOAD_IMG); } else if (id == R.id.nav_moments_gallery) { Intent intent = new Intent(MainActivity.this, ActivityGallery.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else if (id == R.id.nav_slideshow) { GmapsFragment gmap = (GmapsFragment) getFragmentManager().findFragmentByTag("GMAP_TAG"); if (gmap != null && gmap.isVisible()) { // Es muss ueberprueft werden ob das Gmap Fragment schon sichtbar ist, falls das der Fall ist darf das Fragment nicht nochmal geoeffnet werden // ansonsten stuerzt die App bei BackButtonPressed ab } else { try { for (int i = 0; i < navigationView.getMenu().size(); i++) { navigationView.getMenu().getItem(i).setChecked(false); } } catch (Exception e) { } /** * addToBackStack verhindert dass die App sich beim BackPressed im GMap Fragment schliet */ fm.beginTransaction().replace(R.id.content_main, new GmapsFragment(), "GMAP_TAG") .addToBackStack(null).commit(); } // Damit wird nach den Permissions gefragt bevor die Map aufgebaut wird, somit kann direkt auf den Standort gezoomt werden if (ContextCompat.checkSelfPermission(this.getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION }, PERMISSION_ACCESS_COARSE_LOCATION); } } else if (id == R.id.nav_manage) { Intent intent = new Intent(MainActivity.this, ActivityPreference.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else if (id == R.id.nav_share) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(PLAYSTORE_LINK + this.getPackageName()))); } else if (id == R.id.nav_send) { displayImpressumAlertDialog(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:com.artitk.licensefragment.example.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { // if (true) return; FragmentManager fragmentManager = getFragmentManager(); Fragment fragment;/*from w w w. ja v a2 s . c o m*/ ArrayList<Integer> licenseIds = new ArrayList<>(); licenseIds.add(LicenseID.GSON); licenseIds.add(LicenseID.RETROFIT); switch (position) { case 0: if (fragmentManager.findFragmentById(R.id.container) instanceof ScrollViewLicenseFragment) return; fragment = ScrollViewLicenseFragment.newInstance(licenseIds); // Call newInstance() using parameter ArrayList<Integer> break; case 1: if (fragmentManager.findFragmentById(R.id.container) instanceof ListViewLicenseFragment) return; fragment = ListViewLicenseFragment.newInstance(new int[] { LicenseID.PICASSO }) // Call newInstance() using parameter array .withLicenseChain(false); // Disable license chain break; case 2: if (fragmentManager.findFragmentById(R.id.container) instanceof RecyclerViewLicenseFragment) return; ArrayList<License> licenses = new ArrayList<>(); licenses.add(new License(this, "Test Library 1", LicenseType.MIT_LICENSE, "2000-2001", "Test Owner 1")); licenses.add(new License(this, "Test Library 2", LicenseType.GPL_30, "2002", "Test Owner 2")); licenses.add(new License(this, "Test Library 3", LicenseType.EPL_10, "2003", "Test Owner 3")); licenses.add(new License(this, "Custom License 1", R.raw.wtfpl, "2004", "Test Owner 3")); licenses.add(new License(this, "Custom License 2", R.raw.x11, "2005", "Test Owner 4")); fragment = RecyclerViewLicenseFragment.newInstance() // Call newInstance() using without parameter .setLog(true) // Enable Log .withLicenseChain(true) // Enable license chain (default) .addLicense(new int[] { LicenseID.PICASSO }) // Add array (same call newInstance) .addLicense(licenseIds) // Add ArrayList<Integer> (same call newInstance) .addCustomLicense(licenses) // Add Custom License .setCustomUI(new CustomUI() // Set Custom UI .setTitleBackgroundColor(Color.parseColor("#7fff7f")) .setTitleTextColor(getResources().getColor(android.R.color.holo_green_dark)) .setLicenseBackgroundColor(Color.rgb(127, 223, 127)).setLicenseTextColor(Color.DKGRAY)); break; default: return; } // ((LicenseFragmentBase) fragment).setLog(true); // update the main content by replacing fragments fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); fragmentId = position + 1; }
From source file:com.eutectoid.dosomething.PickerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pickers);/*from www . j a va 2 s. co m*/ Bundle args = getIntent().getExtras(); FragmentManager manager = getFragmentManager(); Fragment fragmentToShow = null; Uri intentUri = getIntent().getData(); if (FRIEND_PICKER.equals(intentUri)) { if (savedInstanceState == null) { friendPickerFragment = new FriendPickerFragment(); friendPickerFragment.setSettingsFromBundle(args); friendPickerFragment.setFriendPickerType(FriendPickerFragment.FriendPickerType.TAGGABLE_FRIENDS); } else { friendPickerFragment = (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment); ; } friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { @Override public void onError(PickerFragment fragment, FacebookException error) { PickerActivity.this.onError(error); } }); friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { @Override public void onDoneButtonClicked(PickerFragment fragment) { finishActivity(); } }); fragmentToShow = friendPickerFragment; } else if (PLACE_PICKER.equals(intentUri)) { if (savedInstanceState == null) { placePickerFragment = new PlacePickerFragment(); placePickerFragment.setSettingsFromBundle(args); } else { placePickerFragment = (PlacePickerFragment) manager.findFragmentById(R.id.picker_fragment); } placePickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() { @Override public void onSelectionChanged(PickerFragment fragment) { finishActivity(); // call finish since you can only pick one place } }); placePickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { @Override public void onError(PickerFragment fragment, FacebookException error) { PickerActivity.this.onError(error); } }); placePickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { @Override public void onDoneButtonClicked(PickerFragment fragment) { finishActivity(); } }); fragmentToShow = placePickerFragment; } else { // Nothing to do, finish setResult(RESULT_CANCELED); finish(); return; } manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit(); }
From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java
@Override public void onResume() { super.onResume(); activityIsVisible = true;// ww w . j av a2s.co m // Handle Item list empty due to Fragment stack try { FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); if (fm.getBackStackEntryCount() == 0 && firstFragment.getSecondFragmentContainer() == R.id.one_frame && fm.findFragmentById( R.id.one_frame) instanceof com.lgallardo.youtorrentcontroller.ItemstFragment) { com.lgallardo.youtorrentcontroller.ItemstFragment fragment = (com.lgallardo.youtorrentcontroller.ItemstFragment) fm .findFragmentById(R.id.one_frame); if (fragment.getListView().getCount() == 0) { // Create the about fragment aboutFragment = new AboutFragment(); fragmentTransaction.replace(R.id.one_frame, aboutFragment, "firstFragment"); fragmentTransaction.commit(); // Se titile // setTitle(navigationDrawerItemTitles[drawerList.getCheckedItemPosition()]); setTitle(navigationDrawerItemTitles[DrawerItemRecyclerViewAdapter.actionPosition]); // Close Contextual Action Bar if (firstFragment != null && firstFragment.mActionMode != null) { firstFragment.mActionMode.finish(); } // Refresh current list refreshCurrent(); } } if (fm.getBackStackEntryCount() == 0 && firstFragment.getSecondFragmentContainer() == R.id.content_frame && (fm.findFragmentByTag("secondFragment") instanceof AboutFragment)) { // Create the about fragment aboutFragment = new AboutFragment(); fragmentTransaction.replace(R.id.content_frame, aboutFragment, "secondFragment"); fragmentTransaction.commit(); // Set title setTitle(navigationDrawerItemTitles[DrawerItemRecyclerViewAdapter.actionPosition]); // Close Contextual Action Bar if (firstFragment != null && firstFragment.mActionMode != null) { firstFragment.mActionMode.finish(); } // Refresh current list refreshCurrent(); } } catch (Exception e) { } }
From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get preferences getSettings();//from ww w .ja v a 2 s . co m // Set alarm for checking completed torrents, if not set if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), NotifierService.class), PendingIntent.FLAG_NO_CREATE) == null) { // Set Alarm for checking completed torrents alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), NotifierService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); } // Set alarm for RSS checking, if not set if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), RSSService.class), PendingIntent.FLAG_NO_CREATE) == null) { // Set Alarm for checking completed torrents alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), RSSService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, AlarmManager.INTERVAL_DAY, alarmIntent); } // Set Theme (It must be fore inflating or setContentView) if (dark_ui) { this.setTheme(R.style.Theme_Dark); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); } } else { this.setTheme(R.style.Theme_Light); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.primary)); } } setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.app_bar); if (dark_ui) { toolbar.setBackgroundColor(getResources().getColor(R.color.Theme_Dark_primary)); } setSupportActionBar(toolbar); // Set App title setTitle(R.string.app_shortname); // Drawer menu navigationDrawerServerItems = getResources().getStringArray(R.array.qBittorrentServers); navigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // drawerList = (ListView) findViewById(R.id.left_drawer); mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are ArrayList<ObjectDrawerItem> serverItems = new ArrayList<ObjectDrawerItem>(); ArrayList<ObjectDrawerItem> actionItems = new ArrayList<ObjectDrawerItem>(); ArrayList<ObjectDrawerItem> settingsItems = new ArrayList<ObjectDrawerItem>(); // Add server category serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_servers, getResources().getString(R.string.drawer_servers_category), DRAWER_CATEGORY, false, null)); // Server items int currentServerValue = 1; try { currentServerValue = Integer.parseInt(MainActivity.currentServer); } catch (NumberFormatException e) { } for (int i = 0; i < navigationDrawerServerItems.length; i++) { // Log.d("Debug", "MainActivity - currentServerValue - currentServerValue: " + currentServerValue); // Log.d("Debug", "MainActivity - currentServerValue - (i + 1): " + (i + 1)); // Log.d("Debug", "MainActivity - currentServerValue - (i + 1) == currentServerValue: " + ((i + 1) == currentServerValue)); serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, navigationDrawerServerItems[i], DRAWER_ITEM_SERVERS, ((i + 1) == currentServerValue), "changeCurrentServer")); } // // serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 1", DRAWER_ITEM_SERVERS, true, "changeCurrentServer")); // serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 2", DRAWER_ITEM_SERVERS, false, "changeCurrentServer")); // serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 3", DRAWER_ITEM_SERVERS, false, "changeCurrentServer")); // Add actions actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_all, navigationDrawerItemTitles[0], DRAWER_ITEM_ACTIONS, lastState.equals("all"), "refreshAll")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_downloading, navigationDrawerItemTitles[1], DRAWER_ITEM_ACTIONS, lastState.equals("downloading"), "refreshDownloading")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_completed, navigationDrawerItemTitles[2], DRAWER_ITEM_ACTIONS, lastState.equals("completed"), "refreshCompleted")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_paused, navigationDrawerItemTitles[3], DRAWER_ITEM_ACTIONS, lastState.equals("pause"), "refreshPaused")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_active, navigationDrawerItemTitles[4], DRAWER_ITEM_ACTIONS, lastState.equals("active"), "refreshActive")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_inactive, navigationDrawerItemTitles[5], DRAWER_ITEM_ACTIONS, lastState.equals("inactive"), "refreshInactive")); // Add settings actions // drawerItems.add(new ObjectDrawerItem(R.drawable.ic_action_options, navigationDrawerItemTitles[6], DRAWER_ITEM_ACTIONS, false, "openOptions")); settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_settings, navigationDrawerItemTitles[6], DRAWER_ITEM_ACTIONS, false, "openSettings")); if (packageName.equals("com.lgallardo.youtorrentcontroller")) { settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_pro, navigationDrawerItemTitles[7], DRAWER_ITEM_ACTIONS, false, "getPro")); settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[8], DRAWER_ITEM_ACTIONS, false, "openHelp")); } else { settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[7], DRAWER_ITEM_ACTIONS, false, "openHelp")); } // Set adapter rAdapter = new DrawerItemRecyclerViewAdapter(getApplicationContext(), this, serverItems, actionItems, settingsItems, null); rAdapter.notifyDataSetChanged(); // Log.d("Debug", "MainActivity - oldActionPosition: "+ (Arrays.asList(actionStates).indexOf(lastState))); // drawerList.setAdapter(adapter); mRecyclerView.setAdapter(rAdapter); mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager // Set selection according to last state setSelectionAndTitle(lastState); // Set the item click listener // drawerList.setOnItemClickListener(new DrawerItemClickListener()); // Get drawer title title = drawerTitle = getTitle(); // Add the application icon control code inside MainActivity onCreate drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // New ActionBarDrawerToggle for Google Material Desing (v7) drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { /** * Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); // getSupportActionBar().setTitle(title); } /** * Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // getSupportActionBar().setTitle(drawerTitle); // setTitle(R.string.app_shortname); } }; drawerLayout.setDrawerListener(drawerToggle); // drawerToggle.syncState(); // Finally we set the drawer toggle sync State getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(false); // Get options and save them as shared preferences // qBittorrentOptions qso = new qBittorrentOptions(); // qso.execute(new String[]{qbQueryString + "/preferences", "getSettings"}); // If it were awaked from an intent-filter, // Get token and cookie and then // get intent from the intent filter and Add URL torrent // Log.d("Debug", "MainActivity - 1"); new torrentTokenByIntent().execute(getIntent()); // Fragments // Check whether the activity is using the layout version with // the fragment_container FrameLayout. If so, we must add the first // fragment if (findViewById(R.id.fragment_container) != null) { // However, if we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. // if (savedInstanceState != null) { // return; // } // This fragment will hold the list of torrents if (firstFragment == null) { firstFragment = new com.lgallardo.youtorrentcontroller.ItemstFragment(); } // This fragment will hold the list of torrents helpTabletFragment = new HelpFragment(); // Set the second fragments container firstFragment.setSecondFragmentContainer(R.id.content_frame); // This i the second fragment, holding a default message at the // beginning secondFragment = new AboutFragment(); // Add the fragment to the 'list_frame' FrameLayout FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (fragmentManager.findFragmentByTag("firstFragment") == null) { fragmentTransaction.add(R.id.list_frame, helpTabletFragment, "firstFragment"); } else { fragmentTransaction.replace(R.id.list_frame, helpTabletFragment, "firstFragment"); } if (fragmentManager.findFragmentByTag("secondFragment") == null) { fragmentTransaction.add(R.id.content_frame, secondFragment, "secondFragment"); } else { fragmentTransaction.replace(R.id.content_frame, secondFragment, "secondFragment"); } fragmentTransaction.commit(); // Second fragment will be added in ItemsFRagment's onListItemClick // method } else { // Phones handle just one fragment // Create an instance of ItemsFragments if (firstFragment == null) { firstFragment = new com.lgallardo.youtorrentcontroller.ItemstFragment(); } firstFragment.setSecondFragmentContainer(R.id.one_frame); // This is the about fragment, holding a default message at the // beginning secondFragment = new AboutFragment(); // If we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. // if (savedInstanceState != null) { // // // Handle Item list empty due to Fragment stack // try { // FragmentManager fm = getFragmentManager(); // // if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.youtorrentcontroller.TorrentDetailsFragment) { // // refreshCurrent(); // // } // } // catch (Exception e) { // } // // return; // } // Add the fragment to the 'list_frame' FrameLayout FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (fragmentManager.findFragmentByTag("firstFragment") == null) { fragmentTransaction.add(R.id.one_frame, secondFragment, "firstFragment"); } else { fragmentTransaction.replace(R.id.one_frame, secondFragment, "firstFragment"); } // if torrent details was loaded reset back button stack for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { fragmentManager.popBackStack(); } fragmentTransaction.commit(); } // Activity is visible activityIsVisible = true; // First refresh refreshCurrent(); handler = new Handler(); handler.postDelayed(m_Runnable, refresh_period); // Load banner loadBanner(); }
From source file:de.sourcestream.movieDB.MainActivity.java
/** * Displays fragment view for the selected item from the slide menu. * * @param position is the position that we have selected. *//*from w w w .jav a 2s . c o m*/ private void displayView(int position) { if (position != 0) { // Clear history of the back stack if any FragmentManager fm = getFragmentManager(); fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); // update the main content by replacing fragments Fragment fragment = null; searchMovieDetails = 0; searchCastDetails = 0; searchTvDetails = 0; searchViewCount = false; resetMovieDetailsBundle(); resetCastDetailsBundle(); resetTvDetailsBundle(); switch (position) { // Case 0 is the header we don't want to do anything with it. case 1: reAttachMovieFragments = true; if (oldPos == position) { mDrawerLayout.closeDrawer(mDrawerList); break; } fragment = movieSlideTab; break; case 2: reAttachTVFragments = true; if (oldPos == position) { mDrawerLayout.closeDrawer(mDrawerList); break; } fragment = tvSlideTab; break; case 3: if (oldPos == position) { mDrawerLayout.closeDrawer(mDrawerList); break; } fragment = getFragmentManager().findFragmentByTag("genres"); if (fragment == null) fragment = genresList; if (genresList.getBackState() == 0) genresList.updateList(); break; case 4: if (oldPos == position) { mDrawerLayout.closeDrawer(mDrawerList); break; } fragment = about; break; default: break; } oldPos = position; if (fragment != null) { fm.beginTransaction().replace(R.id.frame_container, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); mDrawerList.setSelection(position); setTitle(navMenuTitles[position - 1]); mDrawerLayout.closeDrawer(mDrawerList); try { movieSlideTab.showInstantToolbar(); tvSlideTab.showInstantToolbar(); } catch (NullPointerException e) { } System.gc(); } } else { mDrawerList.setItemChecked(oldPos, true); } }
From source file:com.lgallardo.qbittorrentclient.RefreshListener.java
@Override public void onResume() { super.onResume(); activityIsVisible = true;/* w w w.jav a2 s . c o m*/ // Handle Item list empty due to Fragment stack try { FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); if (fm.getBackStackEntryCount() == 0 && firstFragment.getSecondFragmentContainer() == R.id.one_frame && fm.findFragmentById( R.id.one_frame) instanceof com.lgallardo.qbittorrentclient.ItemstFragment) { com.lgallardo.qbittorrentclient.ItemstFragment fragment = (com.lgallardo.qbittorrentclient.ItemstFragment) fm .findFragmentById(R.id.one_frame); if (fragment.getListView().getCount() == 0) { // Create the about fragment aboutFragment = new AboutFragment(); fragmentTransaction.replace(R.id.one_frame, aboutFragment, "firstFragment"); fragmentTransaction.commit(); // Se title // setTitle(navigationDrawerItemTitles[drawerList.getCheckedItemPosition()]); // setTitle(navigationDrawerItemTitles[DrawerItemRecyclerViewAdapter.actionPosition]); setSelectionAndTitle(lastState); // Close Contextual Action Bar if (firstFragment != null && firstFragment.mActionMode != null) { firstFragment.mActionMode.finish(); } // Refresh current list refreshCurrent(); } } if (fm.getBackStackEntryCount() == 0 && firstFragment.getSecondFragmentContainer() == R.id.content_frame && (fm.findFragmentByTag("secondFragment") instanceof AboutFragment)) { // Create the about fragment aboutFragment = new AboutFragment(); fragmentTransaction.replace(R.id.content_frame, aboutFragment, "secondFragment"); fragmentTransaction.commit(); // Se title // setTitle(navigationDrawerItemTitles[drawerList.getCheckedItemPosition()]); // setTitle(navigationDrawerItemTitles[DrawerItemRecyclerViewAdapter.actionPosition]); setSelectionAndTitle(lastState); // Close Contextual Action Bar if (firstFragment != null && firstFragment.mActionMode != null) { firstFragment.mActionMode.finish(); } // Refresh current list refreshCurrent(); } } catch (Exception e) { } }