1 /*
2  * Copyright (C) 2022 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 androidx.constraintlayout.core.dsl;
18 
19 /**
20  * Create a Transition Object.
21  * Transition objects reference the start and end Constraints
22  */
23 public class Transition {
24     private OnSwipe mOnSwipe = null;
25     final int UNSET = -1;
26     private final int DEFAULT_DURATION = 400;
27     private final float DEFAULT_STAGGER = 0;
28     private String mId = null;
29     private String mConstraintSetEnd = null;
30     private String mConstraintSetStart = null;
31     @SuppressWarnings("unused") private int mDefaultInterpolator = 0;
32     @SuppressWarnings("unused") private String mDefaultInterpolatorString = null;
33     @SuppressWarnings("unused") private int mDefaultInterpolatorID = -1;
34     private int mDuration = DEFAULT_DURATION;
35     private float mStagger = DEFAULT_STAGGER;
36 
37     private KeyFrames mKeyFrames = new KeyFrames();
38 
setOnSwipe(OnSwipe onSwipe)39     public void setOnSwipe(OnSwipe onSwipe) {
40         mOnSwipe = onSwipe;
41     }
42 
setKeyFrames(@uppressWarnings"HiddenTypeParameter") Keys keyFrames)43     public void setKeyFrames(@SuppressWarnings("HiddenTypeParameter") Keys keyFrames) {
44         mKeyFrames.add(keyFrames);
45     }
46 
Transition(String from, String to)47     public Transition(String from, String to) {
48         mId = "default";
49         mConstraintSetStart = from;
50         mConstraintSetEnd = to;
51     }
52 
Transition(String id, String from, String to)53     public Transition(String id, String from, String to) {
54         mId = id;
55         mConstraintSetStart = from;
56         mConstraintSetEnd = to;
57     }
58 
toJson()59     String toJson() {
60         return toString();
61     }
62 
setId(String id)63     public void setId(String id) {
64         mId = id;
65     }
66 
setTo(String constraintSetEnd)67     public void setTo(String constraintSetEnd) {
68         mConstraintSetEnd = constraintSetEnd;
69     }
70 
setFrom(String constraintSetStart)71     public void setFrom(String constraintSetStart) {
72         mConstraintSetStart = constraintSetStart;
73     }
74 
setDuration(int duration)75     public void setDuration(int duration) {
76         mDuration = duration;
77     }
78 
setStagger(float stagger)79     public void setStagger(float stagger) {
80         mStagger = stagger;
81     }
82 
83     @Override
toString()84     public String toString() {
85         String ret = mId + ":{\n"
86                 + "from:'" + mConstraintSetStart + "',\n"
87                 + "to:'" + mConstraintSetEnd + "',\n";
88         if (mDuration != DEFAULT_DURATION) {
89             ret += "duration:" + mDuration + ",\n";
90         }
91         if (mStagger != DEFAULT_STAGGER) {
92             ret += "stagger:" + mStagger + ",\n";
93         }
94         if (mOnSwipe != null) {
95             ret += mOnSwipe.toString();
96         }
97 
98         ret += mKeyFrames.toString();
99 
100 
101         ret += "},\n";
102 
103         return ret;
104     }
105 
getId()106     public String getId() {
107         return mId;
108     }
109 }
110