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 KeyPosition Object for use in the Core 21 * ConstraintLayout & MotionLayout system 22 */ 23 public class KeyPosition extends Keys { 24 25 private String mTarget = null; 26 private String mTransitionEasing = null; 27 private int mFrame = 0; 28 private float mPercentWidth = Float.NaN; 29 private float mPercentHeight = Float.NaN; 30 private float mPercentX = Float.NaN; 31 private float mPercentY = Float.NaN; 32 private Type mPositionType = Type.CARTESIAN; 33 34 public enum Type { 35 CARTESIAN, 36 SCREEN, 37 PATH 38 } 39 KeyPosition(String firstTarget, int frame)40 public KeyPosition(String firstTarget, int frame) { 41 42 mTarget = firstTarget; 43 mFrame = frame; 44 } 45 getTransitionEasing()46 public String getTransitionEasing() { 47 return mTransitionEasing; 48 } 49 setTransitionEasing(String transitionEasing)50 public void setTransitionEasing(String transitionEasing) { 51 mTransitionEasing = transitionEasing; 52 } 53 getFrames()54 public int getFrames() { 55 return mFrame; 56 } 57 setFrames(int frames)58 public void setFrames(int frames) { 59 mFrame = frames; 60 } 61 getPercentWidth()62 public float getPercentWidth() { 63 return mPercentWidth; 64 } 65 setPercentWidth(float percentWidth)66 public void setPercentWidth(float percentWidth) { 67 mPercentWidth = percentWidth; 68 } 69 getPercentHeight()70 public float getPercentHeight() { 71 return mPercentHeight; 72 } 73 setPercentHeight(float percentHeight)74 public void setPercentHeight(float percentHeight) { 75 mPercentHeight = percentHeight; 76 } 77 getPercentX()78 public float getPercentX() { 79 return mPercentX; 80 } 81 setPercentX(float percentX)82 public void setPercentX(float percentX) { 83 mPercentX = percentX; 84 } 85 getPercentY()86 public float getPercentY() { 87 return mPercentY; 88 } 89 setPercentY(float percentY)90 public void setPercentY(float percentY) { 91 mPercentY = percentY; 92 } 93 getPositionType()94 public Type getPositionType() { 95 return mPositionType; 96 } 97 setPositionType(Type positionType)98 public void setPositionType(Type positionType) { 99 mPositionType = positionType; 100 } 101 getTarget()102 public String getTarget() { 103 return mTarget; 104 } 105 setTarget(String target)106 public void setTarget(String target) { 107 mTarget = target; 108 } 109 110 @Override toString()111 public String toString() { 112 StringBuilder ret = new StringBuilder(); 113 ret.append("KeyPositions:{\n"); 114 115 append(ret, "target", mTarget); 116 ret.append("frame:").append(mFrame).append(",\n"); 117 118 if (mPositionType != null) { 119 ret.append("type:'").append(mPositionType).append("',\n"); 120 } 121 122 append(ret, "easing", mTransitionEasing); 123 append(ret, "percentX", mPercentX); 124 append(ret, "percentY", mPercentY); 125 append(ret, "percentWidth", mPercentWidth); 126 append(ret, "percentHeight", mPercentHeight); 127 128 ret.append("},\n"); 129 return ret.toString(); 130 } 131 } 132