Search in sources :

Example 41 with Fragment

use of android.app.Fragment in project AppIntro by apl-devs.

the class FragmentStatePagerAdapter method destroyItem.

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    Fragment fragment = (Fragment) object;
    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }
    while (mSavedState.size() <= position) {
        mSavedState.add(null);
    }
    mSavedState.set(position, fragment.isAdded() ? mFragmentManager.saveFragmentInstanceState(fragment) : null);
    mFragments.set(position, null);
    mCurTransaction.remove(fragment);
}
Also used : Fragment(android.app.Fragment)

Example 42 with Fragment

use of android.app.Fragment in project AppIntro by apl-devs.

the class FragmentStatePagerAdapter method instantiateItem.

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // 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 (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;
}
Also used : Fragment(android.app.Fragment)

Example 43 with Fragment

use of android.app.Fragment in project AppIntro by apl-devs.

the class FragmentStatePagerAdapter method restoreState.

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                }
            }
        }
    }
}
Also used : Bundle(android.os.Bundle) Parcelable(android.os.Parcelable) Fragment(android.app.Fragment)

Example 44 with Fragment

use of android.app.Fragment in project AppIntro by apl-devs.

the class FragmentStatePagerAdapter method saveState.

@Override
public Parcelable saveState() {
    Bundle state = null;
    if (mSavedState.size() > 0) {
        state = new Bundle();
        Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
        mSavedState.toArray(fss);
        state.putParcelableArray("states", fss);
    }
    for (int i = 0; i < mFragments.size(); i++) {
        Fragment f = mFragments.get(i);
        if (f != null && f.isAdded()) {
            if (state == null) {
                state = new Bundle();
            }
            String key = "f" + i;
            mFragmentManager.putFragment(state, key, f);
        }
    }
    return state;
}
Also used : Bundle(android.os.Bundle) Fragment(android.app.Fragment)

Example 45 with Fragment

use of android.app.Fragment in project coursera-android by aporter.

the class DialtactsActivity method addSearchFragment.

/**
     * Add search fragment.  Note this is called during onLayout, so there's some restrictions,
     * such as executePendingTransaction can't be used in it.
     */
private void addSearchFragment() {
    // changes.
    if (mSearchFragment != null)
        return;
    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment searchFragment = new PhoneNumberPickerFragment();
    searchFragment.setUserVisibleHint(false);
    ft.add(R.id.dialtacts_frame, searchFragment);
    ft.hide(searchFragment);
    ft.commitAllowingStateLoss();
}
Also used : PhoneNumberPickerFragment(com.android.contacts.list.PhoneNumberPickerFragment) FragmentTransaction(android.app.FragmentTransaction) DialpadFragment(com.android.contacts.dialpad.DialpadFragment) Fragment(android.app.Fragment) CallLogFragment(com.android.contacts.calllog.CallLogFragment) PhoneNumberPickerFragment(com.android.contacts.list.PhoneNumberPickerFragment) PhoneFavoriteFragment(com.android.contacts.list.PhoneFavoriteFragment)

Aggregations

Fragment (android.app.Fragment)183 FragmentTransaction (android.app.FragmentTransaction)65 DialogFragment (android.app.DialogFragment)42 FragmentManager (android.app.FragmentManager)34 Bundle (android.os.Bundle)18 PreferenceFragment (android.support.v14.preference.PreferenceFragment)12 Intent (android.content.Intent)11 View (android.view.View)11 BizFragment (org.aisen.weibo.sina.ui.fragment.base.BizFragment)8 TextView (android.widget.TextView)6 ABaseFragment (org.aisen.android.ui.fragment.ABaseFragment)6 Uri (android.net.Uri)5 PreferenceFragment (android.preference.PreferenceFragment)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SuppressLint (android.annotation.SuppressLint)3 ViewGroup (android.view.ViewGroup)3 FrameLayout (android.widget.FrameLayout)3 Method (java.lang.reflect.Method)3 APagingFragment (org.aisen.android.ui.fragment.APagingFragment)3