diff options
author | Adam Powell <adamp@google.com> | 2010-09-02 00:31:03 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-09-02 00:31:03 -0700 |
commit | 0358def77633b6548da06985cb22955a7e85abac (patch) | |
tree | 9ba1ed8127507db4cea9c8489cf868c080494a3a /core | |
parent | 75823339cd03e5b25b576cd7a2b5941254017c4a (diff) | |
parent | 79492a0d75b0b02f11f35500f79dd3fcbc6e2211 (diff) | |
download | frameworks_base-0358def77633b6548da06985cb22955a7e85abac.zip frameworks_base-0358def77633b6548da06985cb22955a7e85abac.tar.gz frameworks_base-0358def77633b6548da06985cb22955a7e85abac.tar.bz2 |
am 79492a0d: Merge "DO NOT MERGE Overscroll continues; asset and behavior tweaks." into gingerbread
Merge commit '79492a0d75b0b02f11f35500f79dd3fcbc6e2211' into gingerbread-plus-aosp
* commit '79492a0d75b0b02f11f35500f79dd3fcbc6e2211':
DO NOT MERGE Overscroll continues; asset and behavior tweaks.
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/view/ViewConfiguration.java | 4 | ||||
-rw-r--r-- | core/java/android/webkit/WebView.java | 38 | ||||
-rw-r--r-- | core/java/android/widget/AbsListView.java | 42 | ||||
-rw-r--r-- | core/java/android/widget/EdgeGlow.java | 28 | ||||
-rw-r--r-- | core/java/android/widget/HorizontalScrollView.java | 6 | ||||
-rw-r--r-- | core/java/android/widget/ScrollView.java | 6 | ||||
-rw-r--r-- | core/res/res/drawable/edge_light.png | bin | 32307 -> 0 bytes | |||
-rw-r--r-- | core/res/res/drawable/overscroll_edge.png | bin | 0 -> 2614 bytes | |||
-rw-r--r-- | core/res/res/drawable/overscroll_glow.png | bin | 183232 -> 36442 bytes |
9 files changed, 85 insertions, 39 deletions
diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index aa9fe76..4d2ba71 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -143,12 +143,12 @@ public class ViewConfiguration { /** * Max distance to overscroll for edge effects */ - private static final int OVERSCROLL_DISTANCE = 4; + private static final int OVERSCROLL_DISTANCE = 2; /** * Max distance to overfling for edge effects */ - private static final int OVERFLING_DISTANCE = 8; + private static final int OVERFLING_DISTANCE = 4; private final int mEdgeSlop; private final int mFadingEdgeLength; diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index c9bd48b..bf528e0 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -1041,7 +1041,7 @@ public class WebView extends AbsoluteLayout if (mode != OVERSCROLL_NEVER) { if (mEdgeGlowTop == null) { final Resources res = getContext().getResources(); - final Drawable edge = res.getDrawable(R.drawable.edge_light); + final Drawable edge = res.getDrawable(R.drawable.overscroll_edge); final Drawable glow = res.getDrawable(R.drawable.overscroll_glow); mEdgeGlowTop = new EdgeGlow(edge, glow); mEdgeGlowBottom = new EdgeGlow(edge, glow); @@ -2567,11 +2567,6 @@ public class WebView extends AbsoluteLayout mInOverScrollMode = true; } - if ((clampedX && maxX > 0) || clampedY) { - // Hitting a scroll barrier breaks velocity; don't fling further. - mVelocityTracker.clear(); - mLastVelocity = 0; - } super.scrollTo(scrollX, scrollY); } @@ -3469,8 +3464,8 @@ public class WebView extends AbsoluteLayout } @Override - protected void dispatchDraw(Canvas canvas) { - super.dispatchDraw(canvas); + public void draw(Canvas canvas) { + super.draw(canvas); if (mEdgeGlowTop != null && drawEdgeGlows(canvas)) { invalidate(); } @@ -3492,7 +3487,7 @@ public class WebView extends AbsoluteLayout if (!mEdgeGlowTop.isFinished()) { final int restoreCount = canvas.save(); - canvas.translate(-width / 2 + scrollX, scrollY); + canvas.translate(-width / 2 + scrollX, Math.min(0, scrollY)); mEdgeGlowTop.setSize(width * 2, height); invalidateForGlow |= mEdgeGlowTop.draw(canvas); canvas.restoreToCount(restoreCount); @@ -3500,7 +3495,7 @@ public class WebView extends AbsoluteLayout if (!mEdgeGlowBottom.isFinished()) { final int restoreCount = canvas.save(); - canvas.translate(-width / 2 - scrollX, scrollY + height); + canvas.translate(-width / 2 + scrollX, Math.max(computeMaxScrollY(), scrollY) + height); canvas.rotate(180, width, 0); mEdgeGlowBottom.setSize(width * 2, height); invalidateForGlow |= mEdgeGlowBottom.draw(canvas); @@ -3510,7 +3505,7 @@ public class WebView extends AbsoluteLayout final int restoreCount = canvas.save(); canvas.rotate(270); - canvas.translate(-height * 1.5f - scrollY, scrollX); + canvas.translate(-height * 1.5f - scrollY, Math.min(0, scrollX)); mEdgeGlowLeft.setSize(height * 2, width); invalidateForGlow |= mEdgeGlowLeft.draw(canvas); canvas.restoreToCount(restoreCount); @@ -3519,7 +3514,8 @@ public class WebView extends AbsoluteLayout final int restoreCount = canvas.save(); canvas.rotate(90); - canvas.translate(-height / 2 + scrollY, -scrollX - width); + canvas.translate(-height / 2 + scrollY, + -(Math.max(computeMaxScrollX(), scrollX) + width)); mEdgeGlowRight.setSize(height * 2, width); invalidateForGlow |= mEdgeGlowRight.draw(canvas); canvas.restoreToCount(restoreCount); @@ -5987,6 +5983,24 @@ public class WebView extends AbsoluteLayout + " maxX=" + maxX + " maxY=" + maxY + " mScrollX=" + mScrollX + " mScrollY=" + mScrollY); } + + // Allow sloppy flings without overscrolling at the edges. + if ((mScrollX == 0 || mScrollX == maxX) && Math.abs(vx) < Math.abs(vy)) { + vx = 0; + } + if ((mScrollY == 0 || mScrollY == maxY) && Math.abs(vy) < Math.abs(vx)) { + vy = 0; + } + + if (mOverscrollDistance < mOverflingDistance) { + if (mScrollX == -mOverscrollDistance || mScrollX == maxX + mOverscrollDistance) { + vx = 0; + } + if (mScrollY == -mOverscrollDistance || mScrollY == maxY + mOverscrollDistance) { + vy = 0; + } + } + mLastVelX = vx; mLastVelY = vy; mLastVelocity = (float) Math.hypot(vx, vy); diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index db50ca1..fe2a43b 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -507,6 +507,20 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te private EdgeGlow mEdgeGlowBottom; /** + * An estimate of how many pixels are between the top of the list and + * the top of the first position in the adapter, based on the last time + * we saw it. Used to hint where to draw edge glows. + */ + private int mFirstPositionDistanceGuess; + + /** + * An estimate of how many pixels are between the bottom of the list and + * the bottom of the last position in the adapter, based on the last time + * we saw it. Used to hint where to draw edge glows. + */ + private int mLastPositionDistanceGuess; + + /** * Interface definition for a callback to be invoked when the list or grid * has been scrolled. */ @@ -632,7 +646,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te if (mode != OVERSCROLL_NEVER) { if (mEdgeGlowTop == null) { final Resources res = getContext().getResources(); - final Drawable edge = res.getDrawable(R.drawable.edge_light); + final Drawable edge = res.getDrawable(R.drawable.overscroll_edge); final Drawable glow = res.getDrawable(R.drawable.overscroll_glow); mEdgeGlowTop = new EdgeGlow(edge, glow); mEdgeGlowBottom = new EdgeGlow(edge, glow); @@ -1684,6 +1698,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te mFlingRunnable.endFling(); if (mScrollY != 0) { mScrollY = 0; + finishGlows(); invalidate(); } } @@ -2041,6 +2056,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te if (mScrollY != 0) { mScrollY = 0; + finishGlows(); invalidate(); } } @@ -2518,7 +2534,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te final int restoreCount = canvas.save(); final int width = getWidth(); - canvas.translate(-width / 2, scrollY); + canvas.translate(-width / 2, Math.min(0, scrollY + mFirstPositionDistanceGuess)); mEdgeGlowTop.setSize(width * 2, getHeight()); if (mEdgeGlowTop.draw(canvas)) { invalidate(); @@ -2530,7 +2546,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te final int width = getWidth(); final int height = getHeight(); - canvas.translate(-width / 2, scrollY + height); + canvas.translate(-width / 2, + Math.max(height, scrollY + mLastPositionDistanceGuess)); canvas.rotate(180, width, 0); mEdgeGlowBottom.setSize(width * 2, height); if (mEdgeGlowBottom.draw(canvas)) { @@ -3223,6 +3240,18 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te final int firstPosition = mFirstPosition; + // Update our guesses for where the first and last views are + if (firstPosition == 0) { + mFirstPositionDistanceGuess = firstTop - mListPadding.top; + } else { + mFirstPositionDistanceGuess += incrementalDeltaY; + } + if (firstPosition + childCount == mItemCount) { + mLastPositionDistanceGuess = lastBottom + mListPadding.bottom; + } else { + mLastPositionDistanceGuess += incrementalDeltaY; + } + if (firstPosition == 0 && firstTop >= listPadding.top && incrementalDeltaY >= 0) { // Don't need to move views down if the top of the first position // is already visible @@ -4167,6 +4196,13 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te return result; } + private void finishGlows() { + if (mEdgeGlowTop != null) { + mEdgeGlowTop.finish(); + mEdgeGlowBottom.finish(); + } + } + /** * Sets the recycler listener to be notified whenever a View is set aside in * the recycler for later reuse. This listener can be used to free resources diff --git a/core/java/android/widget/EdgeGlow.java b/core/java/android/widget/EdgeGlow.java index 06334a0..93222e1 100644 --- a/core/java/android/widget/EdgeGlow.java +++ b/core/java/android/widget/EdgeGlow.java @@ -18,7 +18,6 @@ package android.widget; import android.graphics.Canvas; import android.graphics.drawable.Drawable; -import android.util.Log; import android.view.animation.AnimationUtils; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; @@ -30,8 +29,6 @@ import android.view.animation.Interpolator; public class EdgeGlow { private static final String TAG = "EdgeGlow"; - private static final boolean DEBUG = false; - // Time it will take the effect to fully recede in ms private static final int RECEDE_TIME = 1000; @@ -46,7 +43,10 @@ public class EdgeGlow { private static final float HELD_GLOW_ALPHA = 0.5f; private static final float HELD_GLOW_SCALE_Y = 0.5f; + private static final float MAX_GLOW_HEIGHT = 0.33f; + private static final float PULL_GLOW_BEGIN = 0.5f; + private static final float PULL_EDGE_BEGIN = 0.6f; // Minimum velocity that will be absorbed private static final int MIN_VELOCITY = 750; @@ -103,6 +103,10 @@ public class EdgeGlow { return mState == STATE_IDLE; } + public void finish() { + mState = STATE_IDLE; + } + /** * Call when the object is pulled by the user. * @param deltaDistance Change in distance since the last call @@ -123,7 +127,7 @@ public class EdgeGlow { mPullDistance += deltaDistance; float distance = Math.abs(mPullDistance); - mEdgeAlpha = mEdgeAlphaStart = Math.max(HELD_EDGE_ALPHA, Math.min(distance, 1.f)); + mEdgeAlpha = mEdgeAlphaStart = Math.max(PULL_EDGE_BEGIN, Math.min(distance, 1.f)); mEdgeScaleY = mEdgeScaleYStart = Math.max(HELD_EDGE_SCALE_Y, Math.min(distance, 2.f)); mGlowAlpha = mGlowAlphaStart = Math.max(0.5f, @@ -142,8 +146,6 @@ public class EdgeGlow { mEdgeScaleYFinish = mEdgeScaleY; mGlowAlphaFinish = mGlowAlpha; mGlowScaleYFinish = mGlowScaleY; - - if (DEBUG) Log.d(TAG, "onPull(" + distance + ", " + deltaDistance + ")"); } /** @@ -155,7 +157,6 @@ public class EdgeGlow { if (mState != STATE_PULL && mState != STATE_PULL_DECAY) { return; } - if (DEBUG) Log.d(TAG, "onRelease"); mState = STATE_RECEDE; mEdgeAlphaStart = mEdgeAlpha; @@ -178,7 +179,6 @@ public class EdgeGlow { */ public void onAbsorb(int velocity) { mState = STATE_ABSORB; - if (DEBUG) Log.d(TAG, "onAbsorb uncooked velocity: " + velocity); velocity = Math.max(MIN_VELOCITY, Math.abs(velocity)); mStartTime = AnimationUtils.currentAnimationTimeMillis(); @@ -193,8 +193,6 @@ public class EdgeGlow { mEdgeScaleYFinish = 1.f; mGlowAlphaFinish = 1.f; mGlowScaleYFinish = Math.min(velocity * 0.001f, 1); - - if (DEBUG) Log.d(TAG, "onAbsorb(" + velocity + "): duration " + mDuration); } /** @@ -212,8 +210,11 @@ public class EdgeGlow { final int edgeHeight = mEdge.getIntrinsicHeight(); final int glowHeight = mGlow.getIntrinsicHeight(); + final float distScale = (float) mHeight / mWidth; + mGlow.setAlpha((int) (Math.max(0, Math.min(mGlowAlpha, 1)) * 255)); - mGlow.setBounds(0, 0, mWidth, (int) (glowHeight * mGlowScaleY * 0.5f)); + mGlow.setBounds(0, 0, mWidth, (int) Math.min(glowHeight * mGlowScaleY * distScale * 0.6f, + mHeight * MAX_GLOW_HEIGHT)); mGlow.draw(canvas); mEdge.setAlpha((int) (Math.max(0, Math.min(mEdgeAlpha, 1)) * 255)); @@ -222,8 +223,6 @@ public class EdgeGlow { mWidth, (int) (edgeHeight * mEdgeScaleY)); mEdge.draw(canvas); - if (DEBUG) Log.d(TAG, "draw() glow(" + mGlowAlpha + ", " + mGlowScaleY + ") edge(" + mEdgeAlpha + - ", " + mEdgeScaleY + ")"); return mState != STATE_IDLE; } @@ -255,7 +254,6 @@ public class EdgeGlow { mEdgeScaleYFinish = 0.1f; mGlowAlphaFinish = 0.f; mGlowScaleYFinish = mGlowScaleY; - if (DEBUG) Log.d(TAG, "STATE_ABSORB => STATE_RECEDE"); break; case STATE_PULL: mState = STATE_PULL_DECAY; @@ -271,14 +269,12 @@ public class EdgeGlow { mEdgeScaleYFinish = Math.min(mEdgeScaleYStart, HELD_EDGE_SCALE_Y); mGlowAlphaFinish = Math.min(mGlowAlphaStart, HELD_GLOW_ALPHA); mGlowScaleYFinish = Math.min(mGlowScaleY, HELD_GLOW_SCALE_Y); - if (DEBUG) Log.d(TAG, "STATE_PULL => STATE_PULL_DECAY"); break; case STATE_PULL_DECAY: // Do nothing; wait for release break; case STATE_RECEDE: mState = STATE_IDLE; - if (DEBUG) Log.d(TAG, "STATE_RECEDE => STATE_IDLE"); break; } } diff --git a/core/java/android/widget/HorizontalScrollView.java b/core/java/android/widget/HorizontalScrollView.java index 3493f49..129ad8a 100644 --- a/core/java/android/widget/HorizontalScrollView.java +++ b/core/java/android/widget/HorizontalScrollView.java @@ -1374,7 +1374,7 @@ public class HorizontalScrollView extends FrameLayout { if (mode != OVERSCROLL_NEVER) { if (mEdgeGlowLeft == null) { final Resources res = getContext().getResources(); - final Drawable edge = res.getDrawable(R.drawable.edge_light); + final Drawable edge = res.getDrawable(R.drawable.overscroll_edge); final Drawable glow = res.getDrawable(R.drawable.overscroll_glow); mEdgeGlowLeft = new EdgeGlow(edge, glow); mEdgeGlowRight = new EdgeGlow(edge, glow); @@ -1396,7 +1396,7 @@ public class HorizontalScrollView extends FrameLayout { final int height = getHeight(); canvas.rotate(270); - canvas.translate(-height * 1.5f, scrollX); + canvas.translate(-height * 1.5f, Math.min(0, scrollX)); mEdgeGlowLeft.setSize(getHeight() * 2, getWidth()); if (mEdgeGlowLeft.draw(canvas)) { invalidate(); @@ -1409,7 +1409,7 @@ public class HorizontalScrollView extends FrameLayout { final int height = getHeight(); canvas.rotate(90); - canvas.translate(-height / 2, -scrollX - width); + canvas.translate(-height / 2, -(Math.max(getScrollRange(), scrollX) + width)); mEdgeGlowRight.setSize(height * 2, width); if (mEdgeGlowRight.draw(canvas)) { invalidate(); diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java index 9d971f6..7b5e412 100644 --- a/core/java/android/widget/ScrollView.java +++ b/core/java/android/widget/ScrollView.java @@ -1374,7 +1374,7 @@ public class ScrollView extends FrameLayout { if (mode != OVERSCROLL_NEVER) { if (mEdgeGlowTop == null) { final Resources res = getContext().getResources(); - final Drawable edge = res.getDrawable(R.drawable.edge_light); + final Drawable edge = res.getDrawable(R.drawable.overscroll_edge); final Drawable glow = res.getDrawable(R.drawable.overscroll_glow); mEdgeGlowTop = new EdgeGlow(edge, glow); mEdgeGlowBottom = new EdgeGlow(edge, glow); @@ -1395,7 +1395,7 @@ public class ScrollView extends FrameLayout { final int restoreCount = canvas.save(); final int width = getWidth(); - canvas.translate(-width / 2, scrollY); + canvas.translate(-width / 2, Math.min(0, scrollY)); mEdgeGlowTop.setSize(width * 2, getHeight()); if (mEdgeGlowTop.draw(canvas)) { invalidate(); @@ -1407,7 +1407,7 @@ public class ScrollView extends FrameLayout { final int width = getWidth(); final int height = getHeight(); - canvas.translate(-width / 2, scrollY + height); + canvas.translate(-width / 2, Math.max(getScrollRange(), scrollY) + height); canvas.rotate(180, width, 0); mEdgeGlowBottom.setSize(width * 2, height); if (mEdgeGlowBottom.draw(canvas)) { diff --git a/core/res/res/drawable/edge_light.png b/core/res/res/drawable/edge_light.png Binary files differdeleted file mode 100644 index b026880..0000000 --- a/core/res/res/drawable/edge_light.png +++ /dev/null diff --git a/core/res/res/drawable/overscroll_edge.png b/core/res/res/drawable/overscroll_edge.png Binary files differnew file mode 100644 index 0000000..250c827 --- /dev/null +++ b/core/res/res/drawable/overscroll_edge.png diff --git a/core/res/res/drawable/overscroll_glow.png b/core/res/res/drawable/overscroll_glow.png Binary files differindex 7f1831e..69b456d 100644 --- a/core/res/res/drawable/overscroll_glow.png +++ b/core/res/res/drawable/overscroll_glow.png |