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);

Source Link

Document

Calls #replace(int,Fragment,String) with a null tag.

Usage

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  w w  w  . j  a  v a 2s.  c  om

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

From source file:de.sourcestream.movieDB.controller.CastDetailsInfo.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    activity.getCastDetailsFragment().showInstantToolbar();
    activity.setCastDetailsFragment(null);
    activity.setRestoreMovieDetailsAdapterState(true);
    activity.setRestoreMovieDetailsState(false);

    if (knownList.get(position).getMediaType().equals("movie")) {
        if (activity.getMovieDetailsFragment() != null
                && activity.getLastVisitedMovieInCredits() == knownList.get(position).getId()
                && activity.getMovieDetailsFragment().getTimeOut() == 0) {
            // Old movie details retrieve info and re-init component else crash
            activity.getMovieDetailsFragment().onSaveInstanceState(new Bundle());
            Bundle bundle = new Bundle();
            bundle.putInt("id", knownList.get(position).getId());
            Bundle save = activity.getMovieDetailsFragment().getSave();
            // Re-init movie details and set save information
            movieDetails = new MovieDetails();
            movieDetails.setTimeOut(0);/*from   w w  w  . j av  a 2 s .  co m*/
            movieDetails.setSave(save);
            movieDetails.setArguments(bundle);
        } else
            movieDetails = new MovieDetails();
    }

    if (knownList.get(position).getMediaType().equals("tv")) {
        if (activity.getTvDetailsFragment() != null
                && activity.getLastVisitedMovieInCredits() == knownList.get(position).getId()
                && activity.getTvDetailsFragment().getTimeOut() == 0) {
            // Old movie details retrieve info and re-init component else crash
            activity.getTvDetailsFragment().onSaveInstanceState(new Bundle());
            Bundle bundle = new Bundle();
            bundle.putInt("id", knownList.get(position).getId());
            Bundle save = activity.getTvDetailsFragment().getSave();
            // Re-init movie details and set save information
            tvDetails = new TVDetails();
            tvDetails.setTimeOut(0);
            tvDetails.setSave(save);
            tvDetails.setArguments(bundle);
        } else
            tvDetails = new TVDetails();
    }

    activity.setLastVisitedMovieInCredits(knownList.get(position).getId());
    ((CastDetails) getParentFragment()).setAddToBackStack(true);
    getParentFragment().onSaveInstanceState(new Bundle());
    if (activity.getSearchViewCount())
        activity.incSearchCastDetails();

    FragmentManager manager = getActivity().getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle bundle = new Bundle();
    bundle.putInt("id", knownList.get(position).getId());

    if (knownList.get(position).getMediaType().equals("movie")) {
        movieDetails.setTitle(knownList.get(position).getTitle());
        movieDetails.setArguments(bundle);
        transaction.replace(R.id.frame_container, movieDetails);
    }
    if (knownList.get(position).getMediaType().equals("tv")) {
        tvDetails.setTitle(knownList.get(position).getTitle());
        tvDetails.setArguments(bundle);
        transaction.replace(R.id.frame_container, tvDetails);
    }
    // add the current transaction to the back stack:
    transaction.addToBackStack("castDetails");
    transaction.commit();

}

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addAdminFragment() {
    Fragment frag = null;//from   w  w w  . j  a va  2s.  c o  m
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    NavigationView navigationView;
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.inflateMenu(R.menu.nav_menu_admin);
    frag = new AdminFragment();
    toolbar.setVisibility(View.VISIBLE);

    fragmentTransaction.replace(R.id.fragment_container, frag);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

From source file:com.jlabs.peepaid.searchviewlay.SearchViewLayout.java

private void showContentFragment() {
    if (mFragmentManager != null) {
        final android.app.FragmentTransaction transaction = mFragmentManager.beginTransaction();
        transaction.setCustomAnimations(R.animator.fade_in_object_animator,
                R.animator.fade_out_object_animator);
        transaction.replace(R.id.search_expanded_content, mExpandedContentFragment);
        transaction.commit();/*from  w  w w.  ja v  a 2  s .  c om*/
    } else if (mSupportFragmentManager != null) {
        final android.support.v4.app.FragmentTransaction transaction = mSupportFragmentManager
                .beginTransaction();
        transaction.setCustomAnimations(R.anim.fade_in_anim_set, R.anim.fade_out_anim_set);
        transaction.replace(R.id.search_expanded_content, mExpandedContentSupportFragment);
        transaction.commit();
    }
}

From source file:itcr.gitsnes.MainActivity.java

/**
 *  Methods inflate menu options panel/*w w w  . j  av a 2 s . c  o m*/
 *  Params:
 *      - [menu]
 *  Returns:
 *      - State of building [true]
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /* Inflate the menu; this adds items to the action bar if it is present. */
    getMenuInflater().inflate(R.menu.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    if (null != searchView) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered
            // Log.i("log_tag",newText);

            return true;
        }

        public boolean onQueryTextSubmit(String query) {
            Log.i("log_tag", query);

            MasterGames new_fragment = new MasterGames(json_arr);
            new_fragment.setQname(query);

            RelativeLayout rl = (RelativeLayout) findViewById(R.id.mainback);
            rl.setBackgroundColor(Color.parseColor("#009f28"));
            authButton.setVisibility(View.INVISIBLE);

            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.placeholder, new_fragment);
            transaction.addToBackStack(null);
            transaction.commit();

            return true;

        }
    };

    searchView.setOnQueryTextListener(queryTextListener);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.hufeiya.SignIn.activity.QuizActivity.java

private void inflateFragment() {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (AsyncHttpHelper.user.getUserType()) {//student
        if (category.getId().equals("addcourse")) {

        } else {/*w  w  w .  j a v  a  2 s .com*/
            courseInfoFragment = CourseInfoFragment.newInstance(category.getName());
            transaction.replace(R.id.content, courseInfoFragment);
        }

    } else {//teacher

    }
    transaction.commit();
}

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addClientFragment() {
    Fragment frag = null;/*  w  w  w . j a  v a  2s  . c o  m*/
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (navigationView == null) {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.inflateMenu(R.menu.nav_menu_client);
        toolbar.setVisibility(View.VISIBLE);
    }

    frag = new ClientFragment();

    fragmentTransaction.replace(R.id.fragment_container, frag);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();

}

From source file:ua.boberproduction.bbr.BaseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_settings) {
        startActivity(new Intent(this, EditPreferencesActivity.class));
        return true;

    } else if (id == R.id.action_rate_app) {
        final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
        try {//from w  w w . java 2s.co  m
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
        }
    } else if (id == R.id.action_feedback) {
        FragmentTransaction ft = this.getFragmentManager().beginTransaction();
        FeedbackFragment fragment = new FeedbackFragment();
        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).addToBackStack(null).commit();
    } else if (id == R.id.action_remove_ads) {
        // if Google Services are available, launch the billing. If not, show error message.
        // Showing status
        if (isGoogleServicesAvailable())
            billing.purchaseRemoveAds();
        else
            Toast.makeText(this, getString(R.string.toast_error_google_services_unavailable),
                    Toast.LENGTH_SHORT).show();
    }

    return drawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
}

From source file:com.cdhxqh.inventorymovement.ui.MainActivity.java

/**
 * *//  w  ww .  ja  v  a2  s . c o  m
 */
private void defaultShowItem() {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    if (newItemFragment == null) {
        newItemFragment = new ItemFragment();
        Bundle bundle = new Bundle();
        bundle.putString("text", adapter.getTitle(0));
        newItemFragment.setArguments(bundle);
    }
    fragmentTransaction.replace(R.id.content_frame, newItemFragment).commit();
    drawer.closeDrawer(mDrawerList);
}

From source file:ua.boberproduction.bbr.BaseActivity.java

public void openCategory(int id, String category) {
    // Check if there are any subcategories for the chosen category.
    Observable.fromCallable(() -> SQLiteStructureRepository.getInstance().getChapters(id))
            .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).doOnError((e) -> {
                Log.e(BBRApplication.TAG_BBR, "Error getting category list.", e);
                Utils.toastError(this, getString(R.string.error_loading_categories), Toast.LENGTH_SHORT);
            }).subscribe((categories) -> {
                Fragment fragment;/*from  w w  w . jav  a  2 s  .  c om*/
                Bundle bundle = new Bundle();
                // If there are, load another ListMenuFragment.
                // Also, it will need the 'parent' category to put it into the actionBar's subtitle, so we're putting it into the bundle.
                if (categories.size() > 0) {
                    fragment = new ListMenuFragment();
                } else
                    // If not, load content.
                    fragment = new TextContentFragment();

                // put the clicked category name into a bundle, and put the bundle into the fragment
                bundle.putInt(getString(R.string.tag_category_id), id);
                bundle.putString(getString(R.string.tag_category), category);
                FragmentTransaction ft = this.getFragmentManager().beginTransaction();
                fragment.setArguments(bundle);
                //set sliding animations
                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).addToBackStack(null).commit();
                this.getFragmentManager().executePendingTransactions();
            });
}