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

Commit b1b35db

Browse files
authored
add scheduleTransitionTo (#57)
1 parent f089e7d commit b1b35db

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/motion/widget/MotionLayout.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,8 @@ public class MotionLayout extends ConstraintLayout implements
10461046
private boolean mInLayout = false;
10471047
private StateCache mStateCache;
10481048
private Runnable mOnComplete = null;
1049+
private int[]mScheduledTransitionTo = null;
1050+
int mScheduledTransitions = 0;
10491051

10501052
MotionController getMotionController(int mTouchAnchorId) {
10511053
return mFrameArrayList.get(findViewById(mTouchAnchorId));
@@ -4002,6 +4004,11 @@ protected void fireTransitionCompleted() {
40024004
mOnComplete.run();
40034005
}
40044006

4007+
if (mScheduledTransitionTo != null && mScheduledTransitions > 0) {
4008+
transitionToState(mScheduledTransitionTo[0]);
4009+
System.arraycopy(mScheduledTransitionTo,1,mScheduledTransitionTo,0,mScheduledTransitionTo.length-1);
4010+
mScheduledTransitions--;
4011+
}
40054012
}
40064013

40074014
private void processTransitionCompleted() {
@@ -4205,6 +4212,25 @@ public void updateStateAnimate(int stateId, ConstraintSet set, int duration) {
42054212
}
42064213
}
42074214

4215+
/**
4216+
* on completing the current transition, transition to this state.
4217+
*
4218+
* @param id
4219+
*/
4220+
public void scheduleTransitionTo(int id) {
4221+
if (getCurrentState() == -1) {
4222+
transitionToState(id);
4223+
} else {
4224+
if (mScheduledTransitionTo == null) {
4225+
mScheduledTransitionTo = new int[4];
4226+
} else if (mScheduledTransitionTo.length <= mScheduledTransitions) {
4227+
mScheduledTransitionTo =
4228+
Arrays.copyOf(mScheduledTransitionTo, mScheduledTransitionTo.length * 2);
4229+
}
4230+
mScheduledTransitionTo[mScheduledTransitions++] = id;
4231+
}
4232+
}
4233+
42084234
/**
42094235
* Not sure we want this
42104236
* @hide

projects/MotionLayoutVerification/app/src/main/java/android/support/constraint/app/VerificationActivity.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
8585
String s = AppCompatActivity.class.getName();
8686

8787
private static boolean REVERSE = false;
88+
8889

8990
private final String RUN_FIRST = "verification_309";
9091
private final String LAYOUTS_MATCHES = "verification_\\d+";
91-
9292
private static String SHOW_FIRST = "";
9393
MotionLayout mMotionLayout;
9494
private Flow mFlow;
@@ -541,14 +541,19 @@ public void addToFlow2(View view) {
541541
* @param view
542542
*/
543543
public void twistViews(View view) {
544-
rotate ++;
544+
rotate++;
545545
int current = mMotionLayout.getCurrentState();
546546
ConstraintSet cset = mMotionLayout.cloneConstraintSet(current);
547547
int[] id = {R.id.button1, R.id.button2, R.id.button3, R.id.button4, R.id.button5, R.id.button6};
548548
for (int i : id) {
549-
cset.setRotation(i, ((rotate &1)==0) ? 90 : 0);
549+
cset.setRotation(i, ((rotate & 1) == 0) ? 90 : 0);
550550
}
551+
int r = (rotate + 1);
552+
String str = (((r & 1) == 0) ? "rot 90 " : "rot 0 ") +
553+
(((r & 2) == 0) ? "then start" : "then end");
554+
((Button) view).setText(str);
551555
mMotionLayout.updateStateAnimate(current, cset, 200);
556+
mMotionLayout.scheduleTransitionTo(((rotate & 2) == 0) ? R.id.start : R.id.end);
552557
}
553558

554559
interface Test {

projects/MotionLayoutVerification/app/src/main/res/layout/verification_150.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
android:layout_width="wrap_content"
2424
android:layout_height="wrap_content"
2525
android:text="2"
26+
android:layout_marginTop="50dp"
2627
app:layout_constraintStart_toStartOf="@id/button1"
2728
app:layout_constraintTop_toBottomOf="@id/button1" />
2829

@@ -31,6 +32,7 @@
3132
android:layout_width="wrap_content"
3233
android:layout_height="wrap_content"
3334
android:text="3"
35+
android:layout_marginTop="50dp"
3436
app:layout_constraintStart_toStartOf="@id/button2"
3537
app:layout_constraintTop_toBottomOf="@id/button2" />
3638

@@ -39,6 +41,7 @@
3941
android:layout_width="wrap_content"
4042
android:layout_height="wrap_content"
4143
android:text="4"
44+
android:layout_marginTop="50dp"
4245
app:layout_constraintStart_toStartOf="@id/button3"
4346
app:layout_constraintTop_toBottomOf="@id/button3" />
4447

@@ -47,22 +50,22 @@
4750
android:layout_width="wrap_content"
4851
android:layout_height="wrap_content"
4952
android:text="5"
50-
app:layout_constraintStart_toStartOf="@id/button4"
53+
app:layout_constraintStart_toEndOf="@id/button4"
5154
app:layout_constraintTop_toBottomOf="@id/button4" />
5255

5356
<Button
5457
android:id="@+id/button6"
5558
android:layout_width="wrap_content"
5659
android:layout_height="wrap_content"
5760
android:text="6"
58-
app:layout_constraintStart_toStartOf="@id/button5"
61+
app:layout_constraintStart_toEndOf="@id/button5"
5962
app:layout_constraintTop_toBottomOf="@id/button5" />
6063

6164
<Button
6265
android:id="@+id/button"
6366
android:layout_width="wrap_content"
6467
android:layout_height="wrap_content"
65-
android:text="animatedChange"
68+
android:text="test updateStateAnimate and scheduleTransitionTo"
6669
android:onClick="twistViews"
6770
app:layout_constraintBottom_toBottomOf="parent"
6871
app:layout_constraintEnd_toEndOf="parent"

0 commit comments

Comments
 (0)