1 /* 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 */ 16 package com.android.codegentest; 17 18 import android.os.Parcel; 19 20 import com.android.internal.util.Parcelling; 21 22 import java.util.Date; 23 import 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 */ 34 public class MyDateParcelling implements Parcelling<Date> { 35 36 static AtomicInteger sInstanceCount = new AtomicInteger(0); 37 MyDateParcelling()38 public MyDateParcelling() { 39 sInstanceCount.getAndIncrement(); 40 } 41 42 @Override parcel(Date item, Parcel dest, int parcelFlags)43 public void parcel(Date item, Parcel dest, int parcelFlags) { 44 dest.writeLong(item.getTime()); 45 } 46 47 @Override unparcel(Parcel source)48 public Date unparcel(Parcel source) { 49 return new Date(source.readLong()); 50 } 51 } 52