blob: 4faeb8ee8893e2f7ede58488d68345556391dec6 [file] [log] [blame]
Eugene Susla574b7e12019-03-13 13:16:33 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
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 */
16package com.android.codegentest;
17
18import android.os.Parcel;
19
20import com.android.internal.util.Parcelling;
21
22import java.util.Date;
23import java.util.concurrent.atomic.AtomicInteger;
24
25/**
26 * Sample {@link Parcelling} implementation for {@link Date}.
27 *
28 * See {@link SampleDataClass#mDate} for usage.
29 * See {@link SampleDataClass#writeToParcel} + {@link SampleDataClass#sParcellingForDate}
30 * for resulting generated code.
31 *
32 * Ignore {@link #sInstanceCount} - used for testing.
33 */
Eugene Susla3156a4c2019-07-25 14:05:12 -070034public class MyDateParcelling implements Parcelling<Date> {
Eugene Susla574b7e12019-03-13 13:16:33 -070035
36 static AtomicInteger sInstanceCount = new AtomicInteger(0);
37
Eugene Susla3156a4c2019-07-25 14:05:12 -070038 public MyDateParcelling() {
Eugene Susla574b7e12019-03-13 13:16:33 -070039 sInstanceCount.getAndIncrement();
40 }
41
42 @Override
43 public void parcel(Date item, Parcel dest, int parcelFlags) {
44 dest.writeLong(item.getTime());
45 }
46
47 @Override
48 public Date unparcel(Parcel source) {
49 return new Date(source.readLong());
50 }
51}