Example usage for android.os Parcel readParcelable

List of usage examples for android.os Parcel readParcelable

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public final <T extends Parcelable> T readParcelable(ClassLoader loader) 

Source Link

Document

Read and return a new Parcelable from the parcel.

Usage

From source file:Main.java

@SuppressWarnings("unchecked")
public static Parcelable readParcelable(Context context, String fileName, ClassLoader classLoader) {
    Parcelable parcelable = null;//from  w w  w .j  a va  2 s .co m
    FileInputStream fis = null;
    ByteArrayOutputStream bos = null;
    try {
        fis = context.openFileInput(fileName);
        if (fis != null) {
            bos = new ByteArrayOutputStream();
            byte[] b = new byte[4096];
            int bytesRead;
            while ((bytesRead = fis.read(b)) != -1) {
                bos.write(b, 0, bytesRead);
            }

            byte[] data = bos.toByteArray();

            Parcel parcel = Parcel.obtain();
            parcel.unmarshall(data, 0, data.length);
            parcel.setDataPosition(0);
            parcelable = parcel.readParcelable(classLoader);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
        parcelable = null;
    } finally {
        if (fis != null)
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        if (bos != null)
            try {
                bos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

    return parcelable;
}

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 . j  a  v  a2 s.c om*/
        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.baasbox.android.BaasLink.java

private static BaasObject readObject(Parcel parcel) {
    byte b = parcel.readByte();
    if (b == 0)//from  w  w w  . j ava2  s.c om
        return null;
    if (b == 1) {
        BaasDocument d = parcel.readParcelable(BaasDocument.class.getClassLoader());
        return d;
    } else if (b == 2) {
        BaasFile f = parcel.readParcelable(BaasFile.class.getClassLoader());
        return f;
    }
    return null;
}

From source file:com.tigerpenguin.places.model.Period.java

public Period(Parcel in) {
    openingTime = in.readParcelable(DayTime.class.getClassLoader());
    closingTime = in.readParcelable(DayTime.class.getClassLoader());
}

From source file:com.tigerpenguin.places.model.Geometry.java

public Geometry(Parcel in) {
    location = in.readParcelable(PlaceLocation.class.getClassLoader());
    viewports = new HashMap<String, PlaceLocation>();
    Bundle bundle = in.readBundle(PlaceLocation.class.getClassLoader());
    if (bundle != null) {
        for (String key : bundle.keySet()) {
            viewports.put(key, (PlaceLocation) bundle.getParcelable(key));
        }/*from  w  w w . j a  v a 2s . c  o m*/
    }
}

From source file:com.richtodd.android.quiltdesign.block.QuiltBlock.java

public QuiltBlock(Parcel in) {
    m_block = in.readParcelable(PaperPiecedBlock.class.getClassLoader());
}

From source file:com.schedjoules.eventdiscovery.framework.utils.anims.AbstractAnimated.java

protected AbstractAnimated(Parcel in) {
    this((FragmentTransition) in.readParcelable(AbstractAnimated.class.getClassLoader()), in.readInt(),
            in.readInt(), in.readInt(), in.readInt());
}

From source file:com.vk.sdk.api.model.VKApiGetMessagesResponse.java

/**
 * Creates an MessagesResponse instance from Parcel.
 *///from  w ww  .  j  a va  2s . c  o m
public VKApiGetMessagesResponse(Parcel in) {
    this.count = in.readInt();
    this.items = in.readParcelable(VKList.class.getClassLoader());
}

From source file:com.hannesdorfmann.mosby3.mvp.delegate.MosbyViewStateSavedState.java

protected MosbyViewStateSavedState(Parcel in, ClassLoader loader) {
    super(in, loader);
    this.mosbyViewState = in.readParcelable(loader);
}

From source file:com.vk.sdk.api.model.VKApiDialog.java

/**
 * Creates an Dialog instance from Parcel.
 *///from w ww .jav  a  2s . co m
public VKApiDialog(Parcel in) {
    this.unread = in.readInt();
    this.message = in.readParcelable(VKApiMessage.class.getClassLoader());
}