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:com.android.purenexussettings.TinkerActivity.java

private void displayView(int position) {
    // before anything else - check to see if position matches intent-launching "frags" - for example
    // if ( navMenuTitles[position].equals("TARGETNAME") ) { position = 0; do something}
    boolean mKeepStack = checkPosition(position);

    // update the main content by replacing fragments
    Fragment frags = null;//from  ww w.j av a2s.  c o  m
    String fragname = navMenuFrags[position];
    try {
        frags = (Fragment) Class.forName(mPackageName + "." + fragname).newInstance();
    } catch (Exception e) {
        frags = null;
    }
    if (frags != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        try {
            FragmentTransaction fragtrans = fragmentManager.beginTransaction();
            if (mFromClick || mMenu || mBackPress) {
                fragtrans.setCustomAnimations(R.anim.fadein, R.anim.fadeout, R.anim.fadein, R.anim.fadeout);
            }
            fragtrans.add(R.id.frame_container, frags);
            // The backstack should be cleared if not coming from a fragment flagged as stack keeping or from a backpress
            // After clearing the only entry should be About/main
            if (!mKeepStack && !mBackPress) {
                fragmentStack.clear();
                fragmentStack.push(navMenuFrags[0]);
            }
            // add fragment name to custom stack for backstack tracking
            // only do it if not a backpress, flagged as stack keeping, or dup of last entry
            if (!mBackPress && !mKeepStack
                    && !(fragmentStack.size() >= 1 && fragmentStack.peek().equals(navMenuFrags[position]))) {
                fragmentStack.push(navMenuFrags[position]);
            }

            fragtrans.commit();
        } catch (Exception e) {
        }

        // update selected item and title, then close the drawer
        if (mFromClick || mBackPress) {
            mFromClick = false;
            mBackPress = false;
        } else {
            setTitle(navMenuTitles[position]);
            if (mMenu) {
                mMenu = false;
                mItemPosition = position;
            } else {
                mDrawerLayout.closeDrawer(mNavView);
            }
        }
        invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
    } else {
        // error in creating fragment
        Log.e("TinkerActivity", "Error in creating fragment");
    }
}

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

/**
 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
 * @see #onDialpadShown/*  ww  w .  j  a v  a 2s .c om*/
 */
private void showDialpadFragment(boolean animate) {
    if (mIsDialpadShown || mStateSaved) {
        return;
    }
    mIsDialpadShown = true;

    mListsFragment.setUserVisibleHint(false);

    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    if (mDialpadFragment == null) {
        mDialpadFragment = new DialpadFragment();
        ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
    } else {
        ft.show(mDialpadFragment);
    }

    mDialpadFragment.setAnimate(animate);
    Logger.logScreenView(ScreenEvent.DIALPAD, this);
    ft.commit();

    if (animate) {
        mFloatingActionButtonController.scaleOut();
    } else {
        mFloatingActionButtonController.setVisible(false);
        maybeEnterSearchUi();
    }
    mActionBarController.onDialpadUp();

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

    //adjust the title, so the user will know where we're at when the activity start/resumes.
    setTitle(R.string.launcherDialpadActivityLabel);
}

From source file:com.geecko.QuickLyric.MainActivity.java

private LyricsViewFragment init(FragmentManager fragmentManager, boolean startEmpty) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) fragmentManager
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment == null || lyricsViewFragment.isDetached())
        lyricsViewFragment = new LyricsViewFragment();
    lyricsViewFragment.startEmpty(startEmpty);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.animator.slide_in_end, R.animator.slide_out_start,
            R.animator.slide_in_start, R.animator.slide_out_end);
    if (!lyricsViewFragment.isAdded()) {
        fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }//  www. java  2  s.  com

    Fragment[] activeFragments = getActiveFragments();
    displayedFragment = getDisplayedFragment(activeFragments);

    for (Fragment fragment : activeFragments)
        if (fragment != null) {
            if (fragment != displayedFragment && !fragment.isHidden()) {
                fragmentTransaction.hide(fragment);
                fragment.onHiddenChanged(true);
            } else if (fragment == displayedFragment)
                fragmentTransaction.show(fragment);
        }
    fragmentTransaction.commit();
    return lyricsViewFragment;
}

From source file:itcr.gitsnes.MainActivity.java

/**
 * OnCreate methods do that things://  w ww . j  a  v  a2  s .  com
 *      - Inflate Login formulary frame (hide action bar)
 *      - Init Accelerometer intent (onShake)
 *      - Create login method (auth with FB)
 *      - Handle exceptions of previously methods
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* -- Shows action bar and inflate main Listview from JSON (see BackendHandler) --- */
    getActionBar().hide();
    setContentView(R.layout.activity_main);
    FragmentManager fm = getFragmentManager();
    FragmentTransaction transaction = fm.beginTransaction();

    /* Add transaction and login FB intent to mainActivity*/
    Login login = new Login();
    transaction.add(R.id.placeholder, login).commit();

    /* Init shake sensor and create event to get random game from DB (Backend on app-engine)*/
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mShakeDetector = new ShakeDetector();
    mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeListener() {

        @Override
        public void onShake(int count) {
            /* Inflate random-game detail */
            Toast.makeText(getApplicationContext(), "Buscando juego aleatorio!!", Toast.LENGTH_SHORT).show();
            MasterGames new_fragment = new MasterGames(json_arr);
            new_fragment.setRandomgame("random");
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.placeholder, new_fragment);
            transaction.addToBackStack(null);
            transaction.commit();

        }
    });

    mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);

    /*Initialize FB API helper methods and listen callback from fb_loginbutton*/

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
    authButton = (LoginButton) findViewById(R.id.authButton);
    authButton.setOnErrorListener(new LoginButton.OnErrorListener() {
        @Override
        public void onError(FacebookException error) {
            Log.i(TAG, "Error " + error.getMessage());
        }
    });

    /*Obtaining data from successfully FB API callback using GraphUser*/
    authButton.setReadPermissions(Arrays.asList("email"));
    authButton.setSessionStatusCallback(new Session.StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
            Log.i(TAG, "Accesssss Token");
            if (session.isOpened()) {
                Log.i(TAG, "Access Token" + session.getAccessToken());
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            Log.i(TAG, "User ID " + user.getId());
                            Log.i(TAG, "Email " + user.asMap().get("email"));
                            /* Inflate main-Listview from JSON (see BackendHandler) and saving current user*/
                            back_stage();
                            getActionBar().show();
                            KS.setCurrent_user(user.asMap().get("email").toString());
                            Toast.makeText(getApplicationContext(), "Welcome!! " + KS.getCurrent_user(),
                                    Toast.LENGTH_SHORT).show();
                            new BackendHandler().sendUser(KS.getCurrent_user(),
                                    user.asMap().get("email").toString());
                            //lblEmail.setText(user.asMap().get("email").toString());
                        }
                    }
                });
            } else
                Log.i(TAG, "Nopes Token");
        }
    });
}

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   www  .j a  v  a  2 s . c o  m*/
        } 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.concentricsky.android.khanacademy.app.VideoDetailActivity.java

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

    if (captionFragment != null) {
        tx.remove(captionFragment);//from   ww  w .  j a v  a 2s  .  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.concentricsky.android.khanacademy.app.VideoDetailActivity.java

private void setupUIForCurrentVideo() {
    if (videoFragment != null) {
        videoFragment.dispose();/* w  ww  .j  a  va  2 s. c  o  m*/
    }

    Bundle args = new Bundle();
    args.putString(Constants.PARAM_VIDEO_ID, videoId);

    videoFragment = new VideoFragment();
    videoFragment.registerCallbacks(this);
    videoFragment.setArguments(args);

    FragmentTransaction tx = getFragmentManager().beginTransaction().replace(R.id.video_fragment_container,
            videoFragment, TAG_VIDEO_FRAGMENT);

    currentOrientation = getResources().getConfiguration().orientation;
    onOrientationChanged(currentOrientation);

    if (isPortrait()) {
        captionFragment = new CaptionFragment();
        captionFragment.registerCallbacks(this);
        if (userVideo != null && userVideo.getUser() != null) {
            args.putInt(PARAM_USERVIDEO_POINTS, userVideo.getPoints());
        }
        captionFragment.setArguments(args);

        tx.replace(R.id.detail_bottom_container, captionFragment, TAG_CAPTION_FRAGMENT);
    }

    tx.commit();
}

From source file:org.symptomcheck.capstone.ui.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mUser = DAOManager.get().getUser();/*from www  . j  a  v a  2s  .  c om*/

    setContentView(R.layout.activity_settings);

    toolbar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);
    toolbarTitle = (TextView) findViewById(R.id.txt_toolbar_title);
    mToolBarImageView = (ImageView) findViewById(R.id.imageToolBar);
    // enable ActionBar app icon to behave as action to toggle nav drawer
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
    }

    if (toolbarTitle != null)
        toolbarTitle.setText(getString(R.string.action_settings));
    // Display the fragment as the main content.
    if (mToolBarImageView != null) {
        mToolBarImageView.setVisibility(View.GONE);
        //mToolBarImageView.setOval(false);
        Picasso.with(this).load(R.drawable.ic_action_settings)
                //.resize(96, 96)
                //.centerCrop()
                //.transform(transformation)
                .into(mToolBarImageView);
    }
    // here we would customize Settings Screen according to User type (PATIENT, DOCTOR, ADMIN)
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    if (mUser != null) {
        //TODO#BPR_1
        switch (mUser.getUserType()) {
        case PATIENT:
            fragmentTransaction
                    .replace(R.id.content_settings_checkin_reminder, new CheckInReminderPreferenceFragment()) //TODO#FDAR_2
                    .replace(R.id.content_settings_data_sync, new DataSyncPreferenceFragment())
                    .replace(R.id.content_settings_notification, new NotificationPreferenceFragment());
            break;
        case DOCTOR:
            fragmentTransaction.replace(R.id.content_settings_data_sync, new DataSyncPreferenceFragment())
                    .replace(R.id.content_settings_notification, new NotificationPreferenceFragment());
            break;
        case ADMIN:
            fragmentTransaction
                    .replace(R.id.content_settings_checkin_reminder, new CheckInReminderPreferenceFragment())
                    .replace(R.id.content_settings_data_sync, new DataSyncPreferenceFragment())
                    .replace(R.id.content_settings_notification, new NotificationPreferenceFragment());
            break;
        case UNKNOWN:
            fragmentTransaction.replace(R.id.content_settings_notification,
                    new NotificationPreferenceFragment());
            break;
        }
    } else {
        fragmentTransaction.replace(R.id.content_settings_notification, new NotificationPreferenceFragment());
    }
    fragmentTransaction.commit();
}

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.// w ww .ja v a  2  s.  c  o m
 */
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:org.opendatakit.survey.android.activities.MainMenuActivity.java

public void swapToFragmentView(ScreenList newFragment) {
    WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView: " + newFragment.toString());
    FragmentManager mgr = getFragmentManager();
    Fragment f;/*  w  ww  .  ja  v a2 s .co m*/
    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.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();
    }
}