Skip to content

Commit

Permalink
small changing to spring (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
jafu888 committed Apr 5, 2021
1 parent 4c88f4d commit 7d8eae1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class TouchResponse {
static final int FLAG_DISABLE_POST_SCROLL = 1;
static final int FLAG_DISABLE_SCROLL = 2;
private float mDragThreshold = 10;
private float mSpringDamping = Float.NaN;
private float mSpringDamping = 10;
private float mSpringMass = 1;
private float mSpringStiffness = Float.NaN;
private float mSpringStopThreshold = Float.NaN;
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 rounding edges dynamically.
* Subclass of AppCompatButton 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 @@ -98,10 +98,17 @@ public boolean isStopped() {

private void compute(double dt) {
double x = (mPos - mTargetPos);
double a = getAcceleration();
double dv = a * dt;
double avgV = mV + dv / 2;
mV += dv / 2;
double k = mStiffness;
double c = mDamping;
double a = (-k * x - c * mV) / mMass;
// This refinement of a simple coding of the acceleration increases accuracy
double avgV = mV + a * dt / 2; // pass 1 calculate the average velocity
double avgX = x + dt * (avgV) / 2 - mTargetPos;// pass 1 calculate the average pos
a = (-avgX * k - avgV * c) / mMass; // calculate acceleration over that average pos

double dv = a * dt; // calculate change in velocity
avgV = mV + dv / 2; // average velocity is current + half change
mV += dv;
mPos += avgV * dt;
if (mBoundaryMode > 0) {
if (mPos < 0 && ((mBoundaryMode & 1) == 1)) {
Expand All @@ -114,4 +121,5 @@ private void compute(double dt) {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
<OnSwipe
motion:touchAnchorId="@+id/clock"
motion:dragDirection="dragLeft"
motion:springDamping="10"
motion:onTouchUp="neverCompleteToEnd"
motion:springMass="1"
motion:springBoundary="overshoot"
motion:springStiffness="500" />
<KeyFrameSet></KeyFrameSet>
Expand All @@ -27,7 +25,7 @@
<OnSwipe
motion:touchAnchorId="@+id/clock"
motion:dragDirection="dragRight"
motion:springDamping="10"
motion:springDamping="0.2"
motion:springMass="1"
motion:springBoundary="overshoot"
motion:onTouchUp="neverCompleteToEnd"
Expand Down

0 comments on commit 7d8eae1

Please sign in to comment.