B4A Library PageTurnView library providing a page turn animation

Discussion in 'Additional libraries, classes and official updates' started by agraham, Aug 12, 2011.

  1. Smee

    Smee Well-Known Member Licensed User

    I am trying to call a sub-routine from within

    Code:
    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
    Code:
    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: Aug 16, 2011
  2. agraham

    agraham Expert Licensed User

    No, it's a desaturated mirror image of the page.
     
  3. agraham

    agraham Expert Licensed 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.
     
  4. MikieK

    MikieK Member Licensed 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?
     

    Attached Files:

  5. Smee

    Smee Well-Known Member Licensed 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

    Code:
    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
     
  6. agraham

    agraham Expert Licensed User

    I don't understand what you want but the answer is probably no as the page turn is entirely user driven.
     
  7. agraham

    agraham Expert Licensed User

    The demo already does it in Activity_Resume to go to the correct page if the activity is rebuilt. Just assign to CurrentPage.
     
  8. MikieK

    MikieK Member Licensed User

    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.
     
  9. agraham

    agraham Expert Licensed User

    I did download and run it, although it is missing an image. Your panel pops up on touch and then disappears on "untouch". I don't understand how that could be relevant to a page turn animation.
     
  10. Smee

    Smee Well-Known Member Licensed User

    Andrew, from your example,

    Does this mean that the following logic is not allowed

    if page number =x then labeldescription="No Test"
     
  11. MikieK

    MikieK Member Licensed 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. :)
     

    Attached Files:

  12. agraham

    agraham Expert Licensed 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.
     
  13. agraham

    agraham Expert Licensed User

    Nope, I still don't understand. Your code cannot receive touch events on a PageTurnView as the animation code swallows them all.
     
  14. MikieK

    MikieK Member Licensed 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.
     
  15. MikieK

    MikieK Member Licensed User

    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: Aug 16, 2011
  16. agraham

    agraham Expert Licensed User

    No code can execute after a Return statement.
     
  17. Smee

    Smee Well-Known Member Licensed User

    Hi,

    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
     
  18. MikieK

    MikieK Member Licensed 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.
     
  19. agraham

    agraham Expert Licensed 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.
     
  20. Smee

    Smee Well-Known Member Licensed User

    MickieK i dont follow you

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

    i just dont understand this statement sorry

    From what i can gather this would be impossible i think

    Cheers
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice