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


    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
  2. Star-Dust

    Star-Dust Expert Licensed User

    Example 1 (For B4J and B4A)

    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:
    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}"$)
    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
    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:
    End Sub
    Last edited: Apr 30, 2018
    Almora, micro and LucaMs like this.
  3. HLI

    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.
  4. Star-Dust

    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.
  5. HLI

    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
  6. Star-Dust

    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
    Peter Simpson likes this.
  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