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.example.android.cloudnotes.ui.HomeActivity.java

/**
 * This method controls both fragments, instructing them to display a
 * certain note./*from w w  w. j a  va 2  s .  c om*/
 * 
 * @param noteUri The {@link Uri} of the note to show. To create a new note,
 *            pass {@code null}.
 */
private void showNote(final Uri noteUri) {

    if (mTwoPaneView) {
        // check if the NoteEditFragment has been added
        FragmentManager fm = getFragmentManager();
        NoteEditFragment edit = (NoteEditFragment) fm.findFragmentByTag(NOTE_EDIT_TAG);
        final boolean editNoteAdded = (edit != null);

        if (editNoteAdded) {
            if (edit.mCurrentNote != null && edit.mCurrentNote.equals(noteUri)) {
                // clicked on the currently selected note
                return;
            }

            NoteEditFragment editFrag = (NoteEditFragment) fm.findFragmentByTag(NOTE_EDIT_TAG);
            if (noteUri != null) {
                // load an existing note
                editFrag.loadNote(noteUri);
                NoteListFragment list = (NoteListFragment) fm.findFragmentById(R.id.list);
                list.setActivatedNote(Long.valueOf(noteUri.getLastPathSegment()));
            } else {
                // creating a new note - clear the form & list
                // activation
                if (editNoteAdded) {
                    editFrag.clear();
                }
                NoteListFragment list = (NoteListFragment) fm.findFragmentById(R.id.list);
                list.clearActivation();
            }
        } else {
            // add the NoteEditFragment to the container
            FragmentTransaction ft = fm.beginTransaction();
            edit = new NoteEditFragment();
            ft.add(R.id.note_detail_container, edit, NOTE_EDIT_TAG);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            ft.commit();
            edit.loadNote(noteUri);
        }
    } else {
        startActivity(new Intent(NoteEditFragment.ACTION_VIEW_NOTE, noteUri));
    }
}

From source file:com.tozny.e3db.android.DefaultKeyAuthenticator.java

@RequiresApi(api = Build.VERSION_CODES.M)
@Override//  w ww  . java 2s  .  c o m
public void authenticateWithLockScreen(AuthenticateHandler cont) {
    DeviceCredentialsFragment f = new DeviceCredentialsFragment(cont, title,
            (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE));
    FragmentManager fragmentManager = activity.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(f, "device_credentials_fragment");
    fragmentTransaction.commit();
}

From source file:com.sitewhere.android.example.MainActivity.java

/**
 * Adds the connectivity wizard if preferences have not been set.
 *///  w  w  w . j a  va 2  s  . co m
protected void initExampleApplication() {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    example = new ExampleFragment();
    fragmentTransaction.replace(R.id.container, example);
    fragmentTransaction.commit();

    messageClient.setCallback(this);
    messageClient.connect(MqttServicePreferences.read(this));
    //getActionBar().setTitle("SiteWhere Example");
}

From source file:com.achep.acdisplay.acdisplay.AcDisplayActivity.java

/**
 * Initializes non-UI fragments such as {@link com.achep.acdisplay.fragments.PocketFragment}.
 *//*from w w w.j  a  v a2  s . co  m*/
private void initInternalFragments() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();

    // Turns screen off inside of your pocket.
    if (mConfig.isActiveModeEnabled()) {
        mPocketFragment = PocketFragment.newInstance();
        ft.add(mPocketFragment, PocketFragment.TAG);
    }

    ft.commit();
}

From source file:org.openaccessbutton.openaccessbutton.MainActivity.java

public void launchFragment(Fragment fragment, String tag, Bundle data, boolean backstack) {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment, tag);
    if (backstack) {
        fragmentTransaction.addToBackStack(tag);
    }//w  w w. java 2s  . co  m
    fragmentTransaction.commit();
}

From source file:com.albertcbraun.wifidlitedemoapp.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(int position) {
    Log.v(TAG, "onNavigationDrawerItemSelection. position:" + position);

    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();

    switch (position) {
    case 0://from   w  ww. j a v a  2  s.  co  m
        ft.replace(R.id.container, PeerListAcquisition.newInstance(position));
        break;
    case 1:
        ft.replace(R.id.container, PeerListSubscription.newInstance(position));
        break;
    case 2:
        ft.replace(R.id.container, Misc.newInstance(position));
        break;
    }

    ft.commit();
}

From source file:com.classiqo.nativeandroid_32bitz.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);//from  w  w  w  .j  a va 2 s . co 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 (mediaId != null) {
            transaction.addToBackStack(null);
        }
        transaction.commit();
    }
}

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

private void addPropertiesToPreference(PreferenceCategory mProject, JSONObject projectsObject) {
    try {/*from  ww  w.j a  v  a2 s  .co  m*/
        // 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) {
                FragmentTransaction transaction = mFragmentManager.beginTransaction();
                CommitsFragment commitFragment = new CommitsFragment(mAlertDialog, projectName);
                transaction.addToBackStack(null);
                transaction.replace(mId, commitFragment, projectName);
                transaction.commit();
                return true;
            }
        });
    } catch (JSONException badJsonRequest) {
        Log.e(TAG, "failed to parse required info about project", badJsonRequest);
    }
}

From source file:de.j4velin.pedometer.ui.Activity_Main.java

@Override
protected void onCreate(final Bundle b) {
    super.onCreate(b);
    startService(new Intent(this, SensorListener.class));
    if (b == null) {
        // Create new fragment and transaction
        Fragment newFragment = new Fragment_Overview();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this
        // fragment,
        // and add the transaction to the back stack
        transaction.replace(android.R.id.content, newFragment);

        // Commit the transaction
        transaction.commit();
    }//  ww w  . ja v  a2 s  . co m

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this, this, this);
    builder.addApi(Games.API, Games.GamesOptions.builder().build());
    builder.addScope(Games.SCOPE_GAMES);
    builder.addApi(Fitness.HISTORY_API);
    builder.addApi(Fitness.RECORDING_API);
    builder.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE));

    mGoogleApiClient = builder.build();
}

From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private void hideFragment(final Fragment fragment, final boolean removeParentView,
        final boolean addedToBackStack, final String tag) {
    final FragmentManager manager = getFragmentManager();
    if (manager.findFragmentByTag(tag) != null) {
        final FragmentTransaction transaction = manager.beginTransaction();
        transaction.remove(fragment);//from  w w w.j a v  a2 s  .  com
        transaction.commit();
        if (addedToBackStack) {
            manager.popBackStack();
        }

        final int viewId = getParentId(fragment);
        if (removeParentView && viewId != 0) {
            mContentContainer.removeBorderView(viewId);
        }
    }
}