From 42dcec1fde293a9b805f0b5f673bc4cd85a29dc1 Mon Sep 17 00:00:00 2001 From: jafu888 Date: Wed, 15 Jun 2022 22:14:28 -0700 Subject: [PATCH 1/5] fix relative motion support --- .../constraintlayout/core/motion/Motion.java | 36 ++++++++++++---- .../core/motion/MotionPaths.java | 18 ++++++-- .../core/motion/MotionWidget.java | 9 ++-- .../core/state/Transition.java | 41 ++++++++++++++++++- .../constraintlayout/ConstraintMotionProps.kt | 5 +-- .../example/constraintlayout/MainActivity.kt | 3 +- 6 files changed, 91 insertions(+), 21 deletions(-) diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java index 43e6056f7..6e6db2f80 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java @@ -31,6 +31,8 @@ import androidx.constraintlayout.core.motion.utils.KeyCache; import androidx.constraintlayout.core.motion.utils.KeyCycleOscillator; import androidx.constraintlayout.core.motion.utils.KeyFrameArray; +import androidx.constraintlayout.core.motion.utils.NonNull; +import androidx.constraintlayout.core.motion.utils.Nullable; import androidx.constraintlayout.core.motion.utils.Rect; import androidx.constraintlayout.core.motion.utils.SplineSet; import androidx.constraintlayout.core.motion.utils.TimeCycleSplineSet; @@ -78,7 +80,7 @@ public class Motion implements TypedValues { private static final boolean DEBUG = false; private static final boolean FAVOR_FIXED_SIZE_VIEWS = false; MotionWidget mView; - int mId; + public String mId; String mConstraintTag; private int mCurveFitType = UNSET; private MotionPaths mStartMotionPath = new MotionPaths(); @@ -125,7 +127,7 @@ public class Motion implements TypedValues { private float mQuantizeMotionPhase = Float.NaN; private DifferentialInterpolator mQuantizeMotionInterpolator = null; private boolean mNoMovement = false; - + Motion mRelativeMotion; /** * Get the view to pivot around * @@ -237,16 +239,25 @@ public float getFinalHeight() { * * @return the view id of the view this is in polar mode to or -1 if not in polar */ - public int getAnimateRelativeTo() { + @Nullable + public String getAnimateRelativeTo() { return mStartMotionPath.mAnimateRelativeTo; } /** - * @TODO: add description + * set up the motion to be relative to this other motionController */ public void setupRelative(Motion motionController) { - mStartMotionPath.setupRelative(motionController, motionController.mStartMotionPath); - mEndMotionPath.setupRelative(motionController, motionController.mEndMotionPath); + mRelativeMotion = motionController; + } + private void setupRelative() { + if (mRelativeMotion == null) { + return; + } + Utils.log("start "); + mStartMotionPath.setupRelative(mRelativeMotion, mRelativeMotion.mStartMotionPath); + Utils.log("end"); + mEndMotionPath.setupRelative(mRelativeMotion, mRelativeMotion.mEndMotionPath); } public float getCenterX() { @@ -673,6 +684,8 @@ public void setup(int parentWidth, HashSet cycleAttributes = new HashSet<>(); // attributes we need to oscillate HashMap interpolation = new HashMap<>(); ArrayList triggerList = null; + + setupRelative(); if (DEBUG) { if (mKeyList == null) { Utils.log(TAG, ">>>>>>>>>>>>>>> mKeyList==null"); @@ -1722,7 +1735,11 @@ public boolean setValue(int id, String value) { mQuantizeMotionInterpolator = getInterpolator(SPLINE_STRING, value, 0); return true; } - + if ( MotionType.TYPE_ANIMATE_RELATIVE_TO == id) { + mStartMotionPath.mAnimateRelativeTo = value; + Utils.logStack("mAnimateRelativeTo= "+value,6); + return true; + } return false; } @@ -1763,4 +1780,9 @@ public void setStaggerOffset(float staggerOffset) { public float getMotionStagger() { return mMotionStagger; } + + public void setIdString(String stringId) { + mId = stringId; + mStartMotionPath.mId = mId; + } } diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java index c4b370539..3343c3b2b 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java @@ -47,6 +47,7 @@ public class MotionPaths implements Comparable { public static final int CARTESIAN = MotionKeyPosition.TYPE_CARTESIAN; public static final int SCREEN = MotionKeyPosition.TYPE_SCREEN; static String[] sNames = {"position", "x", "y", "width", "height", "pathRotate"}; + public String mId; Easing mKeyFrameEasing; int mDrawPath = 0; float mTime; @@ -58,7 +59,7 @@ public class MotionPaths implements Comparable { float mPathRotate = Float.NaN; float mProgress = Float.NaN; int mPathMotionArc = UNSET; - int mAnimateRelativeTo = UNSET; + String mAnimateRelativeTo = null; float mRelativeAngle = Float.NaN; Motion mRelativeToController = null; @@ -121,7 +122,8 @@ public MotionPaths(int parentWidth, MotionKeyPosition c, MotionPaths startTimePoint, MotionPaths endTimePoint) { - if (startTimePoint.mAnimateRelativeTo != UNSET) { + Utils.log(" ===================== setup start "+startTimePoint.mId+" : "+ startTimePoint.mAnimateRelativeTo ); + if (startTimePoint.mAnimateRelativeTo != null) { initPolar(parentWidth, parentHeight, c, startTimePoint, endTimePoint); return; } @@ -157,6 +159,9 @@ void initPolar(int parentWidth, mHeight = (int) (s.mHeight + scaleY * scaleHeight); float startfactor = 1 - position; float endfactor = position; + Utils.log(mId+": start "+s.mX+","+s.mY); + Utils.log(mId+": end "+e.mX+","+e.mY); + Utils.log(mId+": mAnimateRelativeTo "+e.mAnimateRelativeTo); switch (c.mPositionType) { case MotionKeyPosition.TYPE_SCREEN: this.mX = Float.isNaN(c.mPercentX) ? (position * (e.mX - s.mX) + s.mX) @@ -192,12 +197,17 @@ public void setupRelative(Motion mc, MotionPaths relative) { double dx = mX + mWidth / 2 - relative.mX - relative.mWidth / 2; double dy = mY + mHeight / 2 - relative.mY - relative.mHeight / 2; mRelativeToController = mc; - + Utils.log(mId+": my === "+mX+" , "+mY); + Utils.log(mId+": relative === "+relative.mX+" , "+relative.mY); + Utils.log(mId+": delta === "+dx+" , "+dy); mX = (float) Math.hypot(dy, dx); if (Float.isNaN(mRelativeAngle)) { + mY = (float) (Math.atan2(dy, dx) + Math.PI / 2); + Utils.log(mId+": compute === "+Math.toDegrees(mY)); } else { mY = (float) Math.toRadians(mRelativeAngle); + Utils.log(mId+": defined === "+Math.toDegrees(mY)); } } @@ -926,7 +936,7 @@ public void applyParameters(MotionWidget c) { point.mDrawPath = c.mMotion.mDrawPath; point.mAnimateCircleAngleTo = c.mMotion.mAnimateCircleAngleTo; point.mProgress = c.mPropertySet.mProgress; - point.mRelativeAngle = 0; // c.layout.circleAngle; + // point.mRelativeAngle = 0; // c.layout.circleAngle; Set at = c.getCustomAttributeNames(); for (String s : at) { CustomVariable attr = c.getCustomAttribute(s); diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionWidget.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionWidget.java index a09ff4180..269a85331 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionWidget.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionWidget.java @@ -57,7 +57,7 @@ public class MotionWidget implements TypedValues { * @DoNotShow */ public static class Motion { - public int mAnimateRelativeTo = UNSET; + public String mAnimateRelativeTo = null; public int mAnimateCircleAngleTo = 0; public String mTransitionEasing = null; public int mPathMotionArc = UNSET; @@ -166,6 +166,10 @@ public boolean setValue(int id, float value) { @Override public boolean setValue(int id, String value) { + if (id == MotionType.TYPE_ANIMATE_RELATIVE_TO) { + mMotion.mAnimateRelativeTo = value; + return true; + } return setValueMotion(id, value); } @@ -179,9 +183,6 @@ public boolean setValue(int id, boolean value) { */ public boolean setValueMotion(int id, int value) { switch (id) { - case MotionType.TYPE_ANIMATE_RELATIVE_TO: - mMotion.mAnimateRelativeTo = value; - break; case MotionType.TYPE_ANIMATE_CIRCLEANGLE_TO: mMotion.mAnimateCircleAngleTo = value; break; diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/Transition.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/Transition.java index c66bc1f3c..437d36b53 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/Transition.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/Transition.java @@ -710,11 +710,31 @@ public void addCustomColor(int state, String widgetId, String property, int colo public void updateFrom(ConstraintWidgetContainer container, int state) { final ArrayList children = container.getChildren(); final int count = children.size(); + WidgetState [] states = new WidgetState[count]; + boolean relative = false; for (int i = 0; i < count; i++) { ConstraintWidget child = children.get(i); WidgetState widgetState = getWidgetState(child.stringId, null, state); + states[i] = widgetState; widgetState.update(child, state); + String id = widgetState.getPathRelativeId(); + if (id != null) { + relative = true; + } } + if (relative) { + for (int i = 0; i < count; i++) { + ConstraintWidget child = children.get(i); + WidgetState widgetState = getWidgetState(child.stringId, null, state); + states[i] = widgetState; + String id = widgetState.getPathRelativeId(); + if (id != null) { + widgetState.setPathRelative(getWidgetState(id, null, state)); + + } + } + } + calcStagger(); } @@ -844,6 +864,7 @@ static class WidgetState { WidgetFrame mEnd; WidgetFrame mInterpolated; Motion mMotionControl; + boolean mNeedSetup = true; MotionWidget mMotionWidgetStart; MotionWidget mMotionWidgetEnd; MotionWidget mMotionWidgetInterpolated; @@ -886,13 +907,23 @@ public void update(ConstraintWidget child, int state) { mStart.update(child); mMotionWidgetStart.updateMotion(mMotionWidgetStart); mMotionControl.setStart(mMotionWidgetStart); + mNeedSetup = true; } else if (state == END) { mEnd.update(child); mMotionControl.setEnd(mMotionWidgetEnd); + mNeedSetup = true; } mParentWidth = -1; } + /** + * Return the id of the widget to animate relative to + * @return id of widget or null + */ + String getPathRelativeId() { + return mMotionControl.getAnimateRelativeTo(); + } + public WidgetFrame getFrame(int type) { if (type == START) { return mStart; @@ -909,14 +940,20 @@ public void interpolate(int parentWidth, // TODO only update if parentHeight != mParentHeight || parentWidth != mParentWidth) { mParentHeight = parentHeight; mParentWidth = parentWidth; - mMotionControl.setup(parentWidth, parentHeight, 1, System.nanoTime()); - + if (mNeedSetup) { + mMotionControl.setup(parentWidth, parentHeight, 1, System.nanoTime()); + mNeedSetup = false; + } WidgetFrame.interpolate(parentWidth, parentHeight, mInterpolated, mStart, mEnd, transition, progress); mInterpolated.interpolatedPos = progress; mMotionControl.interpolate(mMotionWidgetInterpolated, progress, System.nanoTime(), mKeyCache); } + + public void setPathRelative(WidgetState widgetState) { + mMotionControl.setupRelative( widgetState.mMotionControl); + } } static class KeyPosition { diff --git a/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/ConstraintMotionProps.kt b/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/ConstraintMotionProps.kt index 8e0dc2ed4..645873d88 100644 --- a/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/ConstraintMotionProps.kt +++ b/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/ConstraintMotionProps.kt @@ -742,7 +742,7 @@ fun MotionOrbit1() { box1: { width: 50, height: 50, bottom: ['parent', 'bottom', 10], - start: ['parent', 'start', 10], + start: ['parent', 'start', 80], }, title: { top: ['parent', 'top', 10], @@ -754,7 +754,6 @@ fun MotionOrbit1() { bottom: ['parent', 'bottom', 10], start: ['parent', 'start', 10], motion: { - pathArc : 'startHorizontal', relativeTo: 'box1' } } @@ -763,7 +762,7 @@ fun MotionOrbit1() { box1: { width: 50, height: 50, top: ['parent', 'top', 60], - end: ['parent', 'end', 60], + end: ['parent', 'end', 80], }, title: { top: ['parent', 'top', 10], diff --git a/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/MainActivity.kt b/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/MainActivity.kt index 19cc73697..d5942ee31 100644 --- a/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/MainActivity.kt +++ b/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/MainActivity.kt @@ -37,7 +37,7 @@ import com.google.accompanist.coil.rememberCoilPainter class MainActivity : AppCompatActivity() { private var mFrameLayout: FrameLayout? = null private var composeNum = 0 - private val START_NUMBER = 48 + private val START_NUMBER = 58 private var demos:ArrayList = ArrayList() var map = HashMap(); val linkServer = LinkServer() @@ -162,6 +162,7 @@ class MainActivity : AppCompatActivity() { demos.add(object : CompFunc { @Composable override fun Run() { MotionQuantize2() } }) demos.add(object : CompFunc { @Composable override fun Run() { MotionStagger1() } }) demos.add(object : CompFunc { @Composable override fun Run() { MotionStagger2() } }) + demos.add(object : CompFunc { @Composable override fun Run() { MotionOrbit1() } }) demos.add(object : CompFunc { @Composable override fun Run() { Example () } }) demos.add(object : CompFunc { @Composable override fun Run() { RowColExample () } }) From c3d1fea4a5367680beb4cfd96913abd3bb31e5bb Mon Sep 17 00:00:00 2001 From: jafu888 Date: Thu, 16 Jun 2022 08:55:15 -0700 Subject: [PATCH 2/5] support rotations angle --- .../constraintlayout/core/motion/Motion.java | 3 - .../core/motion/MotionPaths.java | 14 ++- .../core/widgets/ConstraintWidget.java | 9 +- .../constraintlayout/ConstraintMotionProps.kt | 90 +++++++++++++++++++ .../example/constraintlayout/MainActivity.kt | 1 + 5 files changed, 102 insertions(+), 15 deletions(-) diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java index 6e6db2f80..56e883bd9 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java @@ -254,9 +254,7 @@ private void setupRelative() { if (mRelativeMotion == null) { return; } - Utils.log("start "); mStartMotionPath.setupRelative(mRelativeMotion, mRelativeMotion.mStartMotionPath); - Utils.log("end"); mEndMotionPath.setupRelative(mRelativeMotion, mRelativeMotion.mEndMotionPath); } @@ -1737,7 +1735,6 @@ public boolean setValue(int id, String value) { } if ( MotionType.TYPE_ANIMATE_RELATIVE_TO == id) { mStartMotionPath.mAnimateRelativeTo = value; - Utils.logStack("mAnimateRelativeTo= "+value,6); return true; } return false; diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java index 3343c3b2b..b095cedc5 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java @@ -122,7 +122,6 @@ public MotionPaths(int parentWidth, MotionKeyPosition c, MotionPaths startTimePoint, MotionPaths endTimePoint) { - Utils.log(" ===================== setup start "+startTimePoint.mId+" : "+ startTimePoint.mAnimateRelativeTo ); if (startTimePoint.mAnimateRelativeTo != null) { initPolar(parentWidth, parentHeight, c, startTimePoint, endTimePoint); return; @@ -197,18 +196,12 @@ public void setupRelative(Motion mc, MotionPaths relative) { double dx = mX + mWidth / 2 - relative.mX - relative.mWidth / 2; double dy = mY + mHeight / 2 - relative.mY - relative.mHeight / 2; mRelativeToController = mc; - Utils.log(mId+": my === "+mX+" , "+mY); - Utils.log(mId+": relative === "+relative.mX+" , "+relative.mY); - Utils.log(mId+": delta === "+dx+" , "+dy); + mX = (float) Math.hypot(dy, dx); if (Float.isNaN(mRelativeAngle)) { - mY = (float) (Math.atan2(dy, dx) + Math.PI / 2); - Utils.log(mId+": compute === "+Math.toDegrees(mY)); } else { mY = (float) Math.toRadians(mRelativeAngle); - Utils.log(mId+": defined === "+Math.toDegrees(mY)); - } } @@ -936,7 +929,10 @@ public void applyParameters(MotionWidget c) { point.mDrawPath = c.mMotion.mDrawPath; point.mAnimateCircleAngleTo = c.mMotion.mAnimateCircleAngleTo; point.mProgress = c.mPropertySet.mProgress; - // point.mRelativeAngle = 0; // c.layout.circleAngle; + if (c.mWidgetFrame != null && c.mWidgetFrame.widget != null) { + point.mRelativeAngle = c.mWidgetFrame.widget.mCircleConstraintAngle; + } + Set at = c.getCustomAttributeNames(); for (String s : at) { CustomVariable attr = c.getCustomAttribute(s); diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/widgets/ConstraintWidget.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/widgets/ConstraintWidget.java index 52fb00484..a74ac0122 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/widgets/ConstraintWidget.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/widgets/ConstraintWidget.java @@ -23,6 +23,7 @@ import androidx.constraintlayout.core.Cache; import androidx.constraintlayout.core.LinearSystem; import androidx.constraintlayout.core.SolverVariable; +import androidx.constraintlayout.core.motion.utils.Utils; import androidx.constraintlayout.core.state.WidgetFrame; import androidx.constraintlayout.core.widgets.analyzer.ChainRun; import androidx.constraintlayout.core.widgets.analyzer.HorizontalWidgetRun; @@ -361,7 +362,7 @@ public boolean hasResolvedTargets(int orientation, int size) { float mResolvedDimensionRatio = 1.0f; private int[] mMaxDimension = {Integer.MAX_VALUE, Integer.MAX_VALUE}; - private float mCircleConstraintAngle = 0; + public float mCircleConstraintAngle = Float.NaN; private boolean mHasBaseline = false; private boolean mInPlaceholder; @@ -602,7 +603,7 @@ public void reset() { mCenterY.reset(); mCenter.reset(); mParent = null; - mCircleConstraintAngle = 0; + mCircleConstraintAngle = Float.NaN; mWidth = 0; mHeight = 0; mDimensionRatio = 0; @@ -676,7 +677,7 @@ private void serializeAnchor(StringBuilder ret, String side, ConstraintAnchor a) } private void serializeCircle(StringBuilder ret, ConstraintAnchor a, float angle) { - if (a.mTarget == null) { + if (a.mTarget == null || Float.isNaN(angle)) { return; } @@ -3583,6 +3584,8 @@ public void copy(ConstraintWidget src, HashMap Date: Thu, 16 Jun 2022 13:30:18 -0700 Subject: [PATCH 3/5] clean up spline --- .../constraintlayout/core/motion/Motion.java | 3 ++- .../core/state/TransitionParser.java | 3 ++- .../constraintlayout/ConstraintMotionProps.kt | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java index 56e883bd9..2041fc95a 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java @@ -82,7 +82,7 @@ public class Motion implements TypedValues { MotionWidget mView; public String mId; String mConstraintTag; - private int mCurveFitType = UNSET; + private int mCurveFitType = CurveFit.SPLINE; private MotionPaths mStartMotionPath = new MotionPaths(); private MotionPaths mEndMotionPath = new MotionPaths(); @@ -945,6 +945,7 @@ public void setup(int parentWidth, mSpline[i + 1] = CurveFit.get(mCurveFitType, timePoints, splinePoints); } + // Spline for positions mSpline[0] = CurveFit.get(mCurveFitType, timePoint, splineData); // --------------------------- SUPPORT ARC MODE -------------- if (points[0].mPathMotionArc != UNSET) { diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/TransitionParser.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/TransitionParser.java index 6fc562c97..6c960889c 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/TransitionParser.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/TransitionParser.java @@ -18,6 +18,7 @@ import androidx.constraintlayout.core.motion.utils.TypedBundle; import androidx.constraintlayout.core.motion.utils.TypedValues; +import androidx.constraintlayout.core.motion.utils.Utils; import androidx.constraintlayout.core.parser.CLArray; import androidx.constraintlayout.core.parser.CLContainer; import androidx.constraintlayout.core.parser.CLElement; @@ -133,7 +134,7 @@ private static int map(String val, String... types) { private static void map(TypedBundle bundle, int type, String val, String... types) { for (int i = 0; i < types.length; i++) { if (types[i].equals(val)) { - bundle.add(TypedValues.PositionType.TYPE_PATH_MOTION_ARC, i); + bundle.add(type, i); } } } diff --git a/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/ConstraintMotionProps.kt b/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/ConstraintMotionProps.kt index 442d42a81..fa3ce75cf 100644 --- a/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/ConstraintMotionProps.kt +++ b/projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/ConstraintMotionProps.kt @@ -861,7 +861,7 @@ fun MotionOrbit2() { }, box2: { width: 50, height: 50, - circular: ['box1', 900, 70], + circular: ['box1', 1800, 70], } } }, @@ -869,7 +869,17 @@ fun MotionOrbit2() { default: { from: 'start', to: 'end', - pathMotionArc : 'none', + KeyFrames: { + KeyPositions: [ + { + target: ['box1'], + type: 'deltaRelative', + frames: [50], + percentX: [ 0.7], + percentY: [ 0.5] + } + ] + }, onSwipe: { anchor: 'box1', maxVelocity: 4.2, From 6621f563e0c755d67d9ff7a4204b9f739f5b3a5f Mon Sep 17 00:00:00 2001 From: jafu888 Date: Fri, 17 Jun 2022 11:31:58 -0700 Subject: [PATCH 4/5] resolve comments --- .../constraintlayout/core/motion/Motion.java | 8 +++---- .../core/motion/MotionPaths.java | 4 +--- .../core/state/Transition.java | 24 ++++++------------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java index 2041fc95a..2ec8df609 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java @@ -31,7 +31,6 @@ import androidx.constraintlayout.core.motion.utils.KeyCache; import androidx.constraintlayout.core.motion.utils.KeyCycleOscillator; import androidx.constraintlayout.core.motion.utils.KeyFrameArray; -import androidx.constraintlayout.core.motion.utils.NonNull; import androidx.constraintlayout.core.motion.utils.Nullable; import androidx.constraintlayout.core.motion.utils.Rect; import androidx.constraintlayout.core.motion.utils.SplineSet; @@ -250,6 +249,7 @@ public String getAnimateRelativeTo() { public void setupRelative(Motion motionController) { mRelativeMotion = motionController; } + private void setupRelative() { if (mRelativeMotion == null) { return; @@ -1734,9 +1734,9 @@ public boolean setValue(int id, String value) { mQuantizeMotionInterpolator = getInterpolator(SPLINE_STRING, value, 0); return true; } - if ( MotionType.TYPE_ANIMATE_RELATIVE_TO == id) { - mStartMotionPath.mAnimateRelativeTo = value; - return true; + if (MotionType.TYPE_ANIMATE_RELATIVE_TO == id) { + mStartMotionPath.mAnimateRelativeTo = value; + return true; } return false; } diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java index b095cedc5..beade20ac 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java @@ -158,9 +158,7 @@ void initPolar(int parentWidth, mHeight = (int) (s.mHeight + scaleY * scaleHeight); float startfactor = 1 - position; float endfactor = position; - Utils.log(mId+": start "+s.mX+","+s.mY); - Utils.log(mId+": end "+e.mX+","+e.mY); - Utils.log(mId+": mAnimateRelativeTo "+e.mAnimateRelativeTo); + switch (c.mPositionType) { case MotionKeyPosition.TYPE_SCREEN: this.mX = Float.isNaN(c.mPercentX) ? (position * (e.mX - s.mX) + s.mX) diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/Transition.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/Transition.java index 437d36b53..42abed015 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/Transition.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/state/Transition.java @@ -705,33 +705,23 @@ public void addCustomColor(int state, String widgetId, String property, int colo } /** - * @TODO: add description + * Update container of parameters for the state + * @param container contains all the widget parameters + * @param state starting or ending */ public void updateFrom(ConstraintWidgetContainer container, int state) { final ArrayList children = container.getChildren(); final int count = children.size(); - WidgetState [] states = new WidgetState[count]; - boolean relative = false; + WidgetState[] states = new WidgetState[count]; + for (int i = 0; i < count; i++) { ConstraintWidget child = children.get(i); WidgetState widgetState = getWidgetState(child.stringId, null, state); states[i] = widgetState; widgetState.update(child, state); - String id = widgetState.getPathRelativeId(); + String id = widgetState.getPathRelativeId(); if (id != null) { - relative = true; - } - } - if (relative) { - for (int i = 0; i < count; i++) { - ConstraintWidget child = children.get(i); - WidgetState widgetState = getWidgetState(child.stringId, null, state); - states[i] = widgetState; - String id = widgetState.getPathRelativeId(); - if (id != null) { - widgetState.setPathRelative(getWidgetState(id, null, state)); - - } + widgetState.setPathRelative(getWidgetState(id, null, state)); } } From 342b14eec9cdcb41f506bf665872d2a0bc9e3f92 Mon Sep 17 00:00:00 2001 From: jafu888 Date: Fri, 17 Jun 2022 13:34:47 -0700 Subject: [PATCH 5/5] remove Nullable --- .../main/java/androidx/constraintlayout/core/motion/Motion.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java index 2ec8df609..0d5780ace 100644 --- a/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java +++ b/constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java @@ -31,7 +31,6 @@ import androidx.constraintlayout.core.motion.utils.KeyCache; import androidx.constraintlayout.core.motion.utils.KeyCycleOscillator; import androidx.constraintlayout.core.motion.utils.KeyFrameArray; -import androidx.constraintlayout.core.motion.utils.Nullable; import androidx.constraintlayout.core.motion.utils.Rect; import androidx.constraintlayout.core.motion.utils.SplineSet; import androidx.constraintlayout.core.motion.utils.TimeCycleSplineSet; @@ -238,7 +237,6 @@ public float getFinalHeight() { * * @return the view id of the view this is in polar mode to or -1 if not in polar */ - @Nullable public String getAnimateRelativeTo() { return mStartMotionPath.mAnimateRelativeTo; }