2

I have used Harism's Page Curl animation for my application, but I have been facing a small problem, I am using the index Value in the getBitmap() method of the CurlActivity, I need to show page numbers to the user on every flip of the page(say using a call to Toast.maketext().show), this works fine while going from page 0 to pageCount.length, but when I move page right to left(the pages, i.e. while going the other way from pageCount.lenth to 0) the index values are not consistently reduced.

Can anyone please help me with this.

Thanks in Advance.

P.S.:That would be my first question on stackoverflow

public Bitmap getBitmap(int width, int height, int index) {

        Bitmap b = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888);
        b.eraseColor(0xFFFFFFFF);
        Canvas c = new Canvas(b);

        //this is where index seems to go wrong on reverse counting, I believe
        Log.e("PAGE--", ""+index);
        Toast.makeText(CurlActivity.this, ""+index, Toast.LENGTH_SHORT).show();
        Drawable d = getResources().getDrawable(mBitmapIds[index]);

        int margin = 7;
        int border = 3;

        return b
}
guenis
  • 2,520
  • 2
  • 25
  • 37
Some one Some where
  • 777
  • 1
  • 8
  • 26

2 Answers2

3

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!

Taynã Bonaldo
  • 621
  • 9
  • 17
  • Can you help me regarding going back to the previous pages with a particular index as well as it does for the next pages ?? – Prateek May 24 '13 at 13:11
  • @prateek Did you mean back pages with the swipe motion (e.g. swipe from left to right)? If so, there is no implementation, because the method updatePage(..) receives int index as a parameter, and this index can be incremented or decremented according to the direction of the swipe. – Taynã Bonaldo May 24 '13 at 16:28
  • But the issue I am facing is that , when I try to go back to the previous page the correct bitmap at that page doesn't get refreshed. – Prateek May 25 '13 at 12:41
  • http://stackoverflow.com/q/16772734/1503130 can you help me in this thread , highly appreciate. – Prateek May 27 '13 at 12:16
  • I have gone through Curl effect as well as flip effect in android where pages of a book are turned but what i need is turn effect on book means when we have a book with first and last cover as hard bound then the turning style will be different from curl and flip effect. So please can any one tell me how to implement this and any supporting links or tutorials or examples (are appreciated ) Thank you – ask4solutions Oct 08 '14 at 10:13
1

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.

harism
  • 6,011
  • 1
  • 36
  • 31
  • Let me first Thank you for the wonderful piece of work you have provided us all with page curl in android. I tried your Suggested way of displaying the mCurrentIndex from the getCurrentIndex method of the CurlView class from inside the getBitmap() Method, but it seems that the getCurrentIndex Method increases the count of the Right Page by one (+1) on the Reverse flip(i.e. moving page left to right), Moreover flipping back to the first page would also not bring back the initial value(from where it had started.) Where am i going wrong here? – Some one Some where Jan 12 '12 at 22:38
  • 1
    Yep, got the answer to my question in the Curl view class only as you had suggested, I was being wrong trying to fetch the page Index from the getBitmap method Cheers !!! – Some one Some where Jan 13 '12 at 12:14
  • @SomeoneSomewhere can you share the solution i.e. where exactly did you do the changes to achieve it I got stuck in the same issue, Also did you make any changes to the getCurrentIndexFunction – Prateek May 24 '13 at 13:44
  • Even if it works for the index this doesn't refresh the images when going back why does this happen? – Prateek May 28 '13 at 06:33
  • @harism stackoverflow.com/questions/16959530/… Can u check this thread! – Chanakya Vadla Jun 06 '13 at 10:39
  • I have gone through Curl effect as well as flip effect in android where pages of a book are turned but what i need is turn effect on book means when we have a book with first and last cover as hard bound then the turning style will be different from curl and flip effect. So please can any one tell me how to implement this and any supporting links or tutorials or examples (are appreciated ) Thank you – ask4solutions Oct 08 '14 at 10:19
  • Can you check this.`http://stackoverflow.com/questions/26547301/curl-page-wasnt-working-in-action-bar-tabs` – Stephen Nov 22 '14 at 03:39
  • @harism it works great Left to Right with currentIndex. problem comes when going backwards. so what would be the workaround for this? Do I need to change the logic in CurlView class. – chathura May 04 '17 at 09:19