22 |
23 |
24 |
--------------------------------------------------------------------------------
/examples/java7-example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/examples/autovalue-example/src/main/java/nz/bradcampbell/autovalueexample/State.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.autovalueexample;
18 |
19 | import android.os.Parcelable;
20 | import com.google.auto.value.AutoValue;
21 | import java.util.Date;
22 |
23 | @AutoValue
24 | public abstract class State implements Parcelable {
25 | public static State create(int count, Date modificationDate) {
26 | return new AutoValue_State(count, modificationDate);
27 | }
28 |
29 | public abstract int count();
30 |
31 | public abstract Date modificationDate();
32 | }
33 |
--------------------------------------------------------------------------------
/examples/java7-lombok-example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/examples/autovalue-example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/serializable/Friend.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.serializable;
18 |
19 | import java.io.Serializable;
20 |
21 | public final class Friend implements Serializable {
22 | private final int id;
23 | private final String name;
24 |
25 | public Friend(
26 | int id,
27 | String name) {
28 | this.id = id;
29 | this.name = name;
30 | }
31 |
32 | public int getId() {
33 | return id;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/serializable/Name.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.serializable;
18 |
19 | import java.io.Serializable;
20 |
21 | public final class Name implements Serializable {
22 | private final String first;
23 | private final String last;
24 |
25 | public Name(
26 | String first,
27 | String last) {
28 | this.first = first;
29 | this.last = last;
30 | }
31 |
32 | public String getFirst() {
33 | return first;
34 | }
35 |
36 | public String getLast() {
37 | return last;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/autovalueparcel/Name.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.autovalueparcel;
18 |
19 | import android.os.Parcelable;
20 | import com.google.auto.value.AutoValue;
21 | import com.google.gson.Gson;
22 | import com.google.gson.TypeAdapter;
23 |
24 | @AutoValue
25 | public abstract class Name implements Parcelable {
26 | public abstract String first();
27 | public abstract String last();
28 |
29 | public static TypeAdapter typeAdapter(Gson gson) {
30 | return new AutoValue_Name.GsonTypeAdapter(gson);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/autovalueparcel/Friend.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.autovalueparcel;
18 |
19 | import android.os.Parcelable;
20 | import com.google.auto.value.AutoValue;
21 | import com.google.gson.Gson;
22 | import com.google.gson.TypeAdapter;
23 |
24 | @AutoValue
25 | public abstract class Friend implements Parcelable {
26 | public abstract int id();
27 | public abstract String name();
28 |
29 | public static TypeAdapter typeAdapter(Gson gson) {
30 | return new AutoValue_Friend.GsonTypeAdapter(gson);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/docs/2.x/paperparcel/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/paperparcel-compiler/src/main/java/paperparcel/OptionsHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel;
18 |
19 | /**
20 | * Holds an {@link OptionsDescriptor} instance across processing rounds.
21 | */
22 | final class OptionsHolder {
23 | private OptionsDescriptor options = OptionsDescriptor.DEFAULT;
24 | private boolean optionsApplied = false;
25 |
26 | final OptionsDescriptor getOptions() {
27 | return options;
28 | }
29 |
30 | final void setOptions(OptionsDescriptor options) {
31 | this.options = options;
32 | this.optionsApplied = true;
33 | }
34 |
35 | final boolean isOptionsApplied() {
36 | return optionsApplied;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/parceler/Friend.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.parceler;
18 |
19 | import org.parceler.Parcel;
20 | import org.parceler.ParcelConstructor;
21 |
22 | @Parcel(Parcel.Serialization.BEAN)
23 | public final class Friend {
24 | private final int id;
25 | private final String name;
26 |
27 | @ParcelConstructor
28 | public Friend(
29 | int id,
30 | String name) {
31 | this.id = id;
32 | this.name = name;
33 | }
34 |
35 | public int getId() {
36 | return id;
37 | }
38 |
39 | public String getName() {
40 | return name;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/parceler/Name.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.parceler;
18 |
19 | import org.parceler.Parcel;
20 | import org.parceler.ParcelConstructor;
21 |
22 | @Parcel(Parcel.Serialization.BEAN)
23 | public final class Name {
24 | private final String first;
25 | private final String last;
26 |
27 | @ParcelConstructor
28 | public Name(
29 | String first,
30 | String last) {
31 | this.first = first;
32 | this.last = last;
33 | }
34 |
35 | public String getFirst() {
36 | return first;
37 | }
38 |
39 | public String getLast() {
40 | return last;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/autovalueparcel/Image.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.autovalueparcel;
18 |
19 | import android.os.Parcelable;
20 | import com.google.auto.value.AutoValue;
21 | import com.google.gson.Gson;
22 | import com.google.gson.TypeAdapter;
23 |
24 | @AutoValue
25 | public abstract class Image implements Parcelable {
26 | public abstract String id();
27 | public abstract String format();
28 | public abstract String url();
29 | public abstract String description();
30 |
31 | public static TypeAdapter typeAdapter(Gson gson) {
32 | return new AutoValue_Image.GsonTypeAdapter(gson);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/examples/realm-example/src/main/java/nz/bradcampbell/realmexample/Email.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.realmexample;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 | import io.realm.RealmObject;
22 | import paperparcel.PaperParcel;
23 |
24 | @PaperParcel
25 | public class Email extends RealmObject implements Parcelable {
26 | public static final Creator CREATOR = PaperParcelEmail.CREATOR;
27 |
28 | public String address;
29 | public boolean active;
30 |
31 | @Override public int describeContents() {
32 | return 0;
33 | }
34 |
35 | @Override public void writeToParcel(Parcel dest, int flags) {
36 | PaperParcelEmail.writeToParcel(this, dest, flags);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/examples/java7-example/src/main/java/nz/bradcampbell/java7example/DateAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.java7example;
18 |
19 | import android.os.Parcel;
20 |
21 | import java.util.Date;
22 |
23 | import androidx.annotation.NonNull;
24 | import paperparcel.TypeAdapter;
25 |
26 | public final class DateAdapter implements TypeAdapter {
27 | public static final DateAdapter INSTANCE = new DateAdapter();
28 |
29 | @NonNull @Override public Date readFromParcel(@NonNull Parcel source) {
30 | return new Date(source.readLong());
31 | }
32 |
33 | @Override public void writeToParcel(@NonNull Date value, @NonNull Parcel dest, int flags) {
34 | dest.writeLong(value.getTime());
35 | }
36 |
37 | private DateAdapter() {}
38 | }
39 |
--------------------------------------------------------------------------------
/examples/java7-lombok-example/src/main/java/nz/bradcampbell/java7example/DateAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.java7example;
18 |
19 | import android.os.Parcel;
20 |
21 | import java.util.Date;
22 |
23 | import androidx.annotation.NonNull;
24 | import paperparcel.TypeAdapter;
25 |
26 | public final class DateAdapter implements TypeAdapter {
27 | public static final DateAdapter INSTANCE = new DateAdapter();
28 |
29 | @NonNull @Override public Date readFromParcel(@NonNull Parcel source) {
30 | return new Date(source.readLong());
31 | }
32 |
33 | @Override public void writeToParcel(@NonNull Date value, @NonNull Parcel dest, int flags) {
34 | dest.writeLong(value.getTime());
35 | }
36 |
37 | private DateAdapter() {}
38 | }
39 |
--------------------------------------------------------------------------------
/examples/autovalue-example/src/main/java/nz/bradcampbell/autovalueexample/DateAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.autovalueexample;
18 |
19 | import android.os.Parcel;
20 |
21 | import java.util.Date;
22 |
23 | import androidx.annotation.NonNull;
24 | import paperparcel.TypeAdapter;
25 |
26 | public final class DateAdapter implements TypeAdapter {
27 | public static final DateAdapter INSTANCE = new DateAdapter();
28 |
29 | @NonNull @Override public Date readFromParcel(@NonNull Parcel source) {
30 | return new Date(source.readLong());
31 | }
32 |
33 | @Override public void writeToParcel(@NonNull Date value, @NonNull Parcel dest, int flags) {
34 | dest.writeLong(value.getTime());
35 | }
36 |
37 | private DateAdapter() {}
38 | }
39 |
--------------------------------------------------------------------------------
/examples/realm-example/src/main/java/nz/bradcampbell/realmexample/Contact.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.realmexample;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 | import io.realm.RealmList;
22 | import io.realm.RealmObject;
23 | import paperparcel.PaperParcel;
24 |
25 | @PaperParcel
26 | public class Contact extends RealmObject implements Parcelable {
27 | public static final Creator CREATOR = PaperParcelContact.CREATOR;
28 |
29 | public String name;
30 | public RealmList emails;
31 |
32 | @Override public int describeContents() {
33 | return 0;
34 | }
35 |
36 | @Override public void writeToParcel(Parcel dest, int flags) {
37 | PaperParcelContact.writeToParcel(this, dest, flags);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/paperparcel/src/main/java/paperparcel/internal/SerializableAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel.internal;
18 |
19 | import android.os.Parcel;
20 |
21 | import java.io.Serializable;
22 |
23 | import androidx.annotation.NonNull;
24 | import androidx.annotation.Nullable;
25 | import paperparcel.TypeAdapter;
26 |
27 | @SuppressWarnings({ "WeakerAccess", "unused", "unchecked" }) // Used by generated code
28 | public final class SerializableAdapter implements TypeAdapter {
29 | @Nullable @Override public T readFromParcel(@NonNull Parcel source) {
30 | return (T) source.readSerializable();
31 | }
32 |
33 | @Override public void writeToParcel(@Nullable T value, @NonNull Parcel dest, int flags) {
34 | dest.writeSerializable(value);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/examples/java7-example/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
27 |
28 |
34 |
35 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/parceltasks/SerializableTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.parceltasks;
18 |
19 | import android.os.Parcel;
20 | import nz.bradcampbell.benchmarkdemo.model.serializable.SerializableResponse;
21 |
22 | public class SerializableTask extends ParcelTask {
23 | public SerializableTask(ParcelListener parcelListener, SerializableResponse response) {
24 | super(parcelListener, response);
25 | }
26 |
27 | @Override protected int writeThenRead(SerializableResponse response, Parcel parcel) {
28 | parcel.writeSerializable(response);
29 | parcel.setDataPosition(0);
30 | SerializableResponse out = (SerializableResponse) parcel.readSerializable();
31 | return out.getUsers().size();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/parceltasks/PaperParcelTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.parceltasks;
18 |
19 | import android.os.Parcel;
20 | import nz.bradcampbell.benchmarkdemo.model.paperparcel.PaperParcelResponse;
21 |
22 | public class PaperParcelTask extends ParcelTask {
23 | public PaperParcelTask(ParcelListener parcelListener, PaperParcelResponse response) {
24 | super(parcelListener, response);
25 | }
26 |
27 | @Override protected int writeThenRead(PaperParcelResponse response, Parcel parcel) {
28 | parcel.writeParcelable(response, 0);
29 | parcel.setDataPosition(0);
30 | PaperParcelResponse out = parcel.readParcelable(PaperParcelResponse.class.getClassLoader());
31 | return out.getUsers().size();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/docs/2.x/paperparcel/paperparcel/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | paperparcel
7 |
8 |
9 |
10 |
11 |
12 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/paperparcel/src/main/java/paperparcel/internal/EnumAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel.internal;
18 |
19 | import android.os.Parcel;
20 |
21 | import androidx.annotation.NonNull;
22 | import paperparcel.TypeAdapter;
23 |
24 | @SuppressWarnings({ "WeakerAccess", "unused" }) // Used by generated code
25 | public final class EnumAdapter> implements TypeAdapter {
26 | private final Class enumClass;
27 |
28 | public EnumAdapter(Class enumClass) {
29 | this.enumClass = enumClass;
30 | }
31 |
32 | @NonNull
33 | @Override public T readFromParcel(@NonNull Parcel source) {
34 | return Enum.valueOf(enumClass, source.readString());
35 | }
36 |
37 | @Override public void writeToParcel(@NonNull T value, @NonNull Parcel dest, int flags) {
38 | dest.writeString(value.name());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/examples/autovalue-example/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
27 |
28 |
34 |
35 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/paperparcel-compiler/src/main/java/paperparcel/CodeBlocks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel;
18 |
19 | import com.squareup.javapoet.CodeBlock;
20 | import java.util.Iterator;
21 |
22 | /** Utility methods for {@link CodeBlock}s */
23 | final class CodeBlocks {
24 |
25 | /** Joins multiple {@link CodeBlock}s together with a given delimiter */
26 | @SuppressWarnings("SameParameterValue")
27 | static CodeBlock join(Iterable codeBlocks, String delimiter) {
28 | CodeBlock.Builder builder = CodeBlock.builder();
29 | Iterator iterator = codeBlocks.iterator();
30 | while (iterator.hasNext()) {
31 | builder.add(iterator.next());
32 | if (iterator.hasNext()) {
33 | builder.add(delimiter);
34 | }
35 | }
36 | return builder.build();
37 | }
38 |
39 | private CodeBlocks() {}
40 | }
41 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/autovalueparcel/AutoValueParcelResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.autovalueparcel;
18 |
19 | import android.os.Parcelable;
20 | import com.google.auto.value.AutoValue;
21 | import com.google.gson.Gson;
22 | import com.google.gson.TypeAdapter;
23 | import com.google.gson.annotations.SerializedName;
24 | import java.util.List;
25 |
26 | @AutoValue
27 | public abstract class AutoValueParcelResponse implements Parcelable {
28 | public abstract List users();
29 | public abstract String status();
30 | @SerializedName("is_real_json") public abstract boolean isRealJson();
31 |
32 | public static TypeAdapter typeAdapter(Gson gson) {
33 | return new AutoValue_AutoValueParcelResponse.GsonTypeAdapter(gson);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/parceltasks/AutoValueParcelTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.parceltasks;
18 |
19 | import android.os.Parcel;
20 | import nz.bradcampbell.benchmarkdemo.model.autovalueparcel.AutoValueParcelResponse;
21 |
22 | public class AutoValueParcelTask extends ParcelTask {
23 | public AutoValueParcelTask(ParcelListener parcelListener, AutoValueParcelResponse response) {
24 | super(parcelListener, response);
25 | }
26 |
27 | @Override protected int writeThenRead(AutoValueParcelResponse response, Parcel parcel) {
28 | parcel.writeParcelable(response, 0);
29 | parcel.setDataPosition(0);
30 | AutoValueParcelResponse out = parcel.readParcelable(AutoValueParcelResponse.class.getClassLoader());
31 | return out.users().size();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/parceltasks/ParcelerTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.parceltasks;
18 |
19 | import android.os.Parcel;
20 | import nz.bradcampbell.benchmarkdemo.model.parceler.ParcelerResponse;
21 | import org.parceler.Parcels;
22 |
23 | public class ParcelerTask extends ParcelTask {
24 | public ParcelerTask(ParcelListener parcelListener, ParcelerResponse response) {
25 | super(parcelListener, response);
26 | }
27 |
28 | @Override protected int writeThenRead(ParcelerResponse response, Parcel parcel) {
29 | parcel.writeParcelable(Parcels.wrap(response), 0);
30 | parcel.setDataPosition(0);
31 | ParcelerResponse out = Parcels.unwrap(parcel.readParcelable(ParcelerResponse.class.getClassLoader()));
32 | return out.getUsers().size();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/examples/kotlin-example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-kapt'
4 |
5 | android {
6 | compileSdkVersion rootProject.ext.compileSdkVersion
7 | buildToolsVersion rootProject.ext.buildToolsVersion
8 |
9 | defaultConfig {
10 | applicationId "nz.bradcampbell.kotlinexample"
11 | minSdkVersion rootProject.ext.minSdkVersion
12 | targetSdkVersion rootProject.ext.targetSdkVersion
13 | versionCode 1
14 | versionName "1.0"
15 | }
16 |
17 | sourceSets {
18 | main.java.srcDirs += 'src/main/kotlin'
19 | test.java.srcDirs += 'src/test/kotlin'
20 | }
21 |
22 | compileOptions {
23 | sourceCompatibility rootProject.ext.sourceCompatibilityVersion
24 | targetCompatibility rootProject.ext.targetCompatibilityVersion
25 | }
26 |
27 | buildTypes {
28 | release {
29 | signingConfig signingConfigs.debug
30 | minifyEnabled true
31 | proguardFiles getDefaultProguardFile('proguard-android.txt')
32 | }
33 | }
34 | }
35 |
36 | dependencies {
37 | implementation deps.appCompat
38 |
39 | implementation project(':paperparcel')
40 | implementation project(':paperparcel-kotlin')
41 | kapt project(':paperparcel-compiler')
42 |
43 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
44 |
45 | testImplementation deps.junit
46 | testImplementation deps.compiletesting
47 | }
48 |
49 | tasks.withType(Test) {
50 | testLogging {
51 | events "passed", "skipped", "failed"
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
27 |
28 |
31 |
32 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | android:
7 | components:
8 | - tools
9 | - platform-tools
10 | - build-tools-28.0.3
11 | - android-28
12 | - extra-google-google_play_services
13 | - extra-google-m2repository
14 | - extra-android-m2repository
15 |
16 | before_install:
17 | # Install a sdkmanager version that supports the --licenses switch and
18 | # accept any Android SDK licenses. The output redirection prevents us from
19 | # hitting the travis log size limit of 4MB which would fail the build.
20 | - yes | sdkmanager tools > /dev/null
21 | - yes | sdkmanager --licenses > /dev/null
22 | # Install the system image
23 | - sdkmanager "system-images;android-24;default;armeabi-v7a"
24 | # Create and launch the emulator
25 | - echo no | avdmanager create avd --force -n test -k "system-images;android-24;default;armeabi-v7a"
26 | - $ANDROID_HOME/emulator/emulator -avd test -no-audio -no-window -no-snapshot -use-system-libs &
27 |
28 | install: ./gradlew clean assemble assembleAndroidTest --stacktrace
29 |
30 | before_script:
31 | - android-wait-for-emulator
32 | - adb shell input keyevent 82
33 |
34 | script: ./gradlew check connectedCheck --stacktrace
35 |
36 | sudo: false
37 |
38 | notifications:
39 | email: false
40 |
41 | before_cache:
42 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
43 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
44 |
45 | cache:
46 | directories:
47 | - $HOME/.gradle/caches/
48 | - $HOME/.gradle/wrapper/
49 | - $HOME/.android/build-cache
50 |
--------------------------------------------------------------------------------
/examples/java7-lombok-example/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
23 |
24 |
29 |
30 |
36 |
37 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/serializable/Image.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.serializable;
18 |
19 | import java.io.Serializable;
20 |
21 | public final class Image implements Serializable {
22 | private final String id;
23 | private final String format;
24 | private final String url;
25 | private final String description;
26 |
27 | public Image(
28 | String id,
29 | String format,
30 | String url,
31 | String description) {
32 | this.id = id;
33 | this.format = format;
34 | this.url = url;
35 | this.description = description;
36 | }
37 |
38 | public String getId() {
39 | return id;
40 | }
41 |
42 | public String getFormat() {
43 | return format;
44 | }
45 |
46 | public String getUrl() {
47 | return url;
48 | }
49 |
50 | public String getDescription() {
51 | return description;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/docs/javascripts/jquery.noisy.min.js:
--------------------------------------------------------------------------------
1 | (function(f){f.fn.noisy=function(a){function m(a){return(a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a))?{r:parseInt(a[1],16),g:parseInt(a[2],16),b:parseInt(a[3],16)}:null}a=f.extend({},f.fn.noisy.defaults,a);"undefined"!==typeof a.color&&(a.randomColors=!1);var g,k,b=!1;try{k=!0,localStorage.setItem("test",""),localStorage.removeItem("test"),b=localStorage.getItem(window.JSON.stringify(a))}catch(q){k=!1}if(b&&!a.disableCache)g=b;else{b=document.createElement("canvas");if(b.getContext){b.width=
2 | b.height=a.size;for(var l=b.getContext("2d"),d=l.createImageData(b.width,b.height),h=Math.round(a.intensity*Math.pow(a.size,2)),n=255*a.opacity;h--;){var e=~~(Math.random()*b.width),c=~~(Math.random()*b.height),e=4*(e+c*d.width);a.randomColors?(c=h%255,a.colorChannels===parseInt(a.colorChannels)?c=h%a.colorChannels:f.isArray(a.colorChannels)&&(c=a.colorChannels[0]+h%(a.colorChannels[1]-a.colorChannels[0])),d.data[e]=c,d.data[e+1]=a.monochrome?c:~~(255*Math.random()),d.data[e+2]=a.monochrome?c:~~(255*
3 | Math.random())):(c=m(a.color),d.data[e]=c.r,d.data[e+1]=c.g,d.data[e+2]=c.b);d.data[e+3]=~~(Math.random()*n)}l.putImageData(d,0,0);g=b.toDataURL("image/png");0!=g.indexOf("data:image/png")&&(g=a.fallback)}else g=a.fallback;if(window.JSON&&k&&!a.disableCache)try{localStorage.setItem(window.JSON.stringify(a),g)}catch(p){console.warn(p.message)}}return this.each(function(){f(this).css("background-image","url('"+g+"'),"+f(this).css("background-image"))})};f.fn.noisy.defaults={intensity:0.9,size:200,opacity:0.08,
4 | fallback:"",monochrome:!1,colorChannels:255,randomColors:!0,disableCache:!1}})(jQuery);
--------------------------------------------------------------------------------
/examples/java7-lombok-example/src/main/java/nz/bradcampbell/java7example/State.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.java7example;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 | import java.util.Date;
22 |
23 | import lombok.AllArgsConstructor;
24 | import lombok.Data;
25 | import lombok.RequiredArgsConstructor;
26 | import lombok.Value;
27 | import paperparcel.PaperParcel;
28 |
29 | @Data
30 | @PaperParcel
31 | @RequiredArgsConstructor
32 | public final class State implements Parcelable {
33 |
34 | public static Parcelable.Creator CREATOR = PaperParcelState.CREATOR;
35 |
36 | private final int count;
37 |
38 | private Date modificationDate;
39 |
40 | private transient long somethingToExclude = 1000L;
41 |
42 | @Override public int describeContents() {
43 | return 0;
44 | }
45 |
46 | @Override public void writeToParcel(Parcel dest, int flags) {
47 | PaperParcelState.writeToParcel(this, dest, flags);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/serializable/SerializableResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.serializable;
18 |
19 | import com.google.gson.annotations.SerializedName;
20 | import java.io.Serializable;
21 | import java.util.List;
22 |
23 | public final class SerializableResponse implements Serializable {
24 | private final List users;
25 | private final String status;
26 | @SerializedName("is_real_json") private final boolean isRealJson;
27 |
28 | public SerializableResponse(
29 | List users,
30 | String status,
31 | boolean isRealJson) {
32 | this.users = users;
33 | this.status = status;
34 | this.isRealJson = isRealJson;
35 | }
36 |
37 | public List getUsers() {
38 | return users;
39 | }
40 |
41 | public String getStatus() {
42 | return status;
43 | }
44 |
45 | public boolean isRealJson() {
46 | return isRealJson;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/paperparcel/Friend.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.paperparcel;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 | import paperparcel.PaperParcel;
22 |
23 | @PaperParcel
24 | public final class Friend implements Parcelable {
25 | public static final Parcelable.Creator CREATOR = PaperParcelFriend.CREATOR;
26 |
27 | private final int id;
28 | private final String name;
29 |
30 | public Friend(
31 | int id,
32 | String name) {
33 | this.id = id;
34 | this.name = name;
35 | }
36 |
37 | public int getId() {
38 | return id;
39 | }
40 |
41 | public String getName() {
42 | return name;
43 | }
44 |
45 | @Override public int describeContents() {
46 | return 0;
47 | }
48 |
49 | @Override public void writeToParcel(Parcel dest, int flags) {
50 | PaperParcelFriend.writeToParcel(this, dest, flags);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/paperparcel/Name.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.paperparcel;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 | import paperparcel.PaperParcel;
22 |
23 | @PaperParcel
24 | public final class Name implements Parcelable {
25 | public static final Parcelable.Creator CREATOR = PaperParcelName.CREATOR;
26 |
27 | public final String first;
28 | public final String last;
29 |
30 | public Name(
31 | String first,
32 | String last) {
33 | this.first = first;
34 | this.last = last;
35 | }
36 |
37 | public String getFirst() {
38 | return first;
39 | }
40 |
41 | public String getLast() {
42 | return last;
43 | }
44 |
45 | @Override public int describeContents() {
46 | return 0;
47 | }
48 |
49 | @Override public void writeToParcel(Parcel dest, int flags) {
50 | PaperParcelName.writeToParcel(this, dest, flags);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/paperparcel-kotlin/src/main/java/paperparcel/PaperParcelable.kt:
--------------------------------------------------------------------------------
1 | package paperparcel
2 |
3 | import android.os.Parcel
4 | import android.os.Parcelable
5 | import java.lang.reflect.Method
6 |
7 | /**
8 | * [Parcelable] with a default [Parcelable.describeContents] and [Parcelable.writeToParcel]
9 | * implementations.
10 | *
11 | * @since 2.0
12 | */
13 | interface PaperParcelable : Parcelable {
14 | override fun describeContents() = 0
15 |
16 | override fun writeToParcel(dest: Parcel, flags: Int) {
17 | val writeMethod = synchronized(writeMethods) {
18 | writeMethods.getOrPut(javaClass) {
19 | val annotatedClass = javaClass.annotatedClass
20 | val generatedClass = Class.forName(annotatedClass.implementationName)
21 | generatedClass
22 | .getDeclaredMethod("writeToParcel", annotatedClass, Parcel::class.java, Int::class.javaPrimitiveType)
23 | .apply { isAccessible = true }
24 | }
25 | }
26 | writeMethod.invoke(null, this, dest, flags)
27 | }
28 |
29 | private val Class<*>.annotatedClass: Class<*>
30 | get() {
31 | if (isAnnotationPresent(PaperParcel::class.java)) {
32 | return this
33 | }
34 | require(this != Any::class.java) {
35 | "Cannot find @PaperParcel on ${this@PaperParcelable.javaClass.name}."
36 | }
37 | return superclass.annotatedClass
38 | }
39 |
40 | private val Class<*>.implementationName: String
41 | get() = "${`package`.name}.PaperParcel${name.substring(`package`.name.length + 1).replace('$', '_')}"
42 |
43 | private companion object {
44 | val writeMethods = HashMap, Method>()
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/parceler/Image.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.parceler;
18 |
19 | import org.parceler.Parcel;
20 | import org.parceler.ParcelConstructor;
21 |
22 | @Parcel(Parcel.Serialization.BEAN)
23 | public final class Image {
24 | private final String id;
25 | private final String format;
26 | private final String url;
27 | private final String description;
28 |
29 | @ParcelConstructor
30 | public Image(
31 | String id,
32 | String format,
33 | String url,
34 | String description) {
35 | this.id = id;
36 | this.format = format;
37 | this.url = url;
38 | this.description = description;
39 | }
40 |
41 | public String getId() {
42 | return id;
43 | }
44 |
45 | public String getFormat() {
46 | return format;
47 | }
48 |
49 | public String getUrl() {
50 | return url;
51 | }
52 |
53 | public String getDescription() {
54 | return description;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/parceler/ParcelerResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.parceler;
18 |
19 | import com.google.gson.annotations.SerializedName;
20 | import java.util.List;
21 | import org.parceler.Parcel;
22 | import org.parceler.ParcelConstructor;
23 |
24 | @Parcel(Parcel.Serialization.BEAN)
25 | public final class ParcelerResponse {
26 | private final List users;
27 | private final String status;
28 | @SerializedName("is_real_json") private final boolean isRealJson;
29 |
30 | @ParcelConstructor
31 | public ParcelerResponse(
32 | List users,
33 | String status,
34 | boolean isRealJson) {
35 | this.users = users;
36 | this.status = status;
37 | this.isRealJson = isRealJson;
38 | }
39 |
40 | public List getUsers() {
41 | return users;
42 | }
43 |
44 | public String getStatus() {
45 | return status;
46 | }
47 |
48 | public boolean isIsRealJson() {
49 | return isRealJson;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/examples/java7-example/src/main/java/nz/bradcampbell/java7example/State.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.java7example;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 | import java.util.Date;
22 |
23 | import paperparcel.PaperParcel;
24 |
25 | @PaperParcel
26 | public final class State implements Parcelable {
27 | public static Parcelable.Creator CREATOR = PaperParcelState.CREATOR;
28 |
29 | private final int count;
30 |
31 | // Non-private variable can be assigned and read directly; it doesn't need a corresponding
32 | // constructor argument/setter method and an accessor method.
33 | Date modificationDate;
34 |
35 | // Excluded from the parcelling/unparcelling process
36 | private transient long somethingToExclude = 1000L;
37 |
38 | public State(int count) {
39 | this.count = count;
40 | }
41 |
42 | public int getCount() {
43 | return count;
44 | }
45 |
46 | @Override public int describeContents() {
47 | return 0;
48 | }
49 |
50 | @Override public void writeToParcel(Parcel dest, int flags) {
51 | PaperParcelState.writeToParcel(this, dest, flags);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/paperparcel-api/src/main/java/paperparcel/Adapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.Target;
22 |
23 | import static java.lang.annotation.RetentionPolicy.SOURCE;
24 |
25 | /**
26 | * Used in conjunction with {@link ProcessorConfig} to add a custom {@link TypeAdapter} to
27 | * PaperParcel's type system.
28 | */
29 | @Documented
30 | @Retention(SOURCE)
31 | @Target({})
32 | public @interface Adapter {
33 | /**
34 | * The {@link TypeAdapter} class to register into PaperParcel's type system.
35 | */
36 | Class extends TypeAdapter> value();
37 |
38 | /**
39 | * Return {@code true} if this {@link TypeAdapter} can handle {@code null}s or doesn't
40 | * need to (i.e. the {@link TypeAdapter} is parcelling a non-nullable type). If this returns
41 | * {@code false} (the default), then PaperParcel will do null-checking for you. Returning
42 | * {@code true} from this method can help by preventing double (or completely unnecessary)
43 | * null-checking.
44 | */
45 | boolean nullSafe() default false;
46 | }
47 |
--------------------------------------------------------------------------------
/paperparcel-api/src/main/java/paperparcel/ProcessorConfig.java:
--------------------------------------------------------------------------------
1 | package paperparcel;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.Target;
6 |
7 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
8 | import static java.lang.annotation.ElementType.PACKAGE;
9 | import static java.lang.annotation.ElementType.TYPE;
10 | import static java.lang.annotation.RetentionPolicy.SOURCE;
11 |
12 | /**
13 | *
Custom configuration of {@code PaperParcelProcessor}.
14 | *
15 | *
This annotation can be applied to any annotation, interface, class, or package element in
16 | * your source code. While this annotation can be almost applied anywhere, the convention is to
17 | * put it in one of the following places:
18 | *
19 | *
20 | *
A custom {@code android.app.Application} class.
21 | *
An empty interface named {@code PaperParcelConfig}.
22 | *
A package-info.java file.
23 | *
24 | *
25 | *
Note that this configuration will only apply to the module that it is defined in. If you
26 | * have a multi-module project where multiple modules are using PaperParcel, you'll need to
27 | * define a {@code ProcessorConfig} for each of those modules.
28 | *
29 | *
Only one {@code ProcessorConfig} can be applied per module.
30 | */
31 | @Documented
32 | @Retention(SOURCE)
33 | @Target({ ANNOTATION_TYPE, TYPE, PACKAGE })
34 | public @interface ProcessorConfig {
35 | /** Defines all of the custom {@link TypeAdapter}s to register into PaperParcel's type system. */
36 | Adapter[] adapters() default {};
37 |
38 | /** Defines the default processor options for {@literal @}PaperParcel classes. */
39 | PaperParcel.Options options() default @PaperParcel.Options;
40 | }
41 |
--------------------------------------------------------------------------------
/paperparcel/src/main/java/paperparcel/internal/SetAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel.internal;
18 |
19 | import android.os.Parcel;
20 |
21 | import java.util.LinkedHashSet;
22 | import java.util.Set;
23 |
24 | import androidx.annotation.NonNull;
25 | import paperparcel.TypeAdapter;
26 |
27 | @SuppressWarnings({ "WeakerAccess", "unused" }) // Used by generated code
28 | public final class SetAdapter implements TypeAdapter> {
29 | private final TypeAdapter itemAdapter;
30 |
31 | public SetAdapter(TypeAdapter itemAdapter) {
32 | this.itemAdapter = itemAdapter;
33 | }
34 |
35 | @NonNull @Override public Set readFromParcel(@NonNull Parcel source) {
36 | int size = source.readInt();
37 | Set value = new LinkedHashSet<>(size);
38 | for (int i = 0; i < size; i++) {
39 | value.add(itemAdapter.readFromParcel(source));
40 | }
41 | return value;
42 | }
43 |
44 | @Override
45 | public void writeToParcel(@NonNull Set value, @NonNull Parcel dest, int flags) {
46 | dest.writeInt(value.size());
47 | for (T item : value) {
48 | itemAdapter.writeToParcel(item, dest, flags);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/examples/realm-example/src/main/java/nz/bradcampbell/realmexample/RealmListTypeAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.realmexample;
18 |
19 | import android.os.Parcel;
20 |
21 | import androidx.annotation.NonNull;
22 | import io.realm.RealmList;
23 | import io.realm.RealmModel;
24 | import paperparcel.TypeAdapter;
25 |
26 | public class RealmListTypeAdapter implements TypeAdapter> {
27 | private final TypeAdapter itemAdapter;
28 |
29 | public RealmListTypeAdapter(TypeAdapter itemAdapter) {
30 | this.itemAdapter = itemAdapter;
31 | }
32 |
33 | @NonNull @Override public RealmList readFromParcel(@NonNull Parcel source) {
34 | int size = source.readInt();
35 | RealmList list = new RealmList<>();
36 | for (int i = 0; i < size; i++) {
37 | list.add(itemAdapter.readFromParcel(source));
38 | }
39 | return list;
40 | }
41 |
42 | @Override public void writeToParcel(@NonNull RealmList value, @NonNull Parcel dest, int flags) {
43 | dest.writeInt(value.size());
44 | for (int i = 0; i < value.size(); i++) {
45 | itemAdapter.writeToParcel(value.get(i), dest, flags);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/paperparcel/src/main/java/paperparcel/internal/CollectionAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel.internal;
18 |
19 | import android.os.Parcel;
20 |
21 | import java.util.ArrayList;
22 | import java.util.Collection;
23 |
24 | import androidx.annotation.NonNull;
25 | import paperparcel.TypeAdapter;
26 |
27 | @SuppressWarnings({ "WeakerAccess", "unused" }) // Used by generated code
28 | public final class CollectionAdapter implements TypeAdapter> {
29 | private final TypeAdapter itemAdapter;
30 |
31 | public CollectionAdapter(TypeAdapter itemAdapter) {
32 | this.itemAdapter = itemAdapter;
33 | }
34 |
35 | @NonNull @Override public Collection readFromParcel(@NonNull Parcel source) {
36 | int size = source.readInt();
37 | Collection value = new ArrayList<>(size);
38 | for (int i = 0; i < size; i++) {
39 | value.add(itemAdapter.readFromParcel(source));
40 | }
41 | return value;
42 | }
43 |
44 | @Override
45 | public void writeToParcel(@NonNull Collection value, @NonNull Parcel dest, int flags) {
46 | dest.writeInt(value.size());
47 | for (T item : value) {
48 | itemAdapter.writeToParcel(item, dest, flags);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/paperparcel/src/main/java/paperparcel/internal/ListAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel.internal;
18 |
19 | import android.os.Parcel;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import androidx.annotation.NonNull;
25 | import paperparcel.TypeAdapter;
26 |
27 | @SuppressWarnings({ "WeakerAccess", "unused" }) // Used by generated code
28 | public final class ListAdapter implements TypeAdapter> {
29 | private final TypeAdapter itemAdapter;
30 |
31 | public ListAdapter(TypeAdapter itemAdapter) {
32 | this.itemAdapter = itemAdapter;
33 | }
34 |
35 | @NonNull @Override public List readFromParcel(@NonNull Parcel source) {
36 | int size = source.readInt();
37 | List value = new ArrayList<>(size);
38 | for (int i = 0; i < size; i++) {
39 | value.add(itemAdapter.readFromParcel(source));
40 | }
41 | return value;
42 | }
43 |
44 | @Override
45 | public void writeToParcel(@NonNull List value, @NonNull Parcel dest, int flags) {
46 | int size = value.size();
47 | dest.writeInt(size);
48 | for (int i = 0; i < size; i++) {
49 | T item = value.get(i);
50 | itemAdapter.writeToParcel(item, dest, flags);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/paperparcel/Image.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.paperparcel;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 | import paperparcel.PaperParcel;
22 |
23 | @PaperParcel
24 | public final class Image implements Parcelable {
25 | public static final Creator CREATOR = PaperParcelImage.CREATOR;
26 |
27 | private final String id;
28 | private final String format;
29 | private final String url;
30 | private final String description;
31 |
32 | public Image(
33 | String id,
34 | String format,
35 | String url,
36 | String description) {
37 | this.id = id;
38 | this.format = format;
39 | this.url = url;
40 | this.description = description;
41 | }
42 |
43 | public String getId() {
44 | return id;
45 | }
46 |
47 | public String getFormat() {
48 | return format;
49 | }
50 |
51 | public String getUrl() {
52 | return url;
53 | }
54 |
55 | public String getDescription() {
56 | return description;
57 | }
58 |
59 | @Override public int describeContents() {
60 | return 0;
61 | }
62 |
63 | @Override public void writeToParcel(Parcel dest, int flags) {
64 | PaperParcelImage.writeToParcel(this, dest, flags);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/paperparcel/src/main/java/paperparcel/internal/SparseArrayAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel.internal;
18 |
19 | import android.os.Parcel;
20 | import android.util.SparseArray;
21 |
22 | import androidx.annotation.NonNull;
23 | import paperparcel.TypeAdapter;
24 |
25 | @SuppressWarnings({ "WeakerAccess", "unused" }) // Used by generated code
26 | public final class SparseArrayAdapter implements TypeAdapter> {
27 | private final TypeAdapter itemAdapter;
28 |
29 | public SparseArrayAdapter(TypeAdapter itemAdapter) {
30 | this.itemAdapter = itemAdapter;
31 | }
32 |
33 | @NonNull @Override public SparseArray readFromParcel(@NonNull Parcel source) {
34 | int size = source.readInt();
35 | SparseArray sparseArray = new SparseArray<>(size);
36 | for (int i = 0; i < size; i++) {
37 | sparseArray.put(source.readInt(), itemAdapter.readFromParcel(source));
38 | }
39 | return sparseArray;
40 | }
41 |
42 | @Override public void writeToParcel(@NonNull SparseArray value, @NonNull Parcel dest, int flags) {
43 | int size = value.size();
44 | dest.writeInt(size);
45 | for (int i = 0; i < size; i++) {
46 | int key = value.keyAt(i);
47 | dest.writeInt(key);
48 | itemAdapter.writeToParcel(value.get(key), dest, flags);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/paperparcel/build.gradle:
--------------------------------------------------------------------------------
1 | import org.gradle.internal.jvm.Jvm
2 |
3 | apply plugin: 'com.android.library'
4 |
5 | android {
6 | compileSdkVersion rootProject.ext.compileSdkVersion
7 | buildToolsVersion rootProject.ext.buildToolsVersion
8 |
9 | defaultConfig {
10 | minSdkVersion rootProject.ext.minSdkVersion
11 |
12 | consumerProguardFiles 'proguard-rules.txt'
13 |
14 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
15 | }
16 |
17 | compileOptions {
18 | sourceCompatibility rootProject.ext.sourceCompatibilityVersion
19 | targetCompatibility rootProject.ext.targetCompatibilityVersion
20 | }
21 | }
22 |
23 | tasks.withType(Test) {
24 | testLogging {
25 | events "passed", "skipped", "failed"
26 | }
27 | }
28 |
29 | dependencies {
30 | api project(':paperparcel-api')
31 | api deps.supportAnnotations
32 |
33 | androidTestImplementation deps.junit
34 | androidTestImplementation deps.truth
35 | androidTestImplementation deps.supportTestRunner
36 | androidTestAnnotationProcessor project(':paperparcel-compiler')
37 |
38 | testImplementation deps.junit
39 | testImplementation deps.truth
40 | testImplementation deps.compiletesting
41 | testImplementation files(getRuntimeJar())
42 | testImplementation files(Jvm.current().getToolsJar())
43 | testImplementation project(':paperparcel-compiler')
44 | testAnnotationProcessor project(':paperparcel-compiler')
45 | }
46 |
47 | def getRuntimeJar() {
48 | try {
49 | final File javaBase = new File(System.getProperty("java.home")).getCanonicalFile();
50 | File runtimeJar = new File(javaBase, "lib/rt.jar");
51 | if (runtimeJar.exists()) {
52 | return runtimeJar;
53 | }
54 | runtimeJar = new File(javaBase, "jre/lib/rt.jar");
55 | return runtimeJar.exists() ? runtimeJar : null;
56 | } catch (IOException e) {
57 | throw new RuntimeException(e);
58 | }
59 | }
60 |
61 | apply from: rootProject.file('gradle/bintray.gradle')
62 | apply from: rootProject.file('gradle/snapshots.gradle')
63 |
--------------------------------------------------------------------------------
/paperparcel-compiler/src/main/java/paperparcel/UniqueNameSet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Dagger Authors.
3 | * Modifications copyright (C) 2016 Bradley Campbell.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package paperparcel;
19 |
20 | import com.google.common.collect.Sets;
21 | import java.util.Set;
22 | import javax.lang.model.SourceVersion;
23 |
24 | /**
25 | * A collector for names to be used in the same namespace that should not conflict. This class
26 | * also ensures that the names are not Java keywords.
27 | */
28 | final class UniqueNameSet {
29 | private final Set uniqueNames = Sets.newLinkedHashSet();
30 |
31 | private final String separator;
32 |
33 | UniqueNameSet() {
34 | this("");
35 | }
36 |
37 | UniqueNameSet(String separator) {
38 | this.separator = separator;
39 | }
40 |
41 | /**
42 | * Generates a unique and valid name using {@code base}. If {@code base} has not yet been added,
43 | * and is not a Java keyword; it will be returned as-is, otherwise it will have a differentiator
44 | * appended.
45 | */
46 | String getUniqueName(CharSequence base) {
47 | String name = base.toString();
48 | for (int differentiator = 1; isInvalidName(name); differentiator++) {
49 | name = base.toString() + separator + differentiator;
50 | }
51 | return name;
52 | }
53 |
54 | private boolean isInvalidName(String name) {
55 | return !uniqueNames.add(name) || SourceVersion.isKeyword(name);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/model/paperparcel/PaperParcelResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.model.paperparcel;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 |
22 | import com.google.gson.annotations.SerializedName;
23 | import java.util.List;
24 | import paperparcel.PaperParcel;
25 |
26 | @PaperParcel
27 | public final class PaperParcelResponse implements Parcelable {
28 | public static final Creator CREATOR = PaperParcelPaperParcelResponse.CREATOR;
29 |
30 | private final List users;
31 | private final String status;
32 | @SerializedName("is_real_json") private final boolean isRealJson;
33 |
34 | public PaperParcelResponse(
35 | List users,
36 | String status,
37 | boolean isRealJson) {
38 | this.users = users;
39 | this.status = status;
40 | this.isRealJson = isRealJson;
41 | }
42 |
43 | public List getUsers() {
44 | return users;
45 | }
46 |
47 | public String getStatus() {
48 | return status;
49 | }
50 |
51 | public boolean isRealJson() {
52 | return isRealJson;
53 | }
54 |
55 | @Override public int describeContents() {
56 | return 0;
57 | }
58 |
59 | @Override public void writeToParcel(Parcel dest, int flags) {
60 | PaperParcelPaperParcelResponse.writeToParcel(this, dest, flags);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/examples/benchmark-demo/src/main/java/nz/bradcampbell/benchmarkdemo/parceltasks/ParcelTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package nz.bradcampbell.benchmarkdemo.parceltasks;
18 |
19 | import android.os.AsyncTask;
20 | import android.os.Parcel;
21 | import java.util.concurrent.TimeUnit;
22 |
23 | public abstract class ParcelTask extends AsyncTask {
24 | public interface ParcelListener {
25 | void onComplete(ParcelTask parcelTask, ParcelResult parcelResult);
26 | }
27 |
28 | private final ParcelListener parcelListener;
29 | private final T response;
30 |
31 | ParcelTask(ParcelListener parcelListener, T response) {
32 | this.parcelListener = parcelListener;
33 | this.response = response;
34 | }
35 |
36 | @Override
37 | protected ParcelResult doInBackground(Void... params) {
38 | System.gc();
39 | Parcel parcel = Parcel.obtain();
40 | long startTime = System.nanoTime();
41 | int objectCount = writeThenRead(response, parcel);
42 | long endTime = System.nanoTime();
43 | long duration = TimeUnit.NANOSECONDS.toMicros(endTime - startTime);
44 | parcel.recycle();
45 | return new ParcelResult(duration, objectCount);
46 | }
47 |
48 | @Override
49 | protected void onPostExecute(ParcelResult parcelResult) {
50 | parcelListener.onComplete(this, parcelResult);
51 | }
52 |
53 | protected abstract int writeThenRead(T response, Parcel parcel);
54 | }
55 |
--------------------------------------------------------------------------------
/paperparcel/src/main/java/paperparcel/internal/ParcelableAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel.internal;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 |
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 | import paperparcel.TypeAdapter;
25 |
26 | @SuppressWarnings({ "WeakerAccess", "unused" }) // Used by generated code
27 | public final class ParcelableAdapter implements TypeAdapter {
28 | private final Parcelable.Creator creator;
29 |
30 | public ParcelableAdapter(@Nullable Parcelable.Creator creator) {
31 | this.creator = creator;
32 | }
33 |
34 | @Nullable @Override public T readFromParcel(@NonNull Parcel source) {
35 | if (creator != null) {
36 | T result = null;
37 | if (source.readInt() == 1) {
38 | result = creator.createFromParcel(source);
39 | }
40 | return result;
41 | } else {
42 | return source.readParcelable(ParcelableAdapter.class.getClassLoader());
43 | }
44 | }
45 |
46 | @Override public void writeToParcel(@Nullable T value, @NonNull Parcel dest, int flags) {
47 | if (creator != null) {
48 | if (value == null) {
49 | dest.writeInt(0);
50 | } else {
51 | dest.writeInt(1);
52 | value.writeToParcel(dest, flags);
53 | }
54 | } else {
55 | dest.writeParcelable(value, flags);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/paperparcel/src/main/java/paperparcel/internal/MapAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Bradley Campbell.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package paperparcel.internal;
18 |
19 | import android.os.Parcel;
20 |
21 | import java.util.LinkedHashMap;
22 | import java.util.Map;
23 |
24 | import androidx.annotation.NonNull;
25 | import paperparcel.TypeAdapter;
26 |
27 | @SuppressWarnings({ "WeakerAccess", "unused" }) // Used by generated code
28 | public final class MapAdapter implements TypeAdapter