Skip to content

Commit

Permalink
add new experimental mode callMeasure
Browse files Browse the repository at this point in the history
  • Loading branch information
jafu888 authored and oscar-ad committed Nov 11, 2021
1 parent 3b6031b commit 9000a7e
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 18 deletions.
Expand Up @@ -86,6 +86,7 @@ public class MotionController {
private static final boolean FAVOR_FIXED_SIZE_VIEWS = false;
View mView;
int mId;
boolean mForceMeasure = false;
String mConstraintTag;
private int mCurveFitType = KeyFrames.UNSET;
private MotionPaths mStartMotionPath = new MotionPaths();
Expand Down Expand Up @@ -259,6 +260,13 @@ public void getCenter(double p, float[] pos, float[] vel) {
mStartMotionPath.getCenter(p, mInterpolateVariables, position, pos, velocity, vel);
}

/**
* During the next layout call measure then layout
*/
public void remeasure() {
mForceMeasure = true;
}

/**
* fill the array point with the center coordinates point[0] is filled with the
* x coordinate of "time" 0.0 mPoints[point.length-1] is filled with the y coordinate of "time"
Expand Down Expand Up @@ -1274,7 +1282,8 @@ boolean interpolate(View child, float global_position, long time, KeyCache keyCa
}

if (!mNoMovement) {
mStartMotionPath.setView(position, child, mInterpolateVariables, mInterpolateData, mInterpolateVelocity, null);
mStartMotionPath.setView(position, child, mInterpolateVariables, mInterpolateData, mInterpolateVelocity, null, mForceMeasure);
mForceMeasure = false;
}
if (mTransformPivotTarget != UNSET) {
if (mTransformPivotView == null) {
Expand Down Expand Up @@ -1350,10 +1359,11 @@ boolean interpolate(View child, float global_position, long time, KeyCache keyCa
b = t + height;
}
if (mEndMotionPath.width != mStartMotionPath.width
|| mEndMotionPath.height != mStartMotionPath.height) {
|| mEndMotionPath.height != mStartMotionPath.height || mForceMeasure) {
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
child.measure(widthMeasureSpec, heightMeasureSpec);
mForceMeasure = false;
}
child.layout(l, t, r, b);
}
Expand Down
Expand Up @@ -16,6 +16,12 @@

package androidx.constraintlayout.motion.widget;

import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static androidx.constraintlayout.motion.widget.MotionScene.Transition.TRANSITION_FLAG_FIRST_DRAW;
import static androidx.constraintlayout.motion.widget.MotionScene.Transition.TRANSITION_FLAG_INTERCEPT_TOUCH;
import static androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID;
import static androidx.constraintlayout.widget.ConstraintSet.UNSET;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
Expand All @@ -38,7 +44,6 @@
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.TextView;

Expand Down Expand Up @@ -69,12 +74,6 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static androidx.constraintlayout.motion.widget.MotionScene.Transition.TRANSITION_FLAG_FIRST_DRAW;
import static androidx.constraintlayout.motion.widget.MotionScene.Transition.TRANSITION_FLAG_INTERCEPT_TOUCH;
import static androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID;
import static androidx.constraintlayout.widget.ConstraintSet.UNSET;


/**
* A subclass of ConstraintLayout that supports animating between various states <b>Added in 2.0</b>
Expand Down Expand Up @@ -1592,7 +1591,9 @@ public void setProgress(float pos, float velocity) {
setState(TransitionState.MOVING);
mLastVelocity = velocity;
if (velocity != 0.0f) {
animateTo(velocity>0?1:0);
animateTo(velocity > 0 ? 1 : 0);
} else if (pos != 0f && pos != 1f) {
animateTo(pos > 0.5f ? 1 : 0);
}
}

Expand Down Expand Up @@ -2878,9 +2879,19 @@ private Rect toRect(ConstraintWidget cw) {
public void requestLayout() {
if (!(mMeasureDuringTransition)) {
if (mCurrentState == UNSET && mScene != null
&& mScene.mCurrentTransition != null
&& mScene.mCurrentTransition.getLayoutDuringTransition() == MotionScene.LAYOUT_IGNORE_REQUEST) {
return;
&& mScene.mCurrentTransition != null) {
int mode = mScene.mCurrentTransition.getLayoutDuringTransition();
if (mode == MotionScene.LAYOUT_IGNORE_REQUEST) {
return;
} else if (mode == MotionScene.LAYOUT_CALL_MEASURE) {
final int n = getChildCount();
for (int i = 0; i < n; i++) {
View v = getChildAt(i);
MotionController motionController = mFrameArrayList.get(v);
motionController.remeasure();
}
return;
}
}
}
super.requestLayout();
Expand Down
Expand Up @@ -489,7 +489,7 @@ void getBounds(int[] toUse, double[] data, float[] point, int offset) {
double[] mTempDelta = new double[18];

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

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

if (remeasure) {
if (remeasure || mForceMeasure) {
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(i_width, View.MeasureSpec.EXACTLY);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(i_height, View.MeasureSpec.EXACTLY);

Expand Down
Expand Up @@ -82,6 +82,8 @@ public class MotionScene {
private int mLayoutDuringTransition = 0;
public static final int LAYOUT_IGNORE_REQUEST = 0;
public static final int LAYOUT_HONOR_REQUEST = 1;
public static final int LAYOUT_CALL_MEASURE = 3;

private MotionEvent mLastTouchDown;
private boolean mIgnoreTouch = false;
private boolean mMotionOutsideRegion = false;
Expand Down
Expand Up @@ -1197,6 +1197,8 @@
<attr name="layoutDuringTransition" format="enum">
<enum name="ignoreRequest" value="0" />
<enum name="honorRequest" value="1" />
<enum name="callMeasure" value="2" />

</attr>

<attr name="transitionDisable" format="boolean" />
Expand Down
Expand Up @@ -19,6 +19,7 @@
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
Expand All @@ -29,7 +30,7 @@
/**
* Test transitionToState bug
*/
public class OnCreateTransiton extends AppCompatActivity {
public class CheckSetProgress extends AppCompatActivity {
private static final String TAG = "CustomSwipeClick";
String layout_name;
MotionLayout mMotionLayout;
Expand Down Expand Up @@ -61,4 +62,42 @@ public void onTransitionTrigger(MotionLayout motionLayout, int triggerId, boolea
});
}

public void progressP0(View v) {
mMotionLayout.setProgress(0);
}
public void progressP5(View v){
mMotionLayout.setProgress(0.5f);
}
public void progressP1(View v){
mMotionLayout.setProgress(1f);
}
public void progressP0V0(View v) {
mMotionLayout.setProgress(0,0);

}
public void progressP0V1(View v) {
mMotionLayout.setProgress(0,1);

}
public void progressP5V_1(View v){
mMotionLayout.setProgress(0.5f,-0.1f);

}
public void progressP5V1(View v){
mMotionLayout.setProgress(0.5f,0.1f);

}
public void progressP1V0(View v){
mMotionLayout.setProgress(1f,0f);

}
public void progressP1V_1(View v){
mMotionLayout.setProgress(1f,-0.1f);

}
public void progressP50(View v){
mMotionLayout.setProgress((float) Math.random(),0f);

}

}
Expand Up @@ -108,7 +108,7 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
private static boolean REVERSE = false;


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

private static String SHOW_FIRST = "";
Expand Down
Expand Up @@ -129,6 +129,15 @@
app:layout_constraintStart_toStartOf="@+id/b8"
app:layout_constraintTop_toBottomOf="@+id/b8" />

<Button
android:id="@+id/ba"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="progressP5"
android:onClick="progressP50"
app:layout_constraintStart_toStartOf="@+id/b9"
app:layout_constraintTop_toBottomOf="@+id/b9" />


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

0 comments on commit 9000a7e

Please sign in to comment.