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 KeyCycle Object for use in the Core
21  * ConstraintLayout & MotionLayout system
22  * This allows multiple KeyCycle positions to defined in one object.
23  */
24 public class KeyCycles extends KeyAttributes {
25 
26 
27     public enum Wave {
28         SIN,
29         SQUARE,
30         TRIANGLE,
31         SAW,
32         REVERSE_SAW,
33         COS
34     }
35 
36     private KeyCycles.Wave mWaveShape = null;
37     private float[] mWavePeriod = null;
38     private float[] mWaveOffset = null;
39     private float[] mWavePhase = null;
40 
KeyCycles(int numOfFrames, String... targets)41     KeyCycles(int numOfFrames, String... targets) {
42         super(numOfFrames, targets);
43         TYPE = "KeyCycle";
44     }
45 
getWaveShape()46     public KeyCycles.Wave getWaveShape() {
47         return mWaveShape;
48     }
49 
setWaveShape(KeyCycles.Wave waveShape)50     public void setWaveShape(KeyCycles.Wave waveShape) {
51         mWaveShape = waveShape;
52     }
53 
getWavePeriod()54     public float[] getWavePeriod() {
55         return mWavePeriod;
56     }
57 
setWavePeriod(float... wavePeriod)58     public void setWavePeriod(float... wavePeriod) {
59         mWavePeriod = wavePeriod;
60     }
61 
getWaveOffset()62     public float[] getWaveOffset() {
63         return mWaveOffset;
64     }
65 
setWaveOffset(float... waveOffset)66     public void setWaveOffset(float... waveOffset) {
67         mWaveOffset = waveOffset;
68     }
69 
getWavePhase()70     public float[] getWavePhase() {
71         return mWavePhase;
72     }
73 
setWavePhase(float... wavePhase)74     public void setWavePhase(float... wavePhase) {
75         mWavePhase = wavePhase;
76     }
77 
78     @Override
attributesToString(StringBuilder builder)79     protected void attributesToString(StringBuilder builder) {
80         super.attributesToString(builder);
81 
82         if (mWaveShape != null) {
83             builder.append("shape:'").append(mWaveShape).append("',\n");
84         }
85         append(builder, "period", mWavePeriod);
86         append(builder, "offset", mWaveOffset);
87         append(builder, "phase", mWavePhase);
88 
89     }
90 
91 
92 }
93