Example usage for android.app Fragment setInitialSavedState

List of usage examples for android.app Fragment setInitialSavedState

Introduction

In this page you can find the example usage for android.app Fragment setInitialSavedState.

Prototype

public void setInitialSavedState(SavedState state) 

Source Link

Document

Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned by FragmentManager#saveFragmentInstanceState(Fragment) FragmentManager.saveFragmentInstanceState .

Usage

From source file:com.afollestad.impression.utils.FragmentStatePagerAdapter.java

@SuppressLint("CommitTransaction")
@Override//w  w  w.  ja v  a 2 s.c om
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = mFragments.get(position);
        if (f != null) {
            return f;
        }
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    FragmentCompat.setMenuVisibility(fragment, false);
    FragmentCompat.setUserVisibleHint(fragment, false);
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment, "page:" + position);

    return fragment;
}

From source file:org.birthdayadapter.util.FragmentStatePagerAdapterV14.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do. This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = mFragments.get(position);
        if (f != null) {
            return f;
        }/*  w  w w.ja  v  a 2 s.  c  o m*/
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    // fragment.setUserVisibleHint(false);
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment);

    return fragment;
}

From source file:com.view.FragmentStatePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing 
    // to do. This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = mFragments.get(position);
        if (f != null) {
            return f;
        }//from   w  ww.  ja v a2s.  c  o m
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    fragment.setUserVisibleHint(false);
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment);

    return fragment;
}

From source file:com.alimuzaffar.ramadanalarm.widget.FragmentStatePagerAdapter.java

@SuppressLint("NewApi")
@Override//from w w w  .j  a  va  2  s  . c o m
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = mFragments.get(position);
        if (f != null) {
            return f;
        }
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        fragment.setUserVisibleHint(false);
    }
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment);

    return fragment;
}

From source file:com.nononsenseapps.support.app.FragmentStatePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = mFragments.get(position);
        if (f != null) {
            return f;
        }//from w w  w  . j  a  v a  2 s.  c o m
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    setMenuVisibility(fragment, false);
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment);

    return fragment;
}

From source file:com.android.mail.utils.FragmentStatePagerAdapter2.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    final Fragment existing = mFragments.get(position);
    if (existing != null) {
        return existing;
    }/*from w w w.ja  v  a2 s  . com*/

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        LogUtils.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mEnableSavedStates && mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    if (fragment != mCurrentPrimaryItem) {
        setItemVisible(fragment, false);
    }
    mFragments.put(position, fragment);
    mCurTransaction.add(container.getId(), fragment);

    return fragment;
}

From source file:com.tapchatapp.android.app.ui.TapchatFragmentStatePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = mFragments.get(position);
        if (f != null) {
            int newPos = getItemPosition(f);
            if (position == newPos) {
                if (f.getView() != null && f.getView().getParent() != container) {
                    ((ViewGroup) f.getView().getParent()).removeView(f.getView());
                    container.addView(f.getView());
                }/*from w ww.j a  va  2s .co m*/
                return f;
            } else {
                mFragments.remove(position);
                mFragments.ensureCapacity(newPos + 1);
                for (int i = mFragments.size(); i < (newPos + 1); i++) {
                    mFragments.add(null);
                }
                mFragments.set(newPos, f);
            }
        }
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment, getTag(position));

    return fragment;
}

From source file:com.tct.mail.utils.FragmentStatePagerAdapter2.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    final Fragment existing = mFragments.get(position);
    if (existing != null) {
        return existing;
    }// w w w .  j  a  va  2  s. c om

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        LogUtils.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mEnableSavedStates && mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    //TS: jian.xu 2015-11-02 EMAIL BUGFIX-1106488 MOD_S
    if (fragment != null && fragment != mCurrentPrimaryItem) {
        setItemVisible(fragment, false);
    }
    //TS: jian.xu 2015-11-02 EMAIL BUGFIX-1106488 MOD_E
    mFragments.put(position, fragment);
    mCurTransaction.add(container.getId(), fragment);

    return fragment;
}

From source file:org.kegbot.app.util.SortableFragmentStatePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {

    createIdCache();//from  w w w  .j a  v  a  2 s .  c om

    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = mFragments.get(position);
        if (f != null) {
            return f;
        }
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    if (Build.VERSION.SDK_INT >= 15) {
        fragment.setUserVisibleHint(false);
    }
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment);

    return fragment;
}

From source file:com.github.paradam.infinitepager.InfiniteFragmentStatePagerAdapter.java

/**
 * Create the page for the given position.  The adapter is responsible for adding the view to
 * the container given here, although it only must ensure this is done by the time it returns
 * from {@link #finishUpdate(android.view.ViewGroup)}.
 *
 * @param container The containing View in which the page will be shown.
 * @param position  The page position to be instantiated.
 * @return Returns an Object representing the new page.  This does not need to be a View, but
 * can be some other container of the page.
 *///  w w  w.ja  va 2  s.c o m
public Object instantiateRelativeItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do. This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    Fragment f;
    if (mFragments.size() > position) {
        f = mFragments.get(position);
        if (f != null) {
            return f;
        }
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }
    f = getRelativeItem(position);

    if (f.getView() != null) {
        mCurTransaction.remove(f);
    }

    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null && !f.isAdded()) {
            f.setInitialSavedState(fss);
        } else if (f.isAdded()) {
            Log.e(TAG, "Error when instantiating Fragment: " + f + ", FragmentSavedState: " + fss
                    + ", fragment already added: " + f.isAdded());
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }

    FragmentCompat.setMenuVisibility(f, false);
    FragmentCompat.setUserVisibleHint(f, false);
    mFragments.set(position, f);
    mCurTransaction.add(container.getId(), f);

    return f;
}