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