B4J Library [B4X] [XUI] SD: B4XViewEvent

Star-Dust

Expert
Licensed User
Using the XUI views I realized the need to follow the events of Touch, Drag, Click and Release in a unique way. Required XUI 1.72+

In Android I would use this command:
B4X:
Sub EventName_Touch (Action As Int, X As Float, Y As Float)
In B4J I would use this:
B4X:
Sub EventName_MouseDragged (EventData As MouseEvent)
Sub EventName_MouseClicked (EventData As MouseEvent)
Sub EventName_MouseReleased (EventData As MouseEvent)
I wanted to create an XUI class that manages things in a standard way, so if we write apps using XUI views we can also have a standard when we write code related to events, without having to use #IF B4A, #IF B4J

In B4A the result is the same that you would get by setting the Touch event with JavaObject.SetOnTouchListener

In B4J the result is the same that you would get the same as creating an Event with o.CreateEvent ("javafx.event.EventHandler", "Event")

B4i not available at the moment
SD_B4XViewEvent

Author: Star-Dust
Version: 0.01
  • ManagerEvent
    • Events:
      • TouchEvent (action As Int, Coordinate() As TCoordinate)
        ' Cordinate is array for Multi-touch (Only B4A)
    • Fields:
      • Action_Click As Int
      • Action_DoubleClick As Int
      • Action_Down As Int
      • Action_Drag As Int
      • Action_LongClick As Int
      • Action_LoseTouch As Int
      • Action_Up As Int
      • MinMoveAccept As Int ' Default is 2dip (only B4A)
    • Functions:
      • Class_Globals As String
      • CreateViewSetEvent (View As View, EventName As String) As B4XView
      • getLastClick As Long
      • Initialize (mCallBack As Object) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • SetEvent (View As View, EventName As String) As ManagerEvent
    • Properties:
      • LastClick As Long [read only]
  • TCoordinate
    • Fields:
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • X As Float
      • Y As Float
    • Functions:
      • Initialize
        Inizializza i campi al loro valore predefinito.
 

Attachments

Last edited:

Star-Dust

Expert
Licensed User
Example 1 (For B4J and B4A)

B4X:
Sub Globals
    Dim Manager As ManagerEvent
    Private Label1 As Label
    Private Label2 As Label
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")
 
    Manager.Initialize(Me)
    Manager.SetEvent(Label1,"Label1").SetEvent(Label2,"Label2")
    Manager.SetEvent(Label3,"Label3")
End Sub

Sub Label1_TouchEvent (action As Int, Coordinate() As TCoordinate)
    Select action
        Case Manager.Action_Down
            Log($"Label1: Press"$)
        Case Manager.Action_Drag ' Drag
            Log($"Label1: Drag- X:${Coordinate(0).X} Y:${Coordinate(0).y}"$)
        Case Manager.Action_Up ' Release click
            Log($"Label1: Release "$)
        Case Manager.Action_Click
            Log($"Label1: Click"$)
        Case Manager.Action_DoubleClick
            Log($"Label1: DoubleClick"$)
        Case Manager.Action_LongClick
            Log($"Label1: LongClick"$)
        Case Else
            Log($"Label1: ${action}- X:${Coordinate(0).X} Y:${Coordinate(0).y}"$)
    End Select
End Sub

Sub Label2_TouchEvent (action As Int, Coordinate() As TCoordinate)
    Log($"Label2: ${action}- X:${Coordinate(0).X} Y:${Coordinate(0).y}"$)
 
    ToastMessageShow("Label2",False)
End Sub

Sub Label3_TouchEvent (action As Int, Coordinate() As TCoordinate)
    Log($"Label3: ${action}- X:${Coordinate(0).X} Y:${Coordinate(0).y}"$)
End Sub
Example 2
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
Dim xui As XUI
    Dim Manager As ManagerEvent
  
    Private Label1 As Label
    Private Label2 As Label
    Dim B4XLabel1 As B4XView
    Dim B4XLabel2 As B4XView
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")
     
    Manager.Initialize(Me)
    B4XLabel1=Manager.CreateViewSetEvent(Label1,"B4XLabel1")
    B4XLabel2=Manager.CreateViewSetEvent(Label2,"B4XLabel2")
  
    B4XLabel1.Color=xui.Color_Cyan
    B4XLabel2.Color=xui.Color_Yellow
End Sub
 
Last edited:

HLI

New Member
Licensed User
I would like to use something similar to this sample: DoubleClick and/or LongClick. Loading this sample the libraries "Core (Version 9.0)" and "XUI (Version 1.9)" are activated. ManagerEvent and TCoordinate are notified as unkown Types. What is missing? What about Library sd_b4xviewevent? If sd_b4xviewevent is missing, how can I add this Library?

Sorry about these questions. I am a beginner, using B4A since about 1 month. Many thanks for any answers.
 

Star-Dust

Expert
Licensed User
I updated the XML files. Download the libraries again and try again.

Please note that this library is only for particular purposes, for example when an event must be renamed.
Is not necessary to unify the events of B4A and B4J, Now with the XUI library the events are unified.
 

HLI

New Member
Licensed User
Thank very much for your post. Sorry, I must disturb you again. How can I download the libraries? As I wrote I am a "greenhorn".
With kind regards Hans Louis Ineichen
 

Star-Dust

Expert
Licensed User
You can download the libraries and examples from post # 1 of this thread.

They are compress. You should de-compress the file containing the libraries and copy it to your library folder.
While it is always enough for them to just de-compress and open them
 

walterf25

Expert
Licensed User
Then the prefix B4X is not true. B4X prefixes are used for Crosspltform (B4A/J/i). If one is not supported then you should not use b4x as prefix.
LOL, i was tempted to say that but didn't want to sound rude :D

Walter
 

walterf25

Expert
Licensed User
I don´t think it sounds rude.

It sounds other when i am rude :D

PS: Rude or not; Merry Christmas to you all ;-)
Merry Christmas Bud.

Walter
 

Star-Dust

Expert
Licensed User
Then the prefix B4X is not true. B4X prefixes are used for Crosspltform (B4A/J/i). If one is not supported then you should not use b4x as prefix.
You have already made this observation in the past. Erel replied in the following way

As I see it, it is completely fine to mark a thread with [B4X] even if it only supports two platforms. You should explain it in the library instructions.

[B4X] tag is important as the search engine treats such threads as multiplatform.
I also don't think I'm rude if I tell you that you have little memory ;)
 

DonManfred

Expert
Licensed User

Star-Dust

Expert
Licensed User
LOL, i was tempted to say that but didn't want to sound rude :D

Walter
You did well. Don't say it, because you saved yourself a corner ;)
 
Last edited:
Top