Open TIKramer opened 4 years ago
First, you need to know the PageFlip needs a bitmap you passed to show on the screen, if flipping, it needs another bitmap for the next page, that means, PageFlip will at least have two bitmap to show during flipping, one is the first page - current showing page, another is the next page - waiting to show, so, when you want to change anything on current showing page, you just use the canvas to draw anything you want on this bitmap and then pass it to PageFlip to show again, here is an example for how to draw with canvas: https://github.com/eschao/android-PageFlip/blob/adf677e156fd83c8a6eaea650e493e82c876f8c2/Sample/src/main/java/com/eschao/android/widget/sample/pageflip/SinglePageRender.java#L174
// 1. draw background bitmap
Bitmap background = LoadBitmapTask.get(mContext).getBitmap();
Rect rect = new Rect(0, 0, width, height);
mCanvas.drawBitmap(background, null, rect, p);
background.recycle();
background = null;
// 2. draw page number
int fontSize = calcFontSize(80);
p.setColor(Color.WHITE);
p.setStrokeWidth(1);
p.setAntiAlias(true);
p.setShadowLayer(5.0f, 8.0f, 8.0f, Color.BLACK);
p.setTextSize(fontSize);
String text = String.valueOf(number);
float textWidth = p.measureText(text);
float y = height - p.getTextSize() - 20;
mCanvas.drawText(text, (width - textWidth) / 2, y, p);
...
After you have a new bitmap with your desired changes, then you can do like the following codes in function: https://github.com/eschao/android-PageFlip/blob/adf677e156fd83c8a6eaea650e493e82c876f8c2/Sample/src/main/java/com/eschao/android/widget/sample/pageflip/SinglePageRender.java#L60
// draw stationary page without flipping
else if (mDrawCommand == DRAW_FULL_PAGE) {
if (!page.isFirstTextureSet()) {
drawPage(mPageNo);
page.setFirstTexture(mBitmap);
}
mPageFlip.drawPageFrame();
}
Hi I am trying to update the text of my current page when a button is clicked.
I have the button working but I can't get the page to redraw with the new changes. How can I redraw the current page on screen? Thank you.