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: 616
Last edited:

agraham

Expert
Licensed User
Longtime User
Android compresses files into DirAssets but is unable to unpack compressed files larger than 1mb. A workaround for this issue is to change the file extension to jpg. Then the Android packager doesn't compress the file and it can be larger than 1mb but as text compresses very efficiently this might make the file very large. Alternatively split the text file into two or more files and concatenate them when you read them.
 

malc

New Member
Licensed User
Longtime User
I have just installed B4A and run the Hello World example. I thought Id give the Page Turner a try out and downloaded the .jar and .xml files to the Library but when I run the demo it will not comple ...

B4Asnippet.jpg


I realise I'm just a beginner and probably trying something too advanced but can anyone tell me why the demo code will not compile?

Many thanks!
 

malc

New Member
Licensed User
Longtime User
Thanks for the quick reply.

I have read the documentation as indicated, and the correct library is installed, but still no joy.

Maybe I should stick to simpler examples! :confused:
 

malc

New Member
Licensed User
Longtime User
Many thanks nfordbscndrd and Klaus.

I've sussed it now. I had 'PageTurnView' selected in Libs but I hadn't downloaded and installed the 'Threading' library, which is where ExceptionEx is defined.

Sorted now and installed on my device. Works like a charm, I'm impressed!
 

ChrShe

Member
Licensed User
Longtime User
I think I'm totally missing something.
PageTurnView seems to work only with a string passed in. But, I would like to use it to show pages similar to the attached, with a text, a photo and some buttons.

What would be the best way to do this?

DogView.png

I'd also like to have some formatting control over the passed in text. Is that possible?

Thanks much!!!
Chris
 
Last edited:

ChrShe

Member
Licensed User
Longtime User
I think me being a n00b is what make me think that. LOL

I'm looking at the demo and can't see for forest through the trees. :-(

What would be the best way to do what I need? Currently, I'm creating panels and adding them to a scrollview. Could I add them to a PageTurnerView instead? If so...how?

Thanks again!!!!!!
 

ChrShe

Member
Licensed User
Longtime User
Okay, thanks for the info!!!
I'll fiddle and see what I can come up with. :D
 

ChrShe

Member
Licensed User
Longtime User
I got the "A BOOK" and "THE END" pages looking the way I want. WOOHOO!!! :sign0060:

Now on to the dynamically generated pages that go in between those two...this ought to be fun. :D

Thanks so much for the help!
 

kershawj42

New Member
Licensed User
Longtime User
Bitmap resize or scale

Hi,
Very new to Basic4PPC and finding out what a fantastic product this is, and this being a great example of so many very useful libaries.

Having a problem which I can't seem to get around and would be greatful for any available help or suggestions, Using the example found in the libary as an activity called when a menu item is selected and all working fine.
Instead of having the libary create a bitmap from text I wanted a picture on the first page so changed:

B4X:
If Page = 0 Then
         cnv.Initialize2(bmp)
         cnv.DrawColor(Colors.Blue)
         cnv.DrawText( "A Book", Width/2, 100dip, Typeface.DEFAULT, 24, Colors.White, "CENTER")
         Return bmp

To be:

B4X:
If Page = 0 Then
         bmp.Initialize(File.DirAssets, "filename.png")
         Return bmp

The picture shows up, but is not scaled correctly. I did think it was half the size but it's more like 3/4 of the original size, the rest is clipped.
I tried resizing the png but same thing always happens.
Also tried:

B4X:
bmp.InitializeSample(File.DirAssets, "filename.png", Width/2, Height/2)

But same result.
Had a good look around the forum but can't seem to see any method around it. Guess it works fine for others?
I have tried on my own phone (HTC Desire HD) and the emulator (Nexus-ARM, Android 4.0.3) and same result seen.
 

agraham

Expert
Licensed User
Longtime User
From the library help
The GetBitmap(Width as Int, Height As Int, Page as Int) As Bitmap event is called when the Bitmap for the given page number is required. Return the appropriate Bitmap. If the returned Bitmap is not of the requested size it will be displayed scaled to fit.
It tells you what size of Bitmap it needs - it's up to you to provide it.
 

kershawj42

New Member
Licensed User
Longtime User
Finally got the point

Well, nearly sent a reply saying how I'm missing the obvious or just do not understand which turns out would have been pretty close.

As shown in my previous code I was just replacing all the good stuff you had of initializing a canvas, drawing upon this then returning as the bmp with just loading the bitmap and sending it back.
So after a while and a few false starts now realise I needed to still have the canvas, initialize a rectangle on this then draw the image onto this then return the whole thing.

B4X:
Dim bmp As Bitmap
   Dim cover As Bitmap
   Dim cnv As Canvas
   bmp.InitializeMutable(Width, Height) ' do this here so we have a valid return in case of an exception
   Try   
      'File.OpenInput("bad", "filename") ' this would cause an exception to be reported on the main thread
      If Page = 0 Then
         cover.Initialize(File.DirAssets, "filename.bmp")
         cnv.Initialize2(bmp)
         Dim DestRect As Rect
         DestRect.Initialize(0dip, 0dip,Width, Height) 
         cnv.DrawBitmap (cover, Null, DestRect)
         Return bmp

Put the code I used in here in case someone else at the same basic (no pun intended) level finds useful.
Thanks for the nudge in the right direction, like the libary, and unlike my code, expertly done!
:)
 

fanfalveto

Active Member
Licensed User
Longtime User
Thank you for your job is very good.Is possible to get as string the text of the current page?
 

fanfalveto

Active Member
Licensed User
Longtime User
Well I found a way. thanks
B4X:
Pager.Paginate(ipsum)
Log("PAGINAS: "&Pager.PageCount)
Log("LONGITUD TEXTO: "&ipsum.Length)
pag
PageNumber =pagina
PageTurner.CurrentPage = PageNumber
If PageNumber>0 Then
start=(ipsum.Length/Pager.PageCount)
Log("Empieza en: "&(start*pagina))
lectura=ipsum.SubString(start*(pagina-1))
Else
lectura=ipsum
End If
 

zeuspower

Member
Licensed User
Longtime User
Agraham, :sign0188:

beautiful job...

I already loaded from an external text file,and my book is ready :icon_clap:

well...not exactly for publish,but for my eyes is ready !

1. Any first ideas,of how can i insert some graphic images between the images with the text ?

It's easy to change the first an last images because they are static somehow,but the between main images-text seem a little complicated to insert a new(extra) image with a painting or photo for example ,because of the serial generation by pager object ..

thanks

...and something else !

2. I try to use the library inside of my greek mythology app
It takes the text data from my sql database

in the first load it works ok,but the next time it contains the previous text data + the new text data ,how i clear and refresh the text(images) contained in the pager ?

check my code :

B4X:
Sub create_Mini_book(perigrafiData As String)  
  
      If  PageTurner.IsInitialized=False Then   <<----- first run and load OK
   
       PageTurner.Initialize("PageTurner", 20)
         pnlPage3.AddView(PageTurner, 10dip, 10dip, tbhPages.Width - 25dip, tbhPages.Height - 70dip)
       PageTurner.TwoPages = False 
      PageTurner.RenderLeftPage = False
      Pager.SetPageParameters(Pager.ALIGN_CENTER, PageTurner.Width - 20dip, LeftMargin, PageTurner.Height - 20dip, TopMargin, LineSpacing)
      PageTurner.SetMarginPixels(10dip, 10dip, 10dip, 10dip)
   
   PageTurner.AllowLastPageCurl = False ' the default is true   
   
   Font = Font.CreateNew(Typeface.SERIF, Typeface.STYLE_NORMAL)
   Dim text As String
   
      text = perigrafiData & CRLF & CRLF
   
   Pager.SetPaintParameters(Font, 16, Colors.Black, True)
   Pager.Paginate(text)
    
  Else
                                        <<--next load of fresh text from database    
                                                    it adds to the previous text
    
   PageTurner.RemoveView 
      PageTurner.Initialize("PageTurner", 20)
         pnlPage3.AddView(PageTurner, 10dip, 10dip, tbhPages.Width - 25dip, tbhPages.Height - 70dip)
       PageTurner.TwoPages = False 
      PageTurner.RenderLeftPage = False
      Pager.SetPageParameters(Pager.ALIGN_CENTER, PageTurner.Width - 20dip, LeftMargin, PageTurner.Height - 20dip, TopMargin, LineSpacing)
      PageTurner.SetMarginPixels(10dip, 10dip, 10dip, 10dip)
   
   PageTurner.AllowLastPageCurl = False ' the default is true   
   
   Font = Font.CreateNew(Typeface.SERIF, Typeface.STYLE_NORMAL)
   Dim text As String
   text=""                                 << I try here to clear possible previous text data but no use...
   
      text =perigrafiData & CRLF & CRLF
   
   Pager.SetPaintParameters(Font, 16, Colors.Black, True)
   Pager.Paginate(text)
   
    End If
    
      
      
   
   End Sub
 
Last edited:
Top