Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

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

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * //from   w w  w  .  java 2s.c  om
 * @param popStack
 */
public void startTest(final boolean popStack) {
    if (networkInfoCollector != null) {
        if (!networkInfoCollector.hasConnectionFromAndroidApi()) {
            showNoNetworkConnectionToast();
            return;
        }
    }

    final boolean loopMode = ConfigHelper.isLoopMode(this);
    if (loopMode) {
        startService(new Intent(this, RMBTLoopService.class));
    } else {
        FragmentTransaction ft;
        ft = fm.beginTransaction();
        final RMBTTestFragment rmbtTestFragment = new RMBTTestFragment();
        ft.replace(R.id.fragment_content, rmbtTestFragment, AppConstants.PAGE_TITLE_TEST);
        ft.addToBackStack(AppConstants.PAGE_TITLE_TEST);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        if (popStack)
            fm.popBackStack();
        ft.commit();

        final Intent service = new Intent(RMBTService.ACTION_START_TEST, null, this, RMBTService.class);
        startService(service);
    }
}

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  w w  w.ja  v a  2 s  . c  o m*/
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:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * // w ww .  j a  v a  2 s .c  om
 * @param uid
 */
public void showResultDetail(final String testUUid) {
    FragmentTransaction ft;

    final Fragment fragment = new RMBTTestResultDetailFragment();

    final Bundle args = new Bundle();

    args.putString(RMBTTestResultDetailFragment.ARG_UID, testUUid);
    fragment.setArguments(args);

    ft = fm.beginTransaction();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_RESULT_DETAIL);
    ft.addToBackStack(AppConstants.PAGE_TITLE_RESULT_DETAIL);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();

    refreshActionBar(AppConstants.PAGE_TITLE_RESULT_DETAIL);
}

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

/**
 * Ricostruisce la successione della disposizione dei frammenti nei
 * pannelli.//from   ww w  . ja  v a2  s .co 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:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * /* www . java 2  s  . c o m*/
 * @param uid
 */
public void showExpandedResultDetail(QoSServerResultCollection testResultArray, DetailType detailType,
        int position) {
    FragmentTransaction ft;

    //final RMBTResultDetailPagerFragment fragment = new RMBTResultDetailPagerFragment();
    final QoSCategoryPagerFragment fragment = new QoSCategoryPagerFragment();

    fragment.setQoSResult(testResultArray);
    fragment.setDetailType(detailType);

    ft = fm.beginTransaction();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_RESULT_QOS);
    ft.addToBackStack("result_detail_expanded");
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();

    fragment.setCurrentPosition(position);
    refreshActionBar(AppConstants.PAGE_TITLE_RESULT_QOS);
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

public void showMap(boolean popBackStack) {
    if (popBackStack) {
        popBackStackFull();/*from w  w  w . j ava  2  s  .co  m*/
    }

    FragmentTransaction ft;
    ft = fm.beginTransaction();
    Fragment f = new RMBTMapFragment();
    Bundle bundle = new Bundle();
    bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_ALL_GESTURES, true);
    bundle.putBoolean(RMBTMapFragment.OPTION_SHOW_INFO_TOAST, true);
    bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_CONTROL_BUTTONS, true);
    f.setArguments(bundle);
    ft.replace(R.id.fragment_content, f, AppConstants.PAGE_TITLE_MAP);
    ft.addToBackStack(AppConstants.PAGE_TITLE_MAP);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();

    refreshActionBar(AppConstants.PAGE_TITLE_MAP);
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * //from  ww  w .ja  va  2  s .  c  o  m
 * @param uid
 */
public void showQoSTestDetails(List<QoSServerResult> resultList, List<QoSServerResultDesc> descList,
        int index) {
    FragmentTransaction ft;

    //final RMBTResultDetailPagerFragment fragment = new RMBTResultDetailPagerFragment();
    final QoSTestDetailPagerFragment fragment = new QoSTestDetailPagerFragment();

    fragment.setQoSResultList(resultList);
    fragment.setQoSDescList(descList);
    fragment.setInitPosition(index);

    ft = fm.beginTransaction();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_TEST_DETAIL_QOS);
    ft.addToBackStack(AppConstants.PAGE_TITLE_TEST_DETAIL_QOS);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();

    refreshActionBar(AppConstants.PAGE_TITLE_TEST_DETAIL_QOS);
}

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.// www .  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:android.support.v17.leanback.app.BrowseFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (getChildFragmentManager().findFragmentById(R.id.scale_frame) == null) {
        mHeadersFragment = new HeadersFragment();

        createMainFragment(mAdapter, mSelectedPosition);
        FragmentTransaction ft = getChildFragmentManager().beginTransaction().replace(R.id.browse_headers_dock,
                mHeadersFragment);/*w w w . j  ava  2 s. c o  m*/

        if (mMainFragment != null) {
            ft.replace(R.id.scale_frame, mMainFragment);
        } else {
            // Empty adapter used to guard against lazy adapter loading. When this
            // fragment is instantiated, mAdapter might not have the data or might not
            // have been set. In either of those cases mFragmentAdapter will be null.
            // This way we can maintain the invariant that mMainFragmentAdapter is never
            // null and it avoids doing null checks all over the code.
            mMainFragmentAdapter = new MainFragmentAdapter(null);
            mMainFragmentAdapter.setFragmentHost(new FragmentHostImpl());
        }

        ft.commit();
    } else {
        mHeadersFragment = (HeadersFragment) getChildFragmentManager()
                .findFragmentById(R.id.browse_headers_dock);
        mMainFragment = getChildFragmentManager().findFragmentById(R.id.scale_frame);
        mMainFragmentAdapter = ((MainFragmentAdapterProvider) mMainFragment).getMainFragmentAdapter();
        mMainFragmentAdapter.setFragmentHost(new FragmentHostImpl());

        mIsPageRow = savedInstanceState != null ? savedInstanceState.getBoolean(IS_PAGE_ROW, false) : false;

        mSelectedPosition = savedInstanceState != null ? savedInstanceState.getInt(CURRENT_SELECTED_POSITION, 0)
                : 0;

        if (!mIsPageRow) {
            if (mMainFragment instanceof MainFragmentRowsAdapterProvider) {
                mMainFragmentRowsAdapter = ((MainFragmentRowsAdapterProvider) mMainFragment)
                        .getMainFragmentRowsAdapter();
            } else {
                mMainFragmentRowsAdapter = null;
            }
        } else {
            mMainFragmentRowsAdapter = null;
        }
    }

    mHeadersFragment.setHeadersGone(!mCanShowHeaders);
    if (mHeaderPresenterSelector != null) {
        mHeadersFragment.setPresenterSelector(mHeaderPresenterSelector);
    }
    mHeadersFragment.setAdapter(mAdapter);
    mHeadersFragment.setOnHeaderViewSelectedListener(mHeaderViewSelectedListener);
    mHeadersFragment.setOnHeaderClickedListener(mHeaderClickedListener);

    View root = inflater.inflate(R.layout.lb_browse_fragment, container, false);

    getProgressBarManager().setRootView((ViewGroup) root);

    mBrowseFrame = (BrowseFrameLayout) root.findViewById(R.id.browse_frame);
    mBrowseFrame.setOnChildFocusListener(mOnChildFocusListener);
    mBrowseFrame.setOnFocusSearchListener(mOnFocusSearchListener);

    installTitleView(inflater, mBrowseFrame, savedInstanceState);

    mScaleFrameLayout = (ScaleFrameLayout) root.findViewById(R.id.scale_frame);
    mScaleFrameLayout.setPivotX(0);
    mScaleFrameLayout.setPivotY(mContainerListAlignTop);

    setupMainFragment();

    if (mBrandColorSet) {
        mHeadersFragment.setBackgroundColor(mBrandColor);
    }

    mSceneWithHeaders = TransitionHelper.createScene(mBrowseFrame, new Runnable() {
        @Override
        public void run() {
            showHeaders(true);
        }
    });
    mSceneWithoutHeaders = TransitionHelper.createScene(mBrowseFrame, new Runnable() {
        @Override
        public void run() {
            showHeaders(false);
        }
    });
    mSceneAfterEntranceTransition = TransitionHelper.createScene(mBrowseFrame, new Runnable() {
        @Override
        public void run() {
            setEntranceTransitionEndState();
        }
    });

    return root;
}

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

/**
 * Removes a specific fragment from its parent view.
 *
 * @param fragment/*from w  w  w.java2 s .co 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();
}