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

Commit 6c69d5f

Browse files
authored
View transition support (#29)
* viewTransition * more working now * feature complete * ViewTransition1.0 * add Tag switches * formatting and cleanup
1 parent bbd827e commit 6c69d5f

35 files changed

+3055
-163
lines changed

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
package androidx.constraintlayout.motion.widget;
1818

1919
import android.content.Context;
20+
2021
import androidx.constraintlayout.widget.ConstraintAttribute;
2122
import androidx.constraintlayout.motion.utils.CurveFit;
23+
2224
import android.util.AttributeSet;
2325

2426
import java.util.HashMap;
2527
import java.util.HashSet;
2628

2729
/**
28-
* Base class in an element in a KeyFrame
29-
* @hide
30+
* Base class in an element in a KeyFrame
31+
*
32+
* @hide
3033
*/
3134

3235
public abstract class Key {
@@ -35,9 +38,13 @@ public abstract class Key {
3538
int mTargetId = UNSET;
3639
String mTargetString = null;
3740
protected int mType;
41+
3842
abstract void load(Context context, AttributeSet attrs);
43+
3944
HashMap<String, ConstraintAttribute> mCustomConstraints;
45+
4046
abstract void getAttributeNames(HashSet<String> attributes);
47+
4148
static final String ALPHA = "alpha";
4249
static final String ELEVATION = "elevation";
4350
static final String ROTATION = "rotation";
@@ -62,47 +69,53 @@ boolean matches(String constraintTag) {
6269
if (mTargetString == null || constraintTag == null) return false;
6370
return constraintTag.matches(mTargetString);
6471
}
72+
6573
/**
6674
* Defines method to add a a view to splines derived form this key frame.
6775
* The values are written to the spline
68-
* @hide
76+
*
6977
* @param splines splines to write values to
78+
* @hide
7079
*/
7180
public abstract void addValues(HashMap<String, SplineSet> splines);
7281

7382
/**
7483
* Set the value associated with this tag
75-
* @hide
84+
*
7685
* @param tag
7786
* @param value
87+
* @hide
7888
*/
7989
public abstract void setValue(String tag, Object value);
8090

8191
/**
8292
* Return the float given a value. If the value is a "Float" object it is casted
83-
* @hide
93+
*
8494
* @param value
8595
* @return
96+
* @hide
8697
*/
8798
float toFloat(Object value) {
8899
return (value instanceof Float) ? (Float) value : Float.parseFloat(value.toString());
89100
}
90101

91102
/**
92103
* Return the int version of an object if the value is an Integer object it is casted.
93-
* @hide
104+
*
94105
* @param value
95106
* @return
107+
* @hide
96108
*/
97109
int toInt(Object value) {
98110
return (value instanceof Integer) ? (Integer) value : Integer.parseInt(value.toString());
99111
}
100112

101113
/**
102114
* Return the boolean version this object if the object is a Boolean it is casted.
103-
* @hide
115+
*
104116
* @param value
105117
* @return
118+
* @hide
106119
*/
107120
boolean toBoolean(Object value) {
108121
return (value instanceof Boolean) ? (Boolean) value : Boolean.parseBoolean(value.toString());
@@ -111,8 +124,25 @@ boolean toBoolean(Object value) {
111124
/**
112125
* Key frame can speify the type of interpolation it wants on various attributes
113126
* For each string it set it to -1, CurveFit.LINEAR or CurveFit.SPLINE
127+
*
114128
* @param interpolation
115129
*/
116130
public void setInterpolation(HashMap<String, Integer> interpolation) {
117131
}
132+
133+
public Key copy(Key src) {
134+
mFramePosition = src.mFramePosition;
135+
mTargetId = src.mTargetId;
136+
mTargetString = src.mTargetString;
137+
mType = src.mType;
138+
mCustomConstraints = src.mCustomConstraints;
139+
return this;
140+
}
141+
142+
abstract public Key clone();
143+
144+
public Key setViewId(int id) {
145+
mTargetId = id;
146+
return this;
147+
}
118148
}

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import android.content.Context;
2020
import android.content.res.TypedArray;
2121
import android.os.Build;
22+
2223
import androidx.constraintlayout.widget.ConstraintAttribute;
2324
import androidx.constraintlayout.widget.R;
25+
2426
import android.util.AttributeSet;
2527
import android.util.Log;
2628
import android.util.SparseIntArray;
@@ -32,6 +34,7 @@
3234
/**
3335
* Defines container for a key frame of for storing KeyAttributes.
3436
* KeyAttributes change post layout values of a view.
37+
*
3538
* @hide
3639
*/
3740

@@ -231,7 +234,7 @@ public void addValues(HashMap<String, SplineSet> splines) {
231234
splineSet.setPoint(mFramePosition, mPivotY);
232235
}
233236
break;
234-
case Key.TRANSITION_PATH_ROTATE:
237+
case Key.TRANSITION_PATH_ROTATE:
235238
if (!Float.isNaN(mTransitionPathRotate)) {
236239
splineSet.setPoint(mFramePosition, mTransitionPathRotate);
237240
}
@@ -451,4 +454,30 @@ public static void read(KeyAttributes c, TypedArray a) {
451454
}
452455
}
453456
}
457+
458+
public Key copy(Key src) {
459+
super.copy(src);
460+
KeyAttributes k = (KeyAttributes) src;
461+
mCurveFit = k.mCurveFit;
462+
mVisibility = k.mVisibility;
463+
mAlpha = k.mAlpha;
464+
mElevation = k.mElevation;
465+
mRotation = k.mRotation;
466+
mRotationX = k.mRotationX;
467+
mRotationY = k.mRotationY;
468+
mPivotX = k.mPivotX;
469+
mPivotY = k.mPivotY;
470+
mTransitionPathRotate = k.mTransitionPathRotate;
471+
mScaleX = k.mScaleX;
472+
mScaleY = k.mScaleY;
473+
mTranslationX = k.mTranslationX;
474+
mTranslationY = k.mTranslationY;
475+
mTranslationZ = k.mTranslationZ;
476+
mProgress = k.mProgress;
477+
return this;
478+
}
479+
480+
public Key clone() {
481+
return new KeyAttributes().copy(this);
482+
}
454483
}

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

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import androidx.constraintlayout.motion.utils.Oscillator;
2323
import androidx.constraintlayout.widget.ConstraintAttribute;
2424
import androidx.constraintlayout.widget.R;
25+
2526
import android.util.AttributeSet;
2627
import android.util.Log;
2728
import android.util.SparseIntArray;
2829
import android.util.TypedValue;
2930

30-
import java.util.Arrays;
3131
import java.util.HashMap;
3232
import java.util.HashSet;
3333

@@ -119,13 +119,13 @@ public void addCycleValues(HashMap<String, KeyCycleOscillator> oscSet) {
119119
String ckey = key.substring(Key.CUSTOM.length() + 1);
120120
ConstraintAttribute cvalue = mCustomConstraints.get(ckey);
121121
if (cvalue != null && cvalue.getType() == ConstraintAttribute.AttributeType.FLOAT_TYPE) {
122-
oscSet.get(key).setPoint(mFramePosition, mWaveShape,mCustomWaveShpe, mWaveVariesBy, mWavePeriod, mWaveOffset, mWavePhase, cvalue.getValueToInterpolate(), cvalue);
122+
oscSet.get(key).setPoint(mFramePosition, mWaveShape, mCustomWaveShpe, mWaveVariesBy, mWavePeriod, mWaveOffset, mWavePhase, cvalue.getValueToInterpolate(), cvalue);
123123
}
124124
continue;
125125
}
126126
float value = getValue(key);
127127
if (!Float.isNaN(value)) {
128-
oscSet.get(key).setPoint(mFramePosition, mWaveShape,mCustomWaveShpe, mWaveVariesBy, mWavePeriod, mWaveOffset, mWavePhase, value);
128+
oscSet.get(key).setPoint(mFramePosition, mWaveShape, mCustomWaveShpe, mWaveVariesBy, mWavePeriod, mWaveOffset, mWavePhase, value);
129129
}
130130
}
131131
}
@@ -361,7 +361,7 @@ private static void read(KeyCycle c, TypedArray a) {
361361
c.mProgress = a.getFloat(attr, c.mProgress);
362362
break;
363363
case WAVE_PHASE:
364-
c.mWavePhase = a.getFloat(attr, c.mWavePhase)/360;
364+
c.mWavePhase = a.getFloat(attr, c.mWavePhase) / 360;
365365
break;
366366
default:
367367
Log.e(TAG, "unused attribute 0x" + Integer.toHexString(attr) + " " + mAttrMap.get(attr));
@@ -424,4 +424,34 @@ public void setValue(String tag, Object value) {
424424
break;
425425
}
426426
}
427+
428+
public Key copy(Key src) {
429+
super.copy(src);
430+
KeyCycle k = (KeyCycle) src;
431+
mTransitionEasing = k.mTransitionEasing;
432+
mCurveFit = k.mCurveFit;
433+
mWaveShape = k.mWaveShape;
434+
mCustomWaveShpe = k.mCustomWaveShpe;
435+
mWavePeriod = k.mWavePeriod;
436+
mWaveOffset = k.mWaveOffset;
437+
mWavePhase = k.mWavePhase;
438+
mProgress = k.mProgress;
439+
mWaveVariesBy = k.mWaveVariesBy;
440+
mAlpha = k.mAlpha;
441+
mElevation = k.mElevation;
442+
mRotation = k.mRotation;
443+
mTransitionPathRotate = k.mTransitionPathRotate;
444+
mRotationX = k.mRotationX;
445+
mRotationY = k.mRotationY;
446+
mScaleX = k.mScaleX;
447+
mScaleY = k.mScaleY;
448+
mTranslationX = k.mTranslationX;
449+
mTranslationY = k.mTranslationY;
450+
mTranslationZ = k.mTranslationZ;
451+
return this;
452+
}
453+
454+
public Key clone() {
455+
return new KeyCycle().copy(this);
456+
}
427457
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ public class KeyFrames {
5858
}
5959
}
6060

61-
private void addKey(Key key) {
61+
public void addKey(Key key) {
6262
if (!mFramesMap.containsKey(key.mTargetId)) {
6363
mFramesMap.put(key.mTargetId, new ArrayList<>());
6464
}
6565
mFramesMap.get(key.mTargetId).add(key);
6666
}
67+
public KeyFrames() {
6768

69+
}
6870
public KeyFrames(Context context, XmlPullParser parser) {
6971
String tagName = null;
7072
try {
@@ -112,6 +114,17 @@ public KeyFrames(Context context, XmlPullParser parser) {
112114
}
113115
}
114116

117+
/**
118+
* Do not filter the set by matches
119+
* @param motionController
120+
*/
121+
public void addAllFrames(MotionController motionController) {
122+
ArrayList<Key> list = mFramesMap.get(UNSET);
123+
if (list != null) {
124+
motionController.addKeys(list);
125+
}
126+
}
127+
115128
public void addFrames(MotionController motionController) {
116129
ArrayList<Key> list = mFramesMap.get(motionController.mId);
117130
if (list != null) {

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import android.content.Context;
2020
import android.content.res.TypedArray;
2121
import android.graphics.RectF;
22+
2223
import androidx.constraintlayout.widget.R;
2324
import androidx.constraintlayout.motion.utils.Easing;
25+
2426
import android.util.AttributeSet;
2527
import android.util.Log;
2628
import android.util.SparseIntArray;
@@ -368,4 +370,25 @@ public void setValue(String tag, Object value) {
368370

369371
}
370372
}
373+
374+
public Key copy(Key src) {
375+
super.copy(src);
376+
KeyPosition k = (KeyPosition) src;
377+
mTransitionEasing = k.mTransitionEasing;
378+
mPathMotionArc = k.mPathMotionArc;
379+
mDrawPath = k.mDrawPath;
380+
mPercentWidth = k.mPercentWidth;
381+
mPercentHeight = Float.NaN;
382+
mPercentX = k.mPercentX;
383+
mPercentY = k.mPercentY;
384+
mAltPercentX = k.mAltPercentX;
385+
mAltPercentY = k.mAltPercentY;
386+
mCalculatedPositionX = k.mCalculatedPositionX;
387+
mCalculatedPositionY = k.mCalculatedPositionY;
388+
return this;
389+
}
390+
391+
public Key clone() {
392+
return new KeyPosition().copy(this);
393+
}
371394
}

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
import android.content.Context;
1919
import android.content.res.TypedArray;
2020
import android.os.Build;
21+
2122
import androidx.constraintlayout.widget.ConstraintAttribute;
2223
import androidx.constraintlayout.widget.R;
23-
import androidx.constraintlayout.motion.utils.CurveFit;
24+
2425
import android.util.AttributeSet;
2526
import android.util.Log;
2627
import android.util.SparseIntArray;
@@ -70,7 +71,6 @@ public void load(Context context, AttributeSet attrs) {
7071

7172
/**
7273
* Gets the curve fit type this drives the interpolation
73-
*
7474
*/
7575

7676
@Override
@@ -165,7 +165,6 @@ public void setInterpolation(HashMap<String, Integer> interpolation) {
165165
}
166166
}
167167

168-
169168
@Override
170169
public void addValues(HashMap<String, SplineSet> splines) {
171170
// This should not get called
@@ -429,4 +428,31 @@ public static void read(KeyTimeCycle c, TypedArray a) {
429428
}
430429
}
431430
}
431+
432+
public Key copy(Key src) {
433+
super.copy(src);
434+
KeyTimeCycle k = (KeyTimeCycle) src;
435+
mTransitionEasing = k.mTransitionEasing;
436+
mCurveFit = k.mCurveFit;
437+
mWaveShape = k.mWaveShape;
438+
mWavePeriod = k.mWavePeriod;
439+
mWaveOffset = k.mWaveOffset;
440+
mProgress = k.mProgress;
441+
mAlpha = k.mAlpha;
442+
mElevation = k.mElevation;
443+
mRotation = k.mRotation;
444+
mTransitionPathRotate = k.mTransitionPathRotate;
445+
mRotationX = k.mRotationX;
446+
mRotationY = k.mRotationY;
447+
mScaleX = k.mScaleX;
448+
mScaleY = k.mScaleY;
449+
mTranslationX = k.mTranslationX;
450+
mTranslationY = k.mTranslationY;
451+
mTranslationZ = k.mTranslationZ;
452+
return this;
453+
}
454+
455+
public Key clone() {
456+
return new KeyTimeCycle().copy(this);
457+
}
432458
}

0 commit comments

Comments
 (0)