B4J Library [B4X] [XUI] SD: TouchViewEvent

Discussion in 'B4J Libraries & Classes' started by Star-Dust, Apr 29, 2018.

  1. Star-Dust

    Star-Dust Expert Licensed User

    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:
    Code:
    Sub EventName_Touch (Action As Int, X As Float, Y As Float)
    In B4J I would use this:
    Code:
    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

    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):
    Code:
    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
     

    Attached Files:

    Last edited: Apr 30, 2018
    fredo likes this.
  2. klaus

    klaus Expert Licensed User

    What about B4i ?
     
  3. Star-Dust

    Star-Dust Expert Licensed User

    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
     
  4. klaus

    klaus Expert Licensed User

    If you agree, I could have a look.
     
  5. Erel

    Erel Administrator Staff Member 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.
     
  6. Star-Dust

    Star-Dust Expert Licensed User

    Of course, it will be useful for others who use B4i
     
  7. Star-Dust

    Star-Dust Expert Licensed User

    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
     
  8. klaus

    klaus Expert Licensed User

    @Star-Dust:
    Can you send my 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 !
     
  9. Star-Dust

    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:
      Code:
      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: Apr 30, 2018
  10. Star-Dust

    Star-Dust Expert Licensed User

    This project changes its name and is transferred here
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice