The code here is untested, proof of concept code - but given your question, you still seem to be at the prototyping stage. Let me know how you go!
The method described here will work for flipping pages "atomically" - ie, the user swipes their finger, then the page changes. If you're after an actual page curl, you'll need to combine what I've written here with something like http://code.google.com/p/android-page-curl/.
First, sub-class WebView to attach a GestureListener and GestureDetector, as per Fling Gesture and Webview in Android. I've copied the code here for convenience.
class MyWebView extends WebView {
Context context;
GestureDetector gd;
public MyWebView(Context context) {
super(context);
this.context = context;
gd = new GestureDetector(context, sogl);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return gd.onTouchEvent(event);
}
GestureDetector.SimpleOnGestureListener sogl = new GestureDetector.SimpleOnGestureListener() {
public boolean onDown(MotionEvent event) {
return true;
}
public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
if (event1.getRawX() > event2.getRawX()) {
// Scroll up
} else {
// Scroll down
}
return true;
}
};
}
Then, when the user flings the 'page' one way or the other, do the following;
- Render the current contents of the WebView to a Bitmap, as per @Deadeye's answer
Eg:
View v = getYourWebView();
v.setDrawingCacheEnabled(true);
// Cheat to force WebView to draw itself
v.measure(
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
);
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
- Scroll the WebView down by exactly one viewport's length
Use jQuery and be done with it:
$(document).scrollTop($(document).scrollTop()+$(window).height());
- Render the next page into a second Bitmap
Then flip away using whatever page-flipping logic you've already written :)