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