Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify current page./redraw current page. #50

Open
TIKramer opened this issue Jan 29, 2020 · 1 comment
Open

Modify current page./redraw current page. #50

TIKramer opened this issue Jan 29, 2020 · 1 comment

Comments

@TIKramer
Copy link

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.

@eschao
Copy link
Owner

eschao commented Feb 29, 2020

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:

        // 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:

        // draw stationary page without flipping
        else if (mDrawCommand == DRAW_FULL_PAGE) {
            if (!page.isFirstTextureSet()) {
                drawPage(mPageNo);
                page.setFirstTexture(mBitmap);
            }

            mPageFlip.drawPageFrame();
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants