Example usage for android.app FragmentTransaction replace

List of usage examples for android.app FragmentTransaction replace

Introduction

In this page you can find the example usage for android.app FragmentTransaction replace.

Prototype

public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment, String tag);

Source Link

Document

Replace an existing fragment that was added to a container.

Usage

From source file:com.tapchatapp.android.app.activity.MainActivity.java

public void showBuffer(int type, long connectionId, long bufferId, boolean isArchived) {
    boolean isTablet = (findViewById(R.id.content1) != null);

    if (isTablet) {
        Fragment fragment = BufferFragment.create(type, connectionId, bufferId);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.content1, fragment, "buffer");
        transaction.commit();/* w  ww . ja  va2s  .c  o  m*/
    } else {
        Intent intent = new Intent(this, BuffersActivity.class);
        Uri data = Uri.parse(String.format("tapchat://%s/%s", connectionId, bufferId));
        if (isArchived) {
            data = data.buildUpon().appendQueryParameter("display", "archived").build();
        }
        intent.setData(data);
        startActivity(intent);
    }
}

From source file:com.ppgllrd.alfil.MainActivity.java

private void selectCourse(int position) {
    Log.d("ppgllrd", "selectCourse" + position + " " + drawerSelectedIdx);
    boolean isSelectable = drawerItems.get(position) instanceof DrawerCourse;

    if (isSelectable) {
        final DrawerCourse drawerCourse = (DrawerCourse) drawerItems.get(position);
        FragmentManager fragmentManager = getFragmentManager();
        Log.d("ppgllrd", "Count:" + fragmentManager.getBackStackEntryCount());

        if (position != drawerSelectedIdx) {
            Log.d("ppgllrd", "YES");
            drawerSelectedIdx = position;

            studentsListFragment = new StudentsListFragment();
            Bundle args = new Bundle();
            args.putParcelable(StudentsListFragment.ARG_GROUP_STUDENTS_COURSE, drawerCourse.getCourse());
            studentsListFragment.setArguments(args);

            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.replace(R.id.list_Fragment_Placeholder, studentsListFragment, StudentsListFragment.FragmentTag);
            //ft.addToBackStack(StudentInfoFragment.FragmentTag);
            ft.commit();/* w  w w.  j  a  v a2 s.  c  o  m*/
        }
        Log.d("ppgllrd", "YYY");

        actionBarTitleController.closeDrawer();

        if (studentInfoFragment.isShown()) {
            FragmentManager fm = getFragmentManager();
            if (fm.getBackStackEntryCount() > 0) {
                fm.popBackStack();
            }
        }
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.show(studentsListFragment);
        ft.hide(studentInfoFragment);
        // ft.addToBackStack(StudentInfoFragment.FragmentTag);
        ft.commit();

    }
    Log.d("ppgllrd", "ZZZ");
}

From source file:com.luorrak.ouroboros.thread.ThreadActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Util.onActivityCreateSetTheme(this, SettingsHelper.getTheme(this));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_thread);
    Ion.getDefault(getApplicationContext()).getCache().setMaxSize(150 * 1024 * 1024);
    infiniteDbHelper = new InfiniteDbHelper(getApplicationContext());

    toolbar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);//from  www. j  a v a2  s . co  m

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    String resto = getIntent().getStringExtra(Util.INTENT_THREAD_NO);
    String boardName = getIntent().getStringExtra(Util.INTENT_BOARD_NAME);
    int threadPosition = getIntent().getIntExtra(Util.INTENT_THREAD_POSITION, 0);

    boolean threadVisible = false;
    if (savedInstanceState != null) {
        threadDepth = savedInstanceState.getInt("threadDepth");
        int backstackCount = getFragmentManager().getBackStackEntryCount();
        if (backstackCount > 0) {
            if (getFragmentManager().getBackStackEntryAt(backstackCount - 1).getName()
                    .equals("threadDepth" + String.valueOf(threadDepth))) {
                threadVisible = true;
            }
        }
        threadFragment = (ThreadFragment) getFragmentManager().getFragment(savedInstanceState,
                "threadDepth" + String.valueOf(threadDepth));
    } else {
        threadDepth = 0;
        threadFragment = new ThreadFragment().newInstance(resto, boardName, threadPosition);
        threadVisible = true;
    }

    if (threadVisible) {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction
                .replace(R.id.placeholder_card, threadFragment, "threadDepth" + String.valueOf(threadDepth))
                .commit();
    }

    //Watchlist Layout
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    watchList = (RecyclerView) findViewById(R.id.watch_list);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    watchList.setLayoutManager(layoutManager);

    watchListAdapter = new WatchListAdapter(infiniteDbHelper.getWatchlistCursor(), drawerLayout,
            infiniteDbHelper);
    watchList.setAdapter(watchListAdapter);

    ItemTouchHelper.Callback callback = new WatchListTouchHelper(watchListAdapter);
    ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
    touchHelper.attachToRecyclerView(watchList);
}

From source file:com.reallynourl.nourl.fmpfoldermusicplayer.ui.activity.MainActivity.java

private void loadFragmentToContent(IMainContent content) {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.content_panel, content.getFragment(), CONTENT_FRAGMENT_TAG);
    ft.commit();//  w  w  w.j  a va 2 s. c  o m
    SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(this).edit();
    edit.putString(getString(R.string.pref_last_main_content_fragment), content.getName());
    edit.apply();
    mActiveContent = content;
}

From source file:com.ternup.caddisfly.activity.MainActivity.java

/**
 * Display view fragment for selected nav drawer menu option
 */// www . java 2 s .c om
public void displayView(int position, boolean addToBackStack) {

    int index = getCurrentFragmentIndex();

    if (index == position) {
        // requested fragment is already showing
        return;
    }

    Fragment fragment;
    showCheckUpdateOption = false;
    switch (position) {
    case Globals.HOME_SCREEN_INDEX:
        if (homeFragment == null) {
            homeFragment = new HomeFragment();
        }
        fragment = homeFragment;
        break;
    case Globals.LOCATION_LIST_SCREEN_INDEX:
        if (mLocationListFragment == null) {
            mLocationListFragment = new LocationListFragment();
        }
        fragment = mLocationListFragment;
        break;
    case Globals.CALIBRATE_SCREEN_INDEX:
        if (calibrateFragment == null) {
            calibrateFragment = new CalibrateFragment();
        }
        fragment = calibrateFragment;
        break;
    case Globals.SETTINGS_SCREEN_INDEX:
        showCheckUpdateOption = true;
        if (settingsFragment == null) {
            settingsFragment = new SettingsFragment();
        }
        fragment = settingsFragment;
        break;
    case Globals.HELP_SCREEN_INDEX:
        showCheckUpdateOption = true;
        if (helpFragment == null) {
            helpFragment = new HelpFragment();
        }
        fragment = helpFragment;
        break;
    case Globals.ABOUT_SCREEN_INDEX:
        showCheckUpdateOption = true;
        if (aboutFragment == null) {
            aboutFragment = new AboutItFragment();
        }
        fragment = aboutFragment;
        break;
    default:
        toggleTheme();
        return;
    }
    invalidateOptionsMenu();
    if (fragment != null) {

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.replace(R.id.container, fragment, String.valueOf(position));
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        if (addToBackStack) {
            ft.addToBackStack(null);
        }
        ft.commit();
    }
    mNavigationDrawerFragment.checkItem(position);
}

From source file:ua.boberproduction.bbr.notes.NoteEditorFragment.java

@Override
public void showNote() {
    // put data into bundle
    Bundle bundle = new Bundle();
    bundle.putInt(getString(R.string.tag_noteId), note.getId());
    bundle.putString(getString(R.string.tag_articleid), note.getArticleId());
    bundle.putString(getString(R.string.notes_title), note.getTitle());
    bundle.putString(getString(R.string.notes_note_content), note.getText());
    // create and display fragment
    Fragment fragment = new NoteViewerFragment();
    fragment.setArguments(bundle);/*w ww . j  a v  a2 s.co  m*/
    FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.animator.slide_in_right, R.animator.slide_out_left, R.animator.slide_in_left,
            R.animator.slide_out_right);
    ft.replace(R.id.main_frame, fragment, getString(R.string.tag_content_fragment)).addToBackStack("edit")
            .commit();
}

From source file:at.tugraz.ist.akm.activities.MainActivity.java

private void fragmentTransaction(String fragmentTag) {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    mCurrentFragment = Fragment.instantiate(MainActivity.this, fragmentTag);
    transaction.replace(R.id.navigation_drawer_content_frame, mCurrentFragment, fragmentTag);
    transaction.commit();/*from   w  w w  . j a  v a  2 s  .co m*/
}

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 www.ja  v  a  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:me.pzheng.conn.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {

        FragmentManager fm = getFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        Fragment fragment;/*from   w ww.  j a va 2s .  c  o m*/
        fragment = fm.findFragmentByTag(SettingsFragment.TAG);
        if (fragment == null) {
            fragment = new SettingsFragment();
        }
        transaction.replace(R.id.container, fragment, SettingsFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();
        return true;
    }

    return super.onOptionsItemSelected(item);
}

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);
    }//  ww  w.  j  a v a 2 s.  c  o m
    fragmentTransaction.commit();
}