Example usage for android.os Bundle putParcelableArray

List of usage examples for android.os Bundle putParcelableArray

Introduction

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

Prototype

public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) 

Source Link

Document

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

Usage

From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    updateIntent();/*from   w  w  w  . j  av a 2s .com*/
    outState.putParcelable("intent", mEditedIntent);
    outState.putInt("componentType", mComponentType);
    outState.putInt("methodId", mMethodId);
    outState.putParcelableArray("intentFilters", mAttachedIntentFilters);
    RunAsInitReceiver.putBinderInBundle(outState, "localIEState", mLocalState);
    mDestroyExpected = true;
}

From source file:com.bmd.android.collection.SupportLongSparseArrayTest.java

public void testParcelable() {

    final ParcelableLongSparseObjectEntry[] parcelableArray = AndroidCollections.iterate(mArray).only()
            .values("4", "1").toParcelableArray(ParcelableLongSparseObjectEntry.class);

    assertThat(parcelableArray).hasSize(2);
    assertThat(parcelableArray[0].getKey()).isEqualTo(1);
    assertThat(parcelableArray[0].getValue()).isEqualTo("1");
    assertThat(parcelableArray[1].getKey()).isEqualTo(4);
    assertThat(parcelableArray[1].getValue()).isEqualTo("4");

    final ArrayList<ParcelableLongSparseObjectEntry<String>> parcelableList = AndroidCollections.iterate(mArray)
            .but().keys(Arrays.asList(1L, 2L, 3L)).reverse().toParcelableList();

    assertThat(parcelableList).hasSize(2);
    assertThat(parcelableList.get(0).getKey()).isEqualTo(4);
    assertThat(parcelableList.get(0).getValue()).isEqualTo("4");
    assertThat(parcelableList.get(1).getKey()).isEqualTo(0);
    assertThat(parcelableList.get(1).getValue()).isEqualTo("0");
    assertThat(parcelableList).containsExactly(SparseEntries.parcelableEntry(4L, "4"),
            SparseEntries.parcelableEntry(0L, "0"));

    final Bundle bundle = new Bundle();
    bundle.putParcelableArray("array", parcelableArray);
    bundle.putParcelableArrayList("list", parcelableList);

    final Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);/* ww  w  . j av a 2  s  .  co  m*/

    parcel.setDataPosition(0);

    final Bundle out = parcel.readBundle();
    out.setClassLoader(AndroidCollections.class.getClassLoader());

    assertThat(out.getParcelableArray("array")).isEqualTo(parcelableArray);
    assertThat(out.getParcelableArrayList("list")).isEqualTo(new ArrayList<Parcelable>(parcelableList));

    final ArrayList<ParcelableLongSparseObjectEntry<String>> filledList = new ArrayList<ParcelableLongSparseObjectEntry<String>>(
            2);

    AndroidCollections.iterate(mArray).but().keys(1, 2, 3).reverse().fillParcelable(filledList);

    assertThat(filledList).isEqualTo(parcelableList);

    final ParcelableLongSparseObjectEntry[] filledArray = new ParcelableLongSparseObjectEntry[2];

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2L, "2"));

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray, 1);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2L, "2"));
    assertThat(filledArray[0]).isEqualTo(filledArray[1]);

    try {

        AndroidCollections.iterate(mArray).fillParcelable(filledArray);

        fail();

    } catch (final IndexOutOfBoundsException e) {

    }

    final Parcelable[] parcelables = new Parcelable[2];

    AndroidCollections.iterate(mArray).only().to(1).fillParcelable(parcelables);

    assertThat(parcelables).containsExactly(filledArray);
}

From source file:androidx.media.MediaSession2StubImplBase.java

void notifyCustomLayout(ControllerInfo controller, final List<CommandButton> layout) {
    notifyInternal(controller, new Session2Runnable() {
        @Override//from  w  w  w.j  ava  2s .c  o m
        public void run(ControllerInfo controller) throws RemoteException {
            Bundle bundle = new Bundle();
            bundle.putParcelableArray(ARGUMENT_COMMAND_BUTTONS,
                    MediaUtils2.toCommandButtonParcelableArray(layout));
            controller.getControllerBinder().onEvent(SESSION_EVENT_SET_CUSTOM_LAYOUT, bundle);
        }
    });
}

From source file:androidx.media.MediaSession2StubImplBase.java

void notifyPlaylistChanged(final List<MediaItem2> playlist, final MediaMetadata2 metadata) {
    notifyAll(COMMAND_CODE_PLAYLIST_GET_LIST, new Session2Runnable() {
        @Override//  w  w w.  j a v  a 2  s .  co m
        public void run(ControllerInfo controller) throws RemoteException {
            Bundle bundle = new Bundle();
            bundle.putParcelableArray(ARGUMENT_PLAYLIST, MediaUtils2.toMediaItem2ParcelableArray(playlist));
            bundle.putBundle(ARGUMENT_PLAYLIST_METADATA, metadata == null ? null : metadata.toBundle());
            controller.getControllerBinder().onEvent(SESSION_EVENT_ON_PLAYLIST_CHANGED, bundle);
        }
    });
}

From source file:com.bmd.android.collection.LongSparseArrayTest.java

public void testParcelable() {

    if (VERSION.SDK_INT < VERSION_CODES.JELLY_BEAN) {

        return;//from  w w  w  .j  av  a2 s. c om
    }

    final ParcelableLongSparseObjectEntry[] parcelableArray = AndroidCollections.iterate(mArray).only()
            .values("4", "1").toParcelableArray(ParcelableLongSparseObjectEntry.class);

    assertThat(parcelableArray).hasSize(2);
    assertThat(parcelableArray[0].getKey()).isEqualTo(1);
    assertThat(parcelableArray[0].getValue()).isEqualTo("1");
    assertThat(parcelableArray[1].getKey()).isEqualTo(4);
    assertThat(parcelableArray[1].getValue()).isEqualTo("4");

    final ArrayList<ParcelableLongSparseObjectEntry<String>> parcelableList = AndroidCollections.iterate(mArray)
            .but().keys(Arrays.asList(1L, 2L, 3L)).reverse().toParcelableList();

    assertThat(parcelableList).hasSize(2);
    assertThat(parcelableList.get(0).getKey()).isEqualTo(4);
    assertThat(parcelableList.get(0).getValue()).isEqualTo("4");
    assertThat(parcelableList.get(1).getKey()).isEqualTo(0);
    assertThat(parcelableList.get(1).getValue()).isEqualTo("0");
    assertThat(parcelableList).containsExactly(SparseEntries.parcelableEntry(4L, "4"),
            SparseEntries.parcelableEntry(0L, "0"));

    final Bundle bundle = new Bundle();
    bundle.putParcelableArray("array", parcelableArray);
    bundle.putParcelableArrayList("list", parcelableList);

    final Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);

    parcel.setDataPosition(0);

    final Bundle out = parcel.readBundle();
    out.setClassLoader(AndroidCollections.class.getClassLoader());

    assertThat(out.getParcelableArray("array")).isEqualTo(parcelableArray);
    assertThat(out.getParcelableArrayList("list")).isEqualTo(new ArrayList<Parcelable>(parcelableList));

    final ArrayList<ParcelableLongSparseObjectEntry<String>> filledList = new ArrayList<ParcelableLongSparseObjectEntry<String>>(
            2);

    AndroidCollections.iterate(mArray).but().keys(1, 2, 3).reverse().fillParcelable(filledList);

    assertThat(filledList).isEqualTo(parcelableList);

    final ParcelableLongSparseObjectEntry[] filledArray = new ParcelableLongSparseObjectEntry[2];

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2L, "2"));

    AndroidCollections.iterate(mArray).only().value("2").fillParcelable(filledArray, 1);

    assertThat(filledArray[0]).isEqualTo(SparseEntries.parcelableEntry(2L, "2"));
    assertThat(filledArray[0]).isEqualTo(filledArray[1]);

    try {

        AndroidCollections.iterate(mArray).fillParcelable(filledArray);

        fail();

    } catch (final IndexOutOfBoundsException e) {

    }

    final Parcelable[] parcelables = new Parcelable[2];

    AndroidCollections.iterate(mArray).only().to(1).fillParcelable(parcelables);

    assertThat(parcelables).containsExactly(filledArray);
}

From source file:androidx.media.MediaSession2StubImplBase.java

void notifyRoutesInfoChanged(@NonNull final ControllerInfo controller, @Nullable final List<Bundle> routes) {
    notifyInternal(controller, new Session2Runnable() {
        @Override//w  w w.j  a v  a 2 s .  co m
        public void run(ControllerInfo controller) throws RemoteException {
            Bundle bundle = null;
            if (routes != null) {
                bundle = new Bundle();
                bundle.putParcelableArray(ARGUMENT_ROUTE_BUNDLE, routes.toArray(new Bundle[0]));
            }
            controller.getControllerBinder().onEvent(SESSION_EVENT_ON_ROUTES_INFO_CHANGED, bundle);
        }
    });
}

From source file:li.barter.http.HttpResponseParser.java

/**
 * Parse the response for Team//  w w  w .  j av  a 2  s . c  om
 *
 * @param response The response from server
 * @return
 */
private ResponseInfo parseTeamResponse(final String response) throws JSONException {
    final ResponseInfo responseInfo = new ResponseInfo();
    final JSONObject responseObject = new JSONObject(response);
    final JSONArray teamResults = JsonUtils.readJSONArray(responseObject, HttpConstants.TEAM, true, true);
    final Team[] teamArray = new Team[teamResults.length()];
    JSONObject teamObject = null;
    for (int i = 0; i < teamArray.length; i++) {
        teamObject = JsonUtils.readJSONObject(teamResults, i, true, true);
        Logger.e(TAG, teamObject.toString());
        teamArray[i] = new Team();
        readTeamObjectIntoTeam(teamObject, teamArray[i]);
    }
    final Bundle responseBundle = new Bundle(1);
    responseBundle.putParcelableArray(HttpConstants.TEAM, teamArray);
    responseInfo.responseBundle = responseBundle;
    return responseInfo;
}

From source file:li.barter.http.HttpResponseParser.java

/**
 * Method for parsing the foursquare response
 *
 * @param response The Json string response
 * @return/*w  w  w  . ja  v a2 s .  c o m*/
 * @throws JSONException if the Json string is invalid
 */
private ResponseInfo parseVenuesResponse(final String response) throws JSONException {

    final ResponseInfo responseInfo = new ResponseInfo();

    final JSONObject responseObject = JsonUtils.readJSONObject(new JSONObject(response), HttpConstants.RESPONSE,
            true, true);
    final JSONArray venuesArray = JsonUtils.readJSONArray(responseObject, HttpConstants.VENUES, true, true);

    final Venue[] venues = new Venue[venuesArray.length()];
    JSONObject venueObject = null;
    for (int i = 0; i < venues.length; i++) {
        venueObject = JsonUtils.readJSONObject(venuesArray, i, true, true);
        venues[i] = new Venue();
        readVenueObjectIntoVenue(venueObject, venues[i]);
    }

    final Bundle responseBundle = new Bundle(1);
    responseBundle.putParcelableArray(HttpConstants.LOCATIONS, venues);
    responseInfo.responseBundle = responseBundle;
    return responseInfo;
}

From source file:com.goodhustle.ouyaunitybridge.OuyaUnityActivity.java

/**
 * Save the products and receipts if we're going for a restart.
 *//*from ww  w  .  j ava2s  .  c  o  m*/
@Override
protected void onSaveInstanceState(final Bundle outState) {
    if (mProductList != null) {
        outState.putParcelableArray(PRODUCTS_INSTANCE_STATE_KEY,
                mProductList.toArray(new Product[mProductList.size()]));
    }
    if (mReceiptList != null) {
        outState.putParcelableArray(RECEIPTS_INSTANCE_STATE_KEY,
                mReceiptList.toArray(new Receipt[mReceiptList.size()]));
    }
}

From source file:de.spiritcroc.ownlog.ui.fragment.LogFilterEditFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBoolean(KEY_ADD_ITEM, mAddItem);
    outState.putLong(KEY_EDIT_ITEM_ID, mEditItemId);
    outState.putString(KEY_INIT_NAME, mInitName);
    outState.putString(KEY_SET_NAME, mEditName.getText().toString());
    outState.putString(KEY_INIT_SORT_ORDER, mInitSortOrder);
    outState.putInt(KEY_SORT_ORDER, mSortOrder);
    outState.putBoolean(KEY_INIT_STRICT_TAG_FILTER, mInitStrictFilterTags);
    outState.putBoolean(KEY_SET_STRICT_TAG_FILTER, mCheckStrictFilterTags.isChecked());
    outState.putParcelableArray(KEY_INIT_TAGS, mInitTags.toArray(new TagItem[mInitTags.size()]));
    outState.putParcelableArray(KEY_INIT_EXCLUDED_TAGS,
            mInitExcludedTags.toArray(new TagItem[mInitExcludedTags.size()]));
    outState.putParcelableArray(KEY_SET_TAGS, mSetTags.toArray(new TagItem[mSetTags.size()]));
    outState.putParcelableArray(KEY_EXCLUDED_TAGS, mExcludedTags.toArray(new TagItem[mExcludedTags.size()]));
    outState.putParcelableArray(KEY_AVAILABLE_TAGS, mAvailableTags.toArray(new TagItem[mAvailableTags.size()]));
}