B4A Library [B4X] [XUI] SD: TouchViewEvent

This project changes its name and is transferred here

Using the XUI views I realized the need to follow the events of Touch, Drag, Click and Release in a unique way.

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")

SD_XUI_TouchViewEvent

Author: Star-Dust
Version: 0.02
  • ManagerTouchEvent
    • Events:
      • TouchEvent (action As Int, Coordinate() As TCoordinate) ' Multi Touch
    • Fields:
      • Action_Down As Int
      • Action_Drag As Int
      • Action_LoseTouch As Int
      • Action_Up As Int
    • Functions:
      • Class_Globals As String
      • 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.
      • SetTouchEvent (View As B4XView, EventName As String) As String
  • TCoordinate
    • Fields:
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • X As Int
      • Y As Int
    • Functions:
      • Initialize
        Inizializza i campi al loro valore predefinito.


an example of how to do with this library (Both in B4A and in B4J):
B4X:
 Globals
    Dim Manager As ManagerTouchEvent
    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.SetTouchEvent(Label1,"Label1")
    Manager.SetTouchEvent(Label2,"Label2")
End Sub

Sub Label1_TouchEvent (action As Int, Coordinate() As TCoordinate)
    Select action
        Case Manager.Action_Down
               Log($"Label1: Press- X:${Coordinate(0).X} Y:${Coordinate(0).y}"$)     
        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 - X:${Coordinate(0).X} Y:${Coordinate(0).y}"$)            
        Case Manager.Action_Click
               Log($"Label1: Click- X:${Coordinate(0).X} Y:${Coordinate(0).y}"$)      
        Case Manager.Action_DoubleClick
               Log($"Label1: DoubleClick- X:${Coordinate(0).X} Y:${Coordinate(0).y}"$)       
        Case Manager.Action_LongClick
               Log($"Label1: LongClick- 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}"$)
End Sub

HERE B4J Version
 

Attachments

  • B4A_Sample1.zip
    9.2 KB · Views: 235
  • SD_XUI_TouchViewEvent 0.02.zip
    4.6 KB · Views: 239
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Update 0.02

Manages Multi-touch in android and fix bugs for b4j.
In the TouchEvent event the Coordinate Variable will be an array and will contain the points touched. In B4J only one Coordinate

  • TouchEvent (action As Int, Coordinate() As TCoordinate)
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Coming soon:
  1. DoubleClick event
  2. LongClick Event
  3. LastClick Property, will return a variable indicating when it was the last click (type long)
  4. Perhaps the pinch to zoom
  5. This will be possible:
    B4X:
    Dim Label1 As Label
    Dim Lx As B4XView=Manager.CreateAndSetEvent(Label1, "Label" )
If I become crazy, I will distribute the source, but only if I become crazy ;)
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
This project changes its name and is transferred here
 
Top