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

Commit 9000a7e

Browse files
jafu888oscar-ad
authored andcommitted
add new experimental mode callMeasure
1 parent 3b6031b commit 9000a7e

File tree

11 files changed

+493
-18
lines changed

11 files changed

+493
-18
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class MotionController {
8686
private static final boolean FAVOR_FIXED_SIZE_VIEWS = false;
8787
View mView;
8888
int mId;
89+
boolean mForceMeasure = false;
8990
String mConstraintTag;
9091
private int mCurveFitType = KeyFrames.UNSET;
9192
private MotionPaths mStartMotionPath = new MotionPaths();
@@ -259,6 +260,13 @@ public void getCenter(double p, float[] pos, float[] vel) {
259260
mStartMotionPath.getCenter(p, mInterpolateVariables, position, pos, velocity, vel);
260261
}
261262

263+
/**
264+
* During the next layout call measure then layout
265+
*/
266+
public void remeasure() {
267+
mForceMeasure = true;
268+
}
269+
262270
/**
263271
* fill the array point with the center coordinates point[0] is filled with the
264272
* x coordinate of "time" 0.0 mPoints[point.length-1] is filled with the y coordinate of "time"
@@ -1274,7 +1282,8 @@ boolean interpolate(View child, float global_position, long time, KeyCache keyCa
12741282
}
12751283

12761284
if (!mNoMovement) {
1277-
mStartMotionPath.setView(position, child, mInterpolateVariables, mInterpolateData, mInterpolateVelocity, null);
1285+
mStartMotionPath.setView(position, child, mInterpolateVariables, mInterpolateData, mInterpolateVelocity, null, mForceMeasure);
1286+
mForceMeasure = false;
12781287
}
12791288
if (mTransformPivotTarget != UNSET) {
12801289
if (mTransformPivotView == null) {
@@ -1350,10 +1359,11 @@ boolean interpolate(View child, float global_position, long time, KeyCache keyCa
13501359
b = t + height;
13511360
}
13521361
if (mEndMotionPath.width != mStartMotionPath.width
1353-
|| mEndMotionPath.height != mStartMotionPath.height) {
1362+
|| mEndMotionPath.height != mStartMotionPath.height || mForceMeasure) {
13541363
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
13551364
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
13561365
child.measure(widthMeasureSpec, heightMeasureSpec);
1366+
mForceMeasure = false;
13571367
}
13581368
child.layout(l, t, r, b);
13591369
}

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
package androidx.constraintlayout.motion.widget;
1818

19+
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
20+
import static androidx.constraintlayout.motion.widget.MotionScene.Transition.TRANSITION_FLAG_FIRST_DRAW;
21+
import static androidx.constraintlayout.motion.widget.MotionScene.Transition.TRANSITION_FLAG_INTERCEPT_TOUCH;
22+
import static androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID;
23+
import static androidx.constraintlayout.widget.ConstraintSet.UNSET;
24+
1925
import android.annotation.SuppressLint;
2026
import android.content.Context;
2127
import android.content.res.TypedArray;
@@ -38,7 +44,6 @@
3844
import android.view.VelocityTracker;
3945
import android.view.View;
4046
import android.view.ViewGroup;
41-
import android.view.animation.DecelerateInterpolator;
4247
import android.view.animation.Interpolator;
4348
import android.widget.TextView;
4449

@@ -69,12 +74,6 @@
6974
import java.util.List;
7075
import java.util.concurrent.CopyOnWriteArrayList;
7176

72-
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
73-
import static androidx.constraintlayout.motion.widget.MotionScene.Transition.TRANSITION_FLAG_FIRST_DRAW;
74-
import static androidx.constraintlayout.motion.widget.MotionScene.Transition.TRANSITION_FLAG_INTERCEPT_TOUCH;
75-
import static androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID;
76-
import static androidx.constraintlayout.widget.ConstraintSet.UNSET;
77-
7877

7978
/**
8079
* A subclass of ConstraintLayout that supports animating between various states <b>Added in 2.0</b>
@@ -1592,7 +1591,9 @@ public void setProgress(float pos, float velocity) {
15921591
setState(TransitionState.MOVING);
15931592
mLastVelocity = velocity;
15941593
if (velocity != 0.0f) {
1595-
animateTo(velocity>0?1:0);
1594+
animateTo(velocity > 0 ? 1 : 0);
1595+
} else if (pos != 0f && pos != 1f) {
1596+
animateTo(pos > 0.5f ? 1 : 0);
15961597
}
15971598
}
15981599

@@ -2878,9 +2879,19 @@ private Rect toRect(ConstraintWidget cw) {
28782879
public void requestLayout() {
28792880
if (!(mMeasureDuringTransition)) {
28802881
if (mCurrentState == UNSET && mScene != null
2881-
&& mScene.mCurrentTransition != null
2882-
&& mScene.mCurrentTransition.getLayoutDuringTransition() == MotionScene.LAYOUT_IGNORE_REQUEST) {
2883-
return;
2882+
&& mScene.mCurrentTransition != null) {
2883+
int mode = mScene.mCurrentTransition.getLayoutDuringTransition();
2884+
if (mode == MotionScene.LAYOUT_IGNORE_REQUEST) {
2885+
return;
2886+
} else if (mode == MotionScene.LAYOUT_CALL_MEASURE) {
2887+
final int n = getChildCount();
2888+
for (int i = 0; i < n; i++) {
2889+
View v = getChildAt(i);
2890+
MotionController motionController = mFrameArrayList.get(v);
2891+
motionController.remeasure();
2892+
}
2893+
return;
2894+
}
28842895
}
28852896
}
28862897
super.requestLayout();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ void getBounds(int[] toUse, double[] data, float[] point, int offset) {
489489
double[] mTempDelta = new double[18];
490490

491491
// Called on the start Time Point
492-
void setView(float position, View view, int[] toUse, double[] data, double[] slope, double[] cycle) {
492+
void setView(float position, View view, int[] toUse, double[] data, double[] slope, double[] cycle, boolean mForceMeasure) {
493493
float v_x = x;
494494
float v_y = y;
495495
float v_width = width;
@@ -630,7 +630,7 @@ void setView(float position, View view, int[] toUse, double[] data, double[] slo
630630

631631
boolean remeasure = i_width != view.getMeasuredWidth() || i_height != view.getMeasuredHeight();
632632

633-
if (remeasure) {
633+
if (remeasure || mForceMeasure) {
634634
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(i_width, View.MeasureSpec.EXACTLY);
635635
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(i_height, View.MeasureSpec.EXACTLY);
636636

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public class MotionScene {
8282
private int mLayoutDuringTransition = 0;
8383
public static final int LAYOUT_IGNORE_REQUEST = 0;
8484
public static final int LAYOUT_HONOR_REQUEST = 1;
85+
public static final int LAYOUT_CALL_MEASURE = 3;
86+
8587
private MotionEvent mLastTouchDown;
8688
private boolean mIgnoreTouch = false;
8789
private boolean mMotionOutsideRegion = false;

constraintlayout/constraintlayout/src/main/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,8 @@
11971197
<attr name="layoutDuringTransition" format="enum">
11981198
<enum name="ignoreRequest" value="0" />
11991199
<enum name="honorRequest" value="1" />
1200+
<enum name="callMeasure" value="2" />
1201+
12001202
</attr>
12011203

12021204
<attr name="transitionDisable" format="boolean" />

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.content.Context;
2020
import android.os.Bundle;
2121
import android.util.Log;
22+
import android.view.View;
2223

2324
import androidx.annotation.Nullable;
2425
import androidx.appcompat.app.AppCompatActivity;
@@ -29,7 +30,7 @@
2930
/**
3031
* Test transitionToState bug
3132
*/
32-
public class OnCreateTransiton extends AppCompatActivity {
33+
public class CheckSetProgress extends AppCompatActivity {
3334
private static final String TAG = "CustomSwipeClick";
3435
String layout_name;
3536
MotionLayout mMotionLayout;
@@ -61,4 +62,42 @@ public void onTransitionTrigger(MotionLayout motionLayout, int triggerId, boolea
6162
});
6263
}
6364

65+
public void progressP0(View v) {
66+
mMotionLayout.setProgress(0);
67+
}
68+
public void progressP5(View v){
69+
mMotionLayout.setProgress(0.5f);
70+
}
71+
public void progressP1(View v){
72+
mMotionLayout.setProgress(1f);
73+
}
74+
public void progressP0V0(View v) {
75+
mMotionLayout.setProgress(0,0);
76+
77+
}
78+
public void progressP0V1(View v) {
79+
mMotionLayout.setProgress(0,1);
80+
81+
}
82+
public void progressP5V_1(View v){
83+
mMotionLayout.setProgress(0.5f,-0.1f);
84+
85+
}
86+
public void progressP5V1(View v){
87+
mMotionLayout.setProgress(0.5f,0.1f);
88+
89+
}
90+
public void progressP1V0(View v){
91+
mMotionLayout.setProgress(1f,0f);
92+
93+
}
94+
public void progressP1V_1(View v){
95+
mMotionLayout.setProgress(1f,-0.1f);
96+
97+
}
98+
public void progressP50(View v){
99+
mMotionLayout.setProgress((float) Math.random(),0f);
100+
101+
}
102+
64103
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
108108
private static boolean REVERSE = false;
109109

110110

111-
private static final String RUN_FIRST = (true) ? "verification_800" : "bug_005";
111+
private static final String RUN_FIRST = (true) ? "verification_801" : "bug_005";
112112
private final String LAYOUTS_MATCHES = "v.*_.*";
113113

114114
private static String SHOW_FIRST = "";

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@
129129
app:layout_constraintStart_toStartOf="@+id/b8"
130130
app:layout_constraintTop_toBottomOf="@+id/b8" />
131131

132+
<Button
133+
android:id="@+id/ba"
134+
android:layout_width="wrap_content"
135+
android:layout_height="wrap_content"
136+
android:layout_marginTop="16dp"
137+
android:text="progressP5"
138+
android:onClick="progressP50"
139+
app:layout_constraintStart_toStartOf="@+id/b9"
140+
app:layout_constraintTop_toBottomOf="@+id/b9" />
132141

133-
142+
<!--This is used to test setProgress(p,v)-->
134143
</androidx.constraintlayout.motion.widget.MotionLayout>

0 commit comments

Comments
 (0)