Example usage for android.app FragmentTransaction remove

List of usage examples for android.app FragmentTransaction remove

Introduction

In this page you can find the example usage for android.app FragmentTransaction remove.

Prototype

public abstract FragmentTransaction remove(Fragment fragment);

Source Link

Document

Remove an existing fragment.

Usage

From source file:de.mrapp.android.preference.activity.PreferenceActivity.java

/**
 * Removes a specific fragment from its parent view.
 *
 * @param fragment//from   w w w  .ja  va2 s .  c  o m
 *         The fragment, which should be removed, as an instance of the class {@link Fragment}.
 *         The fragment may not be null
 */
private void removeFragment(@NonNull final Fragment fragment) {
    notifyOnPreferenceFragmentHidden();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.remove(fragment);
    transaction.commit();
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

public void showDetailFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.DETAIL);
    this.updateChildViewVisibility(ViewFragmentType.DETAIL);
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.DETAIL, fragmentTransaction);
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    // Try and use the default.
    if (fileName == null) {
        WebLogger.getLogger(getAppName()).d(TAG, "[showDetailFragment] fileName not found in Intent");
        SQLiteDatabase db = null;//  w w w. ja  va2  s .co  m
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getDetailViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    String rowId = IntentUtil.retrieveRowIdFromBundle(this.getIntent().getExtras());
    // Try to retrieve one that already exists.
    DetailViewFragment detailViewFragment = (DetailViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.DETAIL_FRAGMENT);
    if (detailViewFragment == null || createNew) {
        if (detailViewFragment != null) {
            WebLogger.getLogger(getAppName()).d(TAG,
                    "[showDetailViewFragment] removing old detail view fragment");
            fragmentTransaction.remove(detailViewFragment);
        } else {
            WebLogger.getLogger(getAppName()).d(TAG,
                    "[showDetailViewFragment] no existing detail view fragment found");
        }
        detailViewFragment = this.createDetailViewFragment(fileName, rowId);

        fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, detailViewFragment,
                Constants.FragmentTags.DETAIL_FRAGMENT);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG,
                "[showDetailViewFragment] existing detail view fragment found");
        fragmentTransaction.show(detailViewFragment);
    }

    fragmentTransaction.commit();
}

From source file:org.appspot.apprtc.CallActivity.java

@Override
public void onBackPressed() {
    if (chatFragment.isAdded()) {
        // Show in call fragment
        android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.remove(chatFragment);
        ft.commit();/*  w w w .java 2  s  .com*/

    } else {
        super.onBackPressed();
    }
}

From source file:org.appspot.apprtc.CallActivity.java

@Override
public boolean showUserList() {

    userListShown = !userListShown;/* w  w  w.  j  a v  a  2  s.  c  o m*/

    if (userListShown) {
        // Show in call fragment
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(R.id.call_list_fragment_container, callListFragment);
        ft.commit();
    } else {

        // Show in call fragment
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.remove(callListFragment);
        ft.commit();
    }
    return userListShown;
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

private void removeMessageListFragment() {
    if (mMessageViewFragment != null) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.remove(mMessageListFragment);
        mMessageListFragment = null;/*from  w w w  .ja va  2 s.c om*/
        ft.commit();
    }
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

/**
 * Remove MessageViewFragment if necessary.
 *///www.ja  v  a 2 s.c o m
private void removeMessageViewFragment() {
    if (mMessageViewFragment != null) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.remove(mMessageViewFragment);
        mMessageViewFragment = null;
        ft.commit();

        showDefaultTitleView();
    }
}

From source file:com.android.calendar.AllInOneActivity.java

private void setMainPane(FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
    if (mOnSaveInstanceStateCalled) {
        return;//from w w w .  j a  v  a 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();
    }
}