Home | History | Annotate | Download | only in autofill
      1 /*
      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 
     17 package android.view.autofill;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 
     22 import java.util.HashMap;
     23 import java.util.Map;
     24 
     25 /**
     26  * A parcelable HashMap for {@link AutofillId} and {@link AutofillValue}
     27  *
     28  * {@hide}
     29  */
     30 class 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 
     50     public static final Parcelable.Creator<ParcelableMap> CREATOR =
     51             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 }
     74