summaryrefslogtreecommitdiff
path: root/core/java/android/widget
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2010-09-01 17:47:16 -0700
committerAdam Powell <adamp@google.com>2010-09-02 00:14:53 -0700
commit5916882c3f13429d29f95b89dd94bd2d5733da85 (patch)
treea723bca215f9b167d81420c0a90eeed912d0a5ee /core/java/android/widget
parenta2511da9d65b11be7f59ed3f525f77e85aeb4bef (diff)
DO NOT MERGE Overscroll continues; asset and behavior tweaks.
Change-Id: I367643877a397e7b4fa9bd8c40639ff69436e7f0
Diffstat (limited to 'core/java/android/widget')
-rw-r--r--core/java/android/widget/AbsListView.java42
-rw-r--r--core/java/android/widget/EdgeGlow.java28
-rw-r--r--core/java/android/widget/HorizontalScrollView.java6
-rw-r--r--core/java/android/widget/ScrollView.java6
4 files changed, 57 insertions, 25 deletions
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index db50ca15adc4..fe2a43b7abe2 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 06334a06f8b8..93222e1c00fc 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 3493f498caa8..129ad8ac64ed 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 9d971f6b213f..7b5e4125eca8 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)) {