Returning to this after a few months, I now took a different approach: using a handler (as in the Android Snake example) to send a message to the application every 125 milliseconds, in which he was asked to check if there was a scroll and more than 100 milliseconds had passed since the last scroll events.
This seems to work very well, but if anyone can see any flaws or possible improvements, I should be grateful for them.
The corresponding code is in the MyView class:
public class MyView extends android.view.View { ... private long timeCheckInterval = 125;
// Scrolling is complete, so paste the code here
// which calls the doDrawing () method
// to redraw the bitmap with re-centering where the scroll ends
[ layout or view ].invalidate(); } this.sleep(timeCheckInterval); } public void sleep(long delayMillis) { this.removeMessages(0); sendMessageDelayed(obtainMessage(0), delayMillis); } } } @Override protected void onDraw(Canvas canvas){ super.onDraw(canvas);
// the code for drawing a large bitmap image of the buffer onto the presentation canvas // is positioned to account for any scrolling that is performed.
} public void doDrawing() {
// code to perform detailed (and time-consuming) drawing // into a bitmap image of a large buffer
// the next command resets the clock for checking time // the clock starts when the main action // calls this method when the application starts
mTimeCheckHandler.sleep(timeCheckInterval); }
// remainder of class MyView
}
and in class MyGestureDetector
public class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { [MyView].scrollInProgress = true; long now = System.currentTimeMillis(); [MyView].latestScrollEventTime =now; [MyView].scrollX += (int) distanceX; [MyView].scrollY += (int) distanceY;
// the following command calls the View onDraw method // which displays the bitmap of the buffer on the screen // is shifted to allow for scrolling
[MyView].invalidate(); }
// remainder of class MyGestureDetector
}