diff --git a/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionLayout.java b/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionLayout.java
index f6229b7cd..cfae71814 100644
--- a/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionLayout.java
+++ b/constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionLayout.java
@@ -1046,6 +1046,8 @@ public class MotionLayout extends ConstraintLayout implements
private boolean mInLayout = false;
private StateCache mStateCache;
private Runnable mOnComplete = null;
+ private int[]mScheduledTransitionTo = null;
+ int mScheduledTransitions = 0;
MotionController getMotionController(int mTouchAnchorId) {
return mFrameArrayList.get(findViewById(mTouchAnchorId));
@@ -4002,6 +4004,11 @@ protected void fireTransitionCompleted() {
mOnComplete.run();
}
+ if (mScheduledTransitionTo != null && mScheduledTransitions > 0) {
+ transitionToState(mScheduledTransitionTo[0]);
+ System.arraycopy(mScheduledTransitionTo,1,mScheduledTransitionTo,0,mScheduledTransitionTo.length-1);
+ mScheduledTransitions--;
+ }
}
private void processTransitionCompleted() {
@@ -4205,6 +4212,25 @@ public void updateStateAnimate(int stateId, ConstraintSet set, int duration) {
}
}
+ /**
+ * on completing the current transition, transition to this state.
+ *
+ * @param id
+ */
+ public void scheduleTransitionTo(int id) {
+ if (getCurrentState() == -1) {
+ transitionToState(id);
+ } else {
+ if (mScheduledTransitionTo == null) {
+ mScheduledTransitionTo = new int[4];
+ } else if (mScheduledTransitionTo.length <= mScheduledTransitions) {
+ mScheduledTransitionTo =
+ Arrays.copyOf(mScheduledTransitionTo, mScheduledTransitionTo.length * 2);
+ }
+ mScheduledTransitionTo[mScheduledTransitions++] = id;
+ }
+ }
+
/**
* Not sure we want this
* @hide
diff --git a/projects/MotionLayoutVerification/app/src/main/java/android/support/constraint/app/VerificationActivity.java b/projects/MotionLayoutVerification/app/src/main/java/android/support/constraint/app/VerificationActivity.java
index 7905bc34d..b3b9ddb7c 100644
--- a/projects/MotionLayoutVerification/app/src/main/java/android/support/constraint/app/VerificationActivity.java
+++ b/projects/MotionLayoutVerification/app/src/main/java/android/support/constraint/app/VerificationActivity.java
@@ -85,10 +85,10 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
String s = AppCompatActivity.class.getName();
private static boolean REVERSE = false;
+
private final String RUN_FIRST = "verification_309";
private final String LAYOUTS_MATCHES = "verification_\\d+";
-
private static String SHOW_FIRST = "";
MotionLayout mMotionLayout;
private Flow mFlow;
@@ -541,14 +541,19 @@ public void addToFlow2(View view) {
* @param view
*/
public void twistViews(View view) {
- rotate ++;
+ rotate++;
int current = mMotionLayout.getCurrentState();
ConstraintSet cset = mMotionLayout.cloneConstraintSet(current);
int[] id = {R.id.button1, R.id.button2, R.id.button3, R.id.button4, R.id.button5, R.id.button6};
for (int i : id) {
- cset.setRotation(i, ((rotate &1)==0) ? 90 : 0);
+ cset.setRotation(i, ((rotate & 1) == 0) ? 90 : 0);
}
+ int r = (rotate + 1);
+ String str = (((r & 1) == 0) ? "rot 90 " : "rot 0 ") +
+ (((r & 2) == 0) ? "then start" : "then end");
+ ((Button) view).setText(str);
mMotionLayout.updateStateAnimate(current, cset, 200);
+ mMotionLayout.scheduleTransitionTo(((rotate & 2) == 0) ? R.id.start : R.id.end);
}
interface Test {
diff --git a/projects/MotionLayoutVerification/app/src/main/res/layout/verification_150.xml b/projects/MotionLayoutVerification/app/src/main/res/layout/verification_150.xml
index 7b3e40feb..c5bfa9510 100644
--- a/projects/MotionLayoutVerification/app/src/main/res/layout/verification_150.xml
+++ b/projects/MotionLayoutVerification/app/src/main/res/layout/verification_150.xml
@@ -23,6 +23,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
+ android:layout_marginTop="50dp"
app:layout_constraintStart_toStartOf="@id/button1"
app:layout_constraintTop_toBottomOf="@id/button1" />
@@ -31,6 +32,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
+ android:layout_marginTop="50dp"
app:layout_constraintStart_toStartOf="@id/button2"
app:layout_constraintTop_toBottomOf="@id/button2" />
@@ -39,6 +41,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
+ android:layout_marginTop="50dp"
app:layout_constraintStart_toStartOf="@id/button3"
app:layout_constraintTop_toBottomOf="@id/button3" />
@@ -47,7 +50,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
- app:layout_constraintStart_toStartOf="@id/button4"
+ app:layout_constraintStart_toEndOf="@id/button4"
app:layout_constraintTop_toBottomOf="@id/button4" />