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

jSD_XUI_TouchViewEvent

Author: Star-Dust
Version: 0.02
  • ManagerTouchEvent
    • Events:
      • TouchEvent (action As Int, Coordinate() As TCoordinate)
    • 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: Click- 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 B4A Version
 

Attachments

  • JTouchViewEvent_Sample1.zip
    2.1 KB · Views: 194
  • jSD_TouchViewEvent 0.02.zip
    4.9 KB · Views: 181
Last edited:

Star-Dust

Expert
Licensed User
What about B4i ?
You're right, but I do not have an Iphone to try it and I do not even B4i :p
We will see in the future
 

Star-Dust

Expert
Licensed User
Note that I also plan to make it easier. I will add a Touch event to B4J pane that will behave the same way as the touch event in B4A and B4i.
This will be excellent, even if it has not been particularly complicated.

Maybe in the next XUI version, the B4XView could have some ... But it's just a wish, it's the wrong place to say it :p
 

klaus

Expert
Licensed User
Longtime User
@Star-Dust:
Can you send me your code and I will look at it for B4i ?
Currently I use Touch Events for B4A and B4i and MousePressed, MouseDragged and MouseReleades for B4J in the xChart Class.

@Erel
Sounds great !
 
Last edited:

Star-Dust

Expert
Licensed User
Update 0.02.
Fix abug and for Android add a multi touch

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
    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
This project changes its name and is transferred here
 
Top