Merge "DO NOT MERGE Overscroll continues; asset and behavior tweaks." into gingerbread

This commit is contained in:
Adam Powell
2010-09-02 00:28:14 -07:00
committed by Android (Google) Code Review
9 changed files with 85 additions and 39 deletions

View File

@@ -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;

View File

@@ -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);
@@ -5977,6 +5973,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);

View File

@@ -506,6 +506,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

View File

@@ -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;
}
}

View File

@@ -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();

View File

@@ -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)) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 KiB

After

Width:  |  Height:  |  Size: 36 KiB