Example usage for android.support.v4.app FragmentTransaction commitAllowingStateLoss

List of usage examples for android.support.v4.app FragmentTransaction commitAllowingStateLoss

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction commitAllowingStateLoss.

Prototype

public abstract int commitAllowingStateLoss();

Source Link

Document

Like #commit but allows the commit to be executed after an activity's state is saved.

Usage

From source file:com.common.base.FragmentTabHost.java

public void initAllTabView() {

    FragmentTransaction ft = null;

    if (ft == null) {
        ft = mFragmentManager.beginTransaction();
    }//from   w w w  .ja va  2s. c o m

    TabInfo newTab = null;

    for (int i = 0; i < mTabs.size(); i++) {
        if (mTabs.get(i).fragment == null) {
            newTab = mTabs.get(i);
            newTab.fragment = Fragment.instantiate(mContext, newTab.clss.getName(), newTab.args);
            ft.add(mContainerId, newTab.fragment, newTab.tag);
        }
    }
    ft.commitAllowingStateLoss();

}

From source file:com.dm.material.dashboard.candybar.fragments.IconsBaseFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_search, menu);
    MenuItem search = menu.findItem(R.id.menu_search);

    MenuItemCompat.setOnActionExpandListener(search, new MenuItemCompat.OnActionExpandListener() {
        @Override//w w  w . j a v  a  2  s  . c  o  m
        public boolean onMenuItemActionExpand(MenuItem item) {
            FragmentManager fm = getActivity().getSupportFragmentManager();
            if (fm == null)
                return false;

            setHasOptionsMenu(false);
            View view = getActivity().findViewById(R.id.shadow);
            if (view != null)
                view.animate().translationY(-mTabLayout.getHeight()).setDuration(200).start();
            mTabLayout.animate().translationY(-mTabLayout.getHeight()).setDuration(200)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(android.animation.Animator animation) {
                            super.onAnimationEnd(animation);
                            Fragment prev = fm.findFragmentByTag("home");
                            if (prev != null)
                                return;

                            PagerIconsAdapter adapter = (PagerIconsAdapter) mPager.getAdapter();
                            if (adapter == null)
                                return;

                            SearchListener listener = (SearchListener) getActivity();
                            listener.onSearchExpanded(true);

                            FragmentTransaction ft = fm.beginTransaction()
                                    .replace(R.id.container, new IconsSearchFragment(), IconsSearchFragment.TAG)
                                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                                    .addToBackStack(null);

                            try {
                                ft.commit();
                            } catch (Exception e) {
                                ft.commitAllowingStateLoss();
                            }
                        }
                    }).start();

            return false;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            return true;
        }
    });
}

From source file:org.gluu.super_gluu.app.GluuMainActivity.java

public void doQrRequest(OxPush2Request oxPush2Request) {
    if (!validateOxPush2Request(oxPush2Request)) {
        return;/* w ww . j  a v a2s  .  c o m*/
    }
    Settings.setPushDataEmpty(getApplicationContext());
    NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancel(GluuMainActivity.MESSAGE_NOTIFICATION_ID);
    final ProcessManager processManager = createProcessManager(oxPush2Request);
    ApproveDenyFragment approveDenyFragment = new ApproveDenyFragment();
    approveDenyFragment.setIsUserInfo(false);
    approveDenyFragment.setPush2Request(oxPush2Request);
    approveDenyFragment.setListener(new RequestProcessListener() {
        @Override
        public void onApprove() {
            processManager.onOxPushRequest(false);
            //Show tab again
            tabLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
        }

        @Override
        public void onDeny() {
            processManager.onOxPushRequest(true);
            //Show tab again
            tabLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
        }
    });
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.main_root_frame, approveDenyFragment);
    transaction.addToBackStack(null);
    transaction.commitAllowingStateLoss();
    //To hide tabs
    tabLayout.getLayoutParams().height = 0;
}

From source file:com.odoo.MainActivity.java

@Override
public void startDetailFragment(Fragment fragment) {
    Log.d(TAG, "MainActivity->FragmentListener->startDetailFragment()");
    int container_id = (isTwoPane()) ? R.id.fragment_detail_container : R.id.fragment_container;
    FragmentTransaction tran = mFragment.beginTransaction().replace(container_id, fragment, "detail_fragment");
    tran.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    if (!isTwoPane()) {
        tran.addToBackStack(null);/*  w w  w  . j a  va2  s. c o  m*/
        tran.commit();
    } else {
        findViewById(R.id.fragment_detail_container).setVisibility(View.VISIBLE);
        tran.commitAllowingStateLoss();
    }
}

From source file:nl.hnogames.domoticz.MainActivity.java

/**
 * Adds the items to the drawer and registers a click listener on the items
 *///from   w w w  .ja v  a2  s. c  o m
private void addDrawerItems() {
    String[] drawerActions = mSharedPrefs.getNavigationActions();
    fragments = mSharedPrefs.getNavigationFragments();
    int ICONS[] = mSharedPrefs.getNavigationIcons();

    String NAME = getString(R.string.app_name_domoticz);
    String WEBSITE = getString(R.string.domoticz_url);
    int PROFILE = R.drawable.ic_launcher;

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView);
    mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size

    mAdapter = new NavigationAdapter(drawerActions, ICONS, NAME, WEBSITE, PROFILE, this); // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
    mRecyclerView.setAdapter(mAdapter);

    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager

    final GestureDetector mGestureDetector = new GestureDetector(MainActivity.this,
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return true;
                }
            });

    mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
            View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());

            if (child != null && mGestureDetector.onTouchEvent(motionEvent)) {
                try {
                    searchViewAction.setQuery("", false);
                    searchViewAction.clearFocus();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                try {
                    FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
                    //tx.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
                    tx.replace(R.id.main, Fragment.instantiate(MainActivity.this,
                            fragments[recyclerView.getChildPosition(child) - 1]));
                    tx.commitAllowingStateLoss();
                    addFragmentStack(fragments[recyclerView.getChildPosition(child) - 1]);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                invalidateOptionsMenu();
                mDrawer.closeDrawer(GravityCompat.START);

                return true;
            }

            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });

    setupDrawer();
}

From source file:com.umeng.comm.ui.activities.BaseFragmentActivity.java

/**
 * fragmentShowcontainer,?mFragmentContainer
 * ?Fragment?Fragment//w w w.j  a va2 s . c o  m
 * 
 * @param container
 * @param fragmentShow
 */
public void showFragmentInContainer(int container, Fragment fragmentShow) {
    checkContainer();

    if (mCurrentFragment != fragmentShow) {
        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        if (mCurrentFragment != null) {
            // ???Fragment
            transaction.hide(mCurrentFragment);
        }
        // ???Fragment
        if (mFragmentManager.findFragmentByTag(fragmentShow.getClass().getName()) == null) {
            transaction.add(container, fragmentShow, fragmentShow.getClass().getName());
        } else {
            transaction.show(fragmentShow);
        }
        transaction.commitAllowingStateLoss();
        mCurrentFragment = fragmentShow;
    }
}

From source file:com.dm.material.dashboard.candybar.activities.CandyBarMainActivity.java

private void setFragment(Fragment fragment) {
    clearBackStack();//w w  w.  j  ava2s.c om

    FragmentTransaction ft = mFragManager.beginTransaction().replace(R.id.container, fragment, mFragmentTag);
    try {
        ft.commit();
    } catch (Exception e) {
        ft.commitAllowingStateLoss();
    }

    Menu menu = mNavigationView.getMenu();
    menu.getItem(mPosition).setChecked(true);
    mToolbarTitle.setText(menu.getItem(mPosition).getTitle());
}

From source file:org.ieatta.activity.gallery.GalleryActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // force the theme to dark...
    //        setTheme(Theme.DARK.getResourceId());
    app = (IEAApp) getApplicationContext();

    setContentView(R.layout.activity_gallery);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.gallery_toolbar);
    // give it a gradient background
    ViewUtil.setBackgroundDrawable(toolbar,
            GradientUtil.getCubicGradient(getResources().getColor(R.color.lead_gradient_start), Gravity.TOP));
    setSupportActionBar(toolbar);//from   www  . j  a  v  a2 s.  c  om
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("");

    toolbarContainer = (ViewGroup) findViewById(R.id.gallery_toolbar_container);
    infoContainer = (ViewGroup) findViewById(R.id.gallery_info_container);
    // give it a gradient background
    ViewUtil.setBackgroundDrawable(infoContainer, GradientUtil
            .getCubicGradient(getResources().getColor(R.color.lead_gradient_start), Gravity.BOTTOM));

    descriptionText = (TextView) findViewById(R.id.gallery_description_text);
    descriptionText.setShadowLayer(2, 1, 1, getResources().getColor(R.color.lead_text_shadow));

    licenseIcon = (ImageView) findViewById(R.id.gallery_license_icon);
    licenseIcon.setOnClickListener(licenseShortClickListener);
    licenseIcon.setOnLongClickListener(licenseLongClickListener);

    creditText = (TextView) findViewById(R.id.gallery_credit_text);
    creditText.setShadowLayer(2, 1, 1, getResources().getColor(R.color.lead_text_shadow));

    pageTitle = getIntent().getParcelableExtra(EXTRA_PAGETITLE);
    initialImageTitle = getIntent().getParcelableExtra(EXTRA_IMAGETITLE);

    galleryCache = new HashMap<>();
    galleryPager = (ViewPager) findViewById(R.id.gallery_item_pager);
    galleryAdapter = new GalleryItemAdapter(this);
    galleryPager.setAdapter(galleryAdapter);
    galleryPager.setOnPageChangeListener(new GalleryPageChangeListener());

    funnel = new GalleryFunnel(app, getIntent().getIntExtra(EXTRA_SOURCE, 0));
    //
    if (savedInstanceState == null) {
        if (initialImageTitle != null) {
            funnel.logGalleryOpen(pageTitle, initialImageTitle.getDisplayText());
        }
    } else {
        controlsShowing = savedInstanceState.getBoolean("controlsShowing");
        initialImageIndex = savedInstanceState.getInt("pagerIndex");
        // if we have a savedInstanceState, then the initial index overrides
        // the initial Title from our intent.
        initialImageTitle = null;
        if (getSupportFragmentManager().getFragments() != null) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            for (Fragment f : getSupportFragmentManager().getFragments()) {
                if (f instanceof GalleryItemFragment) {
                    ft.remove(f);
                }
            }
            ft.commitAllowingStateLoss();
        }
    }
    toolbarContainer.post(new Runnable() {
        @Override
        public void run() {
            setControlsShowing(controlsShowing);
        }
    });

    // fetch the gallery from the network...
    fetchGalleryCollection();
}

From source file:com.openerp.MainActivity.java

public void startMainFragment(Fragment fragment, boolean addToBackState) {
    Log.d(TAG, "MainActivity->FragmentListener->startMainFragment()");
    int container_id = R.id.fragment_container;

    if (isTwoPane()) {
        findViewById(R.id.fragment_detail_container).setVisibility(View.GONE);
        Fragment detail = mFragment.findFragmentByTag("detail_fragment");
        if (detail != null && !mNewFragment && !detail.isInLayout()) {
            startDetailFragment(recreateFragment(detail));
        }//from   ww  w.  j ava  2 s. c  o  m

    }
    FragmentTransaction tran = mFragment.beginTransaction().replace(container_id, fragment, "main_fragment");
    if (addToBackState) {
        tran.addToBackStack(null);
    }
    tran.commitAllowingStateLoss();
}

From source file:com.abcvoipsip.ui.dialpad.DialerFragment.java

@Override
public void onVisibilityChanged(boolean visible) {
    if (visible && getResources().getBoolean(R.bool.use_dual_panes)) {
        // That's far to be optimal we should consider uncomment tests for reusing fragment
        // if (autoCompleteFragment == null) {
        autoCompleteFragment = new DialerAutocompleteDetailsFragment();

        if (digits != null) {
            Bundle bundle = new Bundle();
            bundle.putCharSequence(DialerAutocompleteDetailsFragment.EXTRA_FILTER_CONSTRAINT,
                    digits.getText().toString());

            autoCompleteFragment.setArguments(bundle);

        }/*from w ww.ja  va  2  s . c  om*/
        // }
        // if
        // (getFragmentManager().findFragmentByTag(TAG_AUTOCOMPLETE_SIDE_FRAG)
        // != autoCompleteFragment) {
        // Execute a transaction, replacing any existing fragment
        // with this one inside the frame.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.details, autoCompleteFragment, TAG_AUTOCOMPLETE_SIDE_FRAG);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commitAllowingStateLoss();

        // }
    }
}