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.android.deskclock.AlarmClockFragment.java

private void showLabelDialog(final Alarm alarm) {
    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment prev = getFragmentManager().findFragmentByTag("label_dialog");
    if (prev != null) {
        ft.remove(prev);
    }//from   www  . java2 s. c  o m
    /// M:If the LabelEditDialog Existed,do not create again
    //ft.addToBackStack(null);
    /// M:Don't need use the method ft.commit(), because it may cause IllegalStateException
    final LabelDialogFragment newFragment = LabelDialogFragment.newInstance(alarm, alarm.label, getTag());
    ft.add(newFragment, "label_dialog");
    ft.commitAllowingStateLoss();
    getFragmentManager().executePendingTransactions();
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animate the transition on burgerButton/MenuButton pressed
 */// w ww  .ja v a  2 s. c o m
public static void pressMenuButton(final MainActivity context) {
    try {
        if (context == null)
            return;
        ((BreadWalletApp) context.getApplication()).cancelToast();
        final FragmentManager fragmentManager = context.getFragmentManager();
        if (level == 0) {
            if (PLATFORM_ON)
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        HTTPServer.startServer();
                    }
                }).start();
            level++;
            CustomPagerAdapter.adapter.showFragments(false, context);
            context.setBurgerButtonImage(BRConstants.CLOSE);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            FragmentSettingsAll to = (FragmentSettingsAll) fragmentManager
                    .findFragmentByTag(FragmentSettingsAll.class.getName());
            if (to == null)
                to = new FragmentSettingsAll();
            fragmentTransaction.add(R.id.main_layout, to, FragmentSettingsAll.class.getName());
            fragmentTransaction.commit();
            final FragmentSettingsAll finalTo = to;
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    TranslateAnimation trans = new TranslateAnimation(0, 0, 1920, 0);
                    trans.setDuration(500);
                    trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                    View view = finalTo.getView();
                    if (view != null)
                        view.startAnimation(trans);
                }
            }, 1);

            InputMethodManager keyboard = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);

            if (keyboard != null)
                keyboard.hideSoftInputFromWindow(
                        CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0);
        } else if (level == 1) {
            if (PLATFORM_ON)
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        HTTPServer.stopServer();
                    }
                }).start();

            level--;
            context.setBurgerButtonImage(BRConstants.BURGER);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.setCustomAnimations(R.animator.from_top, R.animator.to_bottom);
            FragmentSettingsAll fragmentSettingsAll = (FragmentSettingsAll) fragmentManager
                    .findFragmentByTag(FragmentSettingsAll.class.getName());
            fragmentTransaction.remove(fragmentSettingsAll);
            fragmentTransaction.commit();
            CustomPagerAdapter.adapter.showFragments(true, context);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.esri.android.mapsapp.MapFragment.java

/**
 * Opens the map represented by the specified portal item or if null, opens
 * a default map.//from  w  w  w. ja v  a2  s  .com
 */
public void showMap(String portalItemId, String basemapPortalItemId) {

    // remove existing MapFragment explicitly, simply replacing it can cause
    // the app to freeze when switching basemaps
    FragmentTransaction transaction;
    FragmentManager fragmentManager = getFragmentManager();
    Fragment currentMapFragment = fragmentManager.findFragmentByTag(MapFragment.TAG);
    if (currentMapFragment != null) {
        transaction = fragmentManager.beginTransaction();
        transaction.remove(currentMapFragment);
        transaction.commit();
    }

    MapFragment mapFragment = MapFragment.newInstance(portalItemId, basemapPortalItemId);

    transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.maps_app_activity_content_frame, mapFragment, MapFragment.TAG);
    transaction.addToBackStack(null);
    transaction.commit();

    getActivity().invalidateOptionsMenu(); // reload the options menu
}

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

/**
 * @author bbk wangchunhe// w  w w .j a  v a  2 s  . c  o  m
 * @Date 2016/07/15
 * show CallLogFragment of filterType
 * @param filterType
 */
private void showCallLogFragment(int filterType) {

    final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    if (mCalllogList != null) {
        transaction.remove(mCalllogList);
    }

    mCalllogList = new CallLogFragment(filterType);
    transaction.add(R.id.dialtacts_frame, mCalllogList, "mCalllogList");
    mCalllogList.setRecyclerViewChangedImpl(mRecyclerViewChangedImpl);
    transaction.show(mCalllogList);
    transaction.commitAllowingStateLoss();

}

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

/**
 * Hides the search fragment//  w  ww  .  ja va  2  s.com
 */
private void exitSartDialpadFragment() {
    // See related bug in enterSearchUI();
    if (getChildFragmentManager().isDestroyed() || mStateSaved) {
        return;
    }
    setNotInSearchUi();
    final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    if (mSmartDialSearchFragment != null) {
        transaction.remove(mSmartDialSearchFragment);
    }
    if (mRegularSearchFragment != null) {
        transaction.remove(mRegularSearchFragment);
    }
    transaction.commit();

    addCallLogFragmentInList();
}

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

/**
 * Hides the search fragment//  w  w  w  .  j av a 2s . c  o  m
 */
public void exitSearchUi() {
    // See related bug in enterSearchUI();
    if (getChildFragmentManager().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 = getChildFragmentManager().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);
    }
    addCallLogFragmentInList();
    //        mActionBarController.onSearchUiExited();
    //        getActionBar().show();
}

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

/**
 * Shows the search fragment/*www  .  j av a 2 s.  c  o m*/
 */
private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
    if (mStateSaved || getChildFragmentManager().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;
    }
    mDialpadFragment.showSearchView();

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

    final FragmentTransaction transaction = getChildFragmentManager().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) getChildFragmentManager().findFragmentByTag(tag);
    if (animate) {
        transaction.setCustomAnimations(android.R.animator.fade_in, 0);
    } else {
        transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
    }
    if (fragment == null) {

        Log.e(TAG, " --- enterSearchUi --- null");
        if (smartDialSearch) {
            fragment = new SmartDialSearchFragment();
            transaction.add(R.id.dialtacts_frame, fragment, tag);
        } else {
            fragment = new RegularSearchFragment();
            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.
                    showFabInSearchUi();
                    return false;
                }
            });
        }

    } else {
        transaction.show(fragment);

    }
    // DialtactsFragment will provide the options menu
    fragment.setHasOptionsMenu(false);
    fragment.setShowEmptyListForNullQuery(true);
    fragment.setQueryString(query, false /* delaySelection */);
    transaction.commitAllowingStateLoss();
    //        transaction.commit();

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

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

public void showListFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.LIST);
    this.updateChildViewVisibility(ViewFragmentType.LIST);
    // Try to use a passed file name. If one doesn't exist, try to use the
    // default./*from  w  w w. j a  v a 2  s. c  o m*/
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    if (fileName == null) {
        SQLiteDatabase db = null;
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getListViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.LIST, fragmentTransaction);
    ListViewFragment listViewFragment = (ListViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.LIST);
    if (listViewFragment == null || createNew) {
        if (listViewFragment == null) {
            WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] existing list fragment not found");
        } else {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] removing old list fragment");
            fragmentTransaction.remove(listViewFragment);
        }
        listViewFragment = this.createListViewFragment(fileName);
        fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, listViewFragment,
                Constants.FragmentTags.LIST);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showListFragment] existing list fragment found");
        fragmentTransaction.show(listViewFragment);
    }
    fragmentTransaction.commit();
}

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

public void showMapFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.MAP);
    this.updateChildViewVisibility(ViewFragmentType.MAP);
    // Set the list view file name.
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    if (fileName == null) {
        SQLiteDatabase db = null;/*from   ww  w .  j a va 2  s.c  om*/
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getMapListViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.MAP, fragmentTransaction);
    MapListViewFragment mapListViewFragment = (MapListViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.MAP_LIST);
    TableMapInnerFragment innerMapFragment = (TableMapInnerFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.MAP_INNER_MAP);
    if (mapListViewFragment == null || (fileName != null && !fileName.equals(mapListViewFragment.getFileName()))
            || createNew) {
        if (mapListViewFragment != null) {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old map list fragment");
            fragmentTransaction.remove(mapListViewFragment);
        }
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new map list fragment");
        mapListViewFragment = this.createMapListViewFragment(fileName);
        fragmentTransaction.add(R.id.map_view_list, mapListViewFragment, Constants.FragmentTags.MAP_LIST);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing map list fragment found");
        fragmentTransaction.show(mapListViewFragment);
    }
    if (innerMapFragment == null || createNew) {
        if (innerMapFragment != null) {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old inner map fragment");
            fragmentTransaction.remove(innerMapFragment);
        }
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new inner map fragment");
        innerMapFragment = this.createInnerMapFragment();
        fragmentTransaction.add(R.id.map_view_inner_map, innerMapFragment,
                Constants.FragmentTags.MAP_INNER_MAP);
        innerMapFragment.listener = this;
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing inner map fragment found");
        innerMapFragment.listener = this;
        fragmentTransaction.show(innerMapFragment);
    }
    fragmentTransaction.commit();
}

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

/**
 * Show the spreadsheet fragment./*w ww  .j a  v  a 2  s.c  o m*/
 * 
 * @param createNew
 */
public void showSpreadsheetFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.SPREADSHEET);
    this.updateChildViewVisibility(ViewFragmentType.SPREADSHEET);
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    // Hide all the other fragments.
    this.hideAllOtherViewFragments(ViewFragmentType.SPREADSHEET, fragmentTransaction);
    // Try to retrieve one already there.
    SpreadsheetFragment spreadsheetFragment = (SpreadsheetFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.SPREADSHEET);
    if (spreadsheetFragment == null) {
        WebLogger.getLogger(getAppName()).d(TAG,
                "[showSpreadsheetFragment] no existing spreadshseet " + "fragment found");
    } else {
        WebLogger.getLogger(getAppName()).d(TAG,
                "[showSpreadsheetFragment] existing spreadsheet fragment " + "found");
    }
    WebLogger.getLogger(getAppName()).d(TAG, "[showSpreadsheetFragment] createNew is: " + createNew);
    if (spreadsheetFragment == null || createNew) {
        if (spreadsheetFragment != null) {
            WebLogger.getLogger(getAppName()).d(TAG, "[showSpreadsheetFragment] removing existing fragment");
            // Get rid of the existing fragment
            fragmentTransaction.remove(spreadsheetFragment);
        }
        spreadsheetFragment = this.createSpreadsheetFragment();
        fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, spreadsheetFragment,
                Constants.FragmentTags.SPREADSHEET);
    } else {
        fragmentTransaction.show(spreadsheetFragment);
    }
    fragmentTransaction.commit();
}