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

Commit 8848939

Browse files
authored
Small cleanup and KeyTrigger call ViewTransition (#31)
* ViewTransion from KeyTrigger * Create workspace.xml * remove workspace
1 parent e76e50d commit 8848939

File tree

12 files changed

+275
-311
lines changed

12 files changed

+275
-311
lines changed

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

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public class KeyTrigger extends Key {
5959
private float mFireThreshold = Float.NaN;
6060
private float mFireLastPos;
6161
private boolean mPostLayout = false;
62+
int mViewTransitionOnNegativeCross = UNSET;
63+
int mViewTransitionOnPositiveCross = UNSET;
64+
int mViewTransitionOnCross = UNSET;
6265

6366
RectF mCollisionRect = new RectF();
6467
RectF mTargetRect = new RectF();
@@ -195,14 +198,29 @@ public void conditionallyFire(float pos, View child) {
195198
}
196199
View call = (mTriggerReceiver == UNSET) ? child : ((MotionLayout) child.getParent()).findViewById(mTriggerReceiver);
197200

198-
if (fireNegative && mNegativeCross != null) {
199-
fire(mNegativeCross, call);
201+
if (fireNegative) {
202+
if (mNegativeCross != null) {
203+
fire(mNegativeCross, call);
204+
}
205+
if (mViewTransitionOnNegativeCross != UNSET) {
206+
((MotionLayout) child.getParent()).viewTransition(mViewTransitionOnNegativeCross, call);
207+
}
200208
}
201-
if (firePositive && mPositiveCross != null) {
202-
fire(mPositiveCross, call);
209+
if (firePositive) {
210+
if (mPositiveCross != null) {
211+
fire(mPositiveCross, call);
212+
}
213+
if (mViewTransitionOnPositiveCross != UNSET) {
214+
((MotionLayout) child.getParent()).viewTransition(mViewTransitionOnPositiveCross, call);
215+
}
203216
}
204-
if (fireCross && mCross != null) {
205-
fire(mCross, call);
217+
if (fireCross) {
218+
if (mCross != null) {
219+
fire(mCross, call);
220+
}
221+
if (mViewTransitionOnCross != UNSET) {
222+
((MotionLayout) child.getParent()).viewTransition(mViewTransitionOnCross, call);
223+
}
206224
}
207225

208226
}
@@ -266,6 +284,9 @@ private static class Loader {
266284
private static final int COLLISION = 9;
267285
private static final int POST_LAYOUT = 10;
268286
private static final int TRIGGER_RECEIVER = 11;
287+
private static final int VT_CROSS = 12;
288+
private static final int VT_NEGATIVE_CROSS = 13;
289+
private static final int VT_POSITIVE_CROSS = 14;
269290

270291
private static SparseIntArray mAttrMap = new SparseIntArray();
271292

@@ -280,6 +301,9 @@ private static class Loader {
280301
mAttrMap.append(R.styleable.KeyTrigger_motion_triggerOnCollision, COLLISION);
281302
mAttrMap.append(R.styleable.KeyTrigger_motion_postLayoutCollision, POST_LAYOUT);
282303
mAttrMap.append(R.styleable.KeyTrigger_triggerReceiver, TRIGGER_RECEIVER);
304+
mAttrMap.append(R.styleable.KeyTrigger_viewTransitionOnCross, VT_CROSS);
305+
mAttrMap.append(R.styleable.KeyTrigger_viewTransitionOnNegativeCross, VT_NEGATIVE_CROSS);
306+
mAttrMap.append(R.styleable.KeyTrigger_viewTransitionOnPositiveCross, VT_POSITIVE_CROSS);
283307
}
284308

285309
public static void read(KeyTrigger c, TypedArray a, Context context) {
@@ -328,6 +352,16 @@ public static void read(KeyTrigger c, TypedArray a, Context context) {
328352
break;
329353
case TRIGGER_RECEIVER:
330354
c.mTriggerReceiver = a.getResourceId(attr, c.mTriggerReceiver);
355+
break;
356+
case VT_NEGATIVE_CROSS:
357+
c.mViewTransitionOnNegativeCross = a.getResourceId(attr, c.mViewTransitionOnNegativeCross);
358+
break;
359+
case VT_POSITIVE_CROSS:
360+
c.mViewTransitionOnPositiveCross = a.getResourceId(attr, c.mViewTransitionOnPositiveCross);
361+
break;
362+
case VT_CROSS:
363+
c.mViewTransitionOnCross = a.getResourceId(attr, c.mViewTransitionOnCross);
364+
break;
331365
default:
332366
Log.e(NAME, "unused attribute 0x" + Integer.toHexString(attr) + " " + mAttrMap.get(attr));
333367
break;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public class MotionController {
110110
private int mQuantizeMotionSteps = UNSET;
111111
private float mQuantizeMotionPhase = Float.NaN;
112112
private Interpolator mQuantizeMotionInterpolator = null;
113+
private boolean mNoMovement = false;
113114

114115
/**
115116
* Get the view to pivot around
@@ -987,6 +988,7 @@ void setEndState(ConstraintWidget cw, ConstraintSet constraintSet) {
987988
void setBothStates(View v) {
988989
mStartMotionPath.time = 0;
989990
mStartMotionPath.position = 0;
991+
mNoMovement=true;
990992
mStartMotionPath.setBounds(v.getX(), v.getY(), v.getWidth(), v.getHeight());
991993
mEndMotionPath.setBounds(v.getX(), v.getY(), v.getWidth(), v.getHeight());
992994
mStartPoint.setState(v);
@@ -1103,8 +1105,9 @@ boolean interpolate(View child, float global_position, long time, KeyCache keyCa
11031105
}
11041106
}
11051107

1106-
mStartMotionPath.setView(position, child, mInterpolateVariables, mInterpolateData, mInterpolateVelocity, null);
1107-
1108+
if (!mNoMovement) {
1109+
mStartMotionPath.setView(position, child, mInterpolateVariables, mInterpolateData, mInterpolateVelocity, null);
1110+
}
11081111
if (mTransformPivotTarget != UNSET) {
11091112
if (mTransformPivotView == null) {
11101113
View layout = (View) child.getParent();

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

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,19 @@
880880
* <td>(method name) backward crossing of the framePosition call this methods on the target</td>
881881
* </tr>
882882
* <tr>
883+
* <td>viewTransitionOnCross&nbsp;</td>
884+
* <td>(ViewTransition Id) start a NoState view transition on crossing or hitting target
885+
* </td>
886+
* </tr>
887+
* <tr>
888+
* <td>viewTransitionOnPositiveCross</td>
889+
* <td>(ViewTransition Id) start a NoState view transition forward crossing of the framePosition or entering target</td>
890+
* </tr>
891+
* <tr>
892+
* <td>viewTransitionOnNegativeCross/td>
893+
* <td>(ViewTransition Id) start a NoState view transition backward crossing of the framePosition or leaving target</td>
894+
* </tr>
895+
* <tr>
883896
* <td>triggerSlack</td>
884897
* <td>(float) do not call trigger again if the framePosition has not moved this fraction away from the trigger point </td>
885898
* </tr>
@@ -4093,6 +4106,10 @@ public void updateState(int stateId, ConstraintSet set) {
40934106
}
40944107
}
40954108

4109+
/**
4110+
* Not sure we want this
4111+
* @hide
4112+
*/
40964113
public void updateState() {
40974114
mModel.initFrom(mLayoutWidget, mScene.getConstraintSet(mBeginState), mScene.getConstraintSet(mEndState));
40984115
rebuildScene();
@@ -4139,6 +4156,11 @@ public float getTargetPosition() {
41394156
return mTransitionGoalPosition;
41404157
}
41414158

4159+
/**
4160+
* Change the current Transition duration.
4161+
*
4162+
* @param milliseconds duration for transition to complete
4163+
*/
41424164
public void setTransitionDuration(int milliseconds) {
41434165
if (mScene == null) {
41444166
Log.e(TAG, "MotionScene not defined");
@@ -4230,23 +4252,41 @@ private void fireTransitionStarted(MotionLayout motionLayout, int mBeginState, i
42304252
}
42314253
}
42324254

4233-
public void viewTransition(int id, View... view) {
4255+
/**
4256+
* Execute a ViewTransition.
4257+
* Transition will execute if its conditions are met and it is enabled
4258+
*
4259+
* @param viewTransitionId
4260+
* @param view The views to apply to
4261+
*/
4262+
public void viewTransition(int viewTransitionId, View... view) {
42344263
if (mScene != null) {
4235-
mScene.viewTransition(id, view);
4264+
mScene.viewTransition(viewTransitionId, view);
42364265
} else {
42374266
Log.e(TAG, " no motionScene");
42384267
}
42394268
}
42404269

4241-
public void enableViewTransition(int id, boolean enable) {
4270+
/**
4271+
* Enable a ViewTransition ID.
4272+
*
4273+
* @param viewTransitionId id of ViewTransition
4274+
* @param enable If false view transition cannot be executed.
4275+
*/
4276+
public void enableViewTransition(int viewTransitionId, boolean enable) {
42424277
if (mScene != null) {
4243-
mScene.enableViewTransition(id, enable);
4278+
mScene.enableViewTransition(viewTransitionId, enable);
42444279
}
42454280
}
42464281

4247-
public boolean isViewTransitionEnabled(int id) {
4282+
/**
4283+
* Is transition id enabled or disabled
4284+
* @param viewTransitionId the ide of the transition
4285+
* @return true if enabled
4286+
*/
4287+
public boolean isViewTransitionEnabled(int viewTransitionId) {
42484288
if (mScene != null) {
4249-
return mScene.isViewTransitionEnabled(id);
4289+
return mScene.isViewTransitionEnabled(viewTransitionId);
42504290
}
42514291
return false;
42524292
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public class ViewTransition {
7070
private int mOnStateTransition = UNSET;
7171
private boolean mDisabled = false;
7272
private int mPathMotionArc = 0;
73-
private int mViewTransitionMode;
74-
private static final int VIEWTRANSITIONMODE_CURRENTSTATE = 0;
75-
private static final int VIEWTRANSITIONMODE_ALLSTATES = 1;
76-
private static final int VIEWTRANSITIONMODE_NOSTATE = 2;
73+
int mViewTransitionMode;
74+
static final int VIEWTRANSITIONMODE_CURRENTSTATE = 0;
75+
static final int VIEWTRANSITIONMODE_ALLSTATES = 1;
76+
static final int VIEWTRANSITIONMODE_NOSTATE = 2;
7777
KeyFrames mKeyFrames;
7878
ConstraintSet.Constraint mConstraintDelta;
7979
private int mDuration = UNSET;
@@ -242,7 +242,7 @@ private void parseViewTransitionTags(Context context, XmlPullParser parser) {
242242
a.recycle();
243243
}
244244

245-
void applyIndependentTransition(ViewTransitionController controller, MotionLayout motionLayout, int fromId, ConstraintSet current, View view) {
245+
void applyIndependentTransition(ViewTransitionController controller, MotionLayout motionLayout,View view) {
246246
MotionController motionController = new MotionController(view);
247247
motionController.setBothStates(view);
248248
mKeyFrames.addAllFrames(motionController);
@@ -305,7 +305,7 @@ void applyTransition(ViewTransitionController controller,
305305
return;
306306
}
307307
if (mViewTransitionMode == VIEWTRANSITIONMODE_NOSTATE) {
308-
applyIndependentTransition(controller, layout, fromId, current, views[0]);
308+
applyIndependentTransition(controller, layout, views[0]);
309309
return;
310310
}
311311
if (mViewTransitionMode == VIEWTRANSITIONMODE_ALLSTATES) {

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,19 @@ void remove(int id) {
6363

6464
private void viewTransition(ViewTransition vt, View... view) {
6565
int currentId = mMotionLayout.getCurrentState();
66-
if (currentId == -1) {
67-
Log.w(TAG, "Dont support transition within transition yet");
68-
return;
69-
}
70-
ConstraintSet current = mMotionLayout.getConstraintSet(currentId);
71-
if (current == null) {
72-
return;
66+
if (vt.mViewTransitionMode != ViewTransition.VIEWTRANSITIONMODE_NOSTATE) {
67+
if (currentId == -1) {
68+
Log.w(TAG, "Dont support transition within transition yet");
69+
return;
70+
}
71+
ConstraintSet current = mMotionLayout.getConstraintSet(currentId);
72+
if (current == null) {
73+
return;
74+
}
75+
vt.applyTransition(this, mMotionLayout, currentId, current, view);
76+
} else {
77+
vt.applyTransition(this, mMotionLayout, currentId, null, view);
7378
}
74-
vt.applyTransition(this, mMotionLayout, currentId, current, view);
75-
7679
}
7780

7881
void enableViewTransition(int id, boolean enable) {

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/utils/widget/ImageFilterButton.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ private void init(Context context, AttributeSet attrs) {
154154

155155
mLayer = new LayerDrawable(mLayers);
156156
mLayer.getDrawable(1).setAlpha((int) (255 * (mCrossfade)));
157+
if (!mOverlay) {
158+
mLayer.getDrawable(0).setAlpha((int) (255 * (1 - mCrossfade)));
159+
}
157160
super.setImageDrawable(mLayer);
158161
}
159162
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/utils/widget/ImageFilterView.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ private void init(Context context, AttributeSet attrs) {
479479

480480
mLayer = new LayerDrawable(mLayers);
481481
mLayer.getDrawable(1).setAlpha((int) (255 * (mCrossfade)));
482+
if (!mOverlay) {
483+
mLayer.getDrawable(0).setAlpha((int) (255 * (1 - mCrossfade)));
484+
}
482485
super.setImageDrawable(mLayer);
483486
}
484487
}

constraintlayout/constraintlayout/src/main/java/androidx/constraintlayout/utils/widget/MotionButton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/**
3737
* An ImageButton that can display, combine and filter images. <b>Added in 2.0</b>
3838
* <p>
39-
* Subclass of AppCompatImageButton to handle various common filtering operations.
39+
* Subclass of AppCompatImageButton to handle rounding edges dynamically.
4040
* </p>
4141
* <h2>MotionButton attributes</h2>
4242
* <td>round</td>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<enum name="start" value="5" />
2222
<enum name="end" value="6" />
2323
</attr>
24-
2524
<!-- Tell ConstraintSet and MotionLayout to ignore the visibility of a view -->
2625
<attr name="visibilityMode" format="enum">
2726
<enum name="normal" value="0" />
@@ -1071,6 +1070,7 @@
10711070
<enum name="ignoreRequest" value="0" />
10721071
<enum name="honorRequest" value="1" />
10731072
</attr>
1073+
10741074
<attr name="transitionDisable" format="boolean" />
10751075

10761076
<!-- ============== Transition ============== -->
@@ -1545,6 +1545,9 @@
15451545
<attr name="onNegativeCross" format="string" />
15461546
<attr name="onPositiveCross" format="string" />
15471547
<attr name="onCross" format="string" />
1548+
<attr name="viewTransitionOnNegativeCross" format="reference" />
1549+
<attr name="viewTransitionOnPositiveCross" format="reference" />
1550+
<attr name="viewTransitionOnCross" format="reference" />
15481551
<attr name="triggerSlack" format="float" />
15491552
<!-- The id of this trigger use when a callback listens for triggers -->
15501553
<attr name="triggerId" format="reference" />

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
@@ -82,7 +82,7 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
8282
String s = AppCompatActivity.class.getName();
8383

8484
private static boolean REVERSE = false;
85-
private final String LAYOUTS_MATCHES = "verification_2\\d+";
85+
private final String LAYOUTS_MATCHES = "verification_\\d+";
8686
private static String SHOW_FIRST = "";
8787
MotionLayout mMotionLayout;
8888
private Flow mFlow;

0 commit comments

Comments
 (0)