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:com.concentricsky.android.khanacademy.app.VideoDetailActivity.java

private void goFullscreen(boolean force) {
    isFullscreen = true;//from  ww  w.  j a v  a 2  s.c o  m
    setRequestedOrientation(force ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
            : ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

    VideoController videoControls = (VideoController) findViewById(R.id.controller);
    if (videoControls != null) {
        videoControls.setFullscreen(true);
    }

    ThumbnailWrapper videoContainer = (ThumbnailWrapper) findViewById(R.id.video_fragment_container);
    videoContainer.setMaintainAspectRatio(false);

    if (captionFragment != null) {
        FragmentTransaction tx = getFragmentManager().beginTransaction();
        tx.remove(captionFragment);
        tx.commit();
    }
    findViewById(R.id.detail_bottom_container).setVisibility(View.GONE);
    if (isBigScreen) {
        findViewById(R.id.detail_right_container).setVisibility(View.GONE);
        findViewById(R.id.detail_center_divider).setVisibility(View.GONE);
    }

    setNavVisibility(videoFragment == null || !videoFragment.isPlaying());

    getDecorViewTreeObserver().addOnGlobalLayoutListener(layoutFixer);
}

From source file:com.concentricsky.android.khanacademy.app.VideoDetailActivity.java

private void createAndAttachCaptionFragment(int containerId) {
    FragmentTransaction tx = getFragmentManager().beginTransaction();

    if (captionFragment != null) {
        tx.remove(captionFragment);
    }//from  www.j a  v  a2 s .c o m

    captionFragment = new CaptionFragment();
    Bundle args = new Bundle();
    if (video != null) {
        args.putString(Constants.PARAM_VIDEO_ID, video.getId());
        if (videoFragment != null) {
            args.putInt(PARAM_VIDEO_POSITION, videoFragment.getVideoPosition());
        }
    }
    // Set args even if empty to avoid possible NPE inside CaptionFragment.
    captionFragment.setArguments(args);
    captionFragment.registerCallbacks(this);

    tx.replace(containerId, captionFragment);
    tx.commit();
    // Force execute, so we can populateHeader afterward.
    getFragmentManager().executePendingTransactions();
}

From source file:com.chen.mail.ui.OnePaneController.java

@Override
protected void showConversation(Conversation conversation, boolean inLoaderCallbacks) {
    super.showConversation(conversation, inLoaderCallbacks);
    mConversationListVisible = false;//from   w w w  .  j  a v  a  2s . c o m
    if (conversation == null) {
        transitionBackToConversationListMode();
        return;
    }
    disableCabMode();
    if (ConversationListContext.isSearchResult(mConvListContext)) {
        mViewMode.enterSearchResultsConversationMode();
    } else {
        mViewMode.enterConversationMode();
    }
    final FragmentManager fm = mActivity.getFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    // Switching to conversation view is an incongruous transition:
    // we are not replacing a fragment with another fragment as
    // usual. Instead, reveal the heretofore inert conversation
    // ViewPager and just remove the previously visible fragment
    // e.g. conversation list, or possibly label list?).
    final Fragment f = fm.findFragmentById(R.id.content_pane);
    // FragmentManager#findFragmentById can return fragments that are not added to the activity.
    // We want to make sure that we don't attempt to remove fragments that are not added to the
    // activity, as when the transaction is popped off, the FragmentManager will attempt to
    // readd the same fragment twice
    if (f != null && f.isAdded()) {
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.remove(f);
        ft.commitAllowingStateLoss();
        fm.executePendingTransactions();
    }
    mPagerController.show(mAccount, mFolder, conversation, true /* changeVisibility */);
    onConversationVisibilityChanged(true);
    onConversationListVisibilityChanged(false);
}

From source file:org.iota.wallet.ui.activity.MainActivity.java

/**
 * Shows a fragment and hides the old one if there was a fragment previously visible
 *//*from ww  w .  ja va2  s . c om*/
private void showFragment(Fragment fragment, boolean addToBackStack, boolean killFragments) {

    if (fragment == null) {
        // Do nothing
        return;
    }

    FragmentManager fragmentManager = getFragmentManager();
    Fragment currentFragment = fragmentManager.findFragmentByTag(currentFragmentTag);

    if (currentFragment != null && currentFragment.getClass().getName().equals(fragment.getClass().getName())) {
        // Fragment already shown, do nothing
        return;
    }

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();

    if (killFragments) {
        Class[] fragmentsToKill = { AboutFragment.class, GenerateQRCodeFragment.class, NeighborsFragment.class,
                NodeInfoFragment.class, PasswordLoginFragment.class, QRScannerFragment.class,
                SeedLoginFragment.class, SettingsFragment.class, TangleExplorerTabFragment.class,
                NewTransferFragment.class, WalletAddressesFragment.class, WalletTabFragment.class,
                WalletTransfersFragment.class };
        for (Class fragmentClass : fragmentsToKill) {
            String tag = fragmentClass.getSimpleName();
            if (tag.equals(fragment.getClass().getSimpleName())) {
                continue;
            }
            Fragment fragmentToKill = fragmentManager.findFragmentByTag(tag);
            if (fragmentToKill != null) {
                fragmentTransaction.remove(fragmentToKill);
            }
        }
    }

    fragmentTransaction.setCustomAnimations(R.animator.fade_in, R.animator.fade_out, R.animator.fade_in,
            R.animator.fade_out);

    if (currentFragment != null) {
        // Hide old fragment
        fragmentTransaction.hide(currentFragment);
    }

    String tag = fragment.getClass().getSimpleName();
    Fragment cachedFragment = fragmentManager.findFragmentByTag(tag);
    if (cachedFragment != null) {
        // Cached fragment available
        fragmentTransaction.show(cachedFragment);
    } else {
        fragmentTransaction.add(FRAGMENT_CONTAINER_ID, fragment, tag);
    }
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(null);
    }
    fragmentTransaction.commit();

    if (fragment instanceof OnBackPressedClickListener) {
        onBackPressedClickListener = (OnBackPressedClickListener) fragment;
    } else
        onBackPressedClickListener = null;

    // setChecked if open from WalletItemDialog
    if (fragment instanceof TangleExplorerTabFragment)
        navigationView.getMenu().findItem(R.id.nav_tangle_explorer).setChecked(true);

    currentFragmentTag = tag;
}

From source file:com.android.dialer.DialtactsActivity.java

/**
 * Hides the search fragment// w  w w  .j a  va  2  s  .  c  o  m
 */
private void exitSearchUi() {
    // See related bug in enterSearchUI();
    if (getFragmentManager().isDestroyed() || mStateSaved) {
        return;
    }

    mSearchView.setText(null);

    if (mDialpadFragment != null) {
        mDialpadFragment.clearDialpad();
    }

    setNotInSearchUi();

    // Restore the FAB for the lists fragment.
    if (getFabAlignment() != FloatingActionButtonController.ALIGN_END) {
        mFloatingActionButtonController.setVisible(false);
    }
    mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS);
    onPageScrolled(mListsFragment.getCurrentTabIndex(), 0 /* offset */, 0 /* pixelOffset */);
    onPageSelected(mListsFragment.getCurrentTabIndex());

    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (mSmartDialSearchFragment != null) {
        transaction.remove(mSmartDialSearchFragment);
    }
    if (mRegularSearchFragment != null) {
        transaction.remove(mRegularSearchFragment);
    }
    transaction.commit();

    mListsFragment.getView().animate().alpha(1).withLayer();

    if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
        // If the dialpad fragment wasn't previously visible, then send a screen view because
        // we are exiting regular search. Otherwise, the screen view will be sent by
        // {@link #hideDialpadFragment}.
        mListsFragment.sendScreenViewForCurrentPosition();
        mListsFragment.setUserVisibleHint(true);
    }

    mActionBarController.onSearchUiExited();
}

From source file:com.tct.mail.ui.OnePaneController.java

@Override
protected void showConversation(Conversation conversation) {
    super.showConversation(conversation);
    // TS: tao.gan 2015-09-21 EMAIL FEATURE-559893 ADD_S
    //we change from ConversationListFragment to ConversationViewFragment, should let the toolbar show
    animateShow(null);/*  w w w  .  ja v a  2 s .com*/
    // TS: tao.gan 2015-09-21 EMAIL FEATURE-559893 ADD_E
    mConversationListVisible = false;
    if (conversation == null) {
        transitionBackToConversationListMode();
        return;
    }
    disableCabMode();
    if (ConversationListContext.isSearchResult(mConvListContext)) {
        mViewMode.enterSearchResultsConversationMode();
    } else {
        mViewMode.enterConversationMode();
    }
    final FragmentManager fm = mActivity.getFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    // Switching to conversation view is an incongruous transition:
    // we are not replacing a fragment with another fragment as
    // usual. Instead, reveal the heretofore inert conversation
    // ViewPager and just remove the previously visible fragment
    // e.g. conversation list, or possibly label list?).
    final Fragment f = fm.findFragmentById(R.id.content_pane);
    // FragmentManager#findFragmentById can return fragments that are not added to the activity.
    // We want to make sure that we don't attempt to remove fragments that are not added to the
    // activity, as when the transaction is popped off, the FragmentManager will attempt to
    // readd the same fragment twice
    if (f != null && f.isAdded()) {
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.remove(f);
        ft.commitAllowingStateLoss();
        //TS: jin.dong 2015-8-28 EMAIL BUGFIX-1075110 MOD_S
        try {
            fm.executePendingTransactions();
        } catch (IllegalArgumentException e) {
            LogUtils.d(LOG_TAG, e, "IllegalArgumentException occurred");
        }
        //TS: jin.dong 2015-8-28 EMAIL BUGFIX-1075110 MOD_E
    }
    mPagerController.show(mAccount, mFolder, conversation, true /* changeVisibility */);
    onConversationVisibilityChanged(true);
    onConversationListVisibilityChanged(false);
}

From source file:com.android.dialer.DialtactsActivity.java

/**
 * Shows the search fragment//from  w w  w .ja  v  a  2 s .  c om
 */
private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
    if (mStateSaved || getFragmentManager().isDestroyed()) {
        // Weird race condition where fragment is doing work after the activity is destroyed
        // due to talkback being on (b/10209937). Just return since we can't do any
        // constructive here.
        return;
    }

    if (DEBUG) {
        Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
    }

    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (mInDialpadSearch && mSmartDialSearchFragment != null) {
        transaction.remove(mSmartDialSearchFragment);
    } else if (mInRegularSearch && mRegularSearchFragment != null) {
        transaction.remove(mRegularSearchFragment);
    }

    final String tag;
    if (smartDialSearch) {
        tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
    } else {
        tag = TAG_REGULAR_SEARCH_FRAGMENT;
    }
    mInDialpadSearch = smartDialSearch;
    mInRegularSearch = !smartDialSearch;

    mFloatingActionButtonController.scaleOut();

    SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
    if (animate) {
        transaction.setCustomAnimations(android.R.animator.fade_in, 0);
    } else {
        transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
    }
    if (fragment == null) {
        if (smartDialSearch) {
            fragment = new SmartDialSearchFragment();
        } else {
            fragment = ObjectFactory.newRegularSearchFragment();
            fragment.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // Show the FAB when the user touches the lists fragment and the soft
                    // keyboard is hidden.
                    hideDialpadFragment(true, false);
                    showFabInSearchUi();
                    return false;
                }
            });
        }
        transaction.add(R.id.dialtacts_frame, fragment, tag);
    } else {
        transaction.show(fragment);
    }
    // DialtactsActivity will provide the options menu
    fragment.setHasOptionsMenu(false);
    fragment.setShowEmptyListForNullQuery(true);
    if (!smartDialSearch) {
        fragment.setQueryString(query, false /* delaySelection */);
    }
    transaction.commit();

    if (animate) {
        mListsFragment.getView().animate().alpha(0).withLayer();
    }
    mListsFragment.setUserVisibleHint(false);

    if (smartDialSearch) {
        Logger.logScreenView(ScreenEvent.SMART_DIAL_SEARCH, this);
    } else {
        Logger.logScreenView(ScreenEvent.REGULAR_SEARCH, this);
    }
}

From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java

/**
 * Ricostruisce la successione della disposizione dei frammenti nei
 * pannelli.//from w w  w .  j a va 2s  .  c o m
 * 
 * @param  fragmentMgr   Gestore dei frammenti.
 * @param  fragmentQueue Frammenti.
 * @return               Identificatore dell’ultimo elemento inserito
 *                       nel back stack.
 */
private int arrangeFragments(FragmentManager fragmentMgr,
        Queue<FragmentLayoutController.FragmentEntry> fragmentQueue) {
    int i;
    int frameCount, tnId, lastTnId;
    FragmentLayoutController.FragmentEntry entry;
    FragmentSupport newFragment, oldFragment;
    FragmentLayoutController.FragmentEntry[] frames;
    FragmentTransaction fragmentTn = null;

    frameCount = 1;
    frames = new FragmentLayoutController.FragmentEntry[myFrameCount];
    Arrays.fill(frames, null);

    lastTnId = -1;
    while (!fragmentQueue.isEmpty()) {
        tnId = -1;
        entry = fragmentQueue.remove();

        try {
            fragmentTn = fragmentMgr.beginTransaction();

            if (frameCount == myFrameCount) {
                // Tutti i pannelli sono occupati:
                // Sposto ogni frammento nel pannello precedente per
                // liberare l'ultimo.
                for (i = 0; i < frameCount; i++) {
                    if (frames[i] == null) {
                        // Inizialmente il primo pannello risulta vuoto
                        // anche se in realta' e' occupato dal frammento
                        // principale (non di dettaglio).
                        continue;
                    }

                    oldFragment = frames[i].getFragment();
                    newFragment = (i > 0) ? oldFragment.cloneFragment() : null;
                    fragmentTn.remove(oldFragment.asFragment());
                    frames[i] = null;

                    if (newFragment != null) {
                        fragmentTn.replace(myFrameIds[i - 1], newFragment.asFragment(), entry.getTag());
                        frames[i - 1] = new FragmentLayoutController.FragmentEntry(newFragment, entry.getTag());
                    }
                }

                frameCount--;
            }

            fragmentTn.add(myFrameIds[frameCount], entry.getFragment().asFragment(), entry.getTag());
            frames[frameCount++] = entry;

            fragmentTn.addToBackStack(null);
        } finally {
            if (fragmentTn != null) {
                tnId = fragmentTn.commit();
                fragmentTn = null;
            }
        }

        if (tnId >= 0) {
            lastTnId = tnId;
        }
    }

    return lastTnId;
}

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

@Override
public void handleEvent(EventInfo event) {
    long displayTime = -1;
    if (event.eventType == EventType.GO_TO) {
        if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
            mBackToPreviousView = true;//from w w w .  jav a  2 s  .com
        } else if (event.viewType != mController.getPreviousViewType() && event.viewType != ViewType.EDIT) {
            // Clear the flag is change to a different view type
            mBackToPreviousView = false;
        }

        setMainPane(null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
        if (mSearchView != null) {
            mSearchView.clearFocus();
        }
        if (mShowCalendarControls) {
            int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? mControlsAnimateWidth
                    : mControlsAnimateHeight;
            boolean noControlsView = event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA;
            if (mControlsMenu != null) {
                mControlsMenu.setVisible(!noControlsView);
                mControlsMenu.setEnabled(!noControlsView);
            }
            if (noControlsView || mHideControls) {
                // hide minimonth and calendar frag
                mShowSideViews = false;
                if (!mHideControls) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", 0,
                            animationSize);
                    slideAnimation.addListener(mSlideAnimationDoneListener);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                } else {
                    mMiniMonth.setVisibility(View.GONE);
                    mCalendarsList.setVisibility(View.GONE);
                    mMiniMonthContainer.setVisibility(View.GONE);
                }
            } else {
                // show minimonth and calendar frag
                mShowSideViews = true;
                mMiniMonth.setVisibility(View.VISIBLE);
                mCalendarsList.setVisibility(View.VISIBLE);
                mMiniMonthContainer.setVisibility(View.VISIBLE);
                if (!mHideControls && (mController.getPreviousViewType() == ViewType.MONTH
                        || mController.getPreviousViewType() == ViewType.AGENDA)) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
                            animationSize, 0);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                }
            }
        }
        displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true)
                : event.startTime.toMillis(true);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(displayTime);
        }
    } else if (event.eventType == EventType.VIEW_EVENT) {

        // If in Agenda view and "show_event_details_with_agenda" is "true",
        // do not create the event info fragment here, it will be created by the Agenda
        // fragment

        if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
            if (event.startTime != null && event.endTime != null) {
                // Event is all day , adjust the goto time to local time
                if (event.isAllDay()) {
                    Utils.convertAlldayUtcToLocal(event.startTime, event.startTime.toMillis(false), mTimeZone);
                    Utils.convertAlldayUtcToLocal(event.endTime, event.endTime.toMillis(false), mTimeZone);
                }
                mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime, event.selectedTime,
                        event.id, ViewType.AGENDA, CalendarController.EXTRA_GOTO_TIME, null, null);
            } else if (event.selectedTime != null) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, event.id,
                        ViewType.AGENDA);
            }
        } else {
            // TODO Fix the temp hack below: && mCurrentView !=
            // ViewType.AGENDA
            if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, -1,
                        ViewType.CURRENT);
            }
            int response = event.getResponse();
            if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda)
                    || ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK)
                            || mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)) {
                // start event info as activity
                Intent intent = new Intent(Intent.ACTION_VIEW);
                Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
                intent.setData(eventUri);
                intent.setClass(this, EventInfoActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
                intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
                intent.putExtra(ATTENDEE_STATUS, response);
                startActivity(intent);
            } else {
                // start event info as a dialog
                EventInfoFragment fragment = new EventInfoFragment(this, event.id,
                        event.startTime.toMillis(false), event.endTime.toMillis(false), response, true,
                        EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */);
                fragment.setDialogParams(event.x, event.y, mActionBar.getHeight());
                FragmentManager fm = getFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                // if we have an old popup replace it
                Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
                if (fOld != null && fOld.isAdded()) {
                    ft.remove(fOld);
                }
                ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
                ft.commit();
            }
        }
        displayTime = event.startTime.toMillis(true);
    } else if (event.eventType == EventType.UPDATE_TITLE) {
        setTitleInActionBar(event);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(mController.getTime());
        }
    }
    updateSecondaryTitleFields(displayTime);
}

From source file:com.android.settings.HWSettings.java

private void createFragments() {
    DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

    this.mViewPager = ((ViewPager) findViewById(R.id.tab_pager));
    this.mPagerAdapter = new SettingsPagerAdapter();
    this.mViewPager.setAdapter(this.mPagerAdapter);
    SettingsPageChangeListener localSettingsPageChangeListener = new SettingsPageChangeListener();
    this.mViewPager.setOnPageChangeListener(localSettingsPageChangeListener);
    this.mFragmentManager = getFragmentManager();
    FragmentTransaction localFragmentTransaction = this.mFragmentManager.beginTransaction();
    Fragment localFragment1 = this.mFragmentManager
            .findFragmentByTag("com.android.settings.HWAllSettingsFragment");
    if (localFragment1 != null)
        localFragmentTransaction.remove(localFragment1);
    Fragment localFragment2 = this.mFragmentManager
            .findFragmentByTag("com.android.settings.HWGeneralSettingsFragment");
    if (localFragment2 != null)
        localFragmentTransaction.remove(localFragment2);
    Log.d("dingjingliang", "createFragments: curTabIndex" + curTabIndex);
    this.mGeneralSettingsFragment = new HWGeneralSettingsFragment(mAuthenticatorHelper, dpm);
    localFragmentTransaction.add(R.id.tab_pager, this.mGeneralSettingsFragment,
            "com.android.settings.HWGeneralSettingsFragment");
    localFragmentTransaction.hide(this.mGeneralSettingsFragment);
    this.mAllSettingsFragment = new HWAllSettingsFragment(mAuthenticatorHelper, dpm);
    localFragmentTransaction.add(R.id.tab_pager, this.mAllSettingsFragment,
            "com.android.settings.HWAllSettingsFragment");
    localFragmentTransaction.hide(this.mAllSettingsFragment);
    localFragmentTransaction.commitAllowingStateLoss();
    this.mFragmentManager.executePendingTransactions();
}