• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.content.res;
17 
18 import android.content.pm.ActivityInfo.Config;
19 import android.ravenwood.annotation.RavenwoodKeepWholeClass;
20 
21 /**
22  * A cache class that can provide new instances of a particular resource which may change
23  * depending on the current {@link Resources.Theme} or {@link Configuration}.
24  * <p>
25  * A constant state should be able to return a bitmask of changing configurations, which
26  * identifies the type of configuration changes that may invalidate this resource. These
27  * configuration changes can be obtained from {@link android.util.TypedValue}. Entities such as
28  * {@link android.animation.Animator} also provide a changing configuration method to include
29  * their dependencies (e.g. An AnimatorSet's changing configuration is the union of the
30  * changing configurations of each Animator in the set)
31  * @hide
32  */
33 @RavenwoodKeepWholeClass
34 abstract public class ConstantState<T> {
35 
36     /**
37      * Return a bit mask of configuration changes that will impact
38      * this resource (and thus require completely reloading it).
39      */
getChangingConfigurations()40     abstract public @Config int getChangingConfigurations();
41 
42     /**
43      * Create a new instance without supplying resources the caller
44      * is running in.
45      */
newInstance()46     public abstract T newInstance();
47 
48     /**
49      * Create a new instance from its constant state.  This
50      * must be implemented for resources that change based on the target
51      * density of their caller (that is depending on whether it is
52      * in compatibility mode).
53      */
newInstance(Resources res)54     public T newInstance(Resources res) {
55         return newInstance();
56     }
57 
58     /**
59      * Create a new instance from its constant state.  This must be
60      * implemented for resources that can have a theme applied.
61      */
newInstance(Resources res, Resources.Theme theme)62     public T newInstance(Resources res, Resources.Theme theme) {
63         return newInstance(res);
64     }
65 }
66