summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2021-03-19 11:37:30 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-03-19 11:37:30 +0000
commit4beb695a825fde03af352180028fa28ef34da133 (patch)
treef3a943b251351c99576168b61580bdf071636910 /core/java
parent7c614b2e105a4f224da9aaf27596d8fa7a1b8ffd (diff)
parenta225d21f7d586d1484af38a55f8d949d076a4d5c (diff)
Merge "Updated EdgeEffect parameters for overscroll stretch" into sc-dev
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/widget/EdgeEffect.java50
-rw-r--r--core/java/android/widget/HorizontalScrollView.java20
-rw-r--r--core/java/android/widget/ScrollView.java20
3 files changed, 20 insertions, 70 deletions
diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java
index 3c411126627f..5f55887d6019 100644
--- a/core/java/android/widget/EdgeEffect.java
+++ b/core/java/android/widget/EdgeEffect.java
@@ -130,7 +130,11 @@ public class EdgeEffect {
public @interface EdgeEffectType {
}
- private static final float DEFAULT_MAX_STRETCH_INTENSITY = 0.08f;
+ private static final float LINEAR_STRETCH_INTENSITY = 0.03f;
+
+ private static final float EXP_STRETCH_INTENSITY = 0.02f;
+
+ private static final float SCROLL_DIST_AFFECTED_BY_EXP_STRETCH = 0.4f;
@SuppressWarnings("UnusedDeclaration")
private static final String TAG = "EdgeEffect";
@@ -176,9 +180,6 @@ public class EdgeEffect {
private long mStartTime;
private float mDuration;
- private float mStretchIntensity = DEFAULT_MAX_STRETCH_INTENSITY;
- private float mStretchDistanceFraction = 1f;
- private float mStretchDistance = -1f;
private final Interpolator mInterpolator = new DecelerateInterpolator();
@@ -269,16 +270,6 @@ public class EdgeEffect {
}
/**
- * Configure the distance in pixels to stretch the content. This is only consumed as part
- * if {@link #setType(int)} is set to {@link #TYPE_STRETCH}
- * @param stretchDistance Stretch distance in pixels when the target View is overscrolled
- * @hide
- */
- public void setStretchDistance(float stretchDistance) {
- mStretchDistance = stretchDistance;
- }
-
- /**
* Reports if this EdgeEffect's animation is finished. If this method returns false
* after a call to {@link #draw(Canvas)} the host widget should schedule another
* drawing pass to continue the animation.
@@ -520,13 +511,6 @@ public class EdgeEffect {
}
/**
- * @hide
- */
- public void setMaxStretchIntensity(float stretchIntensity) {
- mStretchIntensity = stretchIntensity;
- }
-
- /**
* Set or clear the blend mode. A blend mode defines how source pixels
* (generated by a drawing command) are composited with the destination pixels
* (content of the render target).
@@ -642,22 +626,19 @@ public class EdgeEffect {
// assume rotations of increments of 90 degrees
float x = mTmpPoints[10] - mTmpPoints[8];
float width = right - left;
- float vecX = Math.max(-1f, Math.min(1f, x / width));
+ float vecX = dampStretchVector(Math.max(-1f, Math.min(1f, x / width)));
float y = mTmpPoints[11] - mTmpPoints[9];
float height = bottom - top;
- float vecY = Math.max(-1f, Math.min(1f, y / height));
+ float vecY = dampStretchVector(Math.max(-1f, Math.min(1f, y / height)));
renderNode.stretch(
left,
top,
right,
bottom,
- vecX * mStretchIntensity,
- vecY * mStretchIntensity,
- // TODO (njawad/mount) figure out proper stretch distance from UX
- // for now leverage placeholder logic if no stretch distance is provided to
- // consume the displacement ratio times the minimum of the width or height
- mStretchDistance > 0 ? mStretchDistance :
- (mStretchDistanceFraction * Math.max(mWidth, mHeight))
+ vecX,
+ vecY,
+ mWidth,
+ mHeight
);
}
@@ -794,4 +775,13 @@ public class EdgeEffect {
return Math.abs(mVelocity) < VELOCITY_THRESHOLD
&& Math.abs(displacement) < VALUE_THRESHOLD;
}
+
+ private float dampStretchVector(float normalizedVec) {
+ float sign = normalizedVec > 0 ? 1f : -1f;
+ float overscroll = Math.abs(normalizedVec);
+ float linearIntensity = LINEAR_STRETCH_INTENSITY * overscroll;
+ double scalar = Math.E / SCROLL_DIST_AFFECTED_BY_EXP_STRETCH;
+ double expIntensity = EXP_STRETCH_INTENSITY * (1 - Math.exp(-overscroll * scalar));
+ return sign * (float) (linearIntensity + expIntensity);
+ }
}
diff --git a/core/java/android/widget/HorizontalScrollView.java b/core/java/android/widget/HorizontalScrollView.java
index bf552e2a501c..23915e06335a 100644
--- a/core/java/android/widget/HorizontalScrollView.java
+++ b/core/java/android/widget/HorizontalScrollView.java
@@ -249,26 +249,6 @@ public class HorizontalScrollView extends FrameLayout {
}
/**
- * API used for prototyping stretch effect parameters in framework sample apps
- * @hide
- */
- public void setEdgeEffectIntensity(float intensity) {
- mEdgeGlowLeft.setMaxStretchIntensity(intensity);
- mEdgeGlowRight.setMaxStretchIntensity(intensity);
- invalidate();
- }
-
- /**
- * API used for prototyping stretch effect parameters in the framework sample apps
- * @hide
- */
- public void setStretchDistance(float distance) {
- mEdgeGlowLeft.setStretchDistance(distance);
- mEdgeGlowRight.setStretchDistance(distance);
- invalidate();
- }
-
- /**
* Sets the right edge effect color.
*
* @param color The color for the right edge effect.
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index 30067296f967..65f3da79afe0 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -281,26 +281,6 @@ public class ScrollView extends FrameLayout {
}
/**
- * API used for prototyping stretch effect parameters in framework sample apps
- * @hide
- */
- public void setEdgeEffectIntensity(float intensity) {
- mEdgeGlowTop.setMaxStretchIntensity(intensity);
- mEdgeGlowBottom.setMaxStretchIntensity(intensity);
- invalidate();
- }
-
- /**
- * API used for prototyping stretch effect parameters in the framework sample apps
- * @hide
- */
- public void setStretchDistance(float distance) {
- mEdgeGlowTop.setStretchDistance(distance);
- mEdgeGlowBottom.setStretchDistance(distance);
- invalidate();
- }
-
- /**
* Sets the bottom edge effect color.
*
* @param color The color for the bottom edge effect.