Example usage for android.app FragmentTransaction commitAllowingStateLoss

List of usage examples for android.app FragmentTransaction commitAllowingStateLoss

Introduction

In this page you can find the example usage for android.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.android.dialer.DialtactsFragment.java

/**
 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
 * @see #onDialpadShown/*  ww  w.java 2s  .c  o  m*/
 */
public void showDialpadFragment(boolean animate) {

    //        if (mIsDialpadShown || mStateSaved) {
    //            return;
    //        }
    if (mIsDialpadShown || mStateSaved || mDialpadFragment == null) {
        Log.e("showDialpadFragment ", " return; ");
        return;
    }
    mIsDialpadShown = true;
    animate = false;
    mDialpadFragment.setAnimate(animate);
    //        mListsFragment.setUserVisibleHint(false);
    AnalyticsUtil.sendScreenView(mDialpadFragment);

    final FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    //if (mDialpadFragment == null) {
    //mDialpadFragment = new DialpadFragment();
    //  ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
    //} else {
    ft.show(mDialpadFragment);
    //}

    //        mDialpadFragment.setAnimate(animate);

    //        ft.commit();

    //        if (animate) {
    ////            mFloatingActionButtonController.scaleOut();
    //        } else {
    ////            mFloatingActionButtonController.setVisible(false);
    //            maybeEnterSearchUi();
    //        }
    if (!isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
        if (getCallLogFragment() == null) {
            mCalllogList = new CallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL);
            mCalllogList.setRecyclerViewChangedImpl(mRecyclerViewChangedImpl);
            ft.add(R.id.dialtacts_frame, mCalllogList, "mCalllogList");
            ft.show(mCalllogList);
        } else {
            if (mSearchViewShow)
                mDialpadFragment.showSearchView();
            else
                mDialpadFragment.hideSearchView();
        }
    }
    ft.commitAllowingStateLoss();
    sendMessageToReflushEditerView();
    Log.e(TAG, " showDialpadFragment mIsDialpadShown:" + mIsDialpadShown + "  mInDialpadSearch:"
            + mInDialpadSearch + "  isDialpadShown() :" + isDialpadShown());

    //        mListsFragment.getView().animate().alpha(0).withLayer();
}

From source file:com.android.dialer.DialtactsFragment.java

/**
 * Shows the search fragment//from w  ww . j  a  v  a 2  s . co m
 */
private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
    if (mStateSaved || getChildFragmentManager().isDestroyed()) {
        // Weird race condition where fragment is doing work after the activity is destroyed
        // due to talkback being on (b/10209937). Just return since we can't do any
        // constructive here.
        return;
    }
    mDialpadFragment.showSearchView();

    if (DEBUG) {
        Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
    }

    final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    if (mInDialpadSearch && mSmartDialSearchFragment != null) {
        transaction.remove(mSmartDialSearchFragment);
    } else if (mInRegularSearch && mRegularSearchFragment != null) {
        transaction.remove(mRegularSearchFragment);
    }

    final String tag;
    if (smartDialSearch) {
        tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
    } else {
        tag = TAG_REGULAR_SEARCH_FRAGMENT;
    }
    mInDialpadSearch = smartDialSearch;
    mInRegularSearch = !smartDialSearch;

    mFloatingActionButtonController.scaleOut();

    SearchFragment fragment = (SearchFragment) getChildFragmentManager().findFragmentByTag(tag);
    if (animate) {
        transaction.setCustomAnimations(android.R.animator.fade_in, 0);
    } else {
        transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
    }
    if (fragment == null) {

        Log.e(TAG, " --- enterSearchUi --- null");
        if (smartDialSearch) {
            fragment = new SmartDialSearchFragment();
            transaction.add(R.id.dialtacts_frame, fragment, tag);
        } else {
            fragment = new RegularSearchFragment();
            fragment.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // Show the FAB when the user touches the lists fragment and the soft
                    // keyboard is hidden.
                    showFabInSearchUi();
                    return false;
                }
            });
        }

    } else {
        transaction.show(fragment);

    }
    // DialtactsFragment will provide the options menu
    fragment.setHasOptionsMenu(false);
    fragment.setShowEmptyListForNullQuery(true);
    fragment.setQueryString(query, false /* delaySelection */);
    transaction.commitAllowingStateLoss();
    //        transaction.commit();

    //        if (animate) {
    //            mListsFragment.getView().animate().alpha(0).withLayer();
    //        }
    //        mListsFragment.setUserVisibleHint(false);
}

From source file:com.android.mail.compose.ComposeActivity.java

private int replaceFragment(Fragment fragment, int transition, String tag) {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setTransition(transition);
    fragmentTransaction.replace(R.id.wait, fragment, tag);
    final int transactionId = fragmentTransaction.commitAllowingStateLoss();
    return transactionId;
}

From source file:com.android.contacts.activities.PeopleActivity.java

private void createViewsAndFragments(Bundle savedState) {
    // Disable the ActionBar so that we can use a Toolbar. This needs to be called before
    // setContentView().
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.people_activity);

    final FragmentManager fragmentManager = getFragmentManager();

    // Hide all tabs (the current tab will later be reshown once a tab is selected)
    final FragmentTransaction transaction = fragmentManager.beginTransaction();

    mTabTitles = new String[TabState.COUNT];
    mTabTitles[TabState.FAVORITES] = getString(R.string.favorites_tab_label);
    mTabTitles[TabState.ALL] = getString(R.string.all_contacts_tab_label);
    mTabPager = getView(R.id.tab_pager);
    mTabPagerAdapter = new TabPagerAdapter();
    mTabPager.setAdapter(mTabPagerAdapter);
    mTabPager.setOnPageChangeListener(mTabPagerListener);

    // Configure toolbar and toolbar tabs. If in landscape mode, we  configure tabs differntly.
    final Toolbar toolbar = getView(R.id.toolbar);
    setActionBar(toolbar);//from w  w  w  .ja  va2s.c  o  m
    final ViewPagerTabs portraitViewPagerTabs = (ViewPagerTabs) findViewById(R.id.lists_pager_header);
    ViewPagerTabs landscapeViewPagerTabs = null;
    if (portraitViewPagerTabs == null) {
        landscapeViewPagerTabs = (ViewPagerTabs) getLayoutInflater()
                .inflate(R.layout.people_activity_tabs_lands, toolbar, /* attachToRoot = */ false);
        mViewPagerTabs = landscapeViewPagerTabs;
    } else {
        mViewPagerTabs = portraitViewPagerTabs;
    }
    mViewPagerTabs.setViewPager(mTabPager);

    final String FAVORITE_TAG = "tab-pager-favorite";
    final String ALL_TAG = "tab-pager-all";

    // Create the fragments and add as children of the view pager.
    // The pager adapter will only change the visibility; it'll never create/destroy
    // fragments.
    // However, if it's after screen rotation, the fragments have been re-created by
    // the fragment manager, so first see if there're already the target fragments
    // existing.
    mFavoritesFragment = (ContactTileListFragment) fragmentManager.findFragmentByTag(FAVORITE_TAG);
    mAllFragment = (MultiSelectContactsListFragment) fragmentManager.findFragmentByTag(ALL_TAG);

    if (mFavoritesFragment == null) {
        mFavoritesFragment = new ContactTileListFragment();
        mAllFragment = new MultiSelectContactsListFragment();

        transaction.add(R.id.tab_pager, mFavoritesFragment, FAVORITE_TAG);
        transaction.add(R.id.tab_pager, mAllFragment, ALL_TAG);
    }

    mFavoritesFragment.setListener(mFavoritesFragmentListener);

    mAllFragment.setOnContactListActionListener(new ContactBrowserActionListener());
    mAllFragment.setCheckBoxListListener(new CheckBoxListListener());

    // Hide all fragments for now.  We adjust visibility when we get onSelectedTabChanged()
    // from ActionBarAdapter.
    transaction.hide(mFavoritesFragment);
    transaction.hide(mAllFragment);

    transaction.commitAllowingStateLoss();
    fragmentManager.executePendingTransactions();

    // Setting Properties after fragment is created
    mFavoritesFragment.setDisplayType(DisplayType.STREQUENT);

    mActionBarAdapter = new ActionBarAdapter(this, this, getActionBar(), portraitViewPagerTabs,
            landscapeViewPagerTabs, toolbar);
    mActionBarAdapter.initialize(savedState, mRequest);

    // Add shadow under toolbar
    ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources());

    // Configure floating action button
    mFloatingActionButtonContainer = findViewById(R.id.floating_action_button_container);
    final ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
    floatingActionButton.setOnClickListener(this);
    mFloatingActionButtonController = new FloatingActionButtonController(this, mFloatingActionButtonContainer,
            floatingActionButton);
    initializeFabVisibility();

    invalidateOptionsMenuIfNeeded();
}