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

public void showLogFragment() {
    FragmentTransaction ft;
    ft = fm.beginTransaction();//from  w  w w. ja  va 2  s . co  m

    final Fragment fragment = new LogFragment();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_LOG);
    ft.addToBackStack(AppConstants.PAGE_TITLE_LOG);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    ft.commit();
    refreshActionBar(AppConstants.PAGE_TITLE_LOG);
}

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

/**
 * /*from w  w  w .  j a v  a  2 s .c  o  m*/
 */
public void showSync() {
    FragmentTransaction ft;
    ft = fm.beginTransaction();

    final Fragment fragment = new RMBTSyncFragment();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_SYNC);
    ft.addToBackStack(AppConstants.PAGE_TITLE_SYNC);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    ft.commit();
    refreshActionBar(AppConstants.PAGE_TITLE_SYNC);
}

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

public void showNetstatFragment() {
    FragmentTransaction ft;
    ft = fm.beginTransaction();//from  www .j  ava 2 s.  c  om

    final Fragment fragment = new NetstatFragment();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_NETSTAT);
    ft.addToBackStack(AppConstants.PAGE_TITLE_NETSTAT);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    ft.commit();
    refreshActionBar(AppConstants.PAGE_TITLE_NETSTAT);
}

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

public void showFilter() {
    final FragmentManager fm = getFragmentManager();
    FragmentTransaction ft;

    final Fragment fragment = new RMBTFilterFragment();

    ft = fm.beginTransaction();//from   ww  w .jav  a  2 s.c om
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_HISTORY_FILTER);
    ft.addToBackStack(AppConstants.PAGE_TITLE_HISTORY_FILTER);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();

    refreshActionBar(AppConstants.PAGE_TITLE_HISTORY_FILTER);
}

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

/**
 * Hides the search fragment/*from www.j a va 2 s  .  co m*/
 */
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:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * /*  w  w  w .j  ava 2 s  .c  o  m*/
 * @param popStack
 */
public void showHistory(final boolean popStack) {
    popBackStackFull();

    FragmentTransaction ft;
    ft = fm.beginTransaction();

    ft.replace(R.id.fragment_content, new RMBTHistoryFragment(), AppConstants.PAGE_TITLE_HISTORY);
    ft.addToBackStack(AppConstants.PAGE_TITLE_HISTORY);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    if (popStack) {
        fm.popBackStack();
    }

    ft.commit();

    refreshActionBar(AppConstants.PAGE_TITLE_HISTORY);
}

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

/**
 * Hides the search fragment/*  w ww .  j a  v  a 2 s  .  co 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.github.chenxiaolong.dualbootpatcher.MainActivity.java

private void showFragment() {
    FragmentManager fm = getFragmentManager();

    Fragment prevRoms = fm.findFragmentByTag(SwitcherListFragment.TAG);
    Fragment prevPatchFile = fm.findFragmentByTag(PatchFileFragment.TAG);
    Fragment prevFreeSpace = fm.findFragmentByTag(FreeSpaceFragment.TAG);
    Fragment prevAbout = fm.findFragmentByTag(AboutFragment.TAG);

    FragmentTransaction ft = fm.beginTransaction();
    ft.setCustomAnimations(R.animator.fragment_in, 0);

    switch (mFragment) {
    case FRAGMENT_ROMS:
        mTitle = R.string.title_roms;//  w  ww . j av a  2 s. c  om
        updateTitle();

        if (prevRoms == null) {
            Fragment f = SwitcherListFragment.newInstance();
            ft.add(R.id.content_frame, f, SwitcherListFragment.TAG);
        } else {
            ft.show(prevRoms);
        }

        break;

    case FRAGMENT_PATCH_FILE:
        mTitle = R.string.title_patch_zip;
        updateTitle();

        if (prevPatchFile == null) {
            Fragment f = PatchFileFragment.newInstance();
            ft.add(R.id.content_frame, f, PatchFileFragment.TAG);
        } else {
            ft.show(prevPatchFile);
        }

        break;

    case FRAGMENT_FREE_SPACE:
        mTitle = R.string.title_free_space;
        updateTitle();

        if (prevFreeSpace == null) {
            Fragment f = FreeSpaceFragment.newInstance();
            ft.add(R.id.content_frame, f, FreeSpaceFragment.TAG);
        } else {
            ft.show(prevFreeSpace);
        }

        break;

    case FRAGMENT_ABOUT:
        mTitle = BuildConfig.APP_NAME_RESOURCE;
        updateTitle();

        if (prevAbout == null) {
            Fragment f = AboutFragment.newInstance();
            ft.add(R.id.content_frame, f, AboutFragment.TAG);
        } else {
            ft.show(prevAbout);
        }

        break;

    default:
        throw new IllegalStateException("Invalid fragment ID");
    }

    ft.commit();
}

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);
        }/* w  w w. j av  a  2s .  co  m*/
    }

    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:at.alladin.rmbt.android.main.RMBTMainActivity.java

public void showHelp(final String url, boolean popBackStack, String titleId) {
    if (popBackStack) {
        popBackStackFull();//from w ww  .j  av  a2  s.co m
    }

    FragmentTransaction ft;

    ft = fm.beginTransaction();

    final Fragment fragment = new RMBTHelpFragment();
    final Bundle args = new Bundle();

    args.putString(RMBTHelpFragment.ARG_URL, url);
    fragment.setArguments(args);
    ft.replace(R.id.fragment_content, fragment, titleId);
    ft.addToBackStack(titleId);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    ft.commit();
    refreshActionBar(titleId);
}