Share My Creation Class From Layout - a utility to create a boilerplate class from a layout.

Class From Layout

Page2.png

Class from layout is a tool to provide a basic class from a layout file to save time creating the boiler plate yourself. It was in development before Erel released the new Layout to Json utility. Using that makes it more stable as it was originally based on Designer scripts. You need to follow the instructions in the link to setup the Layout to Json utility.

It is not intended to create 100% working classes, but basic boilerplate with view definitions and simple methods and events. It can also provide a Map interface and constants for updating and obtaining the current state of the data in the class.

It is written for the way I work, so may not be suitable for all. If you have any suggestions for improvements, please let me know.

It provides templates for:

  • B4xPage
  • Class with Layout
  • CustomView
  • Dialog Template
  • B4A Main (Activity)
  • B4J Main

Class From Layout makes no changes to the Json or project files.

Supports B4J and B4A.

This is my first attempt with a new Github template, so apologies in advance if something goes wrong.

The help files are quite comprehensive, so I suggest taking a little time to browse them.

All of the dialog templates used in the app were created with ClassFromLayout.

It should be considered a beta version. I would be grateful for any feedback.

Let me know how you get on with it.

Depends on:

The zip file attached is the source code minus the help files (site.zip) which you can download from the Github page here Just copy it as is into the Files folder of the project. Or you can download the full zip including the help files from the Github page Files folder.

Help files can also be found online https://stevel05.github.io/ClassFromLayout/. I will remove them from the app in the next release and link to these.
 

Attachments

  • ClassFromLayout_Source_V0.1.zip
    74.2 KB · Views: 62
Last edited:

stevel05

Expert
Licensed User
Longtime User

Basic Workflow​

Create JsonLayouts​

Class From Layout uses the Layout to Json utility (see setup instructions in the link).

The first step is to add the macro directive to your project:

B4X:
#Macro: After Save, Sync Layouts, ide://run?File=%ADDITIONAL%\JsonLayouts.jar&Args=%PROJECT%&Args=%PROJECT_NAME%

Which creates and syncs the layout files with json files saved to a JsonLayouts directory in the project folder.

Alternatively, if you don't want it to run every time you save the project you an add a Comment Link:

B4X:
'Sync Layouts, ide://run?File=%ADDITIONAL%\JsonLayouts.jar&Args=%PROJECT%&Args=%PROJECT_NAME%

and run the sync manually by control clicking on the link.

Run ClassFromLayout​

You can then run ClassFromLayout, click the open folder button and select the project directory or the JsonLayouts directory that was just created. You can also drag either onto the opening page.

Class From Layout also accepts a project folder or JsonLayouts folder as an argument, so if you package the app, you can call it from a comment link and pass the %PROJECT% alias.

B4X:
'ClassFromLayout ide://run?file=Path\to\ClassFromLayout.exe&Args=%PROJECT%\JsonLayouts

The Path To Config Files field will be updated automatically and files will be saved there when you save a configuration.

The selection box will then show all of the Json Layout files that are in the directory. Select one and click the Open button.

You can then select a Class Type and generate some code to see what it does.

If you have previously saved a configuration for this layout you will see a popup with all the available configuration files that match the layout:

1750937856073.png

Create the class​

Once you have generated a page of code, you will need to:

  1. Add the appropriate class and/or code module (as required) to your project,
  2. Copy the generated code into them.
If you use a code module for constants, make sure the name matches in your project and Class From Layout.
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Very promising ! Keeping an eye on this!
 

Cableguy

Expert
Licensed User
Longtime User
I'm guessing that this would be a huge help in creating Custom views using the designer...
I mean, putting a few independent views in a layout in a way they become a single custom view.
This will then generate a basic skeleton of what the custom view class would be, with all the designer related code, Designer Scripts, Events, methods and such...
Right? (if not, this can evolve into that, no?)
 

stevel05

Expert
Licensed User
Longtime User
It doesn't do anything relating to the physical layout. Designer scripts need to be created in the layout

It will create events, fields, methods and callbacks that are selected within the app.
 
Top