Example usage for android.os Bundle getSparseParcelableArray

List of usage examples for android.os Bundle getSparseParcelableArray

Introduction

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

Prototype

@Nullable
public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

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);/*from  w w w .  jav a  2 s  .c  om*/
        SparseArray<Parcelable> ss = bundle.containsKey(STATE) ? bundle.getSparseParcelableArray(STATE) : null;
        mSavedStates = ss != null ? ss : new SparseArray<Parcelable>();
    }
    super.restoreState(state, loader);
}

From source file:com.cokus.fangdouyu.widget.viewpagerindicator.view.indicator.FragmentListPageAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);/*from ww  w  .  j  a v a 2 s  .c  o m*/
        mSavedState.clear();
        mFragments.clear();
        if (bundle.containsKey("states")) {
            mSavedState = bundle.getSparseParcelableArray("states");
        }
        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) {
                    f.setMenuVisibility(false);
                    mFragments.put(index, f);
                } else {
                    //                  Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:edt.com.edt.view.mainpage.indicator.FragmentListPageAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);//from www  .  ja  va2  s.  co  m
        mSavedState.clear();
        mFragments.clear();
        if (bundle.containsKey("states")) {
            mSavedState = bundle.getSparseParcelableArray("states");
        }
        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) {
                    f.setMenuVisibility(false);
                    mFragments.put(index, f);
                } else {
                    //                  Log.w(TAG, "Bad fragment_home at key " + key);
                }
            }
        }
    }
}

From source file:com.bilibili.lib.pageradapter.IDFragmentStatePagerAdapter.java

@Override
@CallSuper/*  ww  w .  j av a 2 s . co  m*/
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        mSavedState.clear();
        mFragments.clear();
        SparseArray<Fragment.SavedState> fss = bundle.getSparseParcelableArray(KEY_SAVED_STATES);
        if (fss != null) {
            for (int i = 0; i < fss.size(); i++) {
                mSavedState.put(fss.keyAt(i), fss.valueAt(i));
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith(KEY_PREFIX)) {
                Fragment f = mFragmentManager.getFragment(bundle, key);
                int id;
                try {
                    id = Integer.parseInt(key.substring(KEY_PREFIX.length()));
                } catch (NumberFormatException e) {
                    // should not happen!
                    throw new IllegalStateException("Can't find id at key " + key);
                }
                if (f != null) {
                    f.setMenuVisibility(false);
                    mFragments.put(id, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:com.example.li.demo.tab.FragmentListPageAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);/*from   ww w .java2 s  . c o m*/
        mSavedState.clear();
        mFragments.clear();
        if (bundle.containsKey("states")) {
            mSavedState = bundle.getSparseParcelableArray("states");
        }
        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) {
                    f.setMenuVisibility(false);
                    mFragments.put(index, f);
                } else {
                    Log.w("", "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:android.support.v17.leanback.widget.ViewsStateBundle.java

public final void loadFromBundle(Bundle savedBundle) {
    if (mChildStates != null && savedBundle != null) {
        mChildStates.evictAll();//w  w w. j a  v a 2 s . c  om
        for (Iterator<String> i = savedBundle.keySet().iterator(); i.hasNext();) {
            String key = i.next();
            mChildStates.put(key, savedBundle.getSparseParcelableArray(key));
        }
    }
}

From source file:com.example.maxuan.photoutils.ViewPagerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select_viewpager);
    mViewPager = (HackyViewPager) findViewById(R.id.view_pager);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    cancelBtn = (ImageView) findViewById(R.id.selectCancel);
    cancelBtn.setOnClickListener(this);
    selectCheckBox = (CheckBox) findViewById(R.id.checkbox);
    selectCheckBox.setOnClickListener(this);
    completeBtn = (Button) findViewById(R.id.completeBtn);
    completeBtn.setOnClickListener(this);
    photos = new ArrayList<>();
    posArray = new SparseIntArray(10);
    adapter = new PhotoPagerAdapter(this, photos);
    mViewPager.setAdapter(adapter);//from  ww w .j  a  v a  2 s  .  co  m
    mViewPager.addOnPageChangeListener(this);
    Intent intent = getIntent();
    if (intent != null) {
        Bundle bundle = intent.getBundleExtra("data");
        if (bundle == null)
            return;
        selectedPhotoArray = bundle.getSparseParcelableArray("selectedPhotos");
        completeBtn.setText(String.format(format, selectedPhotoArray.size()));
        List<Photo> list = bundle.getParcelableArrayList("photos");
        if (list != null)
            photos.addAll(list);
        for (int i = 0; i < photos.size(); ++i) {
            posArray.put(photos.get(i).id, i);
        }
        position = bundle.getInt("position", 0);
        maxCount = bundle.getInt("maxCount", 9);
        adapter.notifyDataSetChanged();
        mViewPager.setCurrentItem(position);
        selectCheckBox.setChecked(selectedPhotoArray.indexOfKey(photos.get(position).id) >= 0);
    }

    selectedPhotoAdapter = new SelectedPhotoAdapter(this);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    layoutManager.setReverseLayout(true);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(selectedPhotoAdapter);
    recyclerView.setVisibility(selectedPhotoArray.size() > 0 ? View.VISIBLE : View.GONE);
    if (savedInstanceState != null) {
        boolean isLocked = savedInstanceState.getBoolean(ISLOCKED_ARG, false);
        ((HackyViewPager) mViewPager).setLocked(isLocked);
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
        return;
    getWindow().getDecorView()
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

}

From source file:fr.cph.chicago.core.fragment.FavoritesFragment.java

@Override
public final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState == null) {
        final Bundle bundle = activity.getIntent().getExtras();
        busArrivals = bundle.getParcelableArrayList(getString(R.string.bundle_bus_arrivals));
        trainArrivals = bundle.getSparseParcelableArray(getString(R.string.bundle_train_arrivals));
        bikeStations = bundle.getParcelableArrayList(getString(R.string.bundle_bike_stations));
    } else {//from  ww  w  .j  a v  a 2s  .  c  om
        busArrivals = savedInstanceState.getParcelableArrayList(getString(R.string.bundle_bus_arrivals));
        trainArrivals = savedInstanceState.getSparseParcelableArray(getString(R.string.bundle_train_arrivals));
        bikeStations = savedInstanceState.getParcelableArrayList(getString(R.string.bundle_bike_stations));
        boolean boolTrain = App.checkTrainData(activity);
        if (boolTrain) {
            App.checkBusData(activity);
        }
    }
    if (bikeStations == null) {
        bikeStations = new ArrayList<>();
    }
    Util.trackScreen(getContext(), getString(R.string.analytics_favorites_fragment));
}

From source file:com.planyourexchange.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // -- This should be rendered first
    setContentView(R.layout.activity_main);
    // -- create a new Ad
    newAdView();//from   w ww .j a va 2 s.  c  om
    // -- View Pager & Adapter
    viewPager = (ViewPager) findViewById(R.id.main_pager);
    // -- In case we're restoring from a previous saved sate
    SparseArray<Bundle> fragmentKeys = null;
    int position = 0;
    if (savedInstanceState != null) {
        fragmentKeys = savedInstanceState.getSparseParcelableArray(PAGE_FLOW_FRAGMENT_KEYS);
        position = savedInstanceState.getInt(PAGE_FLOW_POSITION);
    }

    pagerAdapter = new PageFlowPagerAdapter(getSupportFragmentManager(), fragmentKeys);
    viewPager.setAdapter(pagerAdapter);
    viewPager.setCurrentItem(position);
}

From source file:android.support.design.internal.NavigationMenuPresenter.java

@Override
public void onRestoreInstanceState(final Parcelable parcelable) {
    if (parcelable instanceof Bundle) {
        Bundle state = (Bundle) parcelable;
        SparseArray<Parcelable> hierarchy = state.getSparseParcelableArray(STATE_HIERARCHY);
        if (hierarchy != null) {
            mMenuView.restoreHierarchyState(hierarchy);
        }/*from  w  ww  .j  ava 2 s.  c  o  m*/
        Bundle adapterState = state.getBundle(STATE_ADAPTER);
        if (adapterState != null) {
            mAdapter.restoreInstanceState(adapterState);
        }
        SparseArray<Parcelable> header = state.getSparseParcelableArray(STATE_HEADER);
        if (header != null) {
            mHeaderLayout.restoreHierarchyState(header);
        }
    }
}