List of usage examples for android.app FragmentTransaction replace
public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment, String tag);
From source file:com.abewy.android.apps.openklyph.app.MainActivity.java
private void updateContent(int selection) { if (selection != oldSelection) { Bundle bundle = new Bundle(); bundle.putString(KlyphBundleExtras.ELEMENT_ID, KlyphSession.getSessionUserId()); String className = classes.get(selection); if (className.equals("com.abewy.android.apps.openklyph.fragment.Chat")) { PackageManager pm = getPackageManager(); try { pm.getPackageInfo(MESSENGER_PACKAGE_NAME, PackageManager.GET_ACTIVITIES); Intent intent = getPackageManager().getLaunchIntentForPackage(MESSENGER_PACKAGE_NAME); startActivity(intent);/*w w w . j a v a 2 s .com*/ } catch (NameNotFoundException e) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MESSENGER_PLAY_STORE_URI)); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(intent); } } else { if (selection < navAdapter.getCount()) setTitle(navAdapter.getItem(selection)); else setTitle(KlyphSession.getSessionUserName()); Fragment fragment = Fragment.instantiate(MainActivity.this, className, bundle); if (previousFragment != null) previousFragment.onSetToBack(this); FragmentTransaction tx = getFragmentManager().beginTransaction(); tx.replace(R.id.main, fragment, FRAGMENT_TAG); tx.commitAllowingStateLoss(); ((IKlyphFragment) fragment).onSetToFront(this); previousFragment = (IKlyphFragment) fragment; navAdapter.setSelectedPosition(selection); navAdapter.notifyDataSetChanged(); oldSelection = selection; if (notificationsFragment != null) notificationsFragment.setHasOptionsMenu(false); } } }
From source file:com.android.mail.ui.TwoPaneController.java
/** * Render the conversation list in the correct pane. *///from w w w . j a v a2 s .c o m private void renderConversationList() { if (mActivity == null) { return; } FragmentTransaction fragmentTransaction = mActivity.getFragmentManager().beginTransaction(); // Use cross fading animation. fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); final Fragment conversationListFragment = ConversationListFragment.newInstance(mConvListContext); fragmentTransaction.replace(R.id.conversation_list_pane, conversationListFragment, TAG_CONVERSATION_LIST); fragmentTransaction.commitAllowingStateLoss(); }
From source file:at.alladin.rmbt.android.map.RMBTMapFragment.java
@Override public void onClick(View v) { final FragmentManager fm = getActivity().getFragmentManager(); final FragmentTransaction ft; final GoogleMap map = getMap(); switch (v.getId()) { case R.id.mapChooseButton: ft = fm.beginTransaction();// w ww. j a v a2s .com ft.replace(R.id.fragment_content, new RMBTMapChooseFragment(), "map_choose"); ft.addToBackStack("map_choose"); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); break; case R.id.mapFilterButton: ft = fm.beginTransaction(); ft.replace(R.id.fragment_content, new RMBTMapFilterFragment(), "map_filter"); ft.addToBackStack("map_filter"); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); break; case R.id.mapLocateButton: if (map != null) { final Location location = geoLocation.getLastKnownLocation(); if (location != null) { final LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude()); gMap.animateCamera(CameraUpdateFactory.newLatLng(latlng)); } } break; case R.id.mapHelpButton: ((RMBTMainActivity) getActivity()).showHelp("", false, AppConstants.PAGE_TITLE_HELP); // TODO: put correct // help url break; case R.id.mapInfoButton: showInfoToast(); break; case R.id.mapZoomInButton: if (map != null) map.animateCamera(CameraUpdateFactory.zoomIn()); break; case R.id.mapZoomOutButton: if (map != null) map.animateCamera(CameraUpdateFactory.zoomOut()); break; default: break; } }
From source file:com.google.android.apps.forscience.whistlepunk.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem == null) { return false; }/*from w ww . j a va 2 s . c om*/ if (menuItem.getGroupId() == R.id.navigation_top) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); Fragment fragment; int itemId = menuItem.getItemId(); final String tag = String.valueOf(itemId); fragment = getFragmentManager().findFragmentByTag(tag); if (fragment == null) { fragment = createNewFragment(itemId); } adjustActivityForSelectedItem(itemId); mTitleToRestore = getTitleToRestore(menuItem); transaction.replace(R.id.content_container, fragment, tag).commit(); if (menuItem.isCheckable()) { menuItem.setChecked(true); } mDrawerLayout.closeDrawers(); restoreActionBar(); mSelectedItemId = itemId; } else if (menuItem.getGroupId() == R.id.navigation_bottom) { mDrawerLayout.closeDrawers(); // Launch intents Intent intent = null; int itemId = menuItem.getItemId(); if (itemId == R.id.navigation_item_website) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.website_url))); } else if (itemId == R.id.navigation_item_settings) { intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_SETTINGS); } else if (itemId == R.id.navigation_item_about) { intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_ABOUT); } else if (itemId == R.id.dev_testing_options) { intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_DEV_OPTIONS); } else if (itemId == R.id.navigation_item_feedback) { mFeedbackProvider.sendFeedback(new LoggingConsumer<Boolean>(TAG, "Send feedback") { @Override public void success(Boolean value) { if (!value) { showFeedbackError(); } } @Override public void fail(Exception e) { super.fail(e); showFeedbackError(); } }); } if (intent != null) { startActivity(intent); } } return false; }
From source file:com.example.pyrkesa.shwc.MainActivity.java
/** * Diplaying fragment view for selected nav drawer list item * *///from w w w .ja va 2 s . co m private void displayView(int position) { Fragment fragment = null; switch (position) { case 0: fragment = new HomeFragment(); mTitle = "SHWC"; break; case 1: fragment = new ScenarioFragment(); mTitle = "Dfinir scnarios"; break; case 2: fragment = new RoomSettingFragment(); mTitle = "Rglage salle"; break; case 3: fragment = new User_Fragment(); mTitle = "Gestion des utilisateurs"; break; default: break; } if (fragment != null) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.test, fragment, ""); transaction.commit(); model.current_page = position; mDrawerList.setItemChecked(position, true); mDrawerList.setSelection(position); //getActionBar().setTitle(mNavigationDrawerItemTitles[position]); // getActionBar().setTitle(position); mDrawerLayout.closeDrawer(mDrawerList); } else { Log.e("MainActivity", "Error in creating fragment"); } }
From source file:com.esri.android.mapsapp.MapsAppActivity.java
/** * Opens the map represented by the specified portal item or if null, opens * a default map.//from w w w . j a v a 2 s . c o m */ public void showMap(String portalItemId, String basemapPortalItemId) { // remove existing MapFragment explicitly, simply replacing it can cause // the app to freeze when switching basemaps FragmentTransaction transaction; FragmentManager fragmentManager = getFragmentManager(); Fragment currentMapFragment = fragmentManager.findFragmentByTag(MapFragment.TAG); if (currentMapFragment != null) { transaction = fragmentManager.beginTransaction(); transaction.remove(currentMapFragment); transaction.commit(); } MapFragment mapFragment = MapFragment.newInstance(portalItemId, basemapPortalItemId); transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.maps_app_activity_content_frame, mapFragment, MapFragment.TAG); transaction.addToBackStack(null); transaction.commit(); invalidateOptionsMenu(); // reload the options menu }
From source file:org.akvo.caddisfly.ui.activity.MainActivity.java
void displayView(int position, boolean addToBackStack) { int index = getCurrentFragmentIndex(); if (index == position) { // requested fragment is already showing return;//from www . ja va 2 s.co m } MainApp mainApp = (MainApp) getApplicationContext(); Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Config.FLOW_ACTION_EXTERNAL_SOURCE.equals(action) && type != null) { if ("text/plain".equals(type)) { //NON-NLS external = true; //mQuestionId = getIntent().getStringExtra("questionId"); mQuestionTitle = getIntent().getStringExtra("questionTitle"); String code = mQuestionTitle.substring(Math.max(0, mQuestionTitle.length() - 5)); mainApp.setSwatches(code); } } if (mainApp.currentTestInfo == null) { mainApp.currentTestInfo = new TestInfo("", "", ""); } Fragment fragment; switch (position) { case Config.HOME_SCREEN_INDEX: mStartFragment = StartFragment.newInstance(external, mainApp.currentTestInfo.getCode()); fragment = mStartFragment; break; case Config.CALIBRATE_SCREEN_INDEX: mCalibrateFragment = new CalibrateFragment(); fragment = mCalibrateFragment; setupActionBarSpinner(); break; case Config.SETTINGS_SCREEN_INDEX: if (mSettingsFragment == null) { mSettingsFragment = new SettingsFragment(); } fragment = mSettingsFragment; break; default: return; } FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); ft.replace(R.id.container, fragment, String.valueOf(position)); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); if (addToBackStack) { ft.addToBackStack(null); } ft.commit(); invalidateOptionsMenu(); updateActionBarNavigation(position); }
From source file:by.zatta.pilight.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { /*//from w ww . j a v a2 s. c o m * The action bar home/up should open or close the drawer. ActionBarDrawerToggle will take care of this. */ publishList(); if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); switch (item.getItemId()) { case R.id.menu_about: openDialogFragment(AboutDialog.newInstance()); return true; case R.id.menu_settings: Fragment pref = fm.findFragmentByTag("prefs"); if (pref == null) { ft.replace(R.id.fragment_main, new PrefFragment(), "prefs"); fm.popBackStack(); ft.addToBackStack(null); ft.commit(); } else { ft.remove(fm.findFragmentByTag("prefs")); ft.commit(); fm.popBackStack(); } return true; default: break; } // Handle your other action bar items... return super.onOptionsItemSelected(item); }
From source file:com.murati.oszk.audiobook.ui.MusicPlayerActivity.java
private void navigateToBrowser(String mediaId) { //TODO: maybe place navigate block here LogHelper.d(TAG, "navigateToBrowser, mediaId=" + mediaId); MediaBrowserFragment fragment = getBrowseFragment(); updateBookButtons(mediaId);// w w w . j a va 2s .com if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) { // Create Transaction FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left, R.animator.slide_in_from_left, R.animator.slide_out_to_right); // Create Backstack // Not an empty, root or the same where we are currently, for refresh retries if (fragment != null && mediaId != null && mediaId != getMediaId()) { transaction.addToBackStack(null); } //Create new fragment and navigate fragment = new MediaBrowserFragment(); fragment.setMediaId(mediaId); transaction.replace(R.id.container, fragment, FRAGMENT_TAG); //Do it transaction.commit(); } }
From source file:blackman.matt.infinitebrowser.InfinityBrowser.java
/** * Load a board using a variety of logics. *//*from w w w . jav a 2 s .c o m*/ private void loadUpABoard() { // Load preferences for activity SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); Boolean ageAccept = preferences.getBoolean("age_guard_accept", false); // Checks if age guard has been accepted if (!ageAccept) { DialogFragment ageGuardDialog = new AgeGuardDialogFragment(); ageGuardDialog.show(getFragmentManager(), "ageGuardDialog"); } else { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Board newBoard; Intent intent = getIntent(); String defaultBoard = preferences.getString("default_board", "").toLowerCase(); if (intent.getData() != null || intent.getExtras() != null) { newBoard = loadFromIntent(intent); } else if (!defaultBoard.equals("")) { newBoard = Board.newInstance(defaultBoard); mTitle = "/" + defaultBoard.toLowerCase() + "/"; } else { newBoard = getFirstDrawerItem(); } if (newBoard != null) { fragmentTransaction.replace(R.id.container, newBoard, mTitle.toString()); findViewById(R.id.ll_help_add_boards).setVisibility(View.GONE); setTitle(mTitle); } fragmentTransaction.commit(); } }