summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBhargav Upperla <bhargavuln@codeaurora.org>2012-12-03 17:32:21 -0800
committerNebojsa Cvetkovic <nebkat@gmail.com>2013-03-03 08:58:55 +0000
commitce6b2513bcfb257cfdeb604060708b3833ccb65e (patch)
treed6674798600a0ecaa951b6268925a437be3420c0
parent1e39be6b64d2fb996120079d221463f0ecd47897 (diff)
downloadandroid_packages_apps_Trebuchet-ce6b2513bcfb257cfdeb604060708b3833ccb65e.tar.gz
android_packages_apps_Trebuchet-ce6b2513bcfb257cfdeb604060708b3833ccb65e.tar.bz2
android_packages_apps_Trebuchet-ce6b2513bcfb257cfdeb604060708b3833ccb65e.zip
Improve scroll responsiveness.
1) mUsePagingTouchSlop set to false. Applist scroll now scrolls with the same thresholds used by homescreen scrolling. 2) Early start of scroll as soon as we detect that it's okay to scroll. Eliminates waiting for next vsync and starts scrolling in the current cycle. instead of the next. Above changes help in reducing first touch to first displacement latencies in scroll usecases. Improves scroll responsiveness. Change-Id: Ib45a361b9b6275e64d0a5b5603aa15fdd386a5f8
-rw-r--r--src/com/cyanogenmod/trebuchet/PagedView.java94
1 files changed, 50 insertions, 44 deletions
diff --git a/src/com/cyanogenmod/trebuchet/PagedView.java b/src/com/cyanogenmod/trebuchet/PagedView.java
index 42ae9687e..d8fccbf12 100644
--- a/src/com/cyanogenmod/trebuchet/PagedView.java
+++ b/src/com/cyanogenmod/trebuchet/PagedView.java
@@ -174,7 +174,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
// It true, use a different slop parameter (pagingTouchSlop = 2 * touchSlop) for deciding
// to switch to a new page
- protected boolean mUsePagingTouchSlop = true;
+ protected boolean mUsePagingTouchSlop = false;
// If true, the subclass should directly update scrollX itself in its computeScroll method
protected boolean mDeferScrollUpdate = false;
@@ -1216,21 +1216,23 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
if (mUsePagingTouchSlop ? xPaged : xMoved) {
// Scroll if the user moved far enough along the X axis
mTouchState = TOUCH_STATE_SCROLLING;
- mTotalMotionX += Math.abs(mLastMotionX - x);
- mLastMotionX = x;
mLastMotionXRemainder = 0;
mTouchX = mScrollX;
pageBeginMoving();
+ // Early scroll by starting as soon as we detect it's okay to scroll
+ // instead of waiting for vsync.
+ initiateScroll(ev);
}
} else {
if (mUsePagingTouchSlop ? yPaged : yMoved) {
// Scroll if the user moved far enough along the X axis
mTouchState = TOUCH_STATE_SCROLLING;
- mTotalMotionY += Math.abs(mLastMotionY - y);
- mLastMotionY = y;
mLastMotionYRemainder = 0;
mTouchY = mScrollY;
pageBeginMoving();
+ // Early scroll by starting as soon as we detect it's okay to scroll
+ // instead of waiting for vsync.
+ initiateScroll(ev);
}
}
// Either way, cancel any pending longpress
@@ -1238,6 +1240,48 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
}
}
+ protected void initiateScroll(MotionEvent ev) {
+ final int pointerIndex = ev.findPointerIndex(mActivePointerId);
+ final float x = ev.getX(pointerIndex);
+ final float deltaX = mLastMotionX + mLastMotionXRemainder - x;
+ final float y = ev.getY(pointerIndex);
+ final float deltaY = mLastMotionY + mLastMotionYRemainder - y;
+
+ mTotalMotionX += Math.abs(deltaX);
+ mTotalMotionY += Math.abs(deltaY);
+
+ // Only scroll and update mLastMotionX if we have moved some discrete amount. We
+ // keep the remainder because we are actually testing if we've moved from the last
+ // scrolled position (which is discrete).
+ if (Math.abs(!mVertical ? deltaX : deltaY) >= 1.0f) {
+ if (!mVertical) {
+ mTouchX += deltaX;
+ mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
+ if (!mDeferScrollUpdate) {
+ scrollBy((int) deltaX, 0);
+ if (DEBUG) Log.d(TAG, "onTouchEvent().Scrolling: " + deltaX);
+ } else {
+ invalidate();
+ }
+ mLastMotionX = x;
+ mLastMotionXRemainder = deltaX - (int) deltaX;
+ } else {
+ mTouchY += deltaY;
+ mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
+ if (!mDeferScrollUpdate) {
+ scrollBy(0, (int) deltaY);
+ if (DEBUG) Log.d(TAG, "onTouchEvent().Scrolling: " + deltaY);
+ } else {
+ invalidate();
+ }
+ mLastMotionY = y;
+ mLastMotionYRemainder =- deltaY - (int) deltaY;
+ }
+ } else {
+ awakenScrollBars();
+ }
+ }
+
protected void cancelCurrentPageLongPress() {
if (mAllowLongPress) {
mAllowLongPress = false;
@@ -1389,45 +1433,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
case MotionEvent.ACTION_MOVE:
if (mTouchState == TOUCH_STATE_SCROLLING) {
// Scroll to follow the motion event
- final int pointerIndex = ev.findPointerIndex(mActivePointerId);
- final float x = ev.getX(pointerIndex);
- final float deltaX = mLastMotionX + mLastMotionXRemainder - x;
- final float y = ev.getY(pointerIndex);
- final float deltaY = mLastMotionY + mLastMotionYRemainder - y;
-
- mTotalMotionX += Math.abs(deltaX);
- mTotalMotionY += Math.abs(deltaY);
-
- // Only scroll and update mLastMotionX if we have moved some discrete amount. We
- // keep the remainder because we are actually testing if we've moved from the last
- // scrolled position (which is discrete).
- if (Math.abs(!mVertical ? deltaX : deltaY) >= 1.0f) {
- if (!mVertical) {
- mTouchX += deltaX;
- mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
- if (!mDeferScrollUpdate) {
- scrollBy((int) deltaX, 0);
- if (DEBUG) Log.d(TAG, "onTouchEvent().Scrolling: " + deltaX);
- } else {
- invalidate();
- }
- mLastMotionX = x;
- mLastMotionXRemainder = deltaX - (int) deltaX;
- } else {
- mTouchY += deltaY;
- mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
- if (!mDeferScrollUpdate) {
- scrollBy(0, (int) deltaY);
- if (DEBUG) Log.d(TAG, "onTouchEvent().Scrolling: " + deltaY);
- } else {
- invalidate();
- }
- mLastMotionY = y;
- mLastMotionYRemainder = deltaY - (int) deltaY;
- }
- } else {
- awakenScrollBars();
- }
+ initiateScroll(ev);
} else {
determineScrollingStart(ev);
}