Example usage for android.os Parcel writeInt

List of usage examples for android.os Parcel writeInt

Introduction

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

Prototype

public final void writeInt(int val) 

Source Link

Document

Write an integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Usage

From source file:Main.java

public static void writeStringToParcel(Parcel out, String str) {
    if (str != null) {
        out.writeInt(1);
        out.writeString(str);//from   w w w.  j  a va2s .  c  om
    } else {
        out.writeInt(0);
    }
}

From source file:Main.java

/**
 * Write a HashMap to a Parcel, class of key and value are both String
 * /*from w ww. j a v a 2s  .c o  m*/
 * @param map
 * @param out
 * @param flags
 */
public static void writeHashMapStringAndString(Map<String, String> map, Parcel out, int flags) {
    if (map != null) {
        out.writeInt(map.size());
        for (Entry<String, String> entry : map.entrySet()) {
            out.writeString(entry.getKey());
            out.writeString(entry.getValue());
        }
    } else {
        out.writeInt(-1);
    }
}

From source file:hochschuledarmstadt.photostream_tools.Fakes.java

public static Photo buildFakePhoto(int id, String filePath, String desc, boolean liked, boolean deleteable,
        int commentCount) {
    Parcel source = Parcel.obtain();
    source.writeInt(id);
    source.writeString(filePath);// w w  w  .j  ava  2s  .co  m
    source.writeString(desc);
    source.writeInt(liked ? 1 : 0);
    source.writeInt(deleteable ? 1 : 0);
    source.writeInt(commentCount);
    source.setDataPosition(0);
    Photo photo = Photo.CREATOR.createFromParcel(source);
    source.recycle();
    return photo;
}

From source file:Main.java

public static void writeStringMap(Map<String, String> map, Parcel parcel) {
    if (map != null && map.size() > 0) {
        parcel.writeInt(map.size());
        for (Map.Entry<String, String> entry : map.entrySet()) {
            parcel.writeString(entry.getKey());
            parcel.writeString(entry.getValue());
        }/*from w  w  w  . j  av  a  2  s .c  o m*/
    } else {
        parcel.writeInt(0);
    }
}

From source file:Main.java

/**
 * Write a HashMap to a Parcel, class of key and value can parcelable both
 * //  www . ja  v  a2 s  .c  om
 * @param map
 * @param out
 * @param flags
 */
public static <K extends Parcelable, V extends Parcelable> void writeHashMap(Map<K, V> map, Parcel out,
        int flags) {
    if (map != null) {
        out.writeInt(map.size());

        for (Entry<K, V> entry : map.entrySet()) {
            out.writeParcelable(entry.getKey(), flags);
            out.writeParcelable(entry.getValue(), flags);
        }
    } else {
        out.writeInt(-1);
    }
}

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

/**
 * Writes a boolean value to a Parcel./*  w  w  w. j  ava 2  s. com*/
 *
 * @param out   the Parcel to write to.
 * @param value the boolean value to write.
 */
static void writeBoolean(Parcel out, boolean value) {
    out.writeInt(value ? 1 : 0);
}

From source file:com.oasisfeng.android.service.notification.StatusBarNotificationCompat.java

private static UserHandle toUserHandle(final int user) {
    final Parcel parcel = Parcel.obtain();
    try {//from  www  .  ja v  a2s  .  c  om
        parcel.writeInt(user);
        parcel.setDataPosition(0);
        return UserHandle.readFromParcel(parcel);
    } finally {
        parcel.recycle();
    }
}

From source file:org.opendatakit.database.queries.BindArgs.java

private static void marshallObject(Parcel out, Object toMarshall) {
    if (toMarshall == null) {
        out.writeInt(0);
    } else if (toMarshall instanceof String) {
        out.writeInt(1);/*  w w  w  .  ja v  a  2s  .c  o  m*/
        out.writeString((String) toMarshall);
    } else if (toMarshall instanceof Integer) {
        out.writeInt(2);
        out.writeInt((Integer) toMarshall);
    } else if (toMarshall instanceof Boolean) {
        if ((Boolean) toMarshall) {
            out.writeInt(3);
        } else {
            out.writeInt(4);
        }
    } else if (toMarshall instanceof Double) {
        out.writeInt(5);
        out.writeDouble((Double) toMarshall);
    } else if (toMarshall instanceof Float) {
        out.writeInt(6);
        out.writeFloat((Float) toMarshall);
    } else if (toMarshall instanceof Long) {
        out.writeInt(7);
        out.writeLong((Long) toMarshall);
    } else {
        throw new IllegalStateException("should have been prevented in constructor");
    }
}

From source file:edu.umich.flowfence.common.QMDescriptor.java

public static void writeToParcel(QMDescriptor desc, Parcel dest, int flags) {
    if (desc == null) {
        dest.writeInt(KIND_NULL);
    } else {/*from w w  w  . j a v a2 s.com*/
        desc.writeToParcel(dest, flags);
    }
}

From source file:edu.umich.oasis.common.SodaDescriptor.java

public static void writeToParcel(SodaDescriptor desc, Parcel dest, int flags) {
    if (desc == null) {
        dest.writeInt(KIND_NULL);
    } else {/*from www  .  ja  v  a  2  s .c o  m*/
        desc.writeToParcel(dest, flags);
    }
}