Android Page Curl Animation by Harism shows inconsistency in the reverse index count in the getBitmap() method of CurlActivity()? Android Page Curl Animation by Harism shows inconsistency in the reverse index count in the getBitmap() method of CurlActivity()? curl curl

Android Page Curl Animation by Harism shows inconsistency in the reverse index count in the getBitmap() method of CurlActivity()?


Firstly, Harism, thank you for sharing this beautiful framework! :)

Now, only to complement the response of Harism:

When working with magazines, books, etc, we deal with an undetermined amount of pages.

In the example presented in class CurlActivity, of project Harism-Android-Page-Curl, uses a "Switch" to control the pages. To be able to meet my needs, I had to change the method "updatePage" and then control my magazines more appropriately, regardless of the amount of pages.

My need was to present the outline below, according to the Index (of the method signature itself) and current Orientation device:

Landscape Orientation ("Side Back" with next page)

Index | Page Left | Page Right

0 | 0 | 1

1 | 2 | 3

2 | 4 | 4

3 | 6 | 7

4 | 8 | 9


Portrait Orientation ("Side Back" with same page mirrored)

Index | Page

0 | 0

1 | 1

2 | 2

3 | 3

4 | 4

....

To implement this scheme, first have to change the method getPageCount thus:

public int getPageCount() {        //return 5;        int pagesCount = 0;        DisplayMetrics displaymetrics = new DisplayMetrics();        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);        int wwidth = displaymetrics.widthPixels;        int hheight = displaymetrics.heightPixels;        if(wwidth > hheight){            if((mBitmapIds.length % 2) > 0)                pagesCount = (mBitmapIds.length / 2) + 1;            else                pagesCount = mBitmapIds.length / 2;        }else{            pagesCount = mBitmapIds.length;        }        return pagesCount;    }

This will allow the page counter will return the actual number of pages.


Then change the method updatePage, conforms the code below:

public void updatePage(CurlPage page, int width, int height, int index) {        DisplayMetrics displaymetrics = new DisplayMetrics();        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);        int wwidth = displaymetrics.widthPixels;        int hheight = displaymetrics.heightPixels;        if(wwidth > hheight){            System.out.println("case landscape orientation...");            Bitmap front = loadBitmap(width, height, (index * 2));            Bitmap back = loadBitmap(width, height, (index * 2) + 1);            Matrix matrix = new Matrix();             matrix.preScale(-1.0f, 1.0f);             Bitmap mirroredBitmap = Bitmap.createBitmap(back, 0, 0, back.getWidth(), back.getHeight(), matrix, false);            page.setTexture(front, CurlPage.SIDE_FRONT);            page.setTexture(mirroredBitmap, CurlPage.SIDE_BACK);        }else{            System.out.println("case portrait orientation...");            Bitmap front = loadBitmap(width, height, index);            Bitmap back = loadBitmap(width, height, index);            page.setTexture(front, CurlPage.SIDE_FRONT);            page.setTexture(back, CurlPage.SIDE_BACK);        }}}

I hope I helped!

And once again, thanks for the framework Harism!


Problem is that you really can't rely on requested page index on purpose you try to implement. Reason for the behavior you're facing is that once you flip through pages forward, only 'next page' is requested, in which case index seems to be what you're expecting. But changing pages backwards works the exact opposite, only 'previous page' is requested, and there's a gap within index between these separate operations.

There's a method CurlView.getCurrentIndex() though which is constantly set to index of the page being shown on right side. It should give you means for having actual page numbers shown.