Search in sources :

Example 1 with Parcel

use of android.os.Parcel in project cw-omnibus by commonsguy.

the class Parcelables method toByteArray.

public static byte[] toByteArray(Parcelable parcelable) {
    Parcel parcel = Parcel.obtain();
    parcelable.writeToParcel(parcel, 0);
    byte[] result = parcel.marshall();
    parcel.recycle();
    return (result);
}
Also used : Parcel(android.os.Parcel)

Example 2 with Parcel

use of android.os.Parcel in project cw-omnibus by commonsguy.

the class Parcelables method toParcelable.

public static <T> T toParcelable(byte[] bytes, Parcelable.Creator<T> creator) {
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return (result);
}
Also used : Parcel(android.os.Parcel)

Example 3 with Parcel

use of android.os.Parcel in project materialistic by hidroh.

the class FavoriteManagerTest method testFavorite.

@Test
public void testFavorite() {
    Parcel parcel = Parcel.obtain();
    parcel.writeString("1");
    parcel.writeString("http://example.com");
    parcel.writeString("title");
    parcel.setDataPosition(0);
    Favorite favorite = Favorite.CREATOR.createFromParcel(parcel);
    assertEquals("title", favorite.getDisplayedTitle());
    assertEquals("example.com", favorite.getSource());
    assertEquals("http://example.com", favorite.getUrl());
    assertEquals("1", favorite.getId());
    assertNotNull(favorite.getDisplayedAuthor(RuntimeEnvironment.application, true, 0));
    assertEquals(Item.STORY_TYPE, favorite.getType());
    assertTrue(favorite.isStoryType());
    assertEquals("title (http://example.com) - https://news.ycombinator.com/item?id=1", favorite.toString());
    assertEquals(0, favorite.describeContents());
    Parcel output = Parcel.obtain();
    favorite.writeToParcel(output, 0);
    output.setDataPosition(0);
    assertEquals("1", output.readString());
    assertThat(Favorite.CREATOR.newArray(1)).hasSize(1);
}
Also used : Parcel(android.os.Parcel) Test(org.junit.Test)

Example 4 with Parcel

use of android.os.Parcel in project Android-ObservableScrollView by ksoichiro.

the class SavedStateTest method testListViewSavedState.

public void testListViewSavedState() throws Throwable {
    Parcel parcel = Parcel.obtain();
    ObservableListView.SavedState state1 = new ObservableListView.SavedState(AbsSavedState.EMPTY_STATE);
    state1.prevFirstVisiblePosition = 1;
    state1.prevFirstVisibleChildHeight = 2;
    state1.prevScrolledChildrenHeight = 3;
    state1.prevScrollY = 4;
    state1.scrollY = 5;
    state1.childrenHeights = new SparseIntArray();
    state1.childrenHeights.put(0, 10);
    state1.childrenHeights.put(1, 20);
    state1.childrenHeights.put(2, 30);
    state1.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    ObservableListView.SavedState state2 = ObservableListView.SavedState.CREATOR.createFromParcel(parcel);
    assertNotNull(state2);
    assertEquals(state1.prevFirstVisiblePosition, state2.prevFirstVisiblePosition);
    assertEquals(state1.prevFirstVisibleChildHeight, state2.prevFirstVisibleChildHeight);
    assertEquals(state1.prevScrolledChildrenHeight, state2.prevScrolledChildrenHeight);
    assertEquals(state1.prevScrollY, state2.prevScrollY);
    assertEquals(state1.scrollY, state2.scrollY);
    assertNotNull(state1.childrenHeights);
    assertEquals(3, state1.childrenHeights.size());
    assertEquals(10, state1.childrenHeights.get(0));
    assertEquals(20, state1.childrenHeights.get(1));
    assertEquals(30, state1.childrenHeights.get(2));
}
Also used : AbsSavedState(android.view.AbsSavedState) SparseIntArray(android.util.SparseIntArray) Parcel(android.os.Parcel)

Example 5 with Parcel

use of android.os.Parcel in project android_frameworks_base by ParanoidAndroid.

the class UsageStatsService method writeStatsFLOCK.

private void writeStatsFLOCK(File file) throws IOException {
    FileOutputStream stream = new FileOutputStream(file);
    try {
        Parcel out = Parcel.obtain();
        writeStatsToParcelFLOCK(out);
        stream.write(out.marshall());
        out.recycle();
        stream.flush();
    } finally {
        FileUtils.sync(stream);
        stream.close();
    }
}
Also used : Parcel(android.os.Parcel) FileOutputStream(java.io.FileOutputStream)

Aggregations

Parcel (android.os.Parcel)3576 Point (android.graphics.Point)263 Test (org.junit.Test)238 SmallTest (android.test.suitebuilder.annotation.SmallTest)163 RemoteException (android.os.RemoteException)142 IBinder (android.os.IBinder)120 IOException (java.io.IOException)105 FileOutputStream (java.io.FileOutputStream)72 File (java.io.File)69 Bundle (android.os.Bundle)60 Intent (android.content.Intent)51 ArrayList (java.util.ArrayList)51 SmallTest (android.support.test.filters.SmallTest)50 ParcelFileDescriptor (android.os.ParcelFileDescriptor)35 FileInputStream (java.io.FileInputStream)34 ComponentName (android.content.ComponentName)33 KeyphraseRecognitionEvent (android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent)28 Keyphrase (android.hardware.soundtrigger.SoundTrigger.Keyphrase)24 KeyphraseSoundModel (android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel)20 Uri (android.net.Uri)20