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