B4A Library PageTurnView library providing a page turn animation

This library displays bitmap images and provides a page turn animation to allow the user to "turn" the pages.

This library wraps an Android view which written by Harri Smått and released as open source under the Apache 2.0 licence. It was located for Basic4android use by forum member Smee.

There is no credit due to me for the functionality of this library. As Harri wrote it as a normal Android view I have merely wrapped Erel's view structure around it to make it accessible to Basic4android.

Belated warning in 2021! Use Release mode. You can probably use legacy debug mode if you need to, but normal debug mode will not work with this library.

EDIT :- Version 1.1 posted. See post #6 for details.

EDIT :- Version 1.2 posted. See post #10 for details.

EDIT :- Version 1.3 posted. See post #43 for details.

EDIT :- Version 1.4 posted. See post #158 for details.
 

Attachments

  • PageTurnView1.4.zip
    38.6 KB · Views: 760
Last edited:

Djembefola

Active Member
Licensed User
Longtime User
Wow!!!
Thank you, Andrew, Harri and Smee.
 

klaus

Expert
Licensed User
Longtime User
Hi Andrew,
Excellent and impressive work :sign0098:.

What is the ba parameter PageTurner.ba ?

I would suggest to replace, in the autocomplete, the argx names by the names like in the other views.
Examples:
Initialize(arg1 As String) > Initialize(EventName As String)
Invalidate3(arg0 As android.graphics.Rect) > Invalidate3(Rect As android.graphics.Rect)
Invalidate3(arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int) > Invalidate3(Left As Int, Top As Int, Right As Int, Bottom As Int)

Best regards.
 

agraham

Expert
Licensed User
Longtime User
What is the ba parameter PageTurner.ba ?
It's an internal field inherited from the Basic4android view wrapper that unfortunately is being exposed by the doclet that generates the xml.
I would suggest to replace, in the autocomplete, the argx names by the names like in the other views
I can't because they are not defined in my library but inherited from the Basic4android view wrapper so the doclet that produces the xml does not have the source code to get the names of the parameters.

Incidentally the present demo is stupidly broken under pause and resume again by me making a beginners mistake and re-initializing the view in Activity_Resume instead of Activity_Create. I will post a modified library and demo in a little while.
 

agraham

Expert
Licensed User
Longtime User
A quick update to version 1.1, mainly because the demo failed under certain circumstances as I had stuff in Activity_Resume that should have been in Activity_Create. Stupid beginners mistake! :sign0161:

After playing on my Xoom i have also added a smoothness parameter to Initialize to specify the number of line segments on the curl of a page as the default of 10 was a little bit obvious on a high resolution screen.

If you get a force close the most likely reason is that a bitmap allocation within the OpenGL code caused an out of memory exception. It can't be trapped normally with a Basic4android Try - Catch as it is not occurring on the main thread but on the rendering. I will look at trapping it within the OpenGL as I do this in my own OpenGl libraries but so far I have modified the code as little as possible to make it easy to update if Harri produces a newer version. In the meantime I have added a RecoverMemory method that forces a garbage collection. If you get force closes you could play with using this in the GetBitmap event and see if it helps.
 

Fox

Active Member
Licensed User
Longtime User
Hello!

Very nice work the libary. I'm not on my home pc so i can't try it but a question is it possible to draw than pics on the page and if yes how. You make an tutorial for this ?

But very nice and useful think :sign0188: sounds cool
 

Fox

Active Member
Licensed User
Longtime User
It displays bitmaps so you can display whatever you want. I don't think it needs a tutorial, the demo should tell you all you need to know.

ok then i will look into if i'm at home...
 

agraham

Expert
Licensed User
Longtime User
Another quick update to version 1.2

Thanks to Erel for sending me the source code for the view wrapper in Basic4android the xml defficiencies that Klaus pointed out above are fixed now and the xml has complete help for all methods.

I have also poked around inside Harris' source code and implemented some explicit bitmap handling which seems to have eliminated the out of memory errors (so far!) I was experiencing. Android suffers from bitmap memory problems in the same way as Windows Mobile. Because bitmaps are large native objects you can't just leave large ones lying round until the garbage collector removes them as you can run out of native memory before managed memory.

As an insurance I have added a RecycleBitmap method which does much the same as Dispose did for a bitmap in Basic4ppc. You might need to use this to manage the bitmaps you feed the PageTurnView with in a real application. I left RecoverMemory in just in case of need. I don't force a garbage collection in the new bitmap handling so I would expect that you will never need to either - but it's there.
 

Smee

Well-Known Member
Licensed User
Longtime User
Many Thanks Andrew,

I am about to download this and give it a whirl. Been away for a little while.

I am trying to load a picture jpg on the page but without much success. Is it possible?
Thanks

Joe
 
Last edited:

hdtvirl

Active Member
Licensed User
Longtime User
Great work.

I was out walking the dog yesterday and wondering how I might do exactly what you guys have done with this Library, I had performed something similar using GDI+ in VB.net and I was trying to figure out how I could transfer the routines to B4A. So I was totally amazed to see it had been done.

So tomorrow morning and I am taking the dog out again to sort out another problem !! I never knew B4A was this easy, just think about the problem and somebody will post the solution. I am only joking of course.

I know you guys put a lot of thought and effort in to everything you post and I am very grateful as I am sure others are too .

I have tried your example on my Acer Iconia and it works ‘FAB’ !!.

Can I use this library in my application as part of V4B ?

Amazing, what a community !!!!!!, I hope one day I can make similar contributions and help other developers like this community does..

BOB
 

Smee

Well-Known Member
Licensed User
Longtime User
So tomorrow morning and I am taking the dog out again to sort out another problem !! I never knew B4A was this easy, just think about the problem and somebody will post the solution.
BOB

Hahahahah
:)
 

Smee

Well-Known Member
Licensed User
Longtime User
Sorry Andrew, not with you

Should be. Whack it on a bitmap and give it to the PageTurnView.

The code i changed was this
B4X:
   bmp.Initialize (File.DirAssets,"26833.jpg")
'   bmp.InitializeMutable(Width, Height)
'   cnv.Initialize2(bmp)
   cnv.Initialize(Activity)
   cnv.DrawBitmap(bmp,Null,DestRect)

The DestRect was declared in Process_Globals coz the program crashed if it was declared elsewhere.
 

Smee

Well-Known Member
Licensed User
Longtime User
This compiles and runs but crashes with error at the last line
B4X:
   Dim Canvas1 As Canvas
      PageTurner.RecoverMemory
      bmp.Initialize (File.DirAssets,"26833.jpg")
      Dim Rect1 As Rect
      Rect1.Initialize(10dip,10dip,10dip+100dip,10dip+100dip)
      Canvas1.DrawBitmap(bmp,Null,Rect1)

i know i am missing the obvious but what?
 

Fox

Active Member
Licensed User
Longtime User
This compiles and runs but crashes with error at the last line
B4X:
   Dim Canvas1 As Canvas
      PageTurner.RecoverMemory
      bmp.Initialize (File.DirAssets,"26833.jpg")
      Dim Rect1 As Rect
      Rect1.Initialize(10dip,10dip,10dip+100dip,10dip+100dip)
      Canvas1.DrawBitmap(bmp,Null,Rect1)

i know i am missing the obvious but what?

Yes an sample for an image on page one and a image on the second page would be good on 1 page i have an image but if i change the side there is no other text...

But here is the code for image show...

B4X:
Sub PageTurner_GetBitmap(Width As Int, Height As Int, Page As Int) As Bitmap 'Called when the Bitmap for the given page number is required. Return the Bitmap
   Dim bmp As Bitmap
   Dim cnv As Canvas
   Dim c As Canvas
   Dim b As Bitmap
   Dim brect As Rect

   bmp.InitializeMutable(Width, Height)
   cnv.Initialize2(bmp)
   
   cnv.DrawColor(PageColors(Page))
   
   If page = 0 Then
   
   cnv.DrawText( "Page 0 Text Center", Width/2, 180dip, Typeface.DEFAULT, 24, Colors.White, "CENTER")
   
   b.Initialize(File.DirAssets, "picture.png")
   brect.Initialize(0,0,b.Width, b.Height)
   cnv.DrawBitmap(b, Null, brect)
   
   
If page = 1 Then 
cnv.DrawText( "Page1 Text", Width/2, 260dip, Typeface.DEFAULT, 24, Colors.White, "CENTER")
   
   If Page = PageColors.Length - 1 Then
   cnv.DrawText( "Letzte Seite", Width/2, 100dip, Typeface.DEFAULT, 24, Colors.White, "CENTER")
   End If
   End If
   End If
   Return bmp
   
End Sub
 

Smee

Well-Known Member
Licensed User
Longtime User
Thanks Fox

I tried that sample code but i still get a crash
at this line
b.Initialize(File.DirAssets, "26833.png")
the error log says this

android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

so i dont know whats happening. It is the same error line when i ran my code

:confused:

EDIT:
Can't believe i missed this, prolly cause i got the same error with my code. Anyway it works since i changed 26833.png to 26833.jpg
:sign0161:
 
Last edited:
Top