Android Question [SOLVED] SwiftButton Haptic Feedback on ButtonDown Event

Mr_Harry

New Member
Licensed User
Hello Friends,
Is there any way that I can have haptic feedback on a SwiftButton when the user presses the button?

SwiftButtons are very convenient and I know the option of Haptic Feedback in the properties of the designer.
Because I need haptic feedback once when the user presses the button and once when the user releases the button, I am using panels to achieve this result but I loose all the simplicity of a SwiftButton. For example, I have to make images instead of just using a symbol from the fontawesome font.

Thank you.

This is how I am doing it at the moment:
Private Sub PanelConnect_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        Case 0 'down
            CallSub2(Starter,"PerformHapticFeedback",Sender)
            PanelConnect.Background = bd_connect_b
        Case 1 'up
            CallSub2(Starter,"PerformHapticFeedback",Sender)
            PanelConnect.Background = bd_connect_a
            doStartBTScan
    End Select
End Sub

Private Sub PerformHapticFeedback (view As Object)
   #if B4A
    Dim jo As JavaObject = view
    jo.RunMethod("performHapticFeedback", Array(1))
   #Else if B4i
   FeedbackGenerator.RunMethod("impactOccurred", Null) 
   #end if
End Sub
 

Mr_Harry

New Member
Licensed User
Thank you Erel.
Works perfectly !

B4X:
Private Sub SwiftButtonReport_ButtonUp
    XUIViewsUtils.PerformHapticFeedback(SwiftButtonReport.mBase)
    B4XPages.ShowPage("ReportPage")
End Sub

Private Sub SwiftButtonReport_ButtonDown
    XUIViewsUtils.PerformHapticFeedback(SwiftButtonReport.mBase)
End Sub
 
Upvote 0
Top