1/*
2 * Copyright (C) 2016 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
17package android.support.transition;
18
19import android.view.View;
20
21import java.util.HashMap;
22import java.util.Map;
23
24/**
25 * Data structure which holds cached values for the transition.
26 * The view field is the target which all of the values pertain to.
27 * The values field is a map which holds information for fields
28 * according to names selected by the transitions. These names should
29 * be unique to avoid clobbering values stored by other transitions,
30 * such as the convention project:transition_name:property_name. For
31 * example, the platform might store a property "alpha" in a transition
32 * "Fader" as "android:fader:alpha".
33 *
34 * <p>These values are cached during the
35 * {@link android.support.transition.Transition#captureStartValues(TransitionValues)}
36 * capture} phases of a scene change, once when the start values are captured
37 * and again when the end values are captured. These start/end values are then
38 * passed into the transitions via the
39 * for {@link android.support.transition.Transition#createAnimator(android.view.ViewGroup,
40 * TransitionValues, TransitionValues)} method.</p>
41 */
42public class TransitionValues {
43
44    /**
45     * The set of values tracked by transitions for this scene
46     */
47    public final Map<String, Object> values = new HashMap<>();
48
49    /**
50     * The View with these values
51     */
52    public View view;
53
54    @Override
55    public boolean equals(Object other) {
56        if (other instanceof TransitionValues) {
57            if (view == ((TransitionValues) other).view) {
58                if (values.equals(((TransitionValues) other).values)) {
59                    return true;
60                }
61            }
62        }
63        return false;
64    }
65
66    @Override
67    public int hashCode() {
68        return 31 * view.hashCode() + values.hashCode();
69    }
70
71    @Override
72    public String toString() {
73        String returnValue = "TransitionValues@" + Integer.toHexString(hashCode()) + ":\n";
74        returnValue += "    view = " + view + "\n";
75        returnValue += "    values:";
76        for (String s : values.keySet()) {
77            returnValue += "    " + s + ": " + values.get(s) + "\n";
78        }
79        return returnValue;
80    }
81
82}
83