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.esri.android.mapsapp.MapsAppActivity.java

/**
 * Opens the map represented by the specified portal item or if null, opens
 * a default map./*  ww w. j a v a2s.  co 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();

    invalidateOptionsMenu(); // reload the options menu
}

From source file:com.antew.redditinpictures.library.ui.RedditFragmentActivity.java

private void initializeActiveView() {
    switch (mActiveViewType) {
    case GRID://from   ww  w. jav  a  2 s  . co  m
        EasyTracker.getInstance(this)
                .send(MapBuilder
                        .createEvent(Constants.Analytics.Category.INITIALIZE,
                                Constants.Analytics.Action.IMAGE_VIEW, Constants.Analytics.Label.GRID, null)
                        .build());
        FragmentTransaction gridTrans = getFragmentManager().beginTransaction();
        gridTrans.replace(R.id.content_fragment, getNewImageGridFragment());
        gridTrans.commit();
        break;
    case LIST:
        EasyTracker.getInstance(this)
                .send(MapBuilder
                        .createEvent(Constants.Analytics.Category.INITIALIZE,
                                Constants.Analytics.Action.IMAGE_VIEW, Constants.Analytics.Label.LIST, null)
                        .build());
        FragmentTransaction listTrans = getFragmentManager().beginTransaction();
        listTrans.replace(R.id.content_fragment, getNewImageListFragment());
        listTrans.commit();
        break;
    }
}

From source file:com.example.android.AudioArchive.ui.MusicPlayerActivity.java

private void navigateToBrowser(String mediaId) {
    LogHelper.d(TAG, "navigateToBrowser, mediaId=" + mediaId);
    MediaBrowserFragment fragment = getBrowseFragment();

    if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) {
        fragment = new MediaBrowserFragment();
        fragment.setMediaId(mediaId);/*w ww .ja v a 2 s  . c  o m*/
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left,
                R.animator.slide_in_from_left, R.animator.slide_out_to_right);
        transaction.replace(R.id.container, fragment, FRAGMENT_TAG);
        // If this is not the top level media (root), we add it to the fragment back stack,
        // so that actionbar toggle and Back will work appropriately:
        if (mediaId != null) {
            transaction.addToBackStack(null);
        }
        transaction.commit();
    }
}

From source file:com.antew.redditinpictures.library.ui.RedditFragmentActivity.java

private void changeViewType(ViewType viewType) {
    if (viewType != null) {
        mActiveViewType = viewType;/*w  w w  .j  a v  a  2 s .  co m*/
        switch (mActiveViewType) {
        case GRID:
            FragmentTransaction gridTrans = getFragmentManager().beginTransaction();
            gridTrans.replace(R.id.content_fragment, getNewImageGridFragment());
            gridTrans.commit();
            invalidateOptionsMenu();
            break;
        case LIST:
            FragmentTransaction listTrans = getFragmentManager().beginTransaction();
            listTrans.replace(R.id.content_fragment, getNewImageListFragment());
            listTrans.commit();
            invalidateOptionsMenu();
            break;
        }
    }
}

From source file:com.aokp.romcontrol.github.tasks.DisplayProjectsListTask.java

private void loadProjectsToArray(JSONArray repoProjectsArray) {
    // scroll through each item in array (projects in repo organization)
    for (int i = 0; i < repoProjectsArray.length(); i++) {
        try {/*from   ww w . j  a v  a 2  s. c o  m*/
            final JSONObject projectsObject = (JSONObject) repoProjectsArray.get(i);
            final Preference mProject = mCategory.getPreferenceManager().createPreferenceScreen(mContext);
            // extract info about each project
            final String projectName = projectsObject.getString("name");
            String projectDescription = projectsObject.getString("description");
            int githubProjectId = projectsObject.getInt("id");
            // apply info to our preference screen
            mProject.setKey(projectName);
            if (projectDescription.contains("") || projectDescription == null) {
                mProject.setTitle(projectName);
                mProject.setSummary(projectDescription);
            } else {
                mProject.setTitle(projectDescription);
                mProject.setSummary(projectName);
            }
            mProject.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference p) {
                    AlertDialog.Builder adb = new AlertDialog.Builder(mAlertDialog.getContext());
                    if (!mFavPackagesStorage.isFavProject(projectName)) {
                        adb.setNegativeButton(R.string.changelog_add_to_favs_list,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Log.d(TAG, "fav packages size=="
                                                + mFavPackagesStorage.getFavProjects().size());
                                        if (mFavPackagesStorage.getFavProjects().size() > 0) {
                                            mPreferenceScreen.addPreference(mFavProjects);
                                        }
                                        mFavPackagesStorage.addProject(projectName);
                                        mCategory.removePreference(mProject);
                                        mFavProjects.addPreference(mProject);
                                    }
                                }).setMessage(R.string.add_favs_or_view);
                    } else {
                        adb.setNegativeButton(R.string.changelog_remove_from_favs_list,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        mFavPackagesStorage.removeProject(projectName);
                                        mFavProjects.removePreference(mProject);
                                        mCategory.addPreference(mProject);
                                        Log.d(TAG, "fav packages size=="
                                                + mFavPackagesStorage.getFavProjects().size());
                                        if (mFavPackagesStorage.getFavProjects().size() == 1) {
                                            mPreferenceScreen.removePreference(mFavProjects);
                                        }
                                    }
                                }).setMessage(R.string.remove_favs_or_view);
                    }
                    adb.setPositiveButton(R.string.changelog_view_commits,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    FragmentTransaction transaction = mFragmentManager.beginTransaction();
                                    CommitsFragment commitFragment = new CommitsFragment(mAlertDialog,
                                            projectName);
                                    transaction.addToBackStack(null);
                                    transaction.replace(mId, commitFragment, projectName);
                                    transaction.commit();
                                }
                            }).create().show();
                    return true;
                }
            });
            if (mFavPackagesStorage.isFavProject(projectName)) {
                if (mFavProjects.findPreference(projectName) == null) {
                    Log.d(TAG, "found Favorite Project: " + projectName);
                    mFavProjects.addPreference(mProject);
                }
            } else {
                if (DEBUG)
                    Log.d(TAG, "adding normal project: " + projectName);
                mCategory.addPreference(mProject);
            }
        } catch (JSONException badJsonRequest) {
            Log.e(TAG, "failed to parse required info about project", badJsonRequest);
        }
    }
    if (mFavPackagesStorage.getFavProjects().size() > 0)
        mPreferenceScreen.addPreference(mFavProjects);
}

From source file:blackman.matt.infinitebrowser.InfinityBrowser.java

/**
 * Creates a new board for a post when reply button is hit.
 *
 * @param boardRoot Link to the thread to open up
 * @param threadNo Thread no being opened
 *//*from   w w w.j av  a  2 s  . c  om*/
@Override
public void onReplyClicked(String boardRoot, String threadNo) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    Boolean ageAccept = preferences.getBoolean("age_guard_accept", false);

    if (ageAccept) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        LinearLayout helpText = (LinearLayout) findViewById(R.id.ll_help_add_boards);

        Board newThread = Board.newInstance(boardRoot, threadNo);

        fragmentTransaction.replace(R.id.container, newThread, threadNo);
        fragmentTransaction.addToBackStack(null);

        fragmentTransaction.commit();

        helpText.setVisibility(View.GONE);
        mTitle = boardRoot.replace("https://8chan.co", "") + threadNo;
        setTitle(mTitle);
    }
}

From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = TaipeiFragment.newInstance(position);

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.content_frame, fragment);
    ft.commit();/*  ww  w .j  a  v a 2s .c  om*/

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

From source file:xyz.sahildave.widget.SearchViewLayout.java

private void showContentFragment() {
    final FragmentTransaction transaction = mFragmentManager.beginTransaction();
    transaction.setCustomAnimations(R.animator.fade_in, R.animator.fade_out);
    transaction.replace(R.id.search_expanded_content, mExpandedContentFragment);
    mExpandedContentFragment.setHasOptionsMenu(false);
    transaction.commit();
}

From source file:com.android.calendar.SearchActivity.java

private void showEventInfo(EventInfo event) {
    if (mShowEventDetailsWithAgenda) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();

        mEventInfoFragment = new EventInfoFragment(this, event.id, event.startTime.toMillis(false),
                event.endTime.toMillis(false), event.getResponse(), false,
                EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */);
        ft.replace(R.id.agenda_event_info, mEventInfoFragment);
        ft.commit();
    } else {/*  w  w w  .j a v  a  2 s  .c  o  m*/
        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.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime != null ? event.startTime.toMillis(true) : -1);
        intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime != null ? event.endTime.toMillis(true) : -1);
        startActivity(intent);
    }
    mCurrentEventId = event.id;
}

From source file:com.silentcircle.silenttext.activity.AccountCreationActivity.java

@Override
public void onNext(Fragment fragment) {
    FragmentTransaction tx = getFragmentManager().beginTransaction();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        tx.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left,
                R.animator.slide_in_from_left, R.animator.slide_out_to_right);
    }/*from   ww w.  j av a  2  s .com*/

    if (tx.isAddToBackStackAllowed()) {
        tx.addToBackStack(null);
    }
    tx.replace(R.id.content, fragment);
    tx.commit();
}