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:

Fox

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

You have an option to show a second pic or text on the page 1? and other pages.. at me there is no pic / Text on the page :)
 

Smee

Well-Known Member
Licensed User
Longtime User
Unable to show text but can show another pic not on the back of the page but on the subsequent page. by loading another image to the next page

When I rotate device the program just exits as does the demo. Any one else have that problem?
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Are you using version 1.2? It works fine on the three devices that I have. Look in the unfiltered logs for an exception.

The GetBitmap and GetPages run on the OpenGL rendering thread, not the application main thread so you can't touch any view or you'll get an exception. I'll put that in the xml. You probably got a file not found exception and Basic4android couldn't display the error message box because it was not on the main thread.
 

Smee

Well-Known Member
Licensed User
Longtime User
Andrew,

Using Ver 2.2

The jpgs all display ok forward and backward. It is only when i rotate from Vertical to Horizontal or vice versa the program drops out.

** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Process anywheresoftware.b4a.agraham.pageturnviewdemo (pid 10376) has died.
WIN DEATH: Window{ae49e7d0 anywheresoftware.b4a.agraham.pageturnviewdemo/anywheresoftware.b4a.agraham.pageturnviewdemo.main paused=false}
WIN DEATH: Window{ae4da310 SurfaceView paused=false}
WIN DEATH: Window{ae46e070 anywheresoftware.b4a.agraham.pageturnviewdemo/anywheresoftware.b4a.agraham.pageturnviewdemo.main paused=false}
Unexpected resume of anywheresoftware.b4a.b4abridge while already resumed in anywheresoftware.b4a.agraham.pageturnviewdemo
showStatusIcon on inactive InputConnection
GC_EXPLICIT freed 5293 objects / 282720 bytes in 29ms
GC_EXPLICIT freed 111 objects / 8552 bytes in 14ms
GC_EXPLICIT freed 96 objects / 3912 bytes in 14ms
GC_EXPLICIT freed 2788 objects / 179064 bytes in 16ms

The above is what i get after changing rotation
 

agraham

Expert
Licensed User
Longtime User
I assume you version mean 1.2. What device and Android version are you using?

Are you sure there isn't an exception showing in the log as by itself that doesn't make sense as an application normally doesn't die without any indication of what went wrong?

Does it do the same with the unedited demo from the library archive?
 

Smee

Well-Known Member
Licensed User
Longtime User
I assume you version mean 1.2. What device and Android version are you using?

Are you sure there isn't an exception showing in the log as by itself that doesn't make sense as an application normally doesn't die without any indication of what went wrong?

Does it do the same with the unedited demo from the library archive?


The device is a viewsonic and android version is 2.2. I updated from 1.5 cos it did the same in 1.5

This is the log with the demo . i cleared the log file then rotated so this is the entire log as it shuts down

Setting rotation to 0, animFlags=1
Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/2 nav=1/2 orien=2 layout=35 uiMode=17 seq=114}
Unexpected resume of anywheresoftware.b4a.agraham.pageturnviewdemo while already resumed in anywheresoftware.b4a.agraham.pageturnviewdemo
** Activity (main) Pause, UserClosed = false **
Process 10834 terminated by signal (11)
WIN DEATH: Window{ae4e4440 SurfaceView paused=false}
WIN DEATH: Window{ae3f8518 anywheresoftware.b4a.agraham.pageturnviewdemo/anywheresoftware.b4a.agraham.pageturnviewdemo.main paused=false}
Process anywheresoftware.b4a.agraham.pageturnviewdemo (pid 10834) has died.
Unexpected resume of anywheresoftware.b4a.b4abridge while already resumed in anywheresoftware.b4a.agraham.pageturnviewdemo
WIN DEATH: Window{ae45c090 anywheresoftware.b4a.agraham.pageturnviewdemo/anywheresoftware.b4a.agraham.pageturnviewdemo.main paused=false}
** Activity (main) Resume **
showStatusIcon on inactive InputConnection
GC_EXPLICIT freed 5381 objects / 288240 bytes in 29ms

EDIT.

Sorry yes the example is the latest one 1.2

The cpu on the device is atom
 
Last edited:

Smee

Well-Known Member
Licensed User
Longtime User
Andrew,

I set the IDE to allow only Landscape and when i turned it this is what i got in the log. On Demo 1.2

GC_EXPLICIT freed 115 objects / 8928 bytes in 16ms
ACTION_BATTERY_CHANGED pluggedType: 0
Setting rotation to 3, animFlags=1
** Activity (main) Pause, UserClosed = false **
Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/2 nav=1/2 orien=1 layout=35 uiMode=17 seq=18}
Unexpected resume of anywheresoftware.b4a.agraham.pageturnviewdemo while already resumed in anywheresoftware.b4a.agraham.pageturnviewdemo
Process 2317 terminated by signal (11)
WIN DEATH: Window{ae4b2a40 SurfaceView paused=false}
WIN DEATH: Window{ae448df0 anywheresoftware.b4a.agraham.pageturnviewdemo/anywheresoftware.b4a.agraham.pageturnviewdemo.main paused=false}
WIN DEATH: Window{ae481488 anywheresoftware.b4a.agraham.pageturnviewdemo/anywheresoftware.b4a.agraham.pageturnviewdemo.main paused=false}
Process anywheresoftware.b4a.agraham.pageturnviewdemo (pid 2317) has died.
Unexpected resume of org.adw.launcher while already resumed in anywheresoftware.b4a.agraham.pageturnviewdemo
aborting loaders
GC_EXPLICIT freed 8724 objects / 575432 bytes in 26ms
csju_screen->width:600
csju_screen->height:1024
GC_EXTERNAL_ALLOC freed 4585 objects / 259632 bytes in 40ms
load applications
--> applications loaded, return
loading user items in Thread[main,5,main]
--> items loaded, return
--> loading from cache: 6, 0
------> binding 6 items
------> binding 0 widgets
------> start binding items
GC_EXTERNAL_ALLOC freed 7760 objects / 505416 bytes in 27ms
GC_EXPLICIT freed 765 objects / 34712 bytes in 37ms
showStatusIcon on inactive InputConnection
Setting rotation to 0, animFlags=1
Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/2 nav=1/2 orien=2 layout=35 uiMode=17 seq=19}
Unexpected resume of org.adw.launcher while already resumed in org.adw.launcher
aborting loaders
GC_EXPLICIT freed 6120 objects / 417216 bytes in 37ms
csju_screen->width:600
csju_screen->height:1024
GC_EXTERNAL_ALLOC freed 2171 objects / 120672 bytes in 39ms
load applications
--> applications loaded, return
loading user items in Thread[main,5,main]
--> items loaded, return
--> loading from cache: 6, 0
------> binding 6 items
------> binding 0 widgets
------> start binding items
GC_EXTERNAL_ALLOC freed 7448 objects / 482376 bytes in 27ms
GC_EXPLICIT freed 188 objects / 7112 bytes in 37ms
GC_EXPLICIT freed 202 objects / 8976 bytes in 30ms
GC_EXPLICIT freed 330 objects / 13152 bytes in 15ms
GC_EXPLICIT freed 425 objects / 20224 bytes in 16ms
 

agraham

Expert
Licensed User
Longtime User
GC_EXPLICIT freed 115 objects / 8928 bytes in 16ms
ACTION_BATTERY_CHANGED pluggedType: 0
Setting rotation to 3, animFlags=1
** Activity (main) Pause, UserClosed = false **
There's something strange happening on that device. With an application restricted to a single orientation you should never get a pause event when you rotate the device.

You could try commenting out the PageTurner.OnPause and PageTurner.OnResume lines but I don't hold out much hope. It looks like a device specific problem to me I'm afraid.
 

Smee

Well-Known Member
Licensed User
Longtime User
its Viewsonic vpad10.

it only happens with this program. All other tests i have tried work ok

i already tried commenting everthing out of the two subs. no good
 

agraham

Expert
Licensed User
Longtime User
its Viewsonic vpad10.
Definitely x86 then. Have you tried the OpenGL library demo and this example?

I'm afraid that I can think of nothing do do to the library code as it runs fine on other devices and there is no indication of what the cause of the failure might be on the Viewpad.
 

Fox

Active Member
Licensed User
Longtime User
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

Where is my problem Page 0 is fantastic if i changed to page 1 no error but just a blue page no text nothing...
 

Smee

Well-Known Member
Licensed User
Longtime User
Definitely x86 then. Have you tried the OpenGL library demo and this example?

The First demo will not run. When i load it a message says to install b4a into a path without spaces and that the path hass illegal characters.
Both of which are incorrect.

The second demo crashes the same way when rotated

I'm afraid that I can think of nothing do do to the library code as it runs fine on other devices and there is no indication of what the cause of the failure might be on the Viewpad.
:sign0148:

BooHooooooo


Thanks very much for your efforts regardless Andrew. It is still a great library even though it will not run on my device
:BangHead::BangHead::BangHead:
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
With an application restricted to a single orientation you should never get a pause event when you rotate the device.

Just to nitpick a little for the sake of complete accuracy (at least as far as my Toshiba Thrive tablet goes). The steps below (copied from the Wiki) describes how an app restricted to a single orientation can be made to rotate. While the steps below only talk about the restart, before that point Pause will be executed (unless this is something peculiar to the Thrive).

1. While in your app, the device goes into Sleep mode, either through a time-out or by the user pressing the device's Sleep (power) button.

2. The user presses the power button to bring the device out of Sleep mode to the security/start-up screen and rotates that screen before exiting it to return to your app.

3. Your app will come back up in the supported orientation, but Android will have started it over as if the app itself had been rotated.
 

Smee

Well-Known Member
Licensed User
Longtime User
Yep, There is definitely something wierd about this device. Not only does it drop out on a change of orientation but if i start the program from the device (as opposed to compiling and running from the bridge) it always starts in landscape regardless of how i am holding the device.
 

MikieK

Member
Licensed User
Longtime User
Gradient on underside of the page

Firstly, can I just say what a fantastic job you have done with this library Andrew. The demo runs great on my milestone. :sign0188:
Sorry to nit pick (as I could never have achieved what you have here)
I have looked everywhere in the documentation, but to no gain.
Is there a way to control the colors shown in the gradient on the underside of the turning page?
 
Top