simulate click - is there a way to activate any view?

riko

Member
Licensed User
Longtime User
Hello,

i am searching for a way to simulate a click on a view (radio button, slider,..).
Is there a way to do it?

Background is i have a transparent gesture-panel over my layout-panel and want to forward not needed actions.
For this i call a sub in the gesture-eventhandler.
This is the Sub i call:
B4X:
Sub ForwardAction(Action As Int, x As Float, y As Float)
   Dim bFoundView As Boolean
   bFoundView = False
    'look if any view is under this x/y
   If Action <> Activity.ACTION_MOVE Then
      Dim v As View
       'iterate through all views of the active panel
      For i = 0 To sd.Panels(sd.currentPanel).NumberOfViews - 1
         v = sd.Panels(sd.currentPanel).GetView(i)
         If (v Is Panel) Then Continue
         'Hittest x/y
         If (v.Left <= x) AND (v.Top <= y) AND (v.Width+v.Left >= x) AND (v.Height+v.Top >= y) Then
               'activate the view
            v.RequestFocus
               bFoundView = True
            Exit
         End If
      Next
   End If
   If bFoundView = False Then 'if no hit forward action to panel
      Panels_Touch(Action, x, y)
   End If
End Sub

But the "RequestFocus" function i used works only for EditFields...:sign0085:
 

francoisg

Active Member
Licensed User
Longtime User
transparent panel, pass touch events to view below?

Any solution to this problem yet?

I have a view with a transparent panel on top of it, where I catch touch events.

I now want to "pass" the handled events down to the view UNDER the transparent panel (a webview or scrollview for instance).

I need the transparent panel on top of the view as I need to "draw" various kinds of information on top of other views as well as handle touch events (next page etc). The view under the panel should however NOT stop responding to touches.

I hope this makes sense? ANY help would be greatly appreciated!!!
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Any solution to this problem yet?

I have a view with a transparent panel on top of it, where I catch touch events.

I now want to "pass" the handled events down to the view UNDER the transparent panel (a webview or scrollview for instance).

I need the transparent panel on top of the view as I need to "draw" various kinds of information on top of other views as well as handle touch events (next page etc). The view under the panel should however NOT stop responding to touches.

I hope this makes sense? ANY help would be greatly appreciated!!!

You have to use the Reflection library to set a Touch listener:
B4X:
Dim r As Reflector
r.Target = your_panel
r.SetOnTouchListener("YourPanel_Touch")

The event handler is declared like this:
YourPanel_Touch(ViewTag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean

In the touch event handler, you return True if you want to consume the event (no other view will get it) or False if you want to let it go through.
 
Upvote 0

francoisg

Active Member
Licensed User
Longtime User
Hi,
tried using reflection but (on Jellybean devices at least) if you return True, the sub gets the touch event and everything after that but the view below does not get called for any touch events (as expected). If you return false, it gets the touch down event but nothing else and nothing afterwards (the view below gets called for touch all events). So, it seems I'm stuck either way?
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hi,
tried using reflection but (on Jellybean devices at least) if you return True, the sub gets the touch event and everything after that but the view below does not get called for any touch events (as expected). If you return false, it gets the touch down event but nothing else and nothing afterwards (the view below gets called for touch all events). So, it seems I'm stuck either way?

This technique works with all Android versions. BUT if a view consumes the down action, then it gets all subsequent actions. I mean: when Action = 0 (down), if you delegate the touch event to another view and this view consumes it, this view will get directly all move actions afterwards.
If the user stops moving his finger and put it again on the screen, then your panel will receive again the down action.
 
Upvote 0

francoisg

Active Member
Licensed User
Longtime User
Yes, that is correct. The issue is that I need to be able to get notified (transparent panel) on all touch events as well as the view below.

I guess I will just need to find another way then ...

Thank you for the reply!
 
Upvote 0

NFOBoy

Active Member
Licensed User
Longtime User
Maybe this would work?

I think this is indeed doable.. but my brain is wrapped around another project that I need to finish today, so coming up with the code would take a bit.

Here would be the approach: Included is an old project I used for sliding panels with a transparent Top that Erel helped me with the reflection events required to send to views below. (I now use AHViewPager, as it is wayyy better than my silly coding attempts)


(Erel, or anyone else uber-uptodate on Reflection, please slap me if I am way off base)

If you also want to send the move events, a similiar thing can be done by using a Reflector to build a MotionEvent (it appears that is exactly the opposite of what is done when we get a Touch event in B4A, i.e. the MotionEvent is broken up into the X, Y, and Action events for us) and then sending that using a Reflector to the onTouchEvent of the View that you want to send it to, which should trigger that View's B4A Touch event. You can then still consume the event in your top transparent panel (so it still receives events# and the bottom ones still get whatever you programatically want to send them.

Hope that makes sense #along with the attached code)

Ross
 

Attachments

  • BetterSlidingPanelsWithTop.zip
    17.4 KB · Views: 253
Upvote 0
Top