1 /* 2 * Copyright (C) 2014 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.content.res; 18 19 import android.annotation.UnsupportedAppUsage; 20 import android.content.pm.ActivityInfo.Config; 21 22 /** 23 * A Cache class which can be used to cache resource objects that are easy to clone but more 24 * expensive to inflate. 25 * 26 * @hide For internal use only. 27 */ 28 public class ConfigurationBoundResourceCache<T> extends ThemedResourceCache<ConstantState<T>> { 29 /** 30 * If the resource is cached, creates and returns a new instance of it. 31 * 32 * @param key a key that uniquely identifies the drawable resource 33 * @param resources a Resources object from which to create new instances. 34 * @param theme the theme where the resource will be used 35 * @return a new instance of the resource, or {@code null} if not in 36 * the cache 37 */ getInstance(long key, Resources resources, Resources.Theme theme)38 public T getInstance(long key, Resources resources, Resources.Theme theme) { 39 final ConstantState<T> entry = get(key, theme); 40 if (entry != null) { 41 return entry.newInstance(resources, theme); 42 } 43 44 return null; 45 } 46 47 @Override shouldInvalidateEntry(ConstantState<T> entry, @Config int configChanges)48 public boolean shouldInvalidateEntry(ConstantState<T> entry, @Config int configChanges) { 49 return Configuration.needNewResources(configChanges, entry.getChangingConfigurations()); 50 } 51 } 52