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