Canvas access from another code module

tchart

Well-Known Member
Licensed User
Longtime User
Hi

I have a B4A project which draws bitmaps on the Activity canvas. Its been working fine but the code is becoming unmanagable. For ease of reading/modifying I am splitting the code into modules.

This has lead me to a problem; How can I access the Activity canvas from a code module so that I can draw bitmaps in the code module.

In the documentation it states that canvas is "an 'Activity Object', it cannot be declared under Sub Process_Globals." - hence my problem.

Is there any way to have a "canvas" that is not part of the Main code module?

Also, I thought I had a work around by calling a Sub (in the main) from a code module but I cant seem to do this either (global variables from Main can be accessed but not Subs)

Does anyone have any ideas or should I just re-engineer the whole thing?

Thanks
Trevor
 

tchart

Well-Known Member
Licensed User
Longtime User
Thanks, good to know.

My problem however is the "drawing" is trigger by a HTTP download which is happening in the code module (assuming thats possible).

ie

Main module initiates HTTP request (in code module)
Code module handles HTTP request
HTTP Request completes and draws bitmap on Activity Canvas

Of course this was all in the main code module and worked fine but now that its split up Im having a problem getting it all to work together.

Trevor
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
You can transmit a Canvas in a routine from the Activity module to a code module. Have a look at the ChartsFramework module.

Best regards.

Thanks Claus, what about the other way? I need to access the canvas or a "main" Sub from a code module.

Edit: to clarify the code module is meant to run "asynchronously" and update the canvas when required.
 
Last edited:
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
You could try to use Callsub.
I haven't tried it.

Best regards.

You sir are a genius! That solves the problem of calling a Main sub from a code module.

However now I have another issue, the HTTP downloader in the code module seems to expect the success/error response subs to be in the main code module. Oh well, back to the drawing board. I think perhaps I am trying to be too modular.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
You sir are a genius! That solves the problem of calling a Main sub from a code module.

However now I have another issue, the HTTP downloader in the code module seems to expect the success/error response subs to be in the main code module. Oh well, back to the drawing board. I think perhaps I am trying to be too modular.

Yes, it will. Because that is where the HTTP Client is instantiated.
But ofcourse you can CallSub that back to the main module as well.
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Yes, it will. Because that is where the HTTP Client is instantiated.
But ofcourse you can CallSub that back to the main module as well.

Actually it may be a bug unless its just the way Android works

The HTTP client is declared and initialised in the code module. The code compiles fine but when I fire off the HTTP request it throws an error saying it can find the sub XXX__ResponseSuccess etc
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
What I do is make a list in the library, and push events onto it like a stack
Then in the main activity you just parse each event in the list
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Or do you mean a FIFO? A stack would mean you process all events in reverse order.

Probably FIFO. I didn't think the order mattered.

But basically all I did was make a type that included:
the object ID#, object type#, X/Y coordinates touched, event type# (down, up, move) and a few other spare integers.

Then push that. And check the list via a timer event.
 
Upvote 0
Top