Android Question crossed with cross platform

mohsyn

Active Member
I've been struggling with this code for quite sometime in order to make it cross-platform compatible.

b4j label as shown in B4XPagesCrossPlatformProjectsV2_1.pdf documentation is as follows:

crossplatform.png

HERE all labels are shown to be compatible across platforms
but in actual there are some properties not available in others (like label.setbackground in b4a is not available in b4j)
after having gone back and forth trying to replace label with some other view and finding out that something else is not available in that view,
it brings me here to ask more experience developers on

1. Is there a comprehensive list of what properties / functions/ methods are available and not available across platforms?
2. Is there a quick guide OR reference OR tool to help convert code to other platforms which can help me ? if not, then, is hit an trial the only way to navigate forward?

B4X:
'called by
label1.SetBackgroundImage(FontAwesomeToBitmap(chrt,40))


Sub FontAwesomeToBitmap (Text As String, FontSize As Float) As B4XBitmap
    Dim xui As XUI
    Dim p As Panel = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 32dip, 32dip)
    Dim cvs1 As B4XCanvas
    cvs1.Initialize(p)
    Dim fnt As B4XFont = xui.CreateFontAwesome(FontSize)
    Dim r As B4XRect = cvs1.MeasureText(Text, fnt)
    Dim BaseLine As Int = cvs1.TargetRect.CenterY - r.Height / 2 - r.Top
    cvs1.DrawText(Text, cvs1.TargetRect.CenterX, BaseLine, fnt, PressedColor, "CENTER")
    Dim b As B4XBitmap = cvs1.CreateBitmap
    cvs1.Release
    Return b
End Sub
 

klaus

Expert
Licensed User
As written: ... which can be almost the same...
This means that there are differences between the platforms.

The only advice: use as much as possible B4XViews, these are wrappers above the platform specific objects with cross-platform common properties.
For more details you might have a look here: https://www.b4x.com/android/forum/threads/b4x-xui-cross-platform-native-ui-library.84359/#content.
In your example: instead of using a Label you may use a B4XView using the new As property:
Label1.As(B4XView).SetBitmap(FontAwesomeToBitmap(chrt,40))
Or, the line above is the short way of the code below:
Private xLabel1 As B4XView
xLabel1 = Label1
xLabel1.SetBitmap(FontAwesomeToBitmap(chrt,40))


You may have a look at the B4X Help Viewer which allows to display all properties, events and methods for all B4X objects.
You can select a platform, a library, an object, a method / event / property and display its functionality.
 
Upvote 0

mohsyn

Active Member
Thanks @klaus
It is nice to have seasoned developers like you around here, ready to help and guide.
I'm yet to get my head around .as and as and .asview and casting.
Will surely check b4x help viewer !!! 👍
 
Upvote 0
Top