Example usage for android.os Bundle setClassLoader

List of usage examples for android.os Bundle setClassLoader

Introduction

In this page you can find the example usage for android.os Bundle setClassLoader.

Prototype

@Override
public void setClassLoader(ClassLoader loader) 

Source Link

Document

Changes the ClassLoader this Bundle uses when instantiating objects.

Usage

From source file:org.getlantern.firetweet.adapter.support.SupportFixedFragmentStatePagerAdapter.java

@Override
public Object instantiateItem(final ViewGroup container, final int position) {
    final Fragment f = (Fragment) super.instantiateItem(container, position);
    final Bundle savedFragmentState = f != null ? FragmentTrojan.getSavedFragmentState(f) : null;
    if (savedFragmentState != null) {
        savedFragmentState.setClassLoader(f.getClass().getClassLoader());
    }/*  w ww  .j  a va2 s.  com*/
    return f;
}

From source file:org.mariotaku.twidere.adapter.SupportFixedFragmentStatePagerAdapter.java

@Override
public Object instantiateItem(final ViewGroup container, final int position) {
    final Fragment f = (Fragment) super.instantiateItem(container, position);
    final Bundle savedFragmentState = f != null ? FragmentAccessor.getSavedFragmentState(f) : null;
    if (savedFragmentState != null) {
        savedFragmentState.setClassLoader(f.getClass().getClassLoader());
    }/*from  ww  w.j a v  a 2 s .c  om*/
    return f;
}

From source file:com.taobao.luaview.view.adapter.FixedFragmentStatePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Object fragment = super.instantiateItem(container, position);
    try {//from ww w .j  a  va  2 s  .  co  m
        final Field saveFragmentStateField = Fragment.class.getDeclaredField("mSavedFragmentState");
        saveFragmentStateField.setAccessible(true);
        final Bundle savedFragmentState = (Bundle) saveFragmentStateField.get(fragment);
        if (savedFragmentState != null) {
            savedFragmentState.setClassLoader(Fragment.class.getClassLoader());
        }
    } catch (Exception e) {
        Log.w("FragmentPagerAdapter", "Could not get mSavedFragmentState field: " + e);
    }
    return fragment;
}

From source file:de.vanita5.twittnuker.adapter.support.SupportFixedFragmentStatePagerAdapter.java

@Override
public Object instantiateItem(final ViewGroup container, final int position) {
    final Fragment f = (Fragment) super.instantiateItem(container, position);
    final Bundle savedFragmentState = f != null ? FragmentTrojan.getSavedFragmentState(f) : null;
    if (savedFragmentState != null && f != null) {
        savedFragmentState.setClassLoader(f.getClass().getClassLoader());
    }//  www  .j ava  2  s  .  co m
    return f;
}

From source file:com.stfalcon.frescoimageviewer.adapter.RecyclingPagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        SparseArray<Parcelable> ss = bundle.containsKey(STATE) ? bundle.getSparseParcelableArray(STATE) : null;
        mSavedStates = ss != null ? ss : new SparseArray<Parcelable>();
    }//from   w  ww  . j  a va2s  . co m
    super.restoreState(state, loader);
}

From source file:nz.ac.otago.psyanlab.common.designer.EditorSectionManager.java

public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        // Store fragment saved states.
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fragmentSavedStates = bundle.getParcelableArray("states");
        int[] stateKeys = bundle.getIntArray("state_keys");
        mSavedState.clear();//from   w ww.j a  v  a  2  s  . c om
        if (fragmentSavedStates != null) {
            for (int i = 0; i < fragmentSavedStates.length; i++) {
                mSavedState.put(stateKeys[i], (Fragment.SavedState) fragmentSavedStates[i]);
            }
        }

        mCurrentPosition = bundle.getInt("current_position");
    }
}

From source file:com.shizhefei.view.multitype.provider.FragmentDataProvider.java

private Fragment instantiate(FragmentData fragmentData) {
    try {/*  ww  w.  j  a  va 2 s.  c o  m*/
        Class<? extends Fragment> fragmentClass = fragmentData.getFragmentClass();
        Fragment f = fragmentData.getFragmentClass().newInstance();
        if (fragmentClass != null) {
            Bundle arguments = fragmentData.getArguments();
            arguments.setClassLoader(f.getClass().getClassLoader());
            f.setArguments(arguments);
        }
        return f;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("fragmentClass ", e);
    }
}

From source file:com.andorn.powertask.adapters.CustomFragmentStatePagerAdapter.java

@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();/* w  w  w  .j a  v a  2s  . c o m*/
        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);
                    }
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:jahirfiquitiva.iconshowcase.fragments.base.FragmentStatePagerAdapter.java

@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();/* ww w.j  av a 2  s .co  m*/
        mFragments.clear();
        if (fss != null) {
            for (Parcelable fs : fss) {
                mSavedState.add((Fragment.SavedState) fs);
            }
        }
        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);
                }
            }
        }
    }
}

From source file:com.example.study.studyproject.adapter.FragmentStatePagerAdapter.java

@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();//from  w w  w .j a v  a 2 s  .c om
        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);
                } else {

                }
            }
        }
    }
}