List of usage examples for android.app FragmentTransaction replace
public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment);
From source file:de.sourcestream.movieDB.controller.SearchList.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. *//*from ww w .jav a2 s .c om*/ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); boolean result; Bundle args; switch (searchList.get(position).getMediaType()) { case "movie": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (movieDetails != null && lastVisitedId == searchList.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", searchList.get(position).getId()); Bundle save = movieDetails.getSave(); movieDetails = new MovieDetails(); movieDetails.setTimeOut(0); movieDetails.setSave(save); movieDetails.setArguments(bundle); } else movieDetails = new MovieDetails(); args = new Bundle(); args.putInt("id", searchList.get(position).getId()); movieDetails.setArguments(args); movieDetails.setTitle(searchList.get(position).getTitle()); transaction.replace(R.id.frame_container, movieDetails); result = true; break; case "person": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (castDetails != null && lastVisitedId == searchList.get(position).getId() && castDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash castDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", searchList.get(position).getId()); Bundle save = castDetails.getSave(); castDetails = new CastDetails(); castDetails.setTimeOut(0); castDetails.setSave(save); castDetails.setArguments(bundle); } else castDetails = new CastDetails(); args = new Bundle(); args.putInt("id", searchList.get(position).getId()); castDetails.setArguments(args); castDetails.setTitle(searchList.get(position).getTitle()); transaction.replace(R.id.frame_container, castDetails); result = true; break; case "tv": activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); if (tvDetails != null && lastVisitedId == searchList.get(position).getId() && tvDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash tvDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", searchList.get(position).getId()); Bundle save = tvDetails.getSave(); tvDetails = new TVDetails(); tvDetails.setTimeOut(0); tvDetails.setSave(save); tvDetails.setArguments(bundle); } else tvDetails = new TVDetails(); args = new Bundle(); args.putInt("id", searchList.get(position).getId()); tvDetails.setArguments(args); tvDetails.setTitle(searchList.get(position).getTitle()); transaction.replace(R.id.frame_container, tvDetails); result = true; break; default: result = false; break; } lastVisitedId = searchList.get(position).getId(); if (result) { // add the current transaction to the back stack: transaction.addToBackStack("movieList"); transaction.commit(); // collapse the search View ((MainActivity) getActivity()).collapseSearchView(); } }
From source file:co.taqat.call.LinphoneActivity.java
private void changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) { if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) { if (newFragmentType == FragmentsAvailable.DIALER) { showStatusBar();/*from w w w . j ava 2s . c om*/ } else { hideStatusBar(); } } emptyFragment = false; LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2); FragmentTransaction transaction = getFragmentManager().beginTransaction(); if (newFragmentType == FragmentsAvailable.EMPTY) { ll.setVisibility(View.VISIBLE); emptyFragment = true; transaction.replace(R.id.fragmentContainer2, newFragment); transaction.commitAllowingStateLoss(); getFragmentManager().executePendingTransactions(); } else { if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) { ll.setVisibility(View.VISIBLE); if (newFragmentType == FragmentsAvailable.CONTACT_EDITOR) { transaction.addToBackStack(newFragmentType.toString()); } transaction.replace(R.id.fragmentContainer2, newFragment); } else { if (newFragmentType == FragmentsAvailable.EMPTY) { ll.setVisibility(View.VISIBLE); transaction.replace(R.id.fragmentContainer2, new EmptyFragment()); emptyFragment = true; } if (newFragmentType == FragmentsAvailable.DIALER || newFragmentType == FragmentsAvailable.ABOUT || newFragmentType == FragmentsAvailable.SETTINGS || newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) { ll.setVisibility(View.GONE); } else { ll.setVisibility(View.VISIBLE); transaction.replace(R.id.fragmentContainer2, new EmptyFragment()); } /*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) { if (newFragmentType.isRightOf(currentFragment)) { transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right); } else { transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right, R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left); } }*/ transaction.replace(R.id.fragmentContainer, newFragment); } transaction.commitAllowingStateLoss(); getFragmentManager().executePendingTransactions(); currentFragment = newFragmentType; if (newFragmentType == FragmentsAvailable.DIALER || newFragmentType == FragmentsAvailable.SETTINGS || newFragmentType == FragmentsAvailable.CONTACTS_LIST || newFragmentType == FragmentsAvailable.CHAT_LIST || newFragmentType == FragmentsAvailable.HISTORY_LIST) { try { getFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); } catch (java.lang.IllegalStateException e) { } } fragmentsHistory.add(currentFragment); } }
From source file:org.path.episample.android.activities.MainMenuActivity.java
public void swapToFragmentView(ScreenList newFragment) { WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView: " + newFragment.toString()); String get = PropertiesSingleton.getProperty("survey", AdminPreferencesActivity.KEY_TURN_ON_OFF_WIFI_AUTOMATICALLY); if (!(get != null && get.equalsIgnoreCase("false"))) { if (mWifiManager.isWifiEnabled() && mWifiManager.getWifiState() != WifiManager.WIFI_STATE_DISABLED) { mWifiManager.setWifiEnabled(false); }//from w w w .j a v a2 s .c om } FragmentManager mgr = getFragmentManager(); Fragment f; if (newFragment == ScreenList.MAIN_SCREEN) { throw new IllegalStateException("unexpected reference to generic main screen"); } else if (newFragment == ScreenList.CUSTOM_VIEW) { WebLogger.getLogger(getAppName()).w(t, "swapToFragmentView: changing navigation to move to WebKit (was custom view)"); f = mgr.findFragmentById(WebViewFragment.ID); if (f == null) { f = new WebViewFragment(); } newFragment = ScreenList.WEBKIT; } else if (newFragment == ScreenList.MAIN_MENU) { f = mgr.findFragmentById(MainMenuFragment.ID); if (f == null) { f = new MainMenuFragment(); } } else if (newFragment == ScreenList.COLLECT_MODULE) { f = mgr.findFragmentById(CollectFragment.ID); if (f == null) { f = new CollectFragment(); } } else if (newFragment == ScreenList.SEND_RECEIVE_WIFI_DIRECT_MODULE) { f = mgr.findFragmentById(SendReceiveFragment.ID); if (f == null) { f = new SendReceiveFragment(); } } /*else if (newFragment == ScreenList.SEND_RECEIVE_BLUETOOTH_MODULE) { f = mgr.findFragmentById(SendReceiveFragmentBT.ID); if (f == null) { f = new SendReceiveFragmentBT(); } }*/ else if (newFragment == ScreenList.SELECT_MODULE) { f = mgr.findFragmentById(SelectFragment.ID); if (f == null) { f = new SelectFragment(); } } else if (newFragment == ScreenList.NAVIGATE_MODULE) { f = mgr.findFragmentById(NavigateFragment.ID); if (f == null) { f = new NavigateFragment(); } } else if (newFragment == ScreenList.RESTORE_MODULE) { f = mgr.findFragmentById(RestoreFragment.ID); if (f == null) { f = new RestoreFragment(); } } else if (newFragment == ScreenList.EDIT_CENSUS_MODULE) { f = mgr.findFragmentById(EditCensusFragment.ID); if (f == null) { f = new EditCensusFragment(); } } else if (newFragment == ScreenList.REMOVE_CENSUS_MODULE) { f = mgr.findFragmentById(RemoveCensusFragment.ID); if (f == null) { f = new RemoveCensusFragment(); } } else if (newFragment == ScreenList.INVALIDATE_CENSUS_MODULE) { f = mgr.findFragmentById(InvalidateCensusFragment.ID); if (f == null) { f = new InvalidateCensusFragment(); } } else if (newFragment == ScreenList.FORM_CHOOSER) { f = mgr.findFragmentById(FormChooserListFragment.ID); if (f == null) { f = new FormChooserListFragment(); } } else if (newFragment == ScreenList.INITIALIZATION_DIALOG) { if (currentFragment == ScreenList.INITIALIZATION_DIALOG) { WebLogger.getLogger(getAppName()).e(t, "Unexpected: currentFragment == INITIALIZATION_DIALOG"); return; } else { f = mgr.findFragmentById(InitializationFragment.ID); if (f == null) { f = new InitializationFragment(); } ((InitializationFragment) f).setFragmentToShowNext( (currentFragment == null) ? ScreenList.FORM_CHOOSER.name() : currentFragment.name()); } } else if (newFragment == ScreenList.FORM_DELETER) { f = mgr.findFragmentById(FormDeleteListFragment.ID); if (f == null) { f = new FormDeleteListFragment(); } } else if (newFragment == ScreenList.FORM_DOWNLOADER) { f = mgr.findFragmentById(FormDownloadListFragment.ID); if (f == null) { f = new FormDownloadListFragment(); } } else if (newFragment == ScreenList.INSTANCE_UPLOADER_TABLE_CHOOSER) { f = mgr.findFragmentById(InstanceUploaderTableChooserListFragment.ID); if (f == null) { f = new InstanceUploaderTableChooserListFragment(); } } else if (newFragment == ScreenList.INSTANCE_UPLOADER) { f = mgr.findFragmentById(InstanceUploaderListFragment.ID); if (f == null) { f = new InstanceUploaderListFragment(); } ((InstanceUploaderListFragment) f).changeUploadTableId(); } else if (newFragment == ScreenList.WEBKIT) { f = mgr.findFragmentById(WebViewFragment.ID); if (f == null) { f = new WebViewFragment(); } } else if (newFragment == ScreenList.ABOUT_MENU) { f = mgr.findFragmentById(AboutMenuFragment.ID); if (f == null) { f = new AboutMenuFragment(); } } else { throw new IllegalStateException("Unrecognized ScreenList type"); } FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content); View frags = findViewById(R.id.main_content); View wkt = findViewById(R.id.webkit_view); shadow.setVisibility(View.GONE); shadow.removeAllViews(); if (newFragment == ScreenList.WEBKIT) { frags.setVisibility(View.GONE); wkt.setVisibility(View.VISIBLE); wkt.invalidate(); } else { wkt.setVisibility(View.GONE); frags.setVisibility(View.VISIBLE); } currentFragment = newFragment; BackStackEntry entry = null; for (int i = 0; i < mgr.getBackStackEntryCount(); ++i) { BackStackEntry e = mgr.getBackStackEntryAt(i); if (e.getName().equals(currentFragment.name())) { entry = e; break; } } if (entry != null) { // flush backward, including the screen want to go back to mgr.popBackStackImmediate(currentFragment.name(), FragmentManager.POP_BACK_STACK_INCLUSIVE); } // add transaction to show the screen we want FragmentTransaction trans = mgr.beginTransaction(); trans.replace(R.id.main_content, f); trans.addToBackStack(currentFragment.name()); trans.commit(); // and see if we should re-initialize... if ((currentFragment != ScreenList.INITIALIZATION_DIALOG) && Survey.getInstance().shouldRunInitializationTask(getAppName())) { WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView -- calling clearRunInitializationTask"); // and immediately clear the should-run flag... Survey.getInstance().clearRunInitializationTask(getAppName()); // OK we should swap to the InitializationFragment view swapToFragmentView(ScreenList.INITIALIZATION_DIALOG); } else { levelSafeInvalidateOptionsMenu(); } }
From source file:de.mrapp.android.preference.activity.PreferenceActivity.java
/** * Replaces the fragment, which is currently contained by a specific parent view, by an other * fragment./*from w ww . j av a2 s. co m*/ * * @param fragment * The fragment, which should replace the current fragment, as an instance of the class * {@link Fragment}. The fragment may not be null * @param parentViewId * The id of the parent view, which contains the fragment, that should be replaced, as * an {@link Integer} value * @param transition * The transition, which should be shown when replacing the fragment, as an {@link * Integer} value or 0, if no transition should be shown */ private void replaceFragment(@NonNull final Fragment fragment, final int parentViewId, final int transition) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.setTransition(transition); transaction.replace(parentViewId, fragment); transaction.commit(); }
From source file:org.appspot.apprtc.CallActivity.java
@Override public void onStartConferenceCall(User user) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.call_fragment_container, callFragment); ft.commit();/*from ww w.j a v a 2 s . com*/ if (!mVideoCallEnabled) { remoteUserImage.setVisibility(View.VISIBLE); } callUser(user); updateVideoView(); if (mLocalSdp == null) { mWaitingToStartCall = true; } else { StartCall(mPeerId); } }
From source file:org.appspot.apprtc.CallActivity.java
@Override public void onAnswerCall() { AnswerIncomingCall(mPeerId);// w w w . j a v a2 s . c o m FragmentTransaction ft = getFragmentManager().beginTransaction(); if (!mVideoCallEnabled) { ft.add(R.id.call_list_fragment_container, callListFragment); } ft.replace(R.id.call_fragment_container, callFragment); ft.commit(); if (!mVideoCallEnabled) { remoteUserImage.setVisibility(View.VISIBLE); } }
From source file:org.appspot.apprtc.CallActivity.java
@Override public void onRemoteDescription(final SerializableSessionDescription sdp, final String token, String id, String conferenceId, final String fromId, final String roomName, String type) { final long delta = System.currentTimeMillis() - callStartedTimeMs; runOnUiThread(new Runnable() { @Override/*from w w w . j a v a 2s.c om*/ public void run() { if (peerConnectionClient == null) { Log.e(TAG, "Received remote SDP for non-initilized peer connection."); return; } //logAndToast("Received remote " + sdp.type + ", delay=" + delta + "ms"); SessionDescription sd = new SessionDescription(sdp.type, sdp.description); peerConnectionClient.setRemoteDescription(sd, token); if (!initiator) { //logAndToast("Creating ANSWER..."); // Create answer. Answer SDP will be sent to offering client in // PeerConnectionEvents.onLocalDescription event. peerConnectionClient.createAnswer(); } else if (sd.type == SessionDescription.Type.OFFER) { // tried to call SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); fmt.setTimeZone(TimeZone.getTimeZone("GMT")); String time = fmt.format(new Date()); String missedCall = String.format(getString(R.string.missed_call), mPeerName); mService.onChatMessage(missedCall, time, "", mOwnId, mPeerId, roomName); sendBye(fromId, "busy"); onCallHangUp(); } else { // Show in call fragment FragmentTransaction ft = getFragmentManager().beginTransaction(); if (!mVideoCallEnabled) { ft.add(R.id.call_list_fragment_container, callListFragment); } ft.replace(R.id.call_fragment_container, callFragment); ft.commit(); if (!mVideoCallEnabled) { remoteUserImage.setVisibility(View.VISIBLE); } } } }); }
From source file:com.android.calendar.AllInOneActivity.java
private void setMainPane(FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) { if (mOnSaveInstanceStateCalled) { return;// w ww .j ava 2 s . c o m } if (!force && mCurrentView == viewType) { return; } // Remove this when transition to and from month view looks fine. boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH; FragmentManager fragmentManager = getFragmentManager(); // Check if our previous view was an Agenda view // TODO remove this if framework ever supports nested fragments if (mCurrentView == ViewType.AGENDA) { // If it was, we need to do some cleanup on it to prevent the // edit/delete buttons from coming back on a rotation. Fragment oldFrag = fragmentManager.findFragmentById(viewId); if (oldFrag instanceof AgendaFragment) { ((AgendaFragment) oldFrag).removeFragments(fragmentManager); } } if (viewType != mCurrentView) { // The rules for this previous view are different than the // controller's and are used for intercepting the back button. if (mCurrentView != ViewType.EDIT && mCurrentView > 0) { mPreviousView = mCurrentView; } mCurrentView = viewType; } // Create new fragment Fragment frag = null; Fragment secFrag = null; switch (viewType) { case ViewType.AGENDA: mNavigationView.getMenu().findItem(R.id.agenda_menu_item).setChecked(true); frag = new AgendaFragment(timeMillis, false); if (mIsTabletConfig) { mToolbar.setTitle(R.string.agenda_view); } break; case ViewType.DAY: mNavigationView.getMenu().findItem(R.id.day_menu_item).setChecked(true); frag = new DayFragment(timeMillis, 1); if (mIsTabletConfig) { mToolbar.setTitle(R.string.day_view); } break; case ViewType.MONTH: mNavigationView.getMenu().findItem(R.id.month_menu_item).setChecked(true); frag = new MonthByWeekFragment(timeMillis, false); if (mShowAgendaWithMonth) { secFrag = new AgendaFragment(timeMillis, false); } if (mIsTabletConfig) { mToolbar.setTitle(R.string.month_view); } break; case ViewType.WEEK: default: mNavigationView.getMenu().findItem(R.id.week_menu_item).setChecked(true); frag = new DayFragment(timeMillis, Utils.getDaysPerWeek(this)); if (mIsTabletConfig) { mToolbar.setTitle(R.string.week_view); } break; } // Update the current view so that the menu can update its look according to the // current view. if (mCalendarToolbarHandler != null) { mCalendarToolbarHandler.setCurrentMainView(viewType); } if (!mIsTabletConfig) { refreshActionbarTitle(timeMillis); } // Show date only on tablet configurations in views different than Agenda if (!mIsTabletConfig) { mDateRange.setVisibility(View.GONE); } else if (viewType != ViewType.AGENDA) { mDateRange.setVisibility(View.VISIBLE); } else { mDateRange.setVisibility(View.GONE); } // Clear unnecessary buttons from the option menu when switching from the agenda view if (viewType != ViewType.AGENDA) { clearOptionsMenu(); } boolean doCommit = false; if (ft == null) { doCommit = true; ft = fragmentManager.beginTransaction(); } if (doTransition) { ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); } ft.replace(viewId, frag); if (mShowAgendaWithMonth) { // Show/hide secondary fragment if (secFrag != null) { ft.replace(R.id.secondary_pane, secFrag); mSecondaryPane.setVisibility(View.VISIBLE); } else { mSecondaryPane.setVisibility(View.GONE); Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane); if (f != null) { ft.remove(f); } mController.deregisterEventHandler(R.id.secondary_pane); } } if (DEBUG) { Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType); } // If the key is already registered this will replace it mController.registerEventHandler(viewId, (EventHandler) frag); if (secFrag != null) { mController.registerEventHandler(viewId, (EventHandler) secFrag); } if (doCommit) { if (DEBUG) { Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing()); } ft.commit(); } }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
private void addMessageListFragment(MessageListFragment fragment, boolean addToBackStack) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.message_list_container, fragment); if (addToBackStack) ft.addToBackStack(null);/*from w w w.j a va 2 s . c o m*/ mMessageListFragment = fragment; int transactionId = ft.commit(); if (transactionId >= 0 && mFirstBackStackId < 0) { mFirstBackStackId = transactionId; } }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
@Override public void openMessage(MessageReference messageReference) { Preferences prefs = Preferences.getPreferences(getApplicationContext()); Account account = prefs.getAccount(messageReference.accountUuid); String folderName = messageReference.folderName; if (folderName.equals(account.getDraftsFolderName())) { MessageCompose.actionEditDraft(this, messageReference); } else {//from www .ja va 2 s . c o m mMessageViewContainer.removeView(mMessageViewPlaceHolder); if (mMessageListFragment != null) { mMessageListFragment.setActiveMessage(messageReference); } MessageViewFragment fragment = MessageViewFragment.newInstance(messageReference); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.message_view_container, fragment); mMessageViewFragment = fragment; ft.commit(); if (mDisplayMode != DisplayMode.SPLIT_VIEW) { showMessageView(); } } }