1d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar/* 2e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * Copyright (C) 2014 The Android Open Source Project 3e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * 4e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * Licensed under the Apache License, Version 2.0 (the "License"); 5e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * you may not use this file except in compliance with the License. 6e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * You may obtain a copy of the License at 7e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * 8e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * http://www.apache.org/licenses/LICENSE-2.0 9e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * 10e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * Unless required by applicable law or agreed to in writing, software 11e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * distributed under the License is distributed on an "AS IS" BASIS, 12e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * See the License for the specific language governing permissions and 14e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * limitations under the License. 15e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette */ 16d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 17e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverettepackage android.content.res; 18d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 19ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viveretteimport android.content.pm.ActivityInfo.Config; 20ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viverette 21d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar/** 22d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * A Cache class which can be used to cache resource objects that are easy to clone but more 23d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * expensive to inflate. 24e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * 25e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * @hide For internal use only. 26d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 27e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverettepublic class ConfigurationBoundResourceCache<T> extends ThemedResourceCache<ConstantState<T>> { 28d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 29e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * If the resource is cached, creates and returns a new instance of it. 30d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * 31e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * @param key a key that uniquely identifies the drawable resource 32fb302ccd8e0610a09691ea5503ff8111dc7a2e41Adam Lesinski * @param resources a Resources object from which to create new instances. 33e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * @param theme the theme where the resource will be used 34e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * @return a new instance of the resource, or {@code null} if not in 35e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette * the cache 36d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 37fb302ccd8e0610a09691ea5503ff8111dc7a2e41Adam Lesinski public T getInstance(long key, Resources resources, Resources.Theme theme) { 38e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette final ConstantState<T> entry = get(key, theme); 39d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar if (entry != null) { 40fb302ccd8e0610a09691ea5503ff8111dc7a2e41Adam Lesinski return entry.newInstance(resources, theme); 41d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 42d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 43e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette return null; 44d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 45d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 46e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette @Override 47ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viverette public boolean shouldInvalidateEntry(ConstantState<T> entry, @Config int configChanges) { 48e54d245b993e1347cb32c23a6bdc907a45fab324Alan Viverette return Configuration.needNewResources(configChanges, entry.getChangingConfigurations()); 49d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 50d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar} 51