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

Commit 3b6031b

Browse files
authored
fix setProgress(p, v) (#438)
1 parent 1295ca9 commit 3b6031b

File tree

6 files changed

+237
-2
lines changed

6 files changed

+237
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import android.view.VelocityTracker;
3939
import android.view.View;
4040
import android.view.ViewGroup;
41+
import android.view.animation.DecelerateInterpolator;
4142
import android.view.animation.Interpolator;
4243
import android.widget.TextView;
4344

@@ -1590,7 +1591,9 @@ public void setProgress(float pos, float velocity) {
15901591
setProgress(pos);
15911592
setState(TransitionState.MOVING);
15921593
mLastVelocity = velocity;
1593-
animateTo(1);
1594+
if (velocity != 0.0f) {
1595+
animateTo(velocity>0?1:0);
1596+
}
15941597
}
15951598

15961599
/////////////////////// use to cache the state

projects/MotionLayoutVerification/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<activity android:name=".CheckSetStates" />
4343
<activity android:name=".Bug010" />
4444
<activity android:name=".FullScreenActivity" />
45+
<activity android:name=".CheckSetProgress" />
4546
</application>
4647

4748
</manifest>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (C) 2021 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.support.constraint.app;
18+
19+
import android.content.Context;
20+
import android.os.Bundle;
21+
import android.util.Log;
22+
23+
import androidx.annotation.Nullable;
24+
import androidx.appcompat.app.AppCompatActivity;
25+
import androidx.constraintlayout.motion.widget.Debug;
26+
import androidx.constraintlayout.motion.widget.MotionLayout;
27+
import androidx.constraintlayout.motion.widget.TransitionAdapter;
28+
29+
/**
30+
* Test transitionToState bug
31+
*/
32+
public class OnCreateTransiton extends AppCompatActivity {
33+
private static final String TAG = "CustomSwipeClick";
34+
String layout_name;
35+
MotionLayout mMotionLayout;
36+
37+
@Override
38+
protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
39+
super.onCreate(savedInstanceState);
40+
Bundle extra = getIntent().getExtras();
41+
String prelayout = extra.getString(Utils.KEY);
42+
layout_name = prelayout;
43+
Context ctx = getApplicationContext();
44+
int id = ctx.getResources().getIdentifier(prelayout, "layout", ctx.getPackageName());
45+
setContentView(id);
46+
mMotionLayout = Utils.findMotionLayout(this);
47+
mMotionLayout.transitionToState(R.id.end);
48+
mMotionLayout.setTransitionListener(new TransitionAdapter() {
49+
@Override
50+
public void onTransitionCompleted(MotionLayout motionLayout, int currentId) {
51+
Log.v(TAG, Debug.getLoc()+" ");
52+
}
53+
54+
@Override
55+
public void onTransitionTrigger(MotionLayout motionLayout, int triggerId, boolean positive, float progress) {
56+
Log.v(TAG, Debug.getLoc()+" "+progress);
57+
if (progress <= 0.001 || progress >= 0.999) {
58+
Debug.logStack(TAG, "",19);
59+
}
60+
}
61+
});
62+
}
63+
64+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
9696
activity_map.put("bug_004", OnCreateTransiton.class);
9797
activity_map.put("verification_503", FullScreenActivity.class);
9898
activity_map.put("v_000", ParseLayouts.class);
99+
activity_map.put("verification_800", CheckSetProgress.class);
99100

100101

101102
// activity_map.put("verification_037", RotationToolbar.class);
@@ -107,7 +108,7 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
107108
private static boolean REVERSE = false;
108109

109110

110-
private static final String RUN_FIRST = (true) ? "verification_131" : "bug_005";
111+
private static final String RUN_FIRST = (true) ? "verification_800" : "bug_005";
111112
private final String LAYOUTS_MATCHES = "v.*_.*";
112113

113114
private static String SHOW_FIRST = "";
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/motionLayout"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
app:layoutDescription="@xml/verification_scene_800"
9+
app:motionDebug="SHOW_PATH"
10+
11+
android:background="#FF003b60">
12+
13+
14+
15+
<ImageView
16+
android:id="@+id/earth"
17+
android:layout_width="100dp"
18+
android:layout_height="100dp"
19+
android:src="@drawable/earth"
20+
app:layout_constraintVertical_bias="0.5"
21+
app:layout_constraintHorizontal_bias="0.5"
22+
app:layout_constraintBottom_toBottomOf="parent"
23+
app:layout_constraintEnd_toEndOf="parent"
24+
app:layout_constraintTop_toTopOf="parent"
25+
app:layout_constraintStart_toStartOf="parent"
26+
27+
/>
28+
29+
<androidx.constraintlayout.utils.widget.ImageFilterView
30+
android:id="@+id/moon"
31+
android:layout_width="20dp"
32+
android:layout_height="20dp"
33+
android:src="@drawable/moon"
34+
35+
app:layout_constraintCircleRadius="30dp"
36+
app:layout_constraintCircleAngle="0"
37+
app:layout_constraintCircle="@id/earth"
38+
/>
39+
40+
<Button
41+
android:id="@+id/b1"
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:layout_marginStart="35dp"
45+
android:layout_marginLeft="35dp"
46+
android:layout_marginTop="48dp"
47+
android:text="progressP0"
48+
android:onClick="progressP0"
49+
app:layout_constraintStart_toStartOf="parent"
50+
app:layout_constraintTop_toTopOf="parent" />
51+
52+
53+
<Button
54+
android:id="@+id/b2"
55+
android:layout_width="wrap_content"
56+
android:layout_height="wrap_content"
57+
android:layout_marginTop="16dp"
58+
android:text="progressP1"
59+
android:onClick="progressP1"
60+
app:layout_constraintStart_toStartOf="@+id/b1"
61+
app:layout_constraintTop_toBottomOf="@+id/b1" />
62+
<Button
63+
android:id="@+id/b3"
64+
android:layout_width="wrap_content"
65+
android:layout_height="wrap_content"
66+
android:layout_marginTop="16dp"
67+
android:text="progressP0V0"
68+
android:onClick="progressP0V0"
69+
app:layout_constraintStart_toStartOf="@+id/b2"
70+
app:layout_constraintTop_toBottomOf="@+id/b2" />
71+
72+
<Button
73+
android:id="@+id/b4"
74+
android:layout_width="wrap_content"
75+
android:layout_height="wrap_content"
76+
android:layout_marginTop="16dp"
77+
android:text="progressP0V1"
78+
android:onClick="progressP0V1"
79+
app:layout_constraintStart_toStartOf="@+id/b3"
80+
app:layout_constraintTop_toBottomOf="@+id/b3" />
81+
82+
<Button
83+
android:id="@+id/b5"
84+
android:layout_width="wrap_content"
85+
android:layout_height="wrap_content"
86+
android:layout_marginTop="16dp"
87+
android:text="progressP1V0"
88+
android:onClick="progressP1V0"
89+
app:layout_constraintStart_toStartOf="@+id/b4"
90+
app:layout_constraintTop_toBottomOf="@+id/b4" />
91+
92+
<Button
93+
android:id="@+id/b6"
94+
android:layout_width="wrap_content"
95+
android:layout_height="wrap_content"
96+
android:layout_marginTop="16dp"
97+
android:text="progressP1V_1"
98+
android:onClick="progressP1V_1"
99+
app:layout_constraintStart_toStartOf="@+id/b5"
100+
app:layout_constraintTop_toBottomOf="@+id/b5" />
101+
102+
<Button
103+
android:id="@+id/b7"
104+
android:layout_width="wrap_content"
105+
android:layout_height="wrap_content"
106+
android:layout_marginTop="16dp"
107+
android:text="progressP5V1"
108+
android:onClick="progressP5V1"
109+
app:layout_constraintStart_toStartOf="@+id/b6"
110+
app:layout_constraintTop_toBottomOf="@+id/b6" />
111+
112+
<Button
113+
android:id="@+id/b8"
114+
android:layout_width="wrap_content"
115+
android:layout_height="wrap_content"
116+
android:layout_marginTop="16dp"
117+
android:text="progressP5V_1"
118+
android:onClick="progressP5V_1"
119+
app:layout_constraintStart_toStartOf="@+id/b7"
120+
app:layout_constraintTop_toBottomOf="@+id/b7" />
121+
122+
<Button
123+
android:id="@+id/b9"
124+
android:layout_width="wrap_content"
125+
android:layout_height="wrap_content"
126+
android:layout_marginTop="16dp"
127+
android:text="progressP5"
128+
android:onClick="progressP5"
129+
app:layout_constraintStart_toStartOf="@+id/b8"
130+
app:layout_constraintTop_toBottomOf="@+id/b8" />
131+
132+
133+
134+
</androidx.constraintlayout.motion.widget.MotionLayout>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:motion="http://schemas.android.com/apk/res-auto"
4+
motion:defaultDuration="2000">
5+
6+
7+
<ConstraintSet
8+
android:id="@+id/end" >
9+
<ConstraintOverride android:id="@+id/moon" motion:layout_constraintCircleRadius="300dp"/>
10+
11+
</ConstraintSet>
12+
13+
<ConstraintSet android:id="@+id/start">
14+
15+
</ConstraintSet>
16+
17+
18+
19+
<Transition
20+
motion:constraintSetEnd="@+id/end"
21+
motion:constraintSetStart="@+id/start"
22+
motion:duration="1000"
23+
motion:motionInterpolator="linear"
24+
>
25+
<OnSwipe />
26+
27+
28+
</Transition>
29+
30+
31+
32+
</MotionScene>

0 commit comments

Comments
 (0)