Android Question BAL to JSON for dynamic layouts?

techknight

Well-Known Member
Licensed User
Longtime User
I haven't performed a deep level of searching to see if this already exists, but I figured I would ask here in case someone knows:

Is there code/tool that would allow me to take layouts and convert them into JSON for dynamically loading them at runtime from a server?

I am trying to build a dynamically configurable UI in the app which would be fed from a server that also includes control events that would also need to be handled at runtime vs compiled, and I Was wondering if this is possible or if it was done already. I would like to do something such as JSON instead of just passing a BAL file down from the server because the goal is to eventually use the same layout data and parse it in Node/React to render out a similar UI to keep things cross-platform.

Thanks!
 

techknight

Well-Known Member
Licensed User
Longtime User
Edit: Just saw BalConverter and its had a lot of updates, I might be able to use that to be able to bring in JSON, and run it in the LoadLayout function to at least use the layout engine which responds to scaling, anchors, etc.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Ahh, darn. So this wont work for what I am trying to do.

My goal was have a server-configurable layout where I can make UI changes without needing to re-release the apps to do so.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Maybe this is why some developers prefer to use WebView to load webpages from the server.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Ahh, darn. So this wont work for what I am trying to do.

My goal was have a server-configurable layout where I can make UI changes without needing to re-release the apps to do so.

You can create an empty layout and then you can do the following:
You can get Root panel dimensions (B4XPages) and have a json file you will create from a B4J app to be downloaded from your server. The json file will be a JSON array of JSON objects. Each JSON object will have six keys: type, name, top, left, width, height. The last four will be fractions in the range of values 0 to 1 which will be multiplied with Root.Width and Root.Height in order to get position and dimensions of each view. Then you will create the environment adding the views and associate the tag of each view with name which will be a value you will check to execute the apropriate code. For XUI views add the tag in {XUIView}.mBase.Tag because their tag represents the classes themselves.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…