This repository was archived by the owner on Dec 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +15
-9
lines changed
constraintlayout/src/main/java/androidx/constraintlayout
core/src/main/java/androidx/constraintlayout/core/motion/utils
projects/MotionLayoutVerification/app/src/main/res/xml Expand file tree Collapse file tree 4 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ class TouchResponse {
104
104
static final int FLAG_DISABLE_POST_SCROLL = 1 ;
105
105
static final int FLAG_DISABLE_SCROLL = 2 ;
106
106
private float mDragThreshold = 10 ;
107
- private float mSpringDamping = Float . NaN ;
107
+ private float mSpringDamping = 10 ;
108
108
private float mSpringMass = 1 ;
109
109
private float mSpringStiffness = Float .NaN ;
110
110
private float mSpringStopThreshold = Float .NaN ;
Original file line number Diff line number Diff line change 36
36
/**
37
37
* An ImageButton that can display, combine and filter images. <b>Added in 2.0</b>
38
38
* <p>
39
- * Subclass of AppCompatImageButton to handle rounding edges dynamically.
39
+ * Subclass of AppCompatButton to handle rounding edges dynamically.
40
40
* </p>
41
41
* <h2>MotionButton attributes</h2>
42
42
* <td>round</td>
Original file line number Diff line number Diff line change @@ -98,10 +98,17 @@ public boolean isStopped() {
98
98
99
99
private void compute (double dt ) {
100
100
double x = (mPos - mTargetPos );
101
- double a = getAcceleration ();
102
- double dv = a * dt ;
103
- double avgV = mV + dv / 2 ;
104
- mV += dv / 2 ;
101
+ double k = mStiffness ;
102
+ double c = mDamping ;
103
+ double a = (-k * x - c * mV ) / mMass ;
104
+ // This refinement of a simple coding of the acceleration increases accuracy
105
+ double avgV = mV + a * dt / 2 ; // pass 1 calculate the average velocity
106
+ double avgX = x + dt * (avgV ) / 2 - mTargetPos ;// pass 1 calculate the average pos
107
+ a = (-avgX * k - avgV * c ) / mMass ; // calculate acceleration over that average pos
108
+
109
+ double dv = a * dt ; // calculate change in velocity
110
+ avgV = mV + dv / 2 ; // average velocity is current + half change
111
+ mV += dv ;
105
112
mPos += avgV * dt ;
106
113
if (mBoundaryMode > 0 ) {
107
114
if (mPos < 0 && ((mBoundaryMode & 1 ) == 1 )) {
@@ -114,4 +121,5 @@ private void compute(double dt) {
114
121
}
115
122
}
116
123
}
124
+
117
125
}
Original file line number Diff line number Diff line change 10
10
<OnSwipe
11
11
motion : touchAnchorId =" @+id/clock"
12
12
motion : dragDirection =" dragLeft"
13
- motion : springDamping =" 10"
14
13
motion : onTouchUp =" neverCompleteToEnd"
15
- motion : springMass =" 1"
16
14
motion : springBoundary =" overshoot"
17
15
motion : springStiffness =" 500" />
18
16
<KeyFrameSet ></KeyFrameSet >
27
25
<OnSwipe
28
26
motion : touchAnchorId =" @+id/clock"
29
27
motion : dragDirection =" dragRight"
30
- motion : springDamping =" 10 "
28
+ motion : springDamping =" 0.2 "
31
29
motion : springMass =" 1"
32
30
motion : springBoundary =" overshoot"
33
31
motion : onTouchUp =" neverCompleteToEnd"
You can’t perform that action at this time.
0 commit comments