Share My Creation Mixer [B4APages]

Hi All

The attached ZIP is a B4XPages attempt. [B4A only]
The sole purpose of creating this app was to try to come to grips with B4XPages.
The reason for posting is the hope that someone will play devils advocate and point out some of the many things I have done incorrectly.

The app itself is a combination of two existing apps.
The First is a modification of an app that calculates the dilution values for embalming fluid. It now calculates the amount of Spirit etc. for mixed drinks. There are four parameters, by entering the values for any three will give the fourth value. Simply drag the parameter to be calculated to the Result Bar and tap a numeric displays of the other parameters to enter the values.
The Second app is a simple calculator taped to the back of the first.

It took a while but I think I did sort of get the hang of B4XPages and it does make things easier.

I'm sure I have made many fundamental errors so any suggestions gratefully received.

Regards Roger
 

Attachments

  • Screenshot_20210123-195711.jpg
    Screenshot_20210123-195711.jpg
    169 KB · Views: 1,737

LucaMs

Expert
Licensed User
Longtime User
The First is a modification of an app that calculates the dilution values for embalming fluid
How much joy 😁

However, I'm curious to see the source and I'll do it shortly.

I can say that the B4XPages are much easier to use than to manage the Activies and they really have many advantages.

I have only some doubts about the big difference between B4A, where it is possible (it is advisable) to use a single Activity but it is different with B4J and I believe also with B4i. I'll have to open a thread for this as this can be a problem in some cases.
 

LucaMs

Expert
Licensed User
Longtime User
I can only give 3 suggestions, only one of which concerns the B4XPages:

1 - the help. The source of the HTML page is shown, rather than the page itself.

2 - the operator touched and therefore current is not highlighted in the calculator.

3 - I would not give generic names to the B4XPages-classes nor to the object variables. In my opinion a good habit could be:
clsCalculator or, better, clspagCalculator - the class
pagCalculator - the object.


[StateManager is used well here. It is useful for keeping state between app "sessions" but it is not necessary to use it while using an app (advantage of B4XPages)]
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
To export your B4XPages project DO NOT use the menu "file - export as zip". Use:

View attachment 105460

LucaMs thanks for the feed back. I completely missed this one.
As it is I am surprised you were able to run the App, I tried from the Zip file I could not. I have tested the new upload and works from this end.

Regards Roger
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
I can only give 3 suggestions, only one of which concerns the B4XPages:

1 - the help. The source of the HTML page is shown, rather than the page itself.

2 - the operator touched and therefore current is not highlighted in the calculator.

3 - I would not give generic names to the B4XPages-classes nor to the object variables. In my opinion a good habit could be:
clsCalculator or, better, clspagCalculator - the class
pagCalculator - the object.


[StateManager is used well here. It is useful for keeping state between app "sessions" but it is not necessary to use it while using an app (advantage of B4XPages)]


1. This puzzles me, hopefully this clears up with the new Zip upload.
2. Great idea, I will give it a try.
3. Good thought. I had briefly considered this early on but didn't follow up. :(

Statemanger: Not really sure where to put the SAVE.

Regards Roger
 

LucaMs

Expert
Licensed User
Longtime User
LucaMs thanks for the feed back. I completely missed this one.
As it is I am surprised you were able to run the App, I tried from the Zip file I could not. I have tested the new upload and works from this end.

Regards Roger
I succeeded because IDE and I have a special relationship, it does everything I tell it; right speaking 😄

[I commented the #CustomBuildAction line, which could not find the files to copy :) (the shared folder)]
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Statemanger: Not really sure where to put the SAVE.
For the current state of the pages, for example the text contained in an EditText (B4XView) it is no longer necessary to use StateManager, it will not be lost if you send the app to background (if the app itself will not be killed by the OS).

To save the status for an eventual restart of the app, you could use the B4XPage_Background event
 
Last edited:

Roger Daley

Well-Known Member
Licensed User
Longtime User
How much joy 😁

However, I'm curious to see the source and I'll do it shortly.

I can say that the B4XPages are much easier to use than to manage the Activies and they really have many advantages.

I have only some doubts about the big difference between B4A, where it is possible (it is advisable) to use a single Activity but it is different with B4J and I believe also with B4i. I'll have to open a thread for this as this can be a problem in some cases.
LucaMs

Not quite sure which source you refer too but attached is the latest version of EMBALMER. It is easy to see that the Pages version is a lot easier to follow.

Regards Roger
 

Attachments

  • Embalmer.zip
    56.4 KB · Views: 191

Roger Daley

Well-Known Member
Licensed User
Longtime User
For the current state of the pages, for example the text contained in an EditText (B4XView) it is no longer necessary to use StateManager, it will not be lost if you send the app to background (if the app itself will not be killed by the OS).

To save the status for an eventual restart of the app, you could use the B4XPage_Background event
Thanks I will make the change.

Roger
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
Well, I don't know your "question" :) (this one).

Anyway, I loaded your helpfile.html in a webview of a B4J-B4XPages project and it looks ok while in B4A it doesn't 🤔

This is a puzzle, I'v tried four devices [Note 3, LGV20, Galaxy A70 and a TAB A10"] with 3 different Android versions. All work without a problem. I'll leave this in the mystery bin. 🤪
 

aeric

Expert
Licensed User
Longtime User
Well, I don't know your "question" :) (this one).

Anyway, I loaded your helpfile.html in a webview of a B4J-B4XPages project and it looks ok while in B4A it doesn't 🤔
Alternatively you can try to load the string from the file then use LoadHtml to show the html.

B4X:
'helpview.LoadUrl($"${xui.FileUri(File.DirAssets, "helpfile.htm")}"$)    'to this line
helpview.LoadHtml(File.ReadString(File.DirAssets, "helpfile.htm"))
 

Roger Daley

Well-Known Member
Licensed User
Longtime User

aeric, thanks for the feedback. Unfortunately I cannot duplicate LucaMs' problem to test solutions, however your suggestion of using "Wait For" sparked in my mind that LucaMs may have a super fast phone and it is a timing issue. Just clutching at straws here.

Below is the Help activity from which I lifted the code in the mixer B4XPage2.

Regards Roger

HelpActiv:
#Region  Activity Attributes
    #FullScreen: true
    #IncludeTitle: false
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private xui As XUI
    Private helpview As WebView                    'See   Sub helpview_OverrideUrl (Url As String) As Boolean
    'Private ph1 As Phone
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("helplay")   
    'ph1.SetScreenOrientation(0)                     '-1 Unspecified, 0 - Landscape, 1 - Portrait
  
    'helpview.LoadURL("file:///android_asset/helpfile.htm")         'Erel said "don't use this".
    'helpview.Loadurl(WebViewAssetFile("helpfile.htm"))                'Erel said "use this with Sub below".
    helpview.LoadUrl($"${xui.FileUri(File.DirAssets, "helpfile.htm")}"$)    'Then Erel said use this [possibly years later]

End Sub

'Sub WebViewAssetFile (FileName As String) As String
'    Dim jo As JavaObject
'    jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File")
'    If jo.GetField("virtualAssetsFolder") = Null Then
'        Return "file:///android_asset/" & FileName.ToLowerCase
'    Else
'        Return "file://" & File.Combine(jo.GetField("virtualAssetsFolder"), _
'       jo.RunMethod("getUnpackedVirtualAssetFile", Array As Object(FileName)))
'    End If
'End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
  
End Sub

Sub helpview_OverrideUrl (Url As String) As Boolean                'ignore
    'Accessing a URL via a link in a Webview may have limitations.
    'This Sub intercepts the URL (Url As String) and calls the default browser to access the URL.
    'Note:  The "helpview" part of the Sub name is the name of the Webview defined in Sub Globals.
    Dim p As PhoneIntents
    Dim message As Email
    helpview.StopLoading

    If Url.StartsWith("mailto:") Then
        message.To.Add(Url.SubString(7))
        StartActivity(message.GetIntent)
    Else
        StartActivity(p.OpenBrowser(Url))
    End If
  
End Sub
 
Top