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

Commit e450604

Browse files
authored
setStartState and more test (#218)
* fix math bug & add AutoCompleteMode * fix comment & and new test * fixed Comment * fix the no callback bug * add setStartState + more verications
1 parent 41e1c41 commit e450604

19 files changed

+696
-6
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,10 @@ protected interface MotionTracker {
11881188
}
11891189

11901190
void setState(TransitionState newState) {
1191+
if (DEBUG) {
1192+
Debug.logStack(TAG, mTransitionState + " -> " + newState + " " +
1193+
Debug.getName(getContext(), mCurrentState), 2);
1194+
}
11911195
if (newState == TransitionState.FINISHED && mCurrentState == UNSET) {
11921196
return;
11931197
}
@@ -1295,6 +1299,23 @@ public float getYVelocity(int id) {
12951299
}
12961300
}
12971301

1302+
/**
1303+
* sets the state to start in. To be used during OnCreate
1304+
*
1305+
* @param beginId the id of the start constraint set
1306+
*/
1307+
void setStartState(int beginId) {
1308+
if (!isAttachedToWindow()) {
1309+
if (mStateCache == null) {
1310+
mStateCache = new StateCache();
1311+
}
1312+
mStateCache.setStartState(beginId);
1313+
mStateCache.setEndState(beginId);
1314+
return;
1315+
}
1316+
mCurrentState = beginId;
1317+
}
1318+
12981319
/**
12991320
* Set a transition explicitly between two constraint sets
13001321
*
@@ -2222,6 +2243,9 @@ public boolean isInRotation() {
22222243
* @param id state to set
22232244
*/
22242245
public void jumpToState(int id) {
2246+
if (!isAttachedToWindow()) {
2247+
mCurrentState = id;
2248+
}
22252249
if (mBeginState == id) {
22262250
setProgress(0);
22272251
} else if (mEndState == id) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<category android:name="android.intent.category.LAUNCHER" />
1919
</intent-filter>
2020
</activity>
21+
<activity android:name=".ButtonDriveAnimate" />
22+
<activity android:name=".OnCreateTransiton" />
23+
2124
<activity android:name=".RotationActivity"
2225
android:configChanges="orientation|screenSize"/>
2326
<activity android:name=".RotationUsingRotateTo"
@@ -36,6 +39,7 @@
3639
/>
3740
<activity android:name=".CheckCallbackActivity" />
3841
<activity android:name=".CheckSetStates" />
42+
<activity android:name=".FullScreenActivity" />
3943

4044
</application>
4145

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,18 @@ protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle sav
4444
Context ctx = getApplicationContext();
4545
int id = ctx.getResources().getIdentifier(prelayout, "layout", ctx.getPackageName());
4646
setContentView(id);
47+
setTitle(layout_name);
4748
mMotionLayout = Utils.findMotionLayout(this);
4849
mMotionLayout.setTransitionListener(new TransitionAdapter() {
4950
@Override
5051
public void onTransitionCompleted(MotionLayout motionLayout, int currentId) {
51-
Log.v(TAG, Debug.getLoc()+" ");
52+
Log.v(TAG, Debug.getLoc()+" "+Debug.getName(getApplicationContext(),currentId));
53+
}
54+
55+
@Override
56+
public void onTransitionTrigger(MotionLayout motionLayout, int triggerId, boolean positive, float progress) {
57+
Log.v(TAG, Debug.getLoc()+" "+progress+" "+Debug.getName(getApplicationContext(),triggerId));
58+
5259
}
5360
});
5461
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,30 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
5151

5252
TextView text = findViewById(R.id.text);
5353
if (text != null) {
54+
5455
mMotionLayout.setTransitionListener(new TransitionAdapter() {
56+
@Override
57+
public void onTransitionStarted(MotionLayout motionLayout, int startId, int endId) {
58+
Log.v(TAG, Debug.getLoc() + " "+Debug.getName(getApplicationContext(),startId));
59+
60+
}
61+
62+
@Override
63+
public void onTransitionChange(MotionLayout motionLayout, int startId, int endId, float progress) {
64+
Log.v(TAG, Debug.getLoc() + " progress "+progress);
65+
66+
}
67+
68+
5569
@Override
5670
public void onTransitionCompleted(MotionLayout motionLayout, int currentId) {
5771
text.setText((currentId == R.id.expanded) ? "cb down" : "cb up");
5872
Log.v(TAG, Debug.getLoc() + " "+Debug.getName(getApplicationContext(),currentId));
73+
Log.v(TAG," --------------------------------------------------------------------");
5974
}
6075

6176
});
77+
6278
}
6379
}
6480
// ================================= Recycler support ====================================
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
import android.view.View;
23+
import android.view.WindowManager;
24+
25+
import androidx.annotation.Nullable;
26+
import androidx.appcompat.app.AppCompatActivity;
27+
import androidx.constraintlayout.motion.widget.Debug;
28+
import androidx.constraintlayout.motion.widget.MotionLayout;
29+
30+
/**
31+
* Test transitionToState bug
32+
*/
33+
public class FullScreenActivity extends AppCompatActivity {
34+
private static final String TAG = "CustomSwipeClick";
35+
String layout_name;
36+
MotionLayout mMotionLayout;
37+
38+
@Override
39+
protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
40+
super.onCreate(savedInstanceState);
41+
Bundle extra = getIntent().getExtras();
42+
String prelayout = extra.getString(Utils.KEY);
43+
layout_name = prelayout;
44+
Context ctx = getApplicationContext();
45+
int id = ctx.getResources().getIdentifier(prelayout, "layout", ctx.getPackageName());
46+
setContentView(id);
47+
getSupportActionBar().hide();
48+
// setTitle(layout_name);
49+
WindowManager.LayoutParams attrs = getWindow().getAttributes();
50+
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
51+
getWindow().setAttributes(attrs);
52+
53+
}
54+
55+
public void goLeft(View v) {
56+
Log.v(TAG, Debug.getLoc()+" ");
57+
mMotionLayout.transitionToState(R.id.left);
58+
59+
}
60+
public void goRight(View v) {
61+
Log.v(TAG, Debug.getLoc()+" ");
62+
mMotionLayout.transitionToState(R.id.right);
63+
64+
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}
55+
56+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
8989
activity_map.put("verification_042", CheckCallbackActivity.class);
9090
activity_map.put("verification_057", CheckSetStates.class);
9191
activity_map.put("verification_502", ButtonDriveAnimate.class);
92+
activity_map.put("bug_004", OnCreateTransiton.class);
93+
activity_map.put("verification_503", FullScreenActivity.class);
94+
9295

9396
// activity_map.put("verification_037", RotationToolbar.class);
9497
// activity_map.put("verification_038", RotationRotateToToolbar.class);
@@ -98,7 +101,8 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
98101

99102
private static boolean REVERSE = false;
100103

101-
private final String RUN_FIRST = "verification_502";
104+
105+
private static final String RUN_FIRST = (true) ? "verification_503" : "bug_005";
102106
private final String LAYOUTS_MATCHES = "v.*_.*";
103107

104108
private static String SHOW_FIRST = "";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M15.5,5l-4.5,0l5,7l-5,7l4.5,0l5,-7z"/>
10+
<path
11+
android:fillColor="@android:color/white"
12+
android:pathData="M8.5,5l-4.5,0l5,7l-5,7l4.5,0l5,-7z"/>
13+
</vector>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.motion.widget.MotionLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:id="@+id/rootView"
7+
android:layout_width="match_parent"
8+
android:layout_height="match_parent"
9+
android:background="#BECEED"
10+
app:layoutDescription="@xml/bug_004_scene"
11+
tools:context=".OnCreateTransiton"
12+
>
13+
<View
14+
android:id="@+id/view"
15+
android:layout_width="100dp"
16+
android:layout_height="50dp"
17+
android:background="#4B1A8F"
18+
android:visibility="invisible"
19+
app:layout_constraintStart_toStartOf="parent"
20+
app:layout_constraintTop_toTopOf="parent" />
21+
<View
22+
android:id="@+id/view2"
23+
android:layout_width="100dp"
24+
android:layout_height="50dp"
25+
android:background="#790"
26+
app:layout_constraintStart_toEndOf="@+id/view"
27+
app:layout_constraintTop_toBottomOf="@+id/view" />
28+
</androidx.constraintlayout.motion.widget.MotionLayout>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.motion.widget.MotionLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:id="@+id/rootView"
7+
android:layout_width="match_parent"
8+
android:layout_height="match_parent"
9+
android:background="#BECEED"
10+
app:layoutDescription="@xml/bug_005_scene"
11+
tools:context=".OnCreateTransiton"
12+
>
13+
14+
<androidx.appcompat.widget.SwitchCompat
15+
android:id="@+id/switchDemo"
16+
android:layout_width="300dp"
17+
android:layout_height="wrap_content"
18+
app:layout_constraintStart_toStartOf="parent"
19+
app:layout_constraintTop_toTopOf="parent" />
20+
21+
</androidx.constraintlayout.motion.widget.MotionLayout>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<View
2222
android:id="@+id/secondSpace"
2323
android:layout_width="0dp"
24-
android:layout_height="50dp"
24+
android:layout_height="20dp"
2525
android:background="#2222FF"
2626
app:layout_constraintEnd_toEndOf="parent"
2727
app:layout_constraintStart_toStartOf="parent"

0 commit comments

Comments
 (0)