Example usage for android.os Bundle putSparseParcelableArray

List of usage examples for android.os Bundle putSparseParcelableArray

Introduction

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

Prototype

public void putSparseParcelableArray(@Nullable String key, @Nullable SparseArray<? extends Parcelable> value) 

Source Link

Document

Inserts a SparceArray of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key.

Usage

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

public static void BrowserPhotos(Activity activity, ArrayList<Photo> photos, int index, int maxCount,
        SparseArray<Photo> selectedPhotos) {
    Intent intent = new Intent(activity, ViewPagerActivity.class);
    Bundle bundle = new Bundle();
    bundle.putSparseParcelableArray("selectedPhotos", selectedPhotos);
    bundle.putParcelableArrayList("photos", photos);
    bundle.putInt("position", index);
    bundle.putInt("maxCount", index);
    intent.putExtra("data", bundle);
    activity.startActivityForResult(intent, REQUEST_PAGE_SELECT_CODE);
}

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

@Override
@CallSuper//from   w  w  w . ja v  a 2  s.c o  m
public Parcelable saveState() {
    Bundle state = new Bundle();
    if (mSavedState.size() > 0) {
        state.putSparseParcelableArray(KEY_SAVED_STATES, mSavedState);
    }
    for (int i = 0; i < mFragments.size(); i++) {
        Fragment f = mFragments.valueAt(i);
        String key = KEY_PREFIX + mFragments.keyAt(i);
        // save Fragment sate in FragmentManager by our key!
        mFragmentManager.putFragment(state, key, f);
    }
    return state;
}

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

@Override
public Parcelable saveState() {
    Bundle state = null;
    if (mSavedState.size() > 0) {
        state = new Bundle();
        state.putSparseParcelableArray("states", mSavedState.clone());
    }//ww  w  .j  a v  a2s .  c o m
    int size = mFragments.size();
    for (int i = 0; i < size; i++) {
        int index = mFragments.keyAt(i);
        Fragment f = mFragments.valueAt(i);
        if (f != null && f.isAdded()) {
            if (state == null) {
                state = new Bundle();
            }
            String key = "f" + index;
            mFragmentManager.putFragment(state, key, f);
        }
    }
    return state;
}

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

@Override
public Parcelable saveState() {
    Bundle bundle = new Bundle();
    for (ViewHolder viewHolder : getAttachedViewHolders()) {
        mSavedStates.put(getItemId(viewHolder.mPosition), viewHolder.onSaveInstanceState());
    }//  w w w .jav a 2  s  .co m
    bundle.putSparseParcelableArray(STATE, mSavedStates);
    return bundle;
}

From source file:fr.cph.chicago.activity.BaseActivity.java

/**
 * Finish current activity and start main activity with custom transition
 * //from  w  w w.j a va 2  s .com
 * @param trainArrivals
 *            the train arrivals
 * @param busArrivals
 *            the bus arrivals
 */
private void startMainActivity(SparseArray<TrainArrival> trainArrivals, List<BusArrival> busArrivals) {
    if (!isFinishing()) {
        Intent intent = new Intent(this, MainActivity.class);
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList("busArrivals", (ArrayList<BusArrival>) busArrivals);
        bundle.putSparseParcelableArray("trainArrivals", trainArrivals);
        intent.putExtras(bundle);

        finish();
        startActivity(intent);
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }
}

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

@Override
protected void onSaveInstanceState(Bundle outState) {
    // -- save the current screen
    int position = viewPager.getCurrentItem();
    outState.putInt(PAGE_FLOW_POSITION, position);
    // -- save fragment keys
    SparseArray<Bundle> fragmentKeys = pagerAdapter.getBundleSparse();
    outState.putSparseParcelableArray(PAGE_FLOW_FRAGMENT_KEYS, fragmentKeys);

    super.onSaveInstanceState(outState);
}

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

@Override
public void onClick(View v) {
    if (v.getId() == R.id.selectCancel) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("").setPositiveButton("", new DialogInterface.OnClickListener() {
            @Override/*from   w  w w  .j ava 2  s.  com*/
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        }).setNegativeButton("?", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                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);
            }
        }).create().show();
    } else if (v.getId() == R.id.checkbox) {
        Photo photo = photos.get(mViewPager.getCurrentItem());
        int pos = selectedPhotoArray.indexOfKey(photo.id);
        if (selectCheckBox.isChecked() && pos < 0) {
            if (selectedPhotoArray.size() < 9) {
                selectedPhotoArray.append(photo.id, photo);
                selectedPhotoAdapter.notifyDataSetChanged();
                recyclerView.scrollToPosition(selectedPhotoArray.indexOfKey(photo.id));
            } else {
                Toast.makeText(this, "??", Toast.LENGTH_SHORT).show();
                selectCheckBox.setChecked(false);
            }
        } else if (!selectCheckBox.isChecked() && pos >= 0) {
            selectedPhotoArray.remove(photo.id);
            selectedPhotoAdapter.notifyItemRemoved(pos);
            //                recyclerView.scrollToPosition(pos>0?pos-1:0);
        }
        completeBtn.setText(String.format(format, selectedPhotoArray.size()));
        handleSelectedPhotoView(selectedPhotoArray.size() != 0);
    } else if (v.getId() == R.id.completeBtn) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putSparseParcelableArray("selectedPhotos", selectedPhotoArray);
        intent.putExtra("data", bundle);
        setResult(RESULT_OK, intent);
        finish();
    }
}

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

/**
 * @return the saved views states/*  w ww .  j  a v  a2s.c  o m*/
 */
public final Bundle saveAsBundle() {
    if (mChildStates == null || mChildStates.size() == 0) {
        return null;
    }
    Map<String, SparseArray<Parcelable>> snapshot = mChildStates.snapshot();
    Bundle bundle = new Bundle();
    for (Iterator<Entry<String, SparseArray<Parcelable>>> i = snapshot.entrySet().iterator(); i.hasNext();) {
        Entry<String, SparseArray<Parcelable>> e = i.next();
        bundle.putSparseParcelableArray(e.getKey(), e.getValue());
    }
    return bundle;
}

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

@Override
public final void onSaveInstanceState(final Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putParcelableArrayList(bundleBusArrivals, (ArrayList<BusArrival>) busArrivals);
    outState.putSparseParcelableArray(bundleTrainArrivals, trainArrivals);
    outState.putParcelableArrayList(bundleBikeStation, (ArrayList<BikeStation>) bikeStations);
}

From source file:io.github.clendy.leanback.widget.ViewsStateBundle.java

public final Bundle saveOnScreenView(Bundle bundle, View view, int id) {
    if (mSavePolicy != BaseGridView.SAVE_NO_CHILD) {
        String key = getSaveStatesKey(id);
        SparseArray<Parcelable> container = new SparseArray<Parcelable>();
        view.saveHierarchyState(container);
        if (bundle == null) {
            bundle = new Bundle();
        }//  w  ww.j  ava 2s  .  com
        bundle.putSparseParcelableArray(key, container);
    }
    return bundle;
}