1 /** 2 * Copyright (C) 2015 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.launcher3.util; 17 18 import android.os.Parcel; 19 import android.os.Parcelable; 20 import android.util.SparseArray; 21 22 public class ParcelableSparseArray extends SparseArray<Parcelable> implements Parcelable { describeContents()23 public int describeContents() { 24 return 0; 25 } 26 writeToParcel(Parcel dest, int flags)27 public void writeToParcel(Parcel dest, int flags) { 28 final int count = size(); 29 dest.writeInt(count); 30 for (int i = 0; i < count; i++) { 31 dest.writeInt(keyAt(i)); 32 dest.writeParcelable(valueAt(i), 0); 33 } 34 } 35 36 public static final Parcelable.Creator<ParcelableSparseArray> CREATOR = 37 new Parcelable.Creator<ParcelableSparseArray>() { 38 public ParcelableSparseArray createFromParcel(Parcel source) { 39 final ParcelableSparseArray array = new ParcelableSparseArray(); 40 final ClassLoader loader = array.getClass().getClassLoader(); 41 final int count = source.readInt(); 42 for (int i = 0; i < count; i++) { 43 array.put(source.readInt(), source.readParcelable(loader)); 44 } 45 return array; 46 } 47 48 public ParcelableSparseArray[] newArray(int size) { 49 return new ParcelableSparseArray[size]; 50 } 51 }; 52 } 53