-
Notifications
You must be signed in to change notification settings - Fork 267
/
AndroidParcelable.xml
42 lines (41 loc) · 4.51 KB
/
AndroidParcelable.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="AndroidParcelable">
<template name="Parcelable" value="protected $className$(android.os.Parcel in) { } @Override public int describeContents() { return 0; } @Override public void writeToParcel(@android.support.annotation.NonNull android.os.Parcel dest, int flags) { } public static final android.os.Parcelable.Creator<$className$> CREATOR = new Parcelable.Creator<$className$>() { @Override public $className$ createFromParcel(Parcel in) { return new $className$(in); } @Override public $className$[] newArray(int size) { return new $className$[size]; } };" description="Create a parcelable block for your current class" toReformat="true" toShortenFQNames="true">
<variable name="className" expression="className()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="ParcelableEnum" value="@Override public int describeContents() { return 0; } @Override public void writeToParcel(android.os.Parcel dest, int flags) { dest.writeInt(this.ordinal()); } public static final android.os.Parcelable.Creator<$className$> CREATOR = new Parcelable.Creator<$className$>() { @Override public $className$ createFromParcel(Parcel in) { return $className$.values()[in.readInt()]; } @Override public $className$[] newArray(int size) { return new $className$[size]; } };" description="Create a parcelable block for your current enum" toReformat="true" toShortenFQNames="true">
<variable name="className" expression="className()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="ParcelableEnumTest" value="@Test public void testDescribeContents() throws Exception { for ($className$ value : $className$.values()) { assertEquals(0, value.describeContents()); } } @Test public void testWriteToParcel() throws Exception { Parcel parcel; for ($className$ value : $className$.values()) { parcel = Parcel.obtain(); Parcel parceled$className$ = ParcelableHelper.writeToParcelAndResetDataPosition(value, 0); value.writeToParcel(parcel, 0); parcel.setDataPosition(0); $className$ unparceled$className$ = $className$.CREATOR.createFromParcel(parceled$className$); assertEquals(value, unparceled$className$); } } @Test public void testArrayParcelable() throws Exception { $className$[] values = $className$.CREATOR.newArray($className$.values().length); assertEquals($className$.values().length, values.length); }" description="Creates basic parcelable enum test methods" toReformat="true" toShortenFQNames="true">
<variable name="className" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="ParcelBoolean" value="dest.writeInt($bool$ ? 0 : 1);" description="writes a single boolean value to a parcel" toReformat="true" toShortenFQNames="true">
<variable name="bool" expression="" defaultValue="" alwaysStopAt="true" />
<context />
</template>
<template name="UnparcelBoolean" value="$bool$ = 0 == in.readInt();" description="reads a single boolean value from a parcel" toReformat="true" toShortenFQNames="true">
<variable name="bool" expression="" defaultValue="" alwaysStopAt="true" />
<context />
</template>
<template name="UnparcelIntArray" value="int $read$[] = in.createIntArray(); in.readIntArray($read$);" description="Unparcels an int array" toReformat="true" toShortenFQNames="true">
<variable name="read" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="UnparcelStringArray" value="String $read$[] = in.createStringArray(); in.readStringArray($read$);" description="Unparcels a String array" toReformat="true" toShortenFQNames="true">
<variable name="read" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
</templateSet>