summaryrefslogtreecommitdiff
path: root/core/java/android/widget/ScrollView.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/widget/ScrollView.java')
-rw-r--r--core/java/android/widget/ScrollView.java50
1 files changed, 29 insertions, 21 deletions
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index 493b28c688f9..e696ff7229e8 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -135,6 +135,8 @@ public class ScrollView extends FrameLayout {
private int mOverscrollDistance;
private int mOverflingDistance;
+ private int mScrollFactor;
+
/**
* ID of the active pointer. This is used to retain consistency during
* drags/flings if multiple pointers are used.
@@ -248,6 +250,7 @@ public class ScrollView extends FrameLayout {
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
mOverscrollDistance = configuration.getScaledOverscrollDistance();
mOverflingDistance = configuration.getScaledOverflingDistance();
+ mScrollFactor = configuration.getScaledScrollFactor();
}
@Override
@@ -782,30 +785,35 @@ public class ScrollView extends FrameLayout {
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
- if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
- switch (event.getAction()) {
- case MotionEvent.ACTION_SCROLL: {
- if (!mIsBeingDragged) {
- final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
- if (vscroll != 0) {
- final int delta = (int) (vscroll * getVerticalScrollFactor());
- final int range = getScrollRange();
- int oldScrollY = mScrollY;
- int newScrollY = oldScrollY - delta;
- if (newScrollY < 0) {
- newScrollY = 0;
- } else if (newScrollY > range) {
- newScrollY = range;
- }
- if (newScrollY != oldScrollY) {
- super.scrollTo(mScrollX, newScrollY);
- return true;
- }
- }
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_SCROLL:
+ final float axisValue;
+ if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
+ axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
+ } else if (event.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)) {
+ axisValue = event.getAxisValue(MotionEvent.AXIS_SCROLL);
+ } else {
+ axisValue = 0;
+ }
+
+ final int delta = Math.round(axisValue * mScrollFactor);
+ if (delta != 0) {
+ final int range = getScrollRange();
+ int oldScrollY = mScrollY;
+ int newScrollY = oldScrollY - delta;
+ if (newScrollY < 0) {
+ newScrollY = 0;
+ } else if (newScrollY > range) {
+ newScrollY = range;
+ }
+ if (newScrollY != oldScrollY) {
+ super.scrollTo(mScrollX, newScrollY);
+ return true;
}
}
- }
+ break;
}
+
return super.onGenericMotionEvent(event);
}