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

Small cleanup and KeyTrigger call ViewTransition #31

Merged
merged 3 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class KeyTrigger extends Key {
private float mFireThreshold = Float.NaN;
private float mFireLastPos;
private boolean mPostLayout = false;
int mViewTransitionOnNegativeCross = UNSET;
int mViewTransitionOnPositiveCross = UNSET;
int mViewTransitionOnCross = UNSET;

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

if (fireNegative && mNegativeCross != null) {
fire(mNegativeCross, call);
if (fireNegative) {
if (mNegativeCross != null) {
fire(mNegativeCross, call);
}
if (mViewTransitionOnNegativeCross != UNSET) {
((MotionLayout) child.getParent()).viewTransition(mViewTransitionOnNegativeCross, call);
}
}
if (firePositive && mPositiveCross != null) {
fire(mPositiveCross, call);
if (firePositive) {
if (mPositiveCross != null) {
fire(mPositiveCross, call);
}
if (mViewTransitionOnPositiveCross != UNSET) {
((MotionLayout) child.getParent()).viewTransition(mViewTransitionOnPositiveCross, call);
}
}
if (fireCross && mCross != null) {
fire(mCross, call);
if (fireCross) {
if (mCross != null) {
fire(mCross, call);
}
if (mViewTransitionOnCross != UNSET) {
((MotionLayout) child.getParent()).viewTransition(mViewTransitionOnCross, call);
}
}

}
Expand Down Expand Up @@ -266,6 +284,9 @@ private static class Loader {
private static final int COLLISION = 9;
private static final int POST_LAYOUT = 10;
private static final int TRIGGER_RECEIVER = 11;
private static final int VT_CROSS = 12;
private static final int VT_NEGATIVE_CROSS = 13;
private static final int VT_POSITIVE_CROSS = 14;

private static SparseIntArray mAttrMap = new SparseIntArray();

Expand All @@ -280,6 +301,9 @@ private static class Loader {
mAttrMap.append(R.styleable.KeyTrigger_motion_triggerOnCollision, COLLISION);
mAttrMap.append(R.styleable.KeyTrigger_motion_postLayoutCollision, POST_LAYOUT);
mAttrMap.append(R.styleable.KeyTrigger_triggerReceiver, TRIGGER_RECEIVER);
mAttrMap.append(R.styleable.KeyTrigger_viewTransitionOnCross, VT_CROSS);
mAttrMap.append(R.styleable.KeyTrigger_viewTransitionOnNegativeCross, VT_NEGATIVE_CROSS);
mAttrMap.append(R.styleable.KeyTrigger_viewTransitionOnPositiveCross, VT_POSITIVE_CROSS);
}

public static void read(KeyTrigger c, TypedArray a, Context context) {
Expand Down Expand Up @@ -328,6 +352,16 @@ public static void read(KeyTrigger c, TypedArray a, Context context) {
break;
case TRIGGER_RECEIVER:
c.mTriggerReceiver = a.getResourceId(attr, c.mTriggerReceiver);
break;
case VT_NEGATIVE_CROSS:
c.mViewTransitionOnNegativeCross = a.getResourceId(attr, c.mViewTransitionOnNegativeCross);
break;
case VT_POSITIVE_CROSS:
c.mViewTransitionOnPositiveCross = a.getResourceId(attr, c.mViewTransitionOnPositiveCross);
break;
case VT_CROSS:
c.mViewTransitionOnCross = a.getResourceId(attr, c.mViewTransitionOnCross);
break;
default:
Log.e(NAME, "unused attribute 0x" + Integer.toHexString(attr) + " " + mAttrMap.get(attr));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public class MotionController {
private int mQuantizeMotionSteps = UNSET;
private float mQuantizeMotionPhase = Float.NaN;
private Interpolator mQuantizeMotionInterpolator = null;
private boolean mNoMovement = false;

/**
* Get the view to pivot around
Expand Down Expand Up @@ -987,6 +988,7 @@ void setEndState(ConstraintWidget cw, ConstraintSet constraintSet) {
void setBothStates(View v) {
mStartMotionPath.time = 0;
mStartMotionPath.position = 0;
mNoMovement=true;
mStartMotionPath.setBounds(v.getX(), v.getY(), v.getWidth(), v.getHeight());
mEndMotionPath.setBounds(v.getX(), v.getY(), v.getWidth(), v.getHeight());
mStartPoint.setState(v);
Expand Down Expand Up @@ -1103,8 +1105,9 @@ boolean interpolate(View child, float global_position, long time, KeyCache keyCa
}
}

mStartMotionPath.setView(position, child, mInterpolateVariables, mInterpolateData, mInterpolateVelocity, null);

if (!mNoMovement) {
mStartMotionPath.setView(position, child, mInterpolateVariables, mInterpolateData, mInterpolateVelocity, null);
}
if (mTransformPivotTarget != UNSET) {
if (mTransformPivotView == null) {
View layout = (View) child.getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,19 @@
* <td>(method name) backward crossing of the framePosition call this methods on the target</td>
* </tr>
* <tr>
* <td>viewTransitionOnCross&nbsp;</td>
* <td>(ViewTransition Id) start a NoState view transition on crossing or hitting target
* </td>
* </tr>
* <tr>
* <td>viewTransitionOnPositiveCross</td>
* <td>(ViewTransition Id) start a NoState view transition forward crossing of the framePosition or entering target</td>
* </tr>
* <tr>
* <td>viewTransitionOnNegativeCross/td>
* <td>(ViewTransition Id) start a NoState view transition backward crossing of the framePosition or leaving target</td>
* </tr>
* <tr>
* <td>triggerSlack</td>
* <td>(float) do not call trigger again if the framePosition has not moved this fraction away from the trigger point </td>
* </tr>
Expand Down Expand Up @@ -4093,6 +4106,10 @@ public void updateState(int stateId, ConstraintSet set) {
}
}

/**
* Not sure we want this
* @hide
*/
public void updateState() {
mModel.initFrom(mLayoutWidget, mScene.getConstraintSet(mBeginState), mScene.getConstraintSet(mEndState));
rebuildScene();
Expand Down Expand Up @@ -4139,6 +4156,11 @@ public float getTargetPosition() {
return mTransitionGoalPosition;
}

/**
* Change the current Transition duration.
*
* @param milliseconds duration for transition to complete
*/
public void setTransitionDuration(int milliseconds) {
if (mScene == null) {
Log.e(TAG, "MotionScene not defined");
Expand Down Expand Up @@ -4230,23 +4252,41 @@ private void fireTransitionStarted(MotionLayout motionLayout, int mBeginState, i
}
}

public void viewTransition(int id, View... view) {
/**
* Execute a ViewTransition.
* Transition will execute if its conditions are met and it is enabled
*
* @param viewTransitionId
* @param view The views to apply to
*/
public void viewTransition(int viewTransitionId, View... view) {
if (mScene != null) {
mScene.viewTransition(id, view);
mScene.viewTransition(viewTransitionId, view);
} else {
Log.e(TAG, " no motionScene");
}
}

public void enableViewTransition(int id, boolean enable) {
/**
* Enable a ViewTransition ID.
*
* @param viewTransitionId id of ViewTransition
* @param enable If false view transition cannot be executed.
*/
public void enableViewTransition(int viewTransitionId, boolean enable) {
if (mScene != null) {
mScene.enableViewTransition(id, enable);
mScene.enableViewTransition(viewTransitionId, enable);
}
}

public boolean isViewTransitionEnabled(int id) {
/**
* Is transition id enabled or disabled
* @param viewTransitionId the ide of the transition
* @return true if enabled
*/
public boolean isViewTransitionEnabled(int viewTransitionId) {
if (mScene != null) {
return mScene.isViewTransitionEnabled(id);
return mScene.isViewTransitionEnabled(viewTransitionId);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public class ViewTransition {
private int mOnStateTransition = UNSET;
private boolean mDisabled = false;
private int mPathMotionArc = 0;
private int mViewTransitionMode;
private static final int VIEWTRANSITIONMODE_CURRENTSTATE = 0;
private static final int VIEWTRANSITIONMODE_ALLSTATES = 1;
private static final int VIEWTRANSITIONMODE_NOSTATE = 2;
int mViewTransitionMode;
static final int VIEWTRANSITIONMODE_CURRENTSTATE = 0;
static final int VIEWTRANSITIONMODE_ALLSTATES = 1;
static final int VIEWTRANSITIONMODE_NOSTATE = 2;
KeyFrames mKeyFrames;
ConstraintSet.Constraint mConstraintDelta;
private int mDuration = UNSET;
Expand Down Expand Up @@ -242,7 +242,7 @@ private void parseViewTransitionTags(Context context, XmlPullParser parser) {
a.recycle();
}

void applyIndependentTransition(ViewTransitionController controller, MotionLayout motionLayout, int fromId, ConstraintSet current, View view) {
void applyIndependentTransition(ViewTransitionController controller, MotionLayout motionLayout,View view) {
MotionController motionController = new MotionController(view);
motionController.setBothStates(view);
mKeyFrames.addAllFrames(motionController);
Expand Down Expand Up @@ -305,7 +305,7 @@ void applyTransition(ViewTransitionController controller,
return;
}
if (mViewTransitionMode == VIEWTRANSITIONMODE_NOSTATE) {
applyIndependentTransition(controller, layout, fromId, current, views[0]);
applyIndependentTransition(controller, layout, views[0]);
return;
}
if (mViewTransitionMode == VIEWTRANSITIONMODE_ALLSTATES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ void remove(int id) {

private void viewTransition(ViewTransition vt, View... view) {
int currentId = mMotionLayout.getCurrentState();
if (currentId == -1) {
Log.w(TAG, "Dont support transition within transition yet");
return;
}
ConstraintSet current = mMotionLayout.getConstraintSet(currentId);
if (current == null) {
return;
if (vt.mViewTransitionMode != ViewTransition.VIEWTRANSITIONMODE_NOSTATE) {
if (currentId == -1) {
Log.w(TAG, "Dont support transition within transition yet");
return;
}
ConstraintSet current = mMotionLayout.getConstraintSet(currentId);
if (current == null) {
return;
}
vt.applyTransition(this, mMotionLayout, currentId, current, view);
} else {
vt.applyTransition(this, mMotionLayout, currentId, null, view);
}
vt.applyTransition(this, mMotionLayout, currentId, current, view);

}

void enableViewTransition(int id, boolean enable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ private void init(Context context, AttributeSet attrs) {

mLayer = new LayerDrawable(mLayers);
mLayer.getDrawable(1).setAlpha((int) (255 * (mCrossfade)));
if (!mOverlay) {
mLayer.getDrawable(0).setAlpha((int) (255 * (1 - mCrossfade)));
}
super.setImageDrawable(mLayer);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ private void init(Context context, AttributeSet attrs) {

mLayer = new LayerDrawable(mLayers);
mLayer.getDrawable(1).setAlpha((int) (255 * (mCrossfade)));
if (!mOverlay) {
mLayer.getDrawable(0).setAlpha((int) (255 * (1 - mCrossfade)));
}
super.setImageDrawable(mLayer);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* An ImageButton that can display, combine and filter images. <b>Added in 2.0</b>
* <p>
* Subclass of AppCompatImageButton to handle various common filtering operations.
* Subclass of AppCompatImageButton to handle rounding edges dynamically.
* </p>
* <h2>MotionButton attributes</h2>
* <td>round</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<enum name="start" value="5" />
<enum name="end" value="6" />
</attr>

<!-- Tell ConstraintSet and MotionLayout to ignore the visibility of a view -->
<attr name="visibilityMode" format="enum">
<enum name="normal" value="0" />
Expand Down Expand Up @@ -1071,6 +1070,7 @@
<enum name="ignoreRequest" value="0" />
<enum name="honorRequest" value="1" />
</attr>

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

<!-- ============== Transition ============== -->
Expand Down Expand Up @@ -1545,6 +1545,9 @@
<attr name="onNegativeCross" format="string" />
<attr name="onPositiveCross" format="string" />
<attr name="onCross" format="string" />
<attr name="viewTransitionOnNegativeCross" format="reference" />
<attr name="viewTransitionOnPositiveCross" format="reference" />
<attr name="viewTransitionOnCross" format="reference" />
<attr name="triggerSlack" format="float" />
<!-- The id of this trigger use when a callback listens for triggers -->
<attr name="triggerId" format="reference" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class VerificationActivity extends AppCompatActivity implements View.OnCl
String s = AppCompatActivity.class.getName();

private static boolean REVERSE = false;
private final String LAYOUTS_MATCHES = "verification_2\\d+";
private final String LAYOUTS_MATCHES = "verification_\\d+";
private static String SHOW_FIRST = "";
MotionLayout mMotionLayout;
private Flow mFlow;
Expand Down
Loading