List of usage examples for android.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:fr.cph.chicago.core.activity.BusMapActivity.java
@Override public final void onStart() { super.onStart(); if (mapFragment == null) { final FragmentManager fm = getFragmentManager(); mapFragment = (MapFragment) fm.findFragmentById(R.id.map); final GoogleMapOptions options = new GoogleMapOptions(); final CameraPosition camera = new CameraPosition(Util.CHICAGO, 10, 0, 0); options.camera(camera);/*w w w .j av a 2 s.co m*/ mapFragment = MapFragment.newInstance(options); mapFragment.setRetainInstance(true); fm.beginTransaction().replace(R.id.map, mapFragment).commit(); } }
From source file:jp.coe.winkbook.ItemListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_item_app_bar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w . j a va2s.c om*/ mTitleList = new LinkedList(); mTitleList.addLast(getTitle()); toolbar.setTitle((String) mTitleList.getLast()); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); final FragmentManager dialogmanager = getFragmentManager(); final android.support.v4.app.FragmentManager manager = getSupportFragmentManager(); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //license LicenseDialogFragment dialog = new LicenseDialogFragment(); dialog.show(dialogmanager, "dialog"); } }); if (savedInstanceState == null) { // ItemListFragment fragment = new ItemListFragment(); // ?? FragmentTransaction ? FragmentTransaction transaction = manager.beginTransaction(); transaction.add(R.id.frameLayout, fragment); transaction.commit(); } }
From source file:org.sleepydragon.rgbclient.MainFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { LOG.v("onActivityCreated()"); super.onActivityCreated(savedInstanceState); final FragmentManager fm = getFragmentManager(); mNetworkClientFragment = (NetworkClientFragment) fm.findFragmentByTag(NetworkClientFragment.TAG); if (mNetworkClientFragment == null) { mNetworkClientFragment = new NetworkClientFragment(); mNetworkClientFragment.setTargetFragment(this, 0); fm.beginTransaction().add(mNetworkClientFragment, NetworkClientFragment.TAG).commit(); }// w w w . j a v a2 s.co m updateDisplayedColor(); // add any color commands that were received during the configuration change synchronized (mCommandQueue) { final ColorCommand lastCommand; if (mCommandQueue.size() > 0) { lastCommand = mCommandQueue.get(mCommandQueue.size() - 1); } else { lastCommand = mColorState.getLastAddedCommand(); } final UUID lastCommandId = (lastCommand == null) ? null : lastCommand.id; mNetworkClientFragment.getCommandsSince(lastCommandId, mCommandQueue); } mHandler.removeMessages(R.id.MSG_PROCESS_QUEUED_COMMANDS); mHandler.sendEmptyMessage(R.id.MSG_PROCESS_QUEUED_COMMANDS); }
From source file:com.sevensales.MainActivity.java
private void selectItem(int position) { // update the main content by replacing fragments getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentManager fragmentManager = getFragmentManager(); //storage.refreshSalesList(); //Log.d("q",String.valueOf(storage.sales_list.size())); //Toast.makeText(this,String.valueOf(getFragmentManager().getBackStackEntryCount()), Toast.LENGTH_LONG).show();getFragmentManager().getBackStackEntryCount(); if (0 == position) { SalesFragment fragment = new SalesFragment(); fragment.sales = storage.getSalesList(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); }//w ww.jav a2 s . c o m if (1 == position) { ShopsFragment fragment = new ShopsFragment(); fragment.shops = storage.getShopsList(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); } if (2 == position) { CategoriesFragment fragment = new CategoriesFragment(); fragment.categories = storage.getCategoriesList(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); } if (3 == position) { SettingsFragment fragment = new SettingsFragment(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); } if (4 == position) { SubscribesFragment fragment = new SubscribesFragment(); fragment.subscribes_list = storage.getSubscribesList(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); } if (5 == position) { SalesFragment fragment = new SalesFragment(); fragment.sales = storage.push_sales_list; fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); } mDrawerList.setItemChecked(position, true); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:dev.dworks.apps.anexplorer.fragment.DirectoryFragment.java
private static void show(FragmentManager fm, int type, RootInfo root, DocumentInfo doc, String query, int anim) { final Bundle args = new Bundle(); args.putInt(EXTRA_TYPE, type);// ww w. j av a 2 s . c o m args.putParcelable(EXTRA_ROOT, root); args.putParcelable(EXTRA_DOC, doc); args.putString(EXTRA_QUERY, query); final FragmentTransaction ft = fm.beginTransaction(); switch (anim) { case ANIM_SIDE: args.putBoolean(EXTRA_IGNORE_STATE, true); break; case ANIM_DOWN: args.putBoolean(EXTRA_IGNORE_STATE, true); ft.setCustomAnimations(R.animator.dir_down, R.animator.dir_frozen); break; case ANIM_UP: ft.setCustomAnimations(R.animator.dir_frozen, R.animator.dir_up); break; } final DirectoryFragment fragment = new DirectoryFragment(); fragment.setArguments(args); ft.replace(R.id.container_directory, fragment); ft.commitAllowingStateLoss(); }
From source file:com.example.volunteerhandbook.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (noDrawYet) return true; // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }/*from w ww .ja v a 2 s.com*/ // Handle action buttons closeSpeaker(); ListRecordBase record = (ListRecordBase) mCurrentFragment; int itemId = item.getItemId(); switch (itemId) { case R.id.action_new: case R.id.action_modify: case R.id.action_delete: case R.id.action_check: case R.id.action_save: record.getArguments().putInt(ListRecordBase.ACTION_TYPE, itemId); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.main_content_frame, mCurrentFragment).commit(); break; case R.id.action_join: break; case R.id.action_websearch: // create intent to perform web search for this planet Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getActionBar().getTitle()); // catch event that there's no activity to handle intent if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent); else Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show(); default: super.onOptionsItemSelected(item); } return true; }
From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java
/** * Ricostruisce la successione dei frammenti nell’unico pannello. * /* ww w . j ava 2 s .c o m*/ * @param fragmentMgr Gestore dei frammenti. * @param fragmentQueue Frammenti. * @return Identificatore dell’ultimo elemento inserito * nel back stack. */ private int arrangePanel(FragmentManager fragmentMgr, Queue<FragmentLayoutController.FragmentEntry> fragmentQueue) { int tnId, lastTnId; FragmentLayoutController.FragmentEntry entry; FragmentTransaction fragmentTn = null; lastTnId = -1; while (!fragmentQueue.isEmpty()) { tnId = -1; entry = fragmentQueue.remove(); try { fragmentTn = fragmentMgr.beginTransaction(); fragmentTn.replace(myFrameIds[0], entry.getFragment().asFragment(), entry.getTag()); fragmentTn.addToBackStack(null); } finally { if (fragmentTn != null) { tnId = fragmentTn.commit(); fragmentTn = null; } } if (tnId >= 0) { lastTnId = tnId; } } return lastTnId; }
From source file:com.saarang.samples.apps.iosched.ui.SearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(com.saarang.samples.apps.iosched.R.layout.activity_search); Toolbar toolbar = getActionBarToolbar(); toolbar.setTitle(com.saarang.samples.apps.iosched.R.string.title_search); toolbar.setNavigationIcon(com.saarang.samples.apps.iosched.R.drawable.ic_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override// w ww. j a v a 2 s . co m public void onClick(View view) { navigateUpToFromChild(SearchActivity.this, IntentCompat .makeMainActivity(new ComponentName(SearchActivity.this, BrowseSessionsActivity.class))); } }); FragmentManager fm = getFragmentManager(); mSessionsFragment = (SessionsFragment) fm .findFragmentById(com.saarang.samples.apps.iosched.R.id.fragment_container); String query = getIntent().getStringExtra(SearchManager.QUERY); query = query == null ? "" : query; mQuery = query; if (mSessionsFragment == null) { mSessionsFragment = new SessionsFragment(); Bundle args = intentToFragmentArguments(new Intent("com.saarang.samples.apps.iosched.SESSION_VIEW", ScheduleContract.Sessions.buildSearchUri(query))); mSessionsFragment.setArguments(args); fm.beginTransaction().add(com.saarang.samples.apps.iosched.R.id.fragment_container, mSessionsFragment) .commit(); } if (mSearchView != null) { mSearchView.setQuery(query, false); } overridePendingTransition(0, 0); }
From source file:com.richtodd.android.quiltdesign.app.BlockEditActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_block_edit); getActionBar().setDisplayHomeAsUpEnabled(true); m_blockNameArgument = getIntent().getStringExtra(ARG_BLOCK_NAME); if (savedInstanceState != null) { m_saveAsBlockName = savedInstanceState.getString("saveAsBlockName"); m_theme = (Theme) savedInstanceState.getParcelable("theme"); }//from w w w . j ava 2 s.c om ActionBar ab = getActionBar(); ab.setTitle("Edit Block"); ab.setSubtitle(getCurrentBlockName()); FragmentManager fm = getFragmentManager(); // Create color settings fragment. { Fragment f = fm.findFragmentById(R.id.layout_blockEditFragment); if (f == null) { f = BlockEditFragment.create(m_blockNameArgument); fm.beginTransaction().add(R.id.layout_blockEditFragment, f).commit(); } } m_themeView = (ThemeView) findViewById(R.id.themeView); m_themeView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Swatch swatch = (Swatch) m_themeView.getItemAtPosition(position); BlockEditFragment fragment = getBlockEditFragment(); if (fragment != null) { fragment.setColor(swatch.getColor()); } } }); m_themeView.setTheme(m_theme); m_button_setColor = (Button) findViewById(R.id.button_setColor); m_button_setColor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { chooseColor(); } }); m_button_addPiece = (Button) findViewById(R.id.button_addPiece); m_button_addPiece.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BlockEditFragment fragment = getBlockEditFragment(); int color = fragment.getColor(); PaperPiecedBlockPiece piece = fragment.addPiece(color); onPieceSelected(fragment, piece); } }); m_button_deletePiece = (Button) findViewById(R.id.button_deletePiece); m_button_deletePiece.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BlockEditFragment fragment = getBlockEditFragment(); fragment.deletePiece(); onPieceSelected(fragment, null); } }); ImageView button_refreshTheme = (ImageView) findViewById(R.id.button_refreshTheme); button_refreshTheme.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { refreshTheme(); } }); ImageView button_selectTheme = (ImageView) findViewById(R.id.button_selectTheme); button_selectTheme.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { chooseTheme(); } }); }
From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java
/** Swaps fragments in the main content view */ private void selectItem(int position) { // set fragment title getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); getSupportActionBar().setDisplayShowTitleEnabled(true); mDrawerToggle.setDrawerIndicatorEnabled(true); setTitle(mTitles[position]);//from w ww.j ava 2 s .c o m // Create a new fragment and specify the planet to show based on position switch (position) { case 0: fragment = new MainPrefsFragment(); break; case 1: fragment = new PrefsGeneralFragment(); break; case 2: fragment = new AppearancePreferencesFragment(); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getSupportActionBar().setDisplayShowTitleEnabled(false); break; case 3: fragment = new ServicePreferencesFragment(); break; case 4: if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(WIDGET_PRESENT, false) || isWidgetPlaced()) { fragment = new WidgetSettingsFragment(); } else { fragment = new HowToAddWidgetFragment(); } break; case 5: fragment = new PrefsAppSpecificFragment(); break; case 6: fragment = new BackupRestorePreferenceFragment(); break; case 7: fragment = new PrefsContactFragment(); break; case 8: fragment = new AboutPreferencesFragment(); break; case 9: requestUnlockApp(); return; } // Insert the fragment by replacing any existing fragment FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // Highlight the selected item, update the title, and close the drawer mDrawerList.setItemChecked(position, true); mDrawerLayout.closeDrawer(mDrawerList); }