B4J Library [B4X] [XUI] SD: B4XViewEvent

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

  1. Star-Dust

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

    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.
     

    Attached Files:

    Last edited: Jul 17, 2018
    calsdn, inakigarm, Erel and 2 others like this.
  2. Star-Dust

    Star-Dust Expert Licensed User

    Example 1 (For B4J and B4A)

    Code:
    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
    Code:
    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: Apr 30, 2018
    Almora, micro and LucaMs like this.
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