blob: d8459aa22fa1e0102615781318ed512553fd93bb [file] [log] [blame]
Philip P. Moltmannb42d1332017-03-27 09:55:30 -07001/*
2 * Copyright (C) 2017 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
17package android.view.autofill;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22import java.util.HashMap;
23import java.util.Map;
24
25/**
26 * A parcelable HashMap for {@link AutofillId} and {@link AutofillValue}
27 *
28 * {@hide}
29 */
30class ParcelableMap extends HashMap<AutofillId, AutofillValue> implements Parcelable {
31 ParcelableMap(int size) {
32 super(size);
33 }
34
35 @Override
36 public int describeContents() {
37 return 0;
38 }
39
40 @Override
41 public void writeToParcel(Parcel dest, int flags) {
42 dest.writeInt(size());
43
44 for (Map.Entry<AutofillId, AutofillValue> entry : entrySet()) {
45 dest.writeParcelable(entry.getKey(), 0);
46 dest.writeParcelable(entry.getValue(), 0);
47 }
48 }
49
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070050 public static final @android.annotation.NonNull Parcelable.Creator<ParcelableMap> CREATOR =
Philip P. Moltmannb42d1332017-03-27 09:55:30 -070051 new Parcelable.Creator<ParcelableMap>() {
52 @Override
53 public ParcelableMap createFromParcel(Parcel source) {
54 int size = source.readInt();
55
56 ParcelableMap map = new ParcelableMap(size);
57
58 for (int i = 0; i < size; i++) {
59 AutofillId key = source.readParcelable(null);
60 AutofillValue value = source.readParcelable(null);
61
62 map.put(key, value);
63 }
64
65 return map;
66 }
67
68 @Override
69 public ParcelableMap[] newArray(int size) {
70 return new ParcelableMap[size];
71 }
72 };
73}