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  * Provides the API for creating a KeyAttribute Object for use in the Core
21  * ConstraintLayout & MotionLayout system
22  */
23 public class KeyAttribute extends Keys {
24     protected String TYPE = "KeyAttributes";
25     private String mTarget = null;
26     private int mFrame = 0;
27     private String mTransitionEasing;
28     private Fit mCurveFit = null;
29     private Visibility mVisibility = null;
30     private float mAlpha = Float.NaN;
31     private float mRotation = Float.NaN;
32     private float mRotationX = Float.NaN;
33     private float mRotationY = Float.NaN;
34     private float mPivotX = Float.NaN;
35     private float mPivotY = Float.NaN;
36     private float mTransitionPathRotate = Float.NaN;
37     private float mScaleX = Float.NaN;
38     private float mScaleY = Float.NaN;
39     private float mTranslationX = Float.NaN;
40     private float mTranslationY = Float.NaN;
41     private float mTranslationZ = Float.NaN;
42 
KeyAttribute(int frame, String target)43     public KeyAttribute(int frame, String target) {
44         mTarget = target;
45         mFrame = frame;
46     }
47 
48     public enum Fit {
49         SPLINE,
50         LINEAR,
51     }
52 
53     public enum Visibility {
54         VISIBLE,
55         INVISIBLE,
56         GONE
57     }
58 
getTarget()59     public String getTarget() {
60         return mTarget;
61     }
62 
setTarget(String target)63     public void setTarget(String target) {
64         mTarget = target;
65     }
66 
getTransitionEasing()67     public String getTransitionEasing() {
68         return mTransitionEasing;
69     }
70 
setTransitionEasing(String transitionEasing)71     public void setTransitionEasing(String transitionEasing) {
72         mTransitionEasing = transitionEasing;
73     }
74 
getCurveFit()75     public Fit getCurveFit() {
76         return mCurveFit;
77     }
78 
setCurveFit(Fit curveFit)79     public void setCurveFit(Fit curveFit) {
80         mCurveFit = curveFit;
81     }
82 
getVisibility()83     public Visibility getVisibility() {
84         return mVisibility;
85     }
86 
setVisibility(Visibility visibility)87     public void setVisibility(Visibility visibility) {
88         mVisibility = visibility;
89     }
90 
getAlpha()91     public float getAlpha() {
92         return mAlpha;
93     }
94 
setAlpha(float alpha)95     public void setAlpha(float alpha) {
96         mAlpha = alpha;
97     }
98 
getRotation()99     public float getRotation() {
100         return mRotation;
101     }
102 
setRotation(float rotation)103     public void setRotation(float rotation) {
104         mRotation = rotation;
105     }
106 
getRotationX()107     public float getRotationX() {
108         return mRotationX;
109     }
110 
setRotationX(float rotationX)111     public void setRotationX(float rotationX) {
112         mRotationX = rotationX;
113     }
114 
getRotationY()115     public float getRotationY() {
116         return mRotationY;
117     }
118 
setRotationY(float rotationY)119     public void setRotationY(float rotationY) {
120         mRotationY = rotationY;
121     }
122 
getPivotX()123     public float getPivotX() {
124         return mPivotX;
125     }
126 
setPivotX(float pivotX)127     public void setPivotX(float pivotX) {
128         mPivotX = pivotX;
129     }
130 
getPivotY()131     public float getPivotY() {
132         return mPivotY;
133     }
134 
setPivotY(float pivotY)135     public void setPivotY(float pivotY) {
136         mPivotY = pivotY;
137     }
138 
getTransitionPathRotate()139     public float getTransitionPathRotate() {
140         return mTransitionPathRotate;
141     }
142 
setTransitionPathRotate(float transitionPathRotate)143     public void setTransitionPathRotate(float transitionPathRotate) {
144         mTransitionPathRotate = transitionPathRotate;
145     }
146 
getScaleX()147     public float getScaleX() {
148         return mScaleX;
149     }
150 
setScaleX(float scaleX)151     public void setScaleX(float scaleX) {
152         mScaleX = scaleX;
153     }
154 
getScaleY()155     public float getScaleY() {
156         return mScaleY;
157     }
158 
setScaleY(float scaleY)159     public void setScaleY(float scaleY) {
160         mScaleY = scaleY;
161     }
162 
getTranslationX()163     public float getTranslationX() {
164         return mTranslationX;
165     }
166 
setTranslationX(float translationX)167     public void setTranslationX(float translationX) {
168         mTranslationX = translationX;
169     }
170 
getTranslationY()171     public float getTranslationY() {
172         return mTranslationY;
173     }
174 
setTranslationY(float translationY)175     public void setTranslationY(float translationY) {
176         mTranslationY = translationY;
177     }
178 
getTranslationZ()179     public float getTranslationZ() {
180         return mTranslationZ;
181     }
182 
setTranslationZ(float translationZ)183     public void setTranslationZ(float translationZ) {
184         mTranslationZ = translationZ;
185     }
186 
187     @Override
toString()188     public String toString() {
189         StringBuilder ret = new StringBuilder();
190         ret.append(TYPE);
191         ret.append(":{\n");
192         attributesToString(ret);
193 
194         ret.append("},\n");
195         return ret.toString();
196     }
197 
attributesToString(StringBuilder builder)198     protected void attributesToString(StringBuilder builder) {
199         append(builder, "target", mTarget);
200         builder.append("frame:").append(mFrame).append(",\n");
201 
202         append(builder, "easing", mTransitionEasing);
203         if (mCurveFit != null) {
204             builder.append("fit:'").append(mCurveFit).append("',\n");
205         }
206         if (mVisibility != null) {
207             builder.append("visibility:'").append(mVisibility).append("',\n");
208         }
209         append(builder, "alpha", mAlpha);
210         append(builder, "rotationX", mRotationX);
211         append(builder, "rotationY", mRotationY);
212         append(builder, "rotationZ", mRotation);
213 
214         append(builder, "pivotX", mPivotX);
215         append(builder, "pivotY", mPivotY);
216         append(builder, "pathRotate", mTransitionPathRotate);
217         append(builder, "scaleX", mScaleX);
218         append(builder, "scaleY", mScaleY);
219         append(builder, "translationX", mTranslationX);
220         append(builder, "translationY", mTranslationY);
221         append(builder, "translationZ", mTranslationZ);
222 
223     }
224 
225 }
226