Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 8600767

Browse files
committed
support rotations angle
1 parent a2e88f3 commit 8600767

File tree

5 files changed

+102
-15
lines changed

5 files changed

+102
-15
lines changed

constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/Motion.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,7 @@ private void setupRelative() {
254254
if (mRelativeMotion == null) {
255255
return;
256256
}
257-
Utils.log("start ");
258257
mStartMotionPath.setupRelative(mRelativeMotion, mRelativeMotion.mStartMotionPath);
259-
Utils.log("end");
260258
mEndMotionPath.setupRelative(mRelativeMotion, mRelativeMotion.mEndMotionPath);
261259
}
262260

@@ -1737,7 +1735,6 @@ public boolean setValue(int id, String value) {
17371735
}
17381736
if ( MotionType.TYPE_ANIMATE_RELATIVE_TO == id) {
17391737
mStartMotionPath.mAnimateRelativeTo = value;
1740-
Utils.logStack("mAnimateRelativeTo= "+value,6);
17411738
return true;
17421739
}
17431740
return false;

constraintlayout/core/src/main/java/androidx/constraintlayout/core/motion/MotionPaths.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public MotionPaths(int parentWidth,
122122
MotionKeyPosition c,
123123
MotionPaths startTimePoint,
124124
MotionPaths endTimePoint) {
125-
Utils.log(" ===================== setup start "+startTimePoint.mId+" : "+ startTimePoint.mAnimateRelativeTo );
126125
if (startTimePoint.mAnimateRelativeTo != null) {
127126
initPolar(parentWidth, parentHeight, c, startTimePoint, endTimePoint);
128127
return;
@@ -197,18 +196,12 @@ public void setupRelative(Motion mc, MotionPaths relative) {
197196
double dx = mX + mWidth / 2 - relative.mX - relative.mWidth / 2;
198197
double dy = mY + mHeight / 2 - relative.mY - relative.mHeight / 2;
199198
mRelativeToController = mc;
200-
Utils.log(mId+": my === "+mX+" , "+mY);
201-
Utils.log(mId+": relative === "+relative.mX+" , "+relative.mY);
202-
Utils.log(mId+": delta === "+dx+" , "+dy);
199+
203200
mX = (float) Math.hypot(dy, dx);
204201
if (Float.isNaN(mRelativeAngle)) {
205-
206202
mY = (float) (Math.atan2(dy, dx) + Math.PI / 2);
207-
Utils.log(mId+": compute === "+Math.toDegrees(mY));
208203
} else {
209204
mY = (float) Math.toRadians(mRelativeAngle);
210-
Utils.log(mId+": defined === "+Math.toDegrees(mY));
211-
212205
}
213206
}
214207

@@ -936,7 +929,10 @@ public void applyParameters(MotionWidget c) {
936929
point.mDrawPath = c.mMotion.mDrawPath;
937930
point.mAnimateCircleAngleTo = c.mMotion.mAnimateCircleAngleTo;
938931
point.mProgress = c.mPropertySet.mProgress;
939-
// point.mRelativeAngle = 0; // c.layout.circleAngle;
932+
if (c.mWidgetFrame != null && c.mWidgetFrame.widget != null) {
933+
point.mRelativeAngle = c.mWidgetFrame.widget.mCircleConstraintAngle;
934+
}
935+
940936
Set<String> at = c.getCustomAttributeNames();
941937
for (String s : at) {
942938
CustomVariable attr = c.getCustomAttribute(s);

constraintlayout/core/src/main/java/androidx/constraintlayout/core/widgets/ConstraintWidget.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import androidx.constraintlayout.core.Cache;
2424
import androidx.constraintlayout.core.LinearSystem;
2525
import androidx.constraintlayout.core.SolverVariable;
26+
import androidx.constraintlayout.core.motion.utils.Utils;
2627
import androidx.constraintlayout.core.state.WidgetFrame;
2728
import androidx.constraintlayout.core.widgets.analyzer.ChainRun;
2829
import androidx.constraintlayout.core.widgets.analyzer.HorizontalWidgetRun;
@@ -361,7 +362,7 @@ public boolean hasResolvedTargets(int orientation, int size) {
361362
float mResolvedDimensionRatio = 1.0f;
362363

363364
private int[] mMaxDimension = {Integer.MAX_VALUE, Integer.MAX_VALUE};
364-
private float mCircleConstraintAngle = 0;
365+
public float mCircleConstraintAngle = Float.NaN;
365366
private boolean mHasBaseline = false;
366367
private boolean mInPlaceholder;
367368

@@ -602,7 +603,7 @@ public void reset() {
602603
mCenterY.reset();
603604
mCenter.reset();
604605
mParent = null;
605-
mCircleConstraintAngle = 0;
606+
mCircleConstraintAngle = Float.NaN;
606607
mWidth = 0;
607608
mHeight = 0;
608609
mDimensionRatio = 0;
@@ -676,7 +677,7 @@ private void serializeAnchor(StringBuilder ret, String side, ConstraintAnchor a)
676677
}
677678

678679
private void serializeCircle(StringBuilder ret, ConstraintAnchor a, float angle) {
679-
if (a.mTarget == null) {
680+
if (a.mTarget == null || Float.isNaN(angle)) {
680681
return;
681682
}
682683

@@ -3589,6 +3590,8 @@ public void copy(ConstraintWidget src, HashMap<ConstraintWidget, ConstraintWidge
35893590

35903591
mMaxDimension = Arrays.copyOf(src.mMaxDimension, src.mMaxDimension.length);
35913592
mCircleConstraintAngle = src.mCircleConstraintAngle;
3593+
Utils.logStack(" copying angle = "+mCircleConstraintAngle, 5);
3594+
35923595
mHasBaseline = src.mHasBaseline;
35933596
mInPlaceholder = src.mInPlaceholder;
35943597

projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/ConstraintMotionProps.kt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,93 @@ fun MotionOrbit1() {
819819
}
820820
}
821821
}
822+
823+
824+
@Preview
825+
@Composable
826+
fun MotionOrbit2() {
827+
828+
var scene =
829+
"""
830+
{
831+
ConstraintSets: {
832+
start: {
833+
box1: {
834+
width: 50, height: 50,
835+
bottom: ['parent', 'bottom', 10],
836+
start: ['parent', 'start', 80],
837+
},
838+
title: {
839+
top: ['parent', 'top', 10],
840+
start: ['parent', 'start', 10],
841+
end: ['parent', 'end', 10],
842+
},
843+
box2: {
844+
width: 50, height: 50,
845+
circular: ['box1',90, 70],
846+
motion: {
847+
relativeTo: 'box1'
848+
}
849+
}
850+
},
851+
end: {
852+
box1: {
853+
width: 50, height: 50,
854+
top: ['parent', 'top', 60],
855+
end: ['parent', 'end', 80],
856+
},
857+
title: {
858+
top: ['parent', 'top', 10],
859+
start: ['parent', 'start', 10],
860+
end: ['parent', 'end', 10],
861+
},
862+
box2: {
863+
width: 50, height: 50,
864+
circular: ['box1', 900, 70],
865+
}
866+
}
867+
},
868+
Transitions: {
869+
default: {
870+
from: 'start',
871+
to: 'end',
872+
pathMotionArc : 'none',
873+
onSwipe: {
874+
anchor: 'box1',
875+
maxVelocity: 4.2,
876+
maxAccel: 3,
877+
direction: 'end',
878+
side: 'start',
879+
mode: 'velocity'
880+
}
881+
}
882+
}
883+
}
884+
""".trimIndent()
885+
886+
Column {
887+
MotionLayout(
888+
modifier = Modifier
889+
.fillMaxSize()
890+
.background(Color.LightGray),
891+
motionScene = MotionScene(content = scene),
892+
debug= EnumSet.of(MotionLayoutDebugFlags.SHOW_ALL),
893+
) {
894+
Text(text = " Orbit the red ",
895+
modifier = Modifier
896+
.layoutId("title")
897+
.background(Color.Gray))
898+
Box(
899+
modifier = Modifier
900+
.background(Color.Red)
901+
.layoutId("box1")
902+
)
903+
Box(
904+
modifier = Modifier
905+
.background(Color.Green)
906+
.layoutId("box2")
907+
)
908+
}
909+
}
910+
}
911+

projects/ComposeConstraintLayout/app/src/main/java/com/example/constraintlayout/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class MainActivity : AppCompatActivity() {
163163
demos.add(object : CompFunc { @Composable override fun Run() { MotionStagger1() } })
164164
demos.add(object : CompFunc { @Composable override fun Run() { MotionStagger2() } })
165165
demos.add(object : CompFunc { @Composable override fun Run() { MotionOrbit1() } })
166+
demos.add(object : CompFunc { @Composable override fun Run() { MotionOrbit2() } })
166167

167168
demos.add(object : CompFunc { @Composable override fun Run() { Example () } })
168169
demos.add(object : CompFunc { @Composable override fun Run() { RowColExample () } })

0 commit comments

Comments
 (0)