B4A Library [Lib] Gesture Detector

Informatix

Expert
Licensed User
The code is yours code exact but i use the Sender to get the button to rotate.

B4X:
Sub TableGesture_onRotation(Degrees As Double, MotionEvent As Object)
  
    If Debug Then Log("TableGesture_onRotation(Degrees = " & Degrees & ", MotionEvent=" & MotionEvent & ")")
  
    Dim TableToRotate As Button
    TableToRotate = Sender
  
    Dim Angle As Float = Degrees
    Dim jo = TableToRotate As JavaObject
    jo.RunMethod("setRotation", Array As Object(Angle))

End Sub

Here is the logfile, i press on the bottom left and the top right corners, and the image rotate like a propeller.
Each instance of GestureDetector is bound to a view so I don't really understand why you need to know who sent the event. That cannot be another view that the one you bound to GD. If you share the GD among different views, it's a mistake. 1 GD = 1 View.
 

TheMightySwe

Active Member
Licensed User
Each instance of GestureDetector is bound to a view so I don't really understand why you need to know who sent the event. That cannot be another view that the one you bound to GD. If you share the GD among different views, it's a mistake. 1 GD = 1 View.
The views and gesturedetectors are made programaticlly depending on data in a database, there can be 50 different views and i only want to rotate the one i have my fingers on.

And it works fine with all the other events.
 
Last edited:

TheMightySwe

Active Member
Licensed User
But i can invent some other way to rotate them if its not possible to use onRotate in that way. No problem.
 

Informatix

Expert
Licensed User
But i can invent some other way to rotate them if its not possible to use onRotate in that way. No problem.
I understood where's your mistake. You bound the GD to the view that you want to rotate. For two-fingers actions, the GD has to be bound to the container holding the view (a panel, the activity, etc.) not to the view itself. Look at my code. The GD is bound to the activity containing the panel, not to the panel to rotate.
 

TheMightySwe

Active Member
Licensed User
I understood where's your mistake. You bound the GD to the view that you want to rotate. For two-fingers actions, the GD has to be bound to the container holding the view (a panel, the activity, etc.) not to the view itself. Look at my code. The GD is bound to the activity containing the panel, not to the panel to rotate.

OK, so I can basiclly not get the Button from the Sender then, so I have to invent another way to rotate the button.

Because I already use a lot of the other events and they work like clockwork except onPinch and the other two finger gesture, but that has to be for the same reason.

I think i will use Doubleclick to clear the panel from all other Buttons except the one i doubleclick, set the GD to the ScrollPanel2D and see what happens. Then use doubleclick again to save placement, angle and the rest and reload from database.
 
Last edited:

Informatix

Expert
Licensed User
OK, so I can basiclly not get the Button from the Sender then, so I have to invent another way to rotate the button.
When you rotate a button, unless it is quite big, your fingers are not on the button, so how do you know the view to rotate? If you can answer to this question, then you can use GD to rotate the view. Usually the trick is to put each view to rotate in a bigger but invisible container. Another idea is to rotate the button touched by one of the fingers (but nothing will happen if the two fingers are outside the button area).
 

TheMightySwe

Active Member
Licensed User
Hi,

Thanks for the help, i found a way to fix the problem. I did like this, in the administration mode I use "onSingleTapConfirmed" to set the button to a Dummy ButtonView in Globals

When I use a GD that is linked to the panel on the two finger gestures. It works like a charm.

I removed the onRotate to the GD that handles the single button.

I don't know if it's the best looking solution, but it works. Thats the most important thing.

Now I have to work out how to limit the buttons size and snap them to a invisible grid.

Thanks for helping me again.

B4X:
Sub ButtonAdminGesture_onSingleTapConfirmed(X As Float, Y As Float, MotionEvent As Object)

    If Debug Then Log("ButtonAdminGesture_onSingleTapUp(MotionEvent=" & MotionEvent & ")")
    ClickedButton = Sender ' Dummy in Globals

End Sub
 

Informatix

Expert
Licensed User
why strange? in some devices the double tap is fired also when the screen is off
Ah sorry, you're right. It seems that the OS has to be modified to make this possible (AFAIK only LG modified it to add such a feature; other solutions need a rooted device). I cannot say whether standard event are used in this case. Try and let us know.
 

TheMightySwe

Active Member
Licensed User
Hi, sorry to pest you with more questions.

Is it possible to "drag and drop" a button from one panel to another?

What events shall I use in that case if its possible?
 

Bill Kantz

Member
Licensed User
I am getting an error when trying to used GD with Margret's Toast Msg Class. I assume it is some conflict over touch events. It is triggered when I use a fling. This happen even after I dismiss the Toast msg with a tap.

both GD and reflection up to date.

Thanks
Bill


B4X:
** Service (ws) Start **
java.lang.NullPointerException
    at android.view.GestureDetector.onTouchEvent(GestureDetector.java:587)
    at flm.b4a.gesturedetector.GestureDetectorForB4A$1.onTouch(GestureDetectorForB4A.java:119)
    at android.view.View.dispatchTouchEvent(View.java:5544)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1912)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1371)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1860)
    at android.view.View.dispatchPointerEvent(View.java:5729)
    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2960)
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2469)
    at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2478)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4456)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
    at dalvik.system.NativeStart.main(Native Method)
 

Informatix

Expert
Licensed User
I am getting an error when trying to used GD with Margret's Toast Msg Class. I assume it is some conflict over touch events. It is triggered when I use a fling. This happen even after I dismiss the Toast msg with a tap.

both GD and reflection up to date.

Thanks
Bill


B4X:
** Service (ws) Start **
java.lang.NullPointerException
    at android.view.GestureDetector.onTouchEvent(GestureDetector.java:587)
    at flm.b4a.gesturedetector.GestureDetectorForB4A$1.onTouch(GestureDetectorForB4A.java:119)
    at android.view.View.dispatchTouchEvent(View.java:5544)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1951)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1712)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1912)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1371)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1860)
    at android.view.View.dispatchPointerEvent(View.java:5729)
    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2960)
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2469)
    at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2478)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4456)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
    at dalvik.system.NativeStart.main(Native Method)
You should see that with Margret because I don't know at all her class/library. I cannot do anything for you on the GD side.
 
Top