Example usage for android.os Parcel obtain

List of usage examples for android.os Parcel obtain

Introduction

In this page you can find the example usage for android.os Parcel obtain.

Prototype

public static Parcel obtain() 

Source Link

Document

Retrieve a new Parcel object from the pool.

Usage

From source file:com.scvngr.levelup.core.model.CreditCardTest.java

@SmallTest
public void testParcel() {
    final CreditCard card = CreditCardFixture.getFullModel(0);

    final Parcel parcel = Parcel.obtain();
    card.writeToParcel(parcel, 0);/*from w  ww. j a v a 2  s.c  om*/
    parcel.setDataPosition(0);

    final CreditCard card2 = CreditCard.CREATOR.createFromParcel(parcel);
    parcel.recycle();
    assertEquals(card, card2);
}

From source file:com.scvngr.levelup.core.model.CampaignTest.java

@SmallTest
public void testParcel() throws JSONException {
    {/* w w  w. j a  v  a  2s. c o  m*/
        final JSONObject object = CampaignFixture.getFullJsonObject();

        final Campaign campaign = new CampaignJsonFactory().from(object);
        final Parcel parcel = Parcel.obtain();
        campaign.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final Campaign parceled = Campaign.CREATOR.createFromParcel(parcel);
        assertEquals(campaign, parceled);
    }
}

From source file:cl.smartcities.isci.transportinspector.backend.BusTest.java

@Test
public void busParcelWriteReadTest() {
    Parcel parcel = Parcel.obtain();
    bus.writeToParcel(parcel, bus.describeContents());

    parcel.setDataPosition(0);/*from w ww  .  ja v  a  2s  . c  o  m*/

    Bus createdFromParcel = Bus.CREATOR.createFromParcel(parcel);

    assertThat(createdFromParcel.getService(), is(SERVICE));
    assertThat(createdFromParcel.getLicensePlate(), is(LICENSE_PLATE));
    assertThat(createdFromParcel.getActiveMapBusIcon(), is(bus.getActiveMapBusIcon()));
    assertThat(createdFromParcel.getBusIcon(), is(bus.getBusIcon()));
    assertThat(createdFromParcel.getDistance(), is(bus.getDistance()));
    assertThat(createdFromParcel.getTime(), is(bus.getTime()));
}

From source file:com.scvngr.levelup.core.model.CauseAffiliationTest.java

@SmallTest
public void testParcel() {
    final CauseAffiliation causeAffiliation = CauseAffiliationFixture.getFullModel();

    final Parcel parcel = Parcel.obtain();
    causeAffiliation.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);/*ww  w .  j a v a  2 s .c o m*/

    final CauseAffiliation causeAffiliation2 = CauseAffiliation.CREATOR.createFromParcel(parcel);
    parcel.recycle();
    assertEquals(causeAffiliation, causeAffiliation2);
}

From source file:com.scvngr.levelup.core.model.PaymentTokenTest.java

@SmallTest
public void testParcel() throws JSONException {
    final JSONObject object = PaymentTokenFixture.getFullJsonObject();

    final PaymentToken paymentToken = new PaymentTokenJsonFactory().from(object);
    final Parcel parcel = Parcel.obtain();
    paymentToken.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);//w  w w  .  jav a  2 s .  co m

    final PaymentToken parceled = PaymentToken.CREATOR.createFromParcel(parcel);
    assertEquals(paymentToken, parceled);
}

From source file:org.gearvrf.weartouchpad.MessageListenerService.java

private static <T> T unmarshall(byte[] bytes, Parcelable.Creator<T> creator) {
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);/*  w  w w.  j  a v a 2 s . com*/
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}

From source file:io.github.data4all.model.data.TransformationParamBeanTest.java

/**
 * Create a new Parcel to save/parcelable the testRelationMember, afterwards
 * a new relation member is created from the parcel and we check if it
 * contains all attributes./*from  w w w  .java 2s.  c o  m*/
 */
@Test
public void test_parcelable_transformationbean() {
    Parcel newParcel = Parcel.obtain();
    Location location = new Location("test");
    location.setLatitude(10);
    location.setLongitude(20);
    TransformationParamBean testBean = new TransformationParamBean(10, 20, 30, 40, 50, location);

    testBean.writeToParcel(newParcel, 0);
    newParcel.setDataPosition(0);
    TransformationParamBean deParcelBean = TransformationParamBean.CREATOR.createFromParcel(newParcel);

    assertEquals(testBean.getHeight(), deParcelBean.getHeight(), 0);
    assertEquals(testBean.getCameraMaxHorizontalViewAngle(), deParcelBean.getCameraMaxHorizontalViewAngle(), 0);
    assertEquals(testBean.getCameraMaxVerticalViewAngle(), deParcelBean.getCameraMaxVerticalViewAngle(), 0);
    assertEquals(testBean.getPhotoWidth(), deParcelBean.getPhotoWidth(), 0);
    assertEquals(testBean.getPhotoHeight(), deParcelBean.getPhotoHeight(), 0);

    assertEquals(location.getProvider(), deParcelBean.getLocation().getProvider());
    assertEquals(location.getLatitude(), deParcelBean.getLocation().getLatitude(), 0);
    assertEquals(location.getLongitude(), deParcelBean.getLocation().getLongitude(), 0);
}

From source file:com.facebook.TestUtils.java

public static <E extends Parcelable> E parcelAndUnparcel(final E object) {
    final Parcel writeParcel = Parcel.obtain();
    final Parcel readParcel = Parcel.obtain();
    try {// w w  w.jav  a  2  s. co m
        writeParcel.writeParcelable(object, 0);
        final byte[] bytes = writeParcel.marshall();
        readParcel.unmarshall(bytes, 0, bytes.length);
        readParcel.setDataPosition(0);
        return readParcel.readParcelable(object.getClass().getClassLoader());
    } finally {
        writeParcel.recycle();
        readParcel.recycle();
    }
}

From source file:com.scvngr.levelup.core.model.UserTest.java

@SmallTest
public void testParcel_full() throws JSONException {
    {//from  ww  w. ja  va 2s.com
        final JSONObject object = UserFixture.getFullJsonObject();

        final User user = new UserJsonFactory().from(object);
        final Parcel parcel = Parcel.obtain();
        user.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final User parceled = User.CREATOR.createFromParcel(parcel);
        assertEquals(user, parceled);
        assertTrue(user.getCustomAttributes().containsKey("test_attr"));
        assertTrue(user.getCustomAttributes().containsKey("test_attr2"));
        assertEquals("0", user.getCustomAttributes().get("test_attr"));
        assertEquals("1", user.getCustomAttributes().get("test_attr2"));
    }

    {
        final JSONObject object = UserFixture.getMinimalJsonObject();

        final User user = new UserJsonFactory().from(object);
        final Parcel parcel = Parcel.obtain();
        user.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final User parceled = User.CREATOR.createFromParcel(parcel);
        assertEquals(user, parceled);
    }

    {
        final JSONObject object = UserFixture.getFullJsonObject();

        object.remove(UserJsonFactory.JsonKeys.CUSTOM_ATTRIBUTES);
        final User user = new UserJsonFactory().from(object);
        final Parcel parcel = Parcel.obtain();
        user.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final User parceled = User.CREATOR.createFromParcel(parcel);
        assertEquals(user, parceled);
        assertNull(parceled.getCustomAttributes());
    }
}

From source file:com.nestlabs.sdk.CameraAndroidTest.java

@Test
public void testCameraToParcel() {
    try {/*w w w .  j  av a  2  s. co  m*/
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_CAMERA_JSON), "utf-8");
        Camera camera = mapper.readValue(json, Camera.class);

        Parcel parcel = Parcel.obtain();
        camera.writeToParcel(parcel, 0);

        parcel.setDataPosition(0);

        Camera cameraFromParcel = Camera.CREATOR.createFromParcel(parcel);
        assertEquals(camera, cameraFromParcel);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    }
}