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:

Smee

Well-Known Member
Licensed User
Longtime User
I am trying to call a sub-routine from within

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

However i am getting errors
main_getlist (java line: 469)
android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
etc.....

Any idea on how would i overcome this?

Thanks

Joe

EDIT:
Ok its not calling the sub thats the problem its whats in it
B4X:
   Cursor2 = SQLConn.ExecQuery("SELECT PName FROM PicturesLink WHERE Picture='" & Filenamex & "'")
           lvOrderPdct.Clear '    THIS LINE HERE CAUSES THE ERROR
           For i = 0 To Cursor2.RowCount-1
            Cursor2.Position = i
            PCodex=Cursor2.GetString("PName")
            Log(ProdCodex)
           lvOrderPdct.AddSingleLine(PCodex)
Next

lvOrderPdct IS A LISTVIEW Dim in GLOBALS
lvOrderPdct.Initialize("lvOrderPdct")
Activity.AddView(lvOrderPdct,0,810,180,160)
lvOrderPdct.Visible=True
lvOrderPdct.AddSingleLine("Test 1")
lvOrderPdct.AddSingleLine("Test 2")
lvOrderPdct.AddSingleLine("Test 3")
lvOrderPdct.AddSingleLine("Test 4")

As long as i dont call the sub the testlines show ok

I have even tried dim another listview in the pageturner sub itself under a different name and putting the code in the sub but it makes no difference.
Why can i not access a listview from here?
:confused::BangHead:
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Version 1.3 now posted includes a TextPaginator object that takes a string and breaks it into pages provides the ability to render any page onto a bitmap for display.

The demo is updated to demonstrate this and also now includes example error handling code. To assist this a RunOnGuiThread method has been added to PageTurnView.

Also added to PageTurnView is a convenience method, SetMarginPixels. Note the caveat in the help about when it needs to be called.
 

MikieK

Member
Licensed User
Longtime User
A probably misguided question.

Hi Andrew
Again, :sign0188: for all your hard work.
attached is a project that I have written using a ListView. Its a bit rough and ready, but the basics are there. I would love to be able to add your page turn animation to this but would like to just be able to call it when the panel is shown. Is there any way I could do this?
 

Attachments

  • Classifieds.zip
    6.4 KB · Views: 246

Smee

Well-Known Member
Licensed User
Longtime User
Awesome Andrew,

I was about to post another small problem i have hit but i will go through the sample first before expecting an answer. No i'll post anyway and look at the example too:)

I have hundreds of pics to show, divided into directories. I am able to display from any directory as required but i am stuck on programmatically changing to the first file of the next page. ie re-set the page number to 1

B4X:
If Page = MaxRecs Then ' Last page Load new Records from Next Directory
   CatNum=CatNum+1
   OpenPictureTable
   Page=0
           LoadNextCat(True)
End If

Thanks for the update
 

MikieK

Member
Licensed User
Longtime User
I don't understand what you want but the answer is probably no as the page turn is entirely user driven.

Hi, sorry again, but in order to understand, you may have to download and run my source. Basically, I just want the pageturner for the image that it produces on top of a given view, I want to be able to handle the touchlistener myself as shown.
 

Smee

Well-Known Member
Licensed User
Longtime User
Andrew, from your example,

' The PageTurnerView events run on a separate thread to the main thread.
' They therefore must not try to manipulate GUI elements.

Does this mean that the following logic is not allowed

if page number =x then labeldescription="No Test"
 

MikieK

Member
Licensed User
Longtime User
:sign0013:i'm a :sign0104:
the file should be attached now.
10pts if you guess what I was trying to emulate.
My point is, when the panel is shown, it would be nice if the corresponding x/y values would translate into your library to generate a bitmap to overlay over the current view (as in the panel). And similarly when you release the touch, the animation either will show the page going back to unchanged, or continue to the next page.

If you don't understand, let me know, if you do, but think it is too much work, dont worry, I'll try to do it myself. (But it definately wont look as good)
The thing is, and again it falls down to me not understanding java(hence why i'm using B4A) I'm sure that whatever you are refering to has to take into consideration where the screen is touched, and what has happened since it was touched.

Incidently, I atleast deserve a very tiny amount of respect for getting the ontouchlistener to work on a ListView without using reflections. :)
 

Attachments

  • Classifieds.zip
    13.8 KB · Views: 218

agraham

Expert
Licensed User
Longtime User
No. You will get an exception as you have already found out previously if you touch a view from a thread other than the main thread. You can use RunOnGuiThread to execute a line like that in a separate Sub but it runs asynchronously and you can't accept a return value.
 

MikieK

Member
Licensed User
Longtime User
Its probably not your fault, I'm new to this. Nevermind. I'll get back to you after I have made more progress. Unfortunately that means that I will probably have to have completely recode the class you are refering to in your libary in B4A, but thats life.
Please don't think that I am not greatful for what you have done so far, because you are part of what makes B4A good.
 

MikieK

Member
Licensed User
Longtime User
I am trying to call a sub-routine from within

you won't get an error if you call the sub after "Return bmp". I've tried a few things here, but I haven't been able to get anything to work (admitedly I haven't tried 1.3 yet, but I'm not sure Andrew is on the same page.)
Have a look at my previous uploaded zip. If you are looking for something similar, give me a day or two, and I'll try to produce something that actully works with something other than a bitmap. no offence meant to Andrew as I still maintain that he is a GOD in B4A compaired to me (excriment)... Sorry for being a dickhead. If I'm not on the same page as you Smee, let me know.
 
Last edited:

Smee

Well-Known Member
Licensed User
Longtime User
Hi,

you won't get an error if you call the sub after "Return bmp".

Of course you wont coz the program will not execute that far.

I tried your zip but it does not execute. I have some issues with my paths i think

Andrew,

The PageTurner.CurrentPage does get me there but i seem to be skipping some pages every now and then. If i cannot sort it i will post the code snippet to see if you can see a logical error in it
 

MikieK

Member
Licensed User
Longtime User
Hence no error.
I reckon the only way that you can put more than a bmp in the PageTurner_GetBitmap sub is to use a webview and then use CaptureBitmap to return an actual bitmap. (personally, I'm not interested in javascript as I want to stick to one language)
Again, I'm new at this, so I could be wrong. BUT I think that this library would be more useful if you ripped out the draw ellements of it and let us handle the touch events.
 

agraham

Expert
Licensed User
Longtime User
There must be a logical error. You set the CurrentPage and the view will promptly raise the GetBitmap event and pass you that page number. Put a Log with the page number before the assignment and another in the GetBitmap event and they should pair up.
 

Smee

Well-Known Member
Licensed User
Longtime User
MickieK i dont follow you

Hence no error.

Why would you put a call to a subroutine in a place where it will never run???????

I reckon the only way that you can put more than a bmp in the PageTurner_GetBitmap sub is to use a webview and then use CaptureBitmap to return an actual bitmap. (personally, I'm not interested in javascript as I want to stick to one language)

i just dont understand this statement sorry

Again, I'm new at this, so I could be wrong. BUT I think that this library would be more useful if you ripped out the draw ellements of it and let us handle the
touch events.

From what i can gather this would be impossible i think

Cheers
 
Top