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:cz.metaverse.android.bilingualreader.ReaderActivity.java

/**
 * Hide panel from view.//from  w  ww  .  j av  a 2 s. c  o m
 */
public void hidePanel(SplitPanel p) {
    Log.d(LOG, "ReaderActivity.hidePanel");

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
    fragmentTransaction.hide(p);
    fragmentTransaction.commit();
}

From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java

/**
 * Reappear panel after it has been hidden.
 *//*from   w w  w. j a  v  a2s. c o m*/
public void showPanel(SplitPanel p) {
    Log.d(LOG, "ReaderActivity.showPanel");

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
    fragmentTransaction.show(p);
    fragmentTransaction.commit();
}

From source file:com.google.android.apps.forscience.whistlepunk.review.RunReviewFragment.java

@Override
public void onEditNoteTimestampClicked(Label label, GoosciLabelValue.LabelValue selectedValue,
        long labelTimestamp) {
    // Dismiss the edit note dialog and show the timestamp dialog.
    EditNoteDialog editDialog = (EditNoteDialog) getChildFragmentManager()
            .findFragmentByTag(EditNoteDialog.TAG);
    if (editDialog != null) {
        editDialog.dismiss();//  ww w . j  a v  a2  s  . c om
    }

    // Show the timestamp edit window below the graph / over the notes
    getView().findViewById(R.id.embedded).setVisibility(View.VISIBLE);
    EditTimeDialog timeDialog = EditTimeDialog.newInstance(label, selectedValue, labelTimestamp,
            mExperimentRun.getFirstTimestamp());
    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    ft.add(R.id.embedded, timeDialog, EditTimeDialog.TAG);
    ft.commit();
    mRunReviewOverlay.setActiveTimestamp(labelTimestamp);
    mRunReviewOverlay.setOnTimestampChangeListener(timeDialog);
    setTimepickerUi(getView(), true);
}

From source file:dk.kk.ibikecphlib.map.MapActivity.java

/**
 * Transition the map activity to another state.
 *
 * @param toState the new state//from w w  w .j  a v  a 2s.  c  om
 */
public void changeState(MapState toState) {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    MapState fromState = state;
    String logMessage = "Changed state ";

    // Give the state a reference back to this activity.
    toState.setMapActivity(this);

    // Transition away from the current state.
    if (fromState != null) {
        logMessage += String.format("from %s ", fromState);
        fromState.transitionAway(toState, fragmentTransaction);
    }

    // Transition to the new state
    state = toState;
    logMessage += String.format("to %s", toState);
    toState.transitionTowards(fromState, fragmentTransaction);

    fragmentTransaction.commit();

    // Insert this as info in the log
    Log.i(TAG, logMessage);
}

From source file:iovi.testtask.MainActivity.java

private void selectItem(int position) {

    Fragment fragment = new ListF();
    FragmentManager fragmentManager;//w  ww  . ja  v a  2 s. c  o  m
    FragmentTransaction fragmentTransaction;
    Bundle args = new Bundle();
    args.putString("Title", mMenuTitles[position]);

    switch (position) {
    case 0:
        args.putString(ListF.TABLE, DataBaseHelper.TABLE_ORGANISATIONS);
        args.putString(ListF.COLUMN, DataBaseHelper.NAME);
        args.putString(ListF.SELECTION, null);
        args.putStringArray(ListF.ARGS, null);
        fragment.setArguments(args);
        fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;
    case 1:
        args.putString(ListF.TABLE, DataBaseHelper.TABLE_NEWS);
        args.putString(ListF.COLUMN, DataBaseHelper.NEWS_TITLE);
        args.putString(ListF.SELECTION, null);
        args.putStringArray(ListF.ARGS, null);
        fragment.setArguments(args);

        fragmentManager = getFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.content_frame, fragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
        break;

    case 2:
        fragment = new ContactsF();
        fragment.setArguments(args);
        fragmentManager = getFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.content_frame, fragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();

        break;
    }

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mMenuTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.example.search.car.pools.welcome.java

private void set_fragment(Fragment fragment) {
    // TODO Auto-generated method stub
    FragmentManager fm = getFragmentManager();
    FragmentTransaction fragmentTransaction = fm.beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment, frag_tag);
    fragmentTransaction.commit();
}

From source file:android.support.v13.app.FragmentTabHost.java

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    String currentTab = getCurrentTabTag();

    // Go through all tabs and make sure their fragments match
    // the correct state.
    FragmentTransaction ft = null;
    for (int i = 0; i < mTabs.size(); i++) {
        TabInfo tab = mTabs.get(i);/*w w  w  .j  a  va 2  s .co m*/
        tab.fragment = mFragmentManager.findFragmentByTag(tab.tag);
        if (tab.fragment != null && !tab.fragment.isDetached()) {
            if (tab.tag.equals(currentTab)) {
                // The fragment for this tab is already there and
                // active, and it is what we really want to have
                // as the current tab.  Nothing to do.
                mLastTab = tab;
            } else {
                // This fragment was restored in the active state,
                // but is not the current tab.  Deactivate it.
                if (ft == null) {
                    ft = mFragmentManager.beginTransaction();
                }
                ft.detach(tab.fragment);
            }
        }
    }

    // We are now ready to go.  Make sure we are switched to the
    // correct tab.
    mAttached = true;
    ft = doTabChanged(currentTab, ft);
    if (ft != null) {
        ft.commit();
        mFragmentManager.executePendingTransactions();
    }
}

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

/**
 * Finishes hiding the dialpad fragment after any animations are completed.
 *//*w ww . j  a  v  a  2  s.c  o m*/
private void commitDialpadFragmentHide() {
    if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
        final FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.hide(mDialpadFragment);
        ft.commit();
    }
    mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
}

From source file:org.chromium.chrome.browser.bookmark.ManageBookmarkActivity.java

/**
 * Initializes the fragment state after a state restoration.
 * <p>/*from w w  w  .j a  v a 2 s  . com*/
 * Reinitializes all of the event listeners on the fragments as they are not persisted across
 * activity recreation (and were referencing the old activity anyway).
 * <p>
 * The hidden state of the fragments are also not persisted across activity changes, so we need
 * to hide and show the fragments accordingly (since we know that hierarchy of the fragments
 * we can do this as a simple nested conditional).
 */
private void initializeFragmentState() {
    AddEditBookmarkFragment baseAddEditFragment = (AddEditBookmarkFragment) getFragmentManager()
            .findFragmentByTag(BASE_ADD_EDIT_FRAGMENT_TAG);
    setActionListenerOnAddEdit(baseAddEditFragment);

    Fragment selectFolderFragment = getFragmentManager().findFragmentByTag(BASE_SELECT_FOLDER_FRAGMENT_TAG);
    if (selectFolderFragment != null) {
        setActionListenerOnFolderSelection((SelectBookmarkFolderFragment) selectFolderFragment);

        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.hide(baseAddEditFragment);

        Fragment addFolderFragment = getFragmentManager().findFragmentByTag(ADD_FOLDER_FRAGMENT_TAG);
        if (addFolderFragment != null) {
            fragmentTransaction.hide(selectFolderFragment);
            setActionListenerOnAddEdit((AddEditBookmarkFragment) addFolderFragment);

            Fragment addFolderSelectFolderFragment = getFragmentManager()
                    .findFragmentByTag(ADD_FOLDER_SELECT_FOLDER_FRAGMENT_TAG);
            if (addFolderSelectFolderFragment != null) {
                setActionListenerOnFolderSelection(
                        (SelectBookmarkFolderFragment) addFolderSelectFolderFragment);
                fragmentTransaction.hide(addFolderFragment);
                fragmentTransaction.show(addFolderSelectFolderFragment);
            } else {
                fragmentTransaction.show(addFolderFragment);
            }
        } else {
            fragmentTransaction.show(selectFolderFragment);
        }
        fragmentTransaction.commit();
    }
}

From source file:com.example.search.car.pools.welcome.java

public void onBackPressed() {
    if (canExit) {
        super.onBackPressed();
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);//  w w  w  .j  a v  a  2s  . c o m
    } else {
        // Fragment fm = getFragmentManager().findFragmentByTag("Search");
        if (frag_tag != "Search") {
            svg_search = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.search1);
            iv_search.setImageDrawable(svg_search.createPictureDrawable());
            rlSearch.setBackgroundColor(Color.parseColor("#00ca98"));
            l_search.setBackground(getResources().getDrawable(R.drawable.white_circle_side_menu));

            svg_dashboard = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.dashboard);
            iv_dashboard.setImageDrawable(svg_dashboard.createPictureDrawable());
            rlDashboard.setBackgroundColor(Color.parseColor("#2C3E50"));
            l_dashboard.setBackground(getResources().getDrawable(R.drawable.search_blue));
            svg_cities = SVGParser.getSVGFromResource(welcome.this.getResources(), R.raw.city);
            iv_cities.setImageDrawable(svg_cities.createPictureDrawable());
            rlCities.setBackgroundColor(Color.parseColor("#2C3E50"));
            l_cities.setBackground(getResources().getDrawable(R.drawable.search_blue));

            FragmentManager fm = getFragmentManager();
            FragmentTransaction fragmentTransaction = fm.beginTransaction();
            fragmentTransaction.replace(R.id.content_frame, new Search());
            fragmentTransaction.commit();
            frag_tag = "Search";
        } else {
            canExit = true;
            Toast.makeText(getApplicationContext(), "Press again to exit", Toast.LENGTH_SHORT).show();
        }

    }
    mHandler.sendEmptyMessageDelayed(1, 2000/* time interval to next press in milli second */);// if not
    // pressed
    // within
    // 2
    // seconds
    // then
    // will
    // be
    // setted(canExit)
    // as
    // false
}