1 /* 2 * Copyright (C) 2016 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.support.v4.app; 18 19 import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP; 20 21 import android.app.Activity; 22 import android.support.annotation.RestrictTo; 23 import android.support.v4.util.SimpleArrayMap; 24 25 /** 26 * Base class for composing together compatibility functionality 27 * 28 * @hide 29 */ 30 @RestrictTo(LIBRARY_GROUP) 31 public class SupportActivity extends Activity { 32 /** 33 * Storage for {@link ExtraData} instances. 34 * 35 * <p>Note that these objects are not retained across configuration changes</p> 36 */ 37 private SimpleArrayMap<Class<? extends ExtraData>, ExtraData> mExtraDataMap = 38 new SimpleArrayMap<>(); 39 40 /** 41 * Store an instance of {@link ExtraData} for later retrieval by class name 42 * via {@link #getExtraData}. 43 * 44 * <p>Note that these objects are not retained across configuration changes</p> 45 * 46 * @see #getExtraData 47 * @hide 48 */ 49 @RestrictTo(LIBRARY_GROUP) putExtraData(ExtraData extraData)50 public void putExtraData(ExtraData extraData) { 51 mExtraDataMap.put(extraData.getClass(), extraData); 52 } 53 54 /** 55 * Retrieves a previously set {@link ExtraData} by class name. 56 * 57 * @see #putExtraData 58 * @hide 59 */ 60 @RestrictTo(LIBRARY_GROUP) getExtraData(Class<T> extraDataClass)61 public <T extends ExtraData> T getExtraData(Class<T> extraDataClass) { 62 return (T) mExtraDataMap.get(extraDataClass); 63 } 64 65 /** 66 * @hide 67 */ 68 @RestrictTo(LIBRARY_GROUP) 69 public static class ExtraData { 70 } 71 } 72