List of usage examples for android.app FragmentTransaction commit
public abstract int commit();
From source file:org.taulabs.androidgcs.ObjectManagerActivity.java
private void selectItem(int position) { NavDrawerItem selectedItem = navConf.getNavItems()[position]; // Selected item indicates an activity to launch if (selectedItem.getType() == NavMenuActivity.ACTIVITY_TYPE) { NavMenuActivity launcherItem = (NavMenuActivity) selectedItem; if (launcherItem.getLaunchClass() != null) { Log.d(TAG,//w ww. j a v a 2 s. c om "ID: " + selectedItem.getId() + " " + selectedItem.getLabel() + " position: " + position); mDrawerList.setItemChecked(position, true); if (selectedItem.updateActionBarTitle()) { setTitle(selectedItem.getLabel()); } if (this.mDrawerLayout.isDrawerOpen(this.mDrawerList)) { mDrawerLayout.closeDrawer(mDrawerList); } startActivity(new Intent(this, launcherItem.getLaunchClass())); } return; } // Selected item indicates the contents to put in the main frame if (selectedItem.getType() == NavMenuItem.ITEM_TYPE) { if (findViewById(navConf.getMainLayout()) == null) { // If not the new main activity should be activated. // Close drawer first mDrawerList.setItemChecked(position, true); if (this.mDrawerLayout.isDrawerOpen(this.mDrawerList)) { mDrawerLayout.closeDrawer(mDrawerList); } // Activate main activity, indicating the fragment it should show Intent mainScreen = new Intent(this, MainActivity.class); mainScreen.putExtra("ContentFrag", selectedItem.getId()); startActivity(mainScreen); return; } else { int id = (int) selectedItem.getId(); FragmentTransaction trans = getFragmentManager().beginTransaction(); trans.replace(navConf.getMainLayout(), getFragmentById(id)); trans.commit(); mDrawerList.setItemChecked(position, true); if (selectedItem.updateActionBarTitle()) { Log.d(TAG, "Selected item title: " + selectedItem.getLabel()); setTitle(selectedItem.getLabel()); } if (this.mDrawerLayout.isDrawerOpen(this.mDrawerList)) { mDrawerLayout.closeDrawer(mDrawerList); } } } }
From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java
protected void switchToMultipleDevicesFragment() { FragmentTransaction ft = mFragmentManager.beginTransaction(); mContentFragment = AddAccessoryContentFragment.newInstance(true); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.replace(R.id.content_fragment, mContentFragment); ft.disallowAddToBackStack();/*from w ww. j av a 2s . com*/ ft.commit(); mMsgHandler.sendEmptyMessageDelayed(MSG_MULTIPAIR_BLINK, BLINK_START); mShowingMultiFragment = true; }
From source file:com.hit.jj.mapshow.RoutingActivity.java
/** * Clear the graphics and empty the directions list *//*w w w . j a va 2 s .c o m*/ public void clearAll() { mFeatureLayer.removeAll(); //Removing the graphics from the layer routeLayer.removeAll(); hiddenSegmentsLayer.removeAll(); curDirections = new ArrayList<String>(); mResults = null; curRoute = null; //Setting to default text directionsLabel.setText(getString(R.string.route_label)); //Locking the Drawer mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); //Removing the cancel icon img_cancel.setVisibility(View.GONE); //Removing the RoutingListFragment if present FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag("Nav Drawer") != null) { FragmentTransaction ft = fm.beginTransaction(); ft.remove(fm.findFragmentByTag("Nav Drawer")); ft.commit(); } }
From source file:com.google.cloud.solutions.cloudadventure.GameActivity.java
/** * This method is called when the Activity receives a message via {@link BroadcastRecevier} that * the game has started.//from ww w. j a v a 2 s .com */ private void onGameStart() { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.remove(mPreGameFragment); fragmentTransaction.commit(); progressDialog.dismiss(); // Set the starting point for fragments mNavFragment.setNewDirectionMapper(Cardinal.valueOf(mPlayer.getOrientation())); mNavFragment.setCurrentTile(mPlayer.getCurrentTile()); }
From source file:de.sourcestream.movieDB.controller.MovieList.java
/** * Callback method to be invoked when an item in this AdapterView has been clicked. * * @param parent The AdapterView where the click happened. * @param view The view within the AdapterView that was clicked (this will be a view provided by the adapter) * @param position The position of the view in the adapter. * @param id The row id of the item that was clicked. */// w w w.ja v a2s . c o m @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { activity.setLastVisitedSimMovie(0); activity.resetMovieDetailsBundle(); activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); activity.setOrientationChanged(false); activity.resetCastDetailsBundle(); if (movieDetails != null && lastVisitedMovie == moviesList.get(position).getId() && movieDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash movieDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", moviesList.get(position).getId()); Bundle save = movieDetails.getSave(); movieDetails = new MovieDetails(); movieDetails.setTimeOut(0); movieDetails.setSave(save); movieDetails.setArguments(bundle); } else movieDetails = new MovieDetails(); lastVisitedMovie = moviesList.get(position).getId(); movieDetails.setTitle(moviesList.get(position).getTitle()); FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); Bundle bundle = new Bundle(); bundle.putInt("id", moviesList.get(position).getId()); movieDetails.setArguments(bundle); transaction.replace(R.id.frame_container, movieDetails); // add the current transaction to the back stack: transaction.addToBackStack("movieList"); transaction.commit(); fragmentActive = true; activity.getMovieSlideTab().showInstantToolbar(); /* ValueAnimator anim = ValueAnimator.ofFloat(0, 1); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float slideOffset = (Float) valueAnimator.getAnimatedValue(); activity.getmDrawerToggle().onDrawerSlide(activity.getmDrawerLayout(), slideOffset); } }); anim.setInterpolator(new DecelerateInterpolator()); // You can change this duration to more closely match that of the default animation. anim.setDuration(700); anim.start();*/ }
From source file:com.frostwire.android.gui.activities.MainActivity.java
private void hideFragments() { try {/* w w w .j av a 2 s. c o m*/ getFragmentManager().executePendingTransactions(); } catch (Throwable t) { LOG.warn(t.getMessage(), t); } FragmentTransaction tx = getFragmentManager().beginTransaction(); tx.hide(search).hide(library).hide(transfers); try { tx.commit(); } catch (IllegalStateException e) { // if not that we can do a lot here, since the root of the problem // is the multiple entry points to MainActivity, just let it run // a possible inconsistent (but probably right) version. // in the future with a higher API, commitNow should be considered LOG.warn("Error running commit in fragment transaction, using weaker option", e); try { tx.commitAllowingStateLoss(); } catch (IllegalStateException e2) { // \_()_/ LOG.warn( "Error running commit in fragment transaction, weaker option also failed (commit already called - mCommited=true)", e2); } } }
From source file:org.restcomm.android.olympus.CallActivity.java
public void onClick(View view) { if (view.getId() == R.id.button_hangup) { if (pendingConnection != null) { // incoming ringing lblStatus.setText("Rejecting Call..."); pendingConnection.reject();/* ww w . j a va 2 s .c o m*/ pendingConnection = null; } else { if (connection != null) { // incoming established or outgoing any state (pending, connecting, connected) lblStatus.setText("Disconnecting Call..."); connection.disconnect(); connection = null; pendingConnection = null; } else { Log.e(TAG, "Error: not connected/connecting/pending"); } } finish(); } else if (view.getId() == R.id.button_answer) { if (pendingConnection != null) { lblStatus.setText("Answering Call..."); btnAnswer.setVisibility(View.INVISIBLE); btnAnswerAudio.setVisibility(View.INVISIBLE); acceptParams = new HashMap<String, Object>(); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_VIDEO_ENABLED, true); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_LOCAL_VIDEO, (PercentFrameLayout) findViewById(R.id.local_video_layout)); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_REMOTE_VIDEO, (PercentFrameLayout) findViewById(R.id.remote_video_layout)); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_AUDIO_CODEC, audioCodecString2Enum( prefs.getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_AUDIO_CODEC, ""))); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC, videoCodecString2Enum( prefs.getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC, ""))); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_RESOLUTION, resolutionString2Enum(prefs .getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_RESOLUTION, ""))); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_FRAME_RATE, frameRateString2Enum(prefs .getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_FRAME_RATE, ""))); acceptParams.put(RCConnection.ParameterKeys.DEBUG_CONNECTION_CANDIDATE_TIMEOUT, Integer.parseInt( prefs.getString(RCConnection.ParameterKeys.DEBUG_CONNECTION_CANDIDATE_TIMEOUT, "0"))); // Check permissions asynchronously and then accept the call handlePermissions(true); } } else if (view.getId() == R.id.button_answer_audio) { if (pendingConnection != null) { lblStatus.setText("Answering Call..."); btnAnswer.setVisibility(View.INVISIBLE); btnAnswerAudio.setVisibility(View.INVISIBLE); acceptParams = new HashMap<String, Object>(); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_VIDEO_ENABLED, false); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_LOCAL_VIDEO, (PercentFrameLayout) findViewById(R.id.local_video_layout)); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_REMOTE_VIDEO, (PercentFrameLayout) findViewById(R.id.remote_video_layout)); acceptParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_AUDIO_CODEC, audioCodecString2Enum( prefs.getString(RCConnection.ParameterKeys.CONNECTION_PREFERRED_AUDIO_CODEC, ""))); acceptParams.put(RCConnection.ParameterKeys.DEBUG_CONNECTION_CANDIDATE_TIMEOUT, Integer.parseInt( prefs.getString(RCConnection.ParameterKeys.DEBUG_CONNECTION_CANDIDATE_TIMEOUT, "0"))); // Check permissions asynchronously and then accept the call handlePermissions(false); } } else if (view.getId() == R.id.button_keypad) { keypadFragment.setConnection(connection); View rootView = getWindow().getDecorView().findViewById(android.R.id.content); // show keypad FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.show(keypadFragment); ft.commit(); } else if (view.getId() == R.id.button_mute_audio) { if (connection != null) { if (!muteAudio) { btnMuteAudio.setImageResource(R.drawable.audio_muted); } else { btnMuteAudio.setImageResource(R.drawable.audio_unmuted); } muteAudio = !muteAudio; connection.setAudioMuted(muteAudio); } } else if (view.getId() == R.id.button_mute_video) { if (connection != null) { muteVideo = !muteVideo; if (muteVideo) { btnMuteVideo.setImageResource(R.drawable.video_muted); //connection.detachVideo(); } else { btnMuteVideo.setImageResource(R.drawable.video_unmuted); //connection.reattachVideo((PercentFrameLayout)findViewById(R.id.local_video_layout), (PercentFrameLayout)findViewById(R.id.remote_video_layout)); } connection.setVideoMuted(muteVideo); } } }
From source file:us.shandian.blacklight.ui.main.MainActivity.java
private void switchTo(int id) { FragmentTransaction ft = mManager.beginTransaction(); ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out, android.R.animator.fade_in, android.R.animator.fade_out); for (int i = 0; i < mFragments.length; i++) { Fragment f = mFragments[i];// w ww . j a v a 2 s . c o m if (f != null) { if (i != id) { ft.hide(f); } else { ft.show(f); } } } ft.commit(); mCurrent = id; mNext = id; }
From source file:com.benlinskey.greekreference.MainActivity.java
/** * Replaces the currently displayed fragment(s) with the specified fragment(s). * @param listFragment the {@link BaseListFragment} to swap in * @param detailFragment the {@link DetailFragment} to swap in, or null if the app is in * one-pane mode/*from w ww . j av a 2 s.c o m*/ */ private void swapInFragments(Fragment listFragment, Fragment detailFragment) { // TODO: Check for invalid null arguments. if (mTwoPane) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.item_list_container, listFragment); transaction.replace(R.id.item_detail_container, detailFragment); transaction.commit(); } else { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.item_list_container, listFragment); transaction.commit(); } }
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();// ww w . ja v a2 s . c o m 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; } }